@onesy/ui-react
Version:
UI for React
155 lines (154 loc) • 6.93 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.rtl_icons = 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 _utils = require("../utils");
var _jsxRuntime = require("react/jsx-runtime");
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) { (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 rtl_icons = exports.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 = (0, _styleReact.style)(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_ => {
var _theme$ui, _theme$ui2;
const $ = (0, _compilerRuntime.c)(14);
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.onesyIcon) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.props) === null || _theme$ui2 === void 0 ? void 0 : _theme$ui2.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 = (0, _objectWithoutProperties2.default)(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.default.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.default.useEffect(t6, t7);
const fontSize = (0, _utils.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 {
var _theme$palette$color$;
color = color === "default" ? theme.palette.text.default.primary : ((_theme$palette$color$ = theme.palette.color[color]) === null || _theme$palette$color$ === void 0 ? void 0 : _theme$palette$color$.main) || color;
}
} else {
color = "";
}
const t8 = (0, _styleReact.classNames)([(0, _utils.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__*/(0, _jsxRuntime.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';
var _default = exports.default = Icon;