UNPKG

@onesy/ui-react

Version:
109 lines 5.47 kB
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; const _excluded = ["ref", "size", "values", "TimelineProps", "TimelineItemProps", "TitleProps", "HeadingProps", "DescriptionProps", "ItemStartProps", "ItemEndProps", "className"]; 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, textToInnerHTML } from '@onesy/utils'; import { classNames, style as styleMethod, useOnesyTheme } from '@onesy/style-react'; import SectionElement from '../Section/Section'; import ListItemElement from '../ListItem'; import TimelineElement from '../Timeline'; import TimelineItemElement from '../TimelineItem'; import TypeElement from '../Type'; import { staticClassName } from '../utils'; import { jsx as _jsx } from "react/jsx-runtime"; const useStyle = styleMethod(theme => ({ root: {}, timeline: {}, timelineItem: { '&.onesy-TimelineItem-root': { width: '100%' }, '& .onesy-TimelineItem-aside': { width: 'calc(50% - 6px)' } } }), { name: 'onesy-SectionTimeline' }); const SectionTimeline = props_ => { const theme = useOnesyTheme(); const props = _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesySectionTimeline?.props?.default), props_); const Section = theme?.elements?.Section || SectionElement; const ListItem = theme?.elements?.ListItem || ListItemElement; const Timeline = theme?.elements?.Timeline || TimelineElement; const TimelineItem = theme?.elements?.TimelineItem || TimelineItemElement; const Type = theme?.elements?.Type || TypeElement; const { ref, size = 'regular', values = [], TimelineProps, TimelineItemProps, TitleProps, HeadingProps, DescriptionProps, ItemStartProps, ItemEndProps, className } = props, other = _objectWithoutProperties(props, _excluded); const { classes } = useStyle(); const refs = { root: React.useRef(undefined) }; return /*#__PURE__*/_jsx(Section, _objectSpread(_objectSpread({ ref: item => { if (ref) { if (is('function', ref)) ref(item);else ref.current = item; } refs.root.current = item; }, className: classNames([staticClassName('SectionTimeline', theme) && ['onesy-SectionTimeline-root', `onesy-SectionTimeline-size-${size}`], className, classes.root]) }, other), {}, { children: /*#__PURE__*/_jsx(Timeline, _objectSpread(_objectSpread({ fullWidth: true }, TimelineProps), {}, { className: classNames([staticClassName('SectionTimeline', theme) && ['onesy-SectionTimeline-timeline'], TimelineProps?.className, classes.timeline]), children: values?.map((item_0, index) => /*#__PURE__*/_jsx(TimelineItem, _objectSpread(_objectSpread({ start: is('string', item_0.title) ? /*#__PURE__*/_jsx(Type, _objectSpread(_objectSpread({ version: size === 'large' ? 'b1' : size === 'regular' ? 'b2' : 'b3', align: "right" }, ItemStartProps), {}, { className: classNames([staticClassName('SectionTimeline', theme) && ['onesy-SectionTimeline-item-start'], ItemStartProps?.className, classes.start]), dangerouslySetInnerHTML: { __html: textToInnerHTML(item_0.title) } })) : item_0.title, end: /*#__PURE__*/_jsx(ListItem, _objectSpread(_objectSpread({ Component: "div", primary: is('string', item_0.heading) ? /*#__PURE__*/_jsx(Type, _objectSpread(_objectSpread({ version: size === 'large' ? 't1' : size === 'regular' ? 't2' : 't3' }, HeadingProps), {}, { dangerouslySetInnerHTML: { __html: textToInnerHTML(item_0.heading) } })) : item_0.heading, secondary: is('string', item_0.description) ? /*#__PURE__*/_jsx(Type, _objectSpread(_objectSpread({ version: size === 'large' ? 'b2' : size === 'regular' ? 'b3' : 'b3' }, DescriptionProps), {}, { dangerouslySetInnerHTML: { __html: textToInnerHTML(item_0.description) } })) : item_0.description, noBackground: true }, ItemEndProps), {}, { className: classNames([staticClassName('SectionTimeline', theme) && ['onesy-SectionTimeline-item-end'], ItemEndProps?.className, classes.end]), noPadding: true })) }, TimelineItemProps), {}, { className: classNames([staticClassName('SectionTimeline', theme) && ['onesy-SectionTimeline-timeline-item'], TimelineItemProps?.className, classes.timelineItem]) }), index)) })) })); }; SectionTimeline.displayName = 'onesy-SectionTimeline'; export default SectionTimeline;