@coopdigital/react 0.36.0 → 0.37.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.
@@ -31,8 +31,8 @@ export interface CardProps extends HTMLAttributes<HTMLDivElement> {
31
31
  label?: string;
32
32
  /** **(Optional)** Specify the background color of the Card label. */
33
33
  labelBackground?: Lights;
34
- /** **(Optional)** Specify the layout of the Card. */
35
- layout?: "vertical" | "horizontal";
34
+ /** **(Optional)** Specify the orientation of the Card. */
35
+ orientation?: "vertical" | "horizontal";
36
36
  }
37
- export declare const Card: ({ as, background, badge, badgePosition, chevron, children, className, heading, headingLevel, href, image, imagePosition, label, labelBackground, layout, ...props }: CardProps) => JSX.Element;
37
+ export declare const Card: ({ as, background, badge, badgePosition, chevron, children, className, heading, headingLevel, href, image, imagePosition, label, labelBackground, orientation, ...props }: CardProps) => JSX.Element;
38
38
  export default Card;
@@ -18,7 +18,7 @@ function getCardLinkElement(as, href) {
18
18
  },
19
19
  };
20
20
  }
21
- const Card = ({ as, background = "white", badge, badgePosition = "inset", chevron = false, children, className, heading, headingLevel = "h3", href, image, imagePosition = "left", label = "", labelBackground, layout = "vertical", ...props }) => {
21
+ const Card = ({ as, background = "white", badge, badgePosition = "inset", chevron = false, children, className, heading, headingLevel = "h3", href, image, imagePosition = "left", label = "", labelBackground, orientation = "vertical", ...props }) => {
22
22
  const linkElement = getCardLinkElement(as, href);
23
23
  const imageProps = {
24
24
  crop: "wide",
@@ -28,7 +28,7 @@ const Card = ({ as, background = "white", badge, badgePosition = "inset", chevro
28
28
  className: clsx("coop-card", background && bgPropToClass(background, className), className),
29
29
  "data-badge-pos": badgePosition,
30
30
  "data-image-pos": imagePosition,
31
- "data-layout": layout !== "vertical" ? layout : undefined,
31
+ "data-orientation": orientation !== "vertical" ? orientation : undefined,
32
32
  ...props,
33
33
  };
34
34
  return (jsxs("article", { ...componentProps, children: [image && jsx(Image, { ...imageProps }), badge && jsx("div", { className: "coop-card--badge", children: badge }), jsxs("div", { className: "coop-card--inner", children: [jsxs("div", { className: "coop-card--content", children: [label && (jsx("span", { className: clsx("coop-card--label", labelBackground && bgPropToClass(labelBackground, className)), children: label })), React.createElement(linkElement.element, linkElement.props, React.createElement(headingLevel, { className: "coop-card--heading" }, heading)), children] }), chevron && (jsx("span", { "aria-hidden": "true", className: "coop-card--icon", role: "presentation", children: jsx(ChevronRightIcon, {}) }))] })] }));
@@ -19,8 +19,10 @@ export interface CheckboxGroupProps extends FieldsetHTMLAttributes<HTMLFieldSetE
19
19
  label?: string;
20
20
  /** **(Optional)** Specify whether the label should be visible to humans or screen readers. */
21
21
  labelVisible?: boolean;
22
+ /** **(Optional)** Specify the CheckboxGroup orientation. */
23
+ orientation?: "horizontal" | "vertical";
22
24
  /** **(Optional)** Specify the CheckboxGroup size. */
23
25
  size?: StandardSizes;
24
26
  }
25
- export declare const CheckboxGroup: ({ children, className, error, hint, label, labelVisible, size, ...props }: CheckboxGroupProps) => JSX.Element;
27
+ export declare const CheckboxGroup: ({ children, className, error, hint, label, labelVisible, orientation, size, ...props }: CheckboxGroupProps) => JSX.Element;
26
28
  export default CheckboxGroup;
@@ -3,17 +3,18 @@ import { clsx } from '../../node_modules/clsx/dist/clsx.js';
3
3
  import { FieldError } from '../FieldError/FieldError.js';
4
4
  import { FieldHint } from '../FieldHint/FieldHint.js';
5
5
 
6
- const CheckboxGroup = ({ children, className, error = false, hint, label, labelVisible = true, size = "md", ...props }) => {
6
+ const CheckboxGroup = ({ children, className, error = false, hint, label, labelVisible = true, orientation = "vertical", size = "md", ...props }) => {
7
7
  const componentProps = {
8
8
  className: clsx("coop-fieldset", "coop-checkbox-group", className),
9
9
  "data-error": error ? "" : undefined,
10
+ "data-orientation": orientation !== "vertical" ? orientation : undefined,
10
11
  "data-size": size.length && size !== "md" ? size : undefined,
11
12
  ...props,
12
13
  };
13
14
  const legendProps = {
14
15
  className: clsx("coop-field-label", !labelVisible && "sr-only"),
15
16
  };
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
+ 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 }), jsx("div", { className: "coop-checkbox-group-options", children: children })] }));
17
18
  };
