UNPKG

@onesy/ui-react

Version:
139 lines 5.21 kB
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; const _excluded = ["tonal", "color", "size", "value", "max", "vertical", "horizontal", "indicator", "element", "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 { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react'; import SurfaceElement from '../Surface'; import { staticClassName } from '../utils'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const useStyle = styleMethod(theme => ({ root: { display: 'inline-flex', position: 'relative' }, badge: _objectSpread(_objectSpread({ position: 'absolute', padding: `${theme.methods.space.value(0.25, 'px')} ${theme.methods.space.value(0.75, 'px')}`, lineHeight: '1px', borderRadius: theme.methods.shape.radius.value(40, 'px'), transition: theme.methods.transitions.make('transform'), pointerEvents: 'none', userSelect: 'none' }, theme.typography.values.l3), {}, { fontSize: `${10 / 16}rem` }), // Vertical & horizontal horizontal_left: { insetInlineStart: '0px' }, horizontal_right: { insetInlineEnd: '0px' }, vertical_top: { top: '0px' }, vertical_horizontal_top_right: { transform: `translate(${theme.direction === 'rtl' ? '-' : ''}50%, -50%)` }, vertical_horizontal_top_left: { transform: `translate(${theme.direction === 'rtl' ? '' : '-'}50%, -50%)` }, vertical_bottom: { bottom: '0px' }, vertical_horizontal_bottom_right: { transform: `translate(${theme.direction === 'rtl' ? '-' : ''}50%, 50%)` }, vertical_horizontal_bottom_left: { transform: `translate(${theme.direction === 'rtl' ? '' : '-'}50%, 50%)` }, indicator: { height: '8px', width: '8px', padding: '0', borderRadius: `${theme.shape.radius.unit * 0.5}px` } }), { name: 'onesy-Badge' }); const Badge = props_ => { const $ = _c(8); const theme = useOnesyTheme(); const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesyBadge?.props?.default), props_); const Surface = theme?.elements?.Surface || SurfaceElement; const { tonal: t0, color: t1, size: t2, value: value_, max, vertical: t3, horizontal: t4, indicator, element, Component: t5, className, children } = props, other = _objectWithoutProperties(props, _excluded); const tonal = t0 === undefined ? false : t0; const color = t1 === undefined ? "primary" : t1; const size = t2 === undefined ? "regular" : t2; const vertical = t3 === undefined ? "top" : t3; const horizontal = t4 === undefined ? "right" : t4; const Component = t5 === undefined ? "span" : t5; const { classes } = useStyle(); let t6; if ($[0] === Symbol.for("react.memo_cache_sentinel")) { t6 = { badge: {} }; $[0] = t6; } else { t6 = $[0]; } const styles = t6; let value = value_; if (max !== undefined && value > max) { value = `${max}+`; } const useValue = value !== undefined || indicator || element; const classesBadge = classNames([staticClassName("Badge", theme) && ["onesy-Badge-badge"], classes.badge, classes[`vertical_${vertical}`], classes[`horizontal_${horizontal}`], classes[`vertical_horizontal_${vertical}_${horizontal}`], indicator && classes.indicator]); const t7 = classNames([staticClassName("Badge", theme) && ["onesy-Badge-root", `onesy-Badge-size-${size}`], className, classes.root]); const t8 = useValue && (element ? /*#__PURE__*/React.cloneElement(element, { className: classNames([classesBadge, element.props?.className]) }) : /*#__PURE__*/_jsx(Surface, { tonal: tonal, color: color, Component: "span", className: classesBadge, style: styles.badge, children: value })); let t9; if ($[1] !== Component || $[2] !== children || $[3] !== other || $[4] !== size || $[5] !== t7 || $[6] !== t8) { t9 = /*#__PURE__*/_jsxs(Component, _objectSpread(_objectSpread({ size: size, className: t7 }, other), {}, { children: [children, t8] })); $[1] = Component; $[2] = children; $[3] = other; $[4] = size; $[5] = t7; $[6] = t8; $[7] = t9; } else { t9 = $[7]; } return t9; }; Badge.displayName = 'onesy-Badge'; export default Badge;