UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

71 lines 5.41 kB
"use strict"; 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.AxisLabel = 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 style_helpers_1 = require("../../util/style-helpers"); var component_types_1 = require("../../util/component-types"); var cx = style_helpers_1.lucidClassNames.bind('&-AxisLabel'); var number = prop_types_1.default.number, string = prop_types_1.default.string, oneOf = prop_types_1.default.oneOf, object = prop_types_1.default.object; var defaultProps = { color: '#000', }; var AxisLabel = function (props) { var _a; var height = props.height, width = props.width, orient = props.orient, label = props.label, color = props.color, style = props.style, className = props.className, passThroughs = __rest(props, ["height", "width", "orient", "label", "color", "style", "className"]); var isH = orient === 'top' || orient === 'bottom'; var isCustomColor = lodash_1.default.startsWith(color, '#'); var colorStyle = isCustomColor ? { fill: color } : null; return (react_1.default.createElement("text", __assign({}, component_types_1.omitProps(passThroughs, undefined, lodash_1.default.keys(exports.AxisLabel.propTypes)), { style: __assign(__assign({}, colorStyle), style), className: cx(className, '&', (_a = {}, _a["&-" + color] = !isCustomColor, _a)), x: isH ? width / 2 : (height / 2) * -1, y: orient === 'right' ? width : orient === 'bottom' ? height : 0, dy: orient === 'top' || orient === 'left' ? '1em' : '-.32em', transform: isH ? '' : 'rotate(-90)' }), label)); }; exports.AxisLabel = AxisLabel; exports.AxisLabel.defaultProps = defaultProps; exports.AxisLabel.displayName = 'AxisLabel'; exports.AxisLabel.peek = { description: "\n\t\t`AxisLabel` is used within a `svg`\n\n\t\tCentered labels for axes that typically are fit into the margins of a\n\t\tchart.\n\t", categories: ['visualizations', 'chart primitives'], }; exports.AxisLabel.propTypes = { style: object(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n\t\tPassed through to the root element.\n\t"], ["\n\t\tPassed through to the root element.\n\t"]))), className: string(templateObject_2 || (templateObject_2 = __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"]))), height: number.isRequired(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n\t\tHeight of the margin this label should fit into.\n\t"], ["\n\t\tHeight of the margin this label should fit into.\n\t"]))), width: number.isRequired(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n\t\tWidth of the margin this label should fit into.\n\t"], ["\n\t\tWidth of the margin this label should fit into.\n\t"]))), color: string(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n\t\tStrings should match an existing color class unless they start with a '#'\n\t\tfor specific colors. E.g.:\n\n\t\t- `COLOR_0`\n\t\t- `COLOR_GOOD`\n\t\t- `'#123abc'`\n\t"], ["\n\t\tStrings should match an existing color class unless they start with a '#'\n\t\tfor specific colors. E.g.:\n\n\t\t- \\`COLOR_0\\`\n\t\t- \\`COLOR_GOOD\\`\n\t\t- \\`'#123abc'\\`\n\t"]))), label: string(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n\t\tContents of the label, should only ever be a string since we use a\n\t\t`text` under the hood.\n\t"], ["\n\t\tContents of the label, should only ever be a string since we use a\n\t\t\\`text\\` under the hood.\n\t"]))), orient: oneOf(['top', 'bottom', 'left', 'right'])(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n\t\tDetermine orientation of the label.\n\t"], ["\n\t\tDetermine orientation of the label.\n\t"]))), }; exports.default = exports.AxisLabel; var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7; //# sourceMappingURL=AxisLabel.js.map