@purpurds/radio-card-group 7.6.1 → 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.
- package/dist/LICENSE.txt +3 -3
- package/dist/radio-card-group.cjs.js +5 -5
- package/dist/radio-card-group.cjs.js.map +1 -1
- package/dist/radio-card-group.d.ts.map +1 -1
- package/dist/radio-card-group.es.js +354 -358
- package/dist/radio-card-group.es.js.map +1 -1
- package/dist/radio-card-item.d.ts +4 -34
- package/dist/radio-card-item.d.ts.map +1 -1
- package/package.json +10 -9
- package/src/radio-card-group.tsx +61 -60
- package/src/radio-card-item.tsx +56 -66
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { default as 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<
|
|
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<
|
|
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,
|
|
1
|
+
{"version":3,"file":"radio-card-item.d.ts","sourceRoot":"","sources":["../src/radio-card-item.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAA8B,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC7F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAKxD,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,SAAS,EAAE,IAAI,GAAG,OAAO,CAAC,GAAG;IACjE;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX;;;;;;;;;;;;;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.
|
|
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/
|
|
21
|
-
"@purpurds/
|
|
22
|
-
"@purpurds/
|
|
23
|
-
"@purpurds/skeleton": "7.
|
|
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/
|
|
45
|
+
"@purpurds/button": "7.7.0",
|
|
46
|
+
"@purpurds/badge": "7.7.0",
|
|
45
47
|
"@purpurds/component-rig": "1.0.0",
|
|
46
|
-
"@purpurds/
|
|
47
|
-
"@purpurds/
|
|
48
|
-
"@purpurds/text-field": "7.6.1"
|
|
48
|
+
"@purpurds/grid": "7.7.0",
|
|
49
|
+
"@purpurds/text-field": "7.7.0"
|
|
49
50
|
},
|
|
50
51
|
"peerDependencies": {
|
|
51
52
|
"@types/react": "^18 || ^19",
|
package/src/radio-card-group.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { Children, cloneElement,
|
|
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
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
package/src/radio-card-item.tsx
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
|
|
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<
|
|
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
|
|
63
|
-
{ title, ...propsx }
|
|
64
|
-
|
|
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
|
-
|
|
58
|
+
const props = { title, ...propsx };
|
|
69
59
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
106
|
-
{
|
|
107
|
-
<span className={cx(`${rootClassName}-
|
|
108
|
-
{typeof
|
|
77
|
+
)}
|
|
78
|
+
<span className={cx(`${rootClassName}-content`)}>
|
|
79
|
+
<span className={cx(`${rootClassName}-top-container`)}>
|
|
80
|
+
{typeof title === "string" ? (
|
|
109
81
|
<Paragraph
|
|
110
|
-
|
|
82
|
+
className={cx(`${rootClassName}-title`)}
|
|
83
|
+
data-testid={dataTestid && `${dataTestid}-title`}
|
|
111
84
|
variant="paragraph-100"
|
|
112
85
|
disabled={disabled}
|
|
113
86
|
>
|
|
114
|
-
{
|
|
87
|
+
{title}
|
|
115
88
|
</Paragraph>
|
|
116
89
|
) : (
|
|
117
|
-
renderCustomElement(
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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> =>
|