@coopdigital/react 0.45.0 → 0.47.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.
Files changed (207) hide show
  1. package/dist/components/AlertBanner/AlertBanner.d.ts +4 -2
  2. package/dist/components/AlertBanner/AlertBanner.js +2 -2
  3. package/dist/components/Author/Author.d.ts +4 -2
  4. package/dist/components/Author/Author.js +2 -2
  5. package/dist/components/Button/Button.d.ts +6 -4
  6. package/dist/components/Button/Button.js +4 -7
  7. package/dist/components/Card/Card.d.ts +4 -2
  8. package/dist/components/Card/Card.js +4 -4
  9. package/dist/components/Checkbox/Checkbox.d.ts +4 -2
  10. package/dist/components/Checkbox/Checkbox.js +2 -2
  11. package/dist/components/Expandable/Expandable.d.ts +4 -2
  12. package/dist/components/Expandable/Expandable.js +4 -4
  13. package/dist/components/Field/Field.d.ts +4 -2
  14. package/dist/components/Field/Field.js +7 -8
  15. package/dist/components/FieldMarkers/Error.d.ts +4 -2
  16. package/dist/components/FieldMarkers/Error.js +2 -2
  17. package/dist/components/FieldMarkers/Hint.d.ts +5 -3
  18. package/dist/components/FieldMarkers/Hint.js +2 -2
  19. package/dist/components/FieldMarkers/Label.d.ts +4 -2
  20. package/dist/components/FieldMarkers/Label.js +6 -2
  21. package/dist/components/FieldMarkers/Legend.d.ts +4 -2
  22. package/dist/components/FieldMarkers/Legend.js +2 -2
  23. package/dist/components/Fieldset/Fieldset.d.ts +4 -2
  24. package/dist/components/Fieldset/Fieldset.js +2 -4
  25. package/dist/components/Flourish/Flourish.d.ts +4 -2
  26. package/dist/components/Flourish/Flourish.js +2 -2
  27. package/dist/components/Icon/AddIcon.d.ts +1 -1
  28. package/dist/components/Icon/AddIcon.js +6 -5
  29. package/dist/components/Icon/ArrowDownIcon.d.ts +1 -1
  30. package/dist/components/Icon/ArrowDownIcon.js +6 -5
  31. package/dist/components/Icon/ArrowLeftIcon.d.ts +1 -1
  32. package/dist/components/Icon/ArrowLeftIcon.js +6 -5
  33. package/dist/components/Icon/ArrowRightIcon.d.ts +1 -1
  34. package/dist/components/Icon/ArrowRightIcon.js +6 -5
  35. package/dist/components/Icon/ArrowUpIcon.d.ts +1 -1
  36. package/dist/components/Icon/ArrowUpIcon.js +6 -5
  37. package/dist/components/Icon/AvatarAltIcon.d.ts +1 -1
  38. package/dist/components/Icon/AvatarAltIcon.js +6 -5
  39. package/dist/components/Icon/AvatarIcon.d.ts +1 -1
  40. package/dist/components/Icon/AvatarIcon.js +6 -5
  41. package/dist/components/Icon/BasketIcon.d.ts +1 -1
  42. package/dist/components/Icon/BasketIcon.js +6 -5
  43. package/dist/components/Icon/CalendarIcon.d.ts +1 -1
  44. package/dist/components/Icon/CalendarIcon.js +6 -5
  45. package/dist/components/Icon/ChevronDownIcon.d.ts +1 -1
  46. package/dist/components/Icon/ChevronDownIcon.js +6 -5
  47. package/dist/components/Icon/ChevronLeftIcon.d.ts +1 -1
  48. package/dist/components/Icon/ChevronLeftIcon.js +6 -5
  49. package/dist/components/Icon/ChevronRightIcon.d.ts +1 -1
  50. package/dist/components/Icon/ChevronRightIcon.js +6 -5
  51. package/dist/components/Icon/ChevronUpIcon.d.ts +1 -1
  52. package/dist/components/Icon/ChevronUpIcon.js +6 -5
  53. package/dist/components/Icon/ClockIcon.d.ts +1 -1
  54. package/dist/components/Icon/ClockIcon.js +6 -5
  55. package/dist/components/Icon/CloseAltIcon.d.ts +1 -1
  56. package/dist/components/Icon/CloseAltIcon.js +6 -5
  57. package/dist/components/Icon/CloseIcon.d.ts +1 -1
  58. package/dist/components/Icon/CloseIcon.js +6 -5
  59. package/dist/components/Icon/CoopCardIcon.d.ts +1 -1
  60. package/dist/components/Icon/CoopCardIcon.js +6 -5
  61. package/dist/components/Icon/CoopIcon.d.ts +1 -1
  62. package/dist/components/Icon/CoopIcon.js +6 -5
  63. package/dist/components/Icon/CoopLocationIcon.d.ts +1 -1
  64. package/dist/components/Icon/CoopLocationIcon.js +6 -5
  65. package/dist/components/Icon/DownloadIcon.d.ts +1 -1
  66. package/dist/components/Icon/DownloadIcon.js +6 -5
  67. package/dist/components/Icon/HomeIcon.d.ts +1 -1
  68. package/dist/components/Icon/HomeIcon.js +6 -5
  69. package/dist/components/Icon/InformationIcon.d.ts +1 -1
  70. package/dist/components/Icon/InformationIcon.js +6 -5
  71. package/dist/components/Icon/LoadingIcon.d.ts +1 -1
  72. package/dist/components/Icon/LoadingIcon.js +6 -5
  73. package/dist/components/Icon/LocationIcon.d.ts +1 -1
  74. package/dist/components/Icon/LocationIcon.js +6 -5
  75. package/dist/components/Icon/MailIcon.d.ts +1 -1
  76. package/dist/components/Icon/MailIcon.js +6 -5
  77. package/dist/components/Icon/MenuIcon.d.ts +1 -1
  78. package/dist/components/Icon/MenuIcon.js +6 -5
  79. package/dist/components/Icon/MessageIcon.d.ts +1 -1
  80. package/dist/components/Icon/MessageIcon.js +6 -5
  81. package/dist/components/Icon/MinusIcon.d.ts +1 -1
  82. package/dist/components/Icon/MinusIcon.js +6 -5
  83. package/dist/components/Icon/OpenNewIcon.d.ts +1 -1
  84. package/dist/components/Icon/OpenNewIcon.js +6 -5
  85. package/dist/components/Icon/PencilIcon.d.ts +1 -1
  86. package/dist/components/Icon/PencilIcon.js +6 -5
  87. package/dist/components/Icon/PhoneIcon.d.ts +1 -1
  88. package/dist/components/Icon/PhoneIcon.js +6 -5
  89. package/dist/components/Icon/QuestionIcon.d.ts +1 -1
  90. package/dist/components/Icon/QuestionIcon.js +6 -5
  91. package/dist/components/Icon/ScooterIcon.d.ts +1 -1
  92. package/dist/components/Icon/ScooterIcon.js +6 -5
  93. package/dist/components/Icon/SearchIcon.d.ts +1 -1
  94. package/dist/components/Icon/SearchIcon.js +6 -5
  95. package/dist/components/Icon/SettingsIcon.d.ts +1 -1
  96. package/dist/components/Icon/SettingsIcon.js +6 -5
  97. package/dist/components/Icon/TickAltIcon.d.ts +1 -1
  98. package/dist/components/Icon/TickAltIcon.js +6 -5
  99. package/dist/components/Icon/TickIcon.d.ts +1 -1
  100. package/dist/components/Icon/TickIcon.js +6 -5
  101. package/dist/components/Icon/VanIcon.d.ts +1 -1
  102. package/dist/components/Icon/VanIcon.js +6 -5
  103. package/dist/components/Icon/WarningIcon.d.ts +1 -1
  104. package/dist/components/Icon/WarningIcon.js +6 -5
  105. package/dist/components/Icon/WriteIcon.d.ts +1 -1
  106. package/dist/components/Icon/WriteIcon.js +6 -5
  107. package/dist/components/Image/Image.d.ts +4 -2
  108. package/dist/components/Image/Image.js +2 -2
  109. package/dist/components/Pill/Pill.d.ts +4 -2
  110. package/dist/components/Pill/Pill.js +7 -8
  111. package/dist/components/Radio/Radio.d.ts +20 -0
  112. package/dist/components/Radio/Radio.js +21 -0
  113. package/dist/components/Radio/index.d.ts +4 -0
  114. package/dist/components/{SearchBox/SearchBox.d.ts → Searchbox/Searchbox.d.ts} +10 -8
  115. package/dist/components/{SearchBox/SearchBox.js → Searchbox/Searchbox.js} +16 -11
  116. package/dist/components/Searchbox/index.d.ts +4 -0
  117. package/dist/components/Signpost/Signpost.d.ts +6 -4
  118. package/dist/components/Signpost/Signpost.js +3 -6
  119. package/dist/components/SkipNav/SkipNav.d.ts +4 -2
  120. package/dist/components/SkipNav/SkipNav.js +2 -2
  121. package/dist/components/Squircle/Squircle.d.ts +4 -2
  122. package/dist/components/Squircle/Squircle.js +2 -2
  123. package/dist/components/Tag/Tag.d.ts +5 -3
  124. package/dist/components/Tag/Tag.js +3 -6
  125. package/dist/components/TextInput/TextInput.d.ts +5 -3
  126. package/dist/components/TextInput/TextInput.js +2 -2
  127. package/dist/components/Textarea/Textarea.d.ts +4 -2
  128. package/dist/components/Textarea/Textarea.js +4 -5
  129. package/dist/{utils/slots.d.ts → hooks/useSlots.d.ts} +1 -1
  130. package/dist/{utils/slots.js → hooks/useSlots.js} +2 -2
  131. package/dist/index.d.ts +2 -2
  132. package/dist/index.js +2 -2
  133. package/package.json +3 -3
  134. package/src/components/AlertBanner/AlertBanner.tsx +6 -2
  135. package/src/components/Author/Author.tsx +5 -2
  136. package/src/components/Button/Button.tsx +10 -15
  137. package/src/components/Card/Card.tsx +7 -5
  138. package/src/components/Checkbox/Checkbox.tsx +6 -2
  139. package/src/components/Expandable/Expandable.tsx +12 -5
  140. package/src/components/Field/Field.tsx +10 -9
  141. package/src/components/FieldMarkers/Error.tsx +9 -3
  142. package/src/components/FieldMarkers/Hint.tsx +10 -4
  143. package/src/components/FieldMarkers/Label.tsx +9 -3
  144. package/src/components/FieldMarkers/Legend.tsx +9 -3
  145. package/src/components/Fieldset/Fieldset.tsx +9 -4
  146. package/src/components/Flourish/Flourish.tsx +5 -2
  147. package/src/components/Icon/AddIcon.tsx +9 -6
  148. package/src/components/Icon/ArrowDownIcon.tsx +9 -6
  149. package/src/components/Icon/ArrowLeftIcon.tsx +9 -6
  150. package/src/components/Icon/ArrowRightIcon.tsx +9 -6
  151. package/src/components/Icon/ArrowUpIcon.tsx +9 -6
  152. package/src/components/Icon/AvatarAltIcon.tsx +9 -6
  153. package/src/components/Icon/AvatarIcon.tsx +9 -6
  154. package/src/components/Icon/BasketIcon.tsx +9 -6
  155. package/src/components/Icon/CalendarIcon.tsx +9 -6
  156. package/src/components/Icon/ChevronDownIcon.tsx +9 -6
  157. package/src/components/Icon/ChevronLeftIcon.tsx +9 -6
  158. package/src/components/Icon/ChevronRightIcon.tsx +9 -6
  159. package/src/components/Icon/ChevronUpIcon.tsx +9 -6
  160. package/src/components/Icon/ClockIcon.tsx +9 -6
  161. package/src/components/Icon/CloseAltIcon.tsx +9 -6
  162. package/src/components/Icon/CloseIcon.tsx +9 -6
  163. package/src/components/Icon/CoopCardIcon.tsx +9 -6
  164. package/src/components/Icon/CoopIcon.tsx +9 -6
  165. package/src/components/Icon/CoopLocationIcon.tsx +9 -6
  166. package/src/components/Icon/DownloadIcon.tsx +9 -6
  167. package/src/components/Icon/HomeIcon.tsx +9 -6
  168. package/src/components/Icon/InformationIcon.tsx +9 -6
  169. package/src/components/Icon/LoadingIcon.tsx +9 -6
  170. package/src/components/Icon/LocationIcon.tsx +9 -6
  171. package/src/components/Icon/MailIcon.tsx +9 -6
  172. package/src/components/Icon/MenuIcon.tsx +9 -6
  173. package/src/components/Icon/MessageIcon.tsx +9 -6
  174. package/src/components/Icon/MinusIcon.tsx +9 -6
  175. package/src/components/Icon/OpenNewIcon.tsx +9 -6
  176. package/src/components/Icon/PencilIcon.tsx +9 -6
  177. package/src/components/Icon/PhoneIcon.tsx +9 -6
  178. package/src/components/Icon/QuestionIcon.tsx +9 -6
  179. package/src/components/Icon/ScooterIcon.tsx +9 -6
  180. package/src/components/Icon/SearchIcon.tsx +9 -6
  181. package/src/components/Icon/SettingsIcon.tsx +9 -6
  182. package/src/components/Icon/TickAltIcon.tsx +9 -6
  183. package/src/components/Icon/TickIcon.tsx +9 -6
  184. package/src/components/Icon/VanIcon.tsx +9 -6
  185. package/src/components/Icon/WarningIcon.tsx +9 -6
  186. package/src/components/Icon/WriteIcon.tsx +9 -6
  187. package/src/components/Image/Image.tsx +5 -2
  188. package/src/components/Pill/Pill.tsx +10 -9
  189. package/src/components/Radio/Radio.tsx +50 -0
  190. package/src/components/Radio/index.ts +5 -0
  191. package/src/components/{SearchBox/SearchBox.tsx → Searchbox/Searchbox.tsx} +33 -30
  192. package/src/components/Searchbox/index.ts +5 -0
  193. package/src/components/Signpost/Signpost.tsx +8 -8
  194. package/src/components/SkipNav/SkipNav.tsx +5 -2
  195. package/src/components/Squircle/Squircle.tsx +5 -2
  196. package/src/components/Tag/Tag.tsx +9 -8
  197. package/src/components/TextInput/TextInput.tsx +18 -3
  198. package/src/components/Textarea/Textarea.tsx +8 -6
  199. package/src/{utils/slots.ts → hooks/useSlots.ts} +1 -1
  200. package/src/index.ts +2 -2
  201. package/dist/components/RadioButton/RadioButton.d.ts +0 -18
  202. package/dist/components/RadioButton/RadioButton.js +0 -22
  203. package/dist/components/RadioButton/index.d.ts +0 -4
  204. package/dist/components/SearchBox/index.d.ts +0 -4
  205. package/src/components/RadioButton/RadioButton.tsx +0 -48
  206. package/src/components/RadioButton/index.ts +0 -5
  207. package/src/components/SearchBox/index.ts +0 -5
