@lattice-ui/radio-group 0.1.1 → 0.3.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/out/index.d.ts CHANGED
@@ -1,4 +1,10 @@
1
- export { RadioGroupIndicator } from "./RadioGroup/RadioGroupIndicator";
2
- export { RadioGroupItem } from "./RadioGroup/RadioGroupItem";
3
- export { RadioGroupRoot, RadioGroupRoot as RadioGroup } from "./RadioGroup/RadioGroupRoot";
1
+ import { RadioGroupIndicator } from "./RadioGroup/RadioGroupIndicator";
2
+ import { RadioGroupItem } from "./RadioGroup/RadioGroupItem";
3
+ import { RadioGroupRoot } from "./RadioGroup/RadioGroupRoot";
4
+ export declare const RadioGroup: {
5
+ readonly Root: typeof RadioGroupRoot;
6
+ readonly Item: typeof RadioGroupItem;
7
+ readonly Indicator: typeof RadioGroupIndicator;
8
+ };
9
+ export { RadioGroupIndicator, RadioGroupItem, RadioGroupRoot };
4
10
  export type { RadioGroupContextValue, RadioGroupIndicatorProps, RadioGroupItemContextValue, RadioGroupItemProps, RadioGroupProps, RadioGroupSetValue, } from "./RadioGroup/types";
package/out/init.luau CHANGED
@@ -1,9 +1,16 @@
1
1
  -- Compiled with roblox-ts v3.0.0
2
2
  local TS = _G[script]
3
- local exports = {}
4
- exports.RadioGroupIndicator = TS.import(script, script, "RadioGroup", "RadioGroupIndicator").RadioGroupIndicator
5
- exports.RadioGroupItem = TS.import(script, script, "RadioGroup", "RadioGroupItem").RadioGroupItem
6
- local _RadioGroupRoot = TS.import(script, script, "RadioGroup", "RadioGroupRoot")
7
- exports.RadioGroupRoot = _RadioGroupRoot.RadioGroupRoot
8
- exports.RadioGroup = _RadioGroupRoot.RadioGroupRoot
9
- return exports
3
+ local RadioGroupIndicator = TS.import(script, script, "RadioGroup", "RadioGroupIndicator").RadioGroupIndicator
4
+ local RadioGroupItem = TS.import(script, script, "RadioGroup", "RadioGroupItem").RadioGroupItem
5
+ local RadioGroupRoot = TS.import(script, script, "RadioGroup", "RadioGroupRoot").RadioGroupRoot
6
+ local RadioGroup = {
7
+ Root = RadioGroupRoot,
8
+ Item = RadioGroupItem,
9
+ Indicator = RadioGroupIndicator,
10
+ }
11
+ return {
12
+ RadioGroup = RadioGroup,
13
+ RadioGroupIndicator = RadioGroupIndicator,
14
+ RadioGroupItem = RadioGroupItem,
15
+ RadioGroupRoot = RadioGroupRoot,
16
+ }
package/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@lattice-ui/radio-group",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "private": false,
5
5
  "main": "out/init.luau",
6
6
  "types": "out/index.d.ts",
7
+ "files": [
8
+ "out",
9
+ "README.md"
10
+ ],
7
11
  "dependencies": {
8
- "@lattice-ui/core": "0.1.1",
9
- "@lattice-ui/focus": "0.1.1"
12
+ "@lattice-ui/core": "0.3.0",
13
+ "@lattice-ui/focus": "0.3.0"
10
14
  },
11
15
  "devDependencies": {
12
16
  "@rbxts/react": "17.3.7-ts.1",
@@ -18,7 +22,7 @@
18
22
  },
19
23
  "scripts": {
20
24
  "build": "rbxtsc -p tsconfig.json",
21
- "watch": "rbxtsc -p tsconfig.json -w",
22
- "typecheck": "tsc -p tsconfig.typecheck.json"
25
+ "typecheck": "tsc -p tsconfig.typecheck.json",
26
+ "watch": "rbxtsc -p tsconfig.json -w"
23
27
  }
24
28
  }
