@onesy/ui-react
Version:
UI for React
197 lines • 7.13 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
const _excluded = ["tonal", "color", "version", "size", "value", "valueDefault", "onChange", "justify", "border", "header", "fixed", "NavigationBarProps", "DividerProps", "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 { is } from '@onesy/utils';
import { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react';
import LineElement from '../Line';
import SurfaceElement from '../Surface';
import DividerElement from '../Divider';
import NavigationBarElement from '../NavigationBar';
import { staticClassName } from '../utils';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const useStyle = styleMethod(theme => ({
root: {
position: 'relative',
height: '100%',
width: '80px',
padding: `${theme.methods.space.value(5, 'px')} 0`,
overflow: 'auto',
zIndex: theme.z_index.app_bar
},
size_small: {
width: '72px'
},
size_regular: {
width: '80px'
},
size_large: {
width: '88px'
},
fixed: {
position: 'fixed',
insetBlock: '0',
insetInlineStart: '0'
},
header: {
marginBottom: '70px'
},
main: {
width: '100%',
flex: '1 1 auto',
'&.onesy-NavigationBar-root': {
background: 'transparent'
}
},
divider: {
position: 'absolute',
height: '100%',
insetBlock: '0',
insetInlineEnd: '0',
'&.onesy-Divider-root': {
margin: '0',
opacity: theme.palette.light ? '0.07' : '0.11'
}
}
}), {
name: 'onesy-NavigationRail'
});
const NavigationRail = props_ => {
const $ = _c(4);
const theme = useOnesyTheme();
const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesyNavigationRail?.props?.default), props_);
const Line = theme?.elements?.Line || LineElement;
const Surface = theme?.elements?.Surface || SurfaceElement;
const Divider = theme?.elements?.Divider || DividerElement;
const NavigationBar = theme?.elements?.NavigationBar || NavigationBarElement;
const {
tonal: t0,
color: t1,
version: t2,
size: t3,
value,
valueDefault,
onChange,
justify: t4,
border,
header: header_,
fixed,
NavigationBarProps,
DividerProps,
className,
style,
children: children_
} = props,
other = _objectWithoutProperties(props, _excluded);
const tonal = t0 === undefined ? true : t0;
const color = t1 === undefined ? "primary" : t1;
const version = t2 === undefined ? "regular" : t2;
const size = t3 === undefined ? "regular" : t3;
const justify = t4 === undefined ? "center" : t4;
const {
classes
} = useStyle();
const [init, setInit] = React.useState(false);
const [selected, setSelected] = React.useState(() => {
const valueNew = valueDefault !== undefined ? valueDefault : value;
return valueNew !== undefined ? is("array", valueNew) ? valueNew : [valueNew] : [];
});
const styles = {
root: {},
icon: {}
};
let t5;
let t6;
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
t5 = () => {
setInit(true);
};
t6 = [];
$[0] = t5;
$[1] = t6;
} else {
t5 = $[0];
t6 = $[1];
}
React.useEffect(t5, t6);
let t7;
if ($[2] !== value) {
t7 = [value];
$[2] = value;
$[3] = t7;
} else {
t7 = $[3];
}
React.useEffect(() => {
if (init && value !== selected) {
setSelected(is("array", value) ? value : [value]);
}
}, t7);
const onSelect = itemProps => {
const valueNew_0 = [itemProps.value];
if (valueNew_0 !== undefined) {
if (!props.hasOwnProperty("value")) {
setSelected(valueNew_0);
}
if (is("function", onChange)) {
onChange(valueNew_0);
}
}
};
const header = React.Children.toArray(header_).map((item, index) => /*#__PURE__*/React.cloneElement(item, {
key: index,
color: item.props.color !== undefined ? item.props.color : color,
tonal: item.props.tonal !== undefined ? item.props.tonal : tonal && ["onesy-Fab"].includes(item.type?.displayName) ? "secondary" : tonal
}));
const children = React.Children.toArray(children_).map((item_0, index_0) => /*#__PURE__*/React.cloneElement(item_0, _objectSpread(_objectSpread({
key: index_0
}, ["onesy-NavigationItem"].includes(item_0.type?.displayName) ? {
vertical: true
} : {}), {}, {
selected: selected.includes(item_0.props.value),
onClick: () => {
if (!item_0.props.disabled) {
onSelect(item_0.props);
if (is("function", item_0.props.onClick)) {
item_0.props.onClick();
}
}
}
})));
return /*#__PURE__*/_jsxs(Surface, _objectSpread(_objectSpread({
Component: Line,
color: color,
tonal: tonal,
direction: "column",
align: "initial",
justify: "initial",
gap: 0,
className: classNames([staticClassName("NavigationRail", theme) && ["onesy-NavigationRail-root", `onesy-NavigationRail-version-${version}`, `onesy-NavigationRail-size-${size}`], className, classes.root, classes[`size_${size}`], fixed && classes.fixed]),
style: _objectSpread(_objectSpread({}, style), styles.root)
}, other), {}, {
children: [header && /*#__PURE__*/_jsx(Line, {
align: "center",
className: classNames([staticClassName("NavigationRail", theme) && ["onesy-NavigationRail-header"], classes.header]),
children: header
}), children && /*#__PURE__*/_jsx(NavigationBar, _objectSpread(_objectSpread({
version: version,
direction: "column",
justify: justify,
gap: 2,
color: color,
tonal: tonal
}, NavigationBarProps), {}, {
className: classNames([staticClassName("NavigationRail", theme) && ["onesy-NavigationRail-main"], NavigationBarProps?.className, classes.main]),
children: children
})), border && /*#__PURE__*/_jsx(Divider, _objectSpread(_objectSpread({
orientation: "vertical"
}, DividerProps), {}, {
className: classNames([staticClassName("NavigationRail", theme) && ["onesy-NavigationRail-divider"], DividerProps?.className, classes.divider])
}))]
}));
};
NavigationRail.displayName = 'onesy-NavigationRail';
export default NavigationRail;