@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.
- package/dist/components/Button/Button.d.ts +6 -4
- package/dist/components/Button/Button.js +4 -6
- package/dist/components/Card/Card.js +2 -2
- package/dist/components/Checkbox/Checkbox.d.ts +4 -24
- package/dist/components/Checkbox/Checkbox.js +7 -14
- package/dist/components/Checkbox/index.d.ts +1 -2
- package/dist/components/Expandable/Expandable.js +2 -2
- package/dist/components/Field/Field.d.ts +44 -5
- package/dist/components/Field/Field.js +68 -5
- package/dist/components/FieldMarkers/Error.d.ts +9 -0
- package/dist/components/{FieldError/FieldError.js → FieldMarkers/Error.js} +2 -2
- package/dist/components/FieldMarkers/Hint.d.ts +9 -0
- package/dist/components/{FieldHint/FieldHint.js → FieldMarkers/Hint.js} +2 -2
- package/dist/components/FieldMarkers/Label.d.ts +11 -0
- package/dist/components/FieldMarkers/Label.js +8 -0
- package/dist/components/FieldMarkers/Legend.d.ts +11 -0
- package/dist/components/FieldMarkers/Legend.js +13 -0
- package/dist/components/Fieldset/Fieldset.d.ts +54 -0
- package/dist/components/Fieldset/Fieldset.js +44 -0
- package/dist/components/Fieldset/index.d.ts +4 -0
- package/dist/components/Pill/Pill.js +2 -2
- package/dist/components/Radio/Radio.d.ts +18 -0
- package/dist/components/Radio/Radio.js +22 -0
- package/dist/components/Radio/index.d.ts +4 -0
- package/dist/components/{SearchBox/SearchBox.d.ts → Searchbox/Searchbox.d.ts} +7 -7
- package/dist/components/{SearchBox/SearchBox.js → Searchbox/Searchbox.js} +6 -6
- package/dist/components/Searchbox/index.d.ts +4 -0
- package/dist/components/TextInput/TextInput.d.ts +5 -19
- package/dist/components/TextInput/TextInput.js +7 -11
- package/dist/components/Textarea/Textarea.d.ts +4 -18
- package/dist/components/Textarea/Textarea.js +8 -9
- package/dist/hooks/useId.d.ts +2 -0
- package/dist/hooks/useId.js +8 -0
- package/dist/{utils/slots.d.ts → hooks/useSlots.d.ts} +3 -1
- package/dist/{utils/slots.js → hooks/useSlots.js} +9 -3
- package/dist/index.d.ts +3 -5
- package/dist/index.js +4 -8
- package/package.json +10 -10
- package/src/components/Button/Button.tsx +10 -14
- package/src/components/Card/Card.tsx +2 -3
- package/src/components/Checkbox/Checkbox.tsx +8 -64
- package/src/components/Checkbox/index.ts +1 -2
- package/src/components/Expandable/Expandable.tsx +2 -2
- package/src/components/Field/Field.tsx +144 -8
- package/src/components/{FieldError/FieldError.tsx → FieldMarkers/Error.tsx} +4 -4
- package/src/components/{FieldHint/FieldHint.tsx → FieldMarkers/Hint.tsx} +5 -9
- package/src/components/FieldMarkers/Label.tsx +21 -0
- package/src/components/FieldMarkers/Legend.tsx +28 -0
- package/src/components/Fieldset/Fieldset.tsx +98 -0
- package/src/components/Fieldset/index.ts +5 -0
- package/src/components/Pill/Pill.tsx +2 -2
- package/src/components/Radio/Radio.tsx +47 -0
- package/src/components/Radio/index.ts +5 -0
- package/src/components/{SearchBox/SearchBox.tsx → Searchbox/Searchbox.tsx} +15 -13
- package/src/components/Searchbox/index.ts +5 -0
- package/src/components/TextInput/TextInput.tsx +25 -46
- package/src/components/Textarea/Textarea.tsx +12 -40
- package/src/hooks/useId.ts +9 -0
- package/src/{utils/slots.ts → hooks/useSlots.ts} +10 -2
- package/src/index.ts +3 -5
- package/dist/components/Checkbox/CheckboxGroup.d.ts +0 -32
- package/dist/components/Checkbox/CheckboxGroup.js +0 -21
- package/dist/components/FieldError/FieldError.d.ts +0 -9
- package/dist/components/FieldError/index.d.ts +0 -4
- package/dist/components/FieldHint/FieldHint.d.ts +0 -9
- package/dist/components/FieldHint/index.d.ts +0 -4
- package/dist/components/FieldLabel/FieldLabel.d.ts +0 -13
- package/dist/components/FieldLabel/FieldLabel.js +0 -13
- package/dist/components/FieldLabel/index.d.ts +0 -4
- package/dist/components/RadioButton/RadioButton.d.ts +0 -36
- package/dist/components/RadioButton/RadioButton.js +0 -26
- package/dist/components/RadioButton/RadioButtonGroup.d.ts +0 -32
- package/dist/components/RadioButton/RadioButtonGroup.js +0 -21
- package/dist/components/RadioButton/index.d.ts +0 -5
- package/dist/components/SearchBox/index.d.ts +0 -4
- package/dist/components/Tag/index.js +0 -5
- package/src/components/Checkbox/CheckboxGroup.tsx +0 -73
- package/src/components/FieldError/index.ts +0 -5
- package/src/components/FieldHint/index.ts +0 -5
- package/src/components/FieldLabel/FieldLabel.tsx +0 -31
- package/src/components/FieldLabel/index.ts +0 -5
- package/src/components/RadioButton/RadioButton.tsx +0 -97
- package/src/components/RadioButton/RadioButtonGroup.tsx +0 -73
- package/src/components/RadioButton/index.ts +0 -6
- 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 {
|
|
4
|
+
import { useState } from "react"
|
|
5
5
|
|
|
6
6
|
import { useDebounce } from "../../hooks/useDebounce"
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
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
|
|
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-
|
|
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>
|
|
@@ -12,13 +12,21 @@ export function getSlotName(node: React.ReactNode): string | false {
|
|
|
12
12
|
: false
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export function
|
|
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
|
-
|
|
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/
|
|
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/
|
|
12
|
+
export * from "./components/Radio"
|
|
15
13
|
export * from "./components/RootSVG"
|
|
16
|
-
export * from "./components/
|
|
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,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,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,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,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,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,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
|