UNPKG

lucid-ui

Version:

A UI component library from Xandr.

82 lines 3.73 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Underline = void 0; var lodash_1 = __importDefault(require("lodash")); var react_1 = __importDefault(require("react")); var prop_types_1 = __importDefault(require("prop-types")); var text_manipulation_1 = require("../../util/text-manipulation"); var style_helpers_1 = require("../../util/style-helpers"); var cx = style_helpers_1.lucidClassNames.bind('&-Underline'); var node = prop_types_1.default.node, string = prop_types_1.default.string, instanceOf = prop_types_1.default.instanceOf, oneOfType = prop_types_1.default.oneOfType; var matchAllRegexp = /^.*$/; var Underline = function (_a) { var className = _a.className, children = _a.children, match = _a.match, passThroughs = __rest(_a, ["className", "children", "match"]); if (!lodash_1.default.isRegExp(match)) { if (lodash_1.default.isString(match)) { match = new RegExp(lodash_1.default.escapeRegExp(match), 'i'); } else { match = matchAllRegexp; } } if (!lodash_1.default.isString(children)) { return (react_1.default.createElement("span", __assign({ className: cx('&', className) }, passThroughs), react_1.default.createElement("span", { style: match === matchAllRegexp ? { textDecoration: 'underline' } : undefined }, children))); } var _b = (0, text_manipulation_1.partitionText)(children, match), pre = _b[0], matchText = _b[1], post = _b[2]; return (react_1.default.createElement("span", __assign({ className: cx('&', className) }, passThroughs), [ pre && react_1.default.createElement("span", { key: 'pre' }, pre), matchText && (react_1.default.createElement("span", { key: 'match', style: { textDecoration: 'underline' } }, matchText)), post && react_1.default.createElement("span", { key: 'post' }, post), ])); }; exports.Underline = Underline; exports.Underline.displayName = 'Underline'; exports.Underline.peek = { description: "Underlines a portion of text that matches a given pattern.", categories: ['controls', 'selectors'], }; exports.Underline.propTypes = { /** Appended to the component-specific class names set on the root element. */ className: string, /** Text to be partially or fully underlined. If non-text is passed as children, it will not attempt to match the given pattern. */ children: node, /** The first match of the given pattern has the underline style applied to it. */ match: oneOfType([string, instanceOf(RegExp)]), }; exports.default = exports.Underline; //# sourceMappingURL=Underline.js.map