@coopdigital/react 0.44.0 → 0.45.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/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/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/RadioButton/RadioButton.d.ts +4 -22
- package/dist/components/RadioButton/RadioButton.js +5 -9
- package/dist/components/RadioButton/index.d.ts +1 -2
- package/dist/components/SearchBox/SearchBox.js +3 -3
- package/dist/components/TextInput/TextInput.d.ts +4 -18
- 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/index.d.ts +1 -3
- package/dist/index.js +2 -6
- package/dist/utils/slots.d.ts +3 -1
- package/dist/utils/slots.js +8 -2
- package/package.json +10 -10
- package/src/components/Checkbox/Checkbox.tsx +8 -64
- package/src/components/Checkbox/index.ts +1 -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/RadioButton/RadioButton.tsx +6 -55
- package/src/components/RadioButton/index.ts +1 -2
- package/src/components/SearchBox/SearchBox.tsx +4 -2
- package/src/components/TextInput/TextInput.tsx +12 -45
- package/src/components/Textarea/Textarea.tsx +12 -40
- package/src/hooks/useId.ts +9 -0
- package/src/index.ts +1 -3
- package/src/utils/slots.ts +10 -2
- 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/RadioButtonGroup.d.ts +0 -32
- package/dist/components/RadioButton/RadioButtonGroup.js +0 -21
- 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/RadioButtonGroup.tsx +0 -73
|
@@ -1,38 +1,18 @@
|
|
|
1
1
|
import type { InputHTMLAttributes, JSX } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { StandardSizes } from "../../../src/types";
|
|
3
3
|
export interface CheckboxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "type"> {
|
|
4
4
|
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
5
5
|
className?: string;
|
|
6
6
|
/** **(Optional)** Specify whether the Checkbox should be disabled. Refer to Experience Library guidance on disabled form controls and accessibility. */
|
|
7
7
|
disabled?: boolean;
|
|
8
|
-
/** **(Optional)** Specify the Checkbox 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 Checkbox hint.
|
|
14
|
-
*
|
|
15
|
-
* This text is rendered under the label to provide further guidance for users.
|
|
16
|
-
*/
|
|
17
|
-
hint?: string;
|
|
8
|
+
/** **(Optional)** Specify the Checkbox error state. */
|
|
9
|
+
error?: boolean;
|
|
18
10
|
/** **(Optional)** Specify the Checkbox id. Will be auto-generated if not set. */
|
|
19
11
|
id?: string;
|
|
20
|
-
/** **(Optional)** Specify the Checkbox 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
12
|
/** Specify the Checkbox name. */
|
|
27
13
|
name: string;
|
|
28
14
|
/** **(Optional)** Specify the Checkbox size. */
|
|
29
15
|
size?: StandardSizes;
|
|
30
|
-
/** **(Optional)** Specify the Checkbox tag text. */
|
|
31
|
-
tag?: string;
|
|
32
|
-
/** **(Optional)** Specify the Checkbox tag className. */
|
|
33
|
-
tagClassName?: string;
|
|
34
|
-
/** **(Optional)** Specify the Checkbox variant. */
|
|
35
|
-
variant?: "default" | "boxed";
|
|
36
16
|
}
|
|
37
|
-
export declare const Checkbox: ({ className, disabled, error,
|
|
17
|
+
export declare const Checkbox: ({ className, disabled, error, id, name, size, ...props }: CheckboxProps) => JSX.Element;
|
|
38
18
|
export default Checkbox;
|
|
@@ -1,27 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
|
-
import { useId } from '
|
|
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';
|
|
3
|
+
import { useId } from '../../hooks/useId.js';
|
|
8
4
|
|
|
9
|
-
const Checkbox = ({ className, disabled, error = false,
|
|
10
|
-
const
|
|
11
|
-
id = id !== null && id !== void 0 ? id : internalId;
|
|
5
|
+
const Checkbox = ({ className, disabled, error = false, id, name, size = "md", ...props }) => {
|
|
6
|
+
const uid = useId(id);
|
|
12
7
|
const componentProps = {
|
|
13
8
|
className: clsx("coop-checkbox", className),
|
|
14
|
-
"data-error": error
|
|
9
|
+
"data-error": error || undefined,
|
|
15
10
|
"data-size": size.length && size !== "md" ? size : undefined,
|
|
16
|
-
"data-variant": variant !== "default" ? variant : undefined,
|
|
17
11
|
disabled,
|
|
18
|
-
id,
|
|
12
|
+
id: uid,
|
|
19
13
|
name,
|
|
20
14
|
type: "checkbox",
|
|
21
15
|
...props,
|
|
22
16
|
};
|
|
23
|
-
|
|
24
|
-
return (jsxs("div", { className: "coop-form-item", ...formItemProps, children: [jsxs("div", { className: "coop-checkbox-wrapper", children: [jsxs("div", { className: "coop-checkbox-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 })] }));
|
|
17
|
+
return jsx("input", { ...componentProps });
|
|
25
18
|
};
|
|
26
19
|
|
|
27
20
|
export { Checkbox, Checkbox as default };
|
|
@@ -1,9 +1,48 @@
|
|
|
1
|
-
import type { HTMLAttributes, JSX
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { HTMLAttributes, JSX } from "react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { type ErrorProps } from "../FieldMarkers/Error";
|
|
4
|
+
import { type HintProps } from "../FieldMarkers/Hint";
|
|
5
|
+
import { type LabelProps } from "../FieldMarkers/Label";
|
|
6
|
+
interface FieldProps extends HTMLAttributes<HTMLDivElement> {
|
|
7
|
+
/** **(Optional)** Specify whether the Field should render inside a box. */
|
|
8
|
+
boxed?: boolean;
|
|
9
|
+
/** Form elements inside the Field.
|
|
10
|
+
*
|
|
11
|
+
* Usually this will be a combination of `Field.Label`, `Field.Hint`, `Field.Error` and an associated control such as `TextInput` or `Checkbox`. */
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
14
|
+
classname?: string;
|
|
15
|
+
/** **(Optional)** Specify the Field error state. Use this to apply visual styling to the field control. */
|
|
16
|
+
error?: boolean;
|
|
17
|
+
/** **(Optional)** Specify whether the Field should show the left-hand error bar if it is in an error state. */
|
|
18
|
+
hideErrorBar?: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface ControlProps extends HTMLAttributes<HTMLDivElement> {
|
|
21
|
+
/** **(Optional)** Elements inside the form control. */
|
|
22
|
+
children?: string | React.ReactNode;
|
|
5
23
|
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
6
24
|
className?: string;
|
|
7
25
|
}
|
|
8
|
-
export declare const
|
|
26
|
+
export declare const FieldControl: {
|
|
27
|
+
({ children, className, ...props }: ControlProps): JSX.Element;
|
|
28
|
+
displayName: string;
|
|
29
|
+
};
|
|
30
|
+
export declare const Field: (({ boxed, children, className, error, hideErrorBar, ...props }: FieldProps) => import("react/jsx-runtime").JSX.Element) & {
|
|
31
|
+
Control: {
|
|
32
|
+
({ children, className, ...props }: ControlProps): JSX.Element;
|
|
33
|
+
displayName: string;
|
|
34
|
+
};
|
|
35
|
+
Error: {
|
|
36
|
+
(props: ErrorProps): import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
displayName: string;
|
|
38
|
+
};
|
|
39
|
+
Hint: {
|
|
40
|
+
(props: HintProps): import("react/jsx-runtime").JSX.Element;
|
|
41
|
+
displayName: string;
|
|
42
|
+
};
|
|
43
|
+
Label: {
|
|
44
|
+
(props: LabelProps): import("react/jsx-runtime").JSX.Element;
|
|
45
|
+
displayName: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
9
48
|
export default Field;
|
|
@@ -1,12 +1,75 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { useId } from '../../hooks/useId.js';
|
|
5
|
+
import { getSlots } from '../../utils/slots.js';
|
|
6
|
+
import { Error } from '../FieldMarkers/Error.js';
|
|
7
|
+
import { Hint } from '../FieldMarkers/Hint.js';
|
|
8
|
+
import { Label } from '../FieldMarkers/Label.js';
|
|
3
9
|
|
|
4
|
-
const
|
|
10
|
+
const componentSlots = {
|
|
11
|
+
Checkbox: null,
|
|
12
|
+
Children: null,
|
|
13
|
+
Control: null,
|
|
14
|
+
FieldError: null,
|
|
15
|
+
FieldHint: null,
|
|
16
|
+
FieldLabel: null,
|
|
17
|
+
RadioButton: null,
|
|
18
|
+
Textarea: null,
|
|
19
|
+
TextInput: null,
|
|
20
|
+
};
|
|
21
|
+
const standardFields = ["Children", "FieldError", "FieldHint", "FieldLabel"];
|
|
22
|
+
const inlineFields = ["Checkbox", "RadioButton"];
|
|
23
|
+
const Root = ({ boxed = false, children, className, error = false, hideErrorBar = false, ...props }) => {
|
|
24
|
+
var _a, _b, _c, _d, _e, _f;
|
|
25
|
+
const slots = getSlots(componentSlots, children);
|
|
26
|
+
const slotsArray = Object.entries(slots);
|
|
27
|
+
const uid = useId();
|
|
28
|
+
const isInlineControl = slotsArray.some((s) => s[1] !== null && inlineFields.includes(s[0]));
|
|
29
|
+
const hasFieldMarkers = !!((_b = (_a = slots.FieldLabel) !== null && _a !== void 0 ? _a : slots.FieldError) !== null && _b !== void 0 ? _b : slots.FieldHint);
|
|
30
|
+
const [, control] = (_c = slotsArray.find((s) => (!standardFields.includes(s[0]) && s[1] !== null ? s : null))) !== null && _c !== void 0 ? _c : [];
|
|
31
|
+
let controlId = uid;
|
|
32
|
+
let controlDisabled = false;
|
|
33
|
+
if (control) {
|
|
34
|
+
if (typeof control === "object" && "props" in control) {
|
|
35
|
+
const controlProps = control.props;
|
|
36
|
+
controlId = (_d = controlProps.id) !== null && _d !== void 0 ? _d : controlId;
|
|
37
|
+
controlDisabled = (_e = controlProps.disabled) !== null && _e !== void 0 ? _e : false;
|
|
38
|
+
}
|
|
39
|
+
slots.Control = React.cloneElement(control, {
|
|
40
|
+
id: controlId,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (slots.FieldLabel && React.isValidElement(slots.FieldLabel)) {
|
|
44
|
+
slots.FieldLabel = React.cloneElement(slots.FieldLabel, {
|
|
45
|
+
htmlFor: (_f = slots.FieldLabel.props.htmlFor) !== null && _f !== void 0 ? _f : controlId,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
5
48
|
const componentProps = {
|
|
6
|
-
className: clsx("coop-form-item ", className),
|
|
7
49
|
...props,
|
|
50
|
+
"aria-disabled": controlDisabled || undefined,
|
|
51
|
+
className: clsx("coop-field", isInlineControl && "coop-field-inline", className),
|
|
52
|
+
"data-boxed": boxed || undefined,
|
|
53
|
+
"data-error": error || undefined,
|
|
54
|
+
"data-hide-error": hideErrorBar || undefined,
|
|
8
55
|
};
|
|
9
|
-
return
|
|
56
|
+
return (jsxs("div", { ...componentProps, children: [!isInlineControl && hasFieldMarkers && (jsxs("div", { className: "coop-field-markers", children: [slots.FieldLabel, slots.FieldHint, slots.FieldError] })), slots.Control && (jsxs("div", { className: "coop-field-control", children: [slots.Control, isInlineControl && hasFieldMarkers && (jsxs("div", { className: "coop-field-markers", children: [slots.FieldLabel, slots.FieldHint, slots.FieldError] }))] })), slots.Children] }));
|
|
57
|
+
};
|
|
58
|
+
const FieldControl = ({ children, className, ...props }) => {
|
|
59
|
+
return (jsx("div", { className: clsx("coop-field-control ", className), ...props, children: children }));
|
|
10
60
|
};
|
|
61
|
+
FieldControl.displayName = "Field.Control";
|
|
62
|
+
const FieldLabel = (props) => jsx(Label, { ...props });
|
|
63
|
+
FieldLabel.displayName = "Field.Label";
|
|
64
|
+
const FieldHint = (props) => jsx(Hint, { ...props });
|
|
65
|
+
FieldHint.displayName = "Field.Hint";
|
|
66
|
+
const FieldError = (props) => jsx(Error, { ...props });
|
|
67
|
+
FieldError.displayName = "Field.Error";
|
|
68
|
+
const Field = Object.assign(Root, {
|
|
69
|
+
Control: FieldControl,
|
|
70
|
+
Error: FieldError,
|
|
71
|
+
Hint: FieldHint,
|
|
72
|
+
Label: FieldLabel,
|
|
73
|
+
});
|
|
11
74
|
|
|
12
|
-
export { Field, Field as default };
|
|
75
|
+
export { Field, FieldControl, Field as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HTMLAttributes, JSX, ReactNode } from "react";
|
|
2
|
+
export interface ErrorProps extends HTMLAttributes<HTMLSpanElement> {
|
|
3
|
+
/** **(Optional)** Error text for the form element. Accepts 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 Error: ({ children, className, ...props }: ErrorProps) => JSX.Element;
|
|
9
|
+
export default Error;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const Error = ({ children, className, ...props }) => {
|
|
5
5
|
const componentProps = {
|
|
6
6
|
className: clsx("coop-field-error ", className),
|
|
7
7
|
...props,
|
|
@@ -9,4 +9,4 @@ const FieldError = ({ children, className, ...props }) => {
|
|
|
9
9
|
return jsx("span", { ...componentProps, children: children });
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
export {
|
|
12
|
+
export { Error, Error as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HTMLAttributes, JSX, ReactNode } from "react";
|
|
2
|
+
export interface HintProps extends HTMLAttributes<HTMLParagraphElement> {
|
|
3
|
+
/** **(Optional)** Hint text for the form element. Accepts 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 Hint: ({ children, className, ...props }: HintProps) => JSX.Element | null;
|
|
9
|
+
export default Hint;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const Hint = ({ children, className, ...props }) => {
|
|
5
5
|
const componentProps = {
|
|
6
6
|
className: clsx("coop-field-hint ", className),
|
|
7
7
|
...props,
|
|
@@ -9,4 +9,4 @@ const FieldHint = ({ children, className, ...props }) => {
|
|
|
9
9
|
return children ? jsx("div", { ...componentProps, children: children }) : null;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
export {
|
|
12
|
+
export { Hint, Hint as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LabelHTMLAttributes } from "react";
|
|
2
|
+
export interface LabelProps extends LabelHTMLAttributes<HTMLLabelElement> {
|
|
3
|
+
/** **(Optional)** Main label for the form element. Accepts any valid JSX or string. */
|
|
4
|
+
children?: string | React.ReactNode;
|
|
5
|
+
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
6
|
+
className?: string;
|
|
7
|
+
/** **(Optional)** Specify whether the label is visible for humans or only for screen readers. */
|
|
8
|
+
isVisible?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const Label: ({ children, className, isVisible, ...props }: LabelProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export default Label;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
|
|
4
|
+
const Label = ({ children, className, isVisible = true, ...props }) => {
|
|
5
|
+
return (jsx("label", { ...props, className: clsx("coop-field-label", !isVisible && "sr-only", className), children: jsx("span", { children: children }) }));
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export { Label, Label as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { HTMLAttributes } from "react";
|
|
2
|
+
export interface LegendProps extends HTMLAttributes<HTMLLegendElement> {
|
|
3
|
+
/** **(Optional)** Main legend for the fieldset. Accepts any valid JSX or string. */
|
|
4
|
+
children?: string | React.ReactNode;
|
|
5
|
+
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
6
|
+
className?: string;
|
|
7
|
+
/** **(Optional)** Specify whether the legend should be visible to humans or screen readers. */
|
|
8
|
+
isVisible?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const Legend: ({ children, className, isVisible, ...props }: LegendProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export default Legend;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
|
|
4
|
+
const Legend = ({ children, className, isVisible = true, ...props }) => {
|
|
5
|
+
const componentProps = {
|
|
6
|
+
"aria-hidden": true,
|
|
7
|
+
className: clsx("coop-field-label", !isVisible && "sr-only", className),
|
|
8
|
+
...props,
|
|
9
|
+
};
|
|
10
|
+
return (jsxs(Fragment, { children: [jsx("legend", { className: "sr-only", children: children }), isVisible && jsx("div", { ...componentProps, children: children })] }));
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { Legend, Legend as default };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type FieldsetHTMLAttributes, type JSX } from "react";
|
|
2
|
+
import { StandardSizes } from "../../../src/types";
|
|
3
|
+
import { type ErrorProps } from "../FieldMarkers/Error";
|
|
4
|
+
import { type HintProps } from "../FieldMarkers/Hint";
|
|
5
|
+
import { type LegendProps } from "../FieldMarkers/Legend";
|
|
6
|
+
export interface FieldsetProps extends FieldsetHTMLAttributes<HTMLFieldSetElement> {
|
|
7
|
+
/** Form elements inside the Fieldset.
|
|
8
|
+
*
|
|
9
|
+
* Usually this will be a combination of `Fieldset.Legend` and `Fieldset.Fields`. */
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
12
|
+
className?: string;
|
|
13
|
+
/** **(Optional)** Specify whether the Fieldset, and all of its descendents, should be disabled. Refer to Experience Library guidance on disabled form controls and accessibility. */
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
/** **(Optional)** Specify the Fieldset error state. Use this to apply visual styling to the field control. */
|
|
16
|
+
error?: boolean;
|
|
17
|
+
/** **(Optional)** Specify whether the Fieldset should show the left-hand error bar if it is in an error state. */
|
|
18
|
+
hideErrorBar?: boolean;
|
|
19
|
+
/** **(Optional)** Specify the size of the Fieldset and all its descendents. */
|
|
20
|
+
size?: StandardSizes;
|
|
21
|
+
}
|
|
22
|
+
interface FieldsetFieldsProps {
|
|
23
|
+
/** **(Optional)** Specify whether all descendent Fields should render inside a box. */
|
|
24
|
+
boxed?: boolean;
|
|
25
|
+
/** **(Optional)** Form elements inside the Fieldset.Fields container. */
|
|
26
|
+
children?: string | React.ReactNode;
|
|
27
|
+
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
28
|
+
className?: string;
|
|
29
|
+
/** **(Optional)** Specify the CheckboxGroup orientation. */
|
|
30
|
+
orientation?: "horizontal" | "vertical";
|
|
31
|
+
}
|
|
32
|
+
export declare const FieldsetFields: {
|
|
33
|
+
({ boxed, children, className, orientation, ...props }: FieldsetFieldsProps): JSX.Element;
|
|
34
|
+
displayName: string;
|
|
35
|
+
};
|
|
36
|
+
export declare const Fieldset: (({ children, className, disabled, error, hideErrorBar, size, ...props }: FieldsetProps) => JSX.Element) & {
|
|
37
|
+
Error: {
|
|
38
|
+
(props: ErrorProps): import("react/jsx-runtime").JSX.Element;
|
|
39
|
+
displayName: string;
|
|
40
|
+
};
|
|
41
|
+
Fields: {
|
|
42
|
+
({ boxed, children, className, orientation, ...props }: FieldsetFieldsProps): JSX.Element;
|
|
43
|
+
displayName: string;
|
|
44
|
+
};
|
|
45
|
+
Hint: {
|
|
46
|
+
(props: HintProps): import("react/jsx-runtime").JSX.Element;
|
|
47
|
+
displayName: string;
|
|
48
|
+
};
|
|
49
|
+
Legend: {
|
|
50
|
+
(props: LegendProps): import("react/jsx-runtime").JSX.Element;
|
|
51
|
+
displayName: string;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export default Fieldset;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { Error } from '../FieldMarkers/Error.js';
|
|
4
|
+
import { Hint } from '../FieldMarkers/Hint.js';
|
|
5
|
+
import { Legend } from '../FieldMarkers/Legend.js';
|
|
6
|
+
|
|
7
|
+
const Root = ({ children, className, disabled, error = false, hideErrorBar = false, size = "md", ...props }) => {
|
|
8
|
+
const componentProps = {
|
|
9
|
+
"aria-disabled": disabled,
|
|
10
|
+
className: clsx("coop-fieldset", className),
|
|
11
|
+
"data-error": error || undefined,
|
|
12
|
+
//"data-variant": variant !== "default" ? variant : undefined,
|
|
13
|
+
"data-hide-error": hideErrorBar || undefined,
|
|
14
|
+
// "data-orientation": orientation !== "vertical" ? orientation : undefined,
|
|
15
|
+
"data-size": size.length && size !== "md" ? size : undefined,
|
|
16
|
+
disabled,
|
|
17
|
+
...props,
|
|
18
|
+
};
|
|
19
|
+
return jsx("fieldset", { ...componentProps, children: children });
|
|
20
|
+
};
|
|
21
|
+
const FieldsetFields = ({ boxed = false, children, className, orientation = "vertical", ...props }) => {
|
|
22
|
+
const componentProps = {
|
|
23
|
+
className: clsx("coop-fieldset-fields", className),
|
|
24
|
+
"data-boxed": boxed || undefined,
|
|
25
|
+
"data-orientation": orientation !== "vertical" ? orientation : undefined,
|
|
26
|
+
...props,
|
|
27
|
+
};
|
|
28
|
+
return jsx("div", { ...componentProps, children: children });
|
|
29
|
+
};
|
|
30
|
+
FieldsetFields.displayName = "Fieldset.Fields";
|
|
31
|
+
const FieldsetLegend = (props) => jsx(Legend, { ...props });
|
|
32
|
+
FieldsetLegend.displayName = "Fieldset.Legend";
|
|
33
|
+
const FieldsetHint = (props) => jsx(Hint, { ...props });
|
|
34
|
+
FieldsetHint.displayName = "Fieldset.Hint";
|
|
35
|
+
const FieldsetError = (props) => jsx(Error, { ...props });
|
|
36
|
+
FieldsetError.displayName = "Fieldset.Error";
|
|
37
|
+
const Fieldset = Object.assign(Root, {
|
|
38
|
+
Error: FieldsetError,
|
|
39
|
+
Fields: FieldsetFields,
|
|
40
|
+
Hint: FieldsetHint,
|
|
41
|
+
Legend: FieldsetLegend,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export { Fieldset, FieldsetFields, Fieldset as default };
|
|
@@ -1,36 +1,18 @@
|
|
|
1
1
|
import { type InputHTMLAttributes, type JSX } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { StandardSizes } from "src/types";
|
|
3
3
|
export interface RadioButtonProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "type"> {
|
|
4
4
|
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
5
5
|
className?: string;
|
|
6
6
|
/** **(Optional)** Specify whether the RadioButton should be disabled. Refer to Experience Library guidance on disabled form controls and accessibility. */
|
|
7
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;
|
|
8
|
+
/** **(Optional)** Specify the RadioButton error state. */
|
|
9
|
+
error?: boolean;
|
|
18
10
|
/** **(Optional)** Specify the RadioButton id. Will be auto-generated if not set. */
|
|
19
11
|
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
12
|
/** Specify the RadioButton name. */
|
|
27
13
|
name: string;
|
|
28
14
|
/** **(Optional)** Specify the RadioButton size. */
|
|
29
15
|
size?: StandardSizes;
|
|
30
|
-
/** **(Optional)** Specify the RadioButton tag text. */
|
|
31
|
-
tag?: string;
|
|
32
|
-
/** **(Optional)** Specify the RadioButton tag className. */
|
|
33
|
-
tagClassName?: string;
|
|
34
16
|
}
|
|
35
|
-
export declare const RadioButton: ({ className, disabled, error,
|
|
17
|
+
export declare const RadioButton: ({ className, disabled, error, id, name, size, ...props }: RadioButtonProps) => JSX.Element;
|
|
36
18
|
export default RadioButton;
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
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
4
|
|
|
9
|
-
const RadioButton = ({ className, disabled, error = false,
|
|
5
|
+
const RadioButton = ({ className, disabled, error = false, id, name, size = "md", ...props }) => {
|
|
10
6
|
const internalId = useId();
|
|
11
7
|
id = id !== null && id !== void 0 ? id : internalId;
|
|
12
8
|
const componentProps = {
|
|
13
9
|
className: clsx("coop-radio-button", className),
|
|
14
|
-
"data-error": error
|
|
10
|
+
"data-error": error || undefined,
|
|
15
11
|
"data-size": size.length && size !== "md" ? size : undefined,
|
|
16
12
|
disabled,
|
|
17
13
|
id,
|
|
@@ -19,8 +15,8 @@ const RadioButton = ({ className, disabled, error = false, hint, id, label, labe
|
|
|
19
15
|
type: "radio",
|
|
20
16
|
...props,
|
|
21
17
|
};
|
|
22
|
-
const formItemProps = { "aria-disabled": disabled ? true : undefined }
|
|
23
|
-
return
|
|
18
|
+
//const formItemProps = { "aria-disabled": disabled ? true : undefined }
|
|
19
|
+
return jsx("input", { ...componentProps });
|
|
24
20
|
};
|
|
25
21
|
|
|
26
22
|
export { RadioButton, RadioButton as default };
|
|
@@ -4,7 +4,7 @@ import { jsxs, jsx } from 'react/jsx-runtime';
|
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
import React, { useState, useId, useCallback } from 'react';
|
|
6
6
|
import { Button } from '../Button/Button.js';
|
|
7
|
-
import {
|
|
7
|
+
import { Label } from '../FieldMarkers/Label.js';
|
|
8
8
|
import { SearchIcon } from '../Icon/SearchIcon.js';
|
|
9
9
|
import { TextInput } from '../TextInput/TextInput.js';
|
|
10
10
|
|
|
@@ -32,7 +32,7 @@ const SearchBox = ({ action, "aria-placeholder": ariaPlaceholder, autoCapitalize
|
|
|
32
32
|
const formProps = {
|
|
33
33
|
action: action !== null && action !== void 0 ? action : undefined,
|
|
34
34
|
className: clsx("coop-search-box", className),
|
|
35
|
-
|
|
35
|
+
"data-size": size && size !== "md" ? size : undefined,
|
|
36
36
|
"data-variant": variant.length && variant !== "green" ? variant : undefined,
|
|
37
37
|
onSubmit: onSubmit ? handleSubmit : undefined,
|
|
38
38
|
};
|
|
@@ -54,7 +54,7 @@ const SearchBox = ({ action, "aria-placeholder": ariaPlaceholder, autoCapitalize
|
|
|
54
54
|
type: "search",
|
|
55
55
|
...props,
|
|
56
56
|
};
|
|
57
|
-
return (jsxs("form", { ...formProps, children: [label && (jsx(
|
|
57
|
+
return (jsxs("form", { ...formProps, children: [label && (jsx(Label, { htmlFor: id, isVisible: labelVisible, children: label })), jsxs("div", { className: "coop-search-box--inner", children: [jsx(TextInput, { ...inputProps }), jsx(Button, { ...buttonProps, children: button.label })] })] }));
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
export { SearchBox, SearchBox as default };
|
|
@@ -1,28 +1,14 @@
|
|
|
1
1
|
import type { InputHTMLAttributes, JSX } from "react";
|
|
2
|
-
import {
|
|
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. */
|
|
5
5
|
className?: string;
|
|
6
6
|
/** **(Optional)** Specify whether the TextInput should be disabled. Refer to Experience Library guidance on disabled form controls and accessibility. */
|
|
7
7
|
disabled?: boolean;
|
|
8
|
-
/** **(Optional)** Specify the TextInput 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 TextInput hint.
|
|
14
|
-
*
|
|
15
|
-
* This text is rendered under the label to provide further guidance for users.
|
|
16
|
-
*/
|
|
17
|
-
hint?: string;
|
|
8
|
+
/** **(Optional)** Specify the TextInput error state. */
|
|
9
|
+
error?: boolean;
|
|
18
10
|
/** **(Optional)** Specify the TextInput id. Will be auto-generated if not set. */
|
|
19
11
|
id?: string;
|
|
20
|
-
/** **(Optional)** Specify the TextInput 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
12
|
/** Specify the TextInput name. */
|
|
27
13
|
name: string;
|
|
28
14
|
/** **(Optional)** Specify the TextInput placeholder text. Do not use in place of a form label. */
|
|
@@ -36,5 +22,5 @@ export interface TextInputProps extends Omit<InputHTMLAttributes<HTMLInputElemen
|
|
|
36
22
|
/** **(Optional)** Specify the TextInput type. */
|
|
37
23
|
type?: "text" | "email" | "number" | "password" | "search" | "tel" | "url";
|
|
38
24
|
}
|
|
39
|
-
export declare const TextInput: ({ "aria-placeholder": ariaPlaceholder, className, disabled, error,
|
|
25
|
+
export declare const TextInput: ({ "aria-placeholder": ariaPlaceholder, className, disabled, error, id, name, placeholder, prefix, size, suffix, type, ...props }: TextInputProps) => JSX.Element;
|
|
40
26
|
export default TextInput;
|
|
@@ -1,28 +1,24 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
|
-
import { useId } from '
|
|
4
|
-
import { FieldError } from '../FieldError/FieldError.js';
|
|
5
|
-
import { FieldHint } from '../FieldHint/FieldHint.js';
|
|
6
|
-
import { FieldLabel } from '../FieldLabel/FieldLabel.js';
|
|
3
|
+
import { useId } from '../../hooks/useId.js';
|
|
7
4
|
|
|
8
|
-
const TextInput = ({ "aria-placeholder": ariaPlaceholder, className, disabled, error = false,
|
|
5
|
+
const TextInput = ({ "aria-placeholder": ariaPlaceholder, className, disabled, error = false, id, name, placeholder, prefix, size = "md", suffix, type = "text", ...props }) => {
|
|
9
6
|
var _a;
|
|
10
|
-
const
|
|
11
|
-
id = id !== null && id !== void 0 ? id : internalId;
|
|
7
|
+
const uid = useId(id);
|
|
12
8
|
const componentProps = {
|
|
13
9
|
"aria-placeholder": (_a = placeholder !== null && placeholder !== void 0 ? placeholder : ariaPlaceholder) !== null && _a !== void 0 ? _a : undefined,
|
|
14
10
|
className: clsx("coop-text-input", className),
|
|
15
|
-
"data-error": error
|
|
11
|
+
"data-error": error || undefined,
|
|
16
12
|
"data-size": size.length && size !== "md" ? size : undefined,
|
|
17
13
|
disabled,
|
|
18
|
-
id,
|
|
14
|
+
id: uid,
|
|
19
15
|
name,
|
|
20
16
|
placeholder,
|
|
21
17
|
type,
|
|
22
18
|
...props,
|
|
23
19
|
};
|
|
24
|
-
const formItemProps = { "aria-disabled": disabled ? true : undefined }
|
|
25
|
-
return (jsxs("div", { className: "coop-
|
|
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 })] }));
|
|
26
22
|
};
|
|
27
23
|
|
|
28
24
|
export { TextInput, TextInput as default };
|