@onesy/ui-react
Version:
UI for React
146 lines • 5.77 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
const _excluded = ["viewBox", "name", "short_name", "tonal", "tone", "color", "size", "noRtl", "disabled", "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 { iconSizeToFontSize, staticClassName } from '../utils';
import { jsx as _jsx } from "react/jsx-runtime";
export const rtl_icons = ['ArrowForwardIos', 'ArrowBackIos', 'ArrowBack', 'ArrowForward', 'ArrowLeft', 'ArrowRight', 'AssignmentReturn', 'CallMade', 'CallMissedOutgoing', 'ChevronLeft', 'ChevronRight', 'DeviceUnknown', 'FeaturedPlayList', 'FlightLand', 'FormatIndentIncrease', 'Functions', 'Input', 'Label', 'LastPage', 'LiveHelp', 'NavigateBefore', 'Note', 'QueueMusic', 'ReplyAll', 'ShortText', 'StarHalf', 'Toc', 'Undo', 'WrapText', 'FirstPage', 'LastPage', 'NavigateNext', 'NavigateBefore'];
const useStyle = styleMethod(theme => ({
root: {
userSelect: 'none',
display: 'inline-flex',
flexShrink: '0',
color: 'inherit',
fill: 'currentColor',
pointerEvents: 'none',
// Make width and height in em unit
// means it will scale based on parent's font-size
// so entire svg will scale based on font-size only
width: '1em',
height: '1em',
transition: theme.methods.transitions.make(['fill', 'transform', 'filter'], {
duration: 'sm',
timing_function: 'standard'
})
},
rtl: {
transform: 'scaleX(-1)',
filter: 'FlipH'
},
disabled: {
opacity: theme.palette.visual_contrast.default.opacity.disabled
}
}), {
name: 'onesy-Icon'
});
const Icon = props_ => {
const $ = _c(14);
const theme = useOnesyTheme();
const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesyIcon?.props?.default), props_);
const {
viewBox: t0,
name,
short_name,
tonal: t1,
tone: t2,
color: t3,
size: t4,
noRtl,
disabled,
Component: t5,
className,
style,
children
} = props,
other = _objectWithoutProperties(props, _excluded);
const viewBox = t0 === undefined ? "0 0 24 24" : t0;
const tonal = t1 === undefined ? true : t1;
const tone = t2 === undefined ? 60 : t2;
const color_ = t3 === undefined ? "inherit" : t3;
const size = t4 === undefined ? "regular" : t4;
const Component = t5 === undefined ? "svg" : t5;
const [rtl, setRtl] = React.useState(theme.direction === "rtl");
const {
classes
} = useStyle();
let t6;
if ($[0] !== theme.subscriptions) {
t6 = () => {
const method = (update, themeNew) => setRtl(themeNew.direction === "rtl");
theme.subscriptions.update.subscribe(method);
return () => {
theme.subscriptions.update.unsubscribe(method);
};
};
$[0] = theme.subscriptions;
$[1] = t6;
} else {
t6 = $[1];
}
let t7;
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
t7 = [];
$[2] = t7;
} else {
t7 = $[2];
}
React.useEffect(t6, t7);
const fontSize = iconSizeToFontSize(size);
const isRtlIcon = rtl_icons.includes(short_name);
let color = color_;
if (!["unset"].includes(color)) {
if (tonal) {
const palette = color === "default" ? theme.palette.color.neutral : !theme.palette.color[color] ? theme.methods.color(color) : theme.palette.color[color];
color = theme.methods.palette.color.value(color, tone, true, palette);
} else {
color = color === "default" ? theme.palette.text.default.primary : theme.palette.color[color]?.main || color;
}
} else {
color = "";
}
const t8 = classNames([staticClassName("Icon", theme) && ["onesy-Icon-root", `onesy-Icon-size-${size}`, !noRtl && rtl && isRtlIcon ? "onesy-Icon-direction-rtl" : "onesy-Icon-direction-ltr", disabled && "onesy-Icon-disabled"], className, classes.root, !noRtl && rtl && isRtlIcon && classes.rtl, disabled && classes.disabled]);
let t9;
if ($[3] !== color || $[4] !== fontSize || $[5] !== style) {
t9 = _objectSpread({
fill: "currentcolor",
color,
fontSize
}, style);
$[3] = color;
$[4] = fontSize;
$[5] = style;
$[6] = t9;
} else {
t9 = $[6];
}
let t10;
if ($[7] !== Component || $[8] !== children || $[9] !== other || $[10] !== t8 || $[11] !== t9 || $[12] !== viewBox) {
t10 = /*#__PURE__*/_jsx(Component, _objectSpread(_objectSpread({
className: t8,
viewBox: viewBox,
width: "1em",
height: "1em",
focusable: "false",
"aria-hidden": true,
style: t9
}, other), {}, {
children: children
}));
$[7] = Component;
$[8] = children;
$[9] = other;
$[10] = t8;
$[11] = t9;
$[12] = viewBox;
$[13] = t10;
} else {
t10 = $[13];
}
return t10;
};
Icon.displayName = 'onesy-Icon';
export default Icon;