@nucleux/radio-group 0.1.1
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/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/index.cjs +86 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +63 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nucleux
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @nucleux/radio-group
|
|
2
|
+
|
|
3
|
+
Single-select radio group — Nucleux agentic UI for React.
|
|
4
|
+
|
|
5
|
+
Part of **[Nucleux](https://github.com/intelligaia-open-labs/nucleux)** — agentic UI components for React. Install a single component, or the full kit via [`@nucleux/react`](https://www.npmjs.com/package/@nucleux/react).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @nucleux/radio-group @nucleux/tokens
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`react` / `react-dom` are peer dependencies.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { RadioGroup, Radio } from "@nucleux/radio-group";
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Requires the theme once in your app: `import "@nucleux/tokens/styles.css";`
|
|
22
|
+
and the Tailwind preset from `@nucleux/tokens/preset`.
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
MIT © Nucleux
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var utils = require('@nucleux/utils');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
|
|
8
|
+
function _interopNamespace(e) {
|
|
9
|
+
if (e && e.__esModule) return e;
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
27
|
+
|
|
28
|
+
// src/index.tsx
|
|
29
|
+
var RadioGroupContext = React__namespace.createContext(null);
|
|
30
|
+
var RadioGroup = React__namespace.forwardRef(
|
|
31
|
+
({ value, defaultValue, onValueChange, label, className, ...props }, ref) => {
|
|
32
|
+
const [internal, setInternal] = React__namespace.useState(defaultValue);
|
|
33
|
+
const isControlled = value != null;
|
|
34
|
+
const current = isControlled ? value : internal;
|
|
35
|
+
const name = React__namespace.useId();
|
|
36
|
+
const setValue = React__namespace.useCallback(
|
|
37
|
+
(v) => {
|
|
38
|
+
if (!isControlled) setInternal(v);
|
|
39
|
+
onValueChange?.(v);
|
|
40
|
+
},
|
|
41
|
+
[isControlled, onValueChange]
|
|
42
|
+
);
|
|
43
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RadioGroupContext.Provider, { value: { value: current, setValue, name }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
44
|
+
"div",
|
|
45
|
+
{
|
|
46
|
+
ref,
|
|
47
|
+
role: "radiogroup",
|
|
48
|
+
"aria-label": label,
|
|
49
|
+
className: utils.cn("flex flex-col gap-2", className),
|
|
50
|
+
...props
|
|
51
|
+
}
|
|
52
|
+
) });
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
RadioGroup.displayName = "RadioGroup";
|
|
56
|
+
var Radio = React__namespace.forwardRef(
|
|
57
|
+
({ value, disabled, className, ...props }, ref) => {
|
|
58
|
+
const ctx = React__namespace.useContext(RadioGroupContext);
|
|
59
|
+
if (!ctx) throw new Error("<Radio> must be used inside <RadioGroup>");
|
|
60
|
+
const checked = ctx.value === value;
|
|
61
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
62
|
+
"button",
|
|
63
|
+
{
|
|
64
|
+
ref,
|
|
65
|
+
type: "button",
|
|
66
|
+
role: "radio",
|
|
67
|
+
"aria-checked": checked,
|
|
68
|
+
disabled,
|
|
69
|
+
onClick: () => !disabled && ctx.setValue(value),
|
|
70
|
+
className: utils.cn(
|
|
71
|
+
"inline-flex size-4 shrink-0 items-center justify-center rounded-full border shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50",
|
|
72
|
+
checked ? "border-primary" : "border-input bg-background",
|
|
73
|
+
className
|
|
74
|
+
),
|
|
75
|
+
...props,
|
|
76
|
+
children: checked && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "size-2 rounded-full bg-primary" })
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
Radio.displayName = "Radio";
|
|
82
|
+
|
|
83
|
+
exports.Radio = Radio;
|
|
84
|
+
exports.RadioGroup = RadioGroup;
|
|
85
|
+
//# sourceMappingURL=index.cjs.map
|
|
86
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["React","jsx","cn"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,IAAM,iBAAA,GAA0BA,+BAA6C,IAAI,CAAA;AAc1E,IAAM,UAAA,GAAmBA,gBAAA,CAAA,UAAA;AAAA,EAC9B,CAAC,EAAE,KAAA,EAAO,YAAA,EAAc,aAAA,EAAe,OAAO,SAAA,EAAW,GAAG,KAAA,EAAM,EAAG,GAAA,KAAQ;AAC3E,IAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAUA,0BAAS,YAAY,CAAA;AAC3D,IAAA,MAAM,eAAe,KAAA,IAAS,IAAA;AAC9B,IAAA,MAAM,OAAA,GAAU,eAAe,KAAA,GAAQ,QAAA;AACvC,IAAA,MAAM,OAAaA,gBAAA,CAAA,KAAA,EAAM;AAEzB,IAAA,MAAM,QAAA,GAAiBA,gBAAA,CAAA,WAAA;AAAA,MACrB,CAAC,CAAA,KAAc;AACb,QAAA,IAAI,CAAC,YAAA,EAAc,WAAA,CAAY,CAAC,CAAA;AAChC,QAAA,aAAA,GAAgB,CAAC,CAAA;AAAA,MACnB,CAAA;AAAA,MACA,CAAC,cAAc,aAAa;AAAA,KAC9B;AAEA,IAAA,uBACEC,cAAA,CAAC,iBAAA,CAAkB,QAAA,EAAlB,EAA2B,KAAA,EAAO,EAAE,KAAA,EAAO,OAAA,EAAS,QAAA,EAAU,IAAA,EAAK,EAClE,QAAA,kBAAAA,cAAA;AAAA,MAAC,KAAA;AAAA,MAAA;AAAA,QACC,GAAA;AAAA,QACA,IAAA,EAAK,YAAA;AAAA,QACL,YAAA,EAAY,KAAA;AAAA,QACZ,SAAA,EAAWC,QAAA,CAAG,qBAAA,EAAuB,SAAS,CAAA;AAAA,QAC7C,GAAG;AAAA;AAAA,KACN,EACF,CAAA;AAAA,EAEJ;AACF;AACA,UAAA,CAAW,WAAA,GAAc,YAAA;AAQlB,IAAM,KAAA,GAAcF,gBAAA,CAAA,UAAA;AAAA,EACzB,CAAC,EAAE,KAAA,EAAO,QAAA,EAAU,WAAW,GAAG,KAAA,IAAS,GAAA,KAAQ;AACjD,IAAA,MAAM,GAAA,GAAYA,4BAAW,iBAAiB,CAAA;AAC9C,IAAA,IAAI,CAAC,GAAA,EAAK,MAAM,IAAI,MAAM,0CAA0C,CAAA;AACpE,IAAA,MAAM,OAAA,GAAU,IAAI,KAAA,KAAU,KAAA;AAC9B,IAAA,uBACEC,cAAA;AAAA,MAAC,QAAA;AAAA,MAAA;AAAA,QACC,GAAA;AAAA,QACA,IAAA,EAAK,QAAA;AAAA,QACL,IAAA,EAAK,OAAA;AAAA,QACL,cAAA,EAAc,OAAA;AAAA,QACd,QAAA;AAAA,QACA,SAAS,MAAM,CAAC,QAAA,IAAY,GAAA,CAAI,SAAS,KAAK,CAAA;AAAA,QAC9C,SAAA,EAAWC,QAAA;AAAA,UACT,kSAAA;AAAA,UACA,UAAU,gBAAA,GAAmB,4BAAA;AAAA,UAC7B;AAAA,SACF;AAAA,QACC,GAAG,KAAA;AAAA,QAEH,QAAA,EAAA,OAAA,oBAAWD,cAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,gCAAA,EAAiC;AAAA;AAAA,KAC/D;AAAA,EAEJ;AACF;AACA,KAAA,CAAM,WAAA,GAAc,OAAA","file":"index.cjs","sourcesContent":["import * as React from \"react\";\nimport { cn } from \"@nucleux/utils\";\n\ninterface RadioGroupContextValue {\n value: string | undefined;\n setValue: (v: string) => void;\n name: string;\n}\nconst RadioGroupContext = React.createContext<RadioGroupContextValue | null>(null);\n\nexport interface RadioGroupProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n /** Controlled selected value. */\n value?: string;\n /** Initial value when uncontrolled. */\n defaultValue?: string;\n /** Called with the newly selected value. */\n onValueChange?: (value: string) => void;\n /** Accessible group label. */\n label?: string;\n}\n\n/** Single-select radio group. Compose with {@link Radio}. */\nexport const RadioGroup = React.forwardRef<HTMLDivElement, RadioGroupProps>(\n ({ value, defaultValue, onValueChange, label, className, ...props }, ref) => {\n const [internal, setInternal] = React.useState(defaultValue);\n const isControlled = value != null;\n const current = isControlled ? value : internal;\n const name = React.useId();\n\n const setValue = React.useCallback(\n (v: string) => {\n if (!isControlled) setInternal(v);\n onValueChange?.(v);\n },\n [isControlled, onValueChange],\n );\n\n return (\n <RadioGroupContext.Provider value={{ value: current, setValue, name }}>\n <div\n ref={ref}\n role=\"radiogroup\"\n aria-label={label}\n className={cn(\"flex flex-col gap-2\", className)}\n {...props}\n />\n </RadioGroupContext.Provider>\n );\n },\n);\nRadioGroup.displayName = \"RadioGroup\";\n\nexport interface RadioProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"value\" | \"type\"> {\n /** The value this radio represents. */\n value: string;\n}\n\n/** A single radio button; must be used inside a {@link RadioGroup}. */\nexport const Radio = React.forwardRef<HTMLButtonElement, RadioProps>(\n ({ value, disabled, className, ...props }, ref) => {\n const ctx = React.useContext(RadioGroupContext);\n if (!ctx) throw new Error(\"<Radio> must be used inside <RadioGroup>\");\n const checked = ctx.value === value;\n return (\n <button\n ref={ref}\n type=\"button\"\n role=\"radio\"\n aria-checked={checked}\n disabled={disabled}\n onClick={() => !disabled && ctx.setValue(value)}\n className={cn(\n \"inline-flex size-4 shrink-0 items-center justify-center rounded-full border shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50\",\n checked ? \"border-primary\" : \"border-input bg-background\",\n className,\n )}\n {...props}\n >\n {checked && <span className=\"size-2 rounded-full bg-primary\" />}\n </button>\n );\n },\n);\nRadio.displayName = \"Radio\";\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface RadioGroupProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> {
|
|
4
|
+
/** Controlled selected value. */
|
|
5
|
+
value?: string;
|
|
6
|
+
/** Initial value when uncontrolled. */
|
|
7
|
+
defaultValue?: string;
|
|
8
|
+
/** Called with the newly selected value. */
|
|
9
|
+
onValueChange?: (value: string) => void;
|
|
10
|
+
/** Accessible group label. */
|
|
11
|
+
label?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Single-select radio group. Compose with {@link Radio}. */
|
|
14
|
+
declare const RadioGroup: React.ForwardRefExoticComponent<RadioGroupProps & React.RefAttributes<HTMLDivElement>>;
|
|
15
|
+
interface RadioProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "value" | "type"> {
|
|
16
|
+
/** The value this radio represents. */
|
|
17
|
+
value: string;
|
|
18
|
+
}
|
|
19
|
+
/** A single radio button; must be used inside a {@link RadioGroup}. */
|
|
20
|
+
declare const Radio: React.ForwardRefExoticComponent<RadioProps & React.RefAttributes<HTMLButtonElement>>;
|
|
21
|
+
|
|
22
|
+
export { Radio, RadioGroup, type RadioGroupProps, type RadioProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
interface RadioGroupProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> {
|
|
4
|
+
/** Controlled selected value. */
|
|
5
|
+
value?: string;
|
|
6
|
+
/** Initial value when uncontrolled. */
|
|
7
|
+
defaultValue?: string;
|
|
8
|
+
/** Called with the newly selected value. */
|
|
9
|
+
onValueChange?: (value: string) => void;
|
|
10
|
+
/** Accessible group label. */
|
|
11
|
+
label?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Single-select radio group. Compose with {@link Radio}. */
|
|
14
|
+
declare const RadioGroup: React.ForwardRefExoticComponent<RadioGroupProps & React.RefAttributes<HTMLDivElement>>;
|
|
15
|
+
interface RadioProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "value" | "type"> {
|
|
16
|
+
/** The value this radio represents. */
|
|
17
|
+
value: string;
|
|
18
|
+
}
|
|
19
|
+
/** A single radio button; must be used inside a {@link RadioGroup}. */
|
|
20
|
+
declare const Radio: React.ForwardRefExoticComponent<RadioProps & React.RefAttributes<HTMLButtonElement>>;
|
|
21
|
+
|
|
22
|
+
export { Radio, RadioGroup, type RadioGroupProps, type RadioProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { cn } from '@nucleux/utils';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
// src/index.tsx
|
|
7
|
+
var RadioGroupContext = React.createContext(null);
|
|
8
|
+
var RadioGroup = React.forwardRef(
|
|
9
|
+
({ value, defaultValue, onValueChange, label, className, ...props }, ref) => {
|
|
10
|
+
const [internal, setInternal] = React.useState(defaultValue);
|
|
11
|
+
const isControlled = value != null;
|
|
12
|
+
const current = isControlled ? value : internal;
|
|
13
|
+
const name = React.useId();
|
|
14
|
+
const setValue = React.useCallback(
|
|
15
|
+
(v) => {
|
|
16
|
+
if (!isControlled) setInternal(v);
|
|
17
|
+
onValueChange?.(v);
|
|
18
|
+
},
|
|
19
|
+
[isControlled, onValueChange]
|
|
20
|
+
);
|
|
21
|
+
return /* @__PURE__ */ jsx(RadioGroupContext.Provider, { value: { value: current, setValue, name }, children: /* @__PURE__ */ jsx(
|
|
22
|
+
"div",
|
|
23
|
+
{
|
|
24
|
+
ref,
|
|
25
|
+
role: "radiogroup",
|
|
26
|
+
"aria-label": label,
|
|
27
|
+
className: cn("flex flex-col gap-2", className),
|
|
28
|
+
...props
|
|
29
|
+
}
|
|
30
|
+
) });
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
RadioGroup.displayName = "RadioGroup";
|
|
34
|
+
var Radio = React.forwardRef(
|
|
35
|
+
({ value, disabled, className, ...props }, ref) => {
|
|
36
|
+
const ctx = React.useContext(RadioGroupContext);
|
|
37
|
+
if (!ctx) throw new Error("<Radio> must be used inside <RadioGroup>");
|
|
38
|
+
const checked = ctx.value === value;
|
|
39
|
+
return /* @__PURE__ */ jsx(
|
|
40
|
+
"button",
|
|
41
|
+
{
|
|
42
|
+
ref,
|
|
43
|
+
type: "button",
|
|
44
|
+
role: "radio",
|
|
45
|
+
"aria-checked": checked,
|
|
46
|
+
disabled,
|
|
47
|
+
onClick: () => !disabled && ctx.setValue(value),
|
|
48
|
+
className: cn(
|
|
49
|
+
"inline-flex size-4 shrink-0 items-center justify-center rounded-full border shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50",
|
|
50
|
+
checked ? "border-primary" : "border-input bg-background",
|
|
51
|
+
className
|
|
52
|
+
),
|
|
53
|
+
...props,
|
|
54
|
+
children: checked && /* @__PURE__ */ jsx("span", { className: "size-2 rounded-full bg-primary" })
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
Radio.displayName = "Radio";
|
|
60
|
+
|
|
61
|
+
export { Radio, RadioGroup };
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":[],"mappings":";;;;;AAQA,IAAM,iBAAA,GAA0B,oBAA6C,IAAI,CAAA;AAc1E,IAAM,UAAA,GAAmB,KAAA,CAAA,UAAA;AAAA,EAC9B,CAAC,EAAE,KAAA,EAAO,YAAA,EAAc,aAAA,EAAe,OAAO,SAAA,EAAW,GAAG,KAAA,EAAM,EAAG,GAAA,KAAQ;AAC3E,IAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAU,eAAS,YAAY,CAAA;AAC3D,IAAA,MAAM,eAAe,KAAA,IAAS,IAAA;AAC9B,IAAA,MAAM,OAAA,GAAU,eAAe,KAAA,GAAQ,QAAA;AACvC,IAAA,MAAM,OAAa,KAAA,CAAA,KAAA,EAAM;AAEzB,IAAA,MAAM,QAAA,GAAiB,KAAA,CAAA,WAAA;AAAA,MACrB,CAAC,CAAA,KAAc;AACb,QAAA,IAAI,CAAC,YAAA,EAAc,WAAA,CAAY,CAAC,CAAA;AAChC,QAAA,aAAA,GAAgB,CAAC,CAAA;AAAA,MACnB,CAAA;AAAA,MACA,CAAC,cAAc,aAAa;AAAA,KAC9B;AAEA,IAAA,uBACE,GAAA,CAAC,iBAAA,CAAkB,QAAA,EAAlB,EAA2B,KAAA,EAAO,EAAE,KAAA,EAAO,OAAA,EAAS,QAAA,EAAU,IAAA,EAAK,EAClE,QAAA,kBAAA,GAAA;AAAA,MAAC,KAAA;AAAA,MAAA;AAAA,QACC,GAAA;AAAA,QACA,IAAA,EAAK,YAAA;AAAA,QACL,YAAA,EAAY,KAAA;AAAA,QACZ,SAAA,EAAW,EAAA,CAAG,qBAAA,EAAuB,SAAS,CAAA;AAAA,QAC7C,GAAG;AAAA;AAAA,KACN,EACF,CAAA;AAAA,EAEJ;AACF;AACA,UAAA,CAAW,WAAA,GAAc,YAAA;AAQlB,IAAM,KAAA,GAAc,KAAA,CAAA,UAAA;AAAA,EACzB,CAAC,EAAE,KAAA,EAAO,QAAA,EAAU,WAAW,GAAG,KAAA,IAAS,GAAA,KAAQ;AACjD,IAAA,MAAM,GAAA,GAAY,iBAAW,iBAAiB,CAAA;AAC9C,IAAA,IAAI,CAAC,GAAA,EAAK,MAAM,IAAI,MAAM,0CAA0C,CAAA;AACpE,IAAA,MAAM,OAAA,GAAU,IAAI,KAAA,KAAU,KAAA;AAC9B,IAAA,uBACE,GAAA;AAAA,MAAC,QAAA;AAAA,MAAA;AAAA,QACC,GAAA;AAAA,QACA,IAAA,EAAK,QAAA;AAAA,QACL,IAAA,EAAK,OAAA;AAAA,QACL,cAAA,EAAc,OAAA;AAAA,QACd,QAAA;AAAA,QACA,SAAS,MAAM,CAAC,QAAA,IAAY,GAAA,CAAI,SAAS,KAAK,CAAA;AAAA,QAC9C,SAAA,EAAW,EAAA;AAAA,UACT,kSAAA;AAAA,UACA,UAAU,gBAAA,GAAmB,4BAAA;AAAA,UAC7B;AAAA,SACF;AAAA,QACC,GAAG,KAAA;AAAA,QAEH,QAAA,EAAA,OAAA,oBAAW,GAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,gCAAA,EAAiC;AAAA;AAAA,KAC/D;AAAA,EAEJ;AACF;AACA,KAAA,CAAM,WAAA,GAAc,OAAA","file":"index.js","sourcesContent":["import * as React from \"react\";\nimport { cn } from \"@nucleux/utils\";\n\ninterface RadioGroupContextValue {\n value: string | undefined;\n setValue: (v: string) => void;\n name: string;\n}\nconst RadioGroupContext = React.createContext<RadioGroupContextValue | null>(null);\n\nexport interface RadioGroupProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n /** Controlled selected value. */\n value?: string;\n /** Initial value when uncontrolled. */\n defaultValue?: string;\n /** Called with the newly selected value. */\n onValueChange?: (value: string) => void;\n /** Accessible group label. */\n label?: string;\n}\n\n/** Single-select radio group. Compose with {@link Radio}. */\nexport const RadioGroup = React.forwardRef<HTMLDivElement, RadioGroupProps>(\n ({ value, defaultValue, onValueChange, label, className, ...props }, ref) => {\n const [internal, setInternal] = React.useState(defaultValue);\n const isControlled = value != null;\n const current = isControlled ? value : internal;\n const name = React.useId();\n\n const setValue = React.useCallback(\n (v: string) => {\n if (!isControlled) setInternal(v);\n onValueChange?.(v);\n },\n [isControlled, onValueChange],\n );\n\n return (\n <RadioGroupContext.Provider value={{ value: current, setValue, name }}>\n <div\n ref={ref}\n role=\"radiogroup\"\n aria-label={label}\n className={cn(\"flex flex-col gap-2\", className)}\n {...props}\n />\n </RadioGroupContext.Provider>\n );\n },\n);\nRadioGroup.displayName = \"RadioGroup\";\n\nexport interface RadioProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"value\" | \"type\"> {\n /** The value this radio represents. */\n value: string;\n}\n\n/** A single radio button; must be used inside a {@link RadioGroup}. */\nexport const Radio = React.forwardRef<HTMLButtonElement, RadioProps>(\n ({ value, disabled, className, ...props }, ref) => {\n const ctx = React.useContext(RadioGroupContext);\n if (!ctx) throw new Error(\"<Radio> must be used inside <RadioGroup>\");\n const checked = ctx.value === value;\n return (\n <button\n ref={ref}\n type=\"button\"\n role=\"radio\"\n aria-checked={checked}\n disabled={disabled}\n onClick={() => !disabled && ctx.setValue(value)}\n className={cn(\n \"inline-flex size-4 shrink-0 items-center justify-center rounded-full border shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50\",\n checked ? \"border-primary\" : \"border-input bg-background\",\n className,\n )}\n {...props}\n >\n {checked && <span className=\"size-2 rounded-full bg-primary\" />}\n </button>\n );\n },\n);\nRadio.displayName = \"Radio\";\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nucleux/radio-group",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"react": ">=18",
|
|
22
|
+
"react-dom": ">=18"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@nucleux/utils": "0.1.1"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"tsup": "^8.3.5",
|
|
29
|
+
"typescript": "^5.7.2",
|
|
30
|
+
"@types/react": "^18.3.18",
|
|
31
|
+
"react": "^18.3.1",
|
|
32
|
+
"lucide-react": "^0.469.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/intelligaia-open-labs/nucleux.git",
|
|
41
|
+
"directory": "packages/radio-group"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/intelligaia-open-labs/nucleux#readme",
|
|
44
|
+
"description": "Single-select radio group — Nucleux agentic UI for React.",
|
|
45
|
+
"keywords": [
|
|
46
|
+
"nucleux",
|
|
47
|
+
"react",
|
|
48
|
+
"ui",
|
|
49
|
+
"components",
|
|
50
|
+
"agentic",
|
|
51
|
+
"ai",
|
|
52
|
+
"tailwind",
|
|
53
|
+
"radio-group"
|
|
54
|
+
],
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsup"
|
|
57
|
+
}
|
|
58
|
+
}
|