@coopdigital/react 0.44.0 → 0.46.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 (85) hide show
  1. package/dist/components/Button/Button.d.ts +6 -4
  2. package/dist/components/Button/Button.js +4 -6
  3. package/dist/components/Card/Card.js +2 -2
  4. package/dist/components/Checkbox/Checkbox.d.ts +4 -24
  5. package/dist/components/Checkbox/Checkbox.js +7 -14
  6. package/dist/components/Checkbox/index.d.ts +1 -2
  7. package/dist/components/Expandable/Expandable.js +2 -2
  8. package/dist/components/Field/Field.d.ts +44 -5
  9. package/dist/components/Field/Field.js +68 -5
  10. package/dist/components/FieldMarkers/Error.d.ts +9 -0
  11. package/dist/components/{FieldError/FieldError.js → FieldMarkers/Error.js} +2 -2
  12. package/dist/components/FieldMarkers/Hint.d.ts +9 -0
  13. package/dist/components/{FieldHint/FieldHint.js → FieldMarkers/Hint.js} +2 -2
  14. package/dist/components/FieldMarkers/Label.d.ts +11 -0
  15. package/dist/components/FieldMarkers/Label.js +8 -0
  16. package/dist/components/FieldMarkers/Legend.d.ts +11 -0
  17. package/dist/components/FieldMarkers/Legend.js +13 -0
  18. package/dist/components/Fieldset/Fieldset.d.ts +54 -0
  19. package/dist/components/Fieldset/Fieldset.js +44 -0
  20. package/dist/components/Fieldset/index.d.ts +4 -0
  21. package/dist/components/Pill/Pill.js +2 -2
  22. package/dist/components/Radio/Radio.d.ts +18 -0
  23. package/dist/components/Radio/Radio.js +22 -0
  24. package/dist/components/Radio/index.d.ts +4 -0
  25. package/dist/components/{SearchBox/SearchBox.d.ts → Searchbox/Searchbox.d.ts} +7 -7
  26. package/dist/components/{SearchBox/SearchBox.js → Searchbox/Searchbox.js} +6 -6
  27. package/dist/components/Searchbox/index.d.ts +4 -0
  28. package/dist/components/TextInput/TextInput.d.ts +5 -19
  29. package/dist/components/TextInput/TextInput.js +7 -11
  30. package/dist/components/Textarea/Textarea.d.ts +4 -18
  31. package/dist/components/Textarea/Textarea.js +8 -9
  32. package/dist/hooks/useId.d.ts +2 -0
  33. package/dist/hooks/useId.js +8 -0
  34. package/dist/{utils/slots.d.ts → hooks/useSlots.d.ts} +3 -1
  35. package/dist/{utils/slots.js → hooks/useSlots.js} +9 -3
  36. package/dist/index.d.ts +3 -5
  37. package/dist/index.js +4 -8
  38. package/package.json +10 -10
  39. package/src/components/Button/Button.tsx +10 -14
  40. package/src/components/Card/Card.tsx +2 -3
  41. package/src/components/Checkbox/Checkbox.tsx +8 -64
  42. package/src/components/Checkbox/index.ts +1 -2
  43. package/src/components/Expandable/Expandable.tsx +2 -2
  44. package/src/components/Field/Field.tsx +144 -8
  45. package/src/components/{FieldError/FieldError.tsx → FieldMarkers/Error.tsx} +4 -4
  46. package/src/components/{FieldHint/FieldHint.tsx → FieldMarkers/Hint.tsx} +5 -9
  47. package/src/components/FieldMarkers/Label.tsx +21 -0
  48. package/src/components/FieldMarkers/Legend.tsx +28 -0
  49. package/src/components/Fieldset/Fieldset.tsx +98 -0
  50. package/src/components/Fieldset/index.ts +5 -0
  51. package/src/components/Pill/Pill.tsx +2 -2
  52. package/src/components/Radio/Radio.tsx +47 -0
  53. package/src/components/Radio/index.ts +5 -0
  54. package/src/components/{SearchBox/SearchBox.tsx → Searchbox/Searchbox.tsx} +15 -13
  55. package/src/components/Searchbox/index.ts +5 -0
  56. package/src/components/TextInput/TextInput.tsx +25 -46
  57. package/src/components/Textarea/Textarea.tsx +12 -40
  58. package/src/hooks/useId.ts +9 -0
  59. package/src/{utils/slots.ts → hooks/useSlots.ts} +10 -2
  60. package/src/index.ts +3 -5
  61. package/dist/components/Checkbox/CheckboxGroup.d.ts +0 -32
  62. package/dist/components/Checkbox/CheckboxGroup.js +0 -21
  63. package/dist/components/FieldError/FieldError.d.ts +0 -9
  64. package/dist/components/FieldError/index.d.ts +0 -4
  65. package/dist/components/FieldHint/FieldHint.d.ts +0 -9
  66. package/dist/components/FieldHint/index.d.ts +0 -4
  67. package/dist/components/FieldLabel/FieldLabel.d.ts +0 -13
  68. package/dist/components/FieldLabel/FieldLabel.js +0 -13
  69. package/dist/components/FieldLabel/index.d.ts +0 -4
  70. package/dist/components/RadioButton/RadioButton.d.ts +0 -36
  71. package/dist/components/RadioButton/RadioButton.js +0 -26
  72. package/dist/components/RadioButton/RadioButtonGroup.d.ts +0 -32
  73. package/dist/components/RadioButton/RadioButtonGroup.js +0 -21
  74. package/dist/components/RadioButton/index.d.ts +0 -5
  75. package/dist/components/SearchBox/index.d.ts +0 -4
  76. package/dist/components/Tag/index.js +0 -5
  77. package/src/components/Checkbox/CheckboxGroup.tsx +0 -73
  78. package/src/components/FieldError/index.ts +0 -5
  79. package/src/components/FieldHint/index.ts +0 -5
  80. package/src/components/FieldLabel/FieldLabel.tsx +0 -31
  81. package/src/components/FieldLabel/index.ts +0 -5
  82. package/src/components/RadioButton/RadioButton.tsx +0 -97
  83. package/src/components/RadioButton/RadioButtonGroup.tsx +0 -73
  84. package/src/components/RadioButton/index.ts +0 -6
  85. package/src/components/SearchBox/index.ts +0 -5
