@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
60 lines (59 loc) • 1.99 kB
JavaScript
"use client";
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
import React from 'react';
import classnames from 'classnames';
import { convertJsxToString, extendPropsWithContext } from "../../shared/component-helper.js";
import Context from "../../shared/Context.js";
import { createSpacingClasses } from "../space/SpacingHelper.js";
import Button from "../button/Button.js";
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,
...rest
} = props;
const params = {
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