@onesy/ui-react
Version:
UI for React
139 lines • 5.47 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
const _excluded = ["ref", "tonal", "color", "size", "elevation", "menu", "menuOpen", "noMaxWidth", "indent", "paddingHorizontal", "paddingVertical", "noBackground", "noChildrenTransform", "onMenuDesktopClose", "SurfaceProps", "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 React from 'react';
import { is } from '@onesy/utils';
import { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react';
import SurfaceElement from '../Surface';
import LineElement from '../Line';
import useMediaQuery from '../useMediaQuery';
import { staticClassName } from '../utils';
import { jsx as _jsx } from "react/jsx-runtime";
const useStyle = styleMethod(theme => ({
root: {
// Reset
margin: '0',
listStyle: 'none',
width: '100%',
position: 'relative',
borderRadius: `${theme.shape.radius.unit / 2}px`
},
padding_vertical_both: {
paddingBlock: theme.methods.space.value('sm', 'px')
},
padding_vertical_start: {
paddingBlockStart: theme.methods.space.value('sm', 'px')
},
padding_vertical_end: {
paddingBlockEnd: theme.methods.space.value('sm', 'px')
},
padding_vertical_none: {
paddingBlock: '0'
},
padding_horizontal_both: {
paddingInline: theme.methods.space.value('rg', 'px')
},
padding_horizontal_start: {
paddingInlineStart: theme.methods.space.value('rg', 'px')
},
padding_horizontal_end: {
paddingInlineEnd: theme.methods.space.value('rg', 'px')
},
padding_horizontal_none: {
paddingInline: '0'
},
menu: {},
noMaxWidth: {
maxWidth: 'unset'
},
noBackground: {
'&.onesy-Surface-root': {
background: 'none'
}
}
}), {
name: 'onesy-List'
});
const List = props_ => {
const theme = useOnesyTheme();
const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesyList?.props?.default), props_);
const Line = theme?.elements?.Line || LineElement;
const Surface = theme?.elements?.Surface || SurfaceElement;
const {
ref,
tonal = true,
color = 'themed',
size: size_,
elevation = props.menu && theme.palette.light ? 2 : 0,
menu,
menuOpen,
noMaxWidth,
indent,
paddingHorizontal = 'none',
paddingVertical = 'both',
noBackground,
noChildrenTransform,
onMenuDesktopClose,
SurfaceProps,
Component = 'ul',
className,
style,
children
} = props,
other = _objectWithoutProperties(props, _excluded);
const {
classes
} = useStyle();
const refs = {
root: React.useRef(undefined)
};
const mobile = useMediaQuery('(max-width: 767px)', {
element: refs.root.current
});
const size = size_ !== undefined ? size_ : mobile ? 'small' : 'regular';
const styles = {
root: {}
};
if (indent !== undefined) styles.root.paddingInlineStart = `${indent * theme.space.unit}px`;
return /*#__PURE__*/_jsx(Surface, _objectSpread(_objectSpread({
ref: item => {
if (ref) {
if (is('function', ref)) ref(item);else ref.current = item;
}
refs.root.current = item;
},
tonal: tonal,
color: color,
elevation: elevation,
gap: 0,
direction: "column",
align: "flex-start",
role: "listbox",
Component: Line,
AdditionalProps: {
Component
}
}, SurfaceProps), {}, {
className: classNames([staticClassName('List', theme) && ['onesy-List-root', `onesy-List-size-${size}`], SurfaceProps?.className, className, classes.root, classes[`padding_vertical_${paddingVertical}`], classes[`padding_horizontal_${paddingHorizontal}`], menu && classes.menu, noMaxWidth && classes.noMaxWidth, noBackground && classes.noBackground]),
style: _objectSpread(_objectSpread({}, style), styles.root),
children: noChildrenTransform ? children : React.Children.toArray(children).map((item_0, index) => {
return /*#__PURE__*/React.cloneElement(item_0, _objectSpread(_objectSpread(_objectSpread({
key: index,
menuItem: menu,
menuOpen,
tonal: item_0.props.tonal !== undefined ? item_0.props.tonal : tonal,
color: item_0.props.color !== undefined ? item_0.props.color : color,
size: item_0.props.size !== undefined ? item_0.props.size : size
}, other), item_0.props), {}, {
onClick: event => {
if (is('function', onMenuDesktopClose) && item_0.props.menuCloseOnClick) onMenuDesktopClose();
if (is('function', item_0.props.onClick)) item_0.props.onClick(event);
}
}));
})
}));
};
List.displayName = 'onesy-List';
export default List;