UNPKG

@onesy/ui-react

Version:
211 lines 8.1 kB
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; const _excluded = ["tonal", "color", "version", "elevation", "size", "value", "valueDefault", "onChange", "total", "boundary", "middle", "first", "before", "next", "last", "renderItem", "disableSelected", "disabled", "IconFirst", "IconBefore", "IconNext", "IconLast", "Component", "className", "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 { is, clamp, pagination } from '@onesy/utils'; import { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react'; import IconMaterialLastPage from '@onesy/icons-material-rounded-react/IconMaterialLastPageW100'; import IconMaterialFirstPage from '@onesy/icons-material-rounded-react/IconMaterialFirstPageW100'; import IconMaterialNavigateNext from '@onesy/icons-material-rounded-react/IconMaterialNavigateNextW100'; import IconMaterialNavigateBefore from '@onesy/icons-material-rounded-react/IconMaterialNavigateBeforeW100'; import TypeElement from '../Type'; import LineElement from '../Line'; import IconButtonElement from '../IconButton'; import PaginationItemElement from '../PaginationItem'; import { staticClassName } from '../utils'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const useStyle = styleMethod(theme => ({ root: {}, dots: { display: 'inline-block', textAlign: 'center' }, dots_size_small: { width: '30px' }, dots_size_regular: { width: '40px' }, dots_size_large: { width: '50px' } }), { name: 'onesy-Pagination' }); const Pagination = props_ => { const $ = _c(12); const theme = useOnesyTheme(); const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesyPagination?.props?.default), props_); const Line = theme?.elements?.Line || LineElement; const Type = theme?.elements?.Type || TypeElement; const IconButton = theme?.elements?.IconButton || IconButtonElement; const PaginationItem = theme?.elements?.PaginationItem || PaginationItemElement; const { tonal: t0, color: t1, version: t2, elevation: t3, size: t4, value: t5, valueDefault, onChange: onChange_, total: t6, boundary: t7, middle: t8, first: t9, before: t10, next: t11, last: t12, renderItem: renderItem_, disableSelected: t13, disabled, IconFirst: t14, IconBefore: t15, IconNext: t16, IconLast: t17, Component: t18, className, children } = props, other = _objectWithoutProperties(props, _excluded); const tonal = t0 === undefined ? false : t0; const color = t1 === undefined ? "default" : t1; const version = t2 === undefined ? "text" : t2; const elevation = t3 === undefined ? false : t3; const size = t4 === undefined ? "regular" : t4; const value_ = t5 === undefined ? 1 : t5; const total = t6 === undefined ? 1 : t6; const boundary = t7 === undefined ? 1 : t7; const middle = t8 === undefined ? 1 : t8; const first = t9 === undefined ? false : t9; const before = t10 === undefined ? true : t10; const next = t11 === undefined ? true : t11; const last = t12 === undefined ? false : t12; const disableSelected = t13 === undefined ? true : t13; const IconFirst = t14 === undefined ? IconMaterialFirstPage : t14; const IconBefore = t15 === undefined ? IconMaterialNavigateBefore : t15; const IconNext = t16 === undefined ? IconMaterialNavigateNext : t16; const IconLast = t17 === undefined ? IconMaterialLastPage : t17; const Component = t18 === undefined ? "div" : t18; const [value, setValue] = React.useState(valueDefault !== undefined ? valueDefault : value_); const { classes } = useStyle(); let t19; if ($[0] !== value_) { t19 = [value_]; $[0] = value_; $[1] = t19; } else { t19 = $[1]; } React.useEffect(() => { if (value_ !== value) { setValue(value_); } }, t19); const onChange = value__ => { if (!props.hasOwnProperty("value")) { setValue(value__); } if (is("function", onChange_)) { onChange_(value__); } }; const values = pagination(value, total, boundary, middle); const renderItem = is("function", renderItem_) ? renderItem_ : (value___0, item) => { if (is("string", item)) { return /*#__PURE__*/_jsx(Type, { version: props.size === "large" ? "b1" : props.size === "small" ? "b3" : "b2", className: classNames([staticClassName("Pagination", theme) && ["onesy-Pagination-dots"], classes.dots, classes[`dots_size_${size}`]]), children: item }); } return /*#__PURE__*/_jsx(PaginationItem, { tonal: tonal, color: color, version: version, elevation: elevation, size: size, onClick: () => onChange(item), selected: value___0 === item, disabled: disabled || value___0 === item && disableSelected, children: item }); }; const IconButtonProps = { tonal, color, version, elevation, size }; const t20 = 0.5; const t21 = "wrap"; const t22 = "row"; const t23 = "flex-start"; const t24 = "center"; const t25 = classNames([staticClassName("Pagination", theme) && ["onesy-Pagination-root", `onesy-Pagination-version-${version}`, `onesy-Pagination-size-${size}`], className, classes.root]); const t26 = first && /*#__PURE__*/_jsx(IconButton, _objectSpread(_objectSpread({ onClick: () => onChange(1), disabled: value === 1 }, IconButtonProps), {}, { children: /*#__PURE__*/_jsx(IconFirst, {}) })); const t27 = before && /*#__PURE__*/_jsx(IconButton, _objectSpread(_objectSpread({ onClick: () => onChange(clamp(value - 1, 1, total)), disabled: value === 1 }, IconButtonProps), {}, { children: /*#__PURE__*/_jsx(IconBefore, {}) })); const t28 = values.map((item_0, index) => renderItem(value, item_0, index)).map(_temp); const t29 = next && /*#__PURE__*/_jsx(IconButton, _objectSpread(_objectSpread({ onClick: () => onChange(clamp(value + 1, 1, total)), disabled: value === total }, IconButtonProps), {}, { children: /*#__PURE__*/_jsx(IconNext, {}) })); const t30 = last && /*#__PURE__*/_jsx(IconButton, _objectSpread(_objectSpread({ onClick: () => onChange(total), disabled: value === total }, IconButtonProps), {}, { children: /*#__PURE__*/_jsx(IconLast, {}) })); let t31; if ($[2] !== Component || $[3] !== Line || $[4] !== other || $[5] !== t25 || $[6] !== t26 || $[7] !== t27 || $[8] !== t28 || $[9] !== t29 || $[10] !== t30) { t31 = /*#__PURE__*/_jsxs(Line, _objectSpread(_objectSpread({ gap: t20, wrap: t21, direction: t22, justify: t23, align: t24, Component: Component, className: t25 }, other), {}, { children: [t26, t27, t28, t29, t30] })); $[2] = Component; $[3] = Line; $[4] = other; $[5] = t25; $[6] = t26; $[7] = t27; $[8] = t28; $[9] = t29; $[10] = t30; $[11] = t31; } else { t31 = $[11]; } return t31; }; Pagination.displayName = 'onesy-Pagination'; export default Pagination; function _temp(item_1, index_0) { return /*#__PURE__*/React.cloneElement(item_1, { key: index_0 }); }