@@ -1,34 +0,0 @@
1
- import { React, Slot } from "@lattice-ui/core";
2
- import { useRadioGroupItemContext } from "./context";
3
- import type { RadioGroupIndicatorProps } from "./types";
4
-
5
- export function RadioGroupIndicator(props: RadioGroupIndicatorProps) {
6
- const radioGroupItemContext = useRadioGroupItemContext();
7
- const visible = radioGroupItemContext.checked;
8
- const forceMount = props.forceMount === true;
9
-
10
- if (!visible && !forceMount) {
11
- return undefined;
12
- }
13
-
14
- const child = props.children;
15
-
16
- if (props.asChild) {
17
- if (!React.isValidElement(child)) {
18
- error("[RadioGroupIndicator] `asChild` requires a child element.");
19
- }
20
-
21
- return <Slot Visible={visible}>{child}</Slot>;
22
- }
23
-
24
- return (
25
- <frame
26
- BackgroundColor3={Color3.fromRGB(240, 244, 252)}
27
- BorderSizePixel={0}
28
- Size={UDim2.fromOffset(10, 10)}
29
- Visible={visible}
30
- >
31
- {child}
32
- </frame>
33
- );
34
- }
@@ -1,89 +0,0 @@
1
- import { React, Slot } from "@lattice-ui/core";
2
- import { RovingFocusItem } from "@lattice-ui/focus";
3
- import { RadioGroupItemContextProvider, useRadioGroupContext } from "./context";
4
- import type { RadioGroupItemProps } from "./types";
5
-
6
- export function RadioGroupItem(props: RadioGroupItemProps) {
7
- const radioGroupContext = useRadioGroupContext();
8
- const disabled = radioGroupContext.disabled || props.disabled === true;
9
- const checked = radioGroupContext.value === props.value;
10
-
11
- const handleSelect = React.useCallback(() => {
12
- if (disabled) {
13
- return;
14
- }
15
-
16
- radioGroupContext.setValue(props.value);
17
- }, [disabled, props.value, radioGroupContext]);
18
-
19
- const handleInputBegan = React.useCallback(
20
- (_rbx: TextButton, inputObject: InputObject) => {
21
- if (disabled) {
22
- return;
23
- }
24
-
25
- const keyCode = inputObject.KeyCode;
26
- if (keyCode !== Enum.KeyCode.Return && keyCode !== Enum.KeyCode.Space) {
27
- return;
28
- }
29
-
30
- radioGroupContext.setValue(props.value);
31
- },
32
- [disabled, props.value, radioGroupContext],
33
- );
34
-
35
- const eventHandlers = React.useMemo(
36
- () => ({
37
- Activated: handleSelect,
38
- SelectionGained: handleSelect,
39
- InputBegan: handleInputBegan,
40
- }),
41
- [handleInputBegan, handleSelect],
42
- );
43
-
44
- const itemContextValue = React.useMemo(
45
- () => ({
46
- checked,
47
- disabled,
48
- }),
49
- [checked, disabled],
50
- );
51
-
52
- return (
53
- <RadioGroupItemContextProvider value={itemContextValue}>
54
- {props.asChild ? (
55
- (() => {
56
- const child = props.children;
57
- if (!child) {
58
- error("[RadioGroupItem] `asChild` requires a child element.");
59
- }
60
-
61
- return (
62
- <RovingFocusItem asChild disabled={disabled}>
63
- <Slot Active={!disabled} Event={eventHandlers} Selectable={!disabled}>
64
- {child}
65
- </Slot>
66
- </RovingFocusItem>
67
- );
68
- })()
69
- ) : (
70
- <RovingFocusItem asChild disabled={disabled}>
71
- <textbutton
72
- Active={!disabled}
73
- AutoButtonColor={false}
74
- BackgroundColor3={checked ? Color3.fromRGB(88, 142, 255) : Color3.fromRGB(47, 53, 68)}
75
- BorderSizePixel={0}
76
- Event={eventHandlers}
77
- Selectable={!disabled}
78
- Size={UDim2.fromOffset(170, 34)}
79
- Text={props.value}
80
- TextColor3={disabled ? Color3.fromRGB(139, 146, 160) : Color3.fromRGB(236, 241, 249)}
81
- TextSize={15}
82
- >
83
- {props.children}
84
- </textbutton>
85
- </RovingFocusItem>
86
- )}
87
- </RadioGroupItemContextProvider>
88
- );
89
- }
@@ -1,50 +0,0 @@
1
- import { React, useControllableState } from "@lattice-ui/core";
2
- import { RovingFocusGroup } from "@lattice-ui/focus";
3
- import { RadioGroupContextProvider } from "./context";
4
- import type { RadioGroupProps } from "./types";
5
-
6
- export function RadioGroupRoot(props: RadioGroupProps) {
7
- const [value, setValueState] = useControllableState<string | undefined>({
8
- value: props.value,
9
- defaultValue: props.defaultValue,
10
- onChange: (nextValue) => {
11
- if (nextValue !== undefined) {
12
- props.onValueChange?.(nextValue);
13
- }
14
- },
15
- });
16
-
17
- const disabled = props.disabled === true;
18
- const required = props.required === true;
19
- const loop = props.loop ?? true;
20
- const orientation = props.orientation ?? "vertical";
21
-
22
- const setValue = React.useCallback(
23
- (nextValue: string) => {
24
- if (disabled) {
25
- return;
26
- }
27
-
28
- setValueState(nextValue);
29
- },
30
- [disabled, setValueState],
31
- );
32
-
33
- const contextValue = React.useMemo(
34
- () => ({
35
- value,
36
- setValue,
37
- disabled,
38
- required,
39
- }),
40
- [disabled, required, setValue, value],
41
- );
42
-
43
- return (
44
- <RadioGroupContextProvider value={contextValue}>
45
- <RovingFocusGroup active={!disabled} autoFocus="none" loop={loop} orientation={orientation}>
46
- {props.children}
47
- </RovingFocusGroup>
48
- </RadioGroupContextProvider>
49
- );
50
- }
@@ -1,8 +0,0 @@
1
- import { createStrictContext } from "@lattice-ui/core";
2
- import type { RadioGroupContextValue, RadioGroupItemContextValue } from "./types";
3
-
4
- const [RadioGroupContextProvider, useRadioGroupContext] = createStrictContext<RadioGroupContextValue>("RadioGroup");
5
- const [RadioGroupItemContextProvider, useRadioGroupItemContext] =
6
- createStrictContext<RadioGroupItemContextValue>("RadioGroupItem");
7
-
8
- export { RadioGroupContextProvider, RadioGroupItemContextProvider, useRadioGroupContext, useRadioGroupItemContext };
@@ -1,41 +0,0 @@
1
- import type React from "@rbxts/react";
2
-
3
- export type RadioGroupOrientation = "horizontal" | "vertical" | "both";
4
-
5
- export type RadioGroupSetValue = (value: string) => void;
6
-
7
- export type RadioGroupContextValue = {
8
- value?: string;
9
- setValue: RadioGroupSetValue;
10
- disabled: boolean;
11
- required: boolean;
12
- };
13
-
14
- export type RadioGroupItemContextValue = {
15
- checked: boolean;
16
- disabled: boolean;
17
- };
18
-
19
- export type RadioGroupProps = {
20
- value?: string;
21
- defaultValue?: string;
22
- onValueChange?: (value: string) => void;
23
- disabled?: boolean;
24
- required?: boolean;
25
- loop?: boolean;
26
- orientation?: RadioGroupOrientation;
27
- children?: React.ReactNode;
28
- };
29
-
30
- export type RadioGroupItemProps = {
31
- value: string;
32
- disabled?: boolean;
33
- asChild?: boolean;
34
- children?: React.ReactElement;
35
- };
36
-
37
- export type RadioGroupIndicatorProps = {
38
- forceMount?: boolean;
39
- asChild?: boolean;
40
- children?: React.ReactNode;
41
- };
package/src/index.ts DELETED
@@ -1,11 +0,0 @@
1
- export { RadioGroupIndicator } from "./RadioGroup/RadioGroupIndicator";
2
- export { RadioGroupItem } from "./RadioGroup/RadioGroupItem";
3
- export { RadioGroupRoot, RadioGroupRoot as RadioGroup } from "./RadioGroup/RadioGroupRoot";
4
- export type {
5
- RadioGroupContextValue,
6
- RadioGroupIndicatorProps,
7
- RadioGroupItemContextValue,
8
- RadioGroupItemProps,
9
- RadioGroupProps,
10
- RadioGroupSetValue,
11
- } from "./RadioGroup/types";
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "rootDir": "src",
5
- "outDir": "out",
6
- "declaration": true,
7
- "typeRoots": [
8
- "./node_modules/@rbxts",
9
- "../../node_modules/@rbxts",
10
- "./node_modules/@lattice-ui",
11
- "../../node_modules/@lattice-ui"
12
- ],
13
- "types": ["types", "compiler-types"]
14
- },
15
- "include": ["src"]
16
- }
@@ -1,25 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "noEmit": true,
5
- "baseUrl": "..",
6
- "rootDir": "..",
7
- "paths": {
8
- "@lattice-ui/checkbox": ["checkbox/src/index.ts"],
9
- "@lattice-ui/core": ["core/src/index.ts"],
10
- "@lattice-ui/dialog": ["dialog/src/index.ts"],
11
- "@lattice-ui/focus": ["focus/src/index.ts"],
12
- "@lattice-ui/layer": ["layer/src/index.ts"],
13
- "@lattice-ui/menu": ["menu/src/index.ts"],
14
- "@lattice-ui/popover": ["popover/src/index.ts"],
15
- "@lattice-ui/popper": ["popper/src/index.ts"],
16
- "@lattice-ui/radio-group": ["radio-group/src/index.ts"],
17
- "@lattice-ui/style": ["style/src/index.ts"],
18
- "@lattice-ui/switch": ["switch/src/index.ts"],
19
- "@lattice-ui/system": ["system/src/index.ts"],
20
- "@lattice-ui/tabs": ["tabs/src/index.ts"],
21
- "@lattice-ui/toggle-group": ["toggle-group/src/index.ts"],
22
- "@lattice-ui/tooltip": ["tooltip/src/index.ts"]
23
- }
24
- }
25
- }