UNPKG

@appbuckets/react-ui

Version:
70 lines (67 loc) 2.13 kB
import { __rest, __assign } from 'tslib'; import * as React from 'react'; import clsx from 'clsx'; import { createShorthandFactory, useElementType, childrenUtils, } from '@appbuckets/react-ui-core'; import { useSharedClassName } from '../utils/customHook.js'; import '../BucketTheme/BucketTheme.js'; import { useWithDefaultProps } from '../BucketTheme/BucketContext.js'; import Button from '../Button/Button.js'; /* -------- * Component Render * -------- */ var ModalActions = function (receivedProps) { var props = useWithDefaultProps('modalActions', receivedProps); var _a = useSharedClassName(props), className = _a.className, _b = _a.rest, actions = _b.actions, children = _b.children; _b.content; var onActionClick = _b.onActionClick, rest = __rest(_b, ['actions', 'children', 'content', 'onActionClick']); /** Get the component element type */ var ElementType = useElementType(ModalActions, receivedProps, props); /** Build the element class list */ var classes = clsx('modal-actions', className); /** If children are declared, render them */ if (!childrenUtils.isNil(children)) { return React.createElement( ElementType, __assign({}, rest, { className: classes }), children ); } return React.createElement( ElementType, __assign({}, rest, { className: classes }), Array.isArray(actions) && actions.map(function (button) { return Button.create(button, { autoGenerateKey: false, overrideProps: function (predefinedProps) { return { onClick: function (e, buttonProps) { if (predefinedProps.onClick) { predefinedProps.onClick(e, buttonProps); } if (onActionClick) { onActionClick(e, buttonProps); } }, }; }, }); }) ); }; ModalActions.displayName = 'ModalActions'; ModalActions.create = createShorthandFactory(ModalActions, function (value) { return { actions: value, }; }); export { ModalActions as default };