@propellerads/input 2.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ComponentPropsWithRef, ReactNode, Ref, ComponentProps } from 'react';
|
|
3
|
-
import { FieldOwnProps as FieldOwnProps$1,
|
|
3
|
+
import { FieldOwnProps as FieldOwnProps$1, Field as Field$1, FieldDescription as FieldDescription$1, FieldGroup as FieldGroup$1, FieldLabel as FieldLabel$1 } from '@propellerads/label';
|
|
4
4
|
export { FieldDescriptionProps, FieldGroupProps, FieldLabelProps, FieldProps } from '@propellerads/label';
|
|
5
5
|
import { Button } from '@base-ui-components/react/button';
|
|
6
6
|
|
|
@@ -98,13 +98,13 @@ declare const InputGroupText: react.ForwardRefExoticComponent<Omit<react.Detaile
|
|
|
98
98
|
/** A small square button inside the box. Name it with `aria-label` when it is only an icon. */
|
|
99
99
|
declare const InputGroupButton: react.ForwardRefExoticComponent<Omit<InputGroupButtonProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
|
|
100
100
|
/** @deprecated Import `Field` from `@propellerads/label`. */
|
|
101
|
-
declare const Field:
|
|
101
|
+
declare const Field: typeof Field$1;
|
|
102
102
|
/** @deprecated Import `FieldLabel` from `@propellerads/label`. */
|
|
103
|
-
declare const FieldLabel:
|
|
103
|
+
declare const FieldLabel: typeof FieldLabel$1;
|
|
104
104
|
/** @deprecated Import `FieldDescription` from `@propellerads/label`. */
|
|
105
|
-
declare const FieldDescription:
|
|
105
|
+
declare const FieldDescription: typeof FieldDescription$1;
|
|
106
106
|
/** @deprecated Import `FieldGroup` from `@propellerads/label`. */
|
|
107
|
-
declare const FieldGroup:
|
|
107
|
+
declare const FieldGroup: typeof FieldGroup$1;
|
|
108
108
|
/**
|
|
109
109
|
* A text field, a password field or a number field, by `type`. A password gets
|
|
110
110
|
* the show-password button; a number stays the native input, so its value is
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { ControlField as a, Field as o, FieldDescription as s, FieldGroup as c,
|
|
|
6
6
|
import { forwardRef as _, useId as v, useState as y } from "react";
|
|
7
7
|
import { clsx as b } from "clsx";
|
|
8
8
|
import { jsx as x, jsxs as S } from "react/jsx-runtime";
|
|
9
|
-
import './index.css'
|
|
9
|
+
import './index.css';// src/cn.ts
|
|
10
10
|
var C = (...e) => b(e), w = {
|
|
11
11
|
Danger: "danger",
|
|
12
12
|
Warning: "warning"
|
|
@@ -260,7 +260,6 @@ var U = _((e, t) => {
|
|
|
260
260
|
});
|
|
261
261
|
});
|
|
262
262
|
U.displayName = "Textarea";
|
|
263
|
-
//#endregion
|
|
264
263
|
export { N as Field, F as FieldDescription, I as FieldGroup, P as FieldLabel, V as Input, V as default, T as InputGroup, O as InputGroupAddon, A as InputGroupButton, E as InputGroupInput, k as InputGroupText, D as InputGroupTextarea, w as InputTone, U as Textarea };
|
|
265
264
|
|
|
266
265
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/cn.ts","../src/types.ts","../src/index.tsx"],"sourcesContent":["import {type ClassValue, clsx} from 'clsx';\n\n/**\n * Joins class names. There is no tailwind-merge here on purpose: the input\n * ships its own stylesheet instead of utility classes, so there is nothing to\n * deduplicate.\n */\nconst cn = (...inputs: ClassValue[]): string => clsx(inputs);\n\nexport {cn};\n","import type {Button as BaseButton} from '@base-ui-components/react/button';\nimport type {FieldOwnProps as LabelFieldOwnProps} from '@propellerads/label';\nimport type {ComponentProps, ComponentPropsWithRef, ReactNode, Ref} from 'react';\n\n/** Which colour the errors are shown in. */\nexport const InputTone = {\n /** Something is wrong and has to be fixed. */\n Danger: 'danger',\n /** Something is allowed but worth a second look — a bid far above the market. */\n Warning: 'warning',\n} as const;\nexport type InputTone = (typeof InputTone)[keyof typeof InputTone];\n\nexport type InputGroupProps = ComponentPropsWithRef<'div'> & {\n /** Colour of the contour when the group is invalid. @default 'danger' */\n tone?: InputTone;\n /** Draws the contour in the tone. Set by `Input` when it has errors. */\n isInvalid?: boolean;\n};\n\nexport type InputGroupInputProps = ComponentPropsWithRef<'input'>;\n\nexport type InputGroupAddonProps = ComponentPropsWithRef<'div'> & {\n /**\n * Where the addon stands. `inline-*` beside the text of an input;\n * `block-*` in the top or bottom end corner of a textarea. @default 'inline-end'\n */\n align?: 'inline-start' | 'inline-end' | 'block-start' | 'block-end';\n};\n\nexport type InputGroupTextProps = ComponentPropsWithRef<'span'>;\n\nexport type InputGroupButtonProps = Omit<ComponentProps<typeof BaseButton>, 'className'> & {\n className?: string;\n};\n\n/**\n * The field around the control: its label and its message, laid out by Label's\n * `Field`. Given any of `label`, `description`, `error` or `warning`, the\n * control draws the field itself; `messageDisplay` is `compact` by default.\n */\ntype FieldOwnProps = LabelFieldOwnProps & {\n /** Sets `required` on the control. No mark: the optional fields are the ones marked. */\n isRequired?: boolean;\n};\n\n/** What `Input` and `Textarea` share: the field, the errors, the counter, the switch and the box. */\ntype FieldControlOwnProps = FieldOwnProps & {\n /**\n * @deprecated Use `error`, or `warning` for the warning tone. Shown behind\n * the `!` mark at the end of the field; a non-empty list also draws the\n * contour in the tone and sets `aria-invalid`.\n */\n errors?: ReadonlyArray<string>;\n /** @deprecated Use `warning` instead of `errors` with `tone=\"warning\"`. @default 'danger' */\n tone?: InputTone;\n /** Hides the `!` mark of `errors` and keeps the contour. Use `messageDisplay` with `error`. @default true */\n showErrors?: boolean;\n /** Called when the `!` mark of `errors` is clicked. */\n onErrorsClick?: () => void;\n /**\n * Shows how many characters are left. Typing past it is allowed and turns the\n * counter red — unlike the native `maxLength`, which stops the keyboard.\n */\n characterLimit?: number;\n /** Counts the value for `characterLimit`. @default trimmed length */\n countCharacters?: (value: string) => number;\n /** Switches the field off. The native `disabled` is not accepted, as on Button. */\n isDisabled?: boolean;\n /** On the group, the box that draws the contour. `className` stays on the control. */\n groupClassName?: string;\n groupStyle?: InputGroupProps['style'];\n};\n\nexport type InputProps = Omit<ComponentPropsWithRef<'input'>, 'disabled' | 'size'> &\n FieldControlOwnProps & {\n /** Before the text: an icon, a currency sign. */\n startAddon?: ReactNode;\n /** After the text, before the counter and the `!` mark. */\n endAddon?: ReactNode;\n /** Names the show-password button. @default 'Show password' */\n passwordToggleLabel?: string;\n ref?: Ref<HTMLInputElement>;\n };\n\nexport type InputGroupTextareaProps = ComponentPropsWithRef<'textarea'>;\n\nexport type TextareaProps = Omit<ComponentPropsWithRef<'textarea'>, 'disabled'> &\n FieldControlOwnProps & {\n /**\n * The height it starts at, in lines. The field grows with the text past it\n * where the browser can size a field by its content. @default 3\n */\n rows?: number;\n ref?: Ref<HTMLTextAreaElement>;\n };\n","import {Button as BaseButton} from '@base-ui-components/react/button';\nimport {Field as BaseField} from '@base-ui-components/react/field';\nimport {Input as BaseInput} from '@base-ui-components/react/input';\nimport ErrorLabel, {errorLabelTextId} from '@propellerads/error-label';\nimport {\n ControlField,\n type FieldDescriptionProps,\n type FieldGroupProps,\n type FieldLabelProps,\n FieldMark,\n type FieldProps,\n hasFieldProps,\n Field as LabelField,\n FieldDescription as LabelFieldDescription,\n FieldGroup as LabelFieldGroup,\n FieldLabel as LabelFieldLabel,\n MessageDisplay,\n splitFieldProps,\n useFieldMessage,\n useFieldTone,\n useIsInField,\n} from '@propellerads/label';\nimport {type ChangeEvent, type ComponentProps, forwardRef, type PropsWithoutRef, useId, useState} from 'react';\nimport './input.css';\nimport {cn} from './cn';\nimport {\n type InputGroupAddonProps,\n type InputGroupButtonProps,\n type InputGroupInputProps,\n type InputGroupProps,\n type InputGroupTextareaProps,\n type InputGroupTextProps,\n type InputProps,\n InputTone,\n type TextareaProps,\n} from './types';\n\n/*\n * The parts follow shadcn's Input Group, on Base UI instead of Radix. The group is\n * the box — contour, corners, focus ring — and the control inside it draws\n * nothing, so an icon, a counter or a button can stand in the same box. `Input`\n * and `Textarea` below are the group with the common parts filled in.\n */\n\n/** The box. Draws the contour and the focus ring for the control inside it. */\nconst InputGroup = forwardRef<HTMLDivElement, PropsWithoutRef<InputGroupProps>>(\n ({tone = InputTone.Danger, isInvalid = false, className, ...props}, ref) => (\n <div\n {...props}\n ref={ref}\n data-tone={tone}\n data-invalid={isInvalid || undefined}\n className={cn('input-group', className)}\n />\n ),\n);\nInputGroup.displayName = 'InputGroup';\n\n/** The `<input>` inside a group. Takes every native prop. */\nconst InputGroupInput = forwardRef<HTMLInputElement, PropsWithoutRef<InputGroupInputProps>>(\n ({className, ...props}, ref) => <BaseInput {...props} ref={ref} className={cn('input-group__control', className)} />,\n);\nInputGroupInput.displayName = 'InputGroupInput';\n\n/** The `<textarea>` inside a group. Takes every native prop. */\nconst InputGroupTextarea = forwardRef<HTMLTextAreaElement, PropsWithoutRef<InputGroupTextareaProps>>(\n ({className, ...props}, ref) => (\n <BaseField.Control\n // Base UI types the control as an <input>, and renders a textarea through\n // `render` the way its own docs do; the props are the textarea's.\n {...(props as unknown as ComponentProps<typeof BaseField.Control>)}\n ref={ref as unknown as ComponentProps<typeof BaseField.Control>['ref']}\n render={<textarea />}\n className={cn('input-group__control', 'input-group__control--multiline', className)}\n />\n ),\n);\nInputGroupTextarea.displayName = 'InputGroupTextarea';\n\n/** Something that stands beside the text: an icon, a unit, a button. */\nconst InputGroupAddon = forwardRef<HTMLDivElement, PropsWithoutRef<InputGroupAddonProps>>(\n ({align = 'inline-end', className, ...props}, ref) => (\n <div\n {...props}\n ref={ref}\n data-align={align}\n className={cn('input-group__addon', `input-group__addon--${align}`, className)}\n />\n ),\n);\nInputGroupAddon.displayName = 'InputGroupAddon';\n\n/** Quiet text inside the box: a unit, a prefix, a counter. */\nconst InputGroupText = forwardRef<HTMLSpanElement, PropsWithoutRef<InputGroupTextProps>>(\n ({className, ...props}, ref) => <span {...props} ref={ref} className={cn('input-group__text', className)} />,\n);\nInputGroupText.displayName = 'InputGroupText';\n\n/** A small square button inside the box. Name it with `aria-label` when it is only an icon. */\nconst InputGroupButton = forwardRef<HTMLButtonElement, PropsWithoutRef<InputGroupButtonProps>>(\n ({className, ...props}, ref) => (\n <BaseButton type=\"button\" {...props} ref={ref} className={cn('input-group__button', className)} />\n ),\n);\nInputGroupButton.displayName = 'InputGroupButton';\n\nconst EyeIcon = ({isOpen}: {isOpen: boolean}) => (\n <svg viewBox=\"0 0 16 16\" width=\"16\" height=\"16\" fill=\"none\" aria-hidden=\"true\">\n <path\n d=\"M1.5 8S4 3.5 8 3.5 14.5 8 14.5 8 12 12.5 8 12.5 1.5 8 1.5 8Z\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n strokeLinejoin=\"round\"\n />\n <circle cx=\"8\" cy=\"8\" r=\"2\" stroke=\"currentColor\" strokeWidth=\"1.5\" />\n {!isOpen && <path d=\"M2.5 13.5l11-11\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />}\n </svg>\n);\n\nconst defaultCount = (value: string): number => value.trim().length;\n\n/*\n * The field moved to @propellerads/label, which every form control builds on.\n * The names stay here so the forms that import them from Input keep working.\n */\n\n/** @deprecated Import `Field` from `@propellerads/label`. */\nconst Field = LabelField;\n/** @deprecated Import `FieldLabel` from `@propellerads/label`. */\nconst FieldLabel = LabelFieldLabel;\n/** @deprecated Import `FieldDescription` from `@propellerads/label`. */\nconst FieldDescription = LabelFieldDescription;\n/** @deprecated Import `FieldGroup` from `@propellerads/label`. */\nconst FieldGroup = LabelFieldGroup;\n\ntype ControlState<E extends HTMLInputElement | HTMLTextAreaElement> = {\n id?: string;\n errors: ReadonlyArray<string>;\n characterLimit?: number;\n countCharacters: (value: string) => number;\n value?: ChangeEvent<E>['target']['value'] | number | ReadonlyArray<string>;\n defaultValue?: ChangeEvent<E>['target']['value'] | number | ReadonlyArray<string>;\n onChange?: (event: ChangeEvent<E>) => void;\n describedBy?: string;\n};\n\n/**\n * What `Input` and `Textarea` work out the same way: the key the error label is\n * named by, whether the control has to be pointed at the errors by hand, and\n * what is left under the character limit.\n */\nconst useControlState = <E extends HTMLInputElement | HTMLTextAreaElement>({\n id,\n errors,\n characterLimit,\n countCharacters,\n value,\n defaultValue,\n onChange,\n describedBy,\n}: ControlState<E>) => {\n const isInField = useIsInField();\n const fieldMessage = useFieldMessage();\n // The field's error or warning draws the contour in its tone; Base UI sets `aria-invalid` for the error.\n const fieldTone = useFieldTone();\n const fallbackKey = useId();\n const errorsKey = id ?? fallbackKey;\n // The counter needs the text even when the control is not controlled.\n const [uncontrolledValue, setUncontrolledValue] = useState<string>(String(defaultValue ?? ''));\n\n const isInvalid = errors.length > 0;\n // The mark of the field's message stands at the end of the box in the compact display.\n const hasFieldMark = fieldMessage?.display === MessageDisplay.Compact;\n const text = value === undefined ? uncontrolledValue : String(value);\n const remaining = characterLimit === undefined ? undefined : characterLimit - countCharacters(text);\n\n const handleChange = (event: ChangeEvent<E>): void => {\n if (value === undefined) {\n setUncontrolledValue(event.target.value);\n }\n\n onChange?.(event);\n };\n\n const ariaProps = {\n // Left out rather than `undefined` when valid: a Field marked invalid writes its own.\n ...(isInvalid ? {'aria-invalid': true} : {}),\n // Inside a Field the description registers itself; outside one it is pointed at here.\n ...(isInvalid && !isInField ? {'aria-describedby': cn(describedBy, errorLabelTextId(errorsKey))} : {}),\n };\n\n return {errorsKey, isInField, isInvalid, fieldTone, hasFieldMark, remaining, handleChange, ariaProps};\n};\n\nconst Counter = ({remaining}: {remaining: number}) => (\n <InputGroupText className=\"input-group__counter\" data-over={remaining < 0 || undefined}>\n {remaining}\n </InputGroupText>\n);\n\n/**\n * The errors as hidden text inside a Field, as a Base UI description, so the\n * control is described by them next to the field's own description. Outside a\n * Field the error label writes this text and the control is pointed at it.\n */\nconst HiddenErrors = ({errorsKey, errors}: {errorsKey: string; errors: ReadonlyArray<string>}) => {\n const isInField = useIsInField();\n const text = errors.join('. ');\n\n // Base UI throws for a description with no Field around it.\n return isInField ? (\n <BaseField.Description id={errorLabelTextId(errorsKey)} hidden>\n {text}\n </BaseField.Description>\n ) : (\n <span id={errorLabelTextId(errorsKey)} hidden>\n {text}\n </span>\n );\n};\n\n/** The box of `Input`: the control, its addons and the old `errors` mark. */\nconst InputBox = forwardRef<HTMLInputElement, PropsWithoutRef<InputProps>>(\n (\n {\n type = 'text',\n id,\n errors = [],\n tone = InputTone.Danger,\n showErrors = true,\n onErrorsClick,\n characterLimit,\n countCharacters = defaultCount,\n isDisabled = false,\n startAddon,\n endAddon,\n passwordToggleLabel = 'Show password',\n groupClassName,\n groupStyle,\n value,\n defaultValue,\n onChange,\n ...props\n },\n ref,\n ) => {\n const [isRevealed, setRevealed] = useState<boolean>(false);\n const {errorsKey, isInField, isInvalid, fieldTone, hasFieldMark, remaining, handleChange, ariaProps} =\n useControlState<HTMLInputElement>({\n id,\n errors,\n characterLimit,\n countCharacters,\n value,\n defaultValue,\n onChange,\n describedBy: props['aria-describedby'],\n });\n\n const isPassword = type === 'password';\n\n return (\n <InputGroup\n tone={fieldTone ?? tone}\n isInvalid={isInvalid || fieldTone !== undefined}\n className={groupClassName}\n style={groupStyle}\n >\n {startAddon !== undefined && <InputGroupAddon align=\"inline-start\">{startAddon}</InputGroupAddon>}\n <InputGroupInput\n {...props}\n ref={ref}\n // Inside a Field the id is Base UI's, so the label finds the input.\n id={id}\n type={isPassword && isRevealed ? 'text' : type}\n value={value}\n defaultValue={defaultValue}\n onChange={handleChange}\n disabled={isDisabled}\n {...ariaProps}\n />\n {(endAddon !== undefined ||\n isPassword ||\n remaining !== undefined ||\n (isInvalid && showErrors) ||\n hasFieldMark) && (\n <InputGroupAddon align=\"inline-end\">\n {endAddon}\n {isPassword && (\n <InputGroupButton\n aria-label={passwordToggleLabel}\n aria-pressed={isRevealed}\n disabled={isDisabled}\n onClick={() => setRevealed((previous) => !previous)}\n >\n <EyeIcon isOpen={isRevealed} />\n </InputGroupButton>\n )}\n {remaining !== undefined && <Counter remaining={remaining} />}\n {isInvalid && showErrors && (\n <ErrorLabel\n elementId={errorsKey}\n errors={errors}\n tone={tone}\n onClick={onErrorsClick}\n hasDescription={!isInField}\n />\n )}\n <FieldMark />\n </InputGroupAddon>\n )}\n {isInvalid && (isInField || !showErrors) && <HiddenErrors errorsKey={errorsKey} errors={errors} />}\n </InputGroup>\n );\n },\n);\nInputBox.displayName = 'InputBox';\n\n/**\n * A text field, a password field or a number field, by `type`. A password gets\n * the show-password button; a number stays the native input, so its value is\n * the string the user typed, a comma included.\n *\n * With a `label`, a `description`, an `error` or a `warning` it draws its\n * field: the label on top, on the left or hidden, and the message behind a mark\n * at its end or, with `messageDisplay=\"line\"`, under it.\n */\nconst Input = forwardRef<HTMLInputElement, PropsWithoutRef<InputProps>>((props, ref) => {\n const {field, rest} = splitFieldProps(props);\n const {isRequired, ...control} = rest;\n const required = isRequired || control.required;\n if (!hasFieldProps(props)) {\n return <InputBox {...control} ref={ref} required={required} />;\n }\n return (\n <ControlField field={field} errors={control.errors} tone={control.tone} isDisabled={control.isDisabled}>\n {/* The errors are the field's now, written by it. */}\n <InputBox {...control} errors={undefined} ref={ref} required={required} />\n </ControlField>\n );\n});\nInput.displayName = 'Input';\n\n/**\n * The box of `Textarea`, the same as `Input`'s. The `!` mark sits in\n * the top corner, next to the first line; the counter in the bottom one, next to\n * where the typing is.\n */\nconst TextareaBox = forwardRef<HTMLTextAreaElement, PropsWithoutRef<TextareaProps>>(\n (\n {\n id,\n rows = 3,\n errors = [],\n tone = InputTone.Danger,\n showErrors = true,\n onErrorsClick,\n characterLimit,\n countCharacters = defaultCount,\n isDisabled = false,\n groupClassName,\n groupStyle,\n value,\n defaultValue,\n onChange,\n ...props\n },\n ref,\n ) => {\n const {errorsKey, isInField, isInvalid, fieldTone, hasFieldMark, remaining, handleChange, ariaProps} =\n useControlState<HTMLTextAreaElement>({\n id,\n errors,\n characterLimit,\n countCharacters,\n value,\n defaultValue,\n onChange,\n describedBy: props['aria-describedby'],\n });\n\n return (\n <InputGroup\n tone={fieldTone ?? tone}\n isInvalid={isInvalid || fieldTone !== undefined}\n className={cn('input-group--multiline', groupClassName)}\n style={groupStyle}\n data-has-errors={(isInvalid && showErrors) || hasFieldMark || undefined}\n data-has-counter={remaining !== undefined || undefined}\n >\n <InputGroupTextarea\n {...props}\n ref={ref}\n id={id}\n rows={rows}\n value={value}\n defaultValue={defaultValue}\n onChange={handleChange}\n disabled={isDisabled}\n {...ariaProps}\n />\n {((isInvalid && showErrors) || hasFieldMark) && (\n <InputGroupAddon align=\"block-start\">\n {isInvalid && showErrors && (\n <ErrorLabel\n elementId={errorsKey}\n errors={errors}\n tone={tone}\n onClick={onErrorsClick}\n hasDescription={!isInField}\n />\n )}\n <FieldMark />\n </InputGroupAddon>\n )}\n {remaining !== undefined && (\n <InputGroupAddon align=\"block-end\">\n <Counter remaining={remaining} />\n </InputGroupAddon>\n )}\n {isInvalid && (isInField || !showErrors) && <HiddenErrors errorsKey={errorsKey} errors={errors} />}\n </InputGroup>\n );\n },\n);\nTextareaBox.displayName = 'TextareaBox';\n\n/** A field for more than a line. Draws its field the way `Input` does. */\nconst Textarea = forwardRef<HTMLTextAreaElement, PropsWithoutRef<TextareaProps>>((props, ref) => {\n const {field, rest} = splitFieldProps(props);\n const {isRequired, ...control} = rest;\n const required = isRequired || control.required;\n if (!hasFieldProps(props)) {\n return <TextareaBox {...control} ref={ref} required={required} />;\n }\n return (\n <ControlField field={field} errors={control.errors} tone={control.tone} isDisabled={control.isDisabled}>\n <TextareaBox {...control} errors={undefined} ref={ref} required={required} />\n </ControlField>\n );\n});\nTextarea.displayName = 'Textarea';\n\nexport default Input;\n\nexport type {\n FieldDescriptionProps,\n FieldGroupProps,\n FieldLabelProps,\n FieldProps,\n InputGroupAddonProps,\n InputGroupButtonProps,\n InputGroupInputProps,\n InputGroupProps,\n InputGroupTextareaProps,\n InputGroupTextProps,\n InputProps,\n TextareaProps,\n};\nexport {\n Field,\n FieldDescription,\n FieldGroup,\n FieldLabel,\n Input,\n InputGroup,\n InputGroupAddon,\n InputGroupButton,\n InputGroupInput,\n InputGroupText,\n InputGroupTextarea,\n InputTone,\n Textarea,\n};\n"],"mappings":";;;;;;;;;AAOA,IAAM,KAAM,GAAG,MAAiC,EAAK,EAAO,ECF/C,IAAY;CAEvB,QAAQ;CAER,SAAS;CACV,ECmCK,IAAa,GAChB,EAAC,UAAO,EAAU,QAAQ,eAAY,IAAO,cAAW,GAAG,KAAQ,MAClE,kBAAC,OAAD;CACE,GAAI;CACC;CACL,aAAW;CACX,gBAAc,KAAa,KAAA;CAC3B,WAAW,EAAG,eAAe,EAAU;CACvC,CAAA,CAEL;AACD,EAAW,cAAc;AAGzB,IAAM,IAAkB,GACrB,EAAC,cAAW,GAAG,KAAQ,MAAQ,kBAAC,GAAD;CAAW,GAAI;CAAY;CAAK,WAAW,EAAG,wBAAwB,EAAU;CAAI,CAAA,CACrH;AACD,EAAgB,cAAc;AAG9B,IAAM,IAAqB,GACxB,EAAC,cAAW,GAAG,KAAQ,MACtB,kBAAC,EAAU,SAAX;CAGE,GAAK;CACA;CACL,QAAQ,kBAAC,YAAD,EAAY,CAAA;CACpB,WAAW,EAAG,wBAAwB,mCAAmC,EAAU;CACnF,CAAA,CAEL;AACD,EAAmB,cAAc;AAGjC,IAAM,IAAkB,GACrB,EAAC,WAAQ,cAAc,cAAW,GAAG,KAAQ,MAC5C,kBAAC,OAAD;CACE,GAAI;CACC;CACL,cAAY;CACZ,WAAW,EAAG,sBAAsB,uBAAuB,KAAS,EAAU;CAC9E,CAAA,CAEL;AACD,EAAgB,cAAc;AAG9B,IAAM,IAAiB,GACpB,EAAC,cAAW,GAAG,KAAQ,MAAQ,kBAAC,QAAD;CAAM,GAAI;CAAY;CAAK,WAAW,EAAG,qBAAqB,EAAU;CAAI,CAAA,CAC7G;AACD,EAAe,cAAc;AAG7B,IAAM,IAAmB,GACtB,EAAC,cAAW,GAA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B,KAAA;EAC9D,oBAAkB,MAAc,KAAA,KAAa,KAAA;YAN/C;GAQE,kBAAC,GAAD;IACE,GAAI;IACC;IACD;IACE;IACC;IACO;IACd,UAAU;IACV,UAAU;IACV,GAAI;IACJ,CAAA;IACC,KAAa,KAAe,MAC7B,kBAAC,GAAD;IAAiB,OAAM;cAAvB,CACG,KAAa,KACZ,kBAAC,GAAD;KACE,WAAW;KACH;KACF;KACN,SAAS;KACT,gBAAgB,CAAC;KACjB,CAAA,EAEJ,kBAAC,GAAD,EAAa,CAAA,CACG;;GAEnB,MAAc,KAAA,KACb,kBAAC,GAAD;IAAiB,OAAM;cACrB,kBAAC,GAAD,EAAoB,cAAa,CAAA;IACjB,CAAA;GAEnB,MAAc,KAAa,CAAC,MAAe,kBAAC,GAAD;IAAyB;IAAmB;IAAU,CAAA;GACvF;;EAGlB;AACD,EAAY,cAAc;AAG1B,IAAM,IAAW,GAAiE,GAAO,MAAQ;CAC/F,IAAM,EAAC,UAAO,YAAQ,EAAgB,EAAM,EACtC,EAAC,eAAY,GAAG,MAAW,GAC3B,IAAW,KAAc,EAAQ;CAIvC,OAHK,EAAc,EAAM,GAIvB,kBAAC,GAAD;EAAqB;EAAO,QAAQ,EAAQ;EAAQ,MAAM,EAAQ;EAAM,YAAY,EAAQ;YAC1F,kBAAC,GAAD;GAAa,GAAI;GAAS,QAAQ,KAAA;GAAgB;GAAe;GAAY,CAAA;EAChE,CAAA,GALR,kBAAC,GAAD;EAAa,GAAI;EAAc;EAAe;EAAY,CAAA;EAOnE;AACF,EAAS,cAAc"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["BaseInput","BaseField","BaseButton","LabelField","LabelFieldLabel","LabelFieldDescription","LabelFieldGroup","Field$1","Input$1","ErrorLabel","Field$2","FieldDescription$1","FieldGroup$1","FieldLabel$1","cn","inputs","clsx","InputTone","InputGroup","forwardRef","props","tone","isInvalid","className","InputGroupInput","InputGroupTextarea","InputGroupAddon","align","InputGroupText","InputGroupButton","Button","EyeIcon","isOpen","defaultCount","value","Field","FieldLabel","FieldDescription","FieldGroup","useControlState","isInField","useIsInField","fieldMessage","useFieldMessage","fieldTone","useFieldTone","fallbackKey","useId","errorsKey","id","uncontrolledValue","setUncontrolledValue","useState","defaultValue","errors","MessageDisplay","characterLimit","countCharacters","event","onChange","describedBy","errorLabelTextId","Counter","remaining","HiddenErrors","text","jsx","InputBox","isRevealed","setRevealed","isPassword","type","groupClassName","groupStyle","startAddon","handleChange","isDisabled","ariaProps","endAddon","showErrors","hasFieldMark","passwordToggleLabel","previous","onErrorsClick","FieldMark","Input","splitFieldProps","control","rest","required","isRequired","hasFieldProps","ControlField","TextareaBox","Textarea"],"sources":["../src/cn.ts","../src/types.ts","../src/index.tsx"],"sourcesContent":["import {type ClassValue, clsx} from 'clsx';\n\n/**\n * Joins class names. There is no tailwind-merge here on purpose: the input\n * ships its own stylesheet instead of utility classes, so there is nothing to\n * deduplicate.\n */\nconst cn = (...inputs: ClassValue[]): string => clsx(inputs);\n\nexport {cn};\n","import type {Button as BaseButton} from '@base-ui-components/react/button';\nimport type {FieldOwnProps as LabelFieldOwnProps} from '@propellerads/label';\nimport type {ComponentProps, ComponentPropsWithRef, ReactNode, Ref} from 'react';\n\n/** Which colour the errors are shown in. */\nexport const InputTone = {\n /** Something is wrong and has to be fixed. */\n Danger: 'danger',\n /** Something is allowed but worth a second look — a bid far above the market. */\n Warning: 'warning',\n} as const;\nexport type InputTone = (typeof InputTone)[keyof typeof InputTone];\n\nexport type InputGroupProps = ComponentPropsWithRef<'div'> & {\n /** Colour of the contour when the group is invalid. @default 'danger' */\n tone?: InputTone;\n /** Draws the contour in the tone. Set by `Input` when it has errors. */\n isInvalid?: boolean;\n};\n\nexport type InputGroupInputProps = ComponentPropsWithRef<'input'>;\n\nexport type InputGroupAddonProps = ComponentPropsWithRef<'div'> & {\n /**\n * Where the addon stands. `inline-*` beside the text of an input;\n * `block-*` in the top or bottom end corner of a textarea. @default 'inline-end'\n */\n align?: 'inline-start' | 'inline-end' | 'block-start' | 'block-end';\n};\n\nexport type InputGroupTextProps = ComponentPropsWithRef<'span'>;\n\nexport type InputGroupButtonProps = Omit<ComponentProps<typeof BaseButton>, 'className'> & {\n className?: string;\n};\n\n/**\n * The field around the control: its label and its message, laid out by Label's\n * `Field`. Given any of `label`, `description`, `error` or `warning`, the\n * control draws the field itself; `messageDisplay` is `compact` by default.\n */\ntype FieldOwnProps = LabelFieldOwnProps & {\n /** Sets `required` on the control. No mark: the optional fields are the ones marked. */\n isRequired?: boolean;\n};\n\n/** What `Input` and `Textarea` share: the field, the errors, the counter, the switch and the box. */\ntype FieldControlOwnProps = FieldOwnProps & {\n /**\n * @deprecated Use `error`, or `warning` for the warning tone. Shown behind\n * the `!` mark at the end of the field; a non-empty list also draws the\n * contour in the tone and sets `aria-invalid`.\n */\n errors?: ReadonlyArray<string>;\n /** @deprecated Use `warning` instead of `errors` with `tone=\"warning\"`. @default 'danger' */\n tone?: InputTone;\n /** Hides the `!` mark of `errors` and keeps the contour. Use `messageDisplay` with `error`. @default true */\n showErrors?: boolean;\n /** Called when the `!` mark of `errors` is clicked. */\n onErrorsClick?: () => void;\n /**\n * Shows how many characters are left. Typing past it is allowed and turns the\n * counter red — unlike the native `maxLength`, which stops the keyboard.\n */\n characterLimit?: number;\n /** Counts the value for `characterLimit`. @default trimmed length */\n countCharacters?: (value: string) => number;\n /** Switches the field off. The native `disabled` is not accepted, as on Button. */\n isDisabled?: boolean;\n /** On the group, the box that draws the contour. `className` stays on the control. */\n groupClassName?: string;\n groupStyle?: InputGroupProps['style'];\n};\n\nexport type InputProps = Omit<ComponentPropsWithRef<'input'>, 'disabled' | 'size'> &\n FieldControlOwnProps & {\n /** Before the text: an icon, a currency sign. */\n startAddon?: ReactNode;\n /** After the text, before the counter and the `!` mark. */\n endAddon?: ReactNode;\n /** Names the show-password button. @default 'Show password' */\n passwordToggleLabel?: string;\n ref?: Ref<HTMLInputElement>;\n };\n\nexport type InputGroupTextareaProps = ComponentPropsWithRef<'textarea'>;\n\nexport type TextareaProps = Omit<ComponentPropsWithRef<'textarea'>, 'disabled'> &\n FieldControlOwnProps & {\n /**\n * The height it starts at, in lines. The field grows with the text past it\n * where the browser can size a field by its content. @default 3\n */\n rows?: number;\n ref?: Ref<HTMLTextAreaElement>;\n };\n","import {Button as BaseButton} from '@base-ui-components/react/button';\nimport {Field as BaseField} from '@base-ui-components/react/field';\nimport {Input as BaseInput} from '@base-ui-components/react/input';\nimport ErrorLabel, {errorLabelTextId} from '@propellerads/error-label';\nimport {\n ControlField,\n type FieldDescriptionProps,\n type FieldGroupProps,\n type FieldLabelProps,\n FieldMark,\n type FieldProps,\n hasFieldProps,\n Field as LabelField,\n FieldDescription as LabelFieldDescription,\n FieldGroup as LabelFieldGroup,\n FieldLabel as LabelFieldLabel,\n MessageDisplay,\n splitFieldProps,\n useFieldMessage,\n useFieldTone,\n useIsInField,\n} from '@propellerads/label';\nimport {type ChangeEvent, type ComponentProps, forwardRef, type PropsWithoutRef, useId, useState} from 'react';\nimport './input.css';\nimport {cn} from './cn';\nimport {\n type InputGroupAddonProps,\n type InputGroupButtonProps,\n type InputGroupInputProps,\n type InputGroupProps,\n type InputGroupTextareaProps,\n type InputGroupTextProps,\n type InputProps,\n InputTone,\n type TextareaProps,\n} from './types';\n\n/*\n * The parts follow shadcn's Input Group, on Base UI instead of Radix. The group is\n * the box — contour, corners, focus ring — and the control inside it draws\n * nothing, so an icon, a counter or a button can stand in the same box. `Input`\n * and `Textarea` below are the group with the common parts filled in.\n */\n\n/** The box. Draws the contour and the focus ring for the control inside it. */\nconst InputGroup = forwardRef<HTMLDivElement, PropsWithoutRef<InputGroupProps>>(\n ({tone = InputTone.Danger, isInvalid = false, className, ...props}, ref) => (\n <div\n {...props}\n ref={ref}\n data-tone={tone}\n data-invalid={isInvalid || undefined}\n className={cn('input-group', className)}\n />\n ),\n);\nInputGroup.displayName = 'InputGroup';\n\n/** The `<input>` inside a group. Takes every native prop. */\nconst InputGroupInput = forwardRef<HTMLInputElement, PropsWithoutRef<InputGroupInputProps>>(\n ({className, ...props}, ref) => <BaseInput {...props} ref={ref} className={cn('input-group__control', className)} />,\n);\nInputGroupInput.displayName = 'InputGroupInput';\n\n/** The `<textarea>` inside a group. Takes every native prop. */\nconst InputGroupTextarea = forwardRef<HTMLTextAreaElement, PropsWithoutRef<InputGroupTextareaProps>>(\n ({className, ...props}, ref) => (\n <BaseField.Control\n // Base UI types the control as an <input>, and renders a textarea through\n // `render` the way its own docs do; the props are the textarea's.\n {...(props as unknown as ComponentProps<typeof BaseField.Control>)}\n ref={ref as unknown as ComponentProps<typeof BaseField.Control>['ref']}\n render={<textarea />}\n className={cn('input-group__control', 'input-group__control--multiline', className)}\n />\n ),\n);\nInputGroupTextarea.displayName = 'InputGroupTextarea';\n\n/** Something that stands beside the text: an icon, a unit, a button. */\nconst InputGroupAddon = forwardRef<HTMLDivElement, PropsWithoutRef<InputGroupAddonProps>>(\n ({align = 'inline-end', className, ...props}, ref) => (\n <div\n {...props}\n ref={ref}\n data-align={align}\n className={cn('input-group__addon', `input-group__addon--${align}`, className)}\n />\n ),\n);\nInputGroupAddon.displayName = 'InputGroupAddon';\n\n/** Quiet text inside the box: a unit, a prefix, a counter. */\nconst InputGroupText = forwardRef<HTMLSpanElement, PropsWithoutRef<InputGroupTextProps>>(\n ({className, ...props}, ref) => <span {...props} ref={ref} className={cn('input-group__text', className)} />,\n);\nInputGroupText.displayName = 'InputGroupText';\n\n/** A small square button inside the box. Name it with `aria-label` when it is only an icon. */\nconst InputGroupButton = forwardRef<HTMLButtonElement, PropsWithoutRef<InputGroupButtonProps>>(\n ({className, ...props}, ref) => (\n <BaseButton type=\"button\" {...props} ref={ref} className={cn('input-group__button', className)} />\n ),\n);\nInputGroupButton.displayName = 'InputGroupButton';\n\nconst EyeIcon = ({isOpen}: {isOpen: boolean}) => (\n <svg viewBox=\"0 0 16 16\" width=\"16\" height=\"16\" fill=\"none\" aria-hidden=\"true\">\n <path\n d=\"M1.5 8S4 3.5 8 3.5 14.5 8 14.5 8 12 12.5 8 12.5 1.5 8 1.5 8Z\"\n stroke=\"currentColor\"\n strokeWidth=\"1.5\"\n strokeLinejoin=\"round\"\n />\n <circle cx=\"8\" cy=\"8\" r=\"2\" stroke=\"currentColor\" strokeWidth=\"1.5\" />\n {!isOpen && <path d=\"M2.5 13.5l11-11\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />}\n </svg>\n);\n\nconst defaultCount = (value: string): number => value.trim().length;\n\n/*\n * The field moved to @propellerads/label, which every form control builds on.\n * The names stay here so the forms that import them from Input keep working.\n */\n\n/** @deprecated Import `Field` from `@propellerads/label`. */\nconst Field: typeof LabelField = LabelField;\n/** @deprecated Import `FieldLabel` from `@propellerads/label`. */\nconst FieldLabel: typeof LabelFieldLabel = LabelFieldLabel;\n/** @deprecated Import `FieldDescription` from `@propellerads/label`. */\nconst FieldDescription: typeof LabelFieldDescription = LabelFieldDescription;\n/** @deprecated Import `FieldGroup` from `@propellerads/label`. */\nconst FieldGroup: typeof LabelFieldGroup = LabelFieldGroup;\n\ntype ControlState<E extends HTMLInputElement | HTMLTextAreaElement> = {\n id?: string;\n errors: ReadonlyArray<string>;\n characterLimit?: number;\n countCharacters: (value: string) => number;\n value?: ChangeEvent<E>['target']['value'] | number | ReadonlyArray<string>;\n defaultValue?: ChangeEvent<E>['target']['value'] | number | ReadonlyArray<string>;\n onChange?: (event: ChangeEvent<E>) => void;\n describedBy?: string;\n};\n\n/**\n * What `Input` and `Textarea` work out the same way: the key the error label is\n * named by, whether the control has to be pointed at the errors by hand, and\n * what is left under the character limit.\n */\nconst useControlState = <E extends HTMLInputElement | HTMLTextAreaElement>({\n id,\n errors,\n characterLimit,\n countCharacters,\n value,\n defaultValue,\n onChange,\n describedBy,\n}: ControlState<E>) => {\n const isInField = useIsInField();\n const fieldMessage = useFieldMessage();\n // The field's error or warning draws the contour in its tone; Base UI sets `aria-invalid` for the error.\n const fieldTone = useFieldTone();\n const fallbackKey = useId();\n const errorsKey = id ?? fallbackKey;\n // The counter needs the text even when the control is not controlled.\n const [uncontrolledValue, setUncontrolledValue] = useState<string>(String(defaultValue ?? ''));\n\n const isInvalid = errors.length > 0;\n // The mark of the field's message stands at the end of the box in the compact display.\n const hasFieldMark = fieldMessage?.display === MessageDisplay.Compact;\n const text = value === undefined ? uncontrolledValue : String(value);\n const remaining = characterLimit === undefined ? undefined : characterLimit - countCharacters(text);\n\n const handleChange = (event: ChangeEvent<E>): void => {\n if (value === undefined) {\n setUncontrolledValue(event.target.value);\n }\n\n onChange?.(event);\n };\n\n const ariaProps = {\n // Left out rather than `undefined` when valid: a Field marked invalid writes its own.\n ...(isInvalid ? {'aria-invalid': true} : {}),\n // Inside a Field the description registers itself; outside one it is pointed at here.\n ...(isInvalid && !isInField ? {'aria-describedby': cn(describedBy, errorLabelTextId(errorsKey))} : {}),\n };\n\n return {errorsKey, isInField, isInvalid, fieldTone, hasFieldMark, remaining, handleChange, ariaProps};\n};\n\nconst Counter = ({remaining}: {remaining: number}) => (\n <InputGroupText className=\"input-group__counter\" data-over={remaining < 0 || undefined}>\n {remaining}\n </InputGroupText>\n);\n\n/**\n * The errors as hidden text inside a Field, as a Base UI description, so the\n * control is described by them next to the field's own description. Outside a\n * Field the error label writes this text and the control is pointed at it.\n */\nconst HiddenErrors = ({errorsKey, errors}: {errorsKey: string; errors: ReadonlyArray<string>}) => {\n const isInField = useIsInField();\n const text = errors.join('. ');\n\n // Base UI throws for a description with no Field around it.\n return isInField ? (\n <BaseField.Description id={errorLabelTextId(errorsKey)} hidden>\n {text}\n </BaseField.Description>\n ) : (\n <span id={errorLabelTextId(errorsKey)} hidden>\n {text}\n </span>\n );\n};\n\n/** The box of `Input`: the control, its addons and the old `errors` mark. */\nconst InputBox = forwardRef<HTMLInputElement, PropsWithoutRef<InputProps>>(\n (\n {\n type = 'text',\n id,\n errors = [],\n tone = InputTone.Danger,\n showErrors = true,\n onErrorsClick,\n characterLimit,\n countCharacters = defaultCount,\n isDisabled = false,\n startAddon,\n endAddon,\n passwordToggleLabel = 'Show password',\n groupClassName,\n groupStyle,\n value,\n defaultValue,\n onChange,\n ...props\n },\n ref,\n ) => {\n const [isRevealed, setRevealed] = useState<boolean>(false);\n const {errorsKey, isInField, isInvalid, fieldTone, hasFieldMark, remaining, handleChange, ariaProps} =\n useControlState<HTMLInputElement>({\n id,\n errors,\n characterLimit,\n countCharacters,\n value,\n defaultValue,\n onChange,\n describedBy: props['aria-describedby'],\n });\n\n const isPassword = type === 'password';\n\n return (\n <InputGroup\n tone={fieldTone ?? tone}\n isInvalid={isInvalid || fieldTone !== undefined}\n className={groupClassName}\n style={groupStyle}\n >\n {startAddon !== undefined && <InputGroupAddon align=\"inline-start\">{startAddon}</InputGroupAddon>}\n <InputGroupInput\n {...props}\n ref={ref}\n // Inside a Field the id is Base UI's, so the label finds the input.\n id={id}\n type={isPassword && isRevealed ? 'text' : type}\n value={value}\n defaultValue={defaultValue}\n onChange={handleChange}\n disabled={isDisabled}\n {...ariaProps}\n />\n {(endAddon !== undefined ||\n isPassword ||\n remaining !== undefined ||\n (isInvalid && showErrors) ||\n hasFieldMark) && (\n <InputGroupAddon align=\"inline-end\">\n {endAddon}\n {isPassword && (\n <InputGroupButton\n aria-label={passwordToggleLabel}\n aria-pressed={isRevealed}\n disabled={isDisabled}\n onClick={() => setRevealed((previous) => !previous)}\n >\n <EyeIcon isOpen={isRevealed} />\n </InputGroupButton>\n )}\n {remaining !== undefined && <Counter remaining={remaining} />}\n {isInvalid && showErrors && (\n <ErrorLabel\n elementId={errorsKey}\n errors={errors}\n tone={tone}\n onClick={onErrorsClick}\n hasDescription={!isInField}\n />\n )}\n <FieldMark />\n </InputGroupAddon>\n )}\n {isInvalid && (isInField || !showErrors) && <HiddenErrors errorsKey={errorsKey} errors={errors} />}\n </InputGroup>\n );\n },\n);\nInputBox.displayName = 'InputBox';\n\n/**\n * A text field, a password field or a number field, by `type`. A password gets\n * the show-password button; a number stays the native input, so its value is\n * the string the user typed, a comma included.\n *\n * With a `label`, a `description`, an `error` or a `warning` it draws its\n * field: the label on top, on the left or hidden, and the message behind a mark\n * at its end or, with `messageDisplay=\"line\"`, under it.\n */\nconst Input = forwardRef<HTMLInputElement, PropsWithoutRef<InputProps>>((props, ref) => {\n const {field, rest} = splitFieldProps(props);\n const {isRequired, ...control} = rest;\n const required = isRequired || control.required;\n if (!hasFieldProps(props)) {\n return <InputBox {...control} ref={ref} required={required} />;\n }\n return (\n <ControlField field={field} errors={control.errors} tone={control.tone} isDisabled={control.isDisabled}>\n {/* The errors are the field's now, written by it. */}\n <InputBox {...control} errors={undefined} ref={ref} required={required} />\n </ControlField>\n );\n});\nInput.displayName = 'Input';\n\n/**\n * The box of `Textarea`, the same as `Input`'s. The `!` mark sits in\n * the top corner, next to the first line; the counter in the bottom one, next to\n * where the typing is.\n */\nconst TextareaBox = forwardRef<HTMLTextAreaElement, PropsWithoutRef<TextareaProps>>(\n (\n {\n id,\n rows = 3,\n errors = [],\n tone = InputTone.Danger,\n showErrors = true,\n onErrorsClick,\n characterLimit,\n countCharacters = defaultCount,\n isDisabled = false,\n groupClassName,\n groupStyle,\n value,\n defaultValue,\n onChange,\n ...props\n },\n ref,\n ) => {\n const {errorsKey, isInField, isInvalid, fieldTone, hasFieldMark, remaining, handleChange, ariaProps} =\n useControlState<HTMLTextAreaElement>({\n id,\n errors,\n characterLimit,\n countCharacters,\n value,\n defaultValue,\n onChange,\n describedBy: props['aria-describedby'],\n });\n\n return (\n <InputGroup\n tone={fieldTone ?? tone}\n isInvalid={isInvalid || fieldTone !== undefined}\n className={cn('input-group--multiline', groupClassName)}\n style={groupStyle}\n data-has-errors={(isInvalid && showErrors) || hasFieldMark || undefined}\n data-has-counter={remaining !== undefined || undefined}\n >\n <InputGroupTextarea\n {...props}\n ref={ref}\n id={id}\n rows={rows}\n value={value}\n defaultValue={defaultValue}\n onChange={handleChange}\n disabled={isDisabled}\n {...ariaProps}\n />\n {((isInvalid && showErrors) || hasFieldMark) && (\n <InputGroupAddon align=\"block-start\">\n {isInvalid && showErrors && (\n <ErrorLabel\n elementId={errorsKey}\n errors={errors}\n tone={tone}\n onClick={onErrorsClick}\n hasDescription={!isInField}\n />\n )}\n <FieldMark />\n </InputGroupAddon>\n )}\n {remaining !== undefined && (\n <InputGroupAddon align=\"block-end\">\n <Counter remaining={remaining} />\n </InputGroupAddon>\n )}\n {isInvalid && (isInField || !showErrors) && <HiddenErrors errorsKey={errorsKey} errors={errors} />}\n </InputGroup>\n );\n },\n);\nTextareaBox.displayName = 'TextareaBox';\n\n/** A field for more than a line. Draws its field the way `Input` does. */\nconst Textarea = forwardRef<HTMLTextAreaElement, PropsWithoutRef<TextareaProps>>((props, ref) => {\n const {field, rest} = splitFieldProps(props);\n const {isRequired, ...control} = rest;\n const required = isRequired || control.required;\n if (!hasFieldProps(props)) {\n return <TextareaBox {...control} ref={ref} required={required} />;\n }\n return (\n <ControlField field={field} errors={control.errors} tone={control.tone} isDisabled={control.isDisabled}>\n <TextareaBox {...control} errors={undefined} ref={ref} required={required} />\n </ControlField>\n );\n});\nTextarea.displayName = 'Textarea';\n\nexport default Input;\n\nexport type {\n FieldDescriptionProps,\n FieldGroupProps,\n FieldLabelProps,\n FieldProps,\n InputGroupAddonProps,\n InputGroupButtonProps,\n InputGroupInputProps,\n InputGroupProps,\n InputGroupTextareaProps,\n InputGroupTextProps,\n InputProps,\n TextareaProps,\n};\nexport {\n Field,\n FieldDescription,\n FieldGroup,\n FieldLabel,\n Input,\n InputGroup,\n InputGroupAddon,\n InputGroupButton,\n InputGroupInput,\n InputGroupText,\n InputGroupTextarea,\n InputTone,\n Textarea,\n};\n"],"mappings":";;;;;;;;;AAOA,IAAMc,KAAM,GAAGC,MAAiCC,EAAKD,CAAM,GCF9CE,IAAY;CAEvB,QAAQ;CAER,SAAS;AACX,GCmCMC,IAAaC,GAChB,EAAC,UAAOF,EAAU,QAAQ,eAAY,IAAO,cAAW,GAAGG,KA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0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"style": "dist/index.css",
|
|
@@ -24,19 +24,19 @@
|
|
|
24
24
|
"url": "https://github.com/propellerads/ui-components/issues"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "tsc && vite build &&
|
|
27
|
+
"build": "tsc && vite build && rollup -c rollup.dts.config.mjs"
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/propellerads/ui-components#readme",
|
|
30
30
|
"private": false,
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@base-ui-components/react": "1.0.0-rc.0",
|
|
33
|
-
"@propellerads/error-label": "^
|
|
34
|
-
"@propellerads/label": "^
|
|
33
|
+
"@propellerads/error-label": "^9.0.0",
|
|
34
|
+
"@propellerads/label": "^7.0.0",
|
|
35
35
|
"class-variance-authority": "^0.7.1",
|
|
36
36
|
"clsx": "^2.1.1"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@propellerads/tokens": ">=0.
|
|
39
|
+
"@propellerads/tokens": ">=0.5.0",
|
|
40
40
|
"react": "^18.0.0 || ^19.0.0",
|
|
41
41
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
42
42
|
},
|