@bonprix-ds/react-radio-group 1.0.2 → 1.0.4
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/index.d.ts +11 -11
- package/dist/index.js +2 -91
- package/dist/src/RadioGroup2.js +11 -0
- package/dist/src/RadioGroup2.js.map +1 -0
- package/dist/src/RadioGroupContext.js +11 -0
- package/dist/src/RadioGroupContext.js.map +1 -0
- package/dist/src/RadioGroupItem.js +51 -0
- package/dist/src/RadioGroupItem.js.map +1 -0
- package/dist/src/RadioGroupRoot.js +52 -0
- package/dist/src/RadioGroupRoot.js.map +1 -0
- package/dist/src/useConsumeRadioGroup.js +8 -0
- package/dist/src/useConsumeRadioGroup.js.map +1 -0
- package/package.json +4 -4
- package/dist/index.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ControlGroupProps } from '@bonprix-ds/utils';
|
|
2
2
|
import { default as default_2 } from 'react';
|
|
3
|
-
import { FC } from 'react';
|
|
4
3
|
import { ReactNode } from 'react';
|
|
5
4
|
|
|
6
5
|
declare interface ControlledInputProps extends Omit<ControlGroupProps, "componentName"> {
|
|
@@ -8,7 +7,17 @@ declare interface ControlledInputProps extends Omit<ControlGroupProps, "componen
|
|
|
8
7
|
onChange: (value: string) => void;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
declare
|
|
10
|
+
declare const RadioGroup: {
|
|
11
|
+
(props: RadioGroupProps): default_2.JSX.Element;
|
|
12
|
+
displayName: string;
|
|
13
|
+
Item: {
|
|
14
|
+
({ value, label, additional, suffix }: RadioGroupItemProps): default_2.JSX.Element;
|
|
15
|
+
displayName: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export default RadioGroup;
|
|
19
|
+
|
|
20
|
+
declare interface RadioGroupItemProps {
|
|
12
21
|
/** The value of the radio button. */
|
|
13
22
|
value: string;
|
|
14
23
|
/** The label of the radio button. */
|
|
@@ -19,17 +28,8 @@ declare interface Props {
|
|
|
19
28
|
additional?: ReactNode;
|
|
20
29
|
}
|
|
21
30
|
|
|
22
|
-
declare const RadioGroup: FC<RadioGroupProps> & Subcomponents;
|
|
23
|
-
export default RadioGroup;
|
|
24
|
-
|
|
25
|
-
declare const RadioGroupItem: ({ value, label, additional, suffix }: Props) => default_2.JSX.Element;
|
|
26
|
-
|
|
27
31
|
export declare type RadioGroupProps = ControlledInputProps | UncontrolledInputProps;
|
|
28
32
|
|
|
29
|
-
declare interface Subcomponents {
|
|
30
|
-
Item: typeof RadioGroupItem;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
33
|
declare interface UncontrolledInputProps extends Omit<ControlGroupProps, "componentName"> {
|
|
34
34
|
value?: never;
|
|
35
35
|
defaultValue: string;
|
package/dist/index.js
CHANGED
|
@@ -1,91 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { createContext as t, useContext as n, useState as r } from "react";
|
|
4
|
-
import * as i from "@radix-ui/react-radio-group";
|
|
5
|
-
import { tv as a } from "tailwind-variants";
|
|
6
|
-
import { jsx as o, jsxs as s } from "react/jsx-runtime";
|
|
7
|
-
//#region src/RadioGroupContext.ts
|
|
8
|
-
var c = t({
|
|
9
|
-
disabled: !1,
|
|
10
|
-
checkedValue: ""
|
|
11
|
-
}), l = () => n(c), u = a({
|
|
12
|
-
base: "preflight typography-input-text flex gap-2 justify-between text-clr-primary",
|
|
13
|
-
slots: {
|
|
14
|
-
item: ["w-6 h-6 border text-inherit border-current rounded-full shrink-0", "focus-visible:outline focus-visible:outline-current focus-visible:outline-1 focus-visible:outline-offset-2"],
|
|
15
|
-
indicatorAndLabel: "flex gap-2 py-3 flex-1 items-center",
|
|
16
|
-
indicator: ["flex items-center justify-center w-full h-full relative after:content-[''] after:block after:w-2.5", "after:h-2.5 after:bg-current after:rounded-[50%]"],
|
|
17
|
-
suffix: "h-12 flex-none"
|
|
18
|
-
},
|
|
19
|
-
variants: { disabled: {
|
|
20
|
-
true: {
|
|
21
|
-
base: "text-clr-disabled",
|
|
22
|
-
item: "bg-clr-bg-disabled"
|
|
23
|
-
},
|
|
24
|
-
false: { base: "hover:cursor-pointer hover:text-clr-on-bg-low" }
|
|
25
|
-
} }
|
|
26
|
-
}), d = ({ value: e, label: t, additional: n, suffix: r }) => {
|
|
27
|
-
let { disabled: a, checkedValue: c } = l(), { base: d, item: f, indicatorAndLabel: p, indicator: m, suffix: h } = u({ disabled: a }), g = e === "" ? "hidden" : void 0, _ = e === c;
|
|
28
|
-
return /* @__PURE__ */ s("div", {
|
|
29
|
-
className: g,
|
|
30
|
-
"data-bpds-radio-group-item": "",
|
|
31
|
-
"data-bpds-has-suffix": !!r,
|
|
32
|
-
"data-bpds-has-additional": !!n,
|
|
33
|
-
children: [/* @__PURE__ */ s("label", {
|
|
34
|
-
className: d(),
|
|
35
|
-
children: [/* @__PURE__ */ s("span", {
|
|
36
|
-
className: p(),
|
|
37
|
-
children: [/* @__PURE__ */ o(i.Item, {
|
|
38
|
-
value: e,
|
|
39
|
-
className: f(),
|
|
40
|
-
disabled: a,
|
|
41
|
-
children: /* @__PURE__ */ o(i.Indicator, { className: m() })
|
|
42
|
-
}), t]
|
|
43
|
-
}), r && /* @__PURE__ */ o("span", {
|
|
44
|
-
className: h(),
|
|
45
|
-
children: r
|
|
46
|
-
})]
|
|
47
|
-
}), n && _ && /* @__PURE__ */ o("div", { children: n })]
|
|
48
|
-
});
|
|
49
|
-
}, f = ({ value: t, onChange: n, label: a, "aria-label": l, "aria-labelledby": u, children: f, name: p, disabled: m = !1, error: h = !1, errorText: g = "", helperText: _, required: v = !1, divider: y = !1, horizontalPadding: b = !1, ...x }) => {
|
|
50
|
-
let S = "defaultValue" in x ? x.defaultValue : void 0, [C, w] = r(S ?? ""), T = t !== void 0, E = T ? t : C;
|
|
51
|
-
return /* @__PURE__ */ o(e, {
|
|
52
|
-
label: a,
|
|
53
|
-
"aria-label": l,
|
|
54
|
-
"aria-labelledby": u,
|
|
55
|
-
name: p,
|
|
56
|
-
disabled: m,
|
|
57
|
-
helperText: _,
|
|
58
|
-
error: h,
|
|
59
|
-
errorText: g,
|
|
60
|
-
required: v,
|
|
61
|
-
componentName: "radio-group",
|
|
62
|
-
divider: y,
|
|
63
|
-
horizontalPadding: b,
|
|
64
|
-
children: /* @__PURE__ */ o(i.Root, {
|
|
65
|
-
name: p,
|
|
66
|
-
value: t,
|
|
67
|
-
onValueChange: (e) => {
|
|
68
|
-
T || w(e), n?.(e);
|
|
69
|
-
},
|
|
70
|
-
orientation: "vertical",
|
|
71
|
-
disabled: m,
|
|
72
|
-
required: v,
|
|
73
|
-
defaultValue: S,
|
|
74
|
-
children: /* @__PURE__ */ s(c, {
|
|
75
|
-
value: {
|
|
76
|
-
disabled: m,
|
|
77
|
-
checkedValue: E
|
|
78
|
-
},
|
|
79
|
-
children: [/* @__PURE__ */ o(d, {
|
|
80
|
-
label: "",
|
|
81
|
-
value: ""
|
|
82
|
-
}), f]
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
f.Item = d;
|
|
88
|
-
//#endregion
|
|
89
|
-
export { f as default };
|
|
90
|
-
|
|
91
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import e from "./src/RadioGroup2.js";
|
|
2
|
+
export { e as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import e from "./RadioGroupItem.js";
|
|
2
|
+
import t from "./RadioGroupRoot.js";
|
|
3
|
+
import "react";
|
|
4
|
+
import { jsx as n } from "react/jsx-runtime";
|
|
5
|
+
//#region src/RadioGroup.tsx
|
|
6
|
+
var r = (e) => /* @__PURE__ */ n(t, { ...e });
|
|
7
|
+
r.displayName = "RadioGroup", r.Item = e;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { r as default };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=RadioGroup2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RadioGroup2.js","names":[],"sources":["../../src/RadioGroup.tsx"],"sourcesContent":["import React from \"react\";\n\nimport RadioGroupItem from \"./RadioGroupItem\";\nimport RadioGroupRoot, { type Props } from \"./RadioGroupRoot\";\n\nexport type { Props };\n\nconst RadioGroup = (props: Props) => <RadioGroupRoot {...props} />;\n\nRadioGroup.displayName = \"RadioGroup\";\n\nRadioGroup.Item = RadioGroupItem;\n\nexport default RadioGroup;\n"],"mappings":";;;;;AAOA,IAAM,KAAc,MAAiB,kBAAC,GAAD,EAAgB,GAAI,EAAQ,CAAA;AAEjE,EAAW,cAAc,cAEzB,EAAW,OAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RadioGroupContext.js","names":[],"sources":["../../src/RadioGroupContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext } from \"react\";\n\nexport interface RadioGroupContextProps {\n disabled: boolean;\n checkedValue: string;\n}\n\nconst RadioGroupContext = createContext<RadioGroupContextProps>({\n disabled: false,\n checkedValue: \"\",\n});\n\nexport default RadioGroupContext;\n"],"mappings":";;;AASA,IAAM,IAAoB,EAAsC;CAC9D,UAAU;CACV,cAAc;AAChB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import e from "./useConsumeRadioGroup.js";
|
|
3
|
+
import "react";
|
|
4
|
+
import { tv as t } from "tailwind-variants";
|
|
5
|
+
import * as n from "@radix-ui/react-radio-group";
|
|
6
|
+
import { jsx as r, jsxs as i } from "react/jsx-runtime";
|
|
7
|
+
//#region src/RadioGroupItem.tsx
|
|
8
|
+
var a = t({
|
|
9
|
+
base: "preflight typography-input-text flex gap-2 justify-between text-clr-primary",
|
|
10
|
+
slots: {
|
|
11
|
+
item: ["w-6 h-6 border text-inherit border-current rounded-full shrink-0", "focus-visible:outline focus-visible:outline-current focus-visible:outline-1 focus-visible:outline-offset-2"],
|
|
12
|
+
indicatorAndLabel: "flex gap-2 py-3 flex-1 items-center",
|
|
13
|
+
indicator: ["flex items-center justify-center w-full h-full relative after:content-[''] after:block after:w-2.5", "after:h-2.5 after:bg-current after:rounded-[50%]"],
|
|
14
|
+
suffix: "h-12 flex-none"
|
|
15
|
+
},
|
|
16
|
+
variants: { disabled: {
|
|
17
|
+
true: {
|
|
18
|
+
base: "text-clr-disabled",
|
|
19
|
+
item: "bg-clr-bg-disabled"
|
|
20
|
+
},
|
|
21
|
+
false: { base: "hover:cursor-pointer hover:text-clr-on-bg-low" }
|
|
22
|
+
} }
|
|
23
|
+
}), o = ({ value: t, label: o, additional: s, suffix: c }) => {
|
|
24
|
+
let { disabled: l, checkedValue: u } = e(), { base: d, item: f, indicatorAndLabel: p, indicator: m, suffix: h } = a({ disabled: l }), g = t === "" ? "hidden" : void 0, _ = t === u;
|
|
25
|
+
return /* @__PURE__ */ i("div", {
|
|
26
|
+
className: g,
|
|
27
|
+
"data-bpds-radio-group-item": "",
|
|
28
|
+
"data-bpds-has-suffix": !!c,
|
|
29
|
+
"data-bpds-has-additional": !!s,
|
|
30
|
+
children: [/* @__PURE__ */ i("label", {
|
|
31
|
+
className: d(),
|
|
32
|
+
children: [/* @__PURE__ */ i("span", {
|
|
33
|
+
className: p(),
|
|
34
|
+
children: [/* @__PURE__ */ r(n.Item, {
|
|
35
|
+
value: t,
|
|
36
|
+
className: f(),
|
|
37
|
+
disabled: l,
|
|
38
|
+
children: /* @__PURE__ */ r(n.Indicator, { className: m() })
|
|
39
|
+
}), o]
|
|
40
|
+
}), c && /* @__PURE__ */ r("span", {
|
|
41
|
+
className: h(),
|
|
42
|
+
children: c
|
|
43
|
+
})]
|
|
44
|
+
}), s && _ && /* @__PURE__ */ r("div", { children: s })]
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
o.displayName = "RadioGroup.Item";
|
|
48
|
+
//#endregion
|
|
49
|
+
export { o as default };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=RadioGroupItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RadioGroupItem.js","names":[],"sources":["../../src/RadioGroupItem.tsx"],"sourcesContent":["\"use client\";\n\nimport React, { ReactNode } from \"react\";\nimport { tv } from \"tailwind-variants\";\nimport * as RadioGroupPrimitive from \"@radix-ui/react-radio-group\";\n\nimport useConsumeRadioGroup from \"./useConsumeRadioGroup\";\n\nconst generateClasses = tv({\n base: \"preflight typography-input-text flex gap-2 justify-between text-clr-primary\",\n slots: {\n item: [\n \"w-6 h-6 border text-inherit border-current rounded-full shrink-0\",\n \"focus-visible:outline focus-visible:outline-current focus-visible:outline-1 focus-visible:outline-offset-2\",\n ],\n // py is used instead of h-8, because h-8 will make the item label vertically centered\n indicatorAndLabel: \"flex gap-2 py-3 flex-1 items-center\",\n indicator: [\n \"flex items-center justify-center w-full h-full relative after:content-[''] after:block after:w-2.5\",\n \"after:h-2.5 after:bg-current after:rounded-[50%]\",\n ],\n // set height explicitly to prevent suffix from breaking layout and spacings\n suffix: \"h-12 flex-none\",\n },\n variants: {\n disabled: {\n true: {\n base: \"text-clr-disabled\",\n item: \"bg-clr-bg-disabled\",\n },\n false: {\n base: \"hover:cursor-pointer hover:text-clr-on-bg-low\",\n },\n },\n },\n});\n\nexport interface RadioGroupItemProps {\n /** The value of the radio button. */\n value: string;\n /** The label of the radio button. */\n label: ReactNode;\n /** Suffix that will be placed on the far right side inside the `<label>` to further visualize the item's value, e.g. with icon(s) or logo(s). Make sure to only include allowed children here to avoid irregular HTML markup. */\n suffix?: ReactNode;\n /** Additional content to be displayed when item is selected. */\n additional?: ReactNode;\n}\n\nconst RadioGroupItem = ({ value, label, additional, suffix }: RadioGroupItemProps) => {\n const { disabled, checkedValue } = useConsumeRadioGroup();\n const { base, item, indicatorAndLabel, indicator, suffix: suffixClasses } = generateClasses({ disabled });\n const hidden = value === \"\" ? \"hidden\" : undefined;\n\n const isChecked = value === checkedValue;\n\n return (\n <div className={hidden} data-bpds-radio-group-item=\"\" data-bpds-has-suffix={!!suffix} data-bpds-has-additional={!!additional}>\n <label className={base()}>\n <span className={indicatorAndLabel()}>\n <RadioGroupPrimitive.Item value={value} className={item()} disabled={disabled}>\n <RadioGroupPrimitive.Indicator className={indicator()} />\n </RadioGroupPrimitive.Item>\n {label}\n </span>\n {suffix && <span className={suffixClasses()}>{suffix}</span>}\n </label>\n {additional && isChecked && <div>{additional}</div>}\n </div>\n );\n};\n\nRadioGroupItem.displayName = \"RadioGroup.Item\";\n\nexport default RadioGroupItem;\n"],"mappings":";;;;;;;AAQA,IAAM,IAAkB,EAAG;CACzB,MAAM;CACN,OAAO;EACL,MAAM,CACJ,oEACA,4GACF;EAEA,mBAAmB;EACnB,WAAW,CACT,sGACA,kDACF;EAEA,QAAQ;CACV;CACA,UAAU,EACR,UAAU;EACR,MAAM;GACJ,MAAM;GACN,MAAM;EACR;EACA,OAAO,EACL,MAAM,gDACR;CACF,EACF;AACF,CAAC,GAaK,KAAkB,EAAE,UAAO,UAAO,eAAY,gBAAkC;CACpF,IAAM,EAAE,aAAU,oBAAiB,EAAqB,GAClD,EAAE,SAAM,SAAM,sBAAmB,cAAW,QAAQ,MAAkB,EAAgB,EAAE,YAAS,CAAC,GAClG,IAAS,MAAU,KAAK,WAAW,KAAA,GAEnC,IAAY,MAAU;CAE5B,OACE,kBAAC,OAAD;EAAK,WAAW;EAAQ,8BAA2B;EAAG,wBAAsB,CAAC,CAAC;EAAQ,4BAA0B,CAAC,CAAC;EAAlH,UAAA,CACE,kBAAC,SAAD;GAAO,WAAW,EAAK;GAAvB,UAAA,CACE,kBAAC,QAAD;IAAM,WAAW,EAAkB;IAAnC,UAAA,CACE,kBAAC,EAAoB,MAArB;KAAiC;KAAO,WAAW,EAAK;KAAa;KACnE,UAAA,kBAAC,EAAoB,WAArB,EAA+B,WAAW,EAAU,EAAI,CAAA;IAChC,CAAA,GACzB,CACG;GACL,CAAA,GAAA,KAAU,kBAAC,QAAD;IAAM,WAAW,EAAc;IAAI,UAAA;GAAa,CAAA,CACtD;EACN,CAAA,GAAA,KAAc,KAAa,kBAAC,OAAD,EAAA,UAAM,EAAgB,CAAA,CAC/C;;AAET;AAEA,EAAe,cAAc"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import e from "./RadioGroupContext.js";
|
|
3
|
+
import t from "./RadioGroupItem.js";
|
|
4
|
+
/* empty css */
|
|
5
|
+
import { useState as n } from "react";
|
|
6
|
+
import * as r from "@radix-ui/react-radio-group";
|
|
7
|
+
import { jsx as i, jsxs as a } from "react/jsx-runtime";
|
|
8
|
+
import { SelectionControlGroup as o } from "@bonprix-ds/internal-components";
|
|
9
|
+
//#region src/RadioGroupRoot.tsx
|
|
10
|
+
var s = ({ value: s, onChange: c, label: l, "aria-label": u, "aria-labelledby": d, children: f, name: p, disabled: m = !1, error: h = !1, errorText: g = "", helperText: _, required: v = !1, divider: y = !1, horizontalPadding: b = !1, ...x }) => {
|
|
11
|
+
let S = "defaultValue" in x ? x.defaultValue : void 0, [C, w] = n(S ?? ""), T = s !== void 0, E = T ? s : C;
|
|
12
|
+
return /* @__PURE__ */ i(o, {
|
|
13
|
+
label: l,
|
|
14
|
+
"aria-label": u,
|
|
15
|
+
"aria-labelledby": d,
|
|
16
|
+
name: p,
|
|
17
|
+
disabled: m,
|
|
18
|
+
helperText: _,
|
|
19
|
+
error: h,
|
|
20
|
+
errorText: g,
|
|
21
|
+
required: v,
|
|
22
|
+
componentName: "radio-group",
|
|
23
|
+
divider: y,
|
|
24
|
+
horizontalPadding: b,
|
|
25
|
+
children: /* @__PURE__ */ i(r.Root, {
|
|
26
|
+
name: p,
|
|
27
|
+
value: s,
|
|
28
|
+
onValueChange: (e) => {
|
|
29
|
+
T || w(e), c?.(e);
|
|
30
|
+
},
|
|
31
|
+
orientation: "vertical",
|
|
32
|
+
disabled: m,
|
|
33
|
+
required: v,
|
|
34
|
+
defaultValue: S,
|
|
35
|
+
children: /* @__PURE__ */ a(e, {
|
|
36
|
+
value: {
|
|
37
|
+
disabled: m,
|
|
38
|
+
checkedValue: E
|
|
39
|
+
},
|
|
40
|
+
children: [/* @__PURE__ */ i(t, {
|
|
41
|
+
label: "",
|
|
42
|
+
value: ""
|
|
43
|
+
}), f]
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
s.displayName = "RadioGroup";
|
|
49
|
+
//#endregion
|
|
50
|
+
export { s as default };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=RadioGroupRoot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RadioGroupRoot.js","names":[],"sources":["../../src/RadioGroupRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport { SelectionControlGroup } from \"@bonprix-ds/internal-components\";\nimport { ControlGroupProps as RadioControlGroupProps } from \"@bonprix-ds/utils\";\nimport React, { useState } from \"react\";\nimport * as RadioGroupPrimitive from \"@radix-ui/react-radio-group\";\n\nimport RadioGroupContext from \"./RadioGroupContext\";\nimport RadioGroupItem from \"./RadioGroupItem\";\n\nimport \"./RadioGroup.css\";\n\ninterface ControlledInputProps extends Omit<RadioControlGroupProps, \"componentName\"> {\n value: string;\n onChange: (value: string) => void;\n}\n\ninterface UncontrolledInputProps extends Omit<RadioControlGroupProps, \"componentName\"> {\n value?: never;\n defaultValue: string;\n onChange?: (value: string) => void;\n}\n\nexport type Props = ControlledInputProps | UncontrolledInputProps;\n\nconst RadioGroupRoot = ({\n value,\n onChange,\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n children,\n name,\n disabled = false,\n error = false,\n errorText = \"\",\n helperText,\n required = false,\n divider = false,\n horizontalPadding = false,\n ...unionProps\n}: Props) => {\n const defaultValue = \"defaultValue\" in unionProps ? unionProps.defaultValue : undefined;\n\n // For the uncontrolled variant, track the checked value internally so the Context\n // (and therefore `isChecked` in `RadioGroup.Item`) stays up-to-date.\n const [internalValue, setInternalValue] = useState(defaultValue ?? \"\");\n const isControlled = value !== undefined;\n const checkedValue = isControlled ? value : internalValue;\n\n const handleValueChange = (newValue: string) => {\n if (!isControlled) setInternalValue(newValue);\n onChange?.(newValue);\n };\n\n return (\n <SelectionControlGroup\n label={label}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n name={name}\n disabled={disabled}\n helperText={helperText}\n error={error}\n errorText={errorText}\n required={required}\n componentName=\"radio-group\"\n divider={divider}\n horizontalPadding={horizontalPadding}\n >\n <RadioGroupPrimitive.Root\n name={name}\n value={value}\n onValueChange={handleValueChange}\n orientation=\"vertical\" // disable navigation via \"←\" and \"→\" keys, only \"↑\" and \"↓\" can be used\n disabled={disabled}\n required={required}\n defaultValue={defaultValue}\n >\n <RadioGroupContext value={{ disabled, checkedValue }}>\n {/* Creating a 'phantom' option is technically more correct for the case when we pass an empty string as a value (initially to not preselect any option in the group). */}\n <RadioGroupItem label=\"\" value=\"\" />\n {children}\n </RadioGroupContext>\n </RadioGroupPrimitive.Root>\n </SelectionControlGroup>\n );\n};\n\nRadioGroupRoot.displayName = \"RadioGroup\";\n\nexport default RadioGroupRoot;\n"],"mappings":";;;;;;;;;AAyBA,IAAM,KAAkB,EACtB,UACA,aACA,UACA,cAAc,GACd,mBAAmB,GACnB,aACA,SACA,cAAW,IACX,WAAQ,IACR,eAAY,IACZ,eACA,cAAW,IACX,aAAU,IACV,uBAAoB,IACpB,GAAG,QACQ;CACX,IAAM,IAAe,kBAAkB,IAAa,EAAW,eAAe,KAAA,GAIxE,CAAC,GAAe,KAAoB,EAAS,KAAgB,EAAE,GAC/D,IAAe,MAAU,KAAA,GACzB,IAAe,IAAe,IAAQ;CAO5C,OACE,kBAAC,GAAD;EACS;EACP,cAAY;EACZ,mBAAiB;EACX;EACI;EACE;EACL;EACI;EACD;EACV,eAAc;EACL;EACU;EAEnB,UAAA,kBAAC,EAAoB,MAArB;GACQ;GACC;GACP,gBAvBqB,MAAqB;IAE9C,AADK,KAAc,EAAiB,CAAQ,GAC5C,IAAW,CAAQ;GACrB;GAqBM,aAAY;GACF;GACA;GACI;GAEd,UAAA,kBAAC,GAAD;IAAmB,OAAO;KAAE;KAAU;IAAa;IAAnD,UAAA,CAEE,kBAAC,GAAD;KAAgB,OAAM;KAAG,OAAM;IAAI,CAAA,GAClC,CACgB;;EACK,CAAA;CACL,CAAA;AAE3B;AAEA,EAAe,cAAc"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConsumeRadioGroup.js","names":[],"sources":["../../src/useConsumeRadioGroup.ts"],"sourcesContent":["import { useContext } from \"react\";\n\nimport RadioGroupContext from \"./RadioGroupContext\";\n\nconst useConsumeRadioGroup = () => {\n return useContext(RadioGroupContext);\n};\n\nexport default useConsumeRadioGroup;\n"],"mappings":";;;AAIA,IAAM,UACG,EAAW,CAAiB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bonprix-ds/react-radio-group",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "RadioGroup component, implemented in React, for the Bonprix Design System.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@radix-ui/react-radio-group": "1.4.7",
|
|
35
|
-
"@bonprix-ds/internal-components": "0.1.
|
|
36
|
-
"@bonprix-ds/utils": "0.
|
|
35
|
+
"@bonprix-ds/internal-components": "0.1.3",
|
|
36
|
+
"@bonprix-ds/utils": "0.2.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"react": "^19.0.0",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"tailwind-variants": "0.3.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"vite": "8.2.
|
|
44
|
+
"vite": "8.2.1",
|
|
45
45
|
"@types/react": "19.2.18",
|
|
46
46
|
"@vitejs/plugin-react": "6.0.5",
|
|
47
47
|
"rollup-preserve-directives": "1.1.3",
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/RadioGroupContext.ts","../src/useConsumeRadioGroup.ts","../src/RadioGroupItem.tsx","../src/RadioGroup.tsx"],"sourcesContent":["\"use client\";\n\nimport { createContext } from \"react\";\n\nexport interface RadioGroupContextProps {\n disabled: boolean;\n checkedValue: string;\n}\n\nconst RadioGroupContext = createContext<RadioGroupContextProps>({\n disabled: false,\n checkedValue: \"\",\n});\n\nexport default RadioGroupContext;\n","import { useContext } from \"react\";\n\nimport RadioGroupContext from \"./RadioGroupContext\";\n\nconst useConsumeRadioGroup = () => {\n return useContext(RadioGroupContext);\n};\n\nexport default useConsumeRadioGroup;\n","\"use client\";\n\nimport React, { ReactNode } from \"react\";\nimport { tv } from \"tailwind-variants\";\nimport * as RadioGroupPrimitive from \"@radix-ui/react-radio-group\";\n\nimport useConsumeRadioGroup from \"./useConsumeRadioGroup\";\n\nconst generateClasses = tv({\n base: \"preflight typography-input-text flex gap-2 justify-between text-clr-primary\",\n slots: {\n item: [\n \"w-6 h-6 border text-inherit border-current rounded-full shrink-0\",\n \"focus-visible:outline focus-visible:outline-current focus-visible:outline-1 focus-visible:outline-offset-2\",\n ],\n // py is used instead of h-8, because h-8 will make the item label vertically centered\n indicatorAndLabel: \"flex gap-2 py-3 flex-1 items-center\",\n indicator: [\n \"flex items-center justify-center w-full h-full relative after:content-[''] after:block after:w-2.5\",\n \"after:h-2.5 after:bg-current after:rounded-[50%]\",\n ],\n // set height explicitly to prevent suffix from breaking layout and spacings\n suffix: \"h-12 flex-none\",\n },\n variants: {\n disabled: {\n true: {\n base: \"text-clr-disabled\",\n item: \"bg-clr-bg-disabled\",\n },\n false: {\n base: \"hover:cursor-pointer hover:text-clr-on-bg-low\",\n },\n },\n },\n});\n\ninterface Props {\n /** The value of the radio button. */\n value: string;\n /** The label of the radio button. */\n label: ReactNode;\n /** Suffix that will be placed on the far right side inside the `<label>` to further visualize the item's value, e.g. with icon(s) or logo(s). Make sure to only include allowed children here to avoid irregular HTML markup. */\n suffix?: ReactNode;\n /** Additional content to be displayed when item is selected. */\n additional?: ReactNode;\n}\n\nconst RadioGroupItem = ({ value, label, additional, suffix }: Props) => {\n const { disabled, checkedValue } = useConsumeRadioGroup();\n const { base, item, indicatorAndLabel, indicator, suffix: suffixClasses } = generateClasses({ disabled });\n const hidden = value === \"\" ? \"hidden\" : undefined;\n\n const isChecked = value === checkedValue;\n\n return (\n <div className={hidden} data-bpds-radio-group-item=\"\" data-bpds-has-suffix={!!suffix} data-bpds-has-additional={!!additional}>\n <label className={base()}>\n <span className={indicatorAndLabel()}>\n <RadioGroupPrimitive.Item value={value} className={item()} disabled={disabled}>\n <RadioGroupPrimitive.Indicator className={indicator()} />\n </RadioGroupPrimitive.Item>\n {label}\n </span>\n {suffix && <span className={suffixClasses()}>{suffix}</span>}\n </label>\n {additional && isChecked && <div>{additional}</div>}\n </div>\n );\n};\n\nexport default RadioGroupItem;\n","\"use client\";\n\nimport { SelectionControlGroup } from \"@bonprix-ds/internal-components\";\nimport { ControlGroupProps as RadioControlGroupProps } from \"@bonprix-ds/utils\";\nimport React, { FC, useState } from \"react\";\nimport * as RadioGroupPrimitive from \"@radix-ui/react-radio-group\";\n\nimport RadioGroupContext from \"./RadioGroupContext\";\nimport RadioGroupItem from \"./RadioGroupItem\";\n\nimport \"./RadioGroup.css\";\n\ninterface Subcomponents {\n Item: typeof RadioGroupItem;\n}\n\ninterface ControlledInputProps extends Omit<RadioControlGroupProps, \"componentName\"> {\n value: string;\n onChange: (value: string) => void;\n}\n\ninterface UncontrolledInputProps extends Omit<RadioControlGroupProps, \"componentName\"> {\n value?: never;\n defaultValue: string;\n onChange?: (value: string) => void;\n}\n\nexport type Props = ControlledInputProps | UncontrolledInputProps;\n\nconst RadioGroup: FC<Props> & Subcomponents = ({\n value,\n onChange,\n label,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n children,\n name,\n disabled = false,\n error = false,\n errorText = \"\",\n helperText,\n required = false,\n divider = false,\n horizontalPadding = false,\n ...unionProps\n}) => {\n const defaultValue = \"defaultValue\" in unionProps ? unionProps.defaultValue : undefined;\n\n // For the uncontrolled variant, track the checked value internally so the Context\n // (and therefore `isChecked` in `RadioGroup.Item`) stays up-to-date.\n const [internalValue, setInternalValue] = useState(defaultValue ?? \"\");\n const isControlled = value !== undefined;\n const checkedValue = isControlled ? value : internalValue;\n\n const handleValueChange = (newValue: string) => {\n if (!isControlled) setInternalValue(newValue);\n onChange?.(newValue);\n };\n\n return (\n <SelectionControlGroup\n label={label}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n name={name}\n disabled={disabled}\n helperText={helperText}\n error={error}\n errorText={errorText}\n required={required}\n componentName=\"radio-group\"\n divider={divider}\n horizontalPadding={horizontalPadding}\n >\n <RadioGroupPrimitive.Root\n name={name}\n value={value}\n onValueChange={handleValueChange}\n orientation=\"vertical\" // disable navigation via \"←\" and \"→\" keys, only \"↑\" and \"↓\" can be used\n disabled={disabled}\n required={required}\n defaultValue={defaultValue}\n >\n <RadioGroupContext value={{ disabled, checkedValue }}>\n {/* Creating a 'phantom' option is technically more correct for the case when we pass an empty string as a value (initially to not preselect any option in the group). */}\n <RadioGroupItem label=\"\" value=\"\" />\n {children}\n </RadioGroupContext>\n </RadioGroupPrimitive.Root>\n </SelectionControlGroup>\n );\n};\n\nRadioGroup.Item = RadioGroupItem;\n\nexport default RadioGroup;\n"],"mappings":";;;;;;;AASA,IAAM,IAAoB,EAAsC;CAC9D,UAAU;CACV,cAAc;AAChB,CAAC,GCRK,UACG,EAAW,CAAiB,GCG/B,IAAkB,EAAG;CACzB,MAAM;CACN,OAAO;EACL,MAAM,CACJ,oEACA,4GACF;EAEA,mBAAmB;EACnB,WAAW,CACT,sGACA,kDACF;EAEA,QAAQ;CACV;CACA,UAAU,EACR,UAAU;EACR,MAAM;GACJ,MAAM;GACN,MAAM;EACR;EACA,OAAO,EACL,MAAM,gDACR;CACF,EACF;AACF,CAAC,GAaK,KAAkB,EAAE,UAAO,UAAO,eAAY,gBAAoB;CACtE,IAAM,EAAE,aAAU,oBAAiB,EAAqB,GAClD,EAAE,SAAM,SAAM,sBAAmB,cAAW,QAAQ,MAAkB,EAAgB,EAAE,YAAS,CAAC,GAClG,IAAS,MAAU,KAAK,WAAW,KAAA,GAEnC,IAAY,MAAU;CAE5B,OACE,kBAAC,OAAD;EAAK,WAAW;EAAQ,8BAA2B;EAAG,wBAAsB,CAAC,CAAC;EAAQ,4BAA0B,CAAC,CAAC;EAAlH,UAAA,CACE,kBAAC,SAAD;GAAO,WAAW,EAAK;GAAvB,UAAA,CACE,kBAAC,QAAD;IAAM,WAAW,EAAkB;IAAnC,UAAA,CACE,kBAAC,EAAoB,MAArB;KAAiC;KAAO,WAAW,EAAK;KAAa;KACnE,UAAA,kBAAC,EAAoB,WAArB,EAA+B,WAAW,EAAU,EAAI,CAAA;IAChC,CAAA,GACzB,CACG;GACL,CAAA,GAAA,KAAU,kBAAC,QAAD;IAAM,WAAW,EAAc;IAAI,UAAA;GAAa,CAAA,CACtD;EACN,CAAA,GAAA,KAAc,KAAa,kBAAC,OAAD,EAAA,UAAM,EAAgB,CAAA,CAC/C;;AAET,GCxCM,KAAyC,EAC7C,UACA,aACA,UACA,cAAc,GACd,mBAAmB,GACnB,aACA,SACA,cAAW,IACX,WAAQ,IACR,eAAY,IACZ,eACA,cAAW,IACX,aAAU,IACV,uBAAoB,IACpB,GAAG,QACC;CACJ,IAAM,IAAe,kBAAkB,IAAa,EAAW,eAAe,KAAA,GAIxE,CAAC,GAAe,KAAoB,EAAS,KAAgB,EAAE,GAC/D,IAAe,MAAU,KAAA,GACzB,IAAe,IAAe,IAAQ;CAO5C,OACE,kBAAC,GAAD;EACS;EACP,cAAY;EACZ,mBAAiB;EACX;EACI;EACE;EACL;EACI;EACD;EACV,eAAc;EACL;EACU;EAEnB,UAAA,kBAAC,EAAoB,MAArB;GACQ;GACC;GACP,gBAvBqB,MAAqB;IAE9C,AADK,KAAc,EAAiB,CAAQ,GAC5C,IAAW,CAAQ;GACrB;GAqBM,aAAY;GACF;GACA;GACI;GAEd,UAAA,kBAAC,GAAD;IAAmB,OAAO;KAAE;KAAU;IAAa;IAAnD,UAAA,CAEE,kBAAC,GAAD;KAAgB,OAAM;KAAG,OAAM;IAAI,CAAA,GAClC,CACgB;;EACK,CAAA;CACL,CAAA;AAE3B;AAEA,EAAW,OAAO"}
|