@coopdigital/react 0.35.0 → 0.36.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.
@@ -23,10 +23,8 @@ export interface CheckboxProps extends Omit<InputHTMLAttributes<HTMLInputElement
23
23
  labelVisible?: boolean;
24
24
  /** Specify the Checkbox name. */
25
25
  name: string;
26
- /** **(Optional)** Specify the Checkbox placeholder text. Do not use in place of a form label. */
27
- placeholder?: string;
28
26
  /** **(Optional)** Specify the Checkbox size. */
29
27
  size?: StandardSizes;
30
28
  }
31
- export declare const Checkbox: ({ "aria-placeholder": ariaPlaceholder, className, error, hint, id, label, labelVisible, name, placeholder, size, ...props }: CheckboxProps) => JSX.Element;
29
+ export declare const Checkbox: ({ className, error, hint, id, label, labelVisible, name, size, ...props }: CheckboxProps) => JSX.Element;
32
30
  export default Checkbox;
@@ -5,18 +5,15 @@ import { FieldError } from '../FieldError/FieldError.js';
5
5
  import { FieldHint } from '../FieldHint/FieldHint.js';
6
6
  import { FieldLabel } from '../FieldLabel/FieldLabel.js';
7
7
 
8
- const Checkbox = ({ "aria-placeholder": ariaPlaceholder, className, error = false, hint, id, label, labelVisible = true, name, placeholder, size = "md", ...props }) => {
9
- var _a;
8
+ const Checkbox = ({ className, error = false, hint, id, label, labelVisible = true, name, size = "md", ...props }) => {
10
9
  const internalId = useId();
11
10
  id = id !== null && id !== void 0 ? id : internalId;
12
11
  const componentProps = {
13
- "aria-placeholder": (_a = placeholder !== null && placeholder !== void 0 ? placeholder : ariaPlaceholder) !== null && _a !== void 0 ? _a : undefined,
14
12
  className: clsx("coop-checkbox", className),
15
13
  "data-error": error ? "" : undefined,
16
14
  "data-size": size.length && size !== "md" ? size : undefined,
17
15
  id,
18
16
  name,
19
- placeholder,
20
17
  type: "checkbox",
21
18
  ...props,
22
19
  };
@@ -1,4 +1,5 @@
1
1
  import Checkbox from "./Checkbox";
2
+ import CheckboxGroup from "./CheckboxGroup";
2
3
  export default Checkbox;
3
- export { Checkbox };
4
+ export { Checkbox, CheckboxGroup };
4
5
  export * from "./Checkbox";
@@ -0,0 +1,30 @@
1
+ import { type InputHTMLAttributes, type JSX } from "react";
2
+ import { FormFieldError, StandardSizes } from "src/types";
3
+ export interface RadioButtonProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "type"> {
4
+ /** **(Optional)** Specify additional CSS classes to be applied to the component. */
5
+ className?: string;
6
+ /** **(Optional)** Specify the RadioButton error state.
7
+ *
8
+ * This is an instance of `FormFieldError`. You can provide either an object with a `message` key, or a boolean value if you need to render the message independently.
9
+ */
10
+ error?: FormFieldError;
11
+ /** **(Optional)** Specify the RadioButton hint.
12
+ *
13
+ * This text is rendered under the label to provide further guidance for users.
14
+ */
15
+ hint?: string;
16
+ /** **(Optional)** Specify the RadioButton id. Will be auto-generated if not set. */
17
+ id?: string;
18
+ /** **(Optional)** Specify the RadioButton label.
19
+ *
20
+ * This property is optional in case you need to render your own label, but all form elements *must* provide a label. */
21
+ label: string;
22
+ /** **(Optional)** Specify whether the label should be visible to humans or screen readers. */
23
+ labelVisible?: boolean;
24
+ /** Specify the RadioButton name. */
25
+ name: string;
26
+ /** **(Optional)** Specify the RadioButton size. */
27
+ size?: StandardSizes;
28
+ }
29
+ export declare const RadioButton: ({ className, error, hint, id, label, labelVisible, name, size, ...props }: RadioButtonProps) => JSX.Element;
30
+ export default RadioButton;
@@ -0,0 +1,23 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { clsx } from '../../node_modules/clsx/dist/clsx.js';
3
+ import { useId } from 'react';
4
+ import { FieldError } from '../FieldError/FieldError.js';
5
+ import { FieldHint } from '../FieldHint/FieldHint.js';
6
+ import { FieldLabel } from '../FieldLabel/FieldLabel.js';
7
+
8
+ const RadioButton = ({ className, error = false, hint, id, label, labelVisible = true, name, size = "md", ...props }) => {
9
+ const internalId = useId();
10
+ id = id !== null && id !== void 0 ? id : internalId;
11
+ const componentProps = {
12
+ className: clsx("coop-radio-button", className),
13
+ "data-error": error ? "" : undefined,
14
+ "data-size": size.length && size !== "md" ? size : undefined,
15
+ id,
16
+ name,
17
+ type: "radio",
18
+ ...props,
19
+ };
20
+ return (jsxs("div", { className: "coop-form-item", children: [jsxs("div", { className: "coop-radio-button-wrapper", children: [jsx("input", { ...componentProps }), label && (jsx(FieldLabel, { htmlFor: id, isVisible: labelVisible, children: label })), hint && jsx(FieldHint, { children: hint })] }), typeof error === "object" && (error === null || error === void 0 ? void 0 : error.message) && jsx(FieldError, { children: error.message })] }));
21
+ };
22
+
23
+ export { RadioButton, RadioButton as default };
@@ -0,0 +1,26 @@
1
+ import type { FieldsetHTMLAttributes, JSX } from "react";
2
+ import { FormFieldError, StandardSizes } from "../../types";
3
+ export interface RadioButtonGroupProps extends FieldsetHTMLAttributes<HTMLFieldSetElement> {
4
+ /** **(Optional)** Main content inside the component. It can be any valid JSX or string. */
5
+ children?: React.ReactNode;
6
+ /** **(Optional)** Specify additional CSS classes to be applied to the component. */
7
+ className?: string;
8
+ /** **(Optional)** Specify the RadioButtonGroup error state.
9
+ *
10
+ * This is an instance of `FormFieldError`. You can provide either an object with a `message` key, or a boolean value if you need to render the message independently.
11
+ */
12
+ error?: FormFieldError;
13
+ /** **(Optional)** Specify the RadioButtonGroup hint.
14
+ *
15
+ * This text is rendered under the label to provide further guidance for users.
16
+ */
17
+ hint?: string;
18
+ /** **(Optional)** Specify the label for the RadioButtonGroup. This will be rendered as a fieldset legend. */
19
+ label?: string;
20
+ /** **(Optional)** Specify whether the label should be visible to humans or screen readers. */
21
+ labelVisible?: boolean;
22
+ /** **(Optional)** Specify the RadioButtonGroup size. */
23
+ size?: StandardSizes;
24
+ }
25
+ export declare const RadioButtonGroup: ({ children, className, error, hint, label, labelVisible, size, ...props }: RadioButtonGroupProps) => JSX.Element;
26
+ export default RadioButtonGroup;
@@ -0,0 +1,19 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { clsx } from '../../node_modules/clsx/dist/clsx.js';
3
+ import { FieldError } from '../FieldError/FieldError.js';
4
+ import { FieldHint } from '../FieldHint/FieldHint.js';
5
+
6
+ const RadioButtonGroup = ({ children, className, error = false, hint, label, labelVisible = true, size = "md", ...props }) => {
7
+ const componentProps = {
8
+ className: clsx("coop-fieldset", "coop-radio-button-group", className),
9
+ "data-error": error ? "" : undefined,
10
+ "data-size": size.length && size !== "md" ? size : undefined,
11
+ ...props,
12
+ };
13
+ const legendProps = {
14
+ className: clsx("coop-field-label", !labelVisible && "sr-only"),
15
+ };
16
+ return (jsxs("fieldset", { ...componentProps, children: [label && jsx("legend", { ...legendProps, children: label }), hint && jsx(FieldHint, { children: hint }), typeof error === "object" && (error === null || error === void 0 ? void 0 : error.message) && jsx(FieldError, { children: error.message }), children] }));
17
+ };
18
+
19
+ export { RadioButtonGroup, RadioButtonGroup as default };
@@ -0,0 +1,5 @@
1
+ import RadioButton from "./RadioButton";
2
+ import RadioButtonGroup from "./RadioButtonGroup";
3
+ export default RadioButton;
4
+ export { RadioButton, RadioButtonGroup };
5
+ export * from "./RadioButton";
package/dist/index.d.ts CHANGED
@@ -3,7 +3,6 @@ export * from "./components/Author";
3
3
  export * from "./components/Button";
4
4
  export * from "./components/Card";
5
5
  export * from "./components/Checkbox";
6
- export * from "./components/Checkbox/CheckboxGroup";
7
6
  export * from "./components/Expandable";
8
7
  export * from "./components/Field";
9
8
  export * from "./components/FieldError";
@@ -12,6 +11,7 @@ export * from "./components/FieldLabel";
12
11
  export * from "./components/Flourish";
13
12
  export * from "./components/Image";
14
13
  export * from "./components/Pill";
14
+ export * from "./components/RadioButton";
15
15
  export * from "./components/RootSVG";
16
16
  export * from "./components/SearchBox";
17
17
  export * from "./components/Signpost";
package/dist/index.js CHANGED
@@ -12,6 +12,8 @@ export { FieldLabel } from './components/FieldLabel/FieldLabel.js';
12
12
  export { Flourish } from './components/Flourish/Flourish.js';
13
13
  export { Image } from './components/Image/Image.js';
14
14
  export { Pill } from './components/Pill/Pill.js';
15
+ export { RadioButton } from './components/RadioButton/RadioButton.js';
16
+ export { RadioButtonGroup } from './components/RadioButton/RadioButtonGroup.js';
15
17
  export { RootSVG } from './components/RootSVG/RootSVG.js';
16
18
  export { SearchBox } from './components/SearchBox/SearchBox.js';
17
19
  export { Signpost } from './components/Signpost/Signpost.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coopdigital/react",
3
3
  "type": "module",
4
- "version": "0.35.0",
4
+ "version": "0.36.0",
5
5
  "private": false,
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -80,7 +80,7 @@
80
80
  "storybook": "$storybook"
81
81
  },
82
82
  "dependencies": {
83
- "@coopdigital/styles": "^0.31.0"
83
+ "@coopdigital/styles": "^0.31.1"
84
84
  },
85
- "gitHead": "eedf8c0062e77a007636c54ec5776aa6cc670cee"
85
+ "gitHead": "a88bc2694b91f0c180f02d39786a1323e6632254"
86
86
  }
