import React, { ReactNode } from 'react' import classNames from 'classnames' import { Tooltip } from '../util/tooltip' export const getCharacterCount = (value: string): number => [...value].length export const isOverMaxLength = (value: string, maxLength: number): boolean => getCharacterCount(value) > maxLength const fieldClassName = 'block px-3.5 py-2.5 w-full text-sm dark:text-gray-300 rounded-md border border-gray-300 dark:border-gray-750 dark:bg-gray-750 focus:outline-none focus:ring-3 focus:ring-indigo-500/20 dark:focus:ring-indigo-500/25 focus:border-indigo-500' interface LabeledFieldProps { label: string id: string value: string onChange: (value: string) => void placeholder: string maxLength?: number } const LabeledField = ({ label, id, value, maxLength, children }: Pick & { children: ReactNode }) => (
{children} {maxLength !== undefined && ( )}
) export const LabeledTextInput = ({ label, id, value, onChange, placeholder, maxLength }: LabeledFieldProps) => ( onChange(e.target.value)} placeholder={placeholder} aria-describedby={maxLength !== undefined ? `${id}-counter` : undefined} className={fieldClassName} /> ) export const LabeledTextarea = ({ label, id, value, onChange, placeholder, maxLength, rows = 3 }: LabeledFieldProps & { rows?: number }) => (