@coopdigital/react 0.41.1 → 0.43.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/Card/Card.d.ts +2 -7
- package/dist/components/Card/Card.js +4 -5
- package/dist/components/Checkbox/Checkbox.d.ts +3 -4
- package/dist/components/Checkbox/Checkbox.js +2 -2
- package/dist/components/Expandable/Expandable.d.ts +14 -7
- package/dist/components/Expandable/Expandable.js +18 -4
- package/dist/components/Flourish/Flourish.d.ts +2 -2
- package/dist/components/Flourish/Flourish.js +2 -2
- package/dist/components/Pill/Pill.d.ts +15 -10
- package/dist/components/Pill/Pill.js +16 -6
- package/dist/components/RadioButton/RadioButton.d.ts +3 -4
- package/dist/components/RadioButton/RadioButton.js +2 -2
- package/dist/components/Squircle/Squircle.d.ts +1 -4
- package/dist/components/Squircle/Squircle.js +3 -3
- package/dist/components/Tag/Tag.d.ts +1 -4
- package/dist/components/Tag/Tag.js +3 -3
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +14 -2
- package/package.json +3 -3
- package/src/components/Card/Card.tsx +3 -20
- package/src/components/Checkbox/Checkbox.tsx +5 -5
- package/src/components/Expandable/Expandable.tsx +45 -26
- package/src/components/Flourish/Flourish.tsx +4 -4
- package/src/components/Pill/Pill.tsx +31 -22
- package/src/components/RadioButton/RadioButton.tsx +5 -5
- package/src/components/Squircle/Squircle.tsx +2 -7
- package/src/components/Tag/Tag.tsx +2 -7
- package/src/utils/index.ts +15 -0
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import type { ForwardRefExoticComponent, HTMLAttributes, JSX } from "react";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import { Lights, Tints, White } from "../../types/colors";
|
|
4
3
|
import { ImageProps } from "../Image";
|
|
5
4
|
export interface CardProps extends HTMLAttributes<HTMLDivElement> {
|
|
6
|
-
/** **(Optional)** Specify the Card background color. */
|
|
7
|
-
background?: Tints | White;
|
|
8
5
|
/** **(Optional)** Specify whether chevron is visible. */
|
|
9
6
|
chevron?: boolean;
|
|
10
7
|
/** **(Optional)** Content inside the component. Children that are not assigned to a slot will be grouped together and rendered under the main Card content. */
|
|
@@ -21,8 +18,6 @@ export interface CardProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
21
18
|
orientation?: "vertical" | "horizontal";
|
|
22
19
|
}
|
|
23
20
|
interface CardLabelProps extends HTMLAttributes<HTMLSpanElement> {
|
|
24
|
-
/** **(Optional)** Specify the Label background color. */
|
|
25
|
-
background?: Lights;
|
|
26
21
|
/** **(Optional)** Content inside the Label. */
|
|
27
22
|
children?: React.ReactNode;
|
|
28
23
|
/** **(Optional)** Specify additional CSS classes to be applied to the Label. */
|
|
@@ -52,9 +47,9 @@ interface CardBadgeProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
52
47
|
}
|
|
53
48
|
type CardImageProps = ImageProps;
|
|
54
49
|
export declare const Card: {
|
|
55
|
-
({
|
|
50
|
+
({ chevron, children, className, href, hrefAs, imagePosition, orientation, ...props }: CardProps): JSX.Element;
|
|
56
51
|
Label: {
|
|
57
|
-
({
|
|
52
|
+
({ children, className }: CardLabelProps): JSX.Element;
|
|
58
53
|
displayName: string;
|
|
59
54
|
};
|
|
60
55
|
Heading: {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import { bgPropToClass } from '../../utils/index.js';
|
|
5
4
|
import { getSlots } from '../../utils/slots.js';
|
|
6
5
|
import { ChevronRightIcon } from '../Icon/ChevronRightIcon.js';
|
|
7
6
|
import { Image } from '../Image/Image.js';
|
|
@@ -23,13 +22,13 @@ function getCardLinkElement(as, href) {
|
|
|
23
22
|
},
|
|
24
23
|
};
|
|
25
24
|
}
|
|
26
|
-
const Card = ({
|
|
25
|
+
const Card = ({ chevron = false, children, className, href, hrefAs, imagePosition = "left", orientation = "vertical", ...props }) => {
|
|
27
26
|
const { element: linkElement, props: linkProps } = getCardLinkElement(hrefAs, href);
|
|
28
27
|
const slots = getSlots(componentSlots, children);
|
|
29
28
|
const innerProps = { className: "coop-card--inner" };
|
|
30
29
|
const hasLinkWrapper = href && !slots.CardHeading;
|
|
31
30
|
const componentProps = {
|
|
32
|
-
className: clsx("coop-card",
|
|
31
|
+
className: clsx("coop-card", className),
|
|
33
32
|
"data-image-pos": imagePosition,
|
|
34
33
|
"data-orientation": orientation !== "vertical" ? orientation : undefined,
|
|
35
34
|
...props,
|
|
@@ -43,8 +42,8 @@ const CardHeading = ({ as = "h3", children, className }) => {
|
|
|
43
42
|
return React.createElement(as, { className: clsx("coop-card--heading", className) }, children);
|
|
44
43
|
};
|
|
45
44
|
CardHeading.displayName = "Card.Heading";
|
|
46
|
-
const CardLabel = ({
|
|
47
|
-
return
|
|
45
|
+
const CardLabel = ({ children, className }) => {
|
|
46
|
+
return jsx("span", { className: clsx("coop-card--label", className), children: children });
|
|
48
47
|
};
|
|
49
48
|
CardLabel.displayName = "Card.Label";
|
|
50
49
|
const CardBadge = ({ align = "right", children, position = "popout", ...props }) => {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { InputHTMLAttributes, JSX } from "react";
|
|
2
2
|
import { FormFieldError, StandardSizes } from "../../../src/types";
|
|
3
|
-
import { TagProps } from "../Tag";
|
|
4
3
|
export interface CheckboxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "type"> {
|
|
5
4
|
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
6
5
|
className?: string;
|
|
@@ -30,10 +29,10 @@ export interface CheckboxProps extends Omit<InputHTMLAttributes<HTMLInputElement
|
|
|
30
29
|
size?: StandardSizes;
|
|
31
30
|
/** **(Optional)** Specify the Checkbox tag text. */
|
|
32
31
|
tag?: string;
|
|
33
|
-
/** **(Optional)** Specify the Checkbox tag
|
|
34
|
-
|
|
32
|
+
/** **(Optional)** Specify the Checkbox tag className. */
|
|
33
|
+
tagClassName?: string;
|
|
35
34
|
/** **(Optional)** Specify the Checkbox variant. */
|
|
36
35
|
variant?: "default" | "boxed";
|
|
37
36
|
}
|
|
38
|
-
export declare const Checkbox: ({ className, disabled, error, hint, id, label, labelVisible, name, size, tag,
|
|
37
|
+
export declare const Checkbox: ({ className, disabled, error, hint, id, label, labelVisible, name, size, tag, tagClassName, variant, ...props }: CheckboxProps) => JSX.Element;
|
|
39
38
|
export default Checkbox;
|
|
@@ -6,7 +6,7 @@ import { FieldHint } from '../FieldHint/FieldHint.js';
|
|
|
6
6
|
import { FieldLabel } from '../FieldLabel/FieldLabel.js';
|
|
7
7
|
import { Tag } from '../Tag/Tag.js';
|
|
8
8
|
|
|
9
|
-
const Checkbox = ({ className, disabled, error = false, hint, id, label, labelVisible = true, name, size = "md", tag,
|
|
9
|
+
const Checkbox = ({ className, disabled, error = false, hint, id, label, labelVisible = true, name, size = "md", tag, tagClassName, variant = "default", ...props }) => {
|
|
10
10
|
const internalId = useId();
|
|
11
11
|
id = id !== null && id !== void 0 ? id : internalId;
|
|
12
12
|
const componentProps = {
|
|
@@ -21,7 +21,7 @@ const Checkbox = ({ className, disabled, error = false, hint, id, label, labelVi
|
|
|
21
21
|
...props,
|
|
22
22
|
};
|
|
23
23
|
const formItemProps = { "aria-disabled": disabled ? true : undefined };
|
|
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, {
|
|
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 })] }));
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
export { Checkbox, Checkbox as default };
|
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
import type { DetailsHTMLAttributes, JSX } from "react";
|
|
2
|
-
import { None, Tints, White } from "../../types/colors";
|
|
1
|
+
import type { DetailsHTMLAttributes, HTMLAttributes, JSX } from "react";
|
|
3
2
|
export interface ExpandableProps extends DetailsHTMLAttributes<HTMLDetailsElement> {
|
|
4
|
-
/** **(Optional)** Specify the Expandable background color. */
|
|
5
|
-
background?: Tints | White | None;
|
|
6
3
|
/** Main content inside the component, only visible when it is open. It can be any valid JSX or string. */
|
|
7
4
|
children: React.ReactNode;
|
|
8
5
|
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
9
6
|
className?: string;
|
|
10
|
-
/** Specify the summary text to show when the Expandable is not open. */
|
|
11
|
-
summary: React.ReactNode;
|
|
12
7
|
}
|
|
13
|
-
|
|
8
|
+
interface ExpandableSummaryProps extends HTMLAttributes<HTMLElement> {
|
|
9
|
+
/** **(Optional)** Content inside the Summary. */
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
/** **(Optional)** Specify additional CSS classes to be applied to the Summary. */
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const Expandable: {
|
|
15
|
+
({ children, className, ...props }: ExpandableProps): JSX.Element;
|
|
16
|
+
Summary: {
|
|
17
|
+
({ children, className, ...props }: ExpandableSummaryProps): import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
displayName: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
14
21
|
export default Expandable;
|
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { clsx } from 'clsx';
|
|
3
|
-
import {
|
|
3
|
+
import { hasUserBg, bgClassToColor } from '../../utils/index.js';
|
|
4
|
+
import { getSlots } from '../../utils/slots.js';
|
|
4
5
|
import 'react';
|
|
5
6
|
import { ChevronDownIcon } from '../Icon/ChevronDownIcon.js';
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
+
const componentSlots = {
|
|
9
|
+
Children: null,
|
|
10
|
+
ExpandableSummary: null,
|
|
11
|
+
};
|
|
12
|
+
const Expandable = ({ children, className, ...props }) => {
|
|
13
|
+
const slots = getSlots(componentSlots, children);
|
|
8
14
|
const componentProps = {
|
|
9
|
-
className: clsx("coop-expandable",
|
|
15
|
+
className: clsx("coop-expandable", !hasUserBg(className) && "bg-tint-grey", className),
|
|
10
16
|
...props,
|
|
11
17
|
};
|
|
12
|
-
|
|
18
|
+
componentProps.style = {
|
|
19
|
+
"--bg": `var(--color-${bgClassToColor(componentProps.className)})`,
|
|
20
|
+
};
|
|
21
|
+
return (jsxs("details", { ...componentProps, children: [slots.ExpandableSummary, jsx("div", { className: "coop-expandable--content", children: slots.Children })] }));
|
|
22
|
+
};
|
|
23
|
+
const ExpandableSummary = ({ children, className, ...props }) => {
|
|
24
|
+
return (jsxs("summary", { ...props, className: className, children: [children, jsx(ChevronDownIcon, { className: "coop-expandable--icon", stroke: "currentColor", strokeWidth: 2, width: "12" })] }));
|
|
13
25
|
};
|
|
26
|
+
ExpandableSummary.displayName = "Expandable.Summary";
|
|
27
|
+
Expandable.Summary = ExpandableSummary;
|
|
14
28
|
|
|
15
29
|
export { Expandable, Expandable as default };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { JSX, ReactNode, SVGProps } from "react";
|
|
2
|
-
import { BrandBlue, Darks, Lights, OfferRed } from "../../types/colors";
|
|
2
|
+
import { Black, BrandBlue, Darks, Lights, OfferRed, Tints, White } from "../../types/colors";
|
|
3
3
|
export interface FlourishProps extends SVGProps<SVGSVGElement> {
|
|
4
4
|
/** Specify the text to be highlighted by the Flourish. */
|
|
5
5
|
children: string | ReactNode;
|
|
6
6
|
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
7
7
|
className?: string;
|
|
8
8
|
/** **(Optional)** Specify the Flourish color. */
|
|
9
|
-
fill?: Darks | Lights | OfferRed | BrandBlue;
|
|
9
|
+
fill?: Darks | Lights | Tints | OfferRed | BrandBlue | White | Black;
|
|
10
10
|
}
|
|
11
11
|
export declare const Flourish: ({ children, className, fill, ...props }: FlourishProps) => JSX.Element;
|
|
12
12
|
export default Flourish;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
|
|
4
|
-
const Flourish = ({ children, className, fill = "
|
|
4
|
+
const Flourish = ({ children, className, fill = "brand-blue", ...props }) => {
|
|
5
5
|
const componentProps = {
|
|
6
6
|
className: clsx("coop-flourish ", className),
|
|
7
7
|
fill: `var(--color-${fill})`,
|
|
8
8
|
...props,
|
|
9
9
|
};
|
|
10
|
-
return (jsxs("span", { style: { position: "relative" }, children: [children, jsx("svg", { ...componentProps,
|
|
10
|
+
return (jsxs("span", { style: { position: "relative" }, children: [children, jsx("svg", { ...componentProps, viewBox: "0 0 276 10", children: jsx("path", { d: "M275.9 8.6c.1-1.6.2-1.8-.4-2.9.3-1-.3-1.2-1.8-1.1v-.3c.6-.4.2-.2 1.4-.1-.9-2.3-5.6-1.8-8.5-2.3C259 .5 246.3.7 237.4.5L185 .4l-33-.2-26.1-.2-67.4 1.2-44.3.5C10.7 2.1 1.5.4 0 3.3l1 .2L0 4v.5C8.2 7.9 26.6 7.2 35.6 7c5 0 13.5 1.6 16.5-.6C53.4 8 59.5 8 62 7.7l45 .1 42.8.3 30.7.3 44.2.6 27.8-.5 23 .8c.1-.8-.3-.5.5-.7ZM219 2.8v-.2l.8-.2h.4l.3.4H219Zm30-.1h1.2c-.8.4-.5.3-1.2 0Zm6.2.6.2-.4h.3l-.5.4Z" }) })] }));
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export { Flourish, Flourish as default };
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ForwardRefExoticComponent, HTMLAttributes, JSX } from "react";
|
|
2
2
|
import React from "react";
|
|
3
3
|
import { StandardSizes } from "src/types";
|
|
4
|
-
import { Darks, OfferRed, Tints } from "../../types/colors";
|
|
5
4
|
export interface PillProps extends HTMLAttributes<HTMLAnchorElement> {
|
|
6
5
|
/** **(Optional)** Specify a custom element to override default `a` or `span`. */
|
|
7
|
-
as?: React.FC<
|
|
8
|
-
/** **(Optional)** Specify the Pill background color. */
|
|
9
|
-
background?: Tints;
|
|
10
|
-
/** **(Optional)** Specify text to display inside the badge. */
|
|
11
|
-
badge?: string;
|
|
12
|
-
/** **(Optional)** Specify the badge background color. */
|
|
13
|
-
badgeBackground?: Darks | OfferRed;
|
|
6
|
+
as?: React.FC<any> | ForwardRefExoticComponent<any> | string;
|
|
14
7
|
/** **(Optional)** Main content inside the component. It can be any valid JSX or string. */
|
|
15
8
|
children?: React.ReactNode;
|
|
16
9
|
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
@@ -20,5 +13,17 @@ export interface PillProps extends HTMLAttributes<HTMLAnchorElement> {
|
|
|
20
13
|
/** **(Optional)** Specify the Pill size. */
|
|
21
14
|
size?: StandardSizes;
|
|
22
15
|
}
|
|
23
|
-
|
|
16
|
+
interface PillBadgeProps extends HTMLAttributes<HTMLSpanElement> {
|
|
17
|
+
/** **(Optional)** Content inside the Badge. */
|
|
18
|
+
children?: React.ReactNode;
|
|
19
|
+
/** **(Optional)** Specify additional CSS classes to be applied to the Badge. */
|
|
20
|
+
className?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const Pill: {
|
|
23
|
+
({ as, children, className, href, size, ...props }: PillProps): JSX.Element;
|
|
24
|
+
Badge: {
|
|
25
|
+
({ children, className }: PillBadgeProps): import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
displayName: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
24
29
|
export default Pill;
|
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { hasUserBg } from '../../utils/index.js';
|
|
5
|
+
import { getSlots } from '../../utils/slots.js';
|
|
5
6
|
|
|
6
|
-
const
|
|
7
|
+
const componentSlots = {
|
|
8
|
+
Children: null,
|
|
9
|
+
PillBadge: null,
|
|
10
|
+
};
|
|
11
|
+
const Pill = ({ as, children, className, href, size = "md", ...props }) => {
|
|
7
12
|
let element = href ? "a" : "span";
|
|
13
|
+
const slots = getSlots(componentSlots, children);
|
|
8
14
|
if (as) {
|
|
9
15
|
element = as;
|
|
10
16
|
}
|
|
11
17
|
const componentProps = {
|
|
12
|
-
className: clsx("coop-pill",
|
|
18
|
+
className: clsx("coop-pill", !hasUserBg(className) && "bg-tint-grey", className),
|
|
13
19
|
"data-size": size.length && size !== "md" ? size : undefined,
|
|
14
20
|
href,
|
|
15
21
|
...props,
|
|
16
22
|
};
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
return React.createElement(element, { ...componentProps }, slots.PillBadge, slots.Children);
|
|
24
|
+
};
|
|
25
|
+
const PillBadge = ({ children, className }) => {
|
|
26
|
+
return (jsx("span", { className: clsx("coop-pill--badge", !hasUserBg(className) && "bg-offer-red", className), children: children }));
|
|
19
27
|
};
|
|
28
|
+
PillBadge.displayName = "Pill.Badge";
|
|
29
|
+
Pill.Badge = PillBadge;
|
|
20
30
|
|
|
21
31
|
export { Pill, Pill as default };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type InputHTMLAttributes, type JSX } from "react";
|
|
2
2
|
import { FormFieldError, StandardSizes } from "src/types";
|
|
3
|
-
import { TagProps } from "../Tag";
|
|
4
3
|
export interface RadioButtonProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "type"> {
|
|
5
4
|
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
6
5
|
className?: string;
|
|
@@ -30,8 +29,8 @@ export interface RadioButtonProps extends Omit<InputHTMLAttributes<HTMLInputElem
|
|
|
30
29
|
size?: StandardSizes;
|
|
31
30
|
/** **(Optional)** Specify the RadioButton tag text. */
|
|
32
31
|
tag?: string;
|
|
33
|
-
/** **(Optional)** Specify the RadioButton tag
|
|
34
|
-
|
|
32
|
+
/** **(Optional)** Specify the RadioButton tag className. */
|
|
33
|
+
tagClassName?: string;
|
|
35
34
|
}
|
|
36
|
-
export declare const RadioButton: ({ className, disabled, error, hint, id, label, labelVisible, name, size, tag,
|
|
35
|
+
export declare const RadioButton: ({ className, disabled, error, hint, id, label, labelVisible, name, size, tag, tagClassName, ...props }: RadioButtonProps) => JSX.Element;
|
|
37
36
|
export default RadioButton;
|
|
@@ -6,7 +6,7 @@ import { FieldHint } from '../FieldHint/FieldHint.js';
|
|
|
6
6
|
import { FieldLabel } from '../FieldLabel/FieldLabel.js';
|
|
7
7
|
import { Tag } from '../Tag/Tag.js';
|
|
8
8
|
|
|
9
|
-
const RadioButton = ({ className, disabled, error = false, hint, id, label, labelVisible = true, name, size = "md", tag,
|
|
9
|
+
const RadioButton = ({ className, disabled, error = false, hint, id, label, labelVisible = true, name, size = "md", tag, tagClassName, ...props }) => {
|
|
10
10
|
const internalId = useId();
|
|
11
11
|
id = id !== null && id !== void 0 ? id : internalId;
|
|
12
12
|
const componentProps = {
|
|
@@ -20,7 +20,7 @@ const RadioButton = ({ className, disabled, error = false, hint, id, label, labe
|
|
|
20
20
|
...props,
|
|
21
21
|
};
|
|
22
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, {
|
|
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
24
|
};
|
|
25
25
|
|
|
26
26
|
export { RadioButton, RadioButton as default };
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { HTMLAttributes, JSX } from "react";
|
|
2
|
-
import { BrandBlue, Green, OfferRed } from "../../types/colors";
|
|
3
2
|
export interface SquircleProps extends HTMLAttributes<HTMLDivElement> {
|
|
4
|
-
/** **(Optional)** Specify the Squircle background color. */
|
|
5
|
-
background?: OfferRed | BrandBlue | Green;
|
|
6
3
|
/** **(Optional)** Main content inside the component. It can be any valid JSX or string. */
|
|
7
4
|
children?: React.ReactNode;
|
|
8
5
|
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
@@ -10,5 +7,5 @@ export interface SquircleProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
10
7
|
/** **(Optional)** Specify the Squircle size. */
|
|
11
8
|
size?: "sm" | "md" | "lg";
|
|
12
9
|
}
|
|
13
|
-
export declare const Squircle: ({
|
|
10
|
+
export declare const Squircle: ({ children, className, size, ...props }: SquircleProps) => JSX.Element;
|
|
14
11
|
export default Squircle;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
|
-
import {
|
|
3
|
+
import { hasUserBg } from '../../utils/index.js';
|
|
4
4
|
|
|
5
|
-
const Squircle = ({
|
|
5
|
+
const Squircle = ({ children, className, size = "lg", ...props }) => {
|
|
6
6
|
const componentProps = {
|
|
7
|
-
className: clsx("coop-squircle",
|
|
7
|
+
className: clsx("coop-squircle", !hasUserBg(className) && "bg-offer-red", className),
|
|
8
8
|
"data-size": size.length && size !== "lg" ? size : undefined,
|
|
9
9
|
...props,
|
|
10
10
|
};
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import type { AnchorHTMLAttributes, ForwardRefExoticComponent, HTMLAttributes, JSX } from "react";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import type { Black, Darks, Greys, Lights, Tints, White } from "../../types/colors";
|
|
4
3
|
export interface TagProps extends HTMLAttributes<HTMLAnchorElement> {
|
|
5
4
|
/** **(Optional)** Specify a custom element to override default `a` or `span`. */
|
|
6
5
|
as?: React.FC<AnchorHTMLAttributes<HTMLElement>> | ForwardRefExoticComponent<any> | string;
|
|
7
|
-
/** **(Optional)** Specify the Tag background color. */
|
|
8
|
-
background?: Lights | Darks | Tints | Greys | White | Black;
|
|
9
6
|
/** **(Optional)** Main content inside the component. It can be any valid JSX or string. */
|
|
10
7
|
children?: React.ReactNode;
|
|
11
8
|
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
@@ -15,5 +12,5 @@ export interface TagProps extends HTMLAttributes<HTMLAnchorElement> {
|
|
|
15
12
|
/** **(Optional)** Specify the Tag size. */
|
|
16
13
|
size?: "sm" | "md";
|
|
17
14
|
}
|
|
18
|
-
export declare const Tag: ({ as,
|
|
15
|
+
export declare const Tag: ({ as, children, className, href, size, ...props }: TagProps) => JSX.Element;
|
|
19
16
|
export default Tag;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import clsx from 'clsx';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { hasUserBg } from '../../utils/index.js';
|
|
4
4
|
|
|
5
|
-
const Tag = ({ as,
|
|
5
|
+
const Tag = ({ as, children, className, href, size = "md", ...props }) => {
|
|
6
6
|
let element = href ? "a" : "span";
|
|
7
7
|
const componentProps = {
|
|
8
|
-
className: clsx("coop-tag",
|
|
8
|
+
className: clsx("coop-tag", !hasUserBg(className) && "bg-tint-grey", className),
|
|
9
9
|
"data-size": size.length && size !== "md" ? size : undefined,
|
|
10
10
|
href,
|
|
11
11
|
...props,
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
const
|
|
1
|
+
const hasUserBg = (userClasses) => {
|
|
2
|
+
return typeof userClasses === "string" && (userClasses === null || userClasses === void 0 ? void 0 : userClasses.includes("bg-")) ? true : false;
|
|
3
|
+
};
|
|
4
|
+
const bgClassToColor = (userClasses) => {
|
|
5
|
+
var _a, _b;
|
|
6
|
+
return (_b = (_a = /bg-([^\s]+)/.exec(userClasses)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : null;
|
|
7
|
+
// return (
|
|
8
|
+
// userClasses
|
|
9
|
+
// .split(" ")
|
|
10
|
+
// .find((c) => c.startsWith("bg"))
|
|
11
|
+
// ?.replace("bg-", "") ?? ""
|
|
12
|
+
// )
|
|
13
|
+
};
|
|
2
14
|
|
|
3
|
-
export {
|
|
15
|
+
export { bgClassToColor, hasUserBg };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coopdigital/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.43.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
"storybook": "$storybook"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@coopdigital/styles": "^0.
|
|
81
|
+
"@coopdigital/styles": "^0.38.0",
|
|
82
82
|
"clsx": "^2.1.1"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "c3dc3d710bed7e0bc415887e1d484ce5f048f98c"
|
|
85
85
|
}
|
|
@@ -3,15 +3,11 @@ import type { ForwardRefExoticComponent, HTMLAttributes, JSX } from "react"
|
|
|
3
3
|
import clsx from "clsx"
|
|
4
4
|
import React from "react"
|
|
5
5
|
|
|
6
|
-
import { bgPropToClass } from "../../../src/utils"
|
|
7
|
-
import { Lights, Tints, White } from "../../types/colors"
|
|
8
6
|
import { getSlots } from "../../utils/slots"
|
|
9
7
|
import { ChevronRightIcon } from "../Icon/ChevronRightIcon"
|
|
10
8
|
import { Image, ImageProps } from "../Image"
|
|
11
9
|
|
|
12
10
|
export interface CardProps extends HTMLAttributes<HTMLDivElement> {
|
|
13
|
-
/** **(Optional)** Specify the Card background color. */
|
|
14
|
-
background?: Tints | White
|
|
15
11
|
/** **(Optional)** Specify whether chevron is visible. */
|
|
16
12
|
chevron?: boolean
|
|
17
13
|
/** **(Optional)** Content inside the component. Children that are not assigned to a slot will be grouped together and rendered under the main Card content. */
|
|
@@ -31,8 +27,6 @@ export interface CardProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
31
27
|
}
|
|
32
28
|
|
|
33
29
|
interface CardLabelProps extends HTMLAttributes<HTMLSpanElement> {
|
|
34
|
-
/** **(Optional)** Specify the Label background color. */
|
|
35
|
-
background?: Lights
|
|
36
30
|
/** **(Optional)** Content inside the Label. */
|
|
37
31
|
children?: React.ReactNode
|
|
38
32
|
/** **(Optional)** Specify additional CSS classes to be applied to the Label. */
|
|
@@ -86,7 +80,6 @@ function getCardLinkElement(as: CardProps["hrefAs"], href?: string) {
|
|
|
86
80
|
}
|
|
87
81
|
|
|
88
82
|
export const Card = ({
|
|
89
|
-
background = "white",
|
|
90
83
|
chevron = false,
|
|
91
84
|
children,
|
|
92
85
|
className,
|
|
@@ -104,7 +97,7 @@ export const Card = ({
|
|
|
104
97
|
const hasLinkWrapper = href && !slots.CardHeading
|
|
105
98
|
|
|
106
99
|
const componentProps = {
|
|
107
|
-
className: clsx("coop-card",
|
|
100
|
+
className: clsx("coop-card", className),
|
|
108
101
|
"data-image-pos": imagePosition,
|
|
109
102
|
"data-orientation": orientation !== "vertical" ? orientation : undefined,
|
|
110
103
|
...props,
|
|
@@ -143,18 +136,8 @@ const CardHeading = ({ as = "h3", children, className }: CardHeadingProps): JSX.
|
|
|
143
136
|
|
|
144
137
|
CardHeading.displayName = "Card.Heading"
|
|
145
138
|
|
|
146
|
-
const CardLabel = ({
|
|
147
|
-
return (
|
|
148
|
-
<span
|
|
149
|
-
className={clsx(
|
|
150
|
-
"coop-card--label",
|
|
151
|
-
className,
|
|
152
|
-
background && bgPropToClass(background, className)
|
|
153
|
-
)}
|
|
154
|
-
>
|
|
155
|
-
{children}
|
|
156
|
-
</span>
|
|
157
|
-
)
|
|
139
|
+
const CardLabel = ({ children, className }: CardLabelProps): JSX.Element => {
|
|
140
|
+
return <span className={clsx("coop-card--label", className)}>{children}</span>
|
|
158
141
|
}
|
|
159
142
|
|
|
160
143
|
CardLabel.displayName = "Card.Label"
|
|
@@ -7,7 +7,7 @@ import { FormFieldError, StandardSizes } from "../../../src/types"
|
|
|
7
7
|
import { FieldError } from "../FieldError"
|
|
8
8
|
import { FieldHint } from "../FieldHint"
|
|
9
9
|
import { FieldLabel } from "../FieldLabel"
|
|
10
|
-
import Tag
|
|
10
|
+
import Tag from "../Tag"
|
|
11
11
|
|
|
12
12
|
export interface CheckboxProps
|
|
13
13
|
extends Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "type"> {
|
|
@@ -39,8 +39,8 @@ export interface CheckboxProps
|
|
|
39
39
|
size?: StandardSizes
|
|
40
40
|
/** **(Optional)** Specify the Checkbox tag text. */
|
|
41
41
|
tag?: string
|
|
42
|
-
/** **(Optional)** Specify the Checkbox tag
|
|
43
|
-
|
|
42
|
+
/** **(Optional)** Specify the Checkbox tag className. */
|
|
43
|
+
tagClassName?: string
|
|
44
44
|
/** **(Optional)** Specify the Checkbox variant. */
|
|
45
45
|
variant?: "default" | "boxed"
|
|
46
46
|
}
|
|
@@ -56,7 +56,7 @@ export const Checkbox = ({
|
|
|
56
56
|
name,
|
|
57
57
|
size = "md",
|
|
58
58
|
tag,
|
|
59
|
-
|
|
59
|
+
tagClassName,
|
|
60
60
|
variant = "default",
|
|
61
61
|
...props
|
|
62
62
|
}: CheckboxProps): JSX.Element => {
|
|
@@ -86,7 +86,7 @@ export const Checkbox = ({
|
|
|
86
86
|
<FieldLabel htmlFor={id} isVisible={labelVisible}>
|
|
87
87
|
<span>{label}</span>{" "}
|
|
88
88
|
{tag && (
|
|
89
|
-
<Tag
|
|
89
|
+
<Tag className={tagClassName} size="sm">
|
|
90
90
|
{tag}
|
|
91
91
|
</Tag>
|
|
92
92
|
)}
|
|
@@ -1,47 +1,66 @@
|
|
|
1
|
-
import type { DetailsHTMLAttributes, JSX } from "react"
|
|
1
|
+
import type { DetailsHTMLAttributes, HTMLAttributes, JSX } from "react"
|
|
2
2
|
|
|
3
3
|
import { clsx } from "clsx"
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { bgClassToColor, hasUserBg } from "../../utils"
|
|
6
|
+
import { getSlots } from "../../utils/slots"
|
|
7
7
|
import { ChevronDownIcon } from "../Icon"
|
|
8
8
|
|
|
9
9
|
export interface ExpandableProps extends DetailsHTMLAttributes<HTMLDetailsElement> {
|
|
10
|
-
/** **(Optional)** Specify the Expandable background color. */
|
|
11
|
-
background?: Tints | White | None
|
|
12
10
|
/** Main content inside the component, only visible when it is open. It can be any valid JSX or string. */
|
|
13
11
|
children: React.ReactNode
|
|
14
12
|
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
15
13
|
className?: string
|
|
16
|
-
/** Specify the summary text to show when the Expandable is not open. */
|
|
17
|
-
summary: React.ReactNode
|
|
18
14
|
}
|
|
19
15
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
children
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
16
|
+
interface ExpandableSummaryProps extends HTMLAttributes<HTMLElement> {
|
|
17
|
+
/** **(Optional)** Content inside the Summary. */
|
|
18
|
+
children?: React.ReactNode
|
|
19
|
+
/** **(Optional)** Specify additional CSS classes to be applied to the Summary. */
|
|
20
|
+
className?: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const componentSlots = {
|
|
24
|
+
Children: null,
|
|
25
|
+
ExpandableSummary: null,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const Expandable = ({ children, className, ...props }: ExpandableProps): JSX.Element => {
|
|
29
|
+
const slots = getSlots(componentSlots, children)
|
|
30
|
+
|
|
27
31
|
const componentProps = {
|
|
28
|
-
className: clsx("coop-expandable",
|
|
32
|
+
className: clsx("coop-expandable", !hasUserBg(className) && "bg-tint-grey", className),
|
|
29
33
|
...props,
|
|
30
34
|
}
|
|
35
|
+
|
|
36
|
+
componentProps.style = {
|
|
37
|
+
"--bg": `var(--color-${bgClassToColor(componentProps.className)})`,
|
|
38
|
+
}
|
|
39
|
+
|
|
31
40
|
return (
|
|
32
|
-
<details {...componentProps}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
<ChevronDownIcon
|
|
36
|
-
className="coop-expandable--icon"
|
|
37
|
-
stroke="currentColor"
|
|
38
|
-
strokeWidth={2}
|
|
39
|
-
width="12"
|
|
40
|
-
/>
|
|
41
|
-
</summary>
|
|
42
|
-
<div className="coop-expandable--content">{children}</div>
|
|
41
|
+
<details {...componentProps}>
|
|
42
|
+
{slots.ExpandableSummary}
|
|
43
|
+
<div className="coop-expandable--content">{slots.Children}</div>
|
|
43
44
|
</details>
|
|
44
45
|
)
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
const ExpandableSummary = ({ children, className, ...props }: ExpandableSummaryProps) => {
|
|
49
|
+
return (
|
|
50
|
+
<summary {...props} className={className}>
|
|
51
|
+
{children}
|
|
52
|
+
<ChevronDownIcon
|
|
53
|
+
className="coop-expandable--icon"
|
|
54
|
+
stroke="currentColor"
|
|
55
|
+
strokeWidth={2}
|
|
56
|
+
width="12"
|
|
57
|
+
/>
|
|
58
|
+
</summary>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
ExpandableSummary.displayName = "Expandable.Summary"
|
|
63
|
+
|
|
64
|
+
Expandable.Summary = ExpandableSummary
|
|
65
|
+
|
|
47
66
|
export default Expandable
|
|
@@ -2,7 +2,7 @@ import type { JSX, ReactNode, SVGProps } from "react"
|
|
|
2
2
|
|
|
3
3
|
import clsx from "clsx"
|
|
4
4
|
|
|
5
|
-
import { BrandBlue, Darks, Lights, OfferRed } from "../../types/colors"
|
|
5
|
+
import { Black, BrandBlue, Darks, Lights, OfferRed, Tints, White } from "../../types/colors"
|
|
6
6
|
|
|
7
7
|
export interface FlourishProps extends SVGProps<SVGSVGElement> {
|
|
8
8
|
/** Specify the text to be highlighted by the Flourish. */
|
|
@@ -10,13 +10,13 @@ export interface FlourishProps extends SVGProps<SVGSVGElement> {
|
|
|
10
10
|
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
11
11
|
className?: string
|
|
12
12
|
/** **(Optional)** Specify the Flourish color. */
|
|
13
|
-
fill?: Darks | Lights | OfferRed | BrandBlue
|
|
13
|
+
fill?: Darks | Lights | Tints | OfferRed | BrandBlue | White | Black
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export const Flourish = ({
|
|
17
17
|
children,
|
|
18
18
|
className,
|
|
19
|
-
fill = "
|
|
19
|
+
fill = "brand-blue",
|
|
20
20
|
...props
|
|
21
21
|
}: FlourishProps): JSX.Element => {
|
|
22
22
|
const componentProps = {
|
|
@@ -28,7 +28,7 @@ export const Flourish = ({
|
|
|
28
28
|
return (
|
|
29
29
|
<span style={{ position: "relative" }}>
|
|
30
30
|
{children}
|
|
31
|
-
<svg {...componentProps}
|
|
31
|
+
<svg {...componentProps} viewBox="0 0 276 10">
|
|
32
32
|
<path d="M275.9 8.6c.1-1.6.2-1.8-.4-2.9.3-1-.3-1.2-1.8-1.1v-.3c.6-.4.2-.2 1.4-.1-.9-2.3-5.6-1.8-8.5-2.3C259 .5 246.3.7 237.4.5L185 .4l-33-.2-26.1-.2-67.4 1.2-44.3.5C10.7 2.1 1.5.4 0 3.3l1 .2L0 4v.5C8.2 7.9 26.6 7.2 35.6 7c5 0 13.5 1.6 16.5-.6C53.4 8 59.5 8 62 7.7l45 .1 42.8.3 30.7.3 44.2.6 27.8-.5 23 .8c.1-.8-.3-.5.5-.7ZM219 2.8v-.2l.8-.2h.4l.3.4H219Zm30-.1h1.2c-.8.4-.5.3-1.2 0Zm6.2.6.2-.4h.3l-.5.4Z" />
|
|
33
33
|
</svg>
|
|
34
34
|
</span>
|
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ForwardRefExoticComponent, HTMLAttributes, JSX } from "react"
|
|
2
2
|
|
|
3
3
|
import clsx from "clsx"
|
|
4
4
|
import React from "react"
|
|
5
5
|
import { StandardSizes } from "src/types"
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { hasUserBg } from "../../utils"
|
|
8
|
+
import { getSlots } from "../../utils/slots"
|
|
9
9
|
|
|
10
10
|
export interface PillProps extends HTMLAttributes<HTMLAnchorElement> {
|
|
11
11
|
/** **(Optional)** Specify a custom element to override default `a` or `span`. */
|
|
12
12
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
-
as?: React.FC<
|
|
14
|
-
/** **(Optional)** Specify the Pill background color. */
|
|
15
|
-
background?: Tints
|
|
16
|
-
/** **(Optional)** Specify text to display inside the badge. */
|
|
17
|
-
badge?: string
|
|
18
|
-
/** **(Optional)** Specify the badge background color. */
|
|
19
|
-
badgeBackground?: Darks | OfferRed
|
|
13
|
+
as?: React.FC<any> | ForwardRefExoticComponent<any> | string
|
|
20
14
|
/** **(Optional)** Main content inside the component. It can be any valid JSX or string. */
|
|
21
15
|
children?: React.ReactNode
|
|
22
16
|
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
@@ -27,11 +21,20 @@ export interface PillProps extends HTMLAttributes<HTMLAnchorElement> {
|
|
|
27
21
|
size?: StandardSizes
|
|
28
22
|
}
|
|
29
23
|
|
|
24
|
+
interface PillBadgeProps extends HTMLAttributes<HTMLSpanElement> {
|
|
25
|
+
/** **(Optional)** Content inside the Badge. */
|
|
26
|
+
children?: React.ReactNode
|
|
27
|
+
/** **(Optional)** Specify additional CSS classes to be applied to the Badge. */
|
|
28
|
+
className?: string
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const componentSlots = {
|
|
32
|
+
Children: null,
|
|
33
|
+
PillBadge: null,
|
|
34
|
+
}
|
|
35
|
+
|
|
30
36
|
export const Pill = ({
|
|
31
37
|
as,
|
|
32
|
-
background = "tint-grey",
|
|
33
|
-
badge,
|
|
34
|
-
badgeBackground = "offer-red",
|
|
35
38
|
children,
|
|
36
39
|
className,
|
|
37
40
|
href,
|
|
@@ -40,26 +43,32 @@ export const Pill = ({
|
|
|
40
43
|
}: PillProps): JSX.Element => {
|
|
41
44
|
let element: PillProps["as"] = href ? "a" : "span"
|
|
42
45
|
|
|
46
|
+
const slots = getSlots(componentSlots, children)
|
|
47
|
+
|
|
43
48
|
if (as) {
|
|
44
49
|
element = as
|
|
45
50
|
}
|
|
46
51
|
|
|
47
52
|
const componentProps = {
|
|
48
|
-
className: clsx("coop-pill",
|
|
53
|
+
className: clsx("coop-pill", !hasUserBg(className) && "bg-tint-grey", className),
|
|
49
54
|
"data-size": size.length && size !== "md" ? size : undefined,
|
|
50
55
|
href,
|
|
51
56
|
...props,
|
|
52
57
|
}
|
|
53
58
|
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
return React.createElement(element, { ...componentProps }, slots.PillBadge, slots.Children)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const PillBadge = ({ children, className }: PillBadgeProps) => {
|
|
63
|
+
return (
|
|
64
|
+
<span className={clsx("coop-pill--badge", !hasUserBg(className) && "bg-offer-red", className)}>
|
|
56
65
|
{children}
|
|
57
|
-
|
|
58
|
-
</>
|
|
59
|
-
) : (
|
|
60
|
-
children
|
|
66
|
+
</span>
|
|
61
67
|
)
|
|
62
|
-
|
|
63
|
-
return React.createElement(element, { ...componentProps }, finalChildren)
|
|
64
68
|
}
|
|
69
|
+
|
|
70
|
+
PillBadge.displayName = "Pill.Badge"
|
|
71
|
+
|
|
72
|
+
Pill.Badge = PillBadge
|
|
73
|
+
|
|
65
74
|
export default Pill
|
|
@@ -5,7 +5,7 @@ import { FormFieldError, StandardSizes } from "src/types"
|
|
|
5
5
|
import { FieldError } from "../FieldError"
|
|
6
6
|
import { FieldHint } from "../FieldHint"
|
|
7
7
|
import { FieldLabel } from "../FieldLabel"
|
|
8
|
-
import Tag
|
|
8
|
+
import Tag from "../Tag"
|
|
9
9
|
|
|
10
10
|
export interface RadioButtonProps
|
|
11
11
|
extends Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "type"> {
|
|
@@ -37,8 +37,8 @@ export interface RadioButtonProps
|
|
|
37
37
|
size?: StandardSizes
|
|
38
38
|
/** **(Optional)** Specify the RadioButton tag text. */
|
|
39
39
|
tag?: string
|
|
40
|
-
/** **(Optional)** Specify the RadioButton tag
|
|
41
|
-
|
|
40
|
+
/** **(Optional)** Specify the RadioButton tag className. */
|
|
41
|
+
tagClassName?: string
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export const RadioButton = ({
|
|
@@ -52,7 +52,7 @@ export const RadioButton = ({
|
|
|
52
52
|
name,
|
|
53
53
|
size = "md",
|
|
54
54
|
tag,
|
|
55
|
-
|
|
55
|
+
tagClassName,
|
|
56
56
|
...props
|
|
57
57
|
}: RadioButtonProps): JSX.Element => {
|
|
58
58
|
const internalId = useId()
|
|
@@ -80,7 +80,7 @@ export const RadioButton = ({
|
|
|
80
80
|
<FieldLabel htmlFor={id} isVisible={labelVisible}>
|
|
81
81
|
<span>{label}</span>{" "}
|
|
82
82
|
{tag && (
|
|
83
|
-
<Tag
|
|
83
|
+
<Tag className={tagClassName} size="sm">
|
|
84
84
|
{tag}
|
|
85
85
|
</Tag>
|
|
86
86
|
)}
|
|
@@ -2,12 +2,8 @@ import type { HTMLAttributes, JSX } from "react"
|
|
|
2
2
|
|
|
3
3
|
import clsx from "clsx"
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import { BrandBlue, Green, OfferRed } from "../../types/colors"
|
|
7
|
-
|
|
5
|
+
import { hasUserBg } from "../../../src/utils"
|
|
8
6
|
export interface SquircleProps extends HTMLAttributes<HTMLDivElement> {
|
|
9
|
-
/** **(Optional)** Specify the Squircle background color. */
|
|
10
|
-
background?: OfferRed | BrandBlue | Green
|
|
11
7
|
/** **(Optional)** Main content inside the component. It can be any valid JSX or string. */
|
|
12
8
|
children?: React.ReactNode
|
|
13
9
|
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
@@ -17,14 +13,13 @@ export interface SquircleProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
17
13
|
}
|
|
18
14
|
|
|
19
15
|
export const Squircle = ({
|
|
20
|
-
background = "offer-red",
|
|
21
16
|
children,
|
|
22
17
|
className,
|
|
23
18
|
size = "lg",
|
|
24
19
|
...props
|
|
25
20
|
}: SquircleProps): JSX.Element => {
|
|
26
21
|
const componentProps = {
|
|
27
|
-
className: clsx("coop-squircle",
|
|
22
|
+
className: clsx("coop-squircle", !hasUserBg(className) && "bg-offer-red", className),
|
|
28
23
|
"data-size": size.length && size !== "lg" ? size : undefined,
|
|
29
24
|
...props,
|
|
30
25
|
}
|
|
@@ -3,16 +3,12 @@ import type { AnchorHTMLAttributes, ForwardRefExoticComponent, HTMLAttributes, J
|
|
|
3
3
|
import clsx from "clsx"
|
|
4
4
|
import React from "react"
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
import { bgPropToClass } from "../../../src/utils"
|
|
6
|
+
import { hasUserBg } from "../../../src/utils"
|
|
9
7
|
|
|
10
8
|
export interface TagProps extends HTMLAttributes<HTMLAnchorElement> {
|
|
11
9
|
/** **(Optional)** Specify a custom element to override default `a` or `span`. */
|
|
12
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
11
|
as?: React.FC<AnchorHTMLAttributes<HTMLElement>> | ForwardRefExoticComponent<any> | string
|
|
14
|
-
/** **(Optional)** Specify the Tag background color. */
|
|
15
|
-
background?: Lights | Darks | Tints | Greys | White | Black
|
|
16
12
|
/** **(Optional)** Main content inside the component. It can be any valid JSX or string. */
|
|
17
13
|
children?: React.ReactNode
|
|
18
14
|
/** **(Optional)** Specify additional CSS classes to be applied to the component. */
|
|
@@ -25,7 +21,6 @@ export interface TagProps extends HTMLAttributes<HTMLAnchorElement> {
|
|
|
25
21
|
|
|
26
22
|
export const Tag = ({
|
|
27
23
|
as,
|
|
28
|
-
background = "tint-grey",
|
|
29
24
|
children,
|
|
30
25
|
className,
|
|
31
26
|
href,
|
|
@@ -34,7 +29,7 @@ export const Tag = ({
|
|
|
34
29
|
}: TagProps): JSX.Element => {
|
|
35
30
|
let element: TagProps["as"] = href ? "a" : "span"
|
|
36
31
|
const componentProps = {
|
|
37
|
-
className: clsx("coop-tag",
|
|
32
|
+
className: clsx("coop-tag", !hasUserBg(className) && "bg-tint-grey", className),
|
|
38
33
|
"data-size": size.length && size !== "md" ? size : undefined,
|
|
39
34
|
href,
|
|
40
35
|
|
package/src/utils/index.ts
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
1
|
export const bgPropToClass = (color: string, userClasses?: string) =>
|
|
2
2
|
userClasses?.includes("bg-") ? "" : `bg-${color}`
|
|
3
|
+
|
|
4
|
+
export const hasUserBg = (userClasses?: string) => {
|
|
5
|
+
return typeof userClasses === "string" && userClasses?.includes("bg-") ? true : false
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const bgClassToColor = (userClasses: string) => {
|
|
9
|
+
return /bg-([^\s]+)/.exec(userClasses)?.[1] ?? null
|
|
10
|
+
|
|
11
|
+
// return (
|
|
12
|
+
// userClasses
|
|
13
|
+
// .split(" ")
|
|
14
|
+
// .find((c) => c.startsWith("bg"))
|
|
15
|
+
// ?.replace("bg-", "") ?? ""
|
|
16
|
+
// )
|
|
17
|
+
}
|