@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 CHANGED
@@ -128,9 +128,11 @@ function Checkbox({
128
128
  className = "",
129
129
  indeterminate = false,
130
130
  label,
131
+ description,
131
132
  ...props
132
133
  }) {
133
134
  const inputRef = React7__namespace.useRef(null);
135
+ const checkboxId = props.id || `checkbox-${name}`;
134
136
  React7__namespace.useEffect(() => {
135
137
  if (inputRef.current) {
136
138
  inputRef.current.indeterminate = indeterminate;
@@ -144,27 +146,37 @@ function Checkbox({
144
146
  };
145
147
  const baseClassName = "checkbox";
146
148
  const errorClassName = error ? "checkbox--error" : "";
147
- const combinedClassName = `${baseClassName} ${errorClassName} ${className}`.trim();
149
+ const checkedClassName = value ? "checkbox--checked" : "";
150
+ const disabledClassName = disabled ? "checkbox--disabled" : "";
151
+ const combinedClassName = `${baseClassName} ${errorClassName} ${checkedClassName} ${disabledClassName} ${className}`.trim();
148
152
  const checkbox = /* @__PURE__ */ React7__namespace.createElement(
149
153
  "input",
150
154
  {
151
155
  ref: inputRef,
152
156
  type: "checkbox",
157
+ id: checkboxId,
153
158
  name,
154
159
  checked: value,
155
160
  onChange: handleChange,
156
161
  onBlur: handleBlur,
157
162
  disabled,
158
163
  required,
159
- className: combinedClassName,
164
+ className: "checkbox-input",
160
165
  "aria-invalid": error || props["aria-invalid"],
161
- "aria-describedby": props["aria-describedby"],
166
+ "aria-describedby": description ? `${checkboxId}-description` : props["aria-describedby"],
162
167
  "aria-required": required || props["aria-required"],
163
168
  ...props
164
169
  }
165
170
  );
166
171
  if (label) {
167
- return /* @__PURE__ */ React7__namespace.createElement("label", { className: "checkbox-label" }, checkbox, /* @__PURE__ */ React7__namespace.createElement("span", { className: "checkbox-label-text" }, label));
172
+ return /* @__PURE__ */ React7__namespace.createElement("label", { className: `checkbox-field ${combinedClassName}`, htmlFor: checkboxId }, /* @__PURE__ */ React7__namespace.createElement("div", { className: "checkbox-field-content" }, checkbox, /* @__PURE__ */ React7__namespace.createElement("div", { className: "checkbox-field-text" }, /* @__PURE__ */ React7__namespace.createElement("span", { className: "checkbox-label" }, label), description && /* @__PURE__ */ React7__namespace.createElement(
173
+ "span",
174
+ {
175
+ className: "checkbox-description",
176
+ id: `${checkboxId}-description`
177
+ },
178
+ description
179
+ ))));
168
180
  }
169
181
  return checkbox;
170
182
  }
@@ -360,10 +372,19 @@ function Radio({
360
372
  "label",
361
373
  {
362
374
  key: option.value,
363
- className: `radio-option ${isDisabled ? "radio-option--disabled" : ""}`,
364
- htmlFor: radioId
375
+ className: `radio-option ${isChecked ? "radio-option--checked" : ""} ${isDisabled ? "radio-option--disabled" : ""}`,
376
+ htmlFor: radioId,
377
+ onKeyDown: (e) => handleKeyDown(e, index),
378
+ tabIndex: 0
365
379
  },
366
- /* @__PURE__ */ React7__namespace.createElement(
380
+ /* @__PURE__ */ React7__namespace.createElement("div", { className: "radio-option-content" }, /* @__PURE__ */ React7__namespace.createElement("div", { className: "radio-option-text" }, /* @__PURE__ */ React7__namespace.createElement("span", { className: "radio-label" }, option.label), option.description && /* @__PURE__ */ React7__namespace.createElement(
381
+ "span",
382
+ {
383
+ className: "radio-description",
384
+ id: `${radioId}-description`
385
+ },
386
+ option.description
387
+ )), /* @__PURE__ */ React7__namespace.createElement(
367
388
  "input",
368
389
  {
369
390
  type: "radio",
@@ -373,20 +394,11 @@ function Radio({
373
394
  checked: isChecked,
374
395
  onChange: (e) => handleChange(e.target.value),
375
396
  onBlur: handleBlur,
376
- onKeyDown: (e) => handleKeyDown(e, index),
377
397
  disabled: isDisabled,
378
398
  required,
379
399
  className: "radio-input",
380
400
  "aria-describedby": option.description ? `${radioId}-description` : props["aria-describedby"]
381
401
  }
382
- ),
383
- /* @__PURE__ */ React7__namespace.createElement("div", { className: "radio-content" }, /* @__PURE__ */ React7__namespace.createElement("span", { className: "radio-label" }, option.label), option.description && /* @__PURE__ */ React7__namespace.createElement(
384
- "span",
385
- {
386
- className: "radio-description",
387
- id: `${radioId}-description`
388
- },
389
- option.description
390
402
  ))
391
403
  );
392
404
  }))