@onesy/ui-react
Version:
UI for React
147 lines (146 loc) • 6.51 kB
JavaScript
;
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 _Surface = _interopRequireDefault(require("../Surface"));
var _utils = require("../utils");
var _jsxRuntime = require("react/jsx-runtime");
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) { (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: {
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_ => {
var _theme$ui, _theme$ui2, _theme$elements, _element$props;
const $ = (0, _compilerRuntime.c)(8);
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.onesyBadge) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.props) === null || _theme$ui2 === void 0 ? void 0 : _theme$ui2.default), props_);
const Surface = (theme === null || theme === void 0 || (_theme$elements = theme.elements) === null || _theme$elements === void 0 ? void 0 : _theme$elements.Surface) || _Surface.default;
const {
tonal: t0,
color: t1,
size: t2,
value: value_,
max,
vertical: t3,
horizontal: t4,
indicator,
element,
Component: t5,
className,
children
} = props,
other = (0, _objectWithoutProperties2.default)(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 = (0, _styleReact.classNames)([(0, _utils.staticClassName)("Badge", theme) && ["onesy-Badge-badge"], classes.badge, classes[`vertical_${vertical}`], classes[`horizontal_${horizontal}`], classes[`vertical_horizontal_${vertical}_${horizontal}`], indicator && classes.indicator]);
const t7 = (0, _styleReact.classNames)([(0, _utils.staticClassName)("Badge", theme) && ["onesy-Badge-root", `onesy-Badge-size-${size}`], className, classes.root]);
const t8 = useValue && (element ? /*#__PURE__*/_react.default.cloneElement(element, {
className: (0, _styleReact.classNames)([classesBadge, (_element$props = element.props) === null || _element$props === void 0 ? void 0 : _element$props.className])
}) : /*#__PURE__*/(0, _jsxRuntime.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__*/(0, _jsxRuntime.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';
var _default = exports.default = Badge;