UNPKG

lucid-ui

Version:

A UI component library from Xandr.

150 lines (149 loc) 6.32 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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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.Point = exports.Kind = 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 chart_helpers_1 = require("../../util/chart-helpers"); var chartConstants = __importStar(require("../../constants/charts")); var cx = style_helpers_1.lucidClassNames.bind('&-Point'); var number = prop_types_1.default.number, bool = prop_types_1.default.bool, string = prop_types_1.default.string, object = prop_types_1.default.object; // These were originally built in a 12x12 grid, except triangles which were // 14x12 cause triangles are poo. var PATHS = [ 'M6,12 C2.686,12 0,9.314 0,6 C0,2.686 2.686,0 6,0 C9.314,-0 12,2.686 12,6 C12,9.314 9.314,12 6,12 z', 'M6,12 C0,12 0,12 0,6 C0,0 -0,0 6,0 C12,0 12,0 12,6 C12,12 12,12 6,12 z', 'M6.034,1.656 C7,0 7,0 7.966,1.656 L13.034,10.344 C14,12 13,12 12,12 L2,12 C1,12 0,12 0.966,10.344 L6.034,1.656 z', 'M7.966,10.344 C7,12 7,12 6.034,10.344 L0.966,1.656 C-0,0 1,0 2,0 L12,0 C13,0 14,0 13.034,1.656 L7.966,10.344 z', 'M2.594,9.406 C-0.812,6 -0.812,6 2.594,2.594 C6,-0.812 6,-0.812 9.406,2.594 C12.812,6 12.812,6 9.406,9.406 C6,12.812 6,12.812 2.594,9.406 z', ]; var Kind; (function (Kind) { Kind[Kind["Circle"] = 0] = "Circle"; Kind[Kind["Square"] = 1] = "Square"; Kind[Kind["TriangleUp"] = 2] = "TriangleUp"; Kind[Kind["TriangleDown"] = 3] = "TriangleDown"; Kind[Kind["Diamond"] = 4] = "Diamond"; })(Kind = exports.Kind || (exports.Kind = {})); var defaultProps = { x: 0, y: 0, kind: 0, color: chartConstants.COLOR_0, hasStroke: false, scale: 1, }; var Point = function (props) { var _a; var color = props.color, hasStroke = props.hasStroke, kind = props.kind, x = props.x, y = props.y, scale = props.scale, className = props.className, style = props.style, passThroughs = __rest(props, ["color", "hasStroke", "kind", "x", "y", "scale", "className", "style"]); var kindIndex = kind % 5; var isCustomColor = lodash_1.default.startsWith(color, '#'); var colorStyle = isCustomColor ? { fill: color } : null; // These transforms are used to center the icon on the x y coordinate // provided. var transforms = [ (0, chart_helpers_1.transformFromCenter)(x, y, 6, 6, scale), (0, chart_helpers_1.transformFromCenter)(x, y, 6, 6, scale), (0, chart_helpers_1.transformFromCenter)(x, y, 7, 6, scale), (0, chart_helpers_1.transformFromCenter)(x, y, 7, 6, scale), (0, chart_helpers_1.transformFromCenter)(x, y, 6, 6, scale), ]; return (react_1.default.createElement("path", __assign({}, passThroughs, { style: __assign(__assign({}, style), colorStyle), className: cx(className, '&', (_a = { '&-has-stroke': hasStroke }, _a["&-".concat(color)] = !isCustomColor, _a)), transform: transforms[kindIndex], d: PATHS[kindIndex] }))); }; exports.Point = Point; exports.Point.defaultProps = defaultProps; exports.Point.displayName = 'Point'; exports.Point.peek = { description: "*For use within an `svg`*. A `Point` is typically used for scatter plots or overlaying shapes on lines.", categories: ['visualizations', 'geoms'], }; exports.Point.propTypes = { /** Passed through to the root element. */ style: object, /** Appended to the component-specific class names set on the root element. */ className: string, /** Determines if the point has a white stroke around it. */ hasStroke: bool, /** x coordinate */ x: number, /** y coordinate */ y: number, /** Zero-based set of shapes. It's recommended that you pass the index of your array for shapes. */ kind: number, /** Strings should match an existing color class unless they start with a '#' for specific colors. E.g.: - \`COLOR_0\` - \`COLOR_GOOD\` - \`'#123abc'\` */ color: string, /** Scale up the size of the symbol. 2 would be double the original size. */ scale: number, }; exports.default = exports.Point; //# sourceMappingURL=Point.js.map