UNPKG

backpack-ui

Version:
124 lines (101 loc) 3.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.underlinedLink = exports.blueLink = exports.visuallyHidden = exports.outline = undefined; var _extends2 = require("babel-runtime/helpers/extends"); var _extends3 = _interopRequireDefault(_extends2); var _colors = require("../styles/colors"); var _colors2 = _interopRequireDefault(_colors); var _timing = require("../styles/timing"); var _timing2 = _interopRequireDefault(_timing); var _color = require("./color"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /** * Adds outline styles * @param {Number} offset Outline offset amount * @return {Object} CSS styles */ function outline() { var offset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 2; return typeof offset === "number" && { outline: "1px lightgray dotted", outlineOffset: offset + "px" }; } /** * Hide only visually, but have available for screen readers * @return {Object} CSS styles */ function visuallyHidden(focusable) { var focusableStyles = { clip: "auto", clipPath: "none", height: "auto", margin: 0, overflow: "visible", position: "static", whiteSpace: "inherit", width: "auto" }; return (0, _extends3.default)({}, { border: 0, clipPath: "inset(50%)", display: "inline-block", height: "1px", margin: "-1px", overflow: "hidden", padding: 0, whiteSpace: "nowrap", width: "1px" }, focusable === "focusable" ? { ":active": focusableStyles, ":focus": focusableStyles } : {}); } /** * Creates a blue hyperlink; for use with inline styles via Radium * @return {Object} CSS styles */ function blueLink() { return { color: _colors2.default.linkPrimary, textDecoration: "none", transition: "color " + _timing2.default.fast + " ease-in-out", ":hover": { color: _colors2.default.linkPrimaryHover }, ":active": { color: _colors2.default.linkPrimaryHover }, ":focus": (0, _extends3.default)({}, outline(), { color: _colors2.default.linkPrimaryHover }) }; } /** * Creates a nicely underlined hyperlink * @param {String} linkColor Link color * @return {Object} CSS styles object */ function underlinedLink() { var linkColor = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _colors2.default.textPrimary; var underlineOffset = 2; var underlineWeight = 1; var backgroundColor = _colors2.default.bgPrimary; var underlineColor = (0, _color.rgba)(linkColor, 0.4); return { color: linkColor, position: "relative", textDecoration: "none", transition: "color " + _timing2.default.fast + " ease", // Draw the underline with a background gradient backgroundImage: "linear-gradient(\n to top,\n transparent,\n transparent " + underlineOffset + "px,\n " + underlineColor + " " + underlineOffset + "px,\n " + underlineColor + " " + (underlineOffset + underlineWeight) + "px,\n transparent " + (underlineOffset + underlineWeight) + "px\n )", // Create breaks in the underline textShadow: "-1px -1px 0 " + backgroundColor + ",\n 1px -1px 0 " + backgroundColor + ",\n -1px 1px 0 " + backgroundColor + ",\n 1px 1px 0 " + backgroundColor }; } exports.outline = outline; exports.visuallyHidden = visuallyHidden; exports.blueLink = blueLink; exports.underlinedLink = underlinedLink;