@propellerads/input 2.0.0 → 2.1.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/README.md CHANGED
@@ -31,18 +31,22 @@ import '@propellerads/tokens/propellerads.css'; // or monetag / propush / zeydoo
31
31
  ## Use
32
32
 
33
33
  ```tsx
34
- import Input, {Field, FieldDescription, FieldLabel} from '@propellerads/input';
35
-
36
- <Field isInvalid={errors.length > 0}>
37
- <FieldLabel isRequired>Email</FieldLabel>
38
- <Input type="email" value={email} onChange={(event) => setEmail(event.target.value)} errors={errors} required />
39
- <FieldDescription>We'll send updates to this address.</FieldDescription>
40
- </Field>
41
-
42
- <Input type="password" autoComplete="current-password" aria-label="Password" />
43
- <Input type="number" step={0.001} min={0} startAddon="$" aria-label="Bid" />
44
- <Input tone="warning" errors={['The bid is 8× the market average']} aria-label="Bid" />
45
- <Input characterLimit={24} aria-label="Title" />
34
+ import Input from '@propellerads/input';
35
+
36
+ <Input
37
+ label="Email"
38
+ type="email"
39
+ value={email}
40
+ onChange={(event) => setEmail(event.target.value)}
41
+ description="We'll send updates to this address."
42
+ error={isValid ? undefined : 'Enter an email like name@example.com'}
43
+ isRequired
44
+ />
45
+
46
+ <Input label="Password" type="password" autoComplete="current-password" />
47
+ <Input label="Bid" type="number" step={0.001} min={0} startAddon="$" warning="The bid is 8× the market average" />
48
+ <Input label="Title" characterLimit={24} />
49
+ <Input label="Search zones" labelPosition="hidden" placeholder="Search zones" />
46
50
  ```
47
51
 
48
52
  `type` picks the field:
@@ -58,15 +62,12 @@ focus ring, so an input and a button stand in one row without adjustment.
58
62
  ## Textarea
59
63
 
60
64
  ```tsx
61
- import {Field, FieldLabel, Textarea} from '@propellerads/input';
65
+ import {Textarea} from '@propellerads/input';
62
66
 
63
- <Field>
64
- <FieldLabel>Message</FieldLabel>
65
- <Textarea placeholder="Type your message here." characterLimit={500} />
66
- </Field>
67
+ <Textarea label="Message" placeholder="Type your message here." characterLimit={500} />
67
68
  ```
68
69
 
69
- The same box as `Input` — contour, focus ring, tone, `errors`,
70
+ The same box and field as `Input` — label, messages, contour, focus ring,
70
71
  `characterLimit`, `isDisabled` — on `--font-paragraph`. `rows` sets the height
71
72
  it starts at (3 by default). The field grows with the text where the browser can
72
73
  size a field by its content (`field-sizing`); in Safari, which cannot yet, it
@@ -74,41 +75,52 @@ keeps its height and the corner handle resizes it. The `!` mark sits in the top
74
75
  end corner, beside the first line; the counter in the bottom one, beside the
75
76
  typing.
76
77
 
77
- ## Errors
78
-
79
- A non-empty `errors` list draws the contour in the tone, sets `aria-invalid`,
80
- and puts a `!` mark at the end of the field. The mark grows in from 80% as the
81
- error appears.
82
-
83
- The mark is [`@propellerads/error-label`](../ErrorLabel/README.md), the same
84
- one every other field in the library uses. The list behind it is Base UI's
85
- Popover:
86
-
87
- - It opens on hover and on click, so it works under a finger as well as a
88
- pointer.
89
- - It appears the shadcn way — out of nothing, from 95%, and two pixels from the
90
- side it grows from — in `--duration-200`, and leaves in `--duration-100`.
91
- - It stands above the mark and flips below it at the edge of the screen.
92
- - It closes on Escape and on a click outside.
93
-
94
- The same text stays in the field for a screen reader: the input points at it
95
- with `aria-describedby`. `showErrors={false}` hides the mark and keeps the
96
- contour and the description.
97
-
98
- `tone="warning"` is for a value that is allowed but worth a second look.
78
+ ## Label and messages
79
+
80
+ Input draws its field with [`Field` from `@propellerads/label`](../Label/README.md),
81
+ the one every form control of the library builds on.
82
+
83
+ - **`label`** names the field. `labelPosition` puts it on top (the default), on
84
+ the left, or hides it for a filter or a table cell, where a screen reader
85
+ still reads it. On the left the label column fits the label, up to 160px: in a
86
+ `FieldGroup` the fields share one column, as wide as the longest label of the
87
+ form, and a field alone takes its own label's width. `labelWidth` fixes the
88
+ column for a form that needs it. `optional`
89
+ adds a quiet "(Optional)"; `isRequired` sets `required` with no mark.
90
+ - **One message:** `error`, else `warning`, else `description`. An error draws
91
+ the contour red and sets `aria-invalid`; a warning draws it yellow. The label
92
+ keeps its colour.
93
+ - **`messageDisplay`**: `compact` by default — the message waits behind a mark
94
+ at the end of the field: the `!` of [ErrorLabel](../ErrorLabel/README.md) for
95
+ an error or a warning, a quiet «i» for the description. The bubble opens on
96
+ hover, focus and tap, above the mark. `line` writes it under the field: the
97
+ usual form.
98
+ - The input is described by the message either way, so a screen reader reads it
99
+ with the field's name. Nothing is announced on its own: a form moves the focus
100
+ to the first field with an error when it is sent.
101
+
102
+ Whether the field is drawn is decided by the props being passed, not by their
103
+ values: write `error={isValid ? undefined : '…'}`, so the field stays put while
104
+ the error comes and goes.
105
+
106
+ ### The old `errors`
107
+
108
+ `errors` and `tone` still work and are deprecated. Without a field of its own
109
+ — no `label`, `description`, `error` or `warning` — they keep the old look: the
110
+ `!` mark at the end of the field, `showErrors={false}` to hide it,
111
+ `onErrorsClick` on a click. With a field of its own the input takes them as
112
+ `error`, or as `warning` with `tone="warning"`, and the field draws the mark:
113
+ `showErrors` and `onErrorsClick` do nothing there. A form that counts on a click
114
+ on the `!` keeps `errors` without a `label` until it is moved over;
115
+ `messageDisplay="line"` is the way to keep the mark out of the field.
99
116
 
100
117
  ## Field
101
118
 
