@onesy/ui-react
Version:
UI for React
164 lines (163 loc) • 7.5 kB
JavaScript
"use strict";
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 _utils = require("@onesy/utils");
var _styleReact = require("@onesy/style-react");
var _Line = _interopRequireDefault(require("../Line"));
var _Surface = _interopRequireDefault(require("../Surface"));
var _utils2 = require("../utils");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["color", "tonal", "version", "value", "valueDefault", "onChange", "fixed", "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 useStyle = (0, _styleReact.style)(theme => ({
root: {
zIndex: theme.z_index.app_bar,
width: '100%',
padding: '0'
},
fixed: {
position: 'fixed',
insetInline: '0',
bottom: '0'
}
}), {
name: 'onesy-NavigationBar'
});
const NavigationBar = props_ => {
var _theme$ui, _theme$ui2, _theme$elements, _theme$elements2;
const $ = (0, _compilerRuntime.c)(4);
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.onesyNavigationBar) === null || _theme$ui2 === void 0 || (_theme$ui2 = _theme$ui2.props) === null || _theme$ui2 === void 0 ? void 0 : _theme$ui2.default), props_);
const Line = (theme === null || theme === void 0 || (_theme$elements = theme.elements) === null || _theme$elements === void 0 ? void 0 : _theme$elements.Line) || _Line.default;
const Surface = (theme === null || theme === void 0 || (_theme$elements2 = theme.elements) === null || _theme$elements2 === void 0 ? void 0 : _theme$elements2.Surface) || _Surface.default;
const {
color: t0,
tonal: t1,
version: t2,
value,
valueDefault,
onChange,
fixed,
className,
style,
children: children_
} = props,
other = (0, _objectWithoutProperties2.default)(props, _excluded);
const color = t0 === undefined ? "primary" : t0;
const tonal = t1 === undefined ? true : t1;
const version = t2 === undefined ? "regular" : t2;
const {
classes
} = useStyle();
const [init, setInit] = _react.default.useState(false);
const [selected, setSelected] = _react.default.useState(() => {
const valueNew = valueDefault !== undefined ? valueDefault : value;
return valueNew !== undefined ? (0, _utils.is)("array", valueNew) ? valueNew : [valueNew] : [];
});
const styles = {
root: {},
icon: {}
};
let t3;
let t4;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t3 = () => {
setInit(true);
};
t4 = [];
$[0] = t3;
$[1] = t4;
} else {
t3 = $[0];
t4 = $[1];
}
_react.default.useEffect(t3, t4);
let t5;
if ($[2] !== value) {
t5 = [value];
$[2] = value;
$[3] = t5;
} else {
t5 = $[3];
}
_react.default.useEffect(() => {
if (init && value !== selected) {
setSelected((0, _utils.is)("array", value) ? value : [value]);
}
}, t5);
const onSelect = itemProps => {
const valueNew_0 = [itemProps.value];
if (valueNew_0 !== undefined) {
if (!props.hasOwnProperty("value")) {
setSelected(valueNew_0);
}
if ((0, _utils.is)("function", onChange)) {
onChange(valueNew_0);
}
}
};
let palette;
if (!theme.palette.color[color] && !["themed", "inverted", "default", "inherit"].includes(color)) {
palette = theme.methods.color(color);
}
if (!theme.palette.color[color] && !["themed", "inverted", "default", "inherit"].includes(color)) {
if (tonal) {
styles.root.backgroundColor = theme.methods.palette.color.value(undefined, 95, true, palette);
} else {
styles.root.backgroundColor = palette.main;
}
}
if (!tonal) {
var _theme$palette$color$, _palette;
let background = (_theme$palette$color$ = theme.palette.color[color]) === null || _theme$palette$color$ === void 0 ? void 0 : _theme$palette$color$.main;
if (color === "default") {
background = theme.palette.background.default.primary;
}
styles.icon.color = theme.methods.palette.color.text(((_palette = palette) === null || _palette === void 0 ? void 0 : _palette.main) || background, true, "light");
} else {
styles.icon.color = theme.methods.palette.color.value(color, 5, true, palette);
}
const children = _react.default.Children.toArray(children_).map((item, index) => {
var _item$type, _item$type2;
return /*#__PURE__*/_react.default.cloneElement(item, _objectSpread(_objectSpread({
key: index
}, ["onesy-NavigationItem"].includes((_item$type = item.type) === null || _item$type === void 0 ? void 0 : _item$type.displayName) ? _objectSpread(_objectSpread({}, other), {}, {
version
}) : {}), {}, {
color: item.props.color !== undefined ? item.props.color : ["onesy-NavigationItem"].includes((_item$type2 = item.type) === null || _item$type2 === void 0 ? void 0 : _item$type2.displayName) ? color : styles.icon.color,
tonal: item.props.tonal !== undefined ? item.props.tonal : tonal,
selected: selected.includes(item.props.value),
onClick: () => {
if (!item.props.disabled) {
onSelect(item.props);
if ((0, _utils.is)("function", item.props.onClick)) {
item.props.onClick();
}
}
}
}));
});
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Surface, _objectSpread(_objectSpread({
Component: Line,
color: color,
tonal: tonal,
direction: "row",
align: "center",
justify: "initial",
gap: 1,
className: (0, _styleReact.classNames)([(0, _utils2.staticClassName)("NavigationBar", theme) && ["onesy-NavigationBar-root"], className, classes.root, fixed && classes.fixed]),
style: _objectSpread(_objectSpread({}, style), styles.root)
}, other), {}, {
children: children
}));
};
NavigationBar.displayName = 'onesy-NavigationBar';
var _default = exports.default = NavigationBar;