UNPKG

@onesy/ui-react

Version:
158 lines 5.62 kB
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; const _excluded = ["size", "gap", "align", "justify", "direction", "wrap", "total", "max", "showAllDefault", "moreShowAll", "AdditionalChip", "AdditionalChipProps", "Component", "className", "style", "children"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import { c as _c } from "react/compiler-runtime"; import React from 'react'; import { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react'; import LineElement from '../Line'; import ChipElement from '../Chip/Chip'; import { staticClassName } from '../utils'; import { jsx as _jsx } from "react/jsx-runtime"; const useStyle = styleMethod(theme => ({ root: { width: '100%', padding: '1px', '&:not($wrap)': { overflowX: 'auto', '&$small': { paddingRight: theme.methods.space.value(0.75, 'px') }, '&$regular': { paddingRight: theme.methods.space.value(1, 'px') }, '&$large': { paddingRight: theme.methods.space.value(1.25, 'px') } } }, size_small: { // columnGap: '6px' }, size_regular: { // columnGap: '8px' }, size_large: { // columnGap: '10px' }, wrap: { flexWrap: 'wrap' }, wrap_small: { // rowGap: '12px' }, wrap_regular: { // rowGap: '16px' }, wrap_large: { // rowGap: '20px' } }), { name: 'onesy-Chips' }); const Chips = props_ => { const $ = _c(12); const theme = useOnesyTheme(); const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesyChips?.props?.default), props_); const Line = theme?.elements?.Line || LineElement; const Chip = theme?.elements?.Chip || ChipElement; const { size: t0, gap: t1, align: t2, justify: t3, direction: t4, wrap, total, max, showAllDefault, moreShowAll: t5, AdditionalChip, AdditionalChipProps: t6, Component: t7, className, style, children: children_ } = props, other = _objectWithoutProperties(props, _excluded); const size = t0 === undefined ? "regular" : t0; const gap = t1 === undefined ? 1 : t1; const align = t2 === undefined ? "flex-start" : t2; const justify = t3 === undefined ? "flex-start" : t3; const direction = t4 === undefined ? "row" : t4; const moreShowAll = t5 === undefined ? true : t5; const AdditionalChipProps = t6 === undefined ? {} : t6; const Component = t7 === undefined ? "div" : t7; const { classes } = useStyle(); const [showAll, setShowAll] = React.useState(showAllDefault !== undefined ? showAllDefault : false); let t8; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { t8 = () => { setShowAll(true); }; $[0] = t8; } else { t8 = $[0]; } const onClickMore = t8; let children = React.Children.toArray(children_); if (!showAll) { children = children.slice(0, max || children.length); if (total !== undefined && total - children.length >= 1 || max < children.length) { let value; if (total !== undefined && total - children.length >= 1) { value = `+${total - children.length}`; } else { value = `+${Math.abs(children.length - max)}`; } if (!AdditionalChipProps.TypeProps) { AdditionalChipProps.TypeProps = {}; } AdditionalChipProps.TypeProps.size = "0.44em"; children.push(AdditionalChip || /*#__PURE__*/_jsx(Chip, _objectSpread(_objectSpread(_objectSpread({ color: "default" }, other), AdditionalChipProps), {}, { onClick: moreShowAll ? onClickMore : undefined, children: value }))); } } const t9 = classNames([staticClassName("Chips", theme) && ["onesy-Chips-root", `onesy-Chips-size-${size}`], className, classes.root, classes[`size_${size}`], wrap === "wrap" && [classes.wrap, classes[`wrap_${size}`]]]); const t10 = React.Children.toArray(children).map((item, index) => /*#__PURE__*/React.cloneElement(item, _objectSpread(_objectSpread({ key: index, size }, other), item.props))); let t11; if ($[1] !== Component || $[2] !== Line || $[3] !== align || $[4] !== direction || $[5] !== gap || $[6] !== justify || $[7] !== style || $[8] !== t10 || $[9] !== t9 || $[10] !== wrap) { t11 = /*#__PURE__*/_jsx(Line, { gap: gap, justify: justify, align: align, direction: direction, wrap: wrap, Component: Component, className: t9, style: style, children: t10 }); $[1] = Component; $[2] = Line; $[3] = align; $[4] = direction; $[5] = gap; $[6] = justify; $[7] = style; $[8] = t10; $[9] = t9; $[10] = wrap; $[11] = t11; } else { t11 = $[11]; } return t11; }; Chips.displayName = 'onesy-Chips'; export default Chips;