102
- The parts follow [shadcn's Field](https://ui.shadcn.com/docs/components/base/input),
103
- on Base UI's. A `Field` wires itself: the label points at the input, and the
104
- input is described by the description and by its errors. No ids by hand.
105
-
106
- | Part | What it does |
107
- |--------------------|-------------------------------------------------------------------------------|
108
- | `Field` | Label, input and description, `--space-8` apart. `orientation="horizontal"` puts them in a row — an input and its button. `isDisabled` switches the input off and fades the words; `isInvalid` turns the contour and the label red and sets `aria-invalid` |
109
- | `FieldLabel` | `isRequired` adds the asterisk. A badge inside stands beside the text. Outside a `Field`, pass `htmlFor` |
110
- | `FieldDescription` | Quiet text under the input, `--font-description` |
111
- | `FieldGroup` | The fields of one form, `--space-24` apart. `columns={2}` makes a grid; below 481px it goes back to one column |
119
+ `Field`, `FieldLabel`, `FieldDescription` and `FieldGroup` moved to
120
+ `@propellerads/label`. Input still exports them, deprecated, so the forms built
121
+ from them keep working; new code takes them from Label. Inside such a `Field` the
122
+ input is wired the same way: the label points at it and it is described by the
123
+ description and its errors.
112
124
 
113
125
  `type="file"` keeps the field's box; the browser's button inside it reads as
114
126
  bold text on the left.
@@ -147,10 +159,21 @@ and `groupStyle` on the box around it.
147
159
  | Prop | Type | Default | What it does |
148
160
  |-----------------------|---------------------------|-------------------|----------------------------------------------------------------|
149
161
  | `type` | `string` | `'text'` | `password` adds the eye, `number` is the native number field |
150
- | `errors` | `readonly string[]` | `[]` | The list behind the `!` mark |
151
- | `tone` | `'danger' \| 'warning'` | `'danger'` | The colour of the contour, the mark and the list |
152
- | `showErrors` | `boolean` | `true` | `false` hides the mark and keeps the contour |
153
- | `onErrorsClick` | `() => void` | — | Called when the mark is clicked |
162
+ | `label` | `ReactNode` | — | The name of the field |
163
+ | `labelPosition` | `'top' \| 'left' \| 'hidden'` | `'top'` | Where the label stands |
164
+ | `labelWidth` | `string` | `fit-content(160px)` | A fixed label column on the left; left out, the column fits the labels |
165
+ | `optional` | `boolean` | `false` | Adds "(Optional)" after the label |
166
+ | `optionalText` | `ReactNode` | `'Optional'` | The word in the brackets |
167
+ | `isRequired` | `boolean` | `false` | Sets `required`, with no mark |
168
+ | `messageDisplay` | `'compact' \| 'line'` | `'compact'` | Behind a mark at the end, or under the field |
169
+ | `description` | `ReactNode` | — | What the field is for |
170
+ | `warning` | `string \| string[]` | — | Allowed, but worth a second look; the contour turns yellow |
171
+ | `error` | `string \| string[]` | — | What is wrong; the contour turns red |
172
+ | `hintLabel` | `string` | `'Hint'` | The name of the «i» for a screen reader |
173
+ | `errors` | `readonly string[]` | `[]` | Deprecated: `error`, or `warning` with `tone="warning"` |
174
+ | `tone` | `'danger' \| 'warning'` | `'danger'` | Deprecated, with `errors` |
175
+ | `showErrors` | `boolean` | `true` | `false` hides the mark of `errors` and keeps the contour |
176
+ | `onErrorsClick` | `() => void` | — | Called when the mark of `errors` is clicked |
154
177
  | `characterLimit` | `number` | — | Shows how many characters are left. Typing past it is allowed |
155
178
  | `countCharacters` | `(value) => number` | trimmed length | Counts for `characterLimit` — emoji, for one |
156
179
  | `isDisabled` | `boolean` | `false` | Switches the field off. The native `disabled` is not accepted |
@@ -163,16 +186,16 @@ and `groupStyle` on the box around it.
163
186
  | Old | New |
164
187
  |-----------------------------------------|------------------------------------------------------------|
165
188
  | `elementId` | `id` |
166
- | `label`, `isRequired` | `<Field><FieldLabel isRequired>…</FieldLabel><Input /></Field>` |
189
+ | `label`, `isRequired` | `label`, `isRequired` — no asterisk; `optional` marks the other fields |
167
190
  | `onChange(value, event)` | `onChange(event)` — `event.target.value` |
168
- | `errors`, `showErrorLabel` | `errors`, `showErrors` |
191
+ | `errors`, `showErrorLabel` | `error`; `messageDisplay="line"` writes it under the field |
169
192
  | `onErrorClick` | `onErrorsClick` |
170
193
  | `maxLength` (the counter) | `characterLimit` — the native `maxLength` stops typing |
171
194
  | `onCalculateLength` | `countCharacters` |
172
195
  | `inputRef` | `ref` |
173
196
  | `customStyles` | `className`, or the `--input-placeholder-*` properties |
174
197
  | `stepAmount`, `minAmount` | `step`, `min` |
175
- | `errorColor` | `tone="warning"` |
198
+ | `errorColor` | `warning` |
176
199
  | `InputNumber` disabled by default | Enabled by default |
177
200
 
178
201
  ## Tokens
package/dist/index.css CHANGED
@@ -1 +1 @@
1
- .input-group{--input-height:36px;--input-contour:var(--color-rich);--input-ring:var(--color-action);--input-accent:var(--color-danger);--input-accent-on:var(--color-light);box-sizing:border-box;border-radius:var(--radius-8);background-color:var(--color-light-inversion);width:100%;min-width:0;box-shadow:inset 0 0 0 var(--space-1) var(--input-contour);color:var(--color-dark-inversion);outline:var(--space-2) solid transparent;outline-offset:var(--space-1);font:var(--font-text);font-family:var(--font-family);transition:box-shadow var(--duration-200) var(--ease-flat), outline-color var(--duration-200) var(--ease-flat);align-items:center;display:flex;position:relative}.input-group[data-tone=warning]{--input-accent:var(--color-warning);--input-accent-on:var(--color-dark)}.input-group:hover{--input-contour:var(--color-quiet)}.input-group[data-invalid]{--input-contour:var(--input-accent);--input-ring:var(--input-accent)}.input-group:has(.input-group__control[aria-invalid=true]){--input-contour:var(--input-accent);--input-ring:var(--input-accent)}.input-group:has(.input-group__control:focus-visible){outline-color:var(--input-ring)}.input-group:has(.input-group__control:disabled){--input-contour:var(--color-rich);opacity:var(--opacity-disabled);cursor:not-allowed}.input-group__control{box-sizing:border-box;width:100%;min-width:0;height:var(--input-height);margin:var(--space-0);padding:var(--space-0) var(--space-12);border-radius:inherit;color:inherit;font:inherit;background:0 0;border:0;outline:none;flex:1}.input-group__control:disabled{cursor:not-allowed}.input-group__control::placeholder{color:var(--input-placeholder-color,var(--color-quiet-text));font-size:var(--input-placeholder-font-size,inherit);font-weight:var(--input-placeholder-font-weight,inherit);text-align:var(--input-placeholder-text-align,inherit);opacity:1}.input-group__addon{align-items:center;gap:var(--space-4);color:var(--color-quiet-text);flex:none;display:flex}.input-group__addon--inline-start{order:-1;padding-inline-start:var(--space-12)}.input-group__addon--inline-start+.input-group__control,.input-group__addon--inline-start~.input-group__control{padding-inline-start:var(--space-8)}.input-group__addon--inline-end{padding-inline-end:var(--space-8)}.input-group__control:has(+.input-group__addon--inline-end){padding-inline-end:var(--space-4)}.input-group .error-label{margin-inline-end:var(--space-0)}.input-group__addon svg{flex:none}.input-group__text{white-space:nowrap}.input-group__counter{font:var(--font-description);font-family:var(--font-family);font-variant-numeric:tabular-nums}.input-group__counter[data-over]{color:var(--color-danger-text)}.input-group__button{box-sizing:border-box;width:24px;height:24px;padding:var(--space-0);border-radius:var(--radius-4);color:var(--color-quiet-text);outline:var(--space-2) solid transparent;outline-offset:calc(-1 * var(--space-2));cursor:pointer;transition:background-color var(--duration-200) var(--ease-flat), color var(--duration-200) var(--ease-flat), outline-color var(--duration-200) var(--ease-flat);background-color:#0000;border:0;justify-content:center;align-items:center;display:inline-flex}.input-group__button:hover{background-color:color-mix(in srgb, var(--color-action) var(--opacity-tint), transparent);color:var(--color-action)}.input-group__button[aria-pressed=true]{color:var(--color-action)}.input-group__button:focus-visible{outline-color:var(--color-action)}.input-group__button:disabled{cursor:not-allowed}.input-group__button:disabled:hover{color:var(--color-quiet-text);background-color:#0000}.field-label{color:var(--color-dark-inversion);font:var(--font-text);font-family:var(--font-family);margin-block-end:var(--space-8);display:inline-block}.field-label[data-required]:after{content:"*";color:var(--color-danger);margin-inline-start:var(--space-2)}.field>.field-label[data-required]:after{margin-inline-start:calc(var(--space-2) - var(--space-8))}.field{gap:var(--space-8);flex-direction:column;min-width:0;display:flex}.field[data-orientation=horizontal]{flex-direction:row;align-items:center}.field[data-orientation=horizontal]>.input-group{flex:1}.field>.field-label{align-items:center;gap:var(--space-8);margin-block-end:var(--space-0);display:inline-flex}.field-description{margin:var(--space-0);color:var(--color-quiet-text);font:var(--font-description);font-family:var(--font-family)}.field[data-invalid]>.field-label{color:var(--color-danger-text)}.field[data-disabled]>.field-label,.field[data-disabled]>.field-description{opacity:var(--opacity-disabled)}.field-group{gap:var(--space-24);flex-direction:column;display:flex}.field-group[data-columns]{grid-template-columns:repeat(var(--field-group-columns), minmax(0, 1fr));display:grid}@media (width<=480px){.field-group[data-columns]{grid-template-columns:minmax(0,1fr)}}.input-group__control[type=file]{padding-block:calc((var(--input-height) - 20px) / 2);color:var(--color-quiet-text);cursor:pointer}.input-group__control::file-selector-button{padding:var(--space-0);color:var(--color-dark-inversion);font:var(--font-h4);font-family:var(--font-family);cursor:pointer;background:0 0;border:0;margin-inline-end:var(--space-8)}.input-group--multiline{--input-multiline-mark-room:calc(var(--space-8) + 20px + var(--space-8));align-items:stretch}.input-group__control--multiline{height:auto;min-height:calc(var(--input-height) * 2);padding:var(--space-8) var(--space-12);font:var(--font-paragraph);font-family:var(--font-family);field-sizing:content;resize:vertical}.input-group--multiline[data-has-errors] .input-group__control--multiline{padding-inline-end:var(--input-multiline-mark-room)}.input-group--multiline[data-has-counter] .input-group__control--multiline{padding-block-end:calc(var(--space-8) + 20px)}.input-group__addon--block-start,.input-group__addon--block-end{padding:var(--space-0);position:absolute;inset-inline-end:var(--space-8)}.input-group__addon--block-start{inset-block-start:var(--space-8)}.input-group__addon--block-end{inset-block-end:var(--space-4)}
1
+ .input-group{--input-height:36px;--input-contour:var(--color-rich);--input-ring:var(--color-action);--input-accent:var(--color-danger);--input-accent-on:var(--color-light);box-sizing:border-box;border-radius:var(--radius-8);background-color:var(--color-light-inversion);width:100%;min-width:0;box-shadow:inset 0 0 0 var(--space-1) var(--input-contour);color:var(--color-dark-inversion);outline:var(--space-2) solid transparent;outline-offset:var(--space-1);font:var(--font-text);font-family:var(--font-family);transition:box-shadow var(--duration-200) var(--ease-flat), outline-color var(--duration-200) var(--ease-flat);align-items:center;display:flex;position:relative}.input-group[data-tone=warning]{--input-accent:var(--color-warning);--input-accent-on:var(--color-dark)}.input-group:hover{--input-contour:var(--color-quiet)}.input-group[data-invalid]{--input-contour:var(--input-accent);--input-ring:var(--input-accent)}.input-group:has(.input-group__control[aria-invalid=true]){--input-contour:var(--input-accent);--input-ring:var(--input-accent)}.input-group:has(.input-group__control:focus-visible){outline-color:var(--input-ring)}.input-group:has(.input-group__control:disabled){--input-contour:var(--color-rich);opacity:var(--opacity-disabled);cursor:not-allowed}.input-group__control{box-sizing:border-box;width:100%;min-width:0;height:var(--input-height);margin:var(--space-0);padding:var(--space-0) var(--space-12);border-radius:inherit;color:inherit;font:inherit;background:0 0;border:0;outline:none;flex:1}.input-group__control:disabled{cursor:not-allowed}.input-group__control::placeholder{color:var(--input-placeholder-color,var(--color-quiet-text));font-size:var(--input-placeholder-font-size,inherit);font-weight:var(--input-placeholder-font-weight,inherit);text-align:var(--input-placeholder-text-align,inherit);opacity:1}.input-group__addon{align-items:center;gap:var(--space-4);color:var(--color-quiet-text);flex:none;display:flex}.input-group__addon--inline-start{order:-1;padding-inline-start:var(--space-12)}.input-group__addon--inline-start+.input-group__control,.input-group__addon--inline-start~.input-group__control{padding-inline-start:var(--space-8)}.input-group__addon--inline-end{padding-inline-end:var(--space-8)}.input-group__control:has(+.input-group__addon--inline-end){padding-inline-end:var(--space-4)}.input-group .error-label,.input-group .field-hint{margin-inline-end:var(--space-0)}.input-group__addon svg{flex:none}.input-group__text{white-space:nowrap}.input-group__counter{font:var(--font-description);font-family:var(--font-family);font-variant-numeric:tabular-nums}.input-group__counter[data-over]{color:var(--color-danger-text)}.input-group__button{box-sizing:border-box;width:24px;height:24px;padding:var(--space-0);border-radius:var(--radius-4);color:var(--color-quiet-text);outline:var(--space-2) solid transparent;outline-offset:calc(-1 * var(--space-2));cursor:pointer;transition:background-color var(--duration-200) var(--ease-flat), color var(--duration-200) var(--ease-flat), outline-color var(--duration-200) var(--ease-flat);background-color:#0000;border:0;justify-content:center;align-items:center;display:inline-flex}.input-group__button:hover{background-color:color-mix(in srgb, var(--color-action) var(--opacity-tint), transparent);color:var(--color-action)}.input-group__button[aria-pressed=true]{color:var(--color-action)}.input-group__button:focus-visible{outline-color:var(--color-action)}.input-group__button:disabled{cursor:not-allowed}.input-group__button:disabled:hover{color:var(--color-quiet-text);background-color:#0000}.input-group__control[type=file]{padding-block:calc((var(--input-height) - 20px) / 2);color:var(--color-quiet-text);cursor:pointer}.input-group__control::file-selector-button{padding:var(--space-0);color:var(--color-dark-inversion);font:var(--font-h4);font-family:var(--font-family);cursor:pointer;background:0 0;border:0;margin-inline-end:var(--space-8)}.input-group--multiline{--input-multiline-mark-room:calc(var(--space-8) + 20px + var(--space-8));align-items:stretch}.input-group__control--multiline{height:auto;min-height:calc(var(--input-height) * 2);padding:var(--space-8) var(--space-12);font:var(--font-paragraph);font-family:var(--font-family);field-sizing:content;resize:vertical}.input-group--multiline[data-has-errors] .input-group__control--multiline{padding-inline-end:var(--input-multiline-mark-room)}.input-group--multiline[data-has-counter] .input-group__control--multiline{padding-block-end:calc(var(--space-8) + 20px)}.input-group__addon--block-start,.input-group__addon--block-end{padding:var(--space-0);position:absolute;inset-inline-end:var(--space-8)}.input-group__addon--block-start{inset-block-start:var(--space-8)}.input-group__addon--block-end{inset-block-end:var(--space-4)}
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import * as react from 'react';
2
- import { ComponentProps, ComponentPropsWithRef, ReactNode, Ref } from 'react';
2
+ import { ComponentPropsWithRef, ReactNode, Ref, ComponentProps } from 'react';
3
+ import { FieldOwnProps as FieldOwnProps$1, FieldProps, FieldDescriptionProps, FieldGroupProps, FieldLabelProps } from '@propellerads/label';
4
+ export { FieldDescriptionProps, FieldGroupProps, FieldLabelProps, FieldProps } from '@propellerads/label';
3
5
  import { Button } from '@base-ui-components/react/button';
4
- import { Field as Field$1 } from '@base-ui-components/react/field';
5
6
 
6
7
  /** Which colour the errors are shown in. */
7
8
  declare const InputTone: {
@@ -29,39 +30,28 @@ type InputGroupTextProps = ComponentPropsWithRef<'span'>;
29
30
  type InputGroupButtonProps = Omit<ComponentProps<typeof Button>, 'className'> & {
30
31
  className?: string;
31
32
  };
32
- type FieldProps = Omit<ComponentProps<typeof Field$1.Root>, 'className' | 'disabled' | 'invalid'> & {
33
- className?: string;
34
- /** `horizontal` puts the parts in a row: an input and its button, a checkbox and its label. @default 'vertical' */
35
- orientation?: 'vertical' | 'horizontal';
36
- /** Switches off the input inside and fades the label and the description. */
37
- isDisabled?: boolean;
38
- /** Marks the field invalid: the contour, the label and `aria-invalid` on the input. */
39
- isInvalid?: boolean;
40
- };
41
- type FieldLabelProps = Omit<ComponentProps<typeof Field$1.Label>, 'className'> & {
42
- className?: string;
43
- /** Adds the asterisk. The input itself takes `required` separately. */
33
+ /**
34
+ * The field around the control: its label and its message, laid out by Label's
35
+ * `Field`. Given any of `label`, `description`, `error` or `warning`, the
36
+ * control draws the field itself; `messageDisplay` is `compact` by default.
37
+ */
38
+ type FieldOwnProps = FieldOwnProps$1 & {
39
+ /** Sets `required` on the control. No mark: the optional fields are the ones marked. */
44
40
  isRequired?: boolean;
45
41
  };
46
- type FieldDescriptionProps = Omit<ComponentProps<typeof Field$1.Description>, 'className'> & {
47
- className?: string;
48
- };
49
- type FieldGroupProps = ComponentPropsWithRef<'div'> & {
50
- /** Lays the fields out in this many equal columns. Stacked when omitted. */
51
- columns?: number;
52
- };
53
- /** What `Input` and `Textarea` share: the errors, the counter, the switch and the box. */
54
- type FieldControlOwnProps = {
42
+ /** What `Input` and `Textarea` share: the field, the errors, the counter, the switch and the box. */
43
+ type FieldControlOwnProps = FieldOwnProps & {
55
44
  /**
56
- * Shown behind the `!` mark at the end of the field. A non-empty list also
57
- * draws the contour in the tone and sets `aria-invalid`.
45
+ * @deprecated Use `error`, or `warning` for the warning tone. Shown behind
46
+ * the `!` mark at the end of the field; a non-empty list also draws the
47
+ * contour in the tone and sets `aria-invalid`.
58
48
  */
59
49
  errors?: ReadonlyArray<string>;
60
- /** Which colour the errors are shown in. @default 'danger' */
50
+ /** @deprecated Use `warning` instead of `errors` with `tone="warning"`. @default 'danger' */
61
51
  tone?: InputTone;
62
- /** Hides the `!` mark and keeps the contour and the description. @default true */
52
+ /** Hides the `!` mark of `errors` and keeps the contour. Use `messageDisplay` with `error`. @default true */
63
53
  showErrors?: boolean;
64
- /** Called when the `!` mark is clicked. */
54
+ /** Called when the `!` mark of `errors` is clicked. */
65
55
  onErrorsClick?: () => void;
66
56
  /**
67
57
  * Shows how many characters are left. Typing past it is allowed and turns the
@@ -95,15 +85,6 @@ type TextareaProps = Omit<ComponentPropsWithRef<'textarea'>, 'disabled'> & Field
95
85
  ref?: Ref<HTMLTextAreaElement>;
96
86
  };
97
87
 
98
- /** A label, a control and a description, stacked or in a row. */
99
- declare const Field: react.ForwardRefExoticComponent<Omit<FieldProps, "ref"> & react.RefAttributes<HTMLDivElement>>;
100
- /** The label. Inside a `Field` it finds the input itself; outside one, pass `htmlFor`. */
101
- declare const FieldLabel: react.ForwardRefExoticComponent<Omit<FieldLabelProps, "ref"> & react.RefAttributes<HTMLLabelElement>>;
102
- /** Quiet text under the input. The input is described by it. */
103
- declare const FieldDescription: react.ForwardRefExoticComponent<Omit<FieldDescriptionProps, "ref"> & react.RefAttributes<HTMLParagraphElement>>;
104
- /** Fields of one form, spaced apart; `columns` lays them out in a grid. */
105
- declare const FieldGroup: react.ForwardRefExoticComponent<Omit<FieldGroupProps, "ref"> & react.RefAttributes<HTMLDivElement>>;
106
-
107
88
  /** The box. Draws the contour and the focus ring for the control inside it. */
108
89
  declare const InputGroup: react.ForwardRefExoticComponent<Omit<InputGroupProps, "ref"> & react.RefAttributes<HTMLDivElement>>;
109
90
  /** The `<input>` inside a group. Takes every native prop. */
@@ -116,18 +97,26 @@ declare const InputGroupAddon: react.ForwardRefExoticComponent<Omit<InputGroupAd
116
97
  declare const InputGroupText: react.ForwardRefExoticComponent<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & react.RefAttributes<HTMLSpanElement>>;
117
98
  /** A small square button inside the box. Name it with `aria-label` when it is only an icon. */
118
99
  declare const InputGroupButton: react.ForwardRefExoticComponent<Omit<InputGroupButtonProps, "ref"> & react.RefAttributes<HTMLButtonElement>>;
100
+ /** @deprecated Import `Field` from `@propellerads/label`. */
101
+ declare const Field: react.ForwardRefExoticComponent<Omit<FieldProps, "ref"> & react.RefAttributes<HTMLDivElement>>;
102
+ /** @deprecated Import `FieldLabel` from `@propellerads/label`. */
103
+ declare const FieldLabel: react.ForwardRefExoticComponent<Omit<FieldLabelProps, "ref"> & react.RefAttributes<HTMLLabelElement>>;
104
+ /** @deprecated Import `FieldDescription` from `@propellerads/label`. */
105
+ declare const FieldDescription: react.ForwardRefExoticComponent<Omit<FieldDescriptionProps, "ref"> & react.RefAttributes<HTMLParagraphElement>>;
106
+ /** @deprecated Import `FieldGroup` from `@propellerads/label`. */
107
+ declare const FieldGroup: react.ForwardRefExoticComponent<Omit<FieldGroupProps, "ref"> & react.RefAttributes<HTMLDivElement>>;
119
108
  /**
120
109
  * A text field, a password field or a number field, by `type`. A password gets
121
110
  * the show-password button; a number stays the native input, so its value is
122
111
  * the string the user typed, a comma included.
112
+ *
113
+ * With a `label`, a `description`, an `error` or a `warning` it draws its
114
+ * field: the label on top, on the left or hidden, and the message behind a mark
115
+ * at its end or, with `messageDisplay="line"`, under it.
123
116
  */
124
117
  declare const Input: react.ForwardRefExoticComponent<Omit<InputProps, "ref"> & react.RefAttributes<HTMLInputElement>>;
125
- /**
126
- * A field for more than a line, the same box as `Input`. The `!` mark sits in
127
- * the top corner, next to the first line; the counter in the bottom one, next to
128
- * where the typing is.
129
- */
118
+ /** A field for more than a line. Draws its field the way `Input` does. */
130
119
  declare const Textarea: react.ForwardRefExoticComponent<Omit<TextareaProps, "ref"> & react.RefAttributes<HTMLTextAreaElement>>;
131
120
 
132
121
  export { Field, FieldDescription, FieldGroup, FieldLabel, Input, InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, InputGroupTextarea, InputTone, Textarea, Input as default };
133
- export type { FieldDescriptionProps, FieldGroupProps, FieldLabelProps, FieldProps, InputGroupAddonProps, InputGroupButtonProps, InputGroupInputProps, InputGroupProps, InputGroupTextProps, InputGroupTextareaProps, InputProps, TextareaProps };
122
+ export type { InputGroupAddonProps, InputGroupButtonProps, InputGroupInputProps, InputGroupProps, InputGroupTextProps, InputGroupTextareaProps, InputProps, TextareaProps };
package/dist/index.js CHANGED
@@ -2,259 +2,265 @@ import { Button as e } from "@base-ui-components/react/button";
2
2
  import { Field as t } from "@base-ui-components/react/field";
3
3
  import { Input as n } from "@base-ui-components/react/input";
4
4
  import r, { errorLabelTextId as i } from "@propellerads/error-label";
5
- import { createContext as a, forwardRef as o, useContext as s, useId as c, useState as l } from "react";
6
- import { clsx as u } from "clsx";
7
- import { jsx as d, jsxs as f } from "react/jsx-runtime";
5
+ import { ControlField as a, Field as o, FieldDescription as s, FieldGroup as c, FieldLabel as l, FieldMark as u, MessageDisplay as d, hasFieldProps as f, splitFieldProps as p, useFieldMessage as m, useFieldTone as h, useIsInField as g } from "@propellerads/label";
6
+ import { forwardRef as _, useId as v, useState as y } from "react";
7
+ import { clsx as b } from "clsx";
8
+ import { jsx as x, jsxs as S } from "react/jsx-runtime";
8
9
  import './index.css';//#region src/cn.ts
9
- var p = (...e) => u(e), m = a(!1), h = () => s(m), g = o(({ orientation: e = "vertical", isDisabled: n, isInvalid: r, className: i, ...a }, o) => /* @__PURE__ */ d(m.Provider, {
10
- value: !0,
11
- children: /* @__PURE__ */ d(t.Root, {
12
- ...a,
13
- ref: o,
14
- disabled: n,
15
- invalid: r,
16
- "data-orientation": e,
17
- className: p("field", i)
18
- })
19
- }));
20
- g.displayName = "Field";
21
- var _ = o(({ isRequired: e = !1, className: n, ...r }, i) => /* @__PURE__ */ d(t.Label, {
22
- ...r,
23
- ref: i,
24
- "data-required": e || void 0,
25
- className: p("field-label", n)
26
- }));
27
- _.displayName = "FieldLabel";
28
- var v = o(({ className: e, ...n }, r) => /* @__PURE__ */ d(t.Description, {
29
- ...n,
30
- ref: r,
31
- className: p("field-description", e)
32
- }));
33
- v.displayName = "FieldDescription";
34
- var y = o(({ columns: e, className: t, style: n, ...r }, i) => /* @__PURE__ */ d("div", {
35
- ...r,
36
- ref: i,
37
- "data-columns": e,
38
- className: p("field-group", t),
39
- style: e === void 0 ? n : {
40
- "--field-group-columns": e,
41
- ...n
42
- }
43
- }));
44
- y.displayName = "FieldGroup";
45
- //#endregion
46
- //#region src/types.ts
47
- var b = {
10
+ var C = (...e) => b(e), w = {
48
11
  Danger: "danger",
49
12
  Warning: "warning"
50
- }, x = o(({ tone: e = b.Danger, isInvalid: t = !1, className: n, ...r }, i) => /* @__PURE__ */ d("div", {
13
+ }, T = _(({ tone: e = w.Danger, isInvalid: t = !1, className: n, ...r }, i) => /* @__PURE__ */ x("div", {
51
14
  ...r,
52
15
  ref: i,
53
16
  "data-tone": e,
54
17
  "data-invalid": t || void 0,
55
- className: p("input-group", n)
18
+ className: C("input-group", n)
56
19
  }));
57
- x.displayName = "InputGroup";
58
- var S = o(({ className: e, ...t }, r) => /* @__PURE__ */ d(n, {
20
+ T.displayName = "InputGroup";
21
+ var E = _(({ className: e, ...t }, r) => /* @__PURE__ */ x(n, {
59
22
  ...t,
60
23
  ref: r,
61
- className: p("input-group__control", e)
24
+ className: C("input-group__control", e)
62
25
  }));
63
- S.displayName = "InputGroupInput";
64
- var C = o(({ className: e, ...n }, r) => /* @__PURE__ */ d(t.Control, {
26
+ E.displayName = "InputGroupInput";
27
+ var D = _(({ className: e, ...n }, r) => /* @__PURE__ */ x(t.Control, {
65
28
  ...n,
66
29
  ref: r,
67
- render: /* @__PURE__ */ d("textarea", {}),
68
- className: p("input-group__control", "input-group__control--multiline", e)
30
+ render: /* @__PURE__ */ x("textarea", {}),
31
+ className: C("input-group__control", "input-group__control--multiline", e)
69
32
  }));
70
- C.displayName = "InputGroupTextarea";
71
- var w = o(({ align: e = "inline-end", className: t, ...n }, r) => /* @__PURE__ */ d("div", {
33
+ D.displayName = "InputGroupTextarea";
34
+ var O = _(({ align: e = "inline-end", className: t, ...n }, r) => /* @__PURE__ */ x("div", {
72
35
  ...n,
73
36
  ref: r,
74
37
  "data-align": e,
75
- className: p("input-group__addon", `input-group__addon--${e}`, t)
38
+ className: C("input-group__addon", `input-group__addon--${e}`, t)
76
39
  }));
77
- w.displayName = "InputGroupAddon";
78
- var T = o(({ className: e, ...t }, n) => /* @__PURE__ */ d("span", {
40
+ O.displayName = "InputGroupAddon";
41
+ var k = _(({ className: e, ...t }, n) => /* @__PURE__ */ x("span", {
79
42
  ...t,
80
43
  ref: n,
81
- className: p("input-group__text", e)
44
+ className: C("input-group__text", e)
82
45
  }));
83
- T.displayName = "InputGroupText";
84
- var E = o(({ className: t, ...n }, r) => /* @__PURE__ */ d(e, {
46
+ k.displayName = "InputGroupText";
47
+ var A = _(({ className: t, ...n }, r) => /* @__PURE__ */ x(e, {
85
48
  type: "button",
86
49
  ...n,
87
50
  ref: r,
88
- className: p("input-group__button", t)
51
+ className: C("input-group__button", t)
89
52
  }));
90
- E.displayName = "InputGroupButton";
91
- var D = ({ isOpen: e }) => /* @__PURE__ */ f("svg", {
53
+ A.displayName = "InputGroupButton";
54
+ var j = ({ isOpen: e }) => /* @__PURE__ */ S("svg", {
92
55
  viewBox: "0 0 16 16",
93
56
  width: "16",
94
57
  height: "16",
95
58
  fill: "none",
96
59
  "aria-hidden": "true",
97
60
  children: [
98
- /* @__PURE__ */ d("path", {
61
+ /* @__PURE__ */ x("path", {
99
62
  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",
100
63
  stroke: "currentColor",
101
64
  strokeWidth: "1.5",
102
65
  strokeLinejoin: "round"
103
66
  }),
104
- /* @__PURE__ */ d("circle", {
67
+ /* @__PURE__ */ x("circle", {
105
68
  cx: "8",
106
69
  cy: "8",
107
70
  r: "2",
108
71
  stroke: "currentColor",
109
72
  strokeWidth: "1.5"
110
73
  }),
111
- !e && /* @__PURE__ */ d("path", {
74
+ !e && /* @__PURE__ */ x("path", {
112
75
  d: "M2.5 13.5l11-11",
113
76
  stroke: "currentColor",
114
77
  strokeWidth: "1.5",
115
78
  strokeLinecap: "round"
116
79
  })
117
80
  ]
118
- }), O = (e) => e.trim().length, k = ({ id: e, errors: t, characterLimit: n, countCharacters: r, value: a, defaultValue: o, onChange: s, describedBy: u }) => {
119
- let d = h(), f = c(), m = e ?? f, [g, _] = l(String(o ?? "")), v = t.length > 0;
81
+ }), M = (e) => e.trim().length, N = o, P = l, F = s, I = c, L = ({ id: e, errors: t, characterLimit: n, countCharacters: r, value: a, defaultValue: o, onChange: s, describedBy: c }) => {
82
+ let l = g(), u = m(), f = h(), p = v(), _ = e ?? p, [b, x] = y(String(o ?? "")), S = t.length > 0;
120
83
  return {
121
- errorsKey: m,
122
- isInField: d,
123
- isInvalid: v,
124
- remaining: n === void 0 ? void 0 : n - r(a === void 0 ? g : String(a)),
84
+ errorsKey: _,
85
+ isInField: l,
86
+ isInvalid: S,
87
+ fieldTone: f,
88
+ hasFieldMark: u?.display === d.Compact,
89
+ remaining: n === void 0 ? void 0 : n - r(a === void 0 ? b : String(a)),
125
90
  handleChange: (e) => {
126
- a === void 0 && _(e.target.value), s?.(e);
91
+ a === void 0 && x(e.target.value), s?.(e);
127
92
  },
128
93
  ariaProps: {
129
- ...v ? { "aria-invalid": !0 } : {},
130
- ...v && !d ? { "aria-describedby": p(u, i(m)) } : {}
94
+ ...S ? { "aria-invalid": !0 } : {},
95
+ ...S && !l ? { "aria-describedby": C(c, i(_)) } : {}
131
96
  }
132
97
  };
133
- }, A = ({ remaining: e }) => /* @__PURE__ */ d(T, {
98
+ }, R = ({ remaining: e }) => /* @__PURE__ */ x(k, {
134
99
  className: "input-group__counter",
135
100
  "data-over": e < 0 || void 0,
136
101
  children: e
137
- }), j = ({ errorsKey: e, errors: n }) => {
138
- let r = h(), a = n.join(". ");
139
- return d(r ? t.Description : "span", {
102
+ }), z = ({ errorsKey: e, errors: n }) => {
103
+ let r = g(), a = n.join(". ");
104
+ return x(r ? t.Description : "span", {
140
105
  id: i(e),
141
106
  hidden: !0,
142
107
  children: a
143
108
  });
144
- }, M = o(({ type: e = "text", id: t, errors: n = [], tone: i = b.Danger, showErrors: a = !0, onErrorsClick: o, characterLimit: s, countCharacters: c = O, isDisabled: u = !1, startAddon: p, endAddon: m, passwordToggleLabel: h = "Show password", groupClassName: g, groupStyle: _, value: v, defaultValue: y, onChange: C, ...T }, M) => {
145
- let [N, P] = l(!1), { errorsKey: F, isInField: I, isInvalid: L, remaining: R, handleChange: z, ariaProps: B } = k({
109
+ }, B = _(({ type: e = "text", id: t, errors: n = [], tone: i = w.Danger, showErrors: a = !0, onErrorsClick: o, characterLimit: s, countCharacters: c = M, isDisabled: l = !1, startAddon: d, endAddon: f, passwordToggleLabel: p = "Show password", groupClassName: m, groupStyle: h, value: g, defaultValue: _, onChange: v, ...b }, C) => {
110
+ let [D, k] = y(!1), { errorsKey: N, isInField: P, isInvalid: F, fieldTone: I, hasFieldMark: B, remaining: V, handleChange: H, ariaProps: U } = L({
146
111
  id: t,
147
112
  errors: n,
148
113
  characterLimit: s,
149
114
  countCharacters: c,
150
- value: v,
151
- defaultValue: y,
152
- onChange: C,
153
- describedBy: T["aria-describedby"]
154
- }), V = e === "password";
155
- return /* @__PURE__ */ f(x, {
156
- tone: i,
157
- isInvalid: L,
158
- className: g,
159
- style: _,
115
+ value: g,
116
+ defaultValue: _,
117
+ onChange: v,
118
+ describedBy: b["aria-describedby"]
119
+ }), W = e === "password";
120
+ return /* @__PURE__ */ S(T, {
121
+ tone: I ?? i,
122
+ isInvalid: F || I !== void 0,
123
+ className: m,
124
+ style: h,
160
125
  children: [
161
- p !== void 0 && /* @__PURE__ */ d(w, {
126
+ d !== void 0 && /* @__PURE__ */ x(O, {
162
127
  align: "inline-start",
163
- children: p
128
+ children: d
164
129
  }),
165
- /* @__PURE__ */ d(S, {
166
- ...T,
167
- ref: M,
130
+ /* @__PURE__ */ x(E, {
131
+ ...b,
132
+ ref: C,
168
133
  id: t,
169
- type: V && N ? "text" : e,
170
- value: v,
171
- defaultValue: y,
172
- onChange: z,
173
- disabled: u,
174
- ...B
134
+ type: W && D ? "text" : e,
135
+ value: g,
136
+ defaultValue: _,
137
+ onChange: H,
138
+ disabled: l,
139
+ ...U
175
140
  }),
176
- (m !== void 0 || V || R !== void 0 || L && a) && /* @__PURE__ */ f(w, {
141
+ (f !== void 0 || W || V !== void 0 || F && a || B) && /* @__PURE__ */ S(O, {
177
142
  align: "inline-end",
178
143
  children: [
179
- m,
180
- V && /* @__PURE__ */ d(E, {
181
- "aria-label": h,
182
- "aria-pressed": N,
183
- disabled: u,
184
- onClick: () => P((e) => !e),
185
- children: /* @__PURE__ */ d(D, { isOpen: N })
144
+ f,
145
+ W && /* @__PURE__ */ x(A, {
146
+ "aria-label": p,
147
+ "aria-pressed": D,
148
+ disabled: l,
149
+ onClick: () => k((e) => !e),
150
+ children: /* @__PURE__ */ x(j, { isOpen: D })
186
151
  }),
187
- R !== void 0 && /* @__PURE__ */ d(A, { remaining: R }),
188
- L && a && /* @__PURE__ */ d(r, {
189
- elementId: F,
152
+ V !== void 0 && /* @__PURE__ */ x(R, { remaining: V }),
153
+ F && a && /* @__PURE__ */ x(r, {
154
+ elementId: N,
190
155
  errors: n,
191
156
  tone: i,
192
157
  onClick: o,
193
- hasDescription: !I
194
- })
158
+ hasDescription: !P
159
+ }),
160
+ /* @__PURE__ */ x(u, {})
195
161
  ]
196
162
  }),
197
- L && (I || !a) && /* @__PURE__ */ d(j, {
198
- errorsKey: F,
163
+ F && (P || !a) && /* @__PURE__ */ x(z, {
164
+ errorsKey: N,
199
165
  errors: n
200
166
  })
201
167
  ]
202
168
  });
203
169
  });
204
- M.displayName = "Input";
205
- var N = o(({ id: e, rows: t = 3, errors: n = [], tone: i = b.Danger, showErrors: a = !0, onErrorsClick: o, characterLimit: s, countCharacters: c = O, isDisabled: l = !1, groupClassName: u, groupStyle: m, value: h, defaultValue: g, onChange: _, ...v }, y) => {
206
- let { errorsKey: S, isInField: T, isInvalid: E, remaining: D, handleChange: M, ariaProps: N } = k({
170
+ B.displayName = "InputBox";
171
+ var V = _((e, t) => {
172
+ let { field: n, rest: r } = p(e), { isRequired: i, ...o } = r, s = i || o.required;
173
+ return f(e) ? /* @__PURE__ */ x(a, {
174
+ field: n,
175
+ errors: o.errors,
176
+ tone: o.tone,
177
+ isDisabled: o.isDisabled,
178
+ children: /* @__PURE__ */ x(B, {
179
+ ...o,
180
+ errors: void 0,
181
+ ref: t,
182
+ required: s
183
+ })
184
+ }) : /* @__PURE__ */ x(B, {
185
+ ...o,
186
+ ref: t,
187
+ required: s
188
+ });
189
+ });
190
+ V.displayName = "Input";
191
+ var H = _(({ id: e, rows: t = 3, errors: n = [], tone: i = w.Danger, showErrors: a = !0, onErrorsClick: o, characterLimit: s, countCharacters: c = M, isDisabled: l = !1, groupClassName: d, groupStyle: f, value: p, defaultValue: m, onChange: h, ...g }, _) => {
192
+ let { errorsKey: v, isInField: y, isInvalid: b, fieldTone: E, hasFieldMark: k, remaining: A, handleChange: j, ariaProps: N } = L({
207
193
  id: e,
208
194
  errors: n,
209
195
  characterLimit: s,
210
196
  countCharacters: c,
211
- value: h,
212
- defaultValue: g,
213
- onChange: _,
214
- describedBy: v["aria-describedby"]
197
+ value: p,
198
+ defaultValue: m,
199
+ onChange: h,
200
+ describedBy: g["aria-describedby"]
215
201
  });
216
- return /* @__PURE__ */ f(x, {
217
- tone: i,
218
- isInvalid: E,
219
- className: p("input-group--multiline", u),
220
- style: m,
221
- "data-has-errors": E && a || void 0,
222
- "data-has-counter": D !== void 0 || void 0,
202
+ return /* @__PURE__ */ S(T, {
203
+ tone: E ?? i,
204
+ isInvalid: b || E !== void 0,
205
+ className: C("input-group--multiline", d),
206
+ style: f,
207
+ "data-has-errors": b && a || k || void 0,
208
+ "data-has-counter": A !== void 0 || void 0,
223
209
  children: [
224
- /* @__PURE__ */ d(C, {
225
- ...v,
226
- ref: y,
210
+ /* @__PURE__ */ x(D, {
211
+ ...g,
212
+ ref: _,
227
213
  id: e,
228
214
  rows: t,
229
- value: h,
230
- defaultValue: g,
231
- onChange: M,
215
+ value: p,
216
+ defaultValue: m,
217
+ onChange: j,
232
218
  disabled: l,
233
219
  ...N
234
220
  }),
235
- E && a && /* @__PURE__ */ d(w, {
221
+ (b && a || k) && /* @__PURE__ */ S(O, {
236
222
  align: "block-start",
237
- children: /* @__PURE__ */ d(r, {
238
- elementId: S,
223
+ children: [b && a && /* @__PURE__ */ x(r, {
224
+ elementId: v,
239
225
  errors: n,
240
226
  tone: i,
241
227
  onClick: o,
242
- hasDescription: !T
243
- })
228
+ hasDescription: !y
229
+ }), /* @__PURE__ */ x(u, {})]
244
230
  }),
245
- D !== void 0 && /* @__PURE__ */ d(w, {
231
+ A !== void 0 && /* @__PURE__ */ x(O, {
246
232
  align: "block-end",
247
- children: /* @__PURE__ */ d(A, { remaining: D })
233
+ children: /* @__PURE__ */ x(R, { remaining: A })
248
234
  }),
249
- E && (T || !a) && /* @__PURE__ */ d(j, {
250
- errorsKey: S,
235
+ b && (y || !a) && /* @__PURE__ */ x(z, {
236
+ errorsKey: v,
251
237
  errors: n
252
238
  })
253
239
  ]
254
240
  });
255
241
  });
256
- N.displayName = "Textarea";
242
+ H.displayName = "TextareaBox";
243
+ var U = _((e, t) => {
244
+ let { field: n, rest: r } = p(e), { isRequired: i, ...o } = r, s = i || o.required;
245
+ return f(e) ? /* @__PURE__ */ x(a, {
246
+ field: n,
247
+ errors: o.errors,
248
+ tone: o.tone,
249
+ isDisabled: o.isDisabled,
250
+ children: /* @__PURE__ */ x(H, {
251
+ ...o,
252
+ errors: void 0,
253
+ ref: t,
254
+ required: s
255
+ })
256
+ }) : /* @__PURE__ */ x(H, {
257
+ ...o,
258
+ ref: t,
259
+ required: s
260
+ });
261
+ });
262
+ U.displayName = "Textarea";
257
263
  //#endregion
258
- export { g as Field, v as FieldDescription, y as FieldGroup, _ as FieldLabel, M as Input, M as default, x as InputGroup, w as InputGroupAddon, E as InputGroupButton, S as InputGroupInput, T as InputGroupText, C as InputGroupTextarea, b as InputTone, N as Textarea };
264
+ 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 };
259
265
 
260
266
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/cn.ts","../src/field.tsx","../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 {Field as BaseField} from '@base-ui-components/react/field';\nimport {type CSSProperties, createContext, forwardRef, type PropsWithoutRef, useContext} from 'react';\nimport {cn} from './cn';\nimport type {FieldDescriptionProps, FieldGroupProps, FieldLabelProps, FieldProps} from './types';\n\n/*\n * The parts follow shadcn's Field, on Base UI's. The field wires itself: the\n * label points at the input, and the input is described by the description and\n * by its errors, with no ids written by hand.\n */\n\n/** Whether a part is standing inside a `Field`, which then does the wiring. */\nconst FieldContext = createContext<boolean>(false);\n\nconst useIsInField = (): boolean => useContext(FieldContext);\n\n/** A label, a control and a description, stacked or in a row. */\nconst Field = forwardRef<HTMLDivElement, PropsWithoutRef<FieldProps>>(\n ({orientation = 'vertical', isDisabled, isInvalid, className, ...props}, ref) => (\n <FieldContext.Provider value={true}>\n <BaseField.Root\n {...props}\n ref={ref}\n disabled={isDisabled}\n invalid={isInvalid}\n data-orientation={orientation}\n className={cn('field', className)}\n />\n </FieldContext.Provider>\n ),\n);\nField.displayName = 'Field';\n\n/** The label. Inside a `Field` it finds the input itself; outside one, pass `htmlFor`. */\nconst FieldLabel = forwardRef<HTMLLabelElement, PropsWithoutRef<FieldLabelProps>>(\n ({isRequired = false, className, ...props}, ref) => (\n <BaseField.Label\n {...props}\n ref={ref}\n data-required={isRequired || undefined}\n className={cn('field-label', className)}\n />\n ),\n);\nFieldLabel.displayName = 'FieldLabel';\n\n/** Quiet text under the input. The input is described by it. */\nconst FieldDescription = forwardRef<HTMLParagraphElement, PropsWithoutRef<FieldDescriptionProps>>(\n ({className, ...props}, ref) => (\n <BaseField.Description {...props} ref={ref} className={cn('field-description', className)} />\n ),\n);\nFieldDescription.displayName = 'FieldDescription';\n\n/** Fields of one form, spaced apart; `columns` lays them out in a grid. */\nconst FieldGroup = forwardRef<HTMLDivElement, PropsWithoutRef<FieldGroupProps>>(\n ({columns, className, style, ...props}, ref) => (\n <div\n {...props}\n ref={ref}\n data-columns={columns}\n className={cn('field-group', className)}\n style={columns === undefined ? style : ({'--field-group-columns': columns, ...style} as CSSProperties)}\n />\n ),\n);\nFieldGroup.displayName = 'FieldGroup';\n\nexport {Field, FieldDescription, FieldGroup, FieldLabel, useIsInField};\n","import type {Button as BaseButton} from '@base-ui-components/react/button';\nimport type {Field as BaseField} from '@base-ui-components/react/field';\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\nexport type FieldProps = Omit<ComponentProps<typeof BaseField.Root>, 'className' | 'disabled' | 'invalid'> & {\n className?: string;\n /** `horizontal` puts the parts in a row: an input and its button, a checkbox and its label. @default 'vertical' */\n orientation?: 'vertical' | 'horizontal';\n /** Switches off the input inside and fades the label and the description. */\n isDisabled?: boolean;\n /** Marks the field invalid: the contour, the label and `aria-invalid` on the input. */\n isInvalid?: boolean;\n};\n\nexport type FieldLabelProps = Omit<ComponentProps<typeof BaseField.Label>, 'className'> & {\n className?: string;\n /** Adds the asterisk. The input itself takes `required` separately. */\n isRequired?: boolean;\n};\n\nexport type FieldDescriptionProps = Omit<ComponentProps<typeof BaseField.Description>, 'className'> & {\n className?: string;\n};\n\nexport type FieldGroupProps = ComponentPropsWithRef<'div'> & {\n /** Lays the fields out in this many equal columns. Stacked when omitted. */\n columns?: number;\n};\n\n/** What `Input` and `Textarea` share: the errors, the counter, the switch and the box. */\ntype FieldControlOwnProps = {\n /**\n * Shown behind the `!` mark at the end of the field. A non-empty list also\n * draws the contour in the tone and sets `aria-invalid`.\n */\n errors?: ReadonlyArray<string>;\n /** Which colour the errors are shown in. @default 'danger' */\n tone?: InputTone;\n /** Hides the `!` mark and keeps the contour and the description. @default true */\n showErrors?: boolean;\n /** Called when the `!` mark 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 {type ChangeEvent, type ComponentProps, forwardRef, type PropsWithoutRef, useId, useState} from 'react';\nimport './input.css';\nimport {cn} from './cn';\nimport {Field, FieldDescription, FieldGroup, FieldLabel, useIsInField} from './field';\nimport {\n type FieldDescriptionProps,\n type FieldGroupProps,\n type FieldLabelProps,\n type FieldProps,\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\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 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 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, 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/**\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 */\nconst Input = 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, remaining, handleChange, ariaProps} = 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 tone={tone} isInvalid={isInvalid} className={groupClassName} style={groupStyle}>\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 || isPassword || remaining !== undefined || (isInvalid && showErrors)) && (\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 </InputGroupAddon>\n )}\n {isInvalid && (isInField || !showErrors) && <HiddenErrors errorsKey={errorsKey} errors={errors} />}\n </InputGroup>\n );\n },\n);\nInput.displayName = 'Input';\n\n/**\n * A field for more than a line, the same box as `Input`. 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 Textarea = 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, remaining, handleChange, ariaProps} = 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={tone}\n isInvalid={isInvalid}\n className={cn('input-group--multiline', groupClassName)}\n style={groupStyle}\n data-has-errors={(isInvalid && showErrors) || 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 && (\n <InputGroupAddon align=\"block-start\">\n <ErrorLabel\n elementId={errorsKey}\n errors={errors}\n tone={tone}\n onClick={onErrorsClick}\n hasDescription={!isInField}\n />\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);\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,ECKtD,IAAe,EAAuB,GAAM,EAE5C,UAA8B,EAAW,EAAa,EAGtD,IAAQ,GACX,EAAC,iBAAc,YAAY,eAAY,cAAW,cAAW,GAAG,KAAQ,MACvE,kBAAC,EAAa,UAAd;CAAuB,OAAO;WAC5B,kBAAC,EAAU,MAAX;EACE,GAAI;EACC;EACL,UAAU;EACV,SAAS;EACT,oBAAkB;EAClB,WAAW,EAAG,SAAS,EAAU;EACjC,CAAA;CACoB,CAAA,CAE3B;AACD,EAAM,cAAc;AAGpB,IAAM,IAAa,GAChB,EAAC,gBAAa,IAAO,cAAW,GAAG,KAAQ,MAC1C,kBAAC,EAAU,OAAX;CACE,GAAI;CACC;CACL,iBAAe,KAAc,KAAA;CAC7B,WAAW,EAAG,eAAe,EAAU;CACvC,CAAA,CAEL;AACD,EAAW,cAAc;AAGzB,IAAM,IAAmB,GACtB,EAAC,cAAW,GAAG,KAAQ,MACtB,kBAAC,EAAU,aAAX;CAAuB,GAAI;CAAY;CAAK,WAAW,EAAG,qBAAqB,EAAU;CAAI,CAAA,CAEhG;AACD,EAAiB,cAAc;AAG/B,IAAM,IAAa,GAChB,EAAC,YAAS,cAAW,UAAO,GAAG,KAAQ,MACtC,kBAAC,OAAD;CACE,GAAI;CACC;CACL,gBAAc;CACd,WAAW,EAAG,eAAe,EAAU;CACvC,OAAO,MAAY,KAAA,IAAY,IAAS;EAAC,yBAAyB;EAAS,GAAG;EAAM;CACpF,CAAA,CAEL;AACD,EAAW,cAAc;;;AC7DzB,IAAa,IAAY;CAEvB,QAAQ;CAER,SAAS;CACV,ECsBK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gBAAa,IACb,mBACA,eACA,UACA,iBACA,aACA,GAAG,KAEL,MACG;CACH,IAAM,EAAC,cAAW,cAAW,cAAW,cAAW,iBAAc,iBAAa,EAAqC;EACjH;EACA;EACA;EACA;EACA;EACA;EACA;EACA,aAAa,EAAM;EACpB,CAAC;CAEF,OACE,kBAAC,GAAD;EACQ;EACK;EACX,WAAW,EAAG,0BAA0B,EAAe;EACvD,OAAO;EACP,mBAAkB,KAAa,KAAe,KAAA;EAC9C,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;GACD,KAAa,KACZ,kBAAC,GAAD;IAAiB,OAAM;cACrB,kBAAC,GAAD;KACE,WAAW;KACH;KACF;KACN,SAAS;KACT,gBAAgB,CAAC;KACjB,CAAA;IACc,CAAA;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,EAAS,cAAc"}
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,GAAG,KAAQ,M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C9D,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@propellerads/input",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "type": "module",
5
5
  "types": "dist/index.d.ts",
6
6
  "style": "dist/index.css",
@@ -30,7 +30,8 @@
30
30
  "private": false,
31
31
  "dependencies": {
32
32
  "@base-ui-components/react": "1.0.0-rc.0",
33
- "@propellerads/error-label": "^8.0.0",
33
+ "@propellerads/error-label": "^8.0.1",
34
+ "@propellerads/label": "^6.1.0",
34
35
  "class-variance-authority": "^0.7.1",
35
36
  "clsx": "^2.1.1"
36
37
  },