UNPKG

@navinc/base-react-components

Version:
46 lines 2.02 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import styled from 'styled-components'; import Button from './button'; import Copy from './copy'; import Icon from './icon.js'; import PropTypes from 'prop-types'; export const HelperIcon = styled(Icon) ` max-width: 16px; max-height: 16px; fill: ${({ theme }) => theme.neutral400}; `; export const HelperDescription = styled(Copy).attrs(() => ({ size: 'sm', bold: true })) ` color: inherit; `; export const HelperItem = styled.div.attrs(({ isLink }) => isLink && { as: Button, variation: 'buttonLink', type: 'button' }) ` display: grid; padding-top: 4px; grid-template-columns: min-content 1fr; grid-gap: 4px; text-align: left; ${({ hasSpaceForErrors }) => (hasSpaceForErrors ? 'min-height: 18px;' : '')} ${({ theme, isLink }) => !isLink && `color: ${theme.neutral400};`} `; /** * Helper is a tooltip component * * @returns ReactElement */ export const Helper = ({ className, hasSpaceForErrors, helperLinkAction, helperText, iconName }) => (_jsxs(HelperItem, Object.assign({ className: className, isLink: !!helperLinkAction, onClick: helperLinkAction, hasSpaceForErrors: hasSpaceForErrors }, { children: [iconName && _jsx(HelperIcon, { name: iconName }, void 0), _jsx(HelperDescription, Object.assign({ "data-testid": `input:helper-text:${helperText}`, light: true, size: "xs" }, { children: helperText }), void 0)] }), void 0)); Helper.propTypes = { /** Classname provided to the HelperItem */ className: PropTypes.string, /** Adds space for an error. Suggest passing !!errors into this prop to add/remove it based on the existence of errors */ hasSpaceForErrors: PropTypes.bool, /** onClick */ helperLinkAction: PropTypes.func, /** Text inside the helper description */ helperText: PropTypes.string, /** Name of icon */ iconName: PropTypes.string, }; Helper.defaultProps = { iconName: 'actions/circle-faq', }; export default styled(Helper) ``; //# sourceMappingURL=helper.js.map