@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,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ButtonHTMLAttributes, ForwardRefExoticComponent, JSX, Ref } from "react";
|
|
2
2
|
import React from "react";
|
|
3
3
|
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
4
4
|
/** **(Optional)** Specify a custom element to override default `a` or `button`. */
|
|
5
|
-
as?: React.FC<
|
|
5
|
+
as?: React.FC<any> | ForwardRefExoticComponent<any> | string;
|
|
6
6
|
/** **(Optional)** Main content inside the component. It can be any valid JSX or string. */
|
|
7
7
|
children?: React.ReactNode;
|
|
8
8
|
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
@@ -18,11 +18,13 @@ export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
|
18
18
|
/** **(Optional)** Specify text to show when the Button is in a loading state. */
|
|
19
19
|
loadingText?: string;
|
|
20
20
|
/** **(Optional)** Callback to run when the button is pressed. If this is an async function, it will be awaited and the button will be in a pending state until the promise is resolved. */
|
|
21
|
-
onClick?:
|
|
21
|
+
onClick?: React.MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>;
|
|
22
|
+
/** **(Optional)** Specify a custom React ref for this component. */
|
|
23
|
+
ref?: Ref<HTMLButtonElement | HTMLAnchorElement>;
|
|
22
24
|
/** **(Optional)** Specify the Button size. */
|
|
23
25
|
size?: "sm" | "md" | "lg";
|
|
24
26
|
/** **(Optional)** Specify the Button variant. */
|
|
25
27
|
variant?: "green" | "blue" | "white" | "grey" | "green-ghost" | "blue-ghost" | "white-ghost" | "grey-ghost" | "text";
|
|
26
28
|
}
|
|
27
|
-
export declare const Button: ({ as, children, className, href, isDisabled, isFullWidth, isLoading, loadingText, onClick, size, variant, ...props }: ButtonProps) => JSX.Element;
|
|
29
|
+
export declare const Button: ({ as, children, className, href, isDisabled, isFullWidth, isLoading, loadingText, onClick, ref, size, variant, ...props }: ButtonProps) => JSX.Element;
|
|
28
30
|
export default Button;
|
|
@@ -5,11 +5,8 @@ import clsx from 'clsx';
|
|
|
5
5
|
import React, { useState, useCallback } from 'react';
|
|
6
6
|
import { LoadingIcon } from '../Icon/LoadingIcon.js';
|
|
7
7
|
|
|
8
|
-
const Button = ({ as, children, className, href, isDisabled = false, isFullWidth = false, isLoading = false, loadingText = "Loading", onClick, size = "md", variant = "green", ...props }) => {
|
|
9
|
-
|
|
10
|
-
if (as) {
|
|
11
|
-
element = as;
|
|
12
|
-
}
|
|
8
|
+
const Button = ({ as, children, className, href, isDisabled = false, isFullWidth = false, isLoading = false, loadingText = "Loading", onClick, ref, size = "md", variant = "green", ...props }) => {
|
|
9
|
+
const element = as !== null && as !== void 0 ? as : (href ? "a" : "button");
|
|
13
10
|
const [isPending, setIsPending] = useState(false);
|
|
14
11
|
const handleClick = useCallback(async (event) => {
|
|
15
12
|
if (isPending || !onClick)
|
|
@@ -31,7 +28,8 @@ const Button = ({ as, children, className, href, isDisabled = false, isFullWidth
|
|
|
31
28
|
"data-variant": variant !== "text" ? variant : undefined,
|
|
32
29
|
"data-width": isFullWidth ? "full" : undefined,
|
|
33
30
|
href,
|
|
34
|
-
onClick: handleClick,
|
|
31
|
+
onClick: onClick ? handleClick : undefined,
|
|
32
|
+
ref,
|
|
35
33
|
...props,
|
|
36
34
|
};
|
|
37
35
|
const finalChildren = isPending || isLoading ? (jsxs(Fragment, { children: [loadingText, jsx(LoadingIcon, {})] })) : (children);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { useSlots } from '../../hooks/useSlots.js';
|
|
5
5
|
import { ChevronRightIcon } from '../Icon/ChevronRightIcon.js';
|
|
6
6
|
import { Image } from '../Image/Image.js';
|
|
7
7
|
|
|
@@ -24,7 +24,7 @@ function getCardLinkElement(as, href) {
|
|
|
24
24
|
}
|
|
25
25
|
const Card = ({ chevron = false, children, className, href, hrefAs, imagePosition = "left", orientation = "vertical", ...props }) => {
|
|
26
26
|
const { element: linkElement, props: linkProps } = getCardLinkElement(hrefAs, href);
|
|
27
|
-
const slots =
|
|
27
|
+
const slots = { ...useSlots(componentSlots, children) };
|
|
28
28
|
const innerProps = { className: "coop-card--inner" };
|
|
29
29
|
const hasLinkWrapper = href && !slots.CardHeading;
|
|
30
30
|
const componentProps = {
|
|
@@ -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,7 +1,7 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { clsx } from 'clsx';
|
|
3
|
+
import { useSlots } from '../../hooks/useSlots.js';
|
|
3
4
|
import { hasUserBg, bgClassToColor } from '../../utils/index.js';
|
|
4
|
-
import { getSlots } from '../../utils/slots.js';
|
|
5
5
|
import 'react';
|
|
6
6
|
import { ChevronDownIcon } from '../Icon/ChevronDownIcon.js';
|
|
7
7
|
|
|
@@ -10,7 +10,7 @@ const componentSlots = {
|
|
|
10
10
|
ExpandableSummary: null,
|
|
11
11
|
};
|
|
12
12
|
const Expandable = ({ children, className, ...props }) => {
|
|
13
|
-
const slots =
|
|
13
|
+
const slots = useSlots(componentSlots, children);
|
|
14
14
|
const componentProps = {
|
|
15
15
|
className: clsx("coop-expandable", !hasUserBg(className) && "bg-tint-grey", className),
|
|
16
16
|
...props,
|
|
@@ -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 { useSlots } from '../../hooks/useSlots.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
|
+
Radio: null,
|
|
18
|
+
Textarea: null,
|
|
19
|
+
TextInput: null,
|
|
20
|
+
};
|
|
21
|
+
const standardFields = ["Children", "FieldError", "FieldHint", "FieldLabel"];
|
|
22
|
+
const inlineFields = ["Checkbox", "Radio"];
|
|
23
|
+
const Root = ({ boxed = false, children, className, error = false, hideErrorBar = false, ...props }) => {
|
|
24
|
+
var _a, _b, _c, _d, _e, _f;
|
|
25
|
+
const slots = { ...useSlots(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,8 +1,8 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import React from 'react';
|
|
4
|
+
import { useSlots } from '../../hooks/useSlots.js';
|
|
4
5
|
import { hasUserBg } from '../../utils/index.js';
|
|
5
|
-
import { getSlots } from '../../utils/slots.js';
|
|
6
6
|
|
|
7
7
|
const componentSlots = {
|
|
8
8
|
Children: null,
|
|
@@ -10,7 +10,7 @@ const componentSlots = {
|
|
|
10
10
|
};
|
|
11
11
|
const Pill = ({ as, children, className, href, size = "md", ...props }) => {
|
|
12
12
|
let element = href ? "a" : "span";
|
|
13
|
-
const slots =
|
|
13
|
+
const slots = useSlots(componentSlots, children);
|
|
14
14
|
if (as) {
|
|
15
15
|
element = as;
|
|
16
16
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type InputHTMLAttributes, type JSX } from "react";
|
|
2
|
+
import { StandardSizes } from "src/types";
|
|
3
|
+
export interface RadioProps 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 Radio should be disabled. Refer to Experience Library guidance on disabled form controls and accessibility. */
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
/** **(Optional)** Specify the Radio error state. */
|
|
9
|
+
error?: boolean;
|
|
10
|
+
/** **(Optional)** Specify the Radio id. Will be auto-generated if not set. */
|
|
11
|
+
id?: string;
|
|
12
|
+
/** Specify the Radio name. */
|
|
13
|
+
name: string;
|
|
14
|
+
/** **(Optional)** Specify the Radio size. */
|
|
15
|
+
size?: StandardSizes;
|
|
16
|
+
}
|
|
17
|
+
export declare const Radio: ({ className, disabled, error, id, name, size, ...props }: RadioProps) => JSX.Element;
|
|
18
|
+
export default Radio;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { useId } from 'react';
|
|
4
|
+
|
|
5
|
+
const Radio = ({ className, disabled, error = false, id, name, size = "md", ...props }) => {
|
|
6
|
+
const internalId = useId();
|
|
7
|
+
id = id !== null && id !== void 0 ? id : internalId;
|
|
8
|
+
const componentProps = {
|
|
9
|
+
className: clsx("coop-radio", className),
|
|
10
|
+
"data-error": error || undefined,
|
|
11
|
+
"data-size": size.length && size !== "md" ? size : undefined,
|
|
12
|
+
disabled,
|
|
13
|
+
id,
|
|
14
|
+
name,
|
|
15
|
+
type: "radio",
|
|
16
|
+
...props,
|
|
17
|
+
};
|
|
18
|
+
//const formItemProps = { "aria-disabled": disabled ? true : undefined }
|
|
19
|
+
return jsx("input", { ...componentProps });
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { Radio, Radio as default };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { InputHTMLAttributes, JSX } from "react";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import { StandardSizes } from "
|
|
3
|
+
import { StandardSizes } from "../../types";
|
|
4
4
|
import { type ButtonProps } from "../Button";
|
|
5
|
-
export interface
|
|
5
|
+
export interface SearchboxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "type"> {
|
|
6
6
|
/** **(Optional)** Specify a server endpoint to submit the form. Will be ignored if onSubmit is also set. */
|
|
7
7
|
action?: string;
|
|
8
8
|
/** **(Optional)** Specify props to forward to the Button element. Use `label` to set Button text. */
|
|
@@ -19,14 +19,14 @@ export interface SearchBoxProps extends Omit<InputHTMLAttributes<HTMLInputElemen
|
|
|
19
19
|
labelVisible?: boolean;
|
|
20
20
|
/** **(Optional)** Specify the TextInput name, also used as the URL search parameter. Defaults to `query`. */
|
|
21
21
|
name?: string;
|
|
22
|
-
/** **(Optional)** Callback to run when the form is submitted. If this is an async function, it will be awaited and the
|
|
22
|
+
/** **(Optional)** Callback to run when the form is submitted. If this is an async function, it will be awaited and the Searchbox will be in a pending state until the promise is resolved. */
|
|
23
23
|
onSubmit?: React.FormEventHandler<HTMLElement> | undefined;
|
|
24
24
|
/** **(Optional)** Specify the TextInput placeholder text Do not use in place of a form label. */
|
|
25
25
|
placeholder?: string;
|
|
26
|
-
/** **(Optional)** Specify the
|
|
26
|
+
/** **(Optional)** Specify the Searchbox size. */
|
|
27
27
|
size?: StandardSizes;
|
|
28
|
-
/** **(Optional)** Specify the
|
|
28
|
+
/** **(Optional)** Specify the Searchbox variant. */
|
|
29
29
|
variant?: "green" | "blue" | "white" | "grey" | "green-ghost" | "blue-ghost" | "white-ghost" | "grey-ghost";
|
|
30
30
|
}
|
|
31
|
-
export declare const
|
|
32
|
-
export default
|
|
31
|
+
export declare const Searchbox: ({ action, "aria-placeholder": ariaPlaceholder, autoCapitalize, autoComplete, button, className, id, label, labelVisible, name, onSubmit, placeholder, size, variant, ...props }: SearchboxProps) => JSX.Element;
|
|
32
|
+
export default Searchbox;
|