UNPKG

lucid-ui

Version:

A UI component library from Xandr.

92 lines (91 loc) 3.88 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.AxisLabel = void 0; var lodash_1 = __importDefault(require("lodash")); var react_1 = __importDefault(require("react")); var prop_types_1 = __importDefault(require("prop-types")); var style_helpers_1 = require("../../util/style-helpers"); 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({}, passThroughs, { style: __assign(__assign({}, colorStyle), style), className: cx(className, '&', (_a = {}, _a["&-".concat(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: "`AxisLabel` is used within a `svg`. Centered labels for axes that typically are fit into the margins of a chart.", categories: ['visualizations', 'chart primitives'], }; exports.AxisLabel.propTypes = { /** Passed through to the root element. */ style: object, /** Appended to the component-specific class names set on the root element. */ className: string, /** Height of the margin this label should fit into. */ height: number.isRequired, /** Width of the margin this label should fit into. */ width: number.isRequired, /** Strings should match an existing color class unless they start with a '#' for specific colors. E.g.: - \`COLOR_0\` - \`COLOR_GOOD\` - \`'#123abc'\` */ color: string, /** Contents of the label, should only ever be a string since we use a \`text\` under the hood. */ label: string, /** Determine orientation of the label. */ orient: oneOf(['top', 'bottom', 'left', 'right']), }; exports.default = exports.AxisLabel; //# sourceMappingURL=AxisLabel.js.map