@page-speed/forms 0.3.5 → 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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { I as InputProps } from './types-WxAFrgDW.cjs';
2
+ import { I as InputProps } from './types-BBif0kuP.cjs';
3
3
 
4
4
  /**
5
5
  * TextInput - High-performance text input component
@@ -29,7 +29,7 @@ import { I as InputProps } from './types-WxAFrgDW.cjs';
29
29
  *
30
30
  * @see https://opensite.ai/developers/page-speed/forms/text-input
31
31
  */
32
- declare function TextInput({ name, value, onChange, onBlur, placeholder, disabled, required, error, className, type, ...props }: InputProps<string> & {
32
+ declare function TextInput({ name, value, onChange, onBlur, placeholder, disabled, required, error, className, type, id, ...props }: InputProps<string> & {
33
33
  type?: "text" | "email" | "password" | "url" | "tel" | "search";
34
34
  }): React.JSX.Element;
35
35
  declare namespace TextInput {
@@ -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
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { I as InputProps } from './types-WxAFrgDW.js';
2
+ import { I as InputProps } from './types-BBif0kuP.js';
3
3
 
4
4
  /**
5
5
  * TextInput - High-performance text input component
@@ -29,7 +29,7 @@ import { I as InputProps } from './types-WxAFrgDW.js';
29
29
  *
30
30
  * @see https://opensite.ai/developers/page-speed/forms/text-input
31
31
  */
32
- declare function TextInput({ name, value, onChange, onBlur, placeholder, disabled, required, error, className, type, ...props }: InputProps<string> & {
32
+ declare function TextInput({ name, value, onChange, onBlur, placeholder, disabled, required, error, className, type, id, ...props }: InputProps<string> & {
33
33
  type?: "text" | "email" | "password" | "url" | "tel" | "search";
34
34
  }): React.JSX.Element;
35
35
  declare namespace TextInput {
@@ -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
@@ -12,6 +12,7 @@ function TextInput({
12
12
  error = false,
13
13
  className = "",
14
14
  type = "text",
15
+ id = "text",
15
16
  ...props
16
17
  }) {
17
18
  const handleChange = (e) => {
@@ -27,6 +28,7 @@ function TextInput({
27
28
  "input",
28
29
  {
29
30
  type,
31
+ id,
30
32
  name,
31
33
  value: value ?? "",
32
34
  onChange: handleChange,
@@ -104,9 +106,11 @@ function Checkbox({
104
106
  className = "",
105
107
  indeterminate = false,
106
108
  label,
109
+ description,
107
110
  ...props
108
111
  }) {
109
112
  const inputRef = React7.useRef(null);
113
+ const checkboxId = props.id || `checkbox-${name}`;
110
114
  React7.useEffect(() => {
111
115
  if (inputRef.current) {
112
116
  inputRef.current.indeterminate = indeterminate;
@@ -120,27 +124,37 @@ function Checkbox({
120
124
  };
121
125
  const baseClassName = "checkbox";
122
126
  const errorClassName = error ? "checkbox--error" : "";
123
- const combinedClassName = `${baseClassName} ${errorClassName} ${className}`.trim();
127
+ const checkedClassName = value ? "checkbox--checked" : "";
128
+ const disabledClassName = disabled ? "checkbox--disabled" : "";
129
+ const combinedClassName = `${baseClassName} ${errorClassName} ${checkedClassName} ${disabledClassName} ${className}`.trim();
124
130
  const checkbox = /* @__PURE__ */ React7.createElement(
125
131
  "input",
126
132
  {
127
133
  ref: inputRef,
128
134
  type: "checkbox",
135
+ id: checkboxId,
129
136
  name,
130
137
  checked: value,
131
138
  onChange: handleChange,
132
139
  onBlur: handleBlur,
133
140
  disabled,
134
141
  required,
135
- className: combinedClassName,
142
+ className: "checkbox-input",
136
143
  "aria-invalid": error || props["aria-invalid"],
137
- "aria-describedby": props["aria-describedby"],
144
+ "aria-describedby": description ? `${checkboxId}-description` : props["aria-describedby"],
138
145
  "aria-required": required || props["aria-required"],
139
146
  ...props
140
147
  }
141
148
  );
142
149
  if (label) {
143
- return /* @__PURE__ */ React7.createElement("label", { className: "checkbox-label" }, checkbox, /* @__PURE__ */ React7.createElement("span", { className: "checkbox-label-text" }, label));
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
+ ))));
144
158
  }
145
159
  return checkbox;
146
160
  }
@@ -336,10 +350,19 @@ function Radio({
336
350
  "label",
337
351
  {
338
352
  key: option.value,
339
- className: `radio-option ${isDisabled ? "radio-option--disabled" : ""}`,
340
- 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
341
357
  },
342
- /* @__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(
343
366
  "input",
344
367
  {
345
368
  type: "radio",
@@ -349,20 +372,11 @@ function Radio({
349
372
  checked: isChecked,
350
373
  onChange: (e) => handleChange(e.target.value),
351
374
  onBlur: handleBlur,
352
- onKeyDown: (e) => handleKeyDown(e, index),
353
375
  disabled: isDisabled,
354
376
  required,
355
377
  className: "radio-input",
356
378
  "aria-describedby": option.description ? `${radioId}-description` : props["aria-describedby"]
357
379
  }
358
- ),
359
- /* @__PURE__ */ React7.createElement("div", { className: "radio-content" }, /* @__PURE__ */ React7.createElement("span", { className: "radio-label" }, option.label), option.description && /* @__PURE__ */ React7.createElement(
360
- "span",
361
- {
362
- className: "radio-description",
363
- id: `${radioId}-description`
364
- },
365
- option.description
366
380
  ))
367
381
  );
368
382
  }))