@ladder-ui/radio-group 0.3.0 → 0.4.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/index.js +37 -31
- package/dist/index.mjs +38 -32
- package/dist/radio-group.css +2 -2
- package/dist/radio-group.d.ts +26 -26
- package/dist/radio-group.vars.css +6 -6
- package/package.json +6 -2
package/dist/index.js
CHANGED
|
@@ -2,41 +2,47 @@
|
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var react = require('react');
|
|
5
|
-
var
|
|
5
|
+
var core = require('@ladder-ui/core');
|
|
6
|
+
var layout = require('@ladder-ui/layout');
|
|
7
|
+
var primitives = require('@ladder-ui/primitives');
|
|
6
8
|
|
|
7
|
-
const RadioGroupContext = react.createContext(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
const RadioGroupContext = react.createContext(null);
|
|
10
|
+
// ─── Variants ────────────────────────────────────────────────────────────────
|
|
11
|
+
const radioGroupItemVariants = core.cva({
|
|
12
|
+
base: "lui-radio-group-item",
|
|
13
|
+
variants: {
|
|
14
|
+
size: {
|
|
15
|
+
sm: "lui-radio-group-item--sm",
|
|
16
|
+
md: "lui-radio-group-item--md",
|
|
17
|
+
lg: "lui-radio-group-item--lg",
|
|
18
|
+
},
|
|
19
|
+
status: {
|
|
20
|
+
default: "",
|
|
21
|
+
error: "lui-radio-group-item--error",
|
|
22
|
+
},
|
|
23
|
+
disabled: {
|
|
24
|
+
true: "lui-radio-group-item--disabled",
|
|
25
|
+
false: "",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
defaultVariants: {
|
|
29
|
+
size: "md",
|
|
30
|
+
status: "default",
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
const RadioGroup = react.forwardRef(({ children, className, value, defaultValue, onValueChange, name, disabled, orientation = "vertical", ...props }, ref) => {
|
|
34
|
+
const radioGroup = primitives.useRadioGroup({ value, defaultValue, onValueChange, name, disabled });
|
|
35
|
+
return (jsxRuntime.jsx(RadioGroupContext, { value: radioGroup, children: jsxRuntime.jsx(layout.Flex, { ref: ref, role: "radiogroup", direction: orientation === "horizontal" ? "row" : "column", gap: "2", className: core.concatClassNames("lui-radio-group", orientation === "horizontal" && "lui-radio-group--horizontal", className), ...props, children: children }) }));
|
|
36
|
+
});
|
|
14
37
|
RadioGroup.displayName = "RadioGroup";
|
|
15
|
-
|
|
38
|
+
const RadioGroupItem = react.forwardRef(({ className, value, size, status, disabled, ...props }, ref) => {
|
|
16
39
|
const ctx = react.use(RadioGroupContext);
|
|
40
|
+
if (!ctx)
|
|
41
|
+
return null;
|
|
42
|
+
const isChecked = ctx.value === value;
|
|
17
43
|
const isDisabled = disabled || ctx.disabled;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
? {
|
|
21
|
-
checked: ctx.value === value,
|
|
22
|
-
onChange: (e) => {
|
|
23
|
-
if (e.target.checked)
|
|
24
|
-
ctx.onValueChange?.(value);
|
|
25
|
-
onChange?.(e);
|
|
26
|
-
},
|
|
27
|
-
}
|
|
28
|
-
: {
|
|
29
|
-
// Uncontrolled: use defaultChecked + native browser behaviour
|
|
30
|
-
defaultChecked: ctx.defaultValue === value,
|
|
31
|
-
onChange: (e) => {
|
|
32
|
-
if (e.target.checked)
|
|
33
|
-
ctx.onValueChange?.(value);
|
|
34
|
-
onChange?.(e);
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
const wrapperClasses = concatClassNames("lui-radio-group-item", `lui-radio-group-item--${size}`, status === "error" ? "lui-radio-group-item--error" : undefined, className);
|
|
38
|
-
return (jsxRuntime.jsxs("span", { "data-slot": "radio-group-item", className: wrapperClasses, style: style, children: [jsxRuntime.jsx("input", { ref: ref, type: "radio", className: "lui-radio-group-item__input", name: ctx.name, value: value, disabled: isDisabled, "aria-invalid": status === "error" ? "true" : undefined, ...controlledProps, ...inputProps }), jsxRuntime.jsx("span", { className: "lui-radio-group-item__control", "aria-hidden": "true", children: jsxRuntime.jsx("span", { className: "lui-radio-group-item__dot" }) })] }));
|
|
39
|
-
}
|
|
44
|
+
return (jsxRuntime.jsxs(layout.Box, { as: "span", "data-slot": "radio-group-item", className: radioGroupItemVariants({ size, status, disabled: isDisabled, className }), children: [jsxRuntime.jsx("input", { ref: ref, type: "radio", name: ctx.name, value: value, checked: isChecked, disabled: isDisabled, "aria-invalid": status === "error" ? true : undefined, className: "lui-radio-group-item__input", onChange: () => ctx.onValueChange(value), ...props }), jsxRuntime.jsx(layout.Box, { as: "span", className: "lui-radio-group-item__control", "aria-hidden": "true", children: jsxRuntime.jsx(layout.Box, { as: "span", className: "lui-radio-group-item__dot" }) })] }));
|
|
45
|
+
});
|
|
40
46
|
RadioGroupItem.displayName = "RadioGroupItem";
|
|
41
47
|
|
|
42
48
|
exports.RadioGroup = RadioGroup;
|
package/dist/index.mjs
CHANGED
|
@@ -1,40 +1,46 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
-
import { createContext,
|
|
3
|
-
import concatClassNames from '@ladder-ui/core
|
|
2
|
+
import { createContext, forwardRef, use } from 'react';
|
|
3
|
+
import { cva, concatClassNames } from '@ladder-ui/core';
|
|
4
|
+
import { Flex, Box } from '@ladder-ui/layout';
|
|
5
|
+
import { useRadioGroup } from '@ladder-ui/primitives';
|
|
4
6
|
|
|
5
|
-
const RadioGroupContext = createContext(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const RadioGroupContext = createContext(null);
|
|
8
|
+
// ─── Variants ────────────────────────────────────────────────────────────────
|
|
9
|
+
const radioGroupItemVariants = cva({
|
|
10
|
+
base: "lui-radio-group-item",
|
|
11
|
+
variants: {
|
|
12
|
+
size: {
|
|
13
|
+
sm: "lui-radio-group-item--sm",
|
|
14
|
+
md: "lui-radio-group-item--md",
|
|
15
|
+
lg: "lui-radio-group-item--lg",
|
|
16
|
+
},
|
|
17
|
+
status: {
|
|
18
|
+
default: "",
|
|
19
|
+
error: "lui-radio-group-item--error",
|
|
20
|
+
},
|
|
21
|
+
disabled: {
|
|
22
|
+
true: "lui-radio-group-item--disabled",
|
|
23
|
+
false: "",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
defaultVariants: {
|
|
27
|
+
size: "md",
|
|
28
|
+
status: "default",
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
const RadioGroup = forwardRef(({ children, className, value, defaultValue, onValueChange, name, disabled, orientation = "vertical", ...props }, ref) => {
|
|
32
|
+
const radioGroup = useRadioGroup({ value, defaultValue, onValueChange, name, disabled });
|
|
33
|
+
return (jsx(RadioGroupContext, { value: radioGroup, children: jsx(Flex, { ref: ref, role: "radiogroup", direction: orientation === "horizontal" ? "row" : "column", gap: "2", className: concatClassNames("lui-radio-group", orientation === "horizontal" && "lui-radio-group--horizontal", className), ...props, children: children }) }));
|
|
34
|
+
});
|
|
12
35
|
RadioGroup.displayName = "RadioGroup";
|
|
13
|
-
|
|
36
|
+
const RadioGroupItem = forwardRef(({ className, value, size, status, disabled, ...props }, ref) => {
|
|
14
37
|
const ctx = use(RadioGroupContext);
|
|
38
|
+
if (!ctx)
|
|
39
|
+
return null;
|
|
40
|
+
const isChecked = ctx.value === value;
|
|
15
41
|
const isDisabled = disabled || ctx.disabled;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
? {
|
|
19
|
-
checked: ctx.value === value,
|
|
20
|
-
onChange: (e) => {
|
|
21
|
-
if (e.target.checked)
|
|
22
|
-
ctx.onValueChange?.(value);
|
|
23
|
-
onChange?.(e);
|
|
24
|
-
},
|
|
25
|
-
}
|
|
26
|
-
: {
|
|
27
|
-
// Uncontrolled: use defaultChecked + native browser behaviour
|
|
28
|
-
defaultChecked: ctx.defaultValue === value,
|
|
29
|
-
onChange: (e) => {
|
|
30
|
-
if (e.target.checked)
|
|
31
|
-
ctx.onValueChange?.(value);
|
|
32
|
-
onChange?.(e);
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
const wrapperClasses = concatClassNames("lui-radio-group-item", `lui-radio-group-item--${size}`, status === "error" ? "lui-radio-group-item--error" : undefined, className);
|
|
36
|
-
return (jsxs("span", { "data-slot": "radio-group-item", className: wrapperClasses, style: style, children: [jsx("input", { ref: ref, type: "radio", className: "lui-radio-group-item__input", name: ctx.name, value: value, disabled: isDisabled, "aria-invalid": status === "error" ? "true" : undefined, ...controlledProps, ...inputProps }), jsx("span", { className: "lui-radio-group-item__control", "aria-hidden": "true", children: jsx("span", { className: "lui-radio-group-item__dot" }) })] }));
|
|
37
|
-
}
|
|
42
|
+
return (jsxs(Box, { as: "span", "data-slot": "radio-group-item", className: radioGroupItemVariants({ size, status, disabled: isDisabled, className }), children: [jsx("input", { ref: ref, type: "radio", name: ctx.name, value: value, checked: isChecked, disabled: isDisabled, "aria-invalid": status === "error" ? true : undefined, className: "lui-radio-group-item__input", onChange: () => ctx.onValueChange(value), ...props }), jsx(Box, { as: "span", className: "lui-radio-group-item__control", "aria-hidden": "true", children: jsx(Box, { as: "span", className: "lui-radio-group-item__dot" }) })] }));
|
|
43
|
+
});
|
|
38
44
|
RadioGroupItem.displayName = "RadioGroupItem";
|
|
39
45
|
|
|
40
46
|
export { RadioGroup, RadioGroupItem };
|
package/dist/radio-group.css
CHANGED
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
.lui-radio-group-item:has(.lui-radio-group-item__input:focus-visible) .lui-radio-group-item__control {
|
|
59
59
|
outline: none;
|
|
60
60
|
border-color: var(--lui-radio-focus-border);
|
|
61
|
-
box-shadow: 0 0 0 2px var(--lui-surface), 0 0 0 4px var(--lui-radio-focus-ring-color);
|
|
61
|
+
box-shadow: 0 0 0 2px var(--lui-bg-surface), 0 0 0 4px var(--lui-radio-focus-ring-color);
|
|
62
62
|
}
|
|
63
63
|
.lui-radio-group-item:has(.lui-radio-group-item__input:checked) .lui-radio-group-item__control {
|
|
64
64
|
background-color: var(--lui-radio-checked-bg);
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
}
|
|
76
76
|
.lui-radio-group-item--error:has(.lui-radio-group-item__input:focus-visible) .lui-radio-group-item__control {
|
|
77
77
|
border-color: var(--lui-error);
|
|
78
|
-
box-shadow: 0 0 0 2px var(--lui-surface), 0 0 0 4px color-mix(in srgb, var(--lui-error) 40%, transparent);
|
|
78
|
+
box-shadow: 0 0 0 2px var(--lui-bg-surface), 0 0 0 4px color-mix(in srgb, var(--lui-error) 40%, transparent);
|
|
79
79
|
}
|
|
80
80
|
.lui-radio-group-item--sm {
|
|
81
81
|
width: var(--lui-radio-size-sm);
|
package/dist/radio-group.d.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import type { Ref } from "react";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import type { Ref, HTMLAttributes, ReactNode } from "react";
|
|
2
|
+
import { type VariantProps } from "@ladder-ui/core";
|
|
3
|
+
import { type UseRadioGroupProps } from "@ladder-ui/primitives";
|
|
4
|
+
declare const radioGroupItemVariants: (props?: (import("packages/core/dist/cva").ConfigVariants<{
|
|
5
|
+
size: {
|
|
6
|
+
sm: string;
|
|
7
|
+
md: string;
|
|
8
|
+
lg: string;
|
|
9
|
+
};
|
|
10
|
+
status: {
|
|
11
|
+
default: string;
|
|
12
|
+
error: string;
|
|
13
|
+
};
|
|
14
|
+
disabled: {
|
|
15
|
+
true: string;
|
|
16
|
+
false: string;
|
|
17
|
+
};
|
|
18
|
+
}> & {
|
|
19
|
+
className?: string;
|
|
20
|
+
}) | undefined) => string;
|
|
21
|
+
export interface RadioGroupProps extends Omit<HTMLAttributes<HTMLDivElement>, "defaultValue">, UseRadioGroupProps {
|
|
22
|
+
children?: ReactNode;
|
|
13
23
|
orientation?: "vertical" | "horizontal";
|
|
14
|
-
/** Disables all radio items in the group. */
|
|
15
|
-
disabled?: boolean;
|
|
16
24
|
}
|
|
17
|
-
export declare
|
|
18
|
-
export
|
|
19
|
-
var displayName: string;
|
|
20
|
-
}
|
|
21
|
-
export interface RadioGroupItemProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "size" | "type" | "value"> {
|
|
25
|
+
export declare const RadioGroup: import("react").ForwardRefExoticComponent<RadioGroupProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
26
|
+
export interface RadioGroupItemProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "size" | "type" | "value">, VariantProps<typeof radioGroupItemVariants> {
|
|
22
27
|
ref?: Ref<HTMLInputElement>;
|
|
23
|
-
/** The value this item represents. Required. */
|
|
24
28
|
value: string;
|
|
25
|
-
/** Size of the radio control. */
|
|
26
29
|
size?: "sm" | "md" | "lg";
|
|
27
|
-
/** Visual validation state. `"error"` adds a red border and sets `aria-invalid="true"`. */
|
|
28
30
|
status?: "default" | "error";
|
|
29
31
|
}
|
|
30
|
-
export declare
|
|
31
|
-
export
|
|
32
|
-
var displayName: string;
|
|
33
|
-
}
|
|
32
|
+
export declare const RadioGroupItem: import("react").ForwardRefExoticComponent<Omit<RadioGroupItemProps, "ref"> & import("react").RefAttributes<HTMLInputElement>>;
|
|
33
|
+
export {};
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
--lui-radio-size-md: 1rem;
|
|
4
4
|
--lui-radio-size-lg: 1.25rem;
|
|
5
5
|
--lui-radio-dot-scale: 0.4;
|
|
6
|
-
--lui-radio-bg: var(--lui-surface);
|
|
7
|
-
--lui-radio-border: var(--lui-
|
|
8
|
-
--lui-radio-checked-bg: var(--lui-
|
|
9
|
-
--lui-radio-checked-dot: var(--lui-
|
|
10
|
-
--lui-radio-focus-border: var(--lui-
|
|
11
|
-
--lui-radio-focus-ring-color: color-mix(in srgb, var(--lui-
|
|
6
|
+
--lui-radio-bg: var(--lui-bg-surface);
|
|
7
|
+
--lui-radio-border: color-mix(in srgb, var(--lui-border-default) 93%, var(--lui-text-primary));
|
|
8
|
+
--lui-radio-checked-bg: var(--lui-bg-interactive);
|
|
9
|
+
--lui-radio-checked-dot: var(--lui-text-inverse);
|
|
10
|
+
--lui-radio-focus-border: var(--lui-bg-interactive);
|
|
11
|
+
--lui-radio-focus-ring-color: color-mix(in srgb, var(--lui-bg-interactive) 40%, transparent);
|
|
12
12
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ladder-ui/radio-group",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"sass": "^1.90.0",
|
|
49
49
|
"tslib": "^2.6.2",
|
|
50
50
|
"typescript": "^5.3.3",
|
|
51
|
-
"@ladder-ui/core": "0.
|
|
51
|
+
"@ladder-ui/core": "0.4.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@ladder-ui/core": ">=0.0.0",
|
|
@@ -57,6 +57,10 @@
|
|
|
57
57
|
"sideEffects": [
|
|
58
58
|
"**/*.css"
|
|
59
59
|
],
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@ladder-ui/layout": "^0.4.0",
|
|
62
|
+
"@ladder-ui/primitives": "^0.4.0"
|
|
63
|
+
},
|
|
60
64
|
"scripts": {
|
|
61
65
|
"build": "pnpm clean && rollup -c",
|
|
62
66
|
"dev": "rollup -c -w",
|