UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

87 lines (86 loc) 3.06 kB
"use client"; import React from 'react'; import clsx from 'clsx'; import Context from "../../../shared/Context.js"; import { applySpacing } from "../../space/SpacingUtils.js"; import { createSkeletonClass } from "../../skeleton/SkeletonHelper.js"; import ButtonContent from "../../button/internal/ButtonContent.js"; import { jsx as _jsx } from "react/jsx-runtime"; export default function PopoverCloseButton({ icon = 'close', iconSize, iconPosition = 'right', variant = 'tertiary', size, className, title, text, children, type: buttonType, stretch, wrap, skeleton, ...rest }) { var _rest$ariaLabel; const context = React.useContext(Context); const hasIcon = Boolean(icon); const content = text !== null && text !== void 0 ? text : children; const hasContent = Boolean(content); const isIconOnly = Boolean(hasIcon && !hasContent); const iconElement = React.isValidElement(icon) ? React.createElement(icon.type, { ...icon.props, className: clsx(icon.props.className, 'dnb-button__icon') }) : null; const resolvedAriaLabel = (_rest$ariaLabel = rest['aria-label']) !== null && _rest$ariaLabel !== void 0 ? _rest$ariaLabel : typeof title === 'string' ? title : undefined; const resolvedType = buttonType === 'button' || buttonType === 'submit' || buttonType === 'reset' ? buttonType : 'button'; let resolvedVariant = variant; let resolvedSize = size; let resolvedIconSize = iconSize; if (isIconOnly) { if (!resolvedVariant) { resolvedVariant = 'secondary'; } if (!resolvedSize) { resolvedSize = 'medium'; } if (!resolvedIconSize && (resolvedSize === 'default' || resolvedSize === 'large')) { resolvedIconSize = 'medium'; } } else if (hasContent) { if (!resolvedVariant) { resolvedVariant = 'primary'; } if (!resolvedSize) { resolvedSize = 'default'; } } if (!resolvedIconSize && resolvedVariant === 'tertiary' && iconPosition === 'top') { resolvedIconSize = 'medium'; } const buttonProps = applySpacing({ ...rest, stretch, wrap, skeleton }, { title, 'aria-label': resolvedAriaLabel, className: clsx(`dnb-button dnb-button--${resolvedVariant}`, createSkeletonClass(resolvedVariant === 'tertiary' ? 'font' : 'shape', skeleton, context), className, hasIcon && `dnb-button--icon-position-${iconPosition} dnb-button--has-icon` + (resolvedIconSize ? ` dnb-button--icon-size-${resolvedIconSize}` : ""), resolvedSize && resolvedSize !== 'default' && `dnb-button--size-${resolvedSize}`, hasContent && 'dnb-button--has-text', isIconOnly && 'dnb-button--icon-only', stretch && 'dnb-button--stretch', wrap && 'dnb-button--wrap'), type: resolvedType, ...rest }); return _jsx("button", { ...buttonProps, children: _jsx(ButtonContent, { title: title, content: content, icon: icon, iconSize: resolvedIconSize, skeleton: skeleton, isIconOnly: isIconOnly, iconElement: iconElement }) }); } //# sourceMappingURL=PopoverCloseButton.js.map