UNPKG

@onesy/ui-react

Version:
106 lines 5.42 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; const _excluded = ["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'; const useStyle = styleMethod(theme => ({ root: {}, timeline: {}, timelineItem: { '&.onesy-TimelineItem-root': { width: '100%' }, '& .onesy-TimelineItem-aside': { width: 'calc(50% - 6px)' } } }), { name: 'onesy-SectionTimeline' }); const SectionTimeline = /*#__PURE__*/React.forwardRef((props_, ref) => { const theme = useOnesyTheme(); const props = React.useMemo(() => _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.onesySectionTimeline?.props?.default), props_), [props_]); const Section = React.useMemo(() => theme?.elements?.Section || SectionElement, [theme]); const ListItem = React.useMemo(() => theme?.elements?.ListItem || ListItemElement, [theme]); const Timeline = React.useMemo(() => theme?.elements?.Timeline || TimelineElement, [theme]); const TimelineItem = React.useMemo(() => theme?.elements?.TimelineItem || TimelineItemElement, [theme]); const Type = React.useMemo(() => theme?.elements?.Type || TypeElement, [theme]); const { 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__*/React.createElement(Section, _extends({ 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), /*#__PURE__*/React.createElement(Timeline, _extends({ fullWidth: true }, TimelineProps, { className: classNames([staticClassName('SectionTimeline', theme) && ['onesy-SectionTimeline-timeline'], TimelineProps?.className, classes.timeline]) }), values?.map((item, index) => /*#__PURE__*/React.createElement(TimelineItem, _extends({ key: index, start: is('string', item.title) ? /*#__PURE__*/React.createElement(Type, _extends({ 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.title) } })) : item.title, end: /*#__PURE__*/React.createElement(ListItem, _extends({ Component: "div", primary: is('string', item.heading) ? /*#__PURE__*/React.createElement(Type, _extends({ version: size === 'large' ? 't1' : size === 'regular' ? 't2' : 't3' }, HeadingProps, { dangerouslySetInnerHTML: { __html: textToInnerHTML(item.heading) } })) : item.heading, secondary: is('string', item.description) ? /*#__PURE__*/React.createElement(Type, _extends({ version: size === 'large' ? 'b2' : size === 'regular' ? 'b3' : 'b3' }, DescriptionProps, { dangerouslySetInnerHTML: { __html: textToInnerHTML(item.description) } })) : item.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]) }))))); }); SectionTimeline.displayName = 'onesy-SectionTimeline'; export default SectionTimeline;