@glob-ui/radio-group 0.0.0-stage → 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kevin Martínez E
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 CHANGED
@@ -1,3 +1,17 @@
1
- # Temporary Holding Version
1
+ # @glob-ui/radio-group
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A group of native radios: one tab stop, arrows move and select.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @glob-ui/radio-group
9
+ ```
10
+
11
+ ## Documentation
12
+
13
+ Full docs, examples and the accessibility table: [Radio group](https://github.com/kevin-martineze/GlobUI/tree/main/apps/docs/content/docs/components/radio-group.mdx).
14
+
15
+ ## License
16
+
17
+ MIT. See [LICENSE](./LICENSE).
@@ -0,0 +1,25 @@
1
+ import * as react from 'react';
2
+ import * as class_variance_authority_types from 'class-variance-authority/types';
3
+ import { VariantProps } from 'class-variance-authority';
4
+
5
+ declare const radioVariants: (props?: ({
6
+ size?: "sm" | "md" | "lg" | null | undefined;
7
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
8
+ interface RadioGroupProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange" | "defaultValue">, VariantProps<typeof radioVariants> {
9
+ value?: string;
10
+ defaultValue?: string;
11
+ onValueChange?: (value: string) => void;
12
+ /** Shared by every radio. Defaults to a generated id. */
13
+ name?: string;
14
+ disabled?: boolean;
15
+ required?: boolean;
16
+ orientation?: "vertical" | "horizontal";
17
+ }
18
+ declare const RadioGroup: react.ForwardRefExoticComponent<RadioGroupProps & react.RefAttributes<HTMLDivElement>>;
19
+ interface RadioGroupItemProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "size" | "name" | "value" | "checked" | "defaultChecked" | "onChange"> {
20
+ value: string;
21
+ label?: React.ReactNode;
22
+ }
23
+ declare const RadioGroupItem: react.ForwardRefExoticComponent<RadioGroupItemProps & react.RefAttributes<HTMLInputElement>>;
24
+
25
+ export { RadioGroup, RadioGroupItem, type RadioGroupItemProps, type RadioGroupProps, radioVariants };
@@ -0,0 +1,25 @@
1
+ import * as react from 'react';
2
+ import * as class_variance_authority_types from 'class-variance-authority/types';
3
+ import { VariantProps } from 'class-variance-authority';
4
+
5
+ declare const radioVariants: (props?: ({
6
+ size?: "sm" | "md" | "lg" | null | undefined;
7
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
8
+ interface RadioGroupProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange" | "defaultValue">, VariantProps<typeof radioVariants> {
9
+ value?: string;
10
+ defaultValue?: string;
11
+ onValueChange?: (value: string) => void;
12
+ /** Shared by every radio. Defaults to a generated id. */
13
+ name?: string;
14
+ disabled?: boolean;
15
+ required?: boolean;
16
+ orientation?: "vertical" | "horizontal";
17
+ }
18
+ declare const RadioGroup: react.ForwardRefExoticComponent<RadioGroupProps & react.RefAttributes<HTMLDivElement>>;
19
+ interface RadioGroupItemProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "size" | "name" | "value" | "checked" | "defaultChecked" | "onChange"> {
20
+ value: string;
21
+ label?: React.ReactNode;
22
+ }
23
+ declare const RadioGroupItem: react.ForwardRefExoticComponent<RadioGroupItemProps & react.RefAttributes<HTMLInputElement>>;
24
+
25
+ export { RadioGroup, RadioGroupItem, type RadioGroupItemProps, type RadioGroupProps, radioVariants };
package/dist/index.js ADDED
@@ -0,0 +1,221 @@
1
+ "use client"
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __objRest = (source, exclude) => {
25
+ var target = {};
26
+ for (var prop in source)
27
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
28
+ target[prop] = source[prop];
29
+ if (source != null && __getOwnPropSymbols)
30
+ for (var prop of __getOwnPropSymbols(source)) {
31
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
32
+ target[prop] = source[prop];
33
+ }
34
+ return target;
35
+ };
36
+ var __export = (target, all) => {
37
+ for (var name in all)
38
+ __defProp(target, name, { get: all[name], enumerable: true });
39
+ };
40
+ var __copyProps = (to, from, except, desc) => {
41
+ if (from && typeof from === "object" || typeof from === "function") {
42
+ for (let key of __getOwnPropNames(from))
43
+ if (!__hasOwnProp.call(to, key) && key !== except)
44
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
45
+ }
46
+ return to;
47
+ };
48
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
49
+
50
+ // src/index.ts
51
+ var index_exports = {};
52
+ __export(index_exports, {
53
+ RadioGroup: () => RadioGroup,
54
+ RadioGroupItem: () => RadioGroupItem,
55
+ radioVariants: () => radioVariants
56
+ });
57
+ module.exports = __toCommonJS(index_exports);
58
+
59
+ // src/radio-group.tsx
60
+ var import_react = require("react");
61
+ var import_class_variance_authority = require("class-variance-authority");
62
+ var import_utils = require("@glob-ui/utils");
63
+ var import_jsx_runtime = require("react/jsx-runtime");
64
+ var radioVariants = (0, import_class_variance_authority.cva)(
65
+ "peer shrink-0 cursor-pointer appearance-none rounded-full border border-glob-border-strong bg-glob-surface transition-colors checked:border-glob-primary checked:bg-glob-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-glob-ring disabled:cursor-not-allowed disabled:opacity-50",
66
+ {
67
+ variants: {
68
+ size: {
69
+ sm: "h-4 w-4",
70
+ md: "h-5 w-5",
71
+ lg: "h-6 w-6"
72
+ }
73
+ },
74
+ defaultVariants: {
75
+ size: "md"
76
+ }
77
+ }
78
+ );
79
+ var dotSize = {
80
+ sm: "h-1.5 w-1.5",
81
+ md: "h-2 w-2",
82
+ lg: "h-2.5 w-2.5"
83
+ };
84
+ var labelSize = {
85
+ sm: "text-xs",
86
+ md: "text-sm",
87
+ lg: "text-base"
88
+ };
89
+ var RadioGroupContext = (0, import_react.createContext)(null);
90
+ var RadioGroup = (0, import_react.forwardRef)(
91
+ (_a, ref) => {
92
+ var _b = _a, {
93
+ value,
94
+ defaultValue,
95
+ onValueChange,
96
+ name,
97
+ disabled,
98
+ required,
99
+ orientation = "vertical",
100
+ size,
101
+ className,
102
+ children
103
+ } = _b, props = __objRest(_b, [
104
+ "value",
105
+ "defaultValue",
106
+ "onValueChange",
107
+ "name",
108
+ "disabled",
109
+ "required",
110
+ "orientation",
111
+ "size",
112
+ "className",
113
+ "children"
114
+ ]);
115
+ const autoName = (0, import_react.useId)();
116
+ const [internalValue, setInternalValue] = (0, import_react.useState)(defaultValue);
117
+ const isControlled = value !== void 0;
118
+ const current = isControlled ? value : internalValue;
119
+ function onSelect(next) {
120
+ if (!isControlled) setInternalValue(next);
121
+ onValueChange == null ? void 0 : onValueChange(next);
122
+ }
123
+ const invalid = props["aria-invalid"] === true || props["aria-invalid"] === "true";
124
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
125
+ RadioGroupContext.Provider,
126
+ {
127
+ value: {
128
+ name: name != null ? name : autoName,
129
+ value: current,
130
+ onSelect,
131
+ disabled,
132
+ required,
133
+ invalid,
134
+ size: size != null ? size : "md"
135
+ },
136
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
137
+ "div",
138
+ __spreadProps(__spreadValues({
139
+ ref,
140
+ role: "radiogroup",
141
+ "aria-orientation": orientation,
142
+ "aria-required": required || void 0,
143
+ "aria-disabled": disabled || void 0,
144
+ className: (0, import_utils.cn)(
145
+ "flex",
146
+ orientation === "horizontal" ? "flex-row flex-wrap gap-4" : "flex-col gap-2",
147
+ className
148
+ )
149
+ }, props), {
150
+ children
151
+ })
152
+ )
153
+ }
154
+ );
155
+ }
156
+ );
157
+ RadioGroup.displayName = "RadioGroup";
158
+ var RadioGroupItem = (0, import_react.forwardRef)(
159
+ (_a, ref) => {
160
+ var _b = _a, { value, label, id, disabled, className } = _b, props = __objRest(_b, ["value", "label", "id", "disabled", "className"]);
161
+ const ctx = (0, import_react.useContext)(RadioGroupContext);
162
+ if (!ctx) throw new Error("RadioGroupItem must be used inside RadioGroup");
163
+ const autoId = (0, import_react.useId)();
164
+ const inputId = id != null ? id : autoId;
165
+ const isDisabled = ctx.disabled || disabled;
166
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "inline-flex items-center gap-2", children: [
167
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "relative inline-flex shrink-0", children: [
168
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
169
+ "input",
170
+ __spreadValues({
171
+ ref,
172
+ type: "radio",
173
+ id: inputId,
174
+ name: ctx.name,
175
+ value,
176
+ checked: ctx.value === value,
177
+ onChange: () => ctx.onSelect(value),
178
+ disabled: isDisabled,
179
+ required: ctx.required,
180
+ className: (0, import_utils.cn)(
181
+ radioVariants({ size: ctx.size }),
182
+ // aria-invalid is not valid on role radio; the group carries it, items only show it.
183
+ ctx.invalid && "border-glob-danger",
184
+ className
185
+ )
186
+ }, props)
187
+ ),
188
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
189
+ "span",
190
+ {
191
+ "aria-hidden": "true",
192
+ className: (0, import_utils.cn)(
193
+ "pointer-events-none absolute inset-0 m-auto hidden rounded-full bg-glob-primary-foreground peer-checked:block",
194
+ dotSize[ctx.size]
195
+ )
196
+ }
197
+ )
198
+ ] }),
199
+ label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
200
+ "label",
201
+ {
202
+ htmlFor: inputId,
203
+ className: (0, import_utils.cn)(
204
+ "cursor-pointer text-glob-text",
205
+ labelSize[ctx.size],
206
+ isDisabled && "cursor-not-allowed opacity-50"
207
+ ),
208
+ children: label
209
+ }
210
+ )
211
+ ] });
212
+ }
213
+ );
214
+ RadioGroupItem.displayName = "RadioGroupItem";
215
+ // Annotate the CommonJS export names for ESM import in node:
216
+ 0 && (module.exports = {
217
+ RadioGroup,
218
+ RadioGroupItem,
219
+ radioVariants
220
+ });
221
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/radio-group.tsx"],"sourcesContent":["export { RadioGroup, RadioGroupItem, radioVariants } from \"./radio-group\"\nexport type { RadioGroupProps, RadioGroupItemProps } from \"./radio-group\"\n","\"use client\"\n\nimport { createContext, forwardRef, useContext, useId, useState } from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { cn } from \"@glob-ui/utils\"\n\nconst radioVariants = cva(\n \"peer shrink-0 cursor-pointer appearance-none rounded-full border border-glob-border-strong bg-glob-surface transition-colors checked:border-glob-primary checked:bg-glob-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-glob-ring disabled:cursor-not-allowed disabled:opacity-50\",\n {\n variants: {\n size: {\n sm: \"h-4 w-4\",\n md: \"h-5 w-5\",\n lg: \"h-6 w-6\",\n },\n },\n defaultVariants: {\n size: \"md\",\n },\n }\n)\n\ntype Size = \"sm\" | \"md\" | \"lg\"\n\nconst dotSize: Record<Size, string> = {\n sm: \"h-1.5 w-1.5\",\n md: \"h-2 w-2\",\n lg: \"h-2.5 w-2.5\",\n}\n\nconst labelSize: Record<Size, string> = {\n sm: \"text-xs\",\n md: \"text-sm\",\n lg: \"text-base\",\n}\n\ninterface RadioGroupContextValue {\n name: string\n value: string | undefined\n onSelect: (value: string) => void\n disabled?: boolean\n required?: boolean\n invalid?: boolean\n size: Size\n}\n\nconst RadioGroupContext = createContext<RadioGroupContextValue | null>(null)\n\nexport interface RadioGroupProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\">,\n VariantProps<typeof radioVariants> {\n value?: string\n defaultValue?: string\n onValueChange?: (value: string) => void\n /** Shared by every radio. Defaults to a generated id. */\n name?: string\n disabled?: boolean\n required?: boolean\n orientation?: \"vertical\" | \"horizontal\"\n}\n\nconst RadioGroup = forwardRef<HTMLDivElement, RadioGroupProps>(\n (\n {\n value,\n defaultValue,\n onValueChange,\n name,\n disabled,\n required,\n orientation = \"vertical\",\n size,\n className,\n children,\n ...props\n },\n ref\n ) => {\n const autoName = useId()\n const [internalValue, setInternalValue] = useState(defaultValue)\n const isControlled = value !== undefined\n const current = isControlled ? value : internalValue\n\n function onSelect(next: string) {\n if (!isControlled) setInternalValue(next)\n onValueChange?.(next)\n }\n\n const invalid = props[\"aria-invalid\"] === true || props[\"aria-invalid\"] === \"true\"\n\n return (\n <RadioGroupContext.Provider\n value={{\n name: name ?? autoName,\n value: current,\n onSelect,\n disabled,\n required,\n invalid,\n size: size ?? \"md\",\n }}\n >\n <div\n ref={ref}\n role=\"radiogroup\"\n aria-orientation={orientation}\n aria-required={required || undefined}\n aria-disabled={disabled || undefined}\n className={cn(\n \"flex\",\n orientation === \"horizontal\" ? \"flex-row flex-wrap gap-4\" : \"flex-col gap-2\",\n className\n )}\n {...props}\n >\n {children}\n </div>\n </RadioGroupContext.Provider>\n )\n }\n)\nRadioGroup.displayName = \"RadioGroup\"\n\nexport interface RadioGroupItemProps\n extends Omit<\n React.InputHTMLAttributes<HTMLInputElement>,\n \"type\" | \"size\" | \"name\" | \"value\" | \"checked\" | \"defaultChecked\" | \"onChange\"\n > {\n value: string\n label?: React.ReactNode\n}\n\nconst RadioGroupItem = forwardRef<HTMLInputElement, RadioGroupItemProps>(\n ({ value, label, id, disabled, className, ...props }, ref) => {\n const ctx = useContext(RadioGroupContext)\n if (!ctx) throw new Error(\"RadioGroupItem must be used inside RadioGroup\")\n\n const autoId = useId()\n const inputId = id ?? autoId\n const isDisabled = ctx.disabled || disabled\n\n return (\n <span className=\"inline-flex items-center gap-2\">\n <span className=\"relative inline-flex shrink-0\">\n <input\n ref={ref}\n type=\"radio\"\n id={inputId}\n name={ctx.name}\n value={value}\n checked={ctx.value === value}\n onChange={() => ctx.onSelect(value)}\n disabled={isDisabled}\n required={ctx.required}\n className={cn(\n radioVariants({ size: ctx.size }),\n // aria-invalid is not valid on role radio; the group carries it, items only show it.\n ctx.invalid && \"border-glob-danger\",\n className\n )}\n {...props}\n />\n <span\n aria-hidden=\"true\"\n className={cn(\n \"pointer-events-none absolute inset-0 m-auto hidden rounded-full bg-glob-primary-foreground peer-checked:block\",\n dotSize[ctx.size]\n )}\n />\n </span>\n {label && (\n <label\n htmlFor={inputId}\n className={cn(\n \"cursor-pointer text-glob-text\",\n labelSize[ctx.size],\n isDisabled && \"cursor-not-allowed opacity-50\"\n )}\n >\n {label}\n </label>\n )}\n </span>\n )\n }\n)\nRadioGroupItem.displayName = \"RadioGroupItem\"\n\nexport { RadioGroup, RadioGroupItem, radioVariants }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,mBAAuE;AACvE,sCAAuC;AACvC,mBAAmB;AAkGX;AAhGR,IAAM,oBAAgB;AAAA,EACpB;AAAA,EACA;AAAA,IACE,UAAU;AAAA,MACR,MAAM;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,MACf,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAIA,IAAM,UAAgC;AAAA,EACpC,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAEA,IAAM,YAAkC;AAAA,EACtC,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAYA,IAAM,wBAAoB,4BAA6C,IAAI;AAe3E,IAAM,iBAAa;AAAA,EACjB,CACE,IAaA,QACG;AAdH,iBACE;AAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,cAAc;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,IAzEN,IA+DI,IAWK,kBAXL,IAWK;AAAA,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WACE,6CAAC,UAAK,WAAU,kCACd;AAAA,mDAAC,UAAK,WAAU,iCACd;AAAA;AAAA,UAAC;AAAA;AAAA,YACC;AAAA,YACA,MAAK;AAAA,YACL,IAAI;AAAA,YACJ,MAAM,IAAI;AAAA,YACV;AAAA,YACA,SAAS,IAAI,UAAU;AAAA,YACvB,UAAU,MAAM,IAAI,SAAS,KAAK;AAAA,YAClC,UAAU;AAAA,YACV,UAAU,IAAI;AAAA,YACd,eAAW;AAAA,cACT,cAAc,EAAE,MAAM,IAAI,KAAK,CAAC;AAAA;AAAA,cAEhC,IAAI,WAAW;AAAA,cACf;AAAA,YACF;AAAA,aACI;AAAA,QACN;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACC,eAAY;AAAA,YACZ,eAAW;AAAA,cACT;AAAA,cACA,QAAQ,IAAI,IAAI;AAAA,YAClB;AAAA;AAAA,QACF;AAAA,SACF;AAAA,MACC,SACC;AAAA,QAAC;AAAA;AAAA,UACC,SAAS;AAAA,UACT,eAAW;AAAA,YACT;AAAA,YACA,UAAU,IAAI,IAAI;AAAA,YAClB,cAAc;AAAA,UAChB;AAAA,UAEC;AAAA;AAAA,MACH;AAAA,OAEJ;AAAA,EAEJ;AACF;AACA,eAAe,cAAc;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,195 @@
1
+ "use client"
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+ var __objRest = (source, exclude) => {
22
+ var target = {};
23
+ for (var prop in source)
24
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
25
+ target[prop] = source[prop];
26
+ if (source != null && __getOwnPropSymbols)
27
+ for (var prop of __getOwnPropSymbols(source)) {
28
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
29
+ target[prop] = source[prop];
30
+ }
31
+ return target;
32
+ };
33
+
34
+ // src/radio-group.tsx
35
+ import { createContext, forwardRef, useContext, useId, useState } from "react";
36
+ import { cva } from "class-variance-authority";
37
+ import { cn } from "@glob-ui/utils";
38
+ import { jsx, jsxs } from "react/jsx-runtime";
39
+ var radioVariants = cva(
40
+ "peer shrink-0 cursor-pointer appearance-none rounded-full border border-glob-border-strong bg-glob-surface transition-colors checked:border-glob-primary checked:bg-glob-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-glob-ring disabled:cursor-not-allowed disabled:opacity-50",
41
+ {
42
+ variants: {
43
+ size: {
44
+ sm: "h-4 w-4",
45
+ md: "h-5 w-5",
46
+ lg: "h-6 w-6"
47
+ }
48
+ },
49
+ defaultVariants: {
50
+ size: "md"
51
+ }
52
+ }
53
+ );
54
+ var dotSize = {
55
+ sm: "h-1.5 w-1.5",
56
+ md: "h-2 w-2",
57
+ lg: "h-2.5 w-2.5"
58
+ };
59
+ var labelSize = {
60
+ sm: "text-xs",
61
+ md: "text-sm",
62
+ lg: "text-base"
63
+ };
64
+ var RadioGroupContext = createContext(null);
65
+ var RadioGroup = forwardRef(
66
+ (_a, ref) => {
67
+ var _b = _a, {
68
+ value,
69
+ defaultValue,
70
+ onValueChange,
71
+ name,
72
+ disabled,
73
+ required,
74
+ orientation = "vertical",
75
+ size,
76
+ className,
77
+ children
78
+ } = _b, props = __objRest(_b, [
79
+ "value",
80
+ "defaultValue",
81
+ "onValueChange",
82
+ "name",
83
+ "disabled",
84
+ "required",
85
+ "orientation",
86
+ "size",
87
+ "className",
88
+ "children"
89
+ ]);
90
+ const autoName = useId();
91
+ const [internalValue, setInternalValue] = useState(defaultValue);
92
+ const isControlled = value !== void 0;
93
+ const current = isControlled ? value : internalValue;
94
+ function onSelect(next) {
95
+ if (!isControlled) setInternalValue(next);
96
+ onValueChange == null ? void 0 : onValueChange(next);
97
+ }
98
+ const invalid = props["aria-invalid"] === true || props["aria-invalid"] === "true";
99
+ return /* @__PURE__ */ jsx(
100
+ RadioGroupContext.Provider,
101
+ {
102
+ value: {
103
+ name: name != null ? name : autoName,
104
+ value: current,
105
+ onSelect,
106
+ disabled,
107
+ required,
108
+ invalid,
109
+ size: size != null ? size : "md"
110
+ },
111
+ children: /* @__PURE__ */ jsx(
112
+ "div",
113
+ __spreadProps(__spreadValues({
114
+ ref,
115
+ role: "radiogroup",
116
+ "aria-orientation": orientation,
117
+ "aria-required": required || void 0,
118
+ "aria-disabled": disabled || void 0,
119
+ className: cn(
120
+ "flex",
121
+ orientation === "horizontal" ? "flex-row flex-wrap gap-4" : "flex-col gap-2",
122
+ className
123
+ )
124
+ }, props), {
125
+ children
126
+ })
127
+ )
128
+ }
129
+ );
130
+ }
131
+ );
132
+ RadioGroup.displayName = "RadioGroup";
133
+ var RadioGroupItem = forwardRef(
134
+ (_a, ref) => {
135
+ var _b = _a, { value, label, id, disabled, className } = _b, props = __objRest(_b, ["value", "label", "id", "disabled", "className"]);
136
+ const ctx = useContext(RadioGroupContext);
137
+ if (!ctx) throw new Error("RadioGroupItem must be used inside RadioGroup");
138
+ const autoId = useId();
139
+ const inputId = id != null ? id : autoId;
140
+ const isDisabled = ctx.disabled || disabled;
141
+ return /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-2", children: [
142
+ /* @__PURE__ */ jsxs("span", { className: "relative inline-flex shrink-0", children: [
143
+ /* @__PURE__ */ jsx(
144
+ "input",
145
+ __spreadValues({
146
+ ref,
147
+ type: "radio",
148
+ id: inputId,
149
+ name: ctx.name,
150
+ value,
151
+ checked: ctx.value === value,
152
+ onChange: () => ctx.onSelect(value),
153
+ disabled: isDisabled,
154
+ required: ctx.required,
155
+ className: cn(
156
+ radioVariants({ size: ctx.size }),
157
+ // aria-invalid is not valid on role radio; the group carries it, items only show it.
158
+ ctx.invalid && "border-glob-danger",
159
+ className
160
+ )
161
+ }, props)
162
+ ),
163
+ /* @__PURE__ */ jsx(
164
+ "span",
165
+ {
166
+ "aria-hidden": "true",
167
+ className: cn(
168
+ "pointer-events-none absolute inset-0 m-auto hidden rounded-full bg-glob-primary-foreground peer-checked:block",
169
+ dotSize[ctx.size]
170
+ )
171
+ }
172
+ )
173
+ ] }),
174
+ label && /* @__PURE__ */ jsx(
175
+ "label",
176
+ {
177
+ htmlFor: inputId,
178
+ className: cn(
179
+ "cursor-pointer text-glob-text",
180
+ labelSize[ctx.size],
181
+ isDisabled && "cursor-not-allowed opacity-50"
182
+ ),
183
+ children: label
184
+ }
185
+ )
186
+ ] });
187
+ }
188
+ );
189
+ RadioGroupItem.displayName = "RadioGroupItem";
190
+ export {
191
+ RadioGroup,
192
+ RadioGroupItem,
193
+ radioVariants
194
+ };
195
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/radio-group.tsx"],"sourcesContent":["\"use client\"\n\nimport { createContext, forwardRef, useContext, useId, useState } from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { cn } from \"@glob-ui/utils\"\n\nconst radioVariants = cva(\n \"peer shrink-0 cursor-pointer appearance-none rounded-full border border-glob-border-strong bg-glob-surface transition-colors checked:border-glob-primary checked:bg-glob-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-glob-ring disabled:cursor-not-allowed disabled:opacity-50\",\n {\n variants: {\n size: {\n sm: \"h-4 w-4\",\n md: \"h-5 w-5\",\n lg: \"h-6 w-6\",\n },\n },\n defaultVariants: {\n size: \"md\",\n },\n }\n)\n\ntype Size = \"sm\" | \"md\" | \"lg\"\n\nconst dotSize: Record<Size, string> = {\n sm: \"h-1.5 w-1.5\",\n md: \"h-2 w-2\",\n lg: \"h-2.5 w-2.5\",\n}\n\nconst labelSize: Record<Size, string> = {\n sm: \"text-xs\",\n md: \"text-sm\",\n lg: \"text-base\",\n}\n\ninterface RadioGroupContextValue {\n name: string\n value: string | undefined\n onSelect: (value: string) => void\n disabled?: boolean\n required?: boolean\n invalid?: boolean\n size: Size\n}\n\nconst RadioGroupContext = createContext<RadioGroupContextValue | null>(null)\n\nexport interface RadioGroupProps\n extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\">,\n VariantProps<typeof radioVariants> {\n value?: string\n defaultValue?: string\n onValueChange?: (value: string) => void\n /** Shared by every radio. Defaults to a generated id. */\n name?: string\n disabled?: boolean\n required?: boolean\n orientation?: \"vertical\" | \"horizontal\"\n}\n\nconst RadioGroup = forwardRef<HTMLDivElement, RadioGroupProps>(\n (\n {\n value,\n defaultValue,\n onValueChange,\n name,\n disabled,\n required,\n orientation = \"vertical\",\n size,\n className,\n children,\n ...props\n },\n ref\n ) => {\n const autoName = useId()\n const [internalValue, setInternalValue] = useState(defaultValue)\n const isControlled = value !== undefined\n const current = isControlled ? value : internalValue\n\n function onSelect(next: string) {\n if (!isControlled) setInternalValue(next)\n onValueChange?.(next)\n }\n\n const invalid = props[\"aria-invalid\"] === true || props[\"aria-invalid\"] === \"true\"\n\n return (\n <RadioGroupContext.Provider\n value={{\n name: name ?? autoName,\n value: current,\n onSelect,\n disabled,\n required,\n invalid,\n size: size ?? \"md\",\n }}\n >\n <div\n ref={ref}\n role=\"radiogroup\"\n aria-orientation={orientation}\n aria-required={required || undefined}\n aria-disabled={disabled || undefined}\n className={cn(\n \"flex\",\n orientation === \"horizontal\" ? \"flex-row flex-wrap gap-4\" : \"flex-col gap-2\",\n className\n )}\n {...props}\n >\n {children}\n </div>\n </RadioGroupContext.Provider>\n )\n }\n)\nRadioGroup.displayName = \"RadioGroup\"\n\nexport interface RadioGroupItemProps\n extends Omit<\n React.InputHTMLAttributes<HTMLInputElement>,\n \"type\" | \"size\" | \"name\" | \"value\" | \"checked\" | \"defaultChecked\" | \"onChange\"\n > {\n value: string\n label?: React.ReactNode\n}\n\nconst RadioGroupItem = forwardRef<HTMLInputElement, RadioGroupItemProps>(\n ({ value, label, id, disabled, className, ...props }, ref) => {\n const ctx = useContext(RadioGroupContext)\n if (!ctx) throw new Error(\"RadioGroupItem must be used inside RadioGroup\")\n\n const autoId = useId()\n const inputId = id ?? autoId\n const isDisabled = ctx.disabled || disabled\n\n return (\n <span className=\"inline-flex items-center gap-2\">\n <span className=\"relative inline-flex shrink-0\">\n <input\n ref={ref}\n type=\"radio\"\n id={inputId}\n name={ctx.name}\n value={value}\n checked={ctx.value === value}\n onChange={() => ctx.onSelect(value)}\n disabled={isDisabled}\n required={ctx.required}\n className={cn(\n radioVariants({ size: ctx.size }),\n // aria-invalid is not valid on role radio; the group carries it, items only show it.\n ctx.invalid && \"border-glob-danger\",\n className\n )}\n {...props}\n />\n <span\n aria-hidden=\"true\"\n className={cn(\n \"pointer-events-none absolute inset-0 m-auto hidden rounded-full bg-glob-primary-foreground peer-checked:block\",\n dotSize[ctx.size]\n )}\n />\n </span>\n {label && (\n <label\n htmlFor={inputId}\n className={cn(\n \"cursor-pointer text-glob-text\",\n labelSize[ctx.size],\n isDisabled && \"cursor-not-allowed opacity-50\"\n )}\n >\n {label}\n </label>\n )}\n </span>\n )\n }\n)\nRadioGroupItem.displayName = \"RadioGroupItem\"\n\nexport { RadioGroup, RadioGroupItem, radioVariants }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,eAAe,YAAY,YAAY,OAAO,gBAAgB;AACvE,SAAS,WAA8B;AACvC,SAAS,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AAA;AAAA,UACC,SAAS;AAAA,UACT,WAAW;AAAA,YACT;AAAA,YACA,UAAU,IAAI,IAAI;AAAA,YAClB,cAAc;AAAA,UAChB;AAAA,UAEC;AAAA;AAAA,MACH;AAAA,OAEJ;AAAA,EAEJ;AACF;AACA,eAAe,cAAc;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,68 @@
1
1
  {
2
2
  "name": "@glob-ui/radio-group",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "main": "./dist/index.js",
5
+ "module": "./dist/index.mjs",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": {
10
+ "types": "./dist/index.d.mts",
11
+ "default": "./dist/index.mjs"
12
+ },
13
+ "require": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ }
17
+ },
18
+ "./package.json": "./package.json"
19
+ },
20
+ "files": [
21
+ "dist/",
22
+ "LICENSE",
23
+ "README.md"
24
+ ],
25
+ "peerDependencies": {
26
+ "react": "^19"
27
+ },
28
+ "dependencies": {
29
+ "@glob-ui/utils": "0.1.0",
30
+ "class-variance-authority": "^0.7.1"
31
+ },
32
+ "devDependencies": {
33
+ "tsup": "^8.5.1"
34
+ },
35
+ "description": "A group of native radios: one tab stop, arrows move and select.",
36
+ "keywords": [
37
+ "react",
38
+ "glob-ui",
39
+ "components",
40
+ "accessible",
41
+ "tailwind",
42
+ "radio-group"
43
+ ],
44
+ "license": "MIT",
45
+ "author": "Kevin Martínez E",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/kevin-martineze/GlobUI.git",
49
+ "directory": "packages/radio-group"
50
+ },
51
+ "homepage": "https://github.com/kevin-martineze/GlobUI#readme",
52
+ "bugs": {
53
+ "url": "https://github.com/kevin-martineze/GlobUI/issues"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public",
57
+ "provenance": true
58
+ },
59
+ "sideEffects": false,
60
+ "type": "commonjs",
61
+ "engines": {
62
+ "node": ">=18.18"
63
+ },
64
+ "scripts": {
65
+ "build": "tsup",
66
+ "dev": "tsup --watch --no-clean"
67
+ }
6
68
  }