UNPKG

@vnmfify/core

Version:

```shell npm i @vnmfify/core -S ```

90 lines (75 loc) 2.61 kB
import { View } from "@vnxjs/components"; import classNames from "classnames"; import * as React from "react"; import { Children, cloneElement, isValidElement, useMemo } from "react"; import { prefixClassname } from "../styles"; import { HAIRLINE_BORDER_LEFT, HAIRLINE_BORDER_TOP } from "../styles/hairline"; import { getLogger } from "../utils/logger"; var { deprecated } = getLogger("Dialog.Actions"); function useActionButtons(props) { return useMemo(() => { var { children, variant } = props; if (children === undefined) { return children; } var __rounded__ = variant === "rounded"; var count = Children.count(children); var zeroIndex = 0; var lastIndex = count - 1; var __children__ = []; Children.forEach(children, (action, index) => { var _action$key; if (! /*#__PURE__*/isValidElement(action)) { __children__.push(action); return; } var element = action; var actionClassNames = [element.props.className]; if (index !== zeroIndex && !__rounded__) { actionClassNames.push(HAIRLINE_BORDER_LEFT); } if (index !== lastIndex) { actionClassNames.push(prefixClassname("dialog__cancel")); } if (index === lastIndex) { actionClassNames.push(prefixClassname("dialog__confirm")); } __children__.push( /*#__PURE__*/cloneElement(action, { key: (_action$key = action.key) !== null && _action$key !== void 0 ? _action$key : index, className: classNames(action.props.className, actionClassNames), size: "large", shape: "square", variant: __rounded__ ? "contained" : "text" })); }); return __children__; }, [props]); } export default function DialogActions(props) { var { theme, variant: variantProp, children: childrenProp } = props; if (theme === "round") { deprecated('Use the variant="rounded" prop instead of the theme="round" prop'); } var variant = variantProp !== null && variantProp !== void 0 ? variantProp : theme === "round" ? "rounded" : undefined; var children = useActionButtons({ children: childrenProp, variant }); return /*#__PURE__*/React.createElement(View, { className: classNames(prefixClassname("dialog__footer"), { [HAIRLINE_BORDER_TOP]: variant !== "rounded", [prefixClassname("dialog__footer--rounded")]: variant === "rounded" }), children: children }); } //# sourceMappingURL=dialog-actions.js.map