18
19
 
19
20
  export { CheckboxGroup, CheckboxGroup as default };
@@ -1,5 +1,6 @@
1
1
  import { type InputHTMLAttributes, type JSX } from "react";
2
2
  import { FormFieldError, StandardSizes } from "src/types";
3
+ import { TagProps } from "../Tag";
3
4
  export interface RadioButtonProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "type"> {
4
5
  /** **(Optional)** Specify additional CSS classes to be applied to the component. */
5
6
  className?: string;
@@ -25,6 +26,12 @@ export interface RadioButtonProps extends Omit<InputHTMLAttributes<HTMLInputElem
25
26
  name: string;
26
27
  /** **(Optional)** Specify the RadioButton size. */
27
28
  size?: StandardSizes;
29
+ /** **(Optional)** Specify the RadioButton tag text. */
30
+ tag?: string;
31
+ /** **(Optional)** Specify the RadioButton tag background color. */
32
+ tagBackground?: TagProps["background"];
33
+ /** **(Optional)** Specify the RadioButton variant. */
34
+ variant?: "default" | "boxed";
28
35
  }
29
- export declare const RadioButton: ({ className, error, hint, id, label, labelVisible, name, size, ...props }: RadioButtonProps) => JSX.Element;
36
+ export declare const RadioButton: ({ className, error, hint, id, label, labelVisible, name, size, tag, tagBackground, variant, ...props }: RadioButtonProps) => JSX.Element;
30
37
  export default RadioButton;
@@ -4,20 +4,22 @@ import { useId } from 'react';
4
4
  import { FieldError } from '../FieldError/FieldError.js';
5
5
  import { FieldHint } from '../FieldHint/FieldHint.js';
6
6
  import { FieldLabel } from '../FieldLabel/FieldLabel.js';
7
+ import { Tag } from '../Tag/Tag.js';
7
8
 
8
- const RadioButton = ({ className, error = false, hint, id, label, labelVisible = true, name, size = "md", ...props }) => {
9
+ const RadioButton = ({ className, error = false, hint, id, label, labelVisible = true, name, size = "md", tag, tagBackground, variant = "default", ...props }) => {
9
10
  const internalId = useId();
10
11
  id = id !== null && id !== void 0 ? id : internalId;
11
12
  const componentProps = {
12
13
  className: clsx("coop-radio-button", className),
13
14
  "data-error": error ? "" : undefined,
14
15
  "data-size": size.length && size !== "md" ? size : undefined,
16
+ "data-variant": variant !== "default" ? variant : undefined,
15
17
  id,
16
18
  name,
17
19
  type: "radio",
18
20
  ...props,
19
21
  };
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 })] }));
22
+ return (jsxs("div", { className: "coop-form-item", children: [jsxs("div", { className: "coop-radio-button-wrapper", children: [jsx("input", { ...componentProps }), label && (jsxs(FieldLabel, { htmlFor: id, isVisible: labelVisible, children: [jsx("span", { children: label }), " ", tag && (jsx(Tag, { background: tagBackground, size: "sm", children: tag }))] })), hint && jsx(FieldHint, { children: hint })] }), typeof error === "object" && (error === null || error === void 0 ? void 0 : error.message) && jsx(FieldError, { children: error.message })] }));
21
23
  };
22
24
 
23
25
  export { RadioButton, RadioButton as default };
@@ -19,8 +19,12 @@ export interface RadioButtonGroupProps extends FieldsetHTMLAttributes<HTMLFieldS
19
19
  label?: string;
20
20
  /** **(Optional)** Specify whether the label should be visible to humans or screen readers. */
21
21
  labelVisible?: boolean;
22
+ /** **(Optional)** Specify the RadioButtonGroup orientation. */
23
+ orientation?: "horizontal" | "vertical";
22
24
  /** **(Optional)** Specify the RadioButtonGroup size. */
23
25
  size?: StandardSizes;
26
+ /** **(Optional)** Specify the RadioButtonGroup variant. */
27
+ variant?: "default" | "boxed";
24
28
  }
25
- export declare const RadioButtonGroup: ({ children, className, error, hint, label, labelVisible, size, ...props }: RadioButtonGroupProps) => JSX.Element;
29
+ export declare const RadioButtonGroup: ({ children, className, error, hint, label, labelVisible, orientation, size, variant, ...props }: RadioButtonGroupProps) => JSX.Element;
26
30
  export default RadioButtonGroup;
@@ -3,17 +3,19 @@ import { clsx } from '../../node_modules/clsx/dist/clsx.js';
3
3
  import { FieldError } from '../FieldError/FieldError.js';
4
4
  import { FieldHint } from '../FieldHint/FieldHint.js';
5
5
 
6
- const RadioButtonGroup = ({ children, className, error = false, hint, label, labelVisible = true, size = "md", ...props }) => {
6
+ const RadioButtonGroup = ({ children, className, error = false, hint, label, labelVisible = true, orientation = "vertical", size = "md", variant = "default", ...props }) => {
7
7
  const componentProps = {
8
8
  className: clsx("coop-fieldset", "coop-radio-button-group", className),
9
9
  "data-error": error ? "" : undefined,
10
+ "data-orientation": orientation !== "vertical" ? orientation : undefined,
10
11
  "data-size": size.length && size !== "md" ? size : undefined,
12
+ "data-variant": variant !== "default" ? variant : undefined,
11
13
  ...props,
12
14
  };
13
15
  const legendProps = {
14
16
  className: clsx("coop-field-label", !labelVisible && "sr-only"),
15
17
  };
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] }));
18
+ 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 }), jsx("div", { className: "coop-radio-button-group-options", children: children })] }));
17
19
  };
18
20
 
19
21
  export { RadioButtonGroup, RadioButtonGroup as default };
@@ -12,6 +12,8 @@ export interface TagProps extends HTMLAttributes<HTMLAnchorElement> {
12
12
  className?: string;
13
13
  /** **(Optional)** Specify the URL that the Tag component will link to when clicked. */
14
14
  href?: string;
15
+ /** **(Optional)** Specify the Tag size. */
16
+ size?: "sm" | "md";
15
17
  }
16
- export declare const Tag: ({ as, background, children, className, href, ...props }: TagProps) => JSX.Element;
18
+ export declare const Tag: ({ as, background, children, className, href, size, ...props }: TagProps) => JSX.Element;
17
19
  export default Tag;
@@ -2,10 +2,11 @@ import { clsx } from '../../node_modules/clsx/dist/clsx.js';
2
2
  import React from 'react';
3
3
  import { bgPropToClass } from '../../utils/index.js';
4
4
 
5
- const Tag = ({ as, background = "tint-grey", children, className, href, ...props }) => {
5
+ const Tag = ({ as, background = "tint-grey", children, className, href, size = "md", ...props }) => {
6
6
  let element = href ? "a" : "span";
7
7
  const componentProps = {
8
8
  className: clsx("coop-tag", bgPropToClass(background, className), className),
9
+ "data-size": size.length && size !== "md" ? size : undefined,
9
10
  href,
10
11
  ...props,
11
12
  };
@@ -0,0 +1,5 @@
1
+ import { Tag } from './Tag.js';
2
+
3
+
4
+
5
+ export { Tag, Tag as default };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coopdigital/react",
3
3
  "type": "module",
4
- "version": "0.36.0",
4
+ "version": "0.37.0",
5
5
  "private": false,
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -56,11 +56,11 @@
56
56
  "description": "",
57
57
  "devDependencies": {
58
58
  "@axe-core/playwright": "^4.10.2",
59
- "@playwright/test": "^1.55.0",
60
- "@storybook/addon-a11y": "^9.1.5",
61
- "@storybook/addon-docs": "^9.1.5",
62
- "@storybook/addon-onboarding": "^9.1.5",
63
- "@storybook/react-vite": "^9.1.5",
59
+ "@playwright/test": "^1.55.1",
60
+ "@storybook/addon-a11y": "^9.1.8",
61
+ "@storybook/addon-docs": "^9.1.8",
62
+ "@storybook/addon-onboarding": "^9.1.8",
63
+ "@storybook/react-vite": "^9.1.8",
64
64
  "@testing-library/jest-dom": "^6.8.0",
65
65
  "@testing-library/react": "^16.3.0",
66
66
  "@types/react": "^19.1.13",
@@ -69,7 +69,7 @@
69
69
  "react": "^19.1.1",
70
70
  "react-dom": "^19.1.1",
71
71
  "serve": "^14.2.5",
72
- "storybook": "^9.1.5"
72
+ "storybook": "^9.1.8"
73
73
  },
74
74
  "peerDependencies": {
75
75
  "clsx": "^2.1.1",
@@ -80,7 +80,7 @@
80
80
  "storybook": "$storybook"
81
81
  },
82
82
  "dependencies": {
83
- "@coopdigital/styles": "^0.31.1"
83
+ "@coopdigital/styles": "^0.32.0"
84
84
  },
85
- "gitHead": "a88bc2694b91f0c180f02d39786a1323e6632254"
85
+ "gitHead": "07c3e26f63d0b276cd48f392ec61241f7db7fe84"
86
86
  }
@@ -39,8 +39,8 @@ export interface CardProps extends HTMLAttributes<HTMLDivElement> {
39
39
  label?: string
40
40
  /** **(Optional)** Specify the background color of the Card label. */
41
41
  labelBackground?: Lights
42
- /** **(Optional)** Specify the layout of the Card. */
43
- layout?: "vertical" | "horizontal"
42
+ /** **(Optional)** Specify the orientation of the Card. */
43
+ orientation?: "vertical" | "horizontal"
44
44
  }
45
45
 
46
46
  function getCardLinkElement(as: CardProps["as"], href?: string) {
@@ -74,7 +74,7 @@ export const Card = ({
74
74
  imagePosition = "left",
75
75
  label = "",
76
76
  labelBackground,
77
- layout = "vertical",
77
+ orientation = "vertical",
78
78
  ...props
79
79
  }: CardProps): JSX.Element => {
80
80
  const linkElement = getCardLinkElement(as, href)
@@ -88,7 +88,7 @@ export const Card = ({
88
88
  className: clsx("coop-card", background && bgPropToClass(background, className), className),
89
89
  "data-badge-pos": badgePosition,
90
90
  "data-image-pos": imagePosition,
91
- "data-layout": layout !== "vertical" ? layout : undefined,
91
+ "data-orientation": orientation !== "vertical" ? orientation : undefined,
92
92
  ...props,
93
93
  }
94
94
 
@@ -25,6 +25,8 @@ export interface CheckboxGroupProps extends FieldsetHTMLAttributes<HTMLFieldSetE
25
25
  label?: string
26
26
  /** **(Optional)** Specify whether the label should be visible to humans or screen readers. */
27
27
  labelVisible?: boolean
28
+ /** **(Optional)** Specify the CheckboxGroup orientation. */
29
+ orientation?: "horizontal" | "vertical"
28
30
  /** **(Optional)** Specify the CheckboxGroup size. */
29
31
  size?: StandardSizes
30
32
  }
@@ -36,12 +38,14 @@ export const CheckboxGroup = ({
36
38
  hint,
37
39
  label,
38
40
  labelVisible = true,
41
+ orientation = "vertical",
39
42
  size = "md",
40
43
  ...props
41
44
  }: CheckboxGroupProps): JSX.Element => {
42
45
  const componentProps = {
43
46
  className: clsx("coop-fieldset", "coop-checkbox-group", className),
44
47
  "data-error": error ? "" : undefined,
48
+ "data-orientation": orientation !== "vertical" ? orientation : undefined,
45
49
  "data-size": size.length && size !== "md" ? size : undefined,
46
50
  ...props,
47
51
  }
@@ -55,7 +59,7 @@ export const CheckboxGroup = ({
55
59
  {label && <legend {...legendProps}>{label}</legend>}
56
60
  {hint && <FieldHint>{hint}</FieldHint>}
57
61
  {typeof error === "object" && error?.message && <FieldError>{error.message}</FieldError>}
58
- {children}
62
+ <div className="coop-checkbox-group-options">{children}</div>
59
63
  </fieldset>
60
64
  )
61
65
  }
@@ -5,6 +5,7 @@ import { FormFieldError, StandardSizes } from "src/types"
5
5
  import { FieldError } from "../FieldError"
6
6
  import { FieldHint } from "../FieldHint"
7
7
  import { FieldLabel } from "../FieldLabel"
8
+ import Tag, { TagProps } from "../Tag"
8
9
 
9
10
  export interface RadioButtonProps
10
11
  extends Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "type"> {
@@ -32,6 +33,12 @@ export interface RadioButtonProps
32
33
  name: string
33
34
  /** **(Optional)** Specify the RadioButton size. */
34
35
  size?: StandardSizes
36
+ /** **(Optional)** Specify the RadioButton tag text. */
37
+ tag?: string
38
+ /** **(Optional)** Specify the RadioButton tag background color. */
39
+ tagBackground?: TagProps["background"]
40
+ /** **(Optional)** Specify the RadioButton variant. */
41
+ variant?: "default" | "boxed"
35
42
  }
36
43
 
37
44
  export const RadioButton = ({
@@ -43,6 +50,9 @@ export const RadioButton = ({
43
50
  labelVisible = true,
44
51
  name,
45
52
  size = "md",
53
+ tag,
54
+ tagBackground,
55
+ variant = "default",
46
56
  ...props
47
57
  }: RadioButtonProps): JSX.Element => {
48
58
  const internalId = useId()
@@ -53,6 +63,7 @@ export const RadioButton = ({
53
63
  className: clsx("coop-radio-button", className),
54
64
  "data-error": error ? "" : undefined,
55
65
  "data-size": size.length && size !== "md" ? size : undefined,
66
+ "data-variant": variant !== "default" ? variant : undefined,
56
67
  id,
57
68
  name,
58
69
  type: "radio",
@@ -66,7 +77,12 @@ export const RadioButton = ({
66
77
 
67
78
  {label && (
68
79
  <FieldLabel htmlFor={id} isVisible={labelVisible}>
69
- {label}
80
+ <span>{label}</span>{" "}
81
+ {tag && (
82
+ <Tag background={tagBackground} size="sm">
83
+ {tag}
84
+ </Tag>
85
+ )}
70
86
  </FieldLabel>
71
87
  )}
72
88
  {hint && <FieldHint>{hint}</FieldHint>}
@@ -25,8 +25,12 @@ export interface RadioButtonGroupProps extends FieldsetHTMLAttributes<HTMLFieldS
25
25
  label?: string
26
26
  /** **(Optional)** Specify whether the label should be visible to humans or screen readers. */
27
27
  labelVisible?: boolean
28
+ /** **(Optional)** Specify the RadioButtonGroup orientation. */
29
+ orientation?: "horizontal" | "vertical"
28
30
  /** **(Optional)** Specify the RadioButtonGroup size. */
29
31
  size?: StandardSizes
32
+ /** **(Optional)** Specify the RadioButtonGroup variant. */
33
+ variant?: "default" | "boxed"
30
34
  }
31
35
 
32
36
  export const RadioButtonGroup = ({
@@ -36,13 +40,17 @@ export const RadioButtonGroup = ({
36
40
  hint,
37
41
  label,
38
42
  labelVisible = true,
43
+ orientation = "vertical",
39
44
  size = "md",
45
+ variant = "default",
40
46
  ...props
41
47
  }: RadioButtonGroupProps): JSX.Element => {
42
48
  const componentProps = {
43
49
  className: clsx("coop-fieldset", "coop-radio-button-group", className),
44
50
  "data-error": error ? "" : undefined,
51
+ "data-orientation": orientation !== "vertical" ? orientation : undefined,
45
52
  "data-size": size.length && size !== "md" ? size : undefined,
53
+ "data-variant": variant !== "default" ? variant : undefined,
46
54
  ...props,
47
55
  }
48
56
 
@@ -55,7 +63,7 @@ export const RadioButtonGroup = ({
55
63
  {label && <legend {...legendProps}>{label}</legend>}
56
64
  {hint && <FieldHint>{hint}</FieldHint>}
57
65
  {typeof error === "object" && error?.message && <FieldError>{error.message}</FieldError>}
58
- {children}
66
+ <div className="coop-radio-button-group-options">{children}</div>
59
67
  </fieldset>
60
68
  )
61
69
  }
@@ -19,6 +19,8 @@ export interface TagProps extends HTMLAttributes<HTMLAnchorElement> {
19
19
  className?: string
20
20
  /** **(Optional)** Specify the URL that the Tag component will link to when clicked. */
21
21
  href?: string
22
+ /** **(Optional)** Specify the Tag size. */
23
+ size?: "sm" | "md"
22
24
  }
23
25
 
24
26
  export const Tag = ({
@@ -27,12 +29,15 @@ export const Tag = ({
27
29
  children,
28
30
  className,
29
31
  href,
32
+ size = "md",
30
33
  ...props
31
34
  }: TagProps): JSX.Element => {
32
35
  let element: TagProps["as"] = href ? "a" : "span"
33
36
  const componentProps = {
34
37
  className: clsx("coop-tag", bgPropToClass(background, className), className),
38
+ "data-size": size.length && size !== "md" ? size : undefined,
35
39
  href,
40
+
36
41
  ...props,
37
42
  }
38
43
  if (as) {