UNPKG

lucid-ui

Version:

A UI component library from AppNexus.

77 lines (68 loc) 4.21 kB
import _keys from "lodash/keys"; import _startsWith from "lodash/startsWith"; function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } import React from 'react'; import PropTypes from 'react-peek/prop-types'; import { lucidClassNames } from '../../util/style-helpers'; import { omitProps } from '../../util/component-types'; import * as chartConstants from '../../constants/charts'; var cx = lucidClassNames.bind('&-Bar'); var number = PropTypes.number, bool = PropTypes.bool, string = PropTypes.string, object = PropTypes.object; var defaultProps = { x: 0, y: 0, height: 0, width: 0, color: chartConstants.COLOR_0, hasStroke: false }; export var Bar = function Bar(props) { var className = props.className, color = props.color, hasStroke = props.hasStroke, height = props.height, width = props.width, style = props.style, x = props.x, y = props.y, passThroughs = _objectWithoutProperties(props, ["className", "color", "hasStroke", "height", "width", "style", "x", "y"]); var isCustomColor = _startsWith(color, '#'); var colorStyle = isCustomColor ? { fill: color } : null; return /*#__PURE__*/React.createElement("rect", _extends({}, omitProps(passThroughs, undefined, _keys(Bar.propTypes)), { className: cx(className, '&', _defineProperty({ '&-has-stroke': hasStroke }, "&-".concat(color), !isCustomColor)), x: x, y: y, height: height, width: width, style: _objectSpread(_objectSpread({}, style), colorStyle) })); }; Bar.defaultProps = defaultProps; Bar.displayName = 'Bar'; Bar.peek = { description: "\n\t\t*For use within an `svg`*\n\n\t\tBars are typically used for bar charts and are pretty much a thin\n\t\twrapper around svg rects.\n\t", categories: ['visualizations', 'geoms'] }; Bar.propTypes = { style: object, className: string, x: number, y: number, height: PropTypes.oneOfType([number, string]), width: PropTypes.oneOfType([number, string]), hasStroke: bool, color: string }; export default Bar;