UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

64 lines (63 loc) 2.95 kB
"use client"; import _extends from "@babel/runtime/helpers/esm/extends"; import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; const _excluded = ["size", "icon", "on_click", "className"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import React from 'react'; import classnames from 'classnames'; import { convertJsxToString, extendPropsWithContext } from '../../shared/component-helper'; import Context from '../../shared/Context'; import { createSpacingClasses } from '../space/SpacingHelper'; import Button from '../button/Button'; const defaultProps = { variant: 'secondary', icon_position: 'left' }; export default function HelpButtonInstance(localProps) { const context = React.useContext(Context); const props = extendPropsWithContext(localProps, defaultProps, context.HelpButton); const { size, icon, on_click, className } = props, rest = _objectWithoutProperties(props, _excluded); const params = _objectSpread({ className: classnames('dnb-help-button', createSpacingClasses(props), className), size, icon }, rest); const isPotentialHelpButton = !params.text || params.variant === 'tertiary'; if (isPotentialHelpButton && !params.icon && params.icon !== false) { params.icon = 'question'; } const isHelpButton = isPotentialHelpButton && ['question', 'information'].includes(String(params.icon)); if (isHelpButton) { if (!params['aria-roledescription']) { params['aria-roledescription'] = context.getTranslation(props).HelpButton.aria_role; } } if (!params.text && typeof params['aria-label'] === 'undefined') { let ariaLabel = convertJsxToString(props.title || props.children); if (!ariaLabel) { ariaLabel = context.getTranslation(props).HelpButton.title; } params['aria-label'] = ariaLabel; } if (icon === 'information' && !size) { params.icon_size = 'medium'; } if (params.title && !params.tooltip && params.tooltip !== false) { params.tooltip = params.title; } if (params.tooltip) { params.title = null; } return React.createElement(Button, _extends({ on_click: on_click }, params)); } //# sourceMappingURL=HelpButtonInstance.js.map