@page-speed/forms 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/inputs.cjs +28 -16
- package/dist/inputs.cjs.map +1 -1
- package/dist/inputs.d.cts +13 -7
- package/dist/inputs.d.ts +13 -7
- package/dist/inputs.js +28 -16
- package/dist/inputs.js.map +1 -1
- package/package.json +1 -1
package/dist/inputs.d.cts
CHANGED
|
@@ -124,10 +124,13 @@ interface CheckboxProps extends Omit<InputProps<boolean>, "onChange" | "placehol
|
|
|
124
124
|
*/
|
|
125
125
|
indeterminate?: boolean;
|
|
126
126
|
/**
|
|
127
|
-
* Label text for the checkbox
|
|
128
|
-
* Can also wrap checkbox in a label element
|
|
127
|
+
* Label text for the checkbox (primary text)
|
|
129
128
|
*/
|
|
130
129
|
label?: React.ReactNode;
|
|
130
|
+
/**
|
|
131
|
+
* Optional description text below the label (secondary text)
|
|
132
|
+
*/
|
|
133
|
+
description?: React.ReactNode;
|
|
131
134
|
/**
|
|
132
135
|
* Additional native input attributes
|
|
133
136
|
*/
|
|
@@ -144,7 +147,8 @@ interface CheckboxProps extends Omit<InputProps<boolean>, "onChange" | "placehol
|
|
|
144
147
|
* - Error state styling
|
|
145
148
|
* - Controlled input behavior
|
|
146
149
|
* - Indeterminate state support
|
|
147
|
-
* - Optional label text
|
|
150
|
+
* - Optional label and description text (with nil guards)
|
|
151
|
+
* - Proper field-based layout structure
|
|
148
152
|
* - All native checkbox attributes supported
|
|
149
153
|
*
|
|
150
154
|
* @example
|
|
@@ -154,6 +158,7 @@ interface CheckboxProps extends Omit<InputProps<boolean>, "onChange" | "placehol
|
|
|
154
158
|
* <Checkbox
|
|
155
159
|
* {...form.getFieldProps('terms')}
|
|
156
160
|
* label="I agree to the terms and conditions"
|
|
161
|
+
* description="By clicking this checkbox, you agree to the terms."
|
|
157
162
|
* error={!!form.errors.terms}
|
|
158
163
|
* aria-describedby={form.errors.terms ? 'terms-error' : undefined}
|
|
159
164
|
* />
|
|
@@ -173,7 +178,7 @@ interface CheckboxProps extends Omit<InputProps<boolean>, "onChange" | "placehol
|
|
|
173
178
|
*
|
|
174
179
|
* @see https://opensite.ai/developers/page-speed/forms/checkbox
|
|
175
180
|
*/
|
|
176
|
-
declare function Checkbox({ name, value, onChange, onBlur, disabled, required, error, className, indeterminate, label, ...props }: CheckboxProps): React.JSX.Element;
|
|
181
|
+
declare function Checkbox({ name, value, onChange, onBlur, disabled, required, error, className, indeterminate, label, description, ...props }: CheckboxProps): React.JSX.Element;
|
|
177
182
|
declare namespace Checkbox {
|
|
178
183
|
var displayName: string;
|
|
179
184
|
}
|
|
@@ -329,11 +334,11 @@ interface RadioOption {
|
|
|
329
334
|
*/
|
|
330
335
|
value: string;
|
|
331
336
|
/**
|
|
332
|
-
* Display label for the option
|
|
337
|
+
* Display label for the option (primary text)
|
|
333
338
|
*/
|
|
334
339
|
label: React.ReactNode;
|
|
335
340
|
/**
|
|
336
|
-
* Optional description text below the label
|
|
341
|
+
* Optional description text below the label (secondary text)
|
|
337
342
|
*/
|
|
338
343
|
description?: React.ReactNode;
|
|
339
344
|
/**
|
|
@@ -379,8 +384,9 @@ interface RadioProps extends Omit<InputProps<string>, "onChange" | "placeholder"
|
|
|
379
384
|
* - Controlled input behavior
|
|
380
385
|
* - Keyboard navigation (arrow keys)
|
|
381
386
|
* - Inline or stacked layout
|
|
382
|
-
* - Optional descriptions for each option
|
|
387
|
+
* - Optional descriptions for each option (with nil guard)
|
|
383
388
|
* - Individual option disabled state
|
|
389
|
+
* - Card-based styling with proper visual hierarchy
|
|
384
390
|
* - All native radio attributes supported
|
|
385
391
|
*
|
|
386
392
|
* @example
|
package/dist/inputs.d.ts
CHANGED
|
@@ -124,10 +124,13 @@ interface CheckboxProps extends Omit<InputProps<boolean>, "onChange" | "placehol
|
|
|
124
124
|
*/
|
|
125
125
|
indeterminate?: boolean;
|
|
126
126
|
/**
|
|
127
|
-
* Label text for the checkbox
|
|
128
|
-
* Can also wrap checkbox in a label element
|
|
127
|
+
* Label text for the checkbox (primary text)
|
|
129
128
|
*/
|
|
130
129
|
label?: React.ReactNode;
|
|
130
|
+
/**
|
|
131
|
+
* Optional description text below the label (secondary text)
|
|
132
|
+
*/
|
|
133
|
+
description?: React.ReactNode;
|
|
131
134
|
/**
|
|
132
135
|
* Additional native input attributes
|
|
133
136
|
*/
|
|
@@ -144,7 +147,8 @@ interface CheckboxProps extends Omit<InputProps<boolean>, "onChange" | "placehol
|
|
|
144
147
|
* - Error state styling
|
|
145
148
|
* - Controlled input behavior
|
|
146
149
|
* - Indeterminate state support
|
|
147
|
-
* - Optional label text
|
|
150
|
+
* - Optional label and description text (with nil guards)
|
|
151
|
+
* - Proper field-based layout structure
|
|
148
152
|
* - All native checkbox attributes supported
|
|
149
153
|
*
|
|
150
154
|
* @example
|
|
@@ -154,6 +158,7 @@ interface CheckboxProps extends Omit<InputProps<boolean>, "onChange" | "placehol
|
|
|
154
158
|
* <Checkbox
|
|
155
159
|
* {...form.getFieldProps('terms')}
|
|
156
160
|
* label="I agree to the terms and conditions"
|
|
161
|
+
* description="By clicking this checkbox, you agree to the terms."
|
|
157
162
|
* error={!!form.errors.terms}
|
|
158
163
|
* aria-describedby={form.errors.terms ? 'terms-error' : undefined}
|
|
159
164
|
* />
|
|
@@ -173,7 +178,7 @@ interface CheckboxProps extends Omit<InputProps<boolean>, "onChange" | "placehol
|
|
|
173
178
|
*
|
|
174
179
|
* @see https://opensite.ai/developers/page-speed/forms/checkbox
|
|
175
180
|
*/
|
|
176
|
-
declare function Checkbox({ name, value, onChange, onBlur, disabled, required, error, className, indeterminate, label, ...props }: CheckboxProps): React.JSX.Element;
|
|
181
|
+
declare function Checkbox({ name, value, onChange, onBlur, disabled, required, error, className, indeterminate, label, description, ...props }: CheckboxProps): React.JSX.Element;
|
|
177
182
|
declare namespace Checkbox {
|
|
178
183
|
var displayName: string;
|
|
179
184
|
}
|
|
@@ -329,11 +334,11 @@ interface RadioOption {
|
|
|
329
334
|
*/
|
|
330
335
|
value: string;
|
|
331
336
|
/**
|
|
332
|
-
* Display label for the option
|
|
337
|
+
* Display label for the option (primary text)
|
|
333
338
|
*/
|
|
334
339
|
label: React.ReactNode;
|
|
335
340
|
/**
|
|
336
|
-
* Optional description text below the label
|
|
341
|
+
* Optional description text below the label (secondary text)
|
|
337
342
|
*/
|
|
338
343
|
description?: React.ReactNode;
|
|
339
344
|
/**
|
|
@@ -379,8 +384,9 @@ interface RadioProps extends Omit<InputProps<string>, "onChange" | "placeholder"
|
|
|
379
384
|
* - Controlled input behavior
|
|
380
385
|
* - Keyboard navigation (arrow keys)
|
|
381
386
|
* - Inline or stacked layout
|
|
382
|
-
* - Optional descriptions for each option
|
|
387
|
+
* - Optional descriptions for each option (with nil guard)
|
|
383
388
|
* - Individual option disabled state
|
|
389
|
+
* - Card-based styling with proper visual hierarchy
|
|
384
390
|
* - All native radio attributes supported
|
|
385
391
|
*
|
|
386
392
|
* @example
|
package/dist/inputs.js
CHANGED
|
@@ -106,9 +106,11 @@ function Checkbox({
|
|
|
106
106
|
className = "",
|
|
107
107
|
indeterminate = false,
|
|
108
108
|
label,
|
|
109
|
+
description,
|
|
109
110
|
...props
|
|
110
111
|
}) {
|
|
111
112
|
const inputRef = React7.useRef(null);
|
|
113
|
+
const checkboxId = props.id || `checkbox-${name}`;
|
|
112
114
|
React7.useEffect(() => {
|
|
113
115
|
if (inputRef.current) {
|
|
114
116
|
inputRef.current.indeterminate = indeterminate;
|
|
@@ -122,27 +124,37 @@ function Checkbox({
|
|
|
122
124
|
};
|
|
123
125
|
const baseClassName = "checkbox";
|
|
124
126
|
const errorClassName = error ? "checkbox--error" : "";
|
|
125
|
-
const
|
|
127
|
+
const checkedClassName = value ? "checkbox--checked" : "";
|
|
128
|
+
const disabledClassName = disabled ? "checkbox--disabled" : "";
|
|
129
|
+
const combinedClassName = `${baseClassName} ${errorClassName} ${checkedClassName} ${disabledClassName} ${className}`.trim();
|
|
126
130
|
const checkbox = /* @__PURE__ */ React7.createElement(
|
|
127
131
|
"input",
|
|
128
132
|
{
|
|
129
133
|
ref: inputRef,
|
|
130
134
|
type: "checkbox",
|
|
135
|
+
id: checkboxId,
|
|
131
136
|
name,
|
|
132
137
|
checked: value,
|
|
133
138
|
onChange: handleChange,
|
|
134
139
|
onBlur: handleBlur,
|
|
135
140
|
disabled,
|
|
136
141
|
required,
|
|
137
|
-
className:
|
|
142
|
+
className: "checkbox-input",
|
|
138
143
|
"aria-invalid": error || props["aria-invalid"],
|
|
139
|
-
"aria-describedby": props["aria-describedby"],
|
|
144
|
+
"aria-describedby": description ? `${checkboxId}-description` : props["aria-describedby"],
|
|
140
145
|
"aria-required": required || props["aria-required"],
|
|
141
146
|
...props
|
|
142
147
|
}
|
|
143
148
|
);
|
|
144
149
|
if (label) {
|
|
145
|
-
return /* @__PURE__ */ React7.createElement("label", { className: "checkbox-
|
|
150
|
+
return /* @__PURE__ */ React7.createElement("label", { className: `checkbox-field ${combinedClassName}`, htmlFor: checkboxId }, /* @__PURE__ */ React7.createElement("div", { className: "checkbox-field-content" }, checkbox, /* @__PURE__ */ React7.createElement("div", { className: "checkbox-field-text" }, /* @__PURE__ */ React7.createElement("span", { className: "checkbox-label" }, label), description && /* @__PURE__ */ React7.createElement(
|
|
151
|
+
"span",
|
|
152
|
+
{
|
|
153
|
+
className: "checkbox-description",
|
|
154
|
+
id: `${checkboxId}-description`
|
|
155
|
+
},
|
|
156
|
+
description
|
|
157
|
+
))));
|
|
146
158
|
}
|
|
147
159
|
return checkbox;
|
|
148
160
|
}
|
|
@@ -338,10 +350,19 @@ function Radio({
|
|
|
338
350
|
"label",
|
|
339
351
|
{
|
|
340
352
|
key: option.value,
|
|
341
|
-
className: `radio-option ${isDisabled ? "radio-option--disabled" : ""}`,
|
|
342
|
-
htmlFor: radioId
|
|
353
|
+
className: `radio-option ${isChecked ? "radio-option--checked" : ""} ${isDisabled ? "radio-option--disabled" : ""}`,
|
|
354
|
+
htmlFor: radioId,
|
|
355
|
+
onKeyDown: (e) => handleKeyDown(e, index),
|
|
356
|
+
tabIndex: 0
|
|
343
357
|
},
|
|
344
|
-
/* @__PURE__ */ React7.createElement(
|
|
358
|
+
/* @__PURE__ */ React7.createElement("div", { className: "radio-option-content" }, /* @__PURE__ */ React7.createElement("div", { className: "radio-option-text" }, /* @__PURE__ */ React7.createElement("span", { className: "radio-label" }, option.label), option.description && /* @__PURE__ */ React7.createElement(
|
|
359
|
+
"span",
|
|
360
|
+
{
|
|
361
|
+
className: "radio-description",
|
|
362
|
+
id: `${radioId}-description`
|
|
363
|
+
},
|
|
364
|
+
option.description
|
|
365
|
+
)), /* @__PURE__ */ React7.createElement(
|
|
345
366
|
"input",
|
|
346
367
|
{
|
|
347
368
|
type: "radio",
|
|
@@ -351,20 +372,11 @@ function Radio({
|
|
|
351
372
|
checked: isChecked,
|
|
352
373
|
onChange: (e) => handleChange(e.target.value),
|
|
353
374
|
onBlur: handleBlur,
|
|
354
|
-
onKeyDown: (e) => handleKeyDown(e, index),
|
|
355
375
|
disabled: isDisabled,
|
|
356
376
|
required,
|
|
357
377
|
className: "radio-input",
|
|
358
378
|
"aria-describedby": option.description ? `${radioId}-description` : props["aria-describedby"]
|
|
359
379
|
}
|
|
360
|
-
),
|
|
361
|
-
/* @__PURE__ */ React7.createElement("div", { className: "radio-content" }, /* @__PURE__ */ React7.createElement("span", { className: "radio-label" }, option.label), option.description && /* @__PURE__ */ React7.createElement(
|
|
362
|
-
"span",
|
|
363
|
-
{
|
|
364
|
-
className: "radio-description",
|
|
365
|
-
id: `${radioId}-description`
|
|
366
|
-
},
|
|
367
|
-
option.description
|
|
368
380
|
))
|
|
369
381
|
);
|
|
370
382
|
}))
|