@onesy/ui-react
Version:
UI for React
166 lines (165 loc) • 6.98 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _compilerRuntime = require("react/compiler-runtime");
var _react = _interopRequireDefault(require("react"));
var _styleReact = require("@onesy/style-react");
var _Line = _interopRequireDefault(require("../Line"));
var _Chip = _interopRequireDefault(require("../Chip/Chip"));
var _utils = require("../utils");
var _jsxRuntime = require("react/jsx-runtime");
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) { (0, _defineProperty2.default)(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; }
const useStyle = (0, _styleReact.style)(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_ => {
var _theme$ui, _theme$ui2, _theme$elements, _theme$elements2;
const $ = (0, _compilerRuntime.c)(12);
const theme = (0, _styleReact.useOnesyTheme)();
const props = _objectSpread(_objectSpread(_objectSpread({}, theme === null || theme === void 0 || (_theme$ui = theme.ui) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.elements) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.all) === null || _theme$ui === void 0 || (_theme$ui = _theme$ui.props) === null || _theme$ui === void 0 ? void 0 : _theme$ui.default), theme === null || theme === void 0 || (_theme$ui2 = theme.ui) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.elements) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.onesyChips) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.props) === null || _theme$ui2 === void 0 ? void 0 : _theme$ui2.default), props_);
const Line = (theme === null || theme === void 0 || (_theme$elements = theme.elements) === null || _theme$elements === void 0 ? void 0 : _theme$elements.Line) || _Line.default;
const Chip = (theme === null || theme === void 0 || (_theme$elements2 = theme.elements) === null || _theme$elements2 === void 0 ? void 0 : _theme$elements2.Chip) || _Chip.default;
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 = (0, _objectWithoutProperties2.default)(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.default.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.default.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__*/(0, _jsxRuntime.jsx)(Chip, _objectSpread(_objectSpread(_objectSpread({
color: "default"
}, other), AdditionalChipProps), {}, {
onClick: moreShowAll ? onClickMore : undefined,
children: value
})));
}
}
const t9 = (0, _styleReact.classNames)([(0, _utils.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.default.Children.toArray(children).map((item, index) => /*#__PURE__*/_react.default.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__*/(0, _jsxRuntime.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';
var _default = exports.default = Chips;