@purpurds/radio-card-group 7.6.0 → 7.7.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.
@@ -1,4 +1,5 @@
1
- import { default as React, HTMLAttributes, ReactElement, ReactNode } from 'react';
1
+ import { default as React, ReactElement, ReactNode } from 'react';
2
+ import { BaseProps } from '@purpurds/common-types';
2
3
  import { RadioCardImageProps } from './radio-card-item-image';
3
4
 
4
5
  type CustomElement = ((props: {
@@ -7,13 +8,11 @@ type CustomElement = ((props: {
7
8
  type NonNullCustomElement = ((props: {
8
9
  disabled?: boolean;
9
10
  }) => NonNullable<ReactNode>) | NonNullable<ReactNode>;
10
- export type RadioCardItemProps = Omit<HTMLAttributes<HTMLDivElement>, "id" | "title"> & {
11
- ["data-testid"]?: string;
11
+ export type RadioCardItemProps = Omit<BaseProps, "id" | "title"> & {
12
12
  /**
13
13
  * `string | ReactNode | (props: { disabled?: boolean }) => ReactNode`
14
14
  */
15
15
  body?: string | CustomElement;
16
- children?: ReactNode;
17
16
  disabled?: boolean;
18
17
  id: string;
19
18
  /**
@@ -37,36 +36,7 @@ export type RadioCardItemProps = Omit<HTMLAttributes<HTMLDivElement>, "id" | "ti
37
36
  */
38
37
  title: string | NonNullCustomElement;
39
38
  };
40
- export declare const RadioCardItem: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<HTMLDivElement>, "title" | "id"> & {
41
- "data-testid"?: string;
42
- /**
43
- * `string | ReactNode | (props: { disabled?: boolean }) => ReactNode`
44
- */
45
- body?: string | CustomElement;
46
- children?: ReactNode;
47
- disabled?: boolean;
48
- id: string;
49
- /**
50
- * The radio image.
51
- *
52
- union = {
53
- "data-testid"?: string | undefined;
54
- altText: string;
55
- loading?: "lazy" | "eager" | undefined;
56
- noPlaceholder?: boolean | undefined;
57
- src: string;
58
- } |
59
- ((props: {
60
- disabled?: boolean;
61
- }) => ReactNode) | React.ReactNode
62
- * */
63
- image?: RadioCardImageProps | CustomElement;
64
- value: string;
65
- /**
66
- * `union = string | Omit<ReactNode, "undefined" | "null">`
67
- */
68
- title: string | NonNullCustomElement;
69
- } & React.RefAttributes<HTMLDivElement>>;
39
+ export declare const RadioCardItem: React.ForwardRefExoticComponent<Omit<RadioCardItemProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
70
40
  export declare const isRadioCardItem: (child?: ReactNode) => child is ReactElement<RadioCardItemProps>;
71
41
  export {};
72
42
  //# sourceMappingURL=radio-card-item.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"radio-card-item.d.ts","sourceRoot":"","sources":["../src/radio-card-item.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAGZ,KAAK,cAAc,EAEnB,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAKf,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,yBAAyB,CAAC;AAIjC,KAAK,aAAa,GAAG,CAAC,CAAC,KAAK,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,KAAK,SAAS,CAAC,GAAG,SAAS,CAAC;AAChF,KAAK,oBAAoB,GACrB,CAAC,CAAC,KAAK,EAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,KAAK,WAAW,CAAC,SAAS,CAAC,CAAC,GAC3D,WAAW,CAAC,SAAS,CAAC,CAAC;AAE3B,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,IAAI,GAAG,OAAO,CAAC,GAAG;IACtF,CAAC,aAAa,CAAC,CAAC,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC;IAC9B,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX;;;;;;;;;;;;;SAaK;IACL,KAAK,CAAC,EAAE,mBAAmB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;;;;;;;;;;;SAaK;IACL,KAAK,CAAC,EAAE,mBAAmB,GAAG,aAAa,CAAC;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,EAAE,MAAM,GAAG,oBAAoB,CAAC;CACtC,CAAC;AAOF,eAAO,MAAM,aAAa,wGA+DzB,CAAC;AAIF,eAAO,MAAM,eAAe,WAAY,SAAS,KAAG,KAAK,IAAI,YAAY,CAAC,kBAAkB,CAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purpurds/radio-card-group",
3
- "version": "7.6.0",
3
+ "version": "7.7.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,11 @@
17
17
  "dependencies": {
18
18
  "@radix-ui/react-radio-group": "~1.2.3",
19
19
  "classnames": "~2.5.0",
20
- "@purpurds/heading": "7.6.0",
21
- "@purpurds/skeleton": "7.6.0",
22
- "@purpurds/tokens": "7.6.0",
23
- "@purpurds/paragraph": "7.6.0"
20
+ "@purpurds/common-types": "7.7.0",
21
+ "@purpurds/tokens": "7.7.0",
22
+ "@purpurds/paragraph": "7.7.0",
23
+ "@purpurds/skeleton": "7.7.0",
24
+ "@purpurds/heading": "7.7.0"
24
25
  },
25
26
  "devDependencies": {
26
27
  "eslint": "9.24.0",
@@ -41,11 +42,11 @@
41
42
  "typescript": "^5.6.3",
42
43
  "vite": "^6.2.1",
43
44
  "vitest": "^3.1.2",
44
- "@purpurds/badge": "7.6.0",
45
- "@purpurds/button": "7.6.0",
46
- "@purpurds/grid": "7.6.0",
47
- "@purpurds/text-field": "7.6.0",
48
- "@purpurds/component-rig": "1.0.0"
45
+ "@purpurds/button": "7.7.0",
46
+ "@purpurds/badge": "7.7.0",
47
+ "@purpurds/component-rig": "1.0.0",
48
+ "@purpurds/grid": "7.7.0",
49
+ "@purpurds/text-field": "7.7.0"
49
50
  },
50
51
  "peerDependencies": {
51
52
  "@types/react": "^18 || ^19",
@@ -1,4 +1,4 @@
1
- import React, { Children, cloneElement, type ForwardedRef, forwardRef, type ReactNode, type Ref } from "react";
1
+ import React, { Children, cloneElement, forwardRef, type ReactNode, type Ref } from "react";
2
2
  import { Heading, type HeadingTagType } from "@purpurds/heading";
3
3
  import * as RadixRadioGroup from "@radix-ui/react-radio-group";
4
4
 
@@ -81,67 +81,68 @@ export type RadioCardGroupProps = StylingProps & {
81
81
 
82
82
  const rootClassName = "purpur-radio-card-group";
83
83
 
84
- const RadioCardGroupComponent = (
85
- {
86
- "data-testid": dataTestId,
87
- "aria-labelledby": ariaLabelledby,
88
- children,
89
- className,
90
- items,
91
- heading,
92
- headingTag = "h2",
93
- loop = true,
94
- orientation = "vertical",
95
- radioPosition = "right",
96
- ...props
97
- }: RadioCardGroupProps,
98
- ref: ForwardedRef<HTMLDivElement>
99
- ) => {
100
- const radioCardItemChildren = Children.toArray(children).filter(isRadioCardItem);
84
+ export const RadioCardGroup = forwardRef<HTMLDivElement, RadioCardGroupProps>(
85
+ (
86
+ {
87
+ "data-testid": dataTestId,
88
+ "aria-labelledby": ariaLabelledby,
89
+ children,
90
+ className,
91
+ items,
92
+ heading,
93
+ headingTag = "h2",
94
+ loop = true,
95
+ orientation = "vertical",
96
+ radioPosition = "right",
97
+ ...props
98
+ },
99
+ ref
100
+ ) => {
101
+ const radioCardItemChildren = Children.toArray(children).filter(isRadioCardItem);
101
102
 
102
- return (
103
- <div className={cx(className, `${rootClassName}__container`)} ref={ref}>
104
- {heading && (
105
- <Heading
106
- data-testid={dataTestId ? `${dataTestId}-heading` : undefined}
107
- id={`${props.id}-heading`}
108
- tag={headingTag}
109
- variant="subsection-100"
110
- >
111
- {props.required && <span aria-hidden>{"* "}</span>}
112
- {heading}
113
- </Heading>
114
- )}
115
- {(!!items?.length || radioCardItemChildren.length) && (
116
- <RadixRadioGroup.Root
117
- {...props}
118
- aria-labelledby={ariaLabelledby || (heading ? `${props.id}-heading` : undefined)}
119
- className={cx(
120
- rootClassName,
121
- `${rootClassName}--${orientation}`,
122
- `${rootClassName}--radio-${radioPosition}`
123
- )}
124
- data-testid={dataTestId}
125
- loop={loop}
126
- >
127
- {items?.map((item) => (
128
- <RadioCardItem
129
- key={item.id}
130
- {...item}
131
- disabled={item.disabled || props.disabled}
132
- data-testid={dataTestId ? `${dataTestId}-item` : undefined}
133
- />
134
- ))}
135
- {Children.map(radioCardItemChildren, (child) =>
136
- cloneElement(child, { disabled: child.props.disabled || props.disabled })
137
- )}
138
- </RadixRadioGroup.Root>
139
- )}
140
- </div>
141
- );
142
- };
103
+ return (
104
+ <div className={cx(className, `${rootClassName}__container`)} ref={ref}>
105
+ {heading && (
106
+ <Heading
107
+ data-testid={dataTestId ? `${dataTestId}-heading` : undefined}
108
+ id={`${props.id}-heading`}
109
+ tag={headingTag}
110
+ variant="subsection-100"
111
+ >
112
+ {props.required && <span aria-hidden>{"* "}</span>}
113
+ {heading}
114
+ </Heading>
115
+ )}
116
+ {(!!items?.length || radioCardItemChildren.length) && (
117
+ <RadixRadioGroup.Root
118
+ {...props}
119
+ aria-labelledby={ariaLabelledby || (heading ? `${props.id}-heading` : undefined)}
120
+ className={cx(
121
+ rootClassName,
122
+ `${rootClassName}--${orientation}`,
123
+ `${rootClassName}--radio-${radioPosition}`
124
+ )}
125
+ data-testid={dataTestId}
126
+ loop={loop}
127
+ >
128
+ {items?.map((item) => (
129
+ <RadioCardItem
130
+ key={item.id}
131
+ {...item}
132
+ disabled={item.disabled || props.disabled}
133
+ data-testid={dataTestId ? `${dataTestId}-item` : undefined}
134
+ />
135
+ ))}
136
+ {Children.map(radioCardItemChildren, (child) =>
137
+ cloneElement(child, { disabled: child.props.disabled || props.disabled })
138
+ )}
139
+ </RadixRadioGroup.Root>
140
+ )}
141
+ </div>
142
+ );
143
+ }
144
+ );
143
145
 
144
- export const RadioCardGroup = forwardRef(RadioCardGroupComponent);
145
146
  RadioCardGroup.displayName = "RadioCardGroup";
146
147
 
147
148
  // RadioCardItem must be exported after `RadioCardGroup` for the Storybook controls to be generated from RadioCardGroup props
@@ -1,11 +1,5 @@
1
- import React, {
2
- type ForwardedRef,
3
- forwardRef,
4
- type HTMLAttributes,
5
- isValidElement,
6
- type ReactElement,
7
- type ReactNode,
8
- } from "react";
1
+ import React, { forwardRef, isValidElement, type ReactElement, type ReactNode } from "react";
2
+ import type { BaseProps } from "@purpurds/common-types";
9
3
  import { Paragraph } from "@purpurds/paragraph";
10
4
  import * as RadixRadioGroup from "@radix-ui/react-radio-group";
11
5
 
@@ -23,13 +17,11 @@ type NonNullCustomElement =
23
17
  | ((props: { disabled?: boolean }) => NonNullable<ReactNode>)
24
18
  | NonNullable<ReactNode>;
25
19
 
26
- export type RadioCardItemProps = Omit<HTMLAttributes<HTMLDivElement>, "id" | "title"> & {
27
- ["data-testid"]?: string;
20
+ export type RadioCardItemProps = Omit<BaseProps, "id" | "title"> & {
28
21
  /**
29
22
  * `string | ReactNode | (props: { disabled?: boolean }) => ReactNode`
30
23
  */
31
24
  body?: string | CustomElement;
32
- children?: ReactNode;
33
25
  disabled?: boolean;
34
26
  id: string;
35
27
  /**
@@ -59,73 +51,71 @@ const renderCustomElement = (
59
51
  { disabled }: Pick<RadioCardItemProps, "disabled">
60
52
  ) => (typeof element === "function" ? element({ disabled }) : element);
61
53
 
62
- const RadioCardItemComponent = (
63
- { title, ...propsx }: RadioCardItemProps,
64
- ref: ForwardedRef<HTMLDivElement>
65
- ) => {
66
- const { ["data-testid"]: dataTestid, body, children, disabled, id, image, value } = propsx;
54
+ export const RadioCardItem = forwardRef<HTMLDivElement, RadioCardItemProps>(
55
+ ({ title, ...propsx }, ref) => {
56
+ const { ["data-testid"]: dataTestid, body, children, disabled, id, image, value } = propsx;
67
57
 
68
- const props = { title, ...propsx };
58
+ const props = { title, ...propsx };
69
59
 
70
- return (
71
- <div className={cx(`${rootClassName}-container`)} ref={ref}>
72
- <RadixRadioGroup.Item
73
- className={cx(rootClassName)}
74
- data-testid={dataTestid}
75
- disabled={disabled}
76
- id={id}
77
- value={value}
78
- >
79
- {image && (
80
- <span className={cx(`${rootClassName}-image-container`)}>
81
- {isRadioCardItemImageProps(image) ? (
82
- <RadioCardImage {...image} data-testid={dataTestid && `${dataTestid}-image`} />
83
- ) : (
84
- renderCustomElement(image, props)
85
- )}
86
- </span>
87
- )}
88
- <span className={cx(`${rootClassName}-content`)}>
89
- <span className={cx(`${rootClassName}-top-container`)}>
90
- {typeof title === "string" ? (
91
- <Paragraph
92
- className={cx(`${rootClassName}-title`)}
93
- data-testid={dataTestid && `${dataTestid}-title`}
94
- variant="paragraph-100"
95
- disabled={disabled}
96
- >
97
- {title}
98
- </Paragraph>
99
- ) : (
100
- renderCustomElement(title, props)
101
- )}
102
- <span className={cx(`${rootClassName}-radio`)}>
103
- <RadixRadioGroup.Indicator className={cx(`${rootClassName}-indicator`)} />
60
+ return (
61
+ <div className={cx(`${rootClassName}-container`)} ref={ref}>
62
+ <RadixRadioGroup.Item
63
+ className={cx(rootClassName)}
64
+ data-testid={dataTestid}
65
+ disabled={disabled}
66
+ id={id}
67
+ value={value}
68
+ >
69
+ {image && (
70
+ <span className={cx(`${rootClassName}-image-container`)}>
71
+ {isRadioCardItemImageProps(image) ? (
72
+ <RadioCardImage {...image} data-testid={dataTestid && `${dataTestid}-image`} />
73
+ ) : (
74
+ renderCustomElement(image, props)
75
+ )}
104
76
  </span>
105
- </span>
106
- {body && (
107
- <span className={cx(`${rootClassName}-bottom-container`)}>
108
- {typeof body === "string" ? (
77
+ )}
78
+ <span className={cx(`${rootClassName}-content`)}>
79
+ <span className={cx(`${rootClassName}-top-container`)}>
80
+ {typeof title === "string" ? (
109
81
  <Paragraph
110
- data-testid={dataTestid && `${dataTestid}-body`}
82
+ className={cx(`${rootClassName}-title`)}
83
+ data-testid={dataTestid && `${dataTestid}-title`}
111
84
  variant="paragraph-100"
112
85
  disabled={disabled}
113
86
  >
114
- {body}
87
+ {title}
115
88
  </Paragraph>
116
89
  ) : (
117
- renderCustomElement(body, props)
90
+ renderCustomElement(title, props)
118
91
  )}
92
+ <span className={cx(`${rootClassName}-radio`)}>
93
+ <RadixRadioGroup.Indicator className={cx(`${rootClassName}-indicator`)} />
94
+ </span>
119
95
  </span>
120
- )}
121
- </span>
122
- </RadixRadioGroup.Item>
123
- {children}
124
- </div>
125
- );
126
- };
96
+ {body && (
97
+ <span className={cx(`${rootClassName}-bottom-container`)}>
98
+ {typeof body === "string" ? (
99
+ <Paragraph
100
+ data-testid={dataTestid && `${dataTestid}-body`}
101
+ variant="paragraph-100"
102
+ disabled={disabled}
103
+ >
104
+ {body}
105
+ </Paragraph>
106
+ ) : (
107
+ renderCustomElement(body, props)
108
+ )}
109
+ </span>
110
+ )}
111
+ </span>
112
+ </RadixRadioGroup.Item>
113
+ {children}
114
+ </div>
115
+ );
116
+ }
117
+ );
127
118
 
128
- export const RadioCardItem = forwardRef(RadioCardItemComponent);
129
119
  RadioCardItem.displayName = "RadioCardItem";
130
120
 
131
121
  export const isRadioCardItem = (child?: ReactNode): child is ReactElement<RadioCardItemProps> =>