@onesy/ui-react
Version:
UI for React
147 lines (146 loc) • 7.79 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 _react = _interopRequireDefault(require("react"));
var _styleReact = require("@onesy/style-react");
var _Surface = _interopRequireDefault(require("../Surface"));
var _Divider = _interopRequireDefault(require("../Divider"));
var _Line = _interopRequireDefault(require("../Line"));
var _utils = require("../utils");
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["orientation", "start", "end", "DividerProps", "iconProps", "icon", "Divider", "Component", "className", "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: {
maxWidth: '100%',
'&:last-of-type': {
'& $divider': {
display: 'none'
}
}
},
orientation_vertical: {
minHeight: '77px'
},
orientation_horizontal: {
minWidth: '114px'
},
icon: {
display: 'inline-block',
width: '12px',
height: '12px',
borderRadius: theme.methods.shape.radius.value(40, 'px')
},
end: {
overflow: 'auto hidden'
},
aside_orientation_vertical: {
padding: `${theme.methods.space.value(0.5, 'px')} ${theme.methods.space.value(3, 'px')}`
},
aside_orientation_horizontal: {
padding: `${theme.methods.space.value(3, 'px')} ${theme.methods.space.value(0.5, 'px')}`
},
iconWrapper: {
lineHeight: '0'
},
iconWrapper_orientation_vertical: {
marginBlock: '8px'
},
iconWrapper_orientation_horizontal: {
marginInline: '8px'
},
divider: {
'&.onesy-Divider-root': {
margin: '0px'
}
},
divider_orientation_vertical: {
'&.onesy-Divider-root': {
width: '2px'
}
},
divider_orientation_horizontal: {
'&.onesy-Divider-root': {
height: '2px'
}
}
}), {
name: 'onesy-TimelineItem'
});
const TimelineItem = props_ => {
var _theme$ui, _theme$ui2, _theme$elements, _theme$elements2, _theme$elements3;
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.onesyTimelineItem) === 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 Divider = (theme === null || theme === void 0 || (_theme$elements3 = theme.elements) === null || _theme$elements3 === void 0 ? void 0 : _theme$elements3.Divider) || _Divider.default;
const {
orientation = 'vertical',
start,
end,
DividerProps: DividerProps_ = !props.Divider ? {
tonal: 'secondary',
color: 'neutral'
} : undefined,
iconProps = !props.icon ? {
tonal: 'secondary',
color: 'neutral',
version: 'filled'
} : undefined,
icon,
Divider: Divider_,
Component = 'li',
className,
children
} = props,
other = (0, _objectWithoutProperties2.default)(props, _excluded);
const {
classes
} = useStyle();
const direction = orientation === 'vertical' ? 'row' : 'column';
const lineDirection = orientation === 'vertical' ? 'column' : 'row';
const DividerProps = _objectSpread({}, DividerProps_);
if (!Divider_) {
DividerProps.orientation = orientation;
}
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, _objectSpread(_objectSpread({
gap: 0,
align: "unset",
justify: "unset",
direction: direction,
Component: Component,
className: (0, _styleReact.classNames)([(0, _utils.staticClassName)('TimelineItem', theme) && ['onesy-TimelineItem-root'], className, classes.root, classes[`orientation_${orientation}`]])
}, other), {}, {
children: [start && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: (0, _styleReact.classNames)([(0, _utils.staticClassName)('TimelineItem', theme) && ['onesy-TimelineItem-aside', 'onesy-TimelineItem-item', 'onesy-TimelineItem-start'], classes.aside, classes.item, classes.start, classes[`aside_orientation_${orientation}`]]),
children: start
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(Line, {
gap: 0,
direction: lineDirection,
align: "center",
justify: "flex-start",
className: (0, _styleReact.classNames)([(0, _utils.staticClassName)('TimelineItem', theme) && ['onesy-TimelineItem-item', 'onesy-TimelineItem-middle'], classes.item, classes.middle]),
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: (0, _styleReact.classNames)([(0, _utils.staticClassName)('TimelineItem', theme) && ['onesy-TimelineItem-icon-wrapper'], classes.iconWrapper, classes[`iconWrapper_orientation_${orientation}`]]),
children: icon ? icon : /*#__PURE__*/(0, _jsxRuntime.jsx)(Surface, _objectSpread(_objectSpread({}, iconProps), {}, {
tonal: true,
className: (0, _styleReact.classNames)([(0, _utils.staticClassName)('TimelineItem', theme) && ['onesy-TimelineItem-icon'], iconProps === null || iconProps === void 0 ? void 0 : iconProps.className, classes.icon])
}))
}), Divider_ ? Divider_ : /*#__PURE__*/(0, _jsxRuntime.jsx)(Divider, _objectSpread(_objectSpread({}, DividerProps), {}, {
className: (0, _styleReact.classNames)([(0, _utils.staticClassName)('TimelineItem', theme) && ['onesy-TimelineItem-divider'], DividerProps === null || DividerProps === void 0 ? void 0 : DividerProps.className, classes.divider, classes[`divider_orientation_${orientation}`]]),
flex: true
}))]
}), (end || children) && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: (0, _styleReact.classNames)([(0, _utils.staticClassName)('TimelineItem', theme) && ['onesy-TimelineItem-aside', 'onesy-TimelineItem-item', 'onesy-TimelineItem-end'], classes.aside, classes.item, classes.end, classes[`aside_orientation_${orientation}`]]),
children: end || children
})]
}));
};
TimelineItem.displayName = 'onesy-TimelineItem';
var _default = exports.default = TimelineItem;