@@ -1,13 +1,11 @@
1
1
  import type { ChangeEvent, JSX, TextareaHTMLAttributes } from "react"
2
2
 
3
3
  import clsx from "clsx"
4
- import { useId, useState } from "react"
4
+ import { useState } from "react"
5
5
 
6
6
  import { useDebounce } from "../../hooks/useDebounce"
7
- import { FormFieldError, StandardSizes } from "../../types"
8
- import { FieldError } from "../FieldError"
9
- import { FieldHint } from "../FieldHint"
10
- import { FieldLabel } from "../FieldLabel"
7
+ import { useId } from "../../hooks/useId"
8
+ import { StandardSizes } from "../../types"
11
9
 
12
10
  const DEBOUNCE_DELAY = 750
13
11
 
@@ -31,24 +29,10 @@ export interface TextareaProps extends TextareaHTMLAttributes<HTMLTextAreaElemen
31
29
  cutoff?: boolean
32
30
  /** **(Optional)** Specify whether the Textarea should be disabled. Refer to Experience Library guidance on disabled form controls and accessibility. */
33
31
  disabled?: boolean
34
- /** **(Optional)** Specify the Textarea error state.
35
- *
36
- * 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.
37
- */
38
- error?: FormFieldError
39
- /** **(Optional)** Specify the Textarea hint.
40
- *
41
- * This text is rendered under the label to provide further guidance for users.
42
- */
43
- hint?: string
32
+ /** **(Optional)** Specify the Textarea error state */
33
+ error?: boolean
44
34
  /** **(Optional)** Specify the Textarea id. Will be auto-generated if not set. */
45
35
  id?: string
