import * as React from 'react'; import { TextControl, tailwind } from '@tesseract-design/web-base'; import { useFallbackId } from '@modal-sh/react-utils'; const { tw } = tailwind; const DateDropdownDerivedElementComponent = 'input'; /** * Derived HTML element of the {@link DateDropdown} component. */ export type DateDropdownDerivedElement = HTMLElementTagNameMap[ typeof DateDropdownDerivedElementComponent ]; /** * Props of the {@link DateDropdown} component. */ export interface DateDropdownProps extends Omit, 'size' | 'type' | 'label' | 'pattern'> { /** * 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, /** * 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, /** * Visual length of the input. */ length?: number, } export const dateDropdownPlugin: tailwind.PluginCreator = ({ addComponents }) => { addComponents({ '.date-dropdown': { '& > input::-webkit-calendar-picker-indicator': { 'background-image': 'none', 'position': 'absolute', 'bottom': '0', 'right': '0', 'height': '100%', 'padding': '0', 'aspect-ratio': '1 / 1', 'cursor': 'inherit', }, '&[data-size="small"] > input::-webkit-calendar-picker-indicator': { 'width': '2.5rem', }, '&[data-size="medium"] > input::-webkit-calendar-picker-indicator': { 'width': '3rem', }, '&[data-size="large"] > input::-webkit-calendar-picker-indicator': { 'width': '4rem', }, }, }); }; /** * Component for inputting date values. */ export const DateDropdown = React.forwardRef< DateDropdownDerivedElement, DateDropdownProps >(( { label, hint, size = 'medium' as const, border = false, block = false, variant = 'default' as const, hiddenLabel = false, className, id: idProp, style, length, ...etcProps }: DateDropdownProps, forwardedRef, ) => { const labelId = React.useId(); const id = useFallbackId(idProp); return (
{label && ( <> {' '} )} {hint && (
{hint}
)}
{border && ( )}
); }); DateDropdown.displayName = 'DateDropdown'; DateDropdown.defaultProps = { label: undefined, hint: undefined, size: 'medium', border: false, block: false, variant: 'default', hiddenLabel: false, length: undefined, };