@korsolutions/ui 0.0.80 → 0.0.82
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/module/components/index.js +1 -0
- package/dist/module/components/index.js.map +1 -1
- package/dist/module/components/radio-group/components/radio-group-content.js +27 -0
- package/dist/module/components/radio-group/components/radio-group-content.js.map +1 -0
- package/dist/module/components/radio-group/components/radio-group-description.js +27 -0
- package/dist/module/components/radio-group/components/radio-group-description.js.map +1 -0
- package/dist/module/components/radio-group/components/radio-group-indicator.js +31 -0
- package/dist/module/components/radio-group/components/radio-group-indicator.js.map +1 -0
- package/dist/module/components/radio-group/components/radio-group-item.js +56 -0
- package/dist/module/components/radio-group/components/radio-group-item.js.map +1 -0
- package/dist/module/components/radio-group/components/radio-group-root.js +41 -0
- package/dist/module/components/radio-group/components/radio-group-root.js.map +1 -0
- package/dist/module/components/radio-group/components/radio-group-title.js +27 -0
- package/dist/module/components/radio-group/components/radio-group-title.js.map +1 -0
- package/dist/module/components/radio-group/context.js +12 -0
- package/dist/module/components/radio-group/context.js.map +1 -0
- package/dist/module/components/radio-group/index.js +18 -0
- package/dist/module/components/radio-group/index.js.map +1 -0
- package/dist/module/components/radio-group/types.js +4 -0
- package/dist/module/components/radio-group/types.js.map +1 -0
- package/dist/module/components/radio-group/variants/default.js +81 -0
- package/dist/module/components/radio-group/variants/default.js.map +1 -0
- package/dist/module/components/radio-group/variants/index.js +9 -0
- package/dist/module/components/radio-group/variants/index.js.map +1 -0
- package/dist/module/components/radio-group/variants/outlined.js +94 -0
- package/dist/module/components/radio-group/variants/outlined.js.map +1 -0
- package/dist/module/hooks/use-organized-children.js +1 -0
- package/dist/module/hooks/use-organized-children.js.map +1 -1
- package/dist/typescript/src/components/index.d.ts +1 -0
- package/dist/typescript/src/components/index.d.ts.map +1 -1
- package/dist/typescript/src/components/radio-group/components/radio-group-content.d.ts +8 -0
- package/dist/typescript/src/components/radio-group/components/radio-group-content.d.ts.map +1 -0
- package/dist/typescript/src/components/radio-group/components/radio-group-description.d.ts +8 -0
- package/dist/typescript/src/components/radio-group/components/radio-group-description.d.ts.map +1 -0
- package/dist/typescript/src/components/radio-group/components/radio-group-indicator.d.ts +8 -0
- package/dist/typescript/src/components/radio-group/components/radio-group-indicator.d.ts.map +1 -0
- package/dist/typescript/src/components/radio-group/components/radio-group-item.d.ts +18 -0
- package/dist/typescript/src/components/radio-group/components/radio-group-item.d.ts.map +1 -0
- package/dist/typescript/src/components/radio-group/components/radio-group-root.d.ts +13 -0
- package/dist/typescript/src/components/radio-group/components/radio-group-root.d.ts.map +1 -0
- package/dist/typescript/src/components/radio-group/components/radio-group-title.d.ts +8 -0
- package/dist/typescript/src/components/radio-group/components/radio-group-title.d.ts.map +1 -0
- package/dist/typescript/src/components/radio-group/context.d.ts +12 -0
- package/dist/typescript/src/components/radio-group/context.d.ts.map +1 -0
- package/dist/typescript/src/components/radio-group/index.d.ts +22 -0
- package/dist/typescript/src/components/radio-group/index.d.ts.map +1 -0
- package/dist/typescript/src/components/radio-group/types.d.ts +13 -0
- package/dist/typescript/src/components/radio-group/types.d.ts.map +1 -0
- package/dist/typescript/src/components/radio-group/variants/default.d.ts +3 -0
- package/dist/typescript/src/components/radio-group/variants/default.d.ts.map +1 -0
- package/dist/typescript/src/components/radio-group/variants/index.d.ts +5 -0
- package/dist/typescript/src/components/radio-group/variants/index.d.ts.map +1 -0
- package/dist/typescript/src/components/radio-group/variants/outlined.d.ts +3 -0
- package/dist/typescript/src/components/radio-group/variants/outlined.d.ts.map +1 -0
- package/dist/typescript/src/hooks/use-organized-children.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/index.ts +1 -0
- package/src/components/radio-group/components/radio-group-content.tsx +23 -0
- package/src/components/radio-group/components/radio-group-description.tsx +23 -0
- package/src/components/radio-group/components/radio-group-indicator.tsx +24 -0
- package/src/components/radio-group/components/radio-group-item.tsx +73 -0
- package/src/components/radio-group/components/radio-group-root.tsx +46 -0
- package/src/components/radio-group/components/radio-group-title.tsx +23 -0
- package/src/components/radio-group/context.ts +20 -0
- package/src/components/radio-group/index.ts +23 -0
- package/src/components/radio-group/types.ts +14 -0
- package/src/components/radio-group/variants/default.tsx +78 -0
- package/src/components/radio-group/variants/index.ts +7 -0
- package/src/components/radio-group/variants/outlined.tsx +90 -0
- package/src/hooks/use-organized-children.tsx +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radio-group-root.d.ts","sourceRoot":"","sources":["../../../../../../src/components/radio-group/components/radio-group-root.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAQ,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAGpF,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC;IACtE,OAAO,CAAC,EAAE,MAAM,OAAO,kBAAkB,CAAC;IAC1C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC9B;AAOD,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,qBAyBxD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type StyleProp, type TextProps, type TextStyle } from "react-native";
|
|
3
|
+
export interface RadioGroupTitleProps extends TextProps {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
style?: StyleProp<TextStyle>;
|
|
6
|
+
}
|
|
7
|
+
export declare function RadioGroupTitle(props: RadioGroupTitleProps): React.JSX.Element;
|
|
8
|
+
//# sourceMappingURL=radio-group-title.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radio-group-title.d.ts","sourceRoot":"","sources":["../../../../../../src/components/radio-group/components/radio-group-title.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAQ,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAIpF,MAAM,WAAW,oBAAqB,SAAQ,SAAS;IACrD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC9B;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,qBAY1D"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { RadioGroupState, RadioGroupStyles } from "./types";
|
|
3
|
+
export interface RadioGroupContextValue {
|
|
4
|
+
value?: string;
|
|
5
|
+
onChange: (value: string) => void;
|
|
6
|
+
isDisabled?: boolean;
|
|
7
|
+
state: RadioGroupState;
|
|
8
|
+
styles?: RadioGroupStyles;
|
|
9
|
+
}
|
|
10
|
+
export declare const RadioGroupContext: React.Context<RadioGroupContextValue | null>;
|
|
11
|
+
export declare const useRadioGroupContext: () => RadioGroupContextValue;
|
|
12
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../../src/components/radio-group/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEjE,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,KAAK,EAAE,eAAe,CAAC;IACvB,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B;AAED,eAAO,MAAM,iBAAiB,8CAA2D,CAAC;AAE1F,eAAO,MAAM,oBAAoB,8BAMhC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RadioGroupContent } from "./components/radio-group-content";
|
|
2
|
+
import { RadioGroupDescription } from "./components/radio-group-description";
|
|
3
|
+
import { RadioGroupIndicator } from "./components/radio-group-indicator";
|
|
4
|
+
import { RadioGroupItem } from "./components/radio-group-item";
|
|
5
|
+
import { RadioGroupRoot } from "./components/radio-group-root";
|
|
6
|
+
import { RadioGroupTitle } from "./components/radio-group-title";
|
|
7
|
+
export declare const RadioGroup: {
|
|
8
|
+
Root: typeof RadioGroupRoot;
|
|
9
|
+
Item: typeof RadioGroupItem;
|
|
10
|
+
Indicator: typeof RadioGroupIndicator;
|
|
11
|
+
Content: typeof RadioGroupContent;
|
|
12
|
+
Title: typeof RadioGroupTitle;
|
|
13
|
+
Description: typeof RadioGroupDescription;
|
|
14
|
+
};
|
|
15
|
+
export type { RadioGroupContentProps } from "./components/radio-group-content";
|
|
16
|
+
export type { RadioGroupDescriptionProps } from "./components/radio-group-description";
|
|
17
|
+
export type { RadioGroupIndicatorProps } from "./components/radio-group-indicator";
|
|
18
|
+
export type { RadioGroupItemProps } from "./components/radio-group-item";
|
|
19
|
+
export type { RadioGroupRootProps } from "./components/radio-group-root";
|
|
20
|
+
export type { RadioGroupTitleProps } from "./components/radio-group-title";
|
|
21
|
+
export * from "./types";
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/radio-group/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE,eAAO,MAAM,UAAU;;;;;;;CAOtB,CAAC;AAEF,YAAY,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC/E,YAAY,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AACvF,YAAY,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AACnF,YAAY,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACzE,YAAY,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACzE,YAAY,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { StyleProp, TextStyle, ViewStyle } from "react-native";
|
|
2
|
+
export type RadioGroupState = "default" | "disabled";
|
|
3
|
+
export type RadioItemState = "default" | "selected" | "disabled" | "hovered";
|
|
4
|
+
export interface RadioGroupStyles {
|
|
5
|
+
root?: Partial<Record<RadioGroupState, StyleProp<ViewStyle>>>;
|
|
6
|
+
item?: Partial<Record<RadioItemState, StyleProp<ViewStyle>>>;
|
|
7
|
+
indicator?: Partial<Record<RadioItemState, StyleProp<ViewStyle>>>;
|
|
8
|
+
dot?: Partial<Record<RadioItemState, StyleProp<ViewStyle>>>;
|
|
9
|
+
content?: Partial<Record<RadioItemState, StyleProp<ViewStyle>>>;
|
|
10
|
+
title?: Partial<Record<RadioItemState, StyleProp<TextStyle>>>;
|
|
11
|
+
description?: Partial<Record<RadioItemState, StyleProp<TextStyle>>>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/components/radio-group/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEpE,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,UAAU,CAAC;AACrD,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC;AAE7E,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC9D,IAAI,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC7D,SAAS,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAClE,GAAG,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC5D,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAChE,KAAK,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAC9D,WAAW,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;CACrE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../../../../../src/components/radio-group/variants/default.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,eAAO,MAAM,2BAA2B,QAAO,gBA0E9C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/components/radio-group/variants/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB;;;CAG9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outlined.d.ts","sourceRoot":"","sources":["../../../../../../src/components/radio-group/variants/outlined.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,eAAO,MAAM,4BAA4B,QAAO,gBAsF/C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-organized-children.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-organized-children.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AACvC,OAAO,EAAQ,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG1D,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,SAAS,EAAE,SAAS,CAAC,SAAS,CAAC,GAAG,SAAS,EAC3C,SAAS,EAAE,SAAS,GAAG,SAAS,GAAG,IAAI,GACtC,KAAK,CAAC,SAAS,
|
|
1
|
+
{"version":3,"file":"use-organized-children.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-organized-children.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AACvC,OAAO,EAAQ,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG1D,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,SAAS,EAAE,SAAS,CAAC,SAAS,CAAC,GAAG,SAAS,EAC3C,SAAS,EAAE,SAAS,GAAG,SAAS,GAAG,IAAI,GACtC,KAAK,CAAC,SAAS,CA4BjB"}
|
package/package.json
CHANGED
package/src/components/index.ts
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View, type StyleProp, type ViewProps, type ViewStyle } from "react-native";
|
|
3
|
+
import { useRadioGroupContext } from "../context";
|
|
4
|
+
import { useRadioGroupItemContext } from "./radio-group-item";
|
|
5
|
+
|
|
6
|
+
export interface RadioGroupContentProps extends ViewProps {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
style?: StyleProp<ViewStyle>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function RadioGroupContent(props: RadioGroupContentProps) {
|
|
12
|
+
const { children, style, ...viewProps } = props;
|
|
13
|
+
const { styles } = useRadioGroupContext();
|
|
14
|
+
const { state } = useRadioGroupItemContext();
|
|
15
|
+
|
|
16
|
+
const composedStyle = [styles?.content?.default, styles?.content?.[state], style];
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<View {...viewProps} style={composedStyle}>
|
|
20
|
+
{children}
|
|
21
|
+
</View>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Text, type StyleProp, type TextProps, type TextStyle } from "react-native";
|
|
3
|
+
import { useRadioGroupContext } from "../context";
|
|
4
|
+
import { useRadioGroupItemContext } from "./radio-group-item";
|
|
5
|
+
|
|
6
|
+
export interface RadioGroupDescriptionProps extends TextProps {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
style?: StyleProp<TextStyle>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function RadioGroupDescription(props: RadioGroupDescriptionProps) {
|
|
12
|
+
const { children, style, ...textProps } = props;
|
|
13
|
+
const { styles } = useRadioGroupContext();
|
|
14
|
+
const { state } = useRadioGroupItemContext();
|
|
15
|
+
|
|
16
|
+
const composedStyle = [styles?.description?.default, styles?.description?.[state], style];
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Text {...textProps} style={composedStyle}>
|
|
20
|
+
{children}
|
|
21
|
+
</Text>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View, type StyleProp, type ViewProps, type ViewStyle } from "react-native";
|
|
3
|
+
import { useRadioGroupContext } from "../context";
|
|
4
|
+
import { useRadioGroupItemContext } from "./radio-group-item";
|
|
5
|
+
|
|
6
|
+
export interface RadioGroupIndicatorProps extends ViewProps {
|
|
7
|
+
style?: StyleProp<ViewStyle>;
|
|
8
|
+
dotStyle?: StyleProp<ViewStyle>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function RadioGroupIndicator(props: RadioGroupIndicatorProps) {
|
|
12
|
+
const { style, dotStyle, ...viewProps } = props;
|
|
13
|
+
const { styles } = useRadioGroupContext();
|
|
14
|
+
const { state, isSelected } = useRadioGroupItemContext();
|
|
15
|
+
|
|
16
|
+
const indicatorStyle = [styles?.indicator?.default, styles?.indicator?.[state], style];
|
|
17
|
+
const computedDotStyle = [styles?.dot?.default, dotStyle];
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<View {...viewProps} style={indicatorStyle}>
|
|
21
|
+
{isSelected && <View style={computedDotStyle} />}
|
|
22
|
+
</View>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import { Pressable, type PressableProps, type StyleProp, type ViewStyle } from "react-native";
|
|
3
|
+
import { useRadioGroupContext } from "../context";
|
|
4
|
+
import type { RadioItemState } from "../types";
|
|
5
|
+
|
|
6
|
+
export interface RadioGroupItemProps extends Omit<PressableProps, "children"> {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
value: string;
|
|
9
|
+
isDisabled?: boolean;
|
|
10
|
+
style?: StyleProp<ViewStyle>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const calculateState = (
|
|
14
|
+
isSelected: boolean,
|
|
15
|
+
isDisabled: boolean | undefined,
|
|
16
|
+
isHovered: boolean,
|
|
17
|
+
): RadioItemState => {
|
|
18
|
+
if (isDisabled) return "disabled";
|
|
19
|
+
if (isSelected) return "selected";
|
|
20
|
+
if (isHovered) return "hovered";
|
|
21
|
+
return "default";
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function RadioGroupItem(props: RadioGroupItemProps) {
|
|
25
|
+
const { children, value, isDisabled, style, ...pressableProps } = props;
|
|
26
|
+
const group = useRadioGroupContext();
|
|
27
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
28
|
+
|
|
29
|
+
const isSelected = group.value === value;
|
|
30
|
+
const itemDisabled = isDisabled ?? group.isDisabled;
|
|
31
|
+
const state = calculateState(isSelected, itemDisabled, isHovered);
|
|
32
|
+
|
|
33
|
+
const composedStyle = [
|
|
34
|
+
group.styles?.item?.default,
|
|
35
|
+
group.styles?.item?.[state],
|
|
36
|
+
style,
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<RadioGroupItemContext.Provider value={{ value, state, isSelected }}>
|
|
41
|
+
<Pressable
|
|
42
|
+
{...pressableProps}
|
|
43
|
+
disabled={itemDisabled}
|
|
44
|
+
onPress={() => {
|
|
45
|
+
if (!itemDisabled) {
|
|
46
|
+
group.onChange(value);
|
|
47
|
+
}
|
|
48
|
+
}}
|
|
49
|
+
onHoverIn={() => setIsHovered(true)}
|
|
50
|
+
onHoverOut={() => setIsHovered(false)}
|
|
51
|
+
style={composedStyle}
|
|
52
|
+
>
|
|
53
|
+
{children}
|
|
54
|
+
</Pressable>
|
|
55
|
+
</RadioGroupItemContext.Provider>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface RadioGroupItemContextValue {
|
|
60
|
+
value: string;
|
|
61
|
+
state: RadioItemState;
|
|
62
|
+
isSelected: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const RadioGroupItemContext = React.createContext<RadioGroupItemContextValue | null>(null);
|
|
66
|
+
|
|
67
|
+
export const useRadioGroupItemContext = () => {
|
|
68
|
+
const context = React.useContext(RadioGroupItemContext);
|
|
69
|
+
if (!context) {
|
|
70
|
+
throw new Error("RadioGroup item components must be used within RadioGroup.Item");
|
|
71
|
+
}
|
|
72
|
+
return context;
|
|
73
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View, type StyleProp, type ViewProps, type ViewStyle } from "react-native";
|
|
3
|
+
import { RadioGroupContext } from "../context";
|
|
4
|
+
import type { RadioGroupState } from "../types";
|
|
5
|
+
import { RadioGroupVariants } from "../variants";
|
|
6
|
+
|
|
7
|
+
export interface RadioGroupRootProps extends Omit<ViewProps, "children"> {
|
|
8
|
+
variant?: keyof typeof RadioGroupVariants;
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
value?: string;
|
|
11
|
+
onChange: (value: string) => void;
|
|
12
|
+
isDisabled?: boolean;
|
|
13
|
+
style?: StyleProp<ViewStyle>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const calculateState = (isDisabled: boolean | undefined): RadioGroupState => {
|
|
17
|
+
if (isDisabled) return "disabled";
|
|
18
|
+
return "default";
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function RadioGroupRoot(props: RadioGroupRootProps) {
|
|
22
|
+
const { children, value, onChange, isDisabled, style, variant, ...viewProps } = props;
|
|
23
|
+
const variantStyles = RadioGroupVariants[variant ?? "default"]();
|
|
24
|
+
|
|
25
|
+
const state = calculateState(isDisabled);
|
|
26
|
+
const composedStyle = [variantStyles.root?.default, variantStyles.root?.[state], style];
|
|
27
|
+
|
|
28
|
+
const contextValue = React.useMemo(
|
|
29
|
+
() => ({
|
|
30
|
+
value,
|
|
31
|
+
onChange,
|
|
32
|
+
isDisabled,
|
|
33
|
+
state,
|
|
34
|
+
styles: variantStyles,
|
|
35
|
+
}),
|
|
36
|
+
[value, onChange, isDisabled, state, variantStyles],
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<RadioGroupContext.Provider value={contextValue}>
|
|
41
|
+
<View {...viewProps} style={composedStyle}>
|
|
42
|
+
{children}
|
|
43
|
+
</View>
|
|
44
|
+
</RadioGroupContext.Provider>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Text, type StyleProp, type TextProps, type TextStyle } from "react-native";
|
|
3
|
+
import { useRadioGroupContext } from "../context";
|
|
4
|
+
import { useRadioGroupItemContext } from "./radio-group-item";
|
|
5
|
+
|
|
6
|
+
export interface RadioGroupTitleProps extends TextProps {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
style?: StyleProp<TextStyle>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function RadioGroupTitle(props: RadioGroupTitleProps) {
|
|
12
|
+
const { children, style, ...textProps } = props;
|
|
13
|
+
const { styles } = useRadioGroupContext();
|
|
14
|
+
const { state } = useRadioGroupItemContext();
|
|
15
|
+
|
|
16
|
+
const composedStyle = [styles?.title?.default, styles?.title?.[state], style];
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Text {...textProps} style={composedStyle}>
|
|
20
|
+
{children}
|
|
21
|
+
</Text>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { RadioGroupState, RadioGroupStyles } from "./types";
|
|
3
|
+
|
|
4
|
+
export interface RadioGroupContextValue {
|
|
5
|
+
value?: string;
|
|
6
|
+
onChange: (value: string) => void;
|
|
7
|
+
isDisabled?: boolean;
|
|
8
|
+
state: RadioGroupState;
|
|
9
|
+
styles?: RadioGroupStyles;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const RadioGroupContext = React.createContext<RadioGroupContextValue | null>(null);
|
|
13
|
+
|
|
14
|
+
export const useRadioGroupContext = () => {
|
|
15
|
+
const context = React.useContext(RadioGroupContext);
|
|
16
|
+
if (!context) {
|
|
17
|
+
throw new Error("RadioGroup compound components must be used within RadioGroup.Root");
|
|
18
|
+
}
|
|
19
|
+
return context;
|
|
20
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { RadioGroupContent } from "./components/radio-group-content";
|
|
2
|
+
import { RadioGroupDescription } from "./components/radio-group-description";
|
|
3
|
+
import { RadioGroupIndicator } from "./components/radio-group-indicator";
|
|
4
|
+
import { RadioGroupItem } from "./components/radio-group-item";
|
|
5
|
+
import { RadioGroupRoot } from "./components/radio-group-root";
|
|
6
|
+
import { RadioGroupTitle } from "./components/radio-group-title";
|
|
7
|
+
|
|
8
|
+
export const RadioGroup = {
|
|
9
|
+
Root: RadioGroupRoot,
|
|
10
|
+
Item: RadioGroupItem,
|
|
11
|
+
Indicator: RadioGroupIndicator,
|
|
12
|
+
Content: RadioGroupContent,
|
|
13
|
+
Title: RadioGroupTitle,
|
|
14
|
+
Description: RadioGroupDescription,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type { RadioGroupContentProps } from "./components/radio-group-content";
|
|
18
|
+
export type { RadioGroupDescriptionProps } from "./components/radio-group-description";
|
|
19
|
+
export type { RadioGroupIndicatorProps } from "./components/radio-group-indicator";
|
|
20
|
+
export type { RadioGroupItemProps } from "./components/radio-group-item";
|
|
21
|
+
export type { RadioGroupRootProps } from "./components/radio-group-root";
|
|
22
|
+
export type { RadioGroupTitleProps } from "./components/radio-group-title";
|
|
23
|
+
export * from "./types";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { StyleProp, TextStyle, ViewStyle } from "react-native";
|
|
2
|
+
|
|
3
|
+
export type RadioGroupState = "default" | "disabled";
|
|
4
|
+
export type RadioItemState = "default" | "selected" | "disabled" | "hovered";
|
|
5
|
+
|
|
6
|
+
export interface RadioGroupStyles {
|
|
7
|
+
root?: Partial<Record<RadioGroupState, StyleProp<ViewStyle>>>;
|
|
8
|
+
item?: Partial<Record<RadioItemState, StyleProp<ViewStyle>>>;
|
|
9
|
+
indicator?: Partial<Record<RadioItemState, StyleProp<ViewStyle>>>;
|
|
10
|
+
dot?: Partial<Record<RadioItemState, StyleProp<ViewStyle>>>;
|
|
11
|
+
content?: Partial<Record<RadioItemState, StyleProp<ViewStyle>>>;
|
|
12
|
+
title?: Partial<Record<RadioItemState, StyleProp<TextStyle>>>;
|
|
13
|
+
description?: Partial<Record<RadioItemState, StyleProp<TextStyle>>>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useThemedStyles } from "../../../utils/use-themed-styles";
|
|
2
|
+
import type { RadioGroupStyles } from "../types";
|
|
3
|
+
|
|
4
|
+
export const useRadioGroupVariantDefault = (): RadioGroupStyles => {
|
|
5
|
+
return useThemedStyles(
|
|
6
|
+
({ colors, fontFamily, fontSize }): RadioGroupStyles => ({
|
|
7
|
+
root: {
|
|
8
|
+
default: {
|
|
9
|
+
gap: 8,
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
item: {
|
|
13
|
+
default: {
|
|
14
|
+
flexDirection: "row",
|
|
15
|
+
alignItems: "flex-start",
|
|
16
|
+
gap: 12,
|
|
17
|
+
},
|
|
18
|
+
disabled: {
|
|
19
|
+
opacity: 0.5,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
indicator: {
|
|
23
|
+
default: {
|
|
24
|
+
width: 20,
|
|
25
|
+
height: 20,
|
|
26
|
+
borderRadius: 10,
|
|
27
|
+
borderWidth: 2,
|
|
28
|
+
borderColor: colors.border,
|
|
29
|
+
backgroundColor: colors.background,
|
|
30
|
+
marginTop: 2,
|
|
31
|
+
alignItems: "center",
|
|
32
|
+
justifyContent: "center",
|
|
33
|
+
},
|
|
34
|
+
selected: {
|
|
35
|
+
borderColor: colors.primary,
|
|
36
|
+
},
|
|
37
|
+
disabled: {
|
|
38
|
+
opacity: 0.5,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
dot: {
|
|
42
|
+
default: {
|
|
43
|
+
width: 8,
|
|
44
|
+
height: 8,
|
|
45
|
+
borderRadius: 4,
|
|
46
|
+
backgroundColor: colors.primary,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
content: {
|
|
50
|
+
default: {
|
|
51
|
+
flex: 1,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
title: {
|
|
55
|
+
default: {
|
|
56
|
+
color: colors.foreground,
|
|
57
|
+
fontSize,
|
|
58
|
+
fontFamily,
|
|
59
|
+
fontWeight: "500",
|
|
60
|
+
},
|
|
61
|
+
disabled: {
|
|
62
|
+
color: colors.mutedForeground,
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
description: {
|
|
66
|
+
default: {
|
|
67
|
+
color: colors.mutedForeground,
|
|
68
|
+
fontSize: fontSize * 0.875,
|
|
69
|
+
fontFamily,
|
|
70
|
+
marginTop: 2,
|
|
71
|
+
},
|
|
72
|
+
disabled: {
|
|
73
|
+
opacity: 0.7,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { useThemedStyles } from "../../../utils/use-themed-styles";
|
|
2
|
+
import type { RadioGroupStyles } from "../types";
|
|
3
|
+
|
|
4
|
+
export const useRadioGroupVariantOutlined = (): RadioGroupStyles => {
|
|
5
|
+
return useThemedStyles(
|
|
6
|
+
({ colors, radius, fontFamily, fontSize }): RadioGroupStyles => ({
|
|
7
|
+
root: {
|
|
8
|
+
default: {
|
|
9
|
+
gap: 8,
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
item: {
|
|
13
|
+
default: {
|
|
14
|
+
flexDirection: "row",
|
|
15
|
+
alignItems: "flex-start",
|
|
16
|
+
gap: 12,
|
|
17
|
+
borderWidth: 1,
|
|
18
|
+
borderColor: colors.border,
|
|
19
|
+
borderRadius: radius,
|
|
20
|
+
padding: 16,
|
|
21
|
+
backgroundColor: colors.background,
|
|
22
|
+
},
|
|
23
|
+
hovered: {
|
|
24
|
+
backgroundColor: colors.muted,
|
|
25
|
+
borderColor: colors.primary,
|
|
26
|
+
},
|
|
27
|
+
selected: {
|
|
28
|
+
borderColor: colors.primary,
|
|
29
|
+
},
|
|
30
|
+
disabled: {
|
|
31
|
+
opacity: 0.5,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
indicator: {
|
|
35
|
+
default: {
|
|
36
|
+
width: 20,
|
|
37
|
+
height: 20,
|
|
38
|
+
borderRadius: 10,
|
|
39
|
+
borderWidth: 2,
|
|
40
|
+
borderColor: colors.border,
|
|
41
|
+
backgroundColor: colors.background,
|
|
42
|
+
marginTop: 2,
|
|
43
|
+
alignItems: "center",
|
|
44
|
+
justifyContent: "center",
|
|
45
|
+
},
|
|
46
|
+
selected: {
|
|
47
|
+
borderColor: colors.primary,
|
|
48
|
+
},
|
|
49
|
+
disabled: {
|
|
50
|
+
opacity: 0.5,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
dot: {
|
|
54
|
+
default: {
|
|
55
|
+
width: 8,
|
|
56
|
+
height: 8,
|
|
57
|
+
borderRadius: 4,
|
|
58
|
+
backgroundColor: colors.primary,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
content: {
|
|
62
|
+
default: {
|
|
63
|
+
flex: 1,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
title: {
|
|
67
|
+
default: {
|
|
68
|
+
color: colors.foreground,
|
|
69
|
+
fontSize,
|
|
70
|
+
fontFamily,
|
|
71
|
+
fontWeight: "500",
|
|
72
|
+
},
|
|
73
|
+
disabled: {
|
|
74
|
+
color: colors.mutedForeground,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
description: {
|
|
78
|
+
default: {
|
|
79
|
+
color: colors.mutedForeground,
|
|
80
|
+
fontSize: fontSize * 0.875,
|
|
81
|
+
fontFamily,
|
|
82
|
+
marginTop: 2,
|
|
83
|
+
},
|
|
84
|
+
disabled: {
|
|
85
|
+
opacity: 0.7,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
);
|
|
90
|
+
};
|