@propellerads/input 2.0.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/README.md +80 -57
- package/dist/index.css +1 -1
- package/dist/index.d.ts +32 -43
- package/dist/index.js +154 -149
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
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
|
|
35
|
-
|
|
36
|
-
<
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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 {
|
|
65
|
+
import {Textarea} from '@propellerads/input';
|
|
62
66
|
|
|
63
|
-
<
|
|
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,
|
|
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
|
-
##
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
| `
|
|
151
|
-
| `
|
|
152
|
-
| `
|
|
153
|
-
| `
|
|
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` |
|
|
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` | `
|
|
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` | `
|
|
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}.
|
|
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 {
|
|
2
|
+
import { ComponentPropsWithRef, ReactNode, Ref, ComponentProps } from 'react';
|
|
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
|
+
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
/**
|
|
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
|
-
|
|
47
|
-
|
|
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
|
-
*
|
|
57
|
-
*
|
|
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
|
-
/**
|
|
50
|
+
/** @deprecated Use `warning` instead of `errors` with `tone="warning"`. @default 'danger' */
|
|
61
51
|
tone?: InputTone;
|
|
62
|
-
/** Hides the `!` mark and keeps the contour
|
|
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: typeof Field$1;
|
|
102
|
+
/** @deprecated Import `FieldLabel` from `@propellerads/label`. */
|
|
103
|
+
declare const FieldLabel: typeof FieldLabel$1;
|
|
104
|
+
/** @deprecated Import `FieldDescription` from `@propellerads/label`. */
|
|
105
|
+
declare const FieldDescription: typeof FieldDescription$1;
|
|
106
|
+
/** @deprecated Import `FieldGroup` from `@propellerads/label`. */
|
|
107
|
+
declare const FieldGroup: typeof FieldGroup$1;
|
|
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 {
|
|
122
|
+
export type { InputGroupAddonProps, InputGroupButtonProps, InputGroupInputProps, InputGroupProps, InputGroupTextProps, InputGroupTextareaProps, InputProps, TextareaProps };
|
package/dist/index.js
CHANGED
|
@@ -2,259 +2,264 @@ 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 {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
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 = {
|
|
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";
|
|
9
|
+
import './index.css';// src/cn.ts
|
|
10
|
+
var C = (...e) => b(e), w = {
|
|
48
11
|
Danger: "danger",
|
|
49
12
|
Warning: "warning"
|
|
50
|
-
},
|
|
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:
|
|
18
|
+
className: C("input-group", n)
|
|
56
19
|
}));
|
|
57
|
-
|
|
58
|
-
var
|
|
20
|
+
T.displayName = "InputGroup";
|
|
21
|
+
var E = _(({ className: e, ...t }, r) => /* @__PURE__ */ x(n, {
|
|
59
22
|
...t,
|
|
60
23
|
ref: r,
|
|
61
|
-
className:
|
|
24
|
+
className: C("input-group__control", e)
|
|
62
25
|
}));
|
|
63
|
-
|
|
64
|
-
var
|
|
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__ */
|
|
68
|
-
className:
|
|
30
|
+
render: /* @__PURE__ */ x("textarea", {}),
|
|
31
|
+
className: C("input-group__control", "input-group__control--multiline", e)
|
|
69
32
|
}));
|
|
70
|
-
|
|
71
|
-
var
|
|
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:
|
|
38
|
+
className: C("input-group__addon", `input-group__addon--${e}`, t)
|
|
76
39
|
}));
|
|
77
|
-
|
|
78
|
-
var
|
|
40
|
+
O.displayName = "InputGroupAddon";
|
|
41
|
+
var k = _(({ className: e, ...t }, n) => /* @__PURE__ */ x("span", {
|
|
79
42
|
...t,
|
|
80
43
|
ref: n,
|
|
81
|
-
className:
|
|
44
|
+
className: C("input-group__text", e)
|
|
82
45
|
}));
|
|
83
|
-
|
|
84
|
-
var
|
|
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:
|
|
51
|
+
className: C("input-group__button", t)
|
|
89
52
|
}));
|
|
90
|
-
|
|
91
|
-
var
|
|
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__ */
|
|
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__ */
|
|
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__ */
|
|
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
|
-
}),
|
|
119
|
-
let
|
|
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:
|
|
122
|
-
isInField:
|
|
123
|
-
isInvalid:
|
|
124
|
-
|
|
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 &&
|
|
91
|
+
a === void 0 && x(e.target.value), s?.(e);
|
|
127
92
|
},
|
|
128
93
|
ariaProps: {
|
|
129
|
-
...
|
|
130
|
-
...
|
|
94
|
+
...S ? { "aria-invalid": !0 } : {},
|
|
95
|
+
...S && !l ? { "aria-describedby": C(c, i(_)) } : {}
|
|
131
96
|
}
|
|
132
97
|
};
|
|
133
|
-
},
|
|
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
|
-
}),
|
|
138
|
-
let r =
|
|
139
|
-
return
|
|
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
|
-
},
|
|
145
|
-
let [
|
|
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:
|
|
151
|
-
defaultValue:
|
|
152
|
-
onChange:
|
|
153
|
-
describedBy:
|
|
154
|
-
}),
|
|
155
|
-
return /* @__PURE__ */
|
|
156
|
-
tone: i,
|
|
157
|
-
isInvalid:
|
|
158
|
-
className:
|
|
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
|
-
|
|
126
|
+
d !== void 0 && /* @__PURE__ */ x(O, {
|
|
162
127
|
align: "inline-start",
|
|
163
|
-
children:
|
|
128
|
+
children: d
|
|
164
129
|
}),
|
|
165
|
-
/* @__PURE__ */
|
|
166
|
-
...
|
|
167
|
-
ref:
|
|
130
|
+
/* @__PURE__ */ x(E, {
|
|
131
|
+
...b,
|
|
132
|
+
ref: C,
|
|
168
133
|
id: t,
|
|
169
|
-
type:
|
|
170
|
-
value:
|
|
171
|
-
defaultValue:
|
|
172
|
-
onChange:
|
|
173
|
-
disabled:
|
|
174
|
-
...
|
|
134
|
+
type: W && D ? "text" : e,
|
|
135
|
+
value: g,
|
|
136
|
+
defaultValue: _,
|
|
137
|
+
onChange: H,
|
|
138
|
+
disabled: l,
|
|
139
|
+
...U
|
|
175
140
|
}),
|
|
176
|
-
(
|
|
141
|
+
(f !== void 0 || W || V !== void 0 || F && a || B) && /* @__PURE__ */ S(O, {
|
|
177
142
|
align: "inline-end",
|
|
178
143
|
children: [
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
"aria-label":
|
|
182
|
-
"aria-pressed":
|
|
183
|
-
disabled:
|
|
184
|
-
onClick: () =>
|
|
185
|
-
children: /* @__PURE__ */
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
elementId:
|
|
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: !
|
|
194
|
-
})
|
|
158
|
+
hasDescription: !P
|
|
159
|
+
}),
|
|
160
|
+
/* @__PURE__ */ x(u, {})
|
|
195
161
|
]
|
|
196
162
|
}),
|
|
197
|
-
|
|
198
|
-
errorsKey:
|
|
163
|
+
F && (P || !a) && /* @__PURE__ */ x(z, {
|
|
164
|
+
errorsKey: N,
|
|
199
165
|
errors: n
|
|
200
166
|
})
|
|
201
167
|
]
|
|
202
168
|
});
|
|
203
169
|
});
|
|
204
|
-
|
|
205
|
-
var
|
|
206
|
-
let {
|
|
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:
|
|
212
|
-
defaultValue:
|
|
213
|
-
onChange:
|
|
214
|
-
describedBy:
|
|
197
|
+
value: p,
|
|
198
|
+
defaultValue: m,
|
|
199
|
+
onChange: h,
|
|
200
|
+
describedBy: g["aria-describedby"]
|
|
215
201
|
});
|
|
216
|
-
return /* @__PURE__ */
|
|
217
|
-
tone: i,
|
|
218
|
-
isInvalid: E,
|
|
219
|
-
className:
|
|
220
|
-
style:
|
|
221
|
-
"data-has-errors":
|
|
222
|
-
"data-has-counter":
|
|
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__ */
|
|
225
|
-
...
|
|
226
|
-
ref:
|
|
210
|
+
/* @__PURE__ */ x(D, {
|
|
211
|
+
...g,
|
|
212
|
+
ref: _,
|
|
227
213
|
id: e,
|
|
228
214
|
rows: t,
|
|
229
|
-
value:
|
|
230
|
-
defaultValue:
|
|
231
|
-
onChange:
|
|
215
|
+
value: p,
|
|
216
|
+
defaultValue: m,
|
|
217
|
+
onChange: j,
|
|
232
218
|
disabled: l,
|
|
233
219
|
...N
|
|
234
220
|
}),
|
|
235
|
-
|
|
221
|
+
(b && a || k) && /* @__PURE__ */ S(O, {
|
|
236
222
|
align: "block-start",
|
|
237
|
-
children: /* @__PURE__ */
|
|
238
|
-
elementId:
|
|
223
|
+
children: [b && a && /* @__PURE__ */ x(r, {
|
|
224
|
+
elementId: v,
|
|
239
225
|
errors: n,
|
|
240
226
|
tone: i,
|
|
241
227
|
onClick: o,
|
|
242
|
-
hasDescription: !
|
|
243
|
-
})
|
|
228
|
+
hasDescription: !y
|
|
229
|
+
}), /* @__PURE__ */ x(u, {})]
|
|
244
230
|
}),
|
|
245
|
-
|
|
231
|
+
A !== void 0 && /* @__PURE__ */ x(O, {
|
|
246
232
|
align: "block-end",
|
|
247
|
-
children: /* @__PURE__ */
|
|
233
|
+
children: /* @__PURE__ */ x(R, { remaining: A })
|
|
248
234
|
}),
|
|
249
|
-
|
|
250
|
-
errorsKey:
|
|
235
|
+
b && (y || !a) && /* @__PURE__ */ x(z, {
|
|
236
|
+
errorsKey: v,
|
|
251
237
|
errors: n
|
|
252
238
|
})
|
|
253
239
|
]
|
|
254
240
|
});
|
|
255
241
|
});
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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";
|
|
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 };
|
|
259
264
|
|
|
260
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/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,IAAa,GAChB,EAAC,UAAO,EA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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":["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,KAAQ,MAClE,kBAAC,OAAD;CACE,GAAIA;CACC;CACL,aAAWC;CACX,gBAAcC,KAAa,KAAA;CAC3B,WAAWR,EAAG,eAAeS,CAAS;AACvC,CAAA,CAEL;AACA,EAAW,cAAc;AAGzB,IAAMC,IAAkBL,GACrB,EAAC,cAAW,GAAGC,KAAQ,MAAQ,kBAACpB,GA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vD,KAAayD,KAAeC,MAC7B,kBAACtD,GAAD;IAAiB,OAAM;IAAvB,UAAA,CACGJ,KAAayD,KACZ,kBAACtE,GAAD;KACE,WAAWuC;KACH;KACF;KACN,SAASmC;KACT,gBAAgB,CAAC3C;IAClB,CAAA,GAEH,kBAAC4C,GAAD,CAAY,CAAA,CACG;;GAElBrB,MAAc,KAAA,KACb,kBAACrC,GAAD;IAAiB,OAAM;IACrB,UAAA,kBAACoC,GAAD,EAAoB,aAAY,CAAA;GACjB,CAAA;GAElBxC,MAAckB,KAAa,CAACuC,MAAe,kBAACf,GAAD;IAAyB;IAAmB;GAAS,CAAA;EACvF;;AAEhB,CACF;AACA,EAAY,cAAc;AAG1B,IAAM8B,IAAW3E,GAAiE,GAAO,MAAQ;CAC/F,IAAM,EAAC,UAAO,YAAQmE,EAAgBlE,CAAK,GACrC,EAAC,eAAY,GAAGmE,MAAWC,GAC3BC,IAAWC,KAAcH,EAAQ;CAIvC,OAHKI,EAAcvE,CAAK,IAItB,kBAACwE,GAAD;EAAqB;EAAO,QAAQL,EAAQ;EAAQ,MAAMA,EAAQ;EAAM,YAAYA,EAAQ;EAC1F,UAAA,kBAACM,GAAD;GAAa,GAAIN;GAAS,QAAQ,KAAA;GAAgB;GAAe;EAAW,CAAA;CAChE,CAAA,IALP,kBAACM,GAAD;EAAa,GAAIN;EAAc;EAAe;CAAW,CAAA;AAOpE,CAAC;AACD,EAAS,cAAc"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@propellerads/input",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"style": "dist/index.css",
|
|
@@ -24,18 +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": "^
|
|
33
|
+
"@propellerads/error-label": "^9.0.0",
|
|
34
|
+
"@propellerads/label": "^7.0.0",
|
|
34
35
|
"class-variance-authority": "^0.7.1",
|
|
35
36
|
"clsx": "^2.1.1"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
|
38
|
-
"@propellerads/tokens": ">=0.
|
|
39
|
+
"@propellerads/tokens": ">=0.5.0",
|
|
39
40
|
"react": "^18.0.0 || ^19.0.0",
|
|
40
41
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
41
42
|
},
|