import * as React from 'react'; import { TextControl, tailwind } from '@tesseract-design/web-base'; import { useFallbackId } from '@modal-sh/react-utils'; const { tw } = tailwind; const MenuMultiSelectDerivedElementComponent = 'select' as const; /** * Derived HTML element of the {@link MenuMultiSelect} component. */ export type MenuMultiSelectDerivedElement = HTMLElementTagNameMap[ typeof MenuMultiSelectDerivedElementComponent ]; /** * Props of the {@link MenuMultiSelect} component. */ export interface MenuMultiSelectProps extends Omit, 'size' | 'label' | 'multiple'> { /** * Short textual description indicating the nature of the component's value. */ label?: React.ReactNode, /** * Short textual description as guidelines for valid input values. */ hint?: React.ReactNode, /** * Size of the component. */ size?: TextControl.Size, /** * Additional description, usually graphical, indicating the nature of the component's value. */ indicator?: React.ReactNode, /** * Should the component display a border? */ border?: boolean, /** * Should the component occupy the whole width of its parent? */ block?: boolean, /** * Style of the component. */ variant?: TextControl.Variant, /** * Is the label hidden? */ hiddenLabel?: boolean, /** * Starting height of the component. */ startingHeight?: number | string, } export const menuMultiSelectPlugin: tailwind.PluginCreator = ({ addComponents }) => { addComponents({ '.menu-multi-select': { '& optgroup': { 'color': 'rgb(var(--color-positive) / 50%)', 'text-transform': 'uppercase', 'font-size': '0.75em', 'margin-top': '0.5rem', 'user-select': 'none', }, '& optgroup > option': { 'color': 'rgb(var(--color-positive))', 'text-transform': 'none', 'font-size': '1.333333em', }, '& option': { 'user-select': 'none', }, }, }); }; /** * Component for inputting textual values. * * This component supports multiline input and adjusts its layout accordingly. */ export const MenuMultiSelect = React.forwardRef< MenuMultiSelectDerivedElement, MenuMultiSelectProps >(( { label, hint, indicator, size = 'medium' as const, border = false, block = false, variant = 'default' as const, hiddenLabel = false, className, startingHeight = '15rem', id: idProp, style, ...etcProps }, forwardedRef, ) => { const labelId = React.useId(); const id = useFallbackId(idProp); return (
{label && ( <> {' '} )} {hint && (
{hint}
)} {indicator && (
{indicator}
)} {border && ( )}
); }); MenuMultiSelect.displayName = 'MenuMultiSelect'; MenuMultiSelect.defaultProps = { label: undefined, hint: undefined, indicator: undefined, size: 'medium', border: false, block: false, variant: 'default', hiddenLabel: false, startingHeight: '15rem', };