lucid-ui
Version:
A UI component library from AppNexus.
78 lines • 4.77 kB
JavaScript
;
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
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("react-peek/prop-types"));
var text_manipulation_1 = require("../../util/text-manipulation");
var style_helpers_1 = require("../../util/style-helpers");
var component_types_1 = require("../../util/component-types");
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) }, component_types_1.omitProps(passThroughs, undefined, lodash_1.default.keys(exports.Underline.propTypes))),
react_1.default.createElement("span", { style: match === matchAllRegexp
? { textDecoration: 'underline' }
: undefined }, children)));
}
var _b = 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) }, component_types_1.omitProps(passThroughs, undefined, lodash_1.default.keys(exports.Underline.propTypes))), [
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: "\n\t\tUnderlines a portion of text that matches a given pattern\n\t",
categories: ['controls', 'selectors'],
};
exports.Underline.propTypes = {
className: string(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\t\tAppended to the component-specific class names set on the root element.\n\t"], ["\n\t\tAppended to the component-specific class names set on the root element.\n\t"]))),
children: node(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n\t\tText to be partially or fully underlined. If non-text is passed as\n\t\tchildren, it will not attempt to match the given pattern.\n\t"], ["\n\t\tText to be partially or fully underlined. If non-text is passed as\n\t\tchildren, it will not attempt to match the given pattern.\n\t"]))),
match: oneOfType([string, instanceOf(RegExp)])(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n\t\tThe first match of the given pattern has the underline style applied to it.\n\t"], ["\n\t\tThe first match of the given pattern has the underline style applied to it.\n\t"]))),
};
exports.default = exports.Underline;
var templateObject_1, templateObject_2, templateObject_3;
//# sourceMappingURL=Underline.js.map