@onesy/ui-react
Version:
UI for React
189 lines • 6.71 kB
JavaScript
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
const _excluded = ["tonal", "color", "inset", "middle", "padding", "opacity", "alignment", "orientation", "flex", "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 { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react';
import TypeElement from '../Type';
import SurfaceElement from '../Surface';
import { staticClassName } from '../utils';
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
const useStyle = styleMethod(theme => ({
root: {
// Reset
margin: '0',
border: 'none',
display: 'flex',
flexShrink: '0',
opacity: theme.palette.visual_contrast.default.opacity.divider,
transition: theme.methods.transitions.make('background')
},
divider_tonal: {
opacity: '1'
},
orientation_vertical: {
margin: '0 8px',
height: '100%',
width: '1px'
},
orientation_vertical_middle: {
margin: `16px 8px`,
height: `calc(100% - 32px)`
},
// Orientation
orientation_horizontal: {
margin: '8px 0',
height: '1px',
width: '100%'
},
orientation_horizontal_middle: {
margin: `8px 16px`,
width: `calc(100% - 32px)`
},
rootWithChildren: {
display: 'flex',
opacity: '1',
color: theme.palette.text.default.primary,
background: 'transparent',
// Reset
height: 'unset',
width: 'unset',
margin: '0',
border: 'none'
},
// Orientation
rootWithChildren_orientation_horizontal: {
flexDirection: 'row',
alignItems: 'center',
width: '100%'
},
rootWithChildren_orientation_horizontal_middle: {
margin: `0 16px`,
width: `calc(100% - 32px)`
},
rootWithChildren_orientation_vertical: {
flexDirection: 'column',
alignItems: 'center',
height: '100%'
},
rootWithChildren_orientation_vertical_middle: {
margin: `16px 0`,
height: `calc(100% - 32px)`
},
// flex
flex_orientation_horizontal: {
flex: '1 1 auto',
width: 'auto'
},
flex_orientation_vertical: {
flex: '1 1 auto'
},
text: {
flex: '0 0 auto'
},
// Orientation
text_horizontal: {
margin: `0 16px`
},
text_vertical: {
margin: `16px 0`
},
divider: {
flex: '0 1 100%',
opacity: theme.palette.visual_contrast.default.opacity.divider
},
// Orientation
divider_orientation_horizontal: {
height: '1px'
},
divider_orientation_vertical: {
width: '1px'
},
orientation_horizontal_padding: {
marginInline: '16px',
width: 'calc(100% - 32px)'
},
orientation_vertical_padding: {
marginBlock: '16px',
height: 'calc(100% - 32px)'
},
color_inherit: {
opacity: theme.palette.visual_contrast.default.opacity.divider,
color: 'inherit',
background: 'currentColor'
},
inset: {
marginLeft: `72px`,
width: `calc(100% - 72px)`
}
}), {
name: 'onesy-Divider'
});
const Divider = props_ => {
const theme = useOnesyTheme();
const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesyDivider?.props?.default), props_);
const Type = theme?.elements?.Type || TypeElement;
const Surface = theme?.elements?.Surface || SurfaceElement;
const {
tonal = true,
color = 'inverted',
inset,
middle,
padding,
opacity = theme.palette.visual_contrast.default.opacity.divider,
alignment = 'center',
orientation = 'horizontal',
flex,
Component: Component_ = 'hr',
className,
style,
children
} = props,
other = _objectWithoutProperties(props, _excluded);
const {
classes
} = useStyle();
const styles = {
root: {},
divider: {},
start: {},
end: {}
};
let Component = Component_;
if (children && Component === 'hr') Component = 'div';
if (alignment === 'start') styles.start.flexBasis = '15%';
if (alignment === 'end') styles.end.flexBasis = '15%';
return /*#__PURE__*/_jsx(Surface, _objectSpread(_objectSpread({
version: "filled",
tonal: tonal,
color: color,
Component: Component,
className: classNames([staticClassName('Divider', theme) && ['onesy-Divider-root'], className, classes[children ? 'rootWithChildren' : 'root'], classes[`${children ? 'rootWithChildren_' : ''}orientation_${orientation}`], flex && classes[`flex_orientation_${orientation}`], inset && classes.inset, middle && classes[`${children ? `rootWithChildren_` : ''}orientation_${orientation}_middle`], padding && classes[`orientation_${orientation}_padding`], color === 'inherit' && classes.color_inherit, tonal && classes.divider_tonal]),
style: _objectSpread(_objectSpread({
opacity
}, style), styles.root)
}, other), {}, {
children: children && /*#__PURE__*/_jsxs(_Fragment, {
children: [/*#__PURE__*/_jsx(Surface, {
version: "filled",
tonal: tonal,
color: color,
className: classNames([staticClassName('Divider', theme) && ['onesy-Divider-divider'], classes.divider, classes[`divider_orientation_${orientation}`], tonal && classes.divider_tonal]),
style: _objectSpread(_objectSpread({}, styles.divider), styles.start)
}), /*#__PURE__*/_jsx(Type, {
version: "b2",
className: classNames([staticClassName('Divider', theme) && ['onesy-Divider-text'], classes.text, classes[`text_${orientation}`]]),
children: children
}), /*#__PURE__*/_jsx(Surface, {
version: "filled",
tonal: tonal,
color: color,
className: classNames([staticClassName('Divider', theme) && ['onesy-Divider-divider'], classes.divider, classes[`divider_orientation_${orientation}`], tonal && classes.divider_tonal]),
style: _objectSpread(_objectSpread({}, styles.divider), styles.end)
})]
})
}));
};
Divider.displayName = 'onesy-Divider';
export default Divider;