@purpurds/radio-card-group 6.12.5 → 7.0.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/LICENSE.txt +3 -3
- package/dist/radio-card-group.cjs.js +3 -3
- package/dist/radio-card-group.cjs.js.map +1 -1
- package/dist/radio-card-group.d.ts +8 -8
- package/dist/radio-card-group.d.ts.map +1 -1
- package/dist/radio-card-group.es.js +98 -105
- package/dist/radio-card-group.es.js.map +1 -1
- package/dist/radio-card-item.d.ts +0 -1
- package/dist/radio-card-item.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/radio-card-group.stories.tsx +6 -3
- package/src/radio-card-group.test.tsx +22 -20
- package/src/radio-card-group.tsx +14 -13
- package/src/radio-card-item.tsx +5 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purpurds/radio-card-group",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"main": "./dist/radio-card-group.cjs.js",
|
|
6
6
|
"types": "./dist/radio-card-group.d.ts",
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@radix-ui/react-radio-group": "~1.2.3",
|
|
19
19
|
"classnames": "~2.5.0",
|
|
20
|
-
"@purpurds/
|
|
21
|
-
"@purpurds/paragraph": "
|
|
22
|
-
"@purpurds/
|
|
23
|
-
"@purpurds/tokens": "
|
|
20
|
+
"@purpurds/heading": "7.0.0",
|
|
21
|
+
"@purpurds/paragraph": "7.0.0",
|
|
22
|
+
"@purpurds/skeleton": "7.0.0",
|
|
23
|
+
"@purpurds/tokens": "7.0.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"eslint": "9.24.0",
|
|
@@ -41,11 +41,11 @@
|
|
|
41
41
|
"typescript": "^5.6.3",
|
|
42
42
|
"vite": "^6.2.1",
|
|
43
43
|
"vitest": "^3.1.2",
|
|
44
|
-
"@purpurds/badge": "
|
|
45
|
-
"@purpurds/button": "
|
|
44
|
+
"@purpurds/badge": "7.0.0",
|
|
45
|
+
"@purpurds/button": "7.0.0",
|
|
46
46
|
"@purpurds/component-rig": "1.0.0",
|
|
47
|
-
"@purpurds/grid": "
|
|
48
|
-
"@purpurds/text-field": "
|
|
47
|
+
"@purpurds/grid": "7.0.0",
|
|
48
|
+
"@purpurds/text-field": "7.0.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@types/react": "^18 || ^19",
|
|
@@ -43,6 +43,9 @@ const meta = {
|
|
|
43
43
|
RadioCardGroupItem: RadioCardItem,
|
|
44
44
|
},
|
|
45
45
|
decorators,
|
|
46
|
+
args: {
|
|
47
|
+
required: false,
|
|
48
|
+
},
|
|
46
49
|
argTypes: {
|
|
47
50
|
orientation: {
|
|
48
51
|
control: "radio",
|
|
@@ -77,7 +80,7 @@ const items: RadioCardGroupItem[] = Array.from(Array(7).keys()).map((key) => ({
|
|
|
77
80
|
export const Controlled: Story = {
|
|
78
81
|
args: {
|
|
79
82
|
items,
|
|
80
|
-
|
|
83
|
+
heading: "Controlled Radio card group",
|
|
81
84
|
id: "radio-card-story",
|
|
82
85
|
value: items[0].value,
|
|
83
86
|
},
|
|
@@ -96,7 +99,7 @@ export const Controlled: Story = {
|
|
|
96
99
|
export const Uncontrolled: Story = {
|
|
97
100
|
args: {
|
|
98
101
|
items,
|
|
99
|
-
|
|
102
|
+
heading: "Uncontrolled radio card group",
|
|
100
103
|
id: "radio-card-story",
|
|
101
104
|
defaultValue: items[0].value,
|
|
102
105
|
},
|
|
@@ -153,7 +156,7 @@ const itemsAsChildren: RadioCardGroupItem[] = [
|
|
|
153
156
|
|
|
154
157
|
export const ItemsAsChildren: Story = {
|
|
155
158
|
args: {
|
|
156
|
-
|
|
159
|
+
heading: "Cards passed as children",
|
|
157
160
|
id: "radio-card-story",
|
|
158
161
|
defaultValue: items[0].value,
|
|
159
162
|
},
|
|
@@ -9,7 +9,7 @@ import { RadioCardImage } from "./radio-card-item-image";
|
|
|
9
9
|
|
|
10
10
|
expect.extend(matchers);
|
|
11
11
|
|
|
12
|
-
describe("
|
|
12
|
+
describe("RadioCardGroup", () => {
|
|
13
13
|
global.ResizeObserver = vi.fn().mockImplementation(() => ({
|
|
14
14
|
observe: vi.fn(),
|
|
15
15
|
unobserve: vi.fn(),
|
|
@@ -29,7 +29,7 @@ describe("RadioButtonGroup", () => {
|
|
|
29
29
|
{ id: "3", title: "3", value: "3" },
|
|
30
30
|
];
|
|
31
31
|
render(<RadioCardGroup items={items} id="test" data-testid="test" value="1" />);
|
|
32
|
-
expect(screen.queryByTestId("test-
|
|
32
|
+
expect(screen.queryByTestId("test-heading")).not.toBeInTheDocument();
|
|
33
33
|
const radioCardItems = screen.getAllByRole("radio");
|
|
34
34
|
|
|
35
35
|
expect(radioCardItems).toHaveLength(3);
|
|
@@ -47,48 +47,50 @@ describe("RadioButtonGroup", () => {
|
|
|
47
47
|
const items = [
|
|
48
48
|
{ id: "1", title: "1", value: "1" },
|
|
49
49
|
{ id: "2", title: "2", value: "2", disabled: true },
|
|
50
|
-
{ id: "3", title: "3", value: "3"
|
|
50
|
+
{ id: "3", title: "3", value: "3" },
|
|
51
51
|
];
|
|
52
52
|
render(
|
|
53
53
|
<form>
|
|
54
|
-
<RadioCardGroup items={items} id="test" data-testid="test" value="1" />
|
|
54
|
+
<RadioCardGroup items={items} id="test" data-testid="test" value="1" required />
|
|
55
55
|
</form>
|
|
56
56
|
);
|
|
57
57
|
|
|
58
|
-
expect(screen.queryByTestId("test-
|
|
58
|
+
expect(screen.queryByTestId("test-heading")).not.toBeInTheDocument();
|
|
59
59
|
const radioCardItems = screen.getAllByTestId("test-item");
|
|
60
60
|
|
|
61
61
|
expect(radioCardItems).toHaveLength(3);
|
|
62
62
|
expect(radioCardItems["0"].nextElementSibling).toBeChecked();
|
|
63
63
|
expect(radioCardItems["0"].nextElementSibling).not.toBeDisabled();
|
|
64
|
-
expect(radioCardItems["0"].nextElementSibling).
|
|
64
|
+
expect(radioCardItems["0"].nextElementSibling).toBeRequired();
|
|
65
65
|
|
|
66
66
|
expect(radioCardItems["1"].nextElementSibling).not.toBeChecked();
|
|
67
67
|
expect(radioCardItems["1"].nextElementSibling).toBeDisabled();
|
|
68
|
-
expect(radioCardItems["1"].nextElementSibling).
|
|
68
|
+
expect(radioCardItems["1"].nextElementSibling).toBeRequired();
|
|
69
69
|
|
|
70
70
|
expect(radioCardItems["2"].nextElementSibling).not.toBeChecked();
|
|
71
71
|
expect(radioCardItems["2"].nextElementSibling).not.toBeDisabled();
|
|
72
72
|
expect(radioCardItems["2"].nextElementSibling).toBeRequired();
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
it("should render with
|
|
75
|
+
it("should render with heading", () => {
|
|
76
76
|
const items = [
|
|
77
77
|
{ id: "1", title: "1", value: "1" },
|
|
78
78
|
{ id: "2", title: "2", value: "2" },
|
|
79
79
|
];
|
|
80
|
-
render(
|
|
80
|
+
render(
|
|
81
|
+
<RadioCardGroup items={items} id="test" data-testid="test" value="1" heading="Heading" />
|
|
82
|
+
);
|
|
81
83
|
|
|
82
84
|
const heading = screen.getByRole("heading", { level: 2 });
|
|
83
85
|
expect(heading).toBeInTheDocument();
|
|
84
|
-
expect(heading).toHaveAttribute("id", "test-
|
|
85
|
-
expect(heading).toHaveTextContent("
|
|
86
|
+
expect(heading).toHaveAttribute("id", "test-heading");
|
|
87
|
+
expect(heading).toHaveTextContent("Heading");
|
|
86
88
|
|
|
87
|
-
expect(screen.getByRole("radiogroup")).toHaveAttribute("aria-labelledby", "test-
|
|
89
|
+
expect(screen.getByRole("radiogroup")).toHaveAttribute("aria-labelledby", "test-heading");
|
|
88
90
|
expect(screen.getAllByRole("radio")).toHaveLength(2);
|
|
89
91
|
});
|
|
90
92
|
|
|
91
|
-
it("should render with h4
|
|
93
|
+
it("should render with h4 heading", () => {
|
|
92
94
|
const items = [
|
|
93
95
|
{ id: "1", title: "1", value: "1" },
|
|
94
96
|
{ id: "2", title: "2", value: "2" },
|
|
@@ -99,15 +101,15 @@ describe("RadioButtonGroup", () => {
|
|
|
99
101
|
id="test"
|
|
100
102
|
data-testid="test"
|
|
101
103
|
value="1"
|
|
102
|
-
|
|
103
|
-
|
|
104
|
+
heading="Heading"
|
|
105
|
+
headingTag="h4"
|
|
104
106
|
/>
|
|
105
107
|
);
|
|
106
108
|
|
|
107
109
|
const heading = screen.getByRole("heading", { level: 4 });
|
|
108
110
|
expect(heading).toBeInTheDocument();
|
|
109
|
-
expect(heading).toHaveAttribute("id", "test-
|
|
110
|
-
expect(heading).toHaveTextContent("
|
|
111
|
+
expect(heading).toHaveAttribute("id", "test-heading");
|
|
112
|
+
expect(heading).toHaveTextContent("Heading");
|
|
111
113
|
});
|
|
112
114
|
|
|
113
115
|
it("should only render children that are RadioCardItems", () => {
|
|
@@ -116,7 +118,7 @@ describe("RadioButtonGroup", () => {
|
|
|
116
118
|
{ id: "2", title: "2", value: "2" },
|
|
117
119
|
];
|
|
118
120
|
render(
|
|
119
|
-
<RadioCardGroup id="test" data-testid="test" value="1"
|
|
121
|
+
<RadioCardGroup id="test" data-testid="test" value="1" heading="Heading">
|
|
120
122
|
<RadioCardImage data-testid="test-radio-item-image" altText="test-alt" src="test-source" />
|
|
121
123
|
{items.map((item) => (
|
|
122
124
|
<RadioCardItem data-testid="test-radio-card-item" key={item.id} {...item} />
|
|
@@ -144,7 +146,7 @@ describe("RadioButtonGroup", () => {
|
|
|
144
146
|
id="test"
|
|
145
147
|
data-testid="test"
|
|
146
148
|
value="1"
|
|
147
|
-
|
|
149
|
+
heading="Heading"
|
|
148
150
|
onValueChange={onValueChangeMock}
|
|
149
151
|
>
|
|
150
152
|
{items.map((item) => (
|
|
@@ -170,7 +172,7 @@ describe("RadioButtonGroup", () => {
|
|
|
170
172
|
];
|
|
171
173
|
|
|
172
174
|
render(
|
|
173
|
-
<RadioCardGroup id="test" data-testid="test"
|
|
175
|
+
<RadioCardGroup id="test" data-testid="test" heading="Heading">
|
|
174
176
|
{items.map((item) => (
|
|
175
177
|
<RadioCardItem data-testid="test-radio-card-item" key={item.id} {...item} />
|
|
176
178
|
))}
|
package/src/radio-card-group.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { Children, cloneElement, ForwardedRef, forwardRef, ReactNode, Ref } from "react";
|
|
2
|
-
import { Heading,type HeadingTagType } from "@purpurds/heading";
|
|
2
|
+
import { Heading, type HeadingTagType } from "@purpurds/heading";
|
|
3
3
|
import * as RadixRadioGroup from "@radix-ui/react-radio-group";
|
|
4
4
|
|
|
5
5
|
import { cx } from "./classnames";
|
|
@@ -13,7 +13,7 @@ type StylingProps = Pick<React.HTMLAttributes<HTMLElement>, "className" | "style
|
|
|
13
13
|
|
|
14
14
|
export type RadioCardGroupProps = StylingProps & {
|
|
15
15
|
/**
|
|
16
|
-
* To use when no
|
|
16
|
+
* To use when no heading is given.
|
|
17
17
|
* */
|
|
18
18
|
["aria-label"]?: string;
|
|
19
19
|
/**
|
|
@@ -40,11 +40,11 @@ export type RadioCardGroupProps = StylingProps & {
|
|
|
40
40
|
/**
|
|
41
41
|
* Renders above the radio card group as a heading
|
|
42
42
|
* */
|
|
43
|
-
|
|
43
|
+
heading?: string;
|
|
44
44
|
/**
|
|
45
|
-
* Changes heading level for
|
|
45
|
+
* Changes heading level for heading.
|
|
46
46
|
*/
|
|
47
|
-
|
|
47
|
+
headingTag?: HeadingTagType;
|
|
48
48
|
/**
|
|
49
49
|
* When true, keyboard navigation will loop from last item to first, and vice versa.
|
|
50
50
|
* */
|
|
@@ -88,8 +88,8 @@ const RadioCardGroupComponent = (
|
|
|
88
88
|
children,
|
|
89
89
|
className,
|
|
90
90
|
items,
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
heading,
|
|
92
|
+
headingTag = "h2",
|
|
93
93
|
loop = true,
|
|
94
94
|
orientation = "vertical",
|
|
95
95
|
radioPosition = "right",
|
|
@@ -101,20 +101,21 @@ const RadioCardGroupComponent = (
|
|
|
101
101
|
|
|
102
102
|
return (
|
|
103
103
|
<div className={cx(className, `${rootClassName}__container`)} ref={ref}>
|
|
104
|
-
{
|
|
104
|
+
{heading && (
|
|
105
105
|
<Heading
|
|
106
|
-
data-testid={dataTestId ? `${dataTestId}-
|
|
107
|
-
id={`${props.id}-
|
|
108
|
-
tag={
|
|
106
|
+
data-testid={dataTestId ? `${dataTestId}-heading` : undefined}
|
|
107
|
+
id={`${props.id}-heading`}
|
|
108
|
+
tag={headingTag}
|
|
109
109
|
variant="subsection-100"
|
|
110
110
|
>
|
|
111
|
-
{
|
|
111
|
+
{props.required && <span aria-hidden>{"* "}</span>}
|
|
112
|
+
{heading}
|
|
112
113
|
</Heading>
|
|
113
114
|
)}
|
|
114
115
|
{(!!items?.length || radioCardItemChildren.length) && (
|
|
115
116
|
<RadixRadioGroup.Root
|
|
116
117
|
{...props}
|
|
117
|
-
aria-labelledby={ariaLabelledby || (
|
|
118
|
+
aria-labelledby={ariaLabelledby || (heading ? `${props.id}-heading` : undefined)}
|
|
118
119
|
className={cx(
|
|
119
120
|
rootClassName,
|
|
120
121
|
`${rootClassName}--${orientation}`,
|
package/src/radio-card-item.tsx
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
ForwardedRef,
|
|
3
|
-
forwardRef,
|
|
4
|
-
isValidElement,
|
|
5
|
-
ReactElement,
|
|
6
|
-
ReactNode,
|
|
7
|
-
} from "react";
|
|
1
|
+
import React, { ForwardedRef, forwardRef, isValidElement, ReactElement, ReactNode } from "react";
|
|
8
2
|
import { Paragraph } from "@purpurds/paragraph";
|
|
9
3
|
import * as RadixRadioGroup from "@radix-ui/react-radio-group";
|
|
10
4
|
|
|
@@ -34,20 +28,19 @@ export type RadioCardItemProps = {
|
|
|
34
28
|
id: string;
|
|
35
29
|
/**
|
|
36
30
|
* The radio image.
|
|
37
|
-
*
|
|
31
|
+
*
|
|
38
32
|
union = {
|
|
39
33
|
"data-testid"?: string | undefined;
|
|
40
34
|
altText: string;
|
|
41
35
|
loading?: "lazy" | "eager" | undefined;
|
|
42
36
|
noPlaceholder?: boolean | undefined;
|
|
43
37
|
src: string;
|
|
44
|
-
} |
|
|
38
|
+
} |
|
|
45
39
|
((props: {
|
|
46
40
|
disabled?: boolean;
|
|
47
41
|
}) => ReactNode) | React.ReactNode
|
|
48
42
|
* */
|
|
49
43
|
image?: RadioCardImageProps | CustomElement;
|
|
50
|
-
required?: boolean;
|
|
51
44
|
value: string;
|
|
52
45
|
/**
|
|
53
46
|
* `union = string | Omit<ReactNode, "undefined" | "null">`
|
|
@@ -64,16 +57,7 @@ const RadioCardItemComponent = (
|
|
|
64
57
|
{ title, ...propsx }: RadioCardItemProps,
|
|
65
58
|
ref: ForwardedRef<HTMLDivElement>
|
|
66
59
|
) => {
|
|
67
|
-
const {
|
|
68
|
-
["data-testid"]: dataTestid,
|
|
69
|
-
body,
|
|
70
|
-
children,
|
|
71
|
-
disabled,
|
|
72
|
-
id,
|
|
73
|
-
image,
|
|
74
|
-
required,
|
|
75
|
-
value,
|
|
76
|
-
} = propsx;
|
|
60
|
+
const { ["data-testid"]: dataTestid, body, children, disabled, id, image, value } = propsx;
|
|
77
61
|
|
|
78
62
|
const props = { title, ...propsx };
|
|
79
63
|
|
|
@@ -84,7 +68,6 @@ const RadioCardItemComponent = (
|
|
|
84
68
|
data-testid={dataTestid}
|
|
85
69
|
disabled={disabled}
|
|
86
70
|
id={id}
|
|
87
|
-
required={required}
|
|
88
71
|
value={value}
|
|
89
72
|
>
|
|
90
73
|
{image && (
|
|
@@ -139,7 +122,5 @@ const RadioCardItemComponent = (
|
|
|
139
122
|
export const RadioCardItem = forwardRef(RadioCardItemComponent);
|
|
140
123
|
RadioCardItem.displayName = "RadioCardItem";
|
|
141
124
|
|
|
142
|
-
export const isRadioCardItem = (
|
|
143
|
-
child?: ReactNode
|
|
144
|
-
): child is ReactElement<RadioCardItemProps> =>
|
|
125
|
+
export const isRadioCardItem = (child?: ReactNode): child is ReactElement<RadioCardItemProps> =>
|
|
145
126
|
isValidElement<RadioCardItemProps>(child) && child?.type === RadioCardItem;
|