@@ -32,14 +32,11 @@ export interface CheckboxProps
32
32
  labelVisible?: boolean
33
33
  /** Specify the Checkbox name. */
34
34
  name: string
35
- /** **(Optional)** Specify the Checkbox placeholder text. Do not use in place of a form label. */
36
- placeholder?: string
37
35
  /** **(Optional)** Specify the Checkbox size. */
38
36
  size?: StandardSizes
39
37
  }
40
38
 
41
39
  export const Checkbox = ({
42
- "aria-placeholder": ariaPlaceholder,
43
40
  className,
44
41
  error = false,
45
42
  hint,
@@ -47,7 +44,6 @@ export const Checkbox = ({
47
44
  label,
48
45
  labelVisible = true,
49
46
  name,
50
- placeholder,
51
47
  size = "md",
52
48
  ...props
53
49
  }: CheckboxProps): JSX.Element => {
@@ -56,13 +52,11 @@ export const Checkbox = ({
56
52
  id = id ?? internalId
57
53
 
58
54
  const componentProps = {
59
- "aria-placeholder": placeholder ?? ariaPlaceholder ?? undefined,
60
55
  className: clsx("coop-checkbox", className),
61
56
  "data-error": error ? "" : undefined,
62
57
  "data-size": size.length && size !== "md" ? size : undefined,
63
58
  id,
64
59
  name,
65
- placeholder,
66
60
  type: "checkbox",
67
61
  ...props,
68
62
  }
@@ -1,5 +1,6 @@
1
1
  import Checkbox from "./Checkbox"
2
+ import CheckboxGroup from "./CheckboxGroup"
2
3
 
3
4
  export default Checkbox
4
- export { Checkbox }
5
+ export { Checkbox, CheckboxGroup }
5
6
  export * from "./Checkbox"
@@ -0,0 +1,79 @@
1
+ import clsx from "clsx"
2
+ import { type InputHTMLAttributes, type JSX, useId } from "react"
3
+ import { FormFieldError, StandardSizes } from "src/types"
4
+
5
+ import { FieldError } from "../FieldError"
6
+ import { FieldHint } from "../FieldHint"
7
+ import { FieldLabel } from "../FieldLabel"
8
+
9
+ export interface RadioButtonProps
10
+ extends Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "type"> {
11
+ /** **(Optional)** Specify additional CSS classes to be applied to the component. */
12
+ className?: string
13
+ /** **(Optional)** Specify the RadioButton error state.
14
+ *
15
+ * This is an instance of `FormFieldError`. You can provide either an object with a `message` key, or a boolean value if you need to render the message independently.
16
+ */
17
+ error?: FormFieldError
18
+ /** **(Optional)** Specify the RadioButton hint.
19
+ *
20
+ * This text is rendered under the label to provide further guidance for users.
21
+ */
22
+ hint?: string
23
+ /** **(Optional)** Specify the RadioButton id. Will be auto-generated if not set. */
24
+ id?: string
25
+ /** **(Optional)** Specify the RadioButton label.
26
+ *
27
+ * This property is optional in case you need to render your own label, but all form elements *must* provide a label. */
28
+ label: string
29
+ /** **(Optional)** Specify whether the label should be visible to humans or screen readers. */
30
+ labelVisible?: boolean
31
+ /** Specify the RadioButton name. */
32
+ name: string
33
+ /** **(Optional)** Specify the RadioButton size. */
34
+ size?: StandardSizes
35
+ }
36
+
37
+ export const RadioButton = ({
38
+ className,
39
+ error = false,
40
+ hint,
41
+ id,
42
+ label,
43
+ labelVisible = true,
44
+ name,
45
+ size = "md",
46
+ ...props
47
+ }: RadioButtonProps): JSX.Element => {
48
+ const internalId = useId()
49
+
50
+ id = id ?? internalId
51
+
52
+ const componentProps = {
53
+ className: clsx("coop-radio-button", className),
54
+ "data-error": error ? "" : undefined,
55
+ "data-size": size.length && size !== "md" ? size : undefined,
56
+ id,
57
+ name,
58
+ type: "radio",
59
+ ...props,
60
+ }
61
+
62
+ return (
63
+ <div className="coop-form-item">
64
+ <div className="coop-radio-button-wrapper">
65
+ <input {...componentProps} />
66
+
67
+ {label && (
68
+ <FieldLabel htmlFor={id} isVisible={labelVisible}>
69
+ {label}
70
+ </FieldLabel>
71
+ )}
72
+ {hint && <FieldHint>{hint}</FieldHint>}
73
+ </div>
74
+ {typeof error === "object" && error?.message && <FieldError>{error.message}</FieldError>}
75
+ </div>
76
+ )
77
+ }
78
+
79
+ export default RadioButton
@@ -0,0 +1,63 @@
1
+ import type { FieldsetHTMLAttributes, JSX } from "react"
2
+
3
+ import clsx from "clsx"
4
+
5
+ import { FormFieldError, StandardSizes } from "../../types"
6
+ import { FieldError } from "../FieldError"
7
+ import { FieldHint } from "../FieldHint"
8
+
9
+ export interface RadioButtonGroupProps extends FieldsetHTMLAttributes<HTMLFieldSetElement> {
10
+ /** **(Optional)** Main content inside the component. It can be any valid JSX or string. */
11
+ children?: React.ReactNode
12
+ /** **(Optional)** Specify additional CSS classes to be applied to the component. */
13
+ className?: string
14
+ /** **(Optional)** Specify the RadioButtonGroup error state.
15
+ *
16
+ * This is an instance of `FormFieldError`. You can provide either an object with a `message` key, or a boolean value if you need to render the message independently.
17
+ */
18
+ error?: FormFieldError
19
+ /** **(Optional)** Specify the RadioButtonGroup hint.
20
+ *
21
+ * This text is rendered under the label to provide further guidance for users.
22
+ */
23
+ hint?: string
24
+ /** **(Optional)** Specify the label for the RadioButtonGroup. This will be rendered as a fieldset legend. */
25
+ label?: string
26
+ /** **(Optional)** Specify whether the label should be visible to humans or screen readers. */
27
+ labelVisible?: boolean
28
+ /** **(Optional)** Specify the RadioButtonGroup size. */
29
+ size?: StandardSizes
30
+ }
31
+
32
+ export const RadioButtonGroup = ({
33
+ children,
34
+ className,
35
+ error = false,
36
+ hint,
37
+ label,
38
+ labelVisible = true,
39
+ size = "md",
40
+ ...props
41
+ }: RadioButtonGroupProps): JSX.Element => {
42
+ const componentProps = {
43
+ className: clsx("coop-fieldset", "coop-radio-button-group", className),
44
+ "data-error": error ? "" : undefined,
45
+ "data-size": size.length && size !== "md" ? size : undefined,
46
+ ...props,
47
+ }
48
+
49
+ const legendProps = {
50
+ className: clsx("coop-field-label", !labelVisible && "sr-only"),
51
+ }
52
+
53
+ return (
54
+ <fieldset {...componentProps}>
55
+ {label && <legend {...legendProps}>{label}</legend>}
56
+ {hint && <FieldHint>{hint}</FieldHint>}
57
+ {typeof error === "object" && error?.message && <FieldError>{error.message}</FieldError>}
58
+ {children}
59
+ </fieldset>
60
+ )
61
+ }
62
+
63
+ export default RadioButtonGroup
@@ -0,0 +1,6 @@
1
+ import RadioButton from "./RadioButton"
2
+ import RadioButtonGroup from "./RadioButtonGroup"
3
+
4
+ export default RadioButton
5
+ export { RadioButton, RadioButtonGroup }
6
+ export * from "./RadioButton"
package/src/index.ts CHANGED
@@ -3,7 +3,6 @@ export * from "./components/Author"
3
3
  export * from "./components/Button"
4
4
  export * from "./components/Card"
5
5
  export * from "./components/Checkbox"
6
- export * from "./components/Checkbox/CheckboxGroup"
7
6
  export * from "./components/Expandable"
8
7
  export * from "./components/Field"
9
8
  export * from "./components/FieldError"
@@ -12,6 +11,7 @@ export * from "./components/FieldLabel"
12
11
  export * from "./components/Flourish"
13
12
  export * from "./components/Image"
14
13
  export * from "./components/Pill"
14
+ export * from "./components/RadioButton"
15
15
  export * from "./components/RootSVG"
16
16
  export * from "./components/SearchBox"
17
17
  export * from "./components/Signpost"