UNPKG

@amaui/ui-react

Version:
157 lines 6.71 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; const _excluded = ["tonal", "color", "version", "iconColor", "iconColorActive", "dividerColor", "dividerColorActive", "step", "activeStep", "active", "completed", "primary", "secondary", "stepDirection", "orientation", "button", "divider", "renderIcon", "ListItemProps", "DividerProps", "Component", "className", "children"]; 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 } from '@amaui/utils'; import { classNames, style as styleMethod, useAmauiTheme } from '@amaui/style-react'; import InteractionElement from '../Interaction'; import PaginationItemElement from '../PaginationItem'; import DividerElement from '../Divider'; import SurfaceElement from '../Surface'; import ListItemElement from '../ListItem'; import LineElement from '../Line'; import { IconDoneAnimated } from '../Buttons/Buttons'; import { staticClassName } from '../utils'; const useStyle = styleMethod(theme => ({ root: { position: 'relative', flex: '0 0 auto', transition: theme.methods.transitions.make('opacity') }, icon: { pointerEvents: 'none' }, inactive: { userSelect: 'none', opacity: theme.palette.visual_contrast.default.opacity.disabled }, direction_row: {}, direction_column: { flex: '1 1 auto', '& .amaui-ListItem-text': { textAlign: 'center' } }, button: { userSelect: 'none', cursor: 'pointer' }, divider: { position: 'absolute', '&.amaui-Divider-root': { margin: '0', transition: theme.methods.transitions.make(['background', 'height']) } }, divider_orientation_horizontal: { top: '20px', right: '0', transform: 'translate(calc(-50% - 70px), -50%)', '&.amaui-Divider-root': { width: 'calc(100% - 62px)' } }, divider_orientation_vertical: { left: '50%', top: '0', transform: 'translate(-50%, calc(-50% - 16px))', '&.amaui-Divider-root': { height: '50%' } }, divider_active_orientation_horizontal: { '&.amaui-Divider-root': { height: '4px' } }, divider_active_orientation_vertical: { '&.amaui-Divider-root': { width: '4px' } } }), { name: 'amaui-Step' }); const Step = /*#__PURE__*/React.forwardRef((props_, ref) => { const theme = useAmauiTheme(); const props = React.useMemo(() => _objectSpread(_objectSpread(_objectSpread({}, theme?.ui?.elements?.all?.props?.default), theme?.ui?.elements?.amauiStep?.props?.default), props_), [props_]); const Line = React.useMemo(() => theme?.elements?.Line || LineElement, [theme]); const Interaction = React.useMemo(() => theme?.elements?.Interaction || InteractionElement, [theme]); const PaginationItem = React.useMemo(() => theme?.elements?.PaginationItem || PaginationItemElement, [theme]); const Divider = React.useMemo(() => theme?.elements?.Divider || DividerElement, [theme]); const Surface = React.useMemo(() => theme?.elements?.Surface || SurfaceElement, [theme]); const ListItem = React.useMemo(() => theme?.elements?.ListItem || ListItemElement, [theme]); const { tonal = true, color = 'default', version = 'text', iconColor = 'inverted', iconColorActive = 'primary', dividerColor = 'inverted', dividerColorActive = 'primary', step = 0, activeStep, active, completed, primary, secondary, stepDirection = 'row', orientation = 'horizontal', button, divider, renderIcon: renderIcon_, ListItemProps, DividerProps, Component = Surface, className, children } = props, other = _objectWithoutProperties(props, _excluded); const { classes } = useStyle(); const activeDivider = activeStep >= step - 1; const renderIcon = is('function', renderIcon_) ? renderIcon_ : () => { return /*#__PURE__*/React.createElement(PaginationItem, { tonal: tonal, color: !(active || completed) ? iconColor : iconColorActive, version: "filled", className: classNames([staticClassName('Step', theme) && ['amaui-Step-icon'], classes.icon]) }, !completed ? step : /*#__PURE__*/React.createElement(IconDoneAnimated, { in: true, add: true })); }; return /*#__PURE__*/React.createElement(Line, _extends({ ref: ref, version: version, tonal: tonal, color: color, gap: 0, direction: stepDirection, align: "center", justify: "center", Component: Component, className: classNames([staticClassName('Step', theme) && ['amaui-Step-root', active && `amaui-Step-active`, completed && `amaui-Step-completed`, !active && !completed && `amaui-Step-inactive`], className, classes.root, classes[`direction_${stepDirection}`], !active && !completed && classes.inactive, button && classes.button]) }, other), button && /*#__PURE__*/React.createElement(Interaction, { border: false }), renderIcon(step, active, completed, activeStep), /*#__PURE__*/React.createElement(ListItem, _extends({ Component: "div", version: version, tonal: tonal, color: color, primary: primary, secondary: secondary }, ListItemProps)), step > 1 && divider && /*#__PURE__*/React.createElement(Divider, _extends({ orientation: orientation, color: activeDivider ? dividerColorActive : dividerColor, flex: true }, DividerProps, { className: classNames([staticClassName('Step', theme) && ['amaui-Step-divider', activeDivider && `amaui-Step-divider-active`], DividerProps?.className, classes.divider, classes[`divider_orientation_${orientation}`], activeDivider && classes[`divider_active_orientation_${orientation}`]]) }))); }); Step.displayName = 'amaui-Step'; export default Step;