46
- /** **(Optional)** Specify the Textarea label.
47
- *
48
- * This property is optional in case you need to render your own label, but all form elements *must* provide a label. */
49
- label?: string
50
- /** **(Optional)** Specify whether the label should be visible to humans or screen readers. */
51
- labelVisible?: boolean
52
36
  /** **(Optional)** Specify the Textarea maxLength. This is the maximum number of characters users can enter. */
53
37
  maxLength?: number
54
38
  /** Specify the Textarea name. */
@@ -69,10 +53,7 @@ export const Textarea = ({
69
53
  cutoff = false,
70
54
  disabled = false,
71
55
  error = false,
72
- hint,
73
56
  id,
74
- label,
75
- labelVisible = true,
76
57
  maxLength,
77
58
  name,
78
59
  onChange: userOnChange = undefined,
@@ -89,7 +70,7 @@ export const Textarea = ({
89
70
  "aria-placeholder": placeholder ?? ariaPlaceholder ?? undefined,
90
71
  className: clsx("coop-textarea", className),
91
72
  cols,
92
- "data-error": error ? "" : undefined,
73
+ "data-error": error ?? undefined,
93
74
  "data-size": size.length && size !== "md" ? size : undefined,
94
75
  disabled,
95
76
  id,
@@ -102,23 +83,15 @@ export const Textarea = ({
102
83
 
103
84
  const [remaining, setRemaining] = useState(maxLength)
104
85
  const debouncedRemaining = useDebounce(remaining, DEBOUNCE_DELAY)
86
+ const showCounter =
87
+ !disabled && counter && maxLength && remaining != null && debouncedRemaining != null
105
88
 
106
89
  const handleChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
107
90
  maxLength && e.target && setRemaining(maxLength - e.target.value.length)
108
91
  }
109
- const formItemProps = { "aria-disabled": disabled ? true : undefined }
92
+ // const formItemProps = { "aria-disabled": disabled ? true : undefined }
110
93
  return (
111
- <div className="coop-form-item" {...formItemProps}>
112
- {label && (
113
- <FieldLabel htmlFor={id} isVisible={labelVisible}>
114
- {label}
115
- </FieldLabel>
116
- )}
117
-
118
- {hint && <FieldHint>{hint}</FieldHint>}
119
-
120
- {typeof error === "object" && error?.message && <FieldError>{error.message}</FieldError>}
121
-
94
+ <div className="coop-textarea-wrapper">
122
95
  <textarea
123
96
  {...componentProps}
124
97
  onChange={(e) => {
@@ -126,13 +99,12 @@ export const Textarea = ({
126
99
  handleChange(e)
127
100
  }}
128
101
  ></textarea>
129
-
130
- {!disabled && counter && maxLength && remaining != null && debouncedRemaining != null && (
102
+ {showCounter && (
131
103
  <>
132
104
  <small
133
105
  aria-hidden="true"
134
106
  className="coop-textarea-counter"
135
- {...(remaining < 0 && { "data-error": "" })}
107
+ {...(remaining < 0 && { "data-error": true })}
136
108
  >
137
109
  {charCountMessage(remaining)}
138
110
  </small>
@@ -0,0 +1,9 @@
1
+ import { useId as _useId } from "react"
2
+
3
+ export type UseId = (id?: string) => string
4
+
5
+ export const useId: UseId = (id) => {
6
+ const uniqueId = _useId()
7
+
8
+ return id ?? uniqueId
9
+ }
@@ -12,13 +12,21 @@ export function getSlotName(node: React.ReactNode): string | false {
12
12
  : false
13
13
  }
14
14
 
15
- export function getSlots<T>(componentSlots: Slots<T>, children: React.ReactNode): Slots<T> {
15
+ export function useSlots<T>(
16
+ componentSlots: Slots<T>,
17
+ children: React.ReactNode,
18
+ options?: { collect?: string[] }
19
+ ): Slots<T> {
16
20
  return React.Children.toArray(children).reduce(
17
21
  (slots, child: React.ReactNode) => {
18
22
  const slotName = getSlotName(child)
19
23
 
20
24
  if (child && slotName && isKey(componentSlots, slotName)) {
21
- slots[slotName] = child
25
+ if (options?.collect?.includes(slotName)) {
26
+ slots[slotName] = slots[slotName] ? [...[slots[slotName]].flat(), child] : [child]
27
+ } else {
28
+ slots[slotName] = child
29
+ }
22
30
  } else if ("Children" in slots) {
23
31
  slots.Children = slots.Children ? [...[slots.Children].flat(), child] : [child]
24
32
  }
package/src/index.ts CHANGED
@@ -5,15 +5,13 @@ export * from "./components/Card"
5
5
  export * from "./components/Checkbox"
6
6
  export * from "./components/Expandable"
7
7
  export * from "./components/Field"
8
- export * from "./components/FieldError"
9
- export * from "./components/FieldHint"
10
- export * from "./components/FieldLabel"
8
+ export * from "./components/Fieldset"
11
9
  export * from "./components/Flourish"
12
10
  export * from "./components/Image"
13
11
  export * from "./components/Pill"
14
- export * from "./components/RadioButton"
12
+ export * from "./components/Radio"
15
13
  export * from "./components/RootSVG"
16
- export * from "./components/SearchBox"
14
+ export * from "./components/Searchbox"
17
15
  export * from "./components/Signpost"
18
16
  export * from "./components/SkipNav"
19
17
  export * from "./components/Squircle"
@@ -1,32 +0,0 @@
1
- import type { FieldsetHTMLAttributes, JSX } from "react";
2
- import { FormFieldError, StandardSizes } from "../../../src/types";
3
- export interface CheckboxGroupProps 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 whether the CheckboxGroup, and all of its descendents, should be disabled. Refer to Experience Library guidance on disabled form controls and accessibility. */
9
- disabled?: boolean;
10
- /** **(Optional)** Specify the CheckboxGroup error state.
11
- *
12
- * 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.
13
- */
14
- error?: FormFieldError;
15
- /** **(Optional)** Specify the CheckboxGroup hint.
16
- *
17
- * This text is rendered under the label to provide further guidance for users.
18
- */
19
- hint?: string;
20
- /** **(Optional)** Specify the label for the CheckboxGroup. This will be rendered as a fieldset legend. */
21
- label?: string;
22
- /** **(Optional)** Specify whether the label should be visible to humans or screen readers. */
23
- labelVisible?: boolean;
24
- /** **(Optional)** Specify the CheckboxGroup orientation. */
25
- orientation?: "horizontal" | "vertical";
26
- /** **(Optional)** Specify the CheckboxGroup size. */
27
- size?: StandardSizes;
28
- /** **(Optional)** Specify the CheckboxGroup variant. */
29
- variant?: "default" | "boxed";
30
- }
31
- export declare const CheckboxGroup: ({ children, className, error, hint, label, labelVisible, orientation, size, variant, ...props }: CheckboxGroupProps) => JSX.Element;
32
- export default CheckboxGroup;
@@ -1,21 +0,0 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
2
- import clsx from 'clsx';
3
- import { FieldError } from '../FieldError/FieldError.js';
4
- import { FieldHint } from '../FieldHint/FieldHint.js';
5
-
6
- const CheckboxGroup = ({ children, className, error = false, hint, label, labelVisible = true, orientation = "vertical", size = "md", variant = "default", ...props }) => {
7
- const componentProps = {
8
- className: clsx("coop-fieldset", "coop-checkbox-group", className),
9
- "data-error": error ? "" : undefined,
10
- "data-orientation": orientation !== "vertical" ? orientation : undefined,
11
- "data-size": size.length && size !== "md" ? size : undefined,
12
- "data-variant": variant !== "default" ? variant : undefined,
13
- ...props,
14
- };
15
- const legendProps = {
16
- className: clsx("coop-field-label", !labelVisible && "sr-only"),
17
- };
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-checkbox-group-options", children: children })] }));
19
- };
20
-
21
- export { CheckboxGroup, CheckboxGroup as default };
@@ -1,9 +0,0 @@
1
- import type { HTMLAttributes, JSX, ReactNode } from "react";
2
- export interface FieldErrorProps extends HTMLAttributes<HTMLSpanElement> {
3
- /** **(Optional)** Main content inside the component. It can be any valid JSX or string. */
4
- children?: string | ReactNode;
5
- /** **(Optional)** Specify additional CSS classes to be applied to the component. */
6
- className?: string;
7
- }
8
- export declare const FieldError: ({ children, className, ...props }: FieldErrorProps) => JSX.Element;
9
- export default FieldError;
@@ -1,4 +0,0 @@
1
- import FieldError from "./FieldError";
2
- export default FieldError;
3
- export { FieldError };
4
- export * from "./FieldError";
@@ -1,9 +0,0 @@
1
- import type { HTMLAttributes, JSX, ReactNode } from "react";
2
- export interface FieldHintProps extends HTMLAttributes<HTMLParagraphElement> {
3
- /** Main content inside the component. It can be any valid JSX or string. */
4
- children: string | ReactNode;
5
- /** **(Optional)** Specify additional CSS classes to be applied to the component. */
6
- className?: string;
7
- }
8
- export declare const FieldHint: ({ children, className, ...props }: FieldHintProps) => JSX.Element | null;
9
- export default FieldHint;
@@ -1,4 +0,0 @@
1
- import FieldHint from "./FieldHint";
2
- export default FieldHint;
3
- export { FieldHint };
4
- export * from "./FieldHint";
@@ -1,13 +0,0 @@
1
- import type { JSX, LabelHTMLAttributes, ReactNode } from "react";
2
- export interface FieldLabelProps extends LabelHTMLAttributes<HTMLLabelElement> {
3
- /** **(Optional)** Main content inside the component. It can be any valid JSX or string. */
4
- children?: string | ReactNode;
5
- /** **(Optional)** Specify additional CSS classes to be applied to the component. */
6
- className?: string;
7
- /** Specify the field ID to connect FieldLabel to the field itself. */
8
- htmlFor: string;
9
- /** **(Optional)** Specify whether the FieldLabel is visible for humans or only for screen readers. */
10
- isVisible?: boolean;
11
- }
12
- export declare const FieldLabel: ({ children, className, htmlFor, isVisible, ...props }: FieldLabelProps) => JSX.Element | null;
13
- export default FieldLabel;
@@ -1,13 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import clsx from 'clsx';
3
-
4
- const FieldLabel = ({ children, className, htmlFor, isVisible = true, ...props }) => {
5
- const componentProps = {
6
- className: clsx("coop-field-label ", isVisible ? "" : "sr-only", className),
7
- htmlFor,
8
- ...props,
9
- };
10
- return children && htmlFor ? jsx("label", { ...componentProps, children: children }) : null;
11
- };
12
-
13
- export { FieldLabel, FieldLabel as default };
@@ -1,4 +0,0 @@
1
- import FieldLabel from "./FieldLabel";
2
- export default FieldLabel;
3
- export { FieldLabel };
4
- export * from "./FieldLabel";
@@ -1,36 +0,0 @@
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 whether the RadioButton should be disabled. Refer to Experience Library guidance on disabled form controls and accessibility. */
7
- disabled?: boolean;
8
- /** **(Optional)** Specify the RadioButton 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 RadioButton hint.
14
- *
15
- * This text is rendered under the label to provide further guidance for users.
16
- */
17
- hint?: string;
18
- /** **(Optional)** Specify the RadioButton id. Will be auto-generated if not set. */
19
- id?: string;
20
- /** **(Optional)** Specify the RadioButton label.
21
- *
22
- * This property is optional in case you need to render your own label, but all form elements *must* provide a label. */
23
- label: string;
24
- /** **(Optional)** Specify whether the label should be visible to humans or screen readers. */
25
- labelVisible?: boolean;
26
- /** Specify the RadioButton name. */
27
- name: string;
28
- /** **(Optional)** Specify the RadioButton size. */
29
- size?: StandardSizes;
30
- /** **(Optional)** Specify the RadioButton tag text. */
31
- tag?: string;
32
- /** **(Optional)** Specify the RadioButton tag className. */
33
- tagClassName?: string;
34
- }
35
- export declare const RadioButton: ({ className, disabled, error, hint, id, label, labelVisible, name, size, tag, tagClassName, ...props }: RadioButtonProps) => JSX.Element;
36
- export default RadioButton;
@@ -1,26 +0,0 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
2
- import clsx from 'clsx';
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
- import { Tag } from '../Tag/Tag.js';
8
-
9
- const RadioButton = ({ className, disabled, error = false, hint, id, label, labelVisible = true, name, size = "md", tag, tagClassName, ...props }) => {
10
- const internalId = useId();
11
- id = id !== null && id !== void 0 ? id : internalId;
12
- const componentProps = {
13
- className: clsx("coop-radio-button", className),
14
- "data-error": error ? "" : undefined,
15
- "data-size": size.length && size !== "md" ? size : undefined,
16
- disabled,
17
- id,
18
- name,
19
- type: "radio",
20
- ...props,
21
- };
22
- const formItemProps = { "aria-disabled": disabled ? true : undefined };
23
- return (jsxs("div", { className: "coop-form-item", ...formItemProps, children: [jsxs("div", { className: "coop-radio-button-wrapper", children: [jsxs("div", { className: "coop-radio-button-input-wrapper", children: [jsx("input", { ...componentProps }), label && (jsxs(FieldLabel, { htmlFor: id, isVisible: labelVisible, children: [jsx("span", { children: label }), " ", tag && (jsx(Tag, { className: tagClassName, 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 })] }));
24
- };
25
-
26
- export { RadioButton, RadioButton as default };
@@ -1,32 +0,0 @@
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 whether the RadioButtonGroup, and all of its descendents, should be disabled. Refer to Experience Library guidance on disabled form controls and accessibility. */
9
- disabled?: boolean;
10
- /** **(Optional)** Specify the RadioButtonGroup error state.
11
- *
12
- * 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.
13
- */
14
- error?: FormFieldError;
15
- /** **(Optional)** Specify the RadioButtonGroup hint.
16
- *
17
- * This text is rendered under the label to provide further guidance for users.
18
- */
19
- hint?: string;
20
- /** **(Optional)** Specify the label for the RadioButtonGroup. This will be rendered as a fieldset legend. */
21
- label?: string;
22
- /** **(Optional)** Specify whether the label should be visible to humans or screen readers. */
23
- labelVisible?: boolean;
24
- /** **(Optional)** Specify the RadioButtonGroup orientation. */
25
- orientation?: "horizontal" | "vertical";
26
- /** **(Optional)** Specify the RadioButtonGroup size. */
27
- size?: StandardSizes;
28
- /** **(Optional)** Specify the RadioButtonGroup variant. */
29
- variant?: "default" | "boxed";
30
- }
31
- export declare const RadioButtonGroup: ({ children, className, error, hint, label, labelVisible, orientation, size, variant, ...props }: RadioButtonGroupProps) => JSX.Element;
32
- export default RadioButtonGroup;
@@ -1,21 +0,0 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
2
- import clsx from 'clsx';
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, orientation = "vertical", size = "md", variant = "default", ...props }) => {
7
- const componentProps = {
8
- className: clsx("coop-fieldset", "coop-radio-button-group", className),
9
- "data-error": error ? "" : undefined,
10
- "data-orientation": orientation !== "vertical" ? orientation : undefined,
11
- "data-size": size.length && size !== "md" ? size : undefined,
12
- "data-variant": variant !== "default" ? variant : undefined,
13
- ...props,
14
- };
15
- const legendProps = {
16
- className: clsx("coop-field-label", !labelVisible && "sr-only"),
17
- };
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 })] }));
19
- };
20
-
21
- export { RadioButtonGroup, RadioButtonGroup as default };
@@ -1,5 +0,0 @@
1
- import RadioButton from "./RadioButton";
2
- import RadioButtonGroup from "./RadioButtonGroup";
3
- export default RadioButton;
4
- export { RadioButton, RadioButtonGroup };
5
- export * from "./RadioButton";
@@ -1,4 +0,0 @@
1
- import SearchBox from "./SearchBox";
2
- export default SearchBox;
3
- export { SearchBox };
4
- export * from "./SearchBox";
@@ -1,5 +0,0 @@
1
- import { Tag } from './Tag.js';
2
-
3
-
4
-
5
- export { Tag, Tag as default };
@@ -1,73 +0,0 @@
1
- import type { FieldsetHTMLAttributes, JSX } from "react"
2
-
3
- import clsx from "clsx"
4
-
5
- import { FormFieldError, StandardSizes } from "../../../src/types"
6
- import { FieldError } from "../FieldError"
7
- import { FieldHint } from "../FieldHint"
8
-
9
- export interface CheckboxGroupProps 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 whether the CheckboxGroup, and all of its descendents, should be disabled. Refer to Experience Library guidance on disabled form controls and accessibility. */
15
- disabled?: boolean
16
- /** **(Optional)** Specify the CheckboxGroup error state.
17
- *
18
- * 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.
19
- */
20
- error?: FormFieldError
21
- /** **(Optional)** Specify the CheckboxGroup hint.
22
- *
23
- * This text is rendered under the label to provide further guidance for users.
24
- */
25
- hint?: string
26
- /** **(Optional)** Specify the label for the CheckboxGroup. This will be rendered as a fieldset legend. */
27
- label?: string
28
- /** **(Optional)** Specify whether the label should be visible to humans or screen readers. */
29
- labelVisible?: boolean
30
- /** **(Optional)** Specify the CheckboxGroup orientation. */
31
- orientation?: "horizontal" | "vertical"
32
- /** **(Optional)** Specify the CheckboxGroup size. */
33
- size?: StandardSizes
34
- /** **(Optional)** Specify the CheckboxGroup variant. */
35
- variant?: "default" | "boxed"
36
- }
37
-
38
- export const CheckboxGroup = ({
39
- children,
40
- className,
41
- error = false,
42
- hint,
43
- label,
44
- labelVisible = true,
45
- orientation = "vertical",
46
- size = "md",
47
- variant = "default",
48
- ...props
49
- }: CheckboxGroupProps): JSX.Element => {
50
- const componentProps = {
51
- className: clsx("coop-fieldset", "coop-checkbox-group", className),
52
- "data-error": error ? "" : undefined,
53
- "data-orientation": orientation !== "vertical" ? orientation : undefined,
54
- "data-size": size.length && size !== "md" ? size : undefined,
55
- "data-variant": variant !== "default" ? variant : undefined,
56
- ...props,
57
- }
58
-
59
- const legendProps = {
60
- className: clsx("coop-field-label", !labelVisible && "sr-only"),
61
- }
62
-
63
- return (
64
- <fieldset {...componentProps}>
65
- {label && <legend {...legendProps}>{label}</legend>}
66
- {hint && <FieldHint>{hint}</FieldHint>}
67
- {typeof error === "object" && error?.message && <FieldError>{error.message}</FieldError>}
68
- <div className="coop-checkbox-group-options">{children}</div>
69
- </fieldset>
70
- )
71
- }
72
-
73
- export default CheckboxGroup
@@ -1,5 +0,0 @@
1
- import FieldError from "./FieldError"
2
-
3
- export default FieldError
4
- export { FieldError }
5
- export * from "./FieldError"
@@ -1,5 +0,0 @@
1
- import FieldHint from "./FieldHint"
2
-
3
- export default FieldHint
4
- export { FieldHint }
5
- export * from "./FieldHint"
@@ -1,31 +0,0 @@
1
- import type { JSX, LabelHTMLAttributes, ReactNode } from "react"
2
-
3
- import clsx from "clsx"
4
-
5
- export interface FieldLabelProps extends LabelHTMLAttributes<HTMLLabelElement> {
6
- /** **(Optional)** Main content inside the component. It can be any valid JSX or string. */
7
- children?: string | ReactNode
8
- /** **(Optional)** Specify additional CSS classes to be applied to the component. */
9
- className?: string
10
- /** Specify the field ID to connect FieldLabel to the field itself. */
11
- htmlFor: string
12
- /** **(Optional)** Specify whether the FieldLabel is visible for humans or only for screen readers. */
13
- isVisible?: boolean
14
- }
15
-
16
- export const FieldLabel = ({
17
- children,
18
- className,
19
- htmlFor,
20
- isVisible = true,
21
- ...props
22
- }: FieldLabelProps): JSX.Element | null => {
23
- const componentProps = {
24
- className: clsx("coop-field-label ", isVisible ? "" : "sr-only", className),
25
- htmlFor,
26
- ...props,
27
- }
28
- return children && htmlFor ? <label {...componentProps}>{children}</label> : null
29
- }
30
-
31
- export default FieldLabel
@@ -1,5 +0,0 @@
1
- import FieldLabel from "./FieldLabel"
2
-
3
- export default FieldLabel
4
- export { FieldLabel }
5
- export * from "./FieldLabel"
@@ -1,97 +0,0 @@
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
- import Tag from "../Tag"
9
-
10
- export interface RadioButtonProps
11
- extends Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "type"> {
12
- /** **(Optional)** Specify additional CSS classes to be applied to the component. */
13
- className?: string
14
- /** **(Optional)** Specify whether the RadioButton should be disabled. Refer to Experience Library guidance on disabled form controls and accessibility. */
15
- disabled?: boolean
16
- /** **(Optional)** Specify the RadioButton error state.
17
- *
18
- * 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.
19
- */
20
- error?: FormFieldError
21
- /** **(Optional)** Specify the RadioButton hint.
22
- *
23
- * This text is rendered under the label to provide further guidance for users.
24
- */
25
- hint?: string
26
- /** **(Optional)** Specify the RadioButton id. Will be auto-generated if not set. */
27
- id?: string
28
- /** **(Optional)** Specify the RadioButton label.
29
- *
30
- * This property is optional in case you need to render your own label, but all form elements *must* provide a label. */
31
- label: string
32
- /** **(Optional)** Specify whether the label should be visible to humans or screen readers. */
33
- labelVisible?: boolean
34
- /** Specify the RadioButton name. */
35
- name: string
36
- /** **(Optional)** Specify the RadioButton size. */
37
- size?: StandardSizes
38
- /** **(Optional)** Specify the RadioButton tag text. */
39
- tag?: string
40
- /** **(Optional)** Specify the RadioButton tag className. */
41
- tagClassName?: string
42
- }
43
-
44
- export const RadioButton = ({
45
- className,
46
- disabled,
47
- error = false,
48
- hint,
49
- id,
50
- label,
51
- labelVisible = true,
52
- name,
53
- size = "md",
54
- tag,
55
- tagClassName,
56
- ...props
57
- }: RadioButtonProps): JSX.Element => {
58
- const internalId = useId()
59
-
60
- id = id ?? internalId
61
-
62
- const componentProps = {
63
- className: clsx("coop-radio-button", className),
64
- "data-error": error ? "" : undefined,
65
- "data-size": size.length && size !== "md" ? size : undefined,
66
- disabled,
67
- id,
68
- name,
69
- type: "radio",
70
- ...props,
71
- }
72
- const formItemProps = { "aria-disabled": disabled ? true : undefined }
73
- return (
74
- <div className="coop-form-item" {...formItemProps}>
75
- <div className="coop-radio-button-wrapper">
76
- <div className="coop-radio-button-input-wrapper">
77
- <input {...componentProps} />
78
-
79
- {label && (
80
- <FieldLabel htmlFor={id} isVisible={labelVisible}>
81
- <span>{label}</span>{" "}
82
- {tag && (
83
- <Tag className={tagClassName} size="sm">
84
- {tag}
85
- </Tag>
86
- )}
87
- </FieldLabel>
88
- )}
89
- </div>
90
- {hint && <FieldHint>{hint}</FieldHint>}
91
- </div>
92
- {typeof error === "object" && error?.message && <FieldError>{error.message}</FieldError>}
93
- </div>
94
- )
95
- }
96
-
97
- export default RadioButton