UNPKG

@coko/client

Version:

Client side common code for coko apps

60 lines (59 loc) 4.15 kB
"use strict"; function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _react = _interopRequireDefault(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _styledComponents = _interopRequireWildcard(require("styled-components")); var _toolkit = require("../../toolkit"); var _templateObject, _templateObject2; function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } var Wrapper = _styledComponents["default"].div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: ", ";\n /* display: inline-block; */\n\n ", "\n\n > button {\n margin-right: ", ";\n }\n\n > button:first-child {\n margin-left: 0;\n }\n\n > button:last-child {\n margin-right: 0;\n }\n"])), function (props) { return props.inline ? 'inline-block' : 'flex'; }, function (props) { var inline = props.inline, justify = props.justify; var justifyValue; if (inline) return null; if (justify === 'left') justifyValue = 'flex-start'; if (justify === 'right') justifyValue = 'flex-end'; if (justify === 'center') justifyValue = 'center'; if (justifyValue) return (0, _styledComponents.css)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n justify-content: ", ";\n "])), justifyValue); return null; }, (0, _toolkit.grid)(1)); var ButtonGroup = function ButtonGroup(props) { var className = props.className, children = props.children, inline = props.inline, justify = props.justify; return /*#__PURE__*/_react["default"].createElement(Wrapper, { className: className, inline: inline, justify: justify }, children); }; ButtonGroup.propTypes = { /** Must be multiple Button components */ children: _propTypes["default"].arrayOf(function (propValue, key, componentName, location, propFullName) { var notButton = propValue.find(function (el) { return el.type.name !== 'Button'; }); if (notButton) return new Error('ButtonGroup children should be instances of Button!'); return null; }).isRequired, /** Sets display to `inline-block` */ inline: _propTypes["default"].bool, /** Sets position of buttons in the row. Only applies when `inline` is `false` */ justify: _propTypes["default"].oneOf(['left', 'right', 'center']) }; ButtonGroup.defaultProps = { inline: false, justify: 'left' }; var _default = ButtonGroup; exports["default"] = _default;