@purpurds/radio-card-group 6.12.5 → 7.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purpurds/radio-card-group",
3
- "version": "6.12.5",
3
+ "version": "7.1.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/skeleton": "6.12.5",
21
- "@purpurds/paragraph": "6.12.5",
22
- "@purpurds/heading": "6.12.5",
23
- "@purpurds/tokens": "6.12.5"
20
+ "@purpurds/heading": "7.1.0",
21
+ "@purpurds/paragraph": "7.1.0",
22
+ "@purpurds/skeleton": "7.1.0",
23
+ "@purpurds/tokens": "7.1.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": "6.12.5",
45
- "@purpurds/button": "6.12.5",
44
+ "@purpurds/badge": "7.1.0",
45
+ "@purpurds/button": "7.1.0",
46
46
  "@purpurds/component-rig": "1.0.0",
47
- "@purpurds/grid": "6.12.5",
48
- "@purpurds/text-field": "6.12.5"
47
+ "@purpurds/grid": "7.1.0",
48
+ "@purpurds/text-field": "7.1.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
- label: "Controlled Radio card group",
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
- label: "Uncontrolled radio card group label",
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
- label: "Cards passed as children",
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("RadioButtonGroup", () => {
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-label")).not.toBeInTheDocument();
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", required: true },
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-label")).not.toBeInTheDocument();
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).not.toBeRequired();
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).not.toBeRequired();
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 label", () => {
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(<RadioCardGroup items={items} id="test" data-testid="test" value="1" label="Label" />);
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-label");
85
- expect(heading).toHaveTextContent("Label");
86
+ expect(heading).toHaveAttribute("id", "test-heading");
87
+ expect(heading).toHaveTextContent("Heading");
86
88
 
87
- expect(screen.getByRole("radiogroup")).toHaveAttribute("aria-labelledby", "test-label");
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 label", () => {
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
- label="Label"
103
- labelTag="h4"
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-label");
110
- expect(heading).toHaveTextContent("Label");
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" label="Label">
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
- label="Label"
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" label="Label">
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
  ))}
@@ -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 label is given.
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
- label?: string;
43
+ heading?: string;
44
44
  /**
45
- * Changes heading level for label.
45
+ * Changes heading level for heading.
46
46
  */
47
- labelTag?: HeadingTagType;
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
- label,
92
- labelTag = "h2",
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
- {label && (
104
+ {heading && (
105
105
  <Heading
106
- data-testid={dataTestId ? `${dataTestId}-label` : undefined}
107
- id={`${props.id}-label`}
108
- tag={labelTag}
106
+ data-testid={dataTestId ? `${dataTestId}-heading` : undefined}
107
+ id={`${props.id}-heading`}
108
+ tag={headingTag}
109
109
  variant="subsection-100"
110
110
  >
111
- {`${props.required ? "* " : ""}${label}`}
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 || (label ? `${props.id}-label` : undefined)}
118
+ aria-labelledby={ariaLabelledby || (heading ? `${props.id}-heading` : undefined)}
118
119
  className={cx(
119
120
  rootClassName,
120
121
  `${rootClassName}--${orientation}`,
@@ -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;