UNPKG

@amaui/ui-react

Version:
106 lines 5.58 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(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } import React from 'react'; import { is, textToInnerHTML } from '@amaui/utils'; import { classNames, style as styleMethod, useAmauiTheme } from '@amaui/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: { '&.amaui-TimelineItem-root': { width: '100%' }, '& .amaui-TimelineItem-aside': { width: 'calc(50% - 6px)' } } }), { name: 'amaui-SectionTimeline' }); const SectionTimeline = /*#__PURE__*/React.forwardRef((props_, ref) => { const theme = useAmauiTheme(); const props = React.useMemo(() => _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.amauiSectionTimeline?.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) && ['amaui-SectionTimeline-root', `amaui-SectionTimeline-size-${size}`], className, classes.root]) }, other), /*#__PURE__*/React.createElement(Timeline, _extends({ fullWidth: true }, TimelineProps, { className: classNames([staticClassName('SectionTimeline', theme) && ['amaui-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) && ['amaui-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) && ['amaui-SectionTimeline-item-end'], ItemEndProps?.className, classes.end]), noPadding: true })) }, TimelineItemProps, { className: classNames([staticClassName('SectionTimeline', theme) && ['amaui-SectionTimeline-timeline-item'], TimelineItemProps?.className, classes.timelineItem]) }))))); }); SectionTimeline.displayName = 'amaui-SectionTimeline'; export default SectionTimeline;