@@ -2,13 +2,13 @@ import { jsx } from 'react/jsx-runtime';
2
2
  import clsx from 'clsx';
3
3
  import { hasUserBg } from '../../utils/index.js';
4
4
 
5
- const Squircle = ({ children, className, size = "lg", ...props }) => {
5
+ const Squircle = ({ children, className, ref, size = "lg", ...props }) => {
6
6
  const componentProps = {
7
7
  className: clsx("coop-squircle", !hasUserBg(className) && "bg-offer-red", className),
8
8
  "data-size": size.length && size !== "lg" ? size : undefined,
9
9
  ...props,
10
10
  };
11
- return (jsx("figure", { ...componentProps, children: jsx("figcaption", { children: children }) }));
11
+ return (jsx("figure", { ...componentProps, ref: ref, children: jsx("figcaption", { children: children }) }));
12
12
  };
13
13
 
14
14
  export { Squircle, Squircle as default };
@@ -1,16 +1,18 @@
1
- import type { AnchorHTMLAttributes, ForwardRefExoticComponent, HTMLAttributes, JSX } from "react";
1
+ import type { ForwardRefExoticComponent, HTMLAttributes, JSX, Ref } from "react";
2
2
  import React from "react";
3
3
  export interface TagProps extends HTMLAttributes<HTMLAnchorElement> {
4
4
  /** **(Optional)** Specify a custom element to override default `a` or `span`. */
5
- as?: React.FC<AnchorHTMLAttributes<HTMLElement>> | ForwardRefExoticComponent<any> | string;
5
+ as?: React.FC<any> | ForwardRefExoticComponent<any> | string;
6
6
  /** **(Optional)** Main content inside the component. It can be any valid JSX or string. */
7
7
  children?: React.ReactNode;
8
8
  /** **(Optional)** Specify additional CSS classes to be applied to the component. */
9
9
  className?: string;
10
10
  /** **(Optional)** Specify the URL that the Tag component will link to when clicked. */
11
11
  href?: string;
12
+ /** **(Optional)** Specify a custom React ref for this component. */
13
+ ref?: Ref<HTMLElement>;
12
14
  /** **(Optional)** Specify the Tag size. */
13
15
  size?: "sm" | "md";
14
16
  }
15
- export declare const Tag: ({ as, children, className, href, size, ...props }: TagProps) => JSX.Element;
17
+ export declare const Tag: ({ as, children, className, href, ref, size, ...props }: TagProps) => JSX.Element;
16
18
  export default Tag;
@@ -2,18 +2,15 @@ import clsx from 'clsx';
2
2
  import React from 'react';
3
3
  import { hasUserBg } from '../../utils/index.js';
4
4
 
5
- const Tag = ({ as, children, className, href, size = "md", ...props }) => {
6
- let element = href ? "a" : "span";
5
+ const Tag = ({ as, children, className, href, ref, size = "md", ...props }) => {
6
+ const element = as !== null && as !== void 0 ? as : (href ? "a" : "span");
7
7
  const componentProps = {
8
8
  className: clsx("coop-tag", !hasUserBg(className) && "bg-tint-grey", className),
9
9
  "data-size": size.length && size !== "md" ? size : undefined,
10
10
  href,
11
11
  ...props,
12
12
  };
13
- if (as) {
14
- element = as;
15
- }
16
- return React.createElement(element, { ...componentProps }, children);
13
+ return React.createElement(element, { ...componentProps, ref }, children);
17
14
  };
18
15
 
19
16
  export { Tag, Tag as default };
@@ -1,4 +1,4 @@
1
- import type { InputHTMLAttributes, JSX } from "react";
1
+ import type { InputHTMLAttributes, JSX, Ref } from "react";
2
2
  import { StandardSizes } from "../../../src/types";
3
3
  export interface TextInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "prefix" | "size" | "type"> {
4
4
  /** **(Optional)** Specify additional CSS classes to be applied to the component. */
@@ -15,12 +15,14 @@ export interface TextInputProps extends Omit<InputHTMLAttributes<HTMLInputElemen
15
15
  placeholder?: string;
16
16
  /** **(Optional)** Specify the prefix. It can be any valid JSX or string. */
17
17
  prefix?: React.ReactNode;
18
+ /** **(Optional)** Specify a custom React ref for this component. */
19
+ ref?: Ref<HTMLInputElement>;
18
20
  /** **(Optional)** Specify the TextInput size. */
19
21
  size?: StandardSizes;
20
22
  /** **(Optional)** Specify the suffix. It can be any valid JSX or string. */
21
23
  suffix?: React.ReactNode;
22
24
  /** **(Optional)** Specify the TextInput type. */
23
- type?: "text" | "email" | "number" | "password" | "search" | "tel" | "url";
25
+ type?: "text" | "email" | "number" | "password" | "search" | "tel" | "url" | "date" | "datetime-local" | "week" | "month" | "time";
24
26
  }
25
- export declare const TextInput: ({ "aria-placeholder": ariaPlaceholder, className, disabled, error, id, name, placeholder, prefix, size, suffix, type, ...props }: TextInputProps) => JSX.Element;
27
+ export declare const TextInput: ({ "aria-placeholder": ariaPlaceholder, className, disabled, error, id, name, placeholder, prefix, ref, size, suffix, type, ...props }: TextInputProps) => JSX.Element;
26
28
  export default TextInput;
@@ -2,7 +2,7 @@ import { jsxs, jsx } from 'react/jsx-runtime';
2
2
  import clsx from 'clsx';
3
3
  import { useId } from '../../hooks/useId.js';
4
4
 
5
- const TextInput = ({ "aria-placeholder": ariaPlaceholder, className, disabled, error = false, id, name, placeholder, prefix, size = "md", suffix, type = "text", ...props }) => {
5
+ const TextInput = ({ "aria-placeholder": ariaPlaceholder, className, disabled, error = false, id, name, placeholder, prefix, ref, size = "md", suffix, type = "text", ...props }) => {
6
6
  var _a;
7
7
  const uid = useId(id);
8
8
  const componentProps = {
@@ -18,7 +18,7 @@ const TextInput = ({ "aria-placeholder": ariaPlaceholder, className, disabled, e
18
18
  ...props,
19
19
  };
20
20
  //const formItemProps = { "aria-disabled": disabled ? true : undefined }
21
- return (jsxs("div", { className: "coop-text-input-wrapper", children: [prefix && jsx("span", { className: "coop-text-input--prefix", children: prefix }), jsx("input", { ...componentProps }), suffix && jsx("span", { className: "coop-text-input--suffix", children: suffix })] }));
21
+ return (jsxs("div", { className: "coop-text-input-wrapper", children: [prefix && jsx("span", { className: "coop-text-input--prefix", children: prefix }), jsx("input", { ...componentProps, ref: ref }), suffix && jsx("span", { className: "coop-text-input--suffix", children: suffix })] }));
22
22
  };
23
23
 
24
24
  export { TextInput, TextInput as default };
@@ -1,4 +1,4 @@
1
- import type { JSX, TextareaHTMLAttributes } from "react";
1
+ import type { JSX, Ref, TextareaHTMLAttributes } from "react";
2
2
  import { StandardSizes } from "../../types";
3
3
  export interface TextareaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
4
4
  /** **(Optional)** Specify additional CSS classes to be applied to the component. */
@@ -26,10 +26,12 @@ export interface TextareaProps extends TextareaHTMLAttributes<HTMLTextAreaElemen
26
26
  name: string;
27
27
  /** **(Optional)** Specify the Textarea placeholder text. Do not use in place of a form label. */
28
28
  placeholder?: string;
29
+ /** **(Optional)** Specify a custom React ref for this component. */
30
+ ref?: Ref<HTMLTextAreaElement>;
29
31
  /** Specify the number of rows (lines of text) in the Textarea. Defaults to `4`. */
30
32
  rows?: number;
31
33
  /** **(Optional)** Specify the Textarea size. */
32
34
  size?: StandardSizes;
33
35
  }
34
- export declare const Textarea: ({ "aria-placeholder": ariaPlaceholder, className, cols, counter, cutoff, disabled, error, id, maxLength, name, onChange: userOnChange, placeholder, rows, size, ...props }: TextareaProps) => JSX.Element;
36
+ export declare const Textarea: ({ "aria-placeholder": ariaPlaceholder, className, cols, counter, cutoff, disabled, error, id, maxLength, name, onChange: userOnChange, placeholder, ref, rows, size, ...props }: TextareaProps) => JSX.Element;
35
37
  export default Textarea;
@@ -8,10 +8,9 @@ const DEBOUNCE_DELAY = 750;
8
8
  const charCountMessage = (remaining) => {
9
9
  return `You have ${Math.abs(remaining).toLocaleString()} ${Math.abs(remaining) === 1 ? "character" : "characters"} ${remaining < 0 ? "too many" : "remaining"}`;
10
10
  };
11
- const Textarea = ({ "aria-placeholder": ariaPlaceholder, className, cols = 30, counter = false, cutoff = false, disabled = false, error = false, id, maxLength, name, onChange: userOnChange = undefined, placeholder, rows = 4, size = "md", ...props }) => {
11
+ const Textarea = ({ "aria-placeholder": ariaPlaceholder, className, cols = 30, counter = false, cutoff = false, disabled = false, error = false, id, maxLength, name, onChange: userOnChange = undefined, placeholder, ref, rows = 4, size = "md", ...props }) => {
12
12
  var _a;
13
- const internalId = useId();
14
- id = id !== null && id !== void 0 ? id : internalId;
13
+ const uid = useId(id);
15
14
  const componentProps = {
16
15
  "aria-placeholder": (_a = placeholder !== null && placeholder !== void 0 ? placeholder : ariaPlaceholder) !== null && _a !== void 0 ? _a : undefined,
17
16
  className: clsx("coop-textarea", className),
@@ -19,7 +18,7 @@ const Textarea = ({ "aria-placeholder": ariaPlaceholder, className, cols = 30, c
19
18
  "data-error": error !== null && error !== void 0 ? error : undefined,
20
19
  "data-size": size.length && size !== "md" ? size : undefined,
21
20
  disabled,
22
- id,
21
+ id: uid,
23
22
  maxLength: cutoff ? maxLength : undefined,
24
23
  name,
25
24
  placeholder,
@@ -36,7 +35,7 @@ const Textarea = ({ "aria-placeholder": ariaPlaceholder, className, cols = 30, c
36
35
  return (jsxs("div", { className: "coop-textarea-wrapper", children: [jsx("textarea", { ...componentProps, onChange: (e) => {
37
36
  userOnChange === null || userOnChange === void 0 ? void 0 : userOnChange(e);
38
37
  handleChange(e);
39
- } }), showCounter && (jsxs(Fragment, { children: [jsx("small", { "aria-hidden": "true", className: "coop-textarea-counter", ...(remaining < 0 && { "data-error": true }), children: charCountMessage(remaining) }), jsx("span", { "aria-live": "polite", className: "sr-only", children: charCountMessage(debouncedRemaining) })] }))] }));
38
+ }, ref: ref }), showCounter && (jsxs(Fragment, { children: [jsx("small", { "aria-hidden": "true", className: "coop-textarea-counter", ...(remaining < 0 && { "data-error": true }), children: charCountMessage(remaining) }), jsx("span", { "aria-live": "polite", className: "sr-only", children: charCountMessage(debouncedRemaining) })] }))] }));
40
39
  };
41
40
 
42
41
  export { Textarea, Textarea as default };
@@ -2,7 +2,7 @@ import React from "react";
2
2
  type Slots<T> = Record<keyof T, React.ReactNode>;
3
3
  export declare function isKey<T extends object>(x: T, k: PropertyKey): k is keyof T;
4
4
  export declare function getSlotName(node: React.ReactNode): string | false;
5
- export declare function getSlots<T>(componentSlots: Slots<T>, children: React.ReactNode, options?: {
5
+ export declare function useSlots<T>(componentSlots: Slots<T>, children: React.ReactNode, options?: {
6
6
  collect?: string[];
7
7
  }): Slots<T>;
8
8
  export {};
@@ -8,7 +8,7 @@ function getSlotName(node) {
8
8
  ? node.type.name
9
9
  : false;
10
10
  }
11
- function getSlots(componentSlots, children, options) {
11
+ function useSlots(componentSlots, children, options) {
12
12
  return React.Children.toArray(children).reduce((slots, child) => {
13
13
  var _a;
14
14
  const slotName = getSlotName(child);
@@ -27,4 +27,4 @@ function getSlots(componentSlots, children, options) {
27
27
  }, { ...componentSlots });
28
28
  }
29
29
 
30
- export { getSlotName, getSlots, isKey };
30
+ export { getSlotName, isKey, useSlots };
package/dist/index.d.ts CHANGED
@@ -9,9 +9,9 @@ export * from "./components/Fieldset";
9
9
  export * from "./components/Flourish";
10
10
  export * from "./components/Image";
11
11
  export * from "./components/Pill";
12
- export * from "./components/RadioButton";
12
+ export * from "./components/Radio";
13
13
  export * from "./components/RootSVG";
14
- export * from "./components/SearchBox";
14
+ export * from "./components/Searchbox";
15
15
  export * from "./components/Signpost";
16
16
  export * from "./components/SkipNav";
17
17
  export * from "./components/Squircle";
package/dist/index.js CHANGED
@@ -9,9 +9,9 @@ export { Fieldset, FieldsetFields } from './components/Fieldset/Fieldset.js';
9
9
  export { Flourish } from './components/Flourish/Flourish.js';
10
10
  export { Image } from './components/Image/Image.js';
11
11
  export { Pill } from './components/Pill/Pill.js';
12
- export { RadioButton } from './components/RadioButton/RadioButton.js';
12
+ export { Radio } from './components/Radio/Radio.js';
13
13
  export { RootSVG } from './components/RootSVG/RootSVG.js';
14
- export { SearchBox } from './components/SearchBox/SearchBox.js';
14
+ export { Searchbox } from './components/Searchbox/Searchbox.js';
15
15
  export { Signpost } from './components/Signpost/Signpost.js';
16
16
  export { SkipNav } from './components/SkipNav/SkipNav.js';
17
17
  export { Squircle } from './components/Squircle/Squircle.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coopdigital/react",
3
3
  "type": "module",
4
- "version": "0.45.0",
4
+ "version": "0.47.0",
5
5
  "private": false,
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -78,8 +78,8 @@
78
78
  "storybook": "$storybook"
79
79
  },
80
80
  "dependencies": {
81
- "@coopdigital/styles": "^0.39.0",
81
+ "@coopdigital/styles": "^0.40.0",
82
82
  "clsx": "^2.1.1"
83
83
  },
84
- "gitHead": "113b5fc44feee8b4e899c75c303f1ed26f9f2629"
84
+ "gitHead": "f28e578e8a74f005d372677975f19a707ea643ca"
85
85
  }
@@ -1,4 +1,4 @@
1
- import type { HTMLAttributes, JSX, ReactNode } from "react"
1
+ import type { HTMLAttributes, JSX, ReactNode, Ref } from "react"
2
2
 
3
3
  import clsx from "clsx"
4
4
 
@@ -9,6 +9,8 @@ export interface AlertBannerProps extends HTMLAttributes<HTMLDivElement> {
9
9
  className?: string
10
10
  /** Specify the main title of the banner, rendered as a `h2`. */
11
11
  heading: string
12
+ /** **(Optional)** Specify a custom React ref for this component. */
13
+ ref?: Ref<HTMLDivElement>
12
14
  /** **(Optional)** Specify the AlertBanner variant. */
13
15
  variant?: "black" | "default"
14
16
  }
@@ -17,6 +19,7 @@ export const AlertBanner = ({
17
19
  children,
18
20
  className,
19
21
  heading,
22
+ ref,
20
23
  variant = "default",
21
24
  ...props
22
25
  }: AlertBannerProps): JSX.Element => {
@@ -25,8 +28,9 @@ export const AlertBanner = ({
25
28
  "data-variant": variant,
26
29
  ...props,
27
30
  }
31
+
28
32
  return (
29
- <aside {...componentProps}>
33
+ <aside {...componentProps} ref={ref}>
30
34
  <div className="coop-alert-banner--inner">
31
35
  <h2 id="coop-alert-banner--headline">{heading}</h2>
32
36
  {children}
@@ -1,4 +1,4 @@
1
- import type { HTMLAttributes, JSX } from "react"
1
+ import type { HTMLAttributes, JSX, Ref } from "react"
2
2
 
3
3
  import clsx from "clsx"
4
4
 
@@ -15,6 +15,8 @@ export interface AuthorProps extends HTMLAttributes<HTMLDivElement> {
15
15
  datePrefix?: string
16
16
  /** **(Optional)** Specify properties of the Author Image. */
17
17
  image?: ImageProps
18
+ /** **(Optional)** Specify a custom React ref for this component. */
19
+ ref?: Ref<HTMLDivElement>
18
20
  }
19
21
 
20
22
  export const Author = ({
@@ -26,6 +28,7 @@ export const Author = ({
26
28
  alt: "",
27
29
  src: "https://s3.eu-west-1.amazonaws.com/assets.digital.coop.co.uk/oneweb/coop-logo-inverted.svg",
28
30
  },
31
+ ref,
29
32
  ...props
30
33
  }: AuthorProps): JSX.Element => {
31
34
  const imageProps: ImageProps = {
@@ -38,7 +41,7 @@ export const Author = ({
38
41
  ...props,
39
42
  }
40
43
  return (
41
- <div {...componentProps}>
44
+ <div {...componentProps} ref={ref}>
42
45
  {image && <Image {...imageProps} />}
43
46
  <div className="coop-author--content">
44
47
  <span>
@@ -1,11 +1,6 @@
1
1
  "use client"
2
2
 
3
- import type {
4
- AnchorHTMLAttributes,
5
- ButtonHTMLAttributes,
6
- ForwardRefExoticComponent,
7
- JSX,
8
- } from "react"
3
+ import type { ButtonHTMLAttributes, ForwardRefExoticComponent, JSX, Ref } from "react"
9
4
 
10
5
  import clsx from "clsx"
11
6
  import React, { useCallback, useState } from "react"
@@ -15,7 +10,7 @@ import { LoadingIcon } from "../Icon"
15
10
  export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
16
11
  /** **(Optional)** Specify a custom element to override default `a` or `button`. */
17
12
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
- as?: React.FC<AnchorHTMLAttributes<HTMLElement>> | ForwardRefExoticComponent<any> | string
13
+ as?: React.FC<any> | ForwardRefExoticComponent<any> | string
19
14
  /** **(Optional)** Main content inside the component. It can be any valid JSX or string. */
20
15
  children?: React.ReactNode
21
16
  /** **(Optional)** Specify additional CSS classes to be applied to the component. */
@@ -31,7 +26,9 @@ export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
31
26
  /** **(Optional)** Specify text to show when the Button is in a loading state. */
32
27
  loadingText?: string
33
28
  /** **(Optional)** Callback to run when the button is pressed. If this is an async function, it will be awaited and the button will be in a pending state until the promise is resolved. */
34
- onClick?: (event: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => void
29
+ onClick?: React.MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>
30
+ /** **(Optional)** Specify a custom React ref for this component. */
31
+ ref?: Ref<HTMLElement>
35
32
  /** **(Optional)** Specify the Button size. */
36
33
  size?: "sm" | "md" | "lg"
37
34
  /** **(Optional)** Specify the Button variant. */
@@ -61,14 +58,12 @@ export const Button = ({
61
58
  isLoading = false,
62
59
  loadingText = "Loading",
63
60
  onClick,
61
+ ref,
64
62
  size = "md",
65
63
  variant = "green",
66
64
  ...props
67
65
  }: ButtonProps): JSX.Element => {
68
- let element: ButtonProps["as"] = href ? "a" : "button"
69
- if (as) {
70
- element = as
71
- }
66
+ const element: ButtonProps["as"] = as ?? (href ? "a" : "button")
72
67
 
73
68
  const [isPending, setIsPending] = useState(false)
74
69
 
@@ -79,7 +74,7 @@ export const Button = ({
79
74
  setIsPending(true)
80
75
 
81
76
  try {
82
- await Promise.resolve(onClick(event as React.MouseEvent<HTMLButtonElement>))
77
+ await Promise.resolve(onClick(event))
83
78
  } finally {
84
79
  setIsPending(false)
85
80
  }
@@ -96,7 +91,7 @@ export const Button = ({
96
91
  "data-variant": variant !== "text" ? variant : undefined,
97
92
  "data-width": isFullWidth ? "full" : undefined,
98
93
  href,
99
- onClick: handleClick,
94
+ onClick: onClick ? handleClick : undefined,
100
95
  ...props,
101
96
  }
102
97
 
@@ -110,6 +105,6 @@ export const Button = ({
110
105
  children
111
106
  )
112
107
 
113
- return React.createElement(element, { ...componentProps }, finalChildren)
108
+ return React.createElement(element, { ...componentProps, ref }, finalChildren)
114
109
  }
115
110
  export default Button
@@ -1,9 +1,9 @@
1
- import type { ForwardRefExoticComponent, HTMLAttributes, JSX } from "react"
1
+ import type { ForwardRefExoticComponent, HTMLAttributes, JSX, Ref } from "react"
2
2
 
3
3
  import clsx from "clsx"
4
4
  import React from "react"
5
5
 
6
- import { getSlots } from "../../utils/slots"
6
+ import { useSlots } from "../../hooks/useSlots"
7
7
  import { ChevronRightIcon } from "../Icon/ChevronRightIcon"
8
8
  import { Image, ImageProps } from "../Image"
9
9
 
@@ -24,6 +24,8 @@ export interface CardProps extends HTMLAttributes<HTMLDivElement> {
24
24
  imagePosition?: "left" | "right"
25
25
  /** **(Optional)** Specify the orientation of the Card. */
26
26
  orientation?: "vertical" | "horizontal"
27
+ /** **(Optional)** Specify a custom React ref for this component. */
28
+ ref?: Ref<HTMLDivElement>
27
29
  }
28
30
 
29
31
  interface CardLabelProps extends HTMLAttributes<HTMLSpanElement> {
@@ -87,12 +89,12 @@ export const Card = ({
87
89
  hrefAs,
88
90
  imagePosition = "left",
89
91
  orientation = "vertical",
92
+ ref,
90
93
  ...props
91
94
  }: CardProps): JSX.Element => {
92
95
  const { element: linkElement, props: linkProps } = getCardLinkElement(hrefAs, href)
93
96
 
94
- const slots = getSlots(componentSlots, children)
95
-
97
+ const slots = { ...useSlots(componentSlots, children) }
96
98
  const innerProps = { className: "coop-card--inner" }
97
99
  const hasLinkWrapper = href && !slots.CardHeading
98
100
 
@@ -108,7 +110,7 @@ export const Card = ({
108
110
  }
109
111
 
110
112
  return (
111
- <article {...componentProps}>
113
+ <article {...componentProps} ref={ref}>
112
114
  {slots.CardImage}
113
115
  {slots.CardBadge}
114
116
  {React.createElement(
@@ -1,4 +1,4 @@
1
- import type { InputHTMLAttributes, JSX } from "react"
1
+ import type { InputHTMLAttributes, JSX, Ref } from "react"
2
2
 
3
3
  import clsx from "clsx"
4
4
 
@@ -17,6 +17,8 @@ export interface CheckboxProps
17
17
  id?: string
18
18
  /** Specify the Checkbox name. */
19
19
  name: string
20
+ /** **(Optional)** Specify a custom React ref for this component. */
21
+ ref?: Ref<HTMLInputElement>
20
22
  /** **(Optional)** Specify the Checkbox size. */
21
23
  size?: StandardSizes
22
24
  }
@@ -27,6 +29,7 @@ export const Checkbox = ({
27
29
  error = false,
28
30
  id,
29
31
  name,
32
+ ref,
30
33
  size = "md",
31
34
  ...props
32
35
  }: CheckboxProps): JSX.Element => {
@@ -41,7 +44,8 @@ export const Checkbox = ({
41
44
  type: "checkbox",
42
45
  ...props,
43
46
  }
44
- return <input {...componentProps} />
47
+
48
+ return <input {...componentProps} ref={ref} />
45
49
  }
46
50
 
47
51
  export default Checkbox
@@ -1,9 +1,9 @@
1
- import type { DetailsHTMLAttributes, HTMLAttributes, JSX } from "react"
1
+ import type { DetailsHTMLAttributes, HTMLAttributes, JSX, Ref } from "react"
2
2
 
3
3
  import { clsx } from "clsx"
4
4
 
5
+ import { useSlots } from "../../hooks/useSlots"
5
6
  import { bgClassToColor, hasUserBg } from "../../utils"
6
- import { getSlots } from "../../utils/slots"
7
7
  import { ChevronDownIcon } from "../Icon"
8
8
 
9
9
  export interface ExpandableProps extends DetailsHTMLAttributes<HTMLDetailsElement> {
@@ -11,6 +11,8 @@ export interface ExpandableProps extends DetailsHTMLAttributes<HTMLDetailsElemen
11
11
  children: React.ReactNode
12
12
  /** **(Optional)** Specify additional CSS classes to be applied to the component. */
13
13
  className?: string
14
+ /** **(Optional)** Specify a custom React ref for this component. */
15
+ ref?: Ref<HTMLDetailsElement>
14
16
  }
15
17
 
16
18
  interface ExpandableSummaryProps extends HTMLAttributes<HTMLElement> {
@@ -25,8 +27,13 @@ const componentSlots = {
25
27
  ExpandableSummary: null,
26
28
  }
27
29
 
28
- export const Expandable = ({ children, className, ...props }: ExpandableProps): JSX.Element => {
29
- const slots = getSlots(componentSlots, children)
30
+ export const Expandable = ({
31
+ children,
32
+ className,
33
+ ref,
34
+ ...props
35
+ }: ExpandableProps): JSX.Element => {
36
+ const slots = useSlots(componentSlots, children)
30
37
 
31
38
  const componentProps = {
32
39
  className: clsx("coop-expandable", !hasUserBg(className) && "bg-tint-grey", className),
@@ -38,7 +45,7 @@ export const Expandable = ({ children, className, ...props }: ExpandableProps):
38
45
  }
39
46
 
40
47
  return (
41
- <details {...componentProps}>
48
+ <details {...componentProps} ref={ref}>
42
49
  {slots.ExpandableSummary}
43
50
  <div className="coop-expandable--content">{slots.Children}</div>
44
51
  </details>
@@ -1,10 +1,10 @@
1
- import type { HTMLAttributes, HTMLProps, JSX } from "react"
1
+ import type { HTMLAttributes, HTMLProps, JSX, Ref } from "react"
2
2
 
3
3
  import clsx from "clsx"
4
4
  import React from "react"
5
5
 
6
6
  import { useId } from "../../hooks/useId"
7
- import { getSlots } from "../../utils/slots"
7
+ import { useSlots } from "../../hooks/useSlots"
8
8
  import { Error as BaseError, type ErrorProps } from "../FieldMarkers/Error"
9
9
  import { Hint as BaseHint, type HintProps } from "../FieldMarkers/Hint"
10
10
  import { Label as BaseLabel, type LabelProps } from "../FieldMarkers/Label"
@@ -16,13 +16,13 @@ const componentSlots = {
16
16
  FieldError: null,
17
17
  FieldHint: null,
18
18
  FieldLabel: null,
19
- RadioButton: null,
19
+ Radio: null,
20
20
  Textarea: null,
21
21
  TextInput: null,
22
22
  }
23
23
 
24
24
  const standardFields = ["Children", "FieldError", "FieldHint", "FieldLabel"]
25
- const inlineFields = ["Checkbox", "RadioButton"]
25
+ const inlineFields = ["Checkbox", "Radio"]
26
26
 
27
27
  interface FieldProps extends HTMLAttributes<HTMLDivElement> {
28
28
  /** **(Optional)** Specify whether the Field should render inside a box. */
@@ -37,6 +37,8 @@ interface FieldProps extends HTMLAttributes<HTMLDivElement> {
37
37
  error?: boolean
38
38
  /** **(Optional)** Specify whether the Field should show the left-hand error bar if it is in an error state. */
39
39
  hideErrorBar?: boolean
40
+ /** **(Optional)** Specify a custom React ref for this component. */
41
+ ref?: Ref<HTMLDivElement>
40
42
  }
41
43
 
42
44
  const Root = ({
@@ -45,19 +47,18 @@ const Root = ({
45
47
  className,
46
48
  error = false,
47
49
  hideErrorBar = false,
50
+ ref,
48
51
  ...props
49
52
  }: FieldProps) => {
50
- const slots = getSlots(componentSlots, children)
53
+ const slots = { ...useSlots(componentSlots, children) }
51
54
  const slotsArray = Object.entries(slots)
52
55
 
53
- const uid = useId()
54
-
55
56
  const isInlineControl = slotsArray.some((s) => s[1] !== null && inlineFields.includes(s[0]))
56
57
  const hasFieldMarkers = !!(slots.FieldLabel ?? slots.FieldError ?? slots.FieldHint)
57
58
  const [, control] =
58
59
  slotsArray.find((s) => (!standardFields.includes(s[0]) && s[1] !== null ? s : null)) ?? []
59
60
 
60
- let controlId = uid
61
+ let controlId = useId()
61
62
  let controlDisabled = false
62
63
 
63
64
  if (control) {
@@ -88,7 +89,7 @@ const Root = ({
88
89
  }
89
90
 
90
91
  return (
91
- <div {...componentProps}>
92
+ <div {...componentProps} ref={ref}>
92
93
  {!isInlineControl && hasFieldMarkers && (
93
94
  <div className="coop-field-markers">
94
95
  {slots.FieldLabel}
@@ -1,4 +1,4 @@
1
- import type { HTMLAttributes, JSX, ReactNode } from "react"
1
+ import type { HTMLAttributes, JSX, ReactNode, Ref } from "react"
2
2
 
3
3
  import clsx from "clsx"
4
4
 
@@ -7,14 +7,20 @@ export interface ErrorProps extends HTMLAttributes<HTMLSpanElement> {
7
7
  children?: string | ReactNode
8
8
  /** **(Optional)** Specify additional CSS classes to be applied to the component. */
9
9
  className?: string
10
+ /** **(Optional)** Specify a custom React ref for this component. */
11
+ ref?: Ref<HTMLSpanElement>
10
12
  }
11
13
 
12
- export const Error = ({ children, className, ...props }: ErrorProps): JSX.Element => {
14
+ export const Error = ({ children, className, ref, ...props }: ErrorProps): JSX.Element => {
13
15
  const componentProps = {
14
16
  className: clsx("coop-field-error ", className),
15
17
  ...props,
16
18
  }
17
- return <span {...componentProps}>{children}</span>
19
+ return (
20
+ <span {...componentProps} ref={ref}>
21
+ {children}
22
+ </span>
23
+ )
18
24
  }
19
25
 
20
26
  export default Error
@@ -1,21 +1,27 @@
1
- import type { HTMLAttributes, JSX, ReactNode } from "react"
1
+ import type { HTMLAttributes, JSX, ReactNode, Ref } from "react"
2
2
 
3
3
  import clsx from "clsx"
4
4
 
5
- export interface HintProps extends HTMLAttributes<HTMLParagraphElement> {
5
+ export interface HintProps extends HTMLAttributes<HTMLDivElement> {
6
6
  /** **(Optional)** Hint text for the form element. Accepts any valid JSX or string. */
7
7
  children?: string | ReactNode
8
8
  /** **(Optional)** Specify additional CSS classes to be applied to the component. */
9
9
  className?: string
10
+ /** **(Optional)** Specify a custom React ref for this component. */
11
+ ref?: Ref<HTMLDivElement>
10
12
  }
11
13
 
12
- export const Hint = ({ children, className, ...props }: HintProps): JSX.Element | null => {
14
+ export const Hint = ({ children, className, ref, ...props }: HintProps): JSX.Element | null => {
13
15
  const componentProps = {
14
16
  className: clsx("coop-field-hint ", className),
15
17
  ...props,
16
18
  }
17
19
 
18
- return children ? <div {...componentProps}>{children}</div> : null
20
+ return (
21
+ <div {...componentProps} ref={ref}>
22
+ {children}
23
+ </div>
24
+ )
19
25
  }
20
26
 
21
27
  export default Hint
@@ -1,5 +1,5 @@
1
1
  import clsx from "clsx"
2
- import { LabelHTMLAttributes } from "react"
2
+ import { LabelHTMLAttributes, Ref } from "react"
3
3
 
4
4
  export interface LabelProps extends LabelHTMLAttributes<HTMLLabelElement> {
5
5
  /** **(Optional)** Main label for the form element. Accepts any valid JSX or string. */
@@ -8,11 +8,17 @@ export interface LabelProps extends LabelHTMLAttributes<HTMLLabelElement> {
8
8
  className?: string
9
9
  /** **(Optional)** Specify whether the label is visible for humans or only for screen readers. */
10
10
  isVisible?: boolean
11
+ /** **(Optional)** Specify a custom React ref for this component. */
12
+ ref?: Ref<HTMLLabelElement>
11
13
  }
12
14
 
13
- export const Label = ({ children, className, isVisible = true, ...props }: LabelProps) => {
15
+ export const Label = ({ children, className, isVisible = true, ref, ...props }: LabelProps) => {
16
+ const componentProps = {
17
+ className: clsx("coop-field-label", !isVisible && "sr-only", className),
18
+ ...props,
19
+ }
14
20
  return (
15
- <label {...props} className={clsx("coop-field-label", !isVisible && "sr-only", className)}>
21
+ <label {...componentProps} ref={ref}>
16
22
  <span>{children}</span>
17
23
  </label>
18
24
  )