@cdx-ui/components 0.0.1-alpha.29 → 0.0.1-alpha.30
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/lib/commonjs/components/Button/index.js +3 -0
- package/lib/commonjs/components/Button/index.js.map +1 -1
- package/lib/commonjs/components/Form/FormLabelRoot.js +33 -0
- package/lib/commonjs/components/Form/FormLabelRoot.js.map +1 -0
- package/lib/commonjs/components/Form/FormLabelRoot.web.js +18 -0
- package/lib/commonjs/components/Form/FormLabelRoot.web.js.map +1 -0
- package/lib/commonjs/components/Form/FormRoot.js +25 -0
- package/lib/commonjs/components/Form/FormRoot.js.map +1 -0
- package/lib/commonjs/components/Form/FormRoot.web.js +17 -0
- package/lib/commonjs/components/Form/FormRoot.web.js.map +1 -0
- package/lib/commonjs/components/Form/index.js +255 -0
- package/lib/commonjs/components/Form/index.js.map +1 -0
- package/lib/commonjs/components/Form/styles.js +57 -0
- package/lib/commonjs/components/Form/styles.js.map +1 -0
- package/lib/commonjs/components/Select/SelectTriggerHost.js +10 -0
- package/lib/commonjs/components/Select/SelectTriggerHost.js.map +1 -0
- package/lib/commonjs/components/Select/SelectTriggerHost.web.js +98 -0
- package/lib/commonjs/components/Select/SelectTriggerHost.web.js.map +1 -0
- package/lib/commonjs/components/Select/index.js +2 -1
- package/lib/commonjs/components/Select/index.js.map +1 -1
- package/lib/commonjs/components/Select/styles.js +3 -3
- package/lib/commonjs/components/Select/styles.js.map +1 -1
- package/lib/commonjs/components/index.js +12 -0
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/index.js +40 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/components/Button/index.js +3 -0
- package/lib/module/components/Button/index.js.map +1 -1
- package/lib/module/components/Form/FormLabelRoot.js +29 -0
- package/lib/module/components/Form/FormLabelRoot.js.map +1 -0
- package/lib/module/components/Form/FormLabelRoot.web.js +13 -0
- package/lib/module/components/Form/FormLabelRoot.web.js.map +1 -0
- package/lib/module/components/Form/FormRoot.js +21 -0
- package/lib/module/components/Form/FormRoot.js.map +1 -0
- package/lib/module/components/Form/FormRoot.web.js +12 -0
- package/lib/module/components/Form/FormRoot.web.js.map +1 -0
- package/lib/module/components/Form/index.js +252 -0
- package/lib/module/components/Form/index.js.map +1 -0
- package/lib/module/components/Form/styles.js +53 -0
- package/lib/module/components/Form/styles.js.map +1 -0
- package/lib/module/components/Select/SelectTriggerHost.js +7 -0
- package/lib/module/components/Select/SelectTriggerHost.js.map +1 -0
- package/lib/module/components/Select/SelectTriggerHost.web.js +93 -0
- package/lib/module/components/Select/SelectTriggerHost.web.js.map +1 -0
- package/lib/module/components/Select/index.js +2 -1
- package/lib/module/components/Select/index.js.map +1 -1
- package/lib/module/components/Select/styles.js +3 -3
- package/lib/module/components/Select/styles.js.map +1 -1
- package/lib/module/components/index.js +1 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/components/Avatar/index.d.ts +1 -1
- package/lib/typescript/components/Avatar/index.d.ts.map +1 -1
- package/lib/typescript/components/Button/index.d.ts.map +1 -1
- package/lib/typescript/components/Checkbox/index.d.ts +1 -1
- package/lib/typescript/components/Checkbox/index.d.ts.map +1 -1
- package/lib/typescript/components/Dialog/index.d.ts +0 -1
- package/lib/typescript/components/Dialog/index.d.ts.map +1 -1
- package/lib/typescript/components/Form/FormLabelRoot.d.ts +18 -0
- package/lib/typescript/components/Form/FormLabelRoot.d.ts.map +1 -0
- package/lib/typescript/components/Form/FormLabelRoot.web.d.ts +20 -0
- package/lib/typescript/components/Form/FormLabelRoot.web.d.ts.map +1 -0
- package/lib/typescript/components/Form/FormRoot.d.ts +12 -0
- package/lib/typescript/components/Form/FormRoot.d.ts.map +1 -0
- package/lib/typescript/components/Form/FormRoot.web.d.ts +10 -0
- package/lib/typescript/components/Form/FormRoot.web.d.ts.map +1 -0
- package/lib/typescript/components/Form/index.d.ts +64 -0
- package/lib/typescript/components/Form/index.d.ts.map +1 -0
- package/lib/typescript/components/Form/styles.d.ts +22 -0
- package/lib/typescript/components/Form/styles.d.ts.map +1 -0
- package/lib/typescript/components/Input/index.d.ts +1 -1
- package/lib/typescript/components/Input/index.d.ts.map +1 -1
- package/lib/typescript/components/Select/SelectTriggerHost.d.ts +3 -0
- package/lib/typescript/components/Select/SelectTriggerHost.d.ts.map +1 -0
- package/lib/typescript/components/Select/SelectTriggerHost.web.d.ts +13 -0
- package/lib/typescript/components/Select/SelectTriggerHost.web.d.ts.map +1 -0
- package/lib/typescript/components/Select/index.d.ts +1 -1
- package/lib/typescript/components/Select/index.d.ts.map +1 -1
- package/lib/typescript/components/Select/styles.d.ts.map +1 -1
- package/lib/typescript/components/Switch/index.d.ts +0 -1
- package/lib/typescript/components/Switch/index.d.ts.map +1 -1
- package/lib/typescript/components/index.d.ts +1 -0
- package/lib/typescript/components/index.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +3 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/components/Avatar/index.tsx +0 -2
- package/src/components/Button/index.tsx +1 -0
- package/src/components/Checkbox/index.tsx +0 -2
- package/src/components/Dialog/index.tsx +0 -2
- package/src/components/Form/FormLabelRoot.tsx +33 -0
- package/src/components/Form/FormLabelRoot.web.tsx +18 -0
- package/src/components/Form/FormRoot.tsx +19 -0
- package/src/components/Form/FormRoot.web.tsx +12 -0
- package/src/components/Form/index.tsx +272 -0
- package/src/components/Form/styles.ts +75 -0
- package/src/components/Input/index.tsx +0 -2
- package/src/components/Select/SelectTriggerHost.tsx +4 -0
- package/src/components/Select/SelectTriggerHost.web.tsx +136 -0
- package/src/components/Select/index.tsx +2 -3
- package/src/components/Select/styles.ts +7 -3
- package/src/components/Switch/index.tsx +0 -2
- package/src/components/index.ts +1 -0
- package/src/index.ts +3 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/Select/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAa,IAAI,EAAE,KAAK,SAAS,EAAE,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAErF,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACvB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAQ,SAAS,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/Select/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAa,IAAI,EAAE,KAAK,SAAS,EAAE,IAAI,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAErF,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACvB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAQ,SAAS,EAAE,MAAM,SAAS,CAAC;AAE1C,OAAO,EACL,KAAK,kBAAkB,EAOxB,MAAM,UAAU,CAAC;AAsBlB,MAAM,WAAW,WAAY,SAAQ,SAAS,EAAE,YAAY,EAAE,kBAAkB;IAC9E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,QAAA,MAAM,UAAU,8FAcf,CAAC;AAQF,MAAM,WAAW,kBAAmB,SAAQ,mBAAmB;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,QAAA,MAAM,aAAa,qGAalB,CAAC;AAQF,MAAM,WAAW,gBAAiB,SAAQ,SAAS,EAAE,iBAAiB;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,QAAA,MAAM,WAAW,mGAMf,CAAC;AAQH,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC;CAAG;AAEvE,QAAA,MAAM,UAAU;qCAAoC,eAAe;;CAMlE,CAAC;AAQF,MAAM,WAAW,kBAAmB,SAAQ,SAAS,EAAE,mBAAmB;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,QAAA,MAAM,aAAa,qGAQlB,CAAC;AAQF,MAAM,WAAW,eAAgB,SAAQ,gBAAgB;IACvD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,QAAA,MAAM,UAAU,kGAYf,CAAC;AAQF,MAAM,WAAW,oBAAqB,SAAQ,SAAS,EAAE,qBAAqB;IAC5E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,QAAA,MAAM,eAAe,uGAUpB,CAAC;AAQF,KAAK,uBAAuB,GAAG,OAAO,UAAU,GAAG;IACjD,OAAO,EAAE,OAAO,aAAa,CAAC;IAC9B,KAAK,EAAE,OAAO,WAAW,CAAC;IAC1B,IAAI,EAAE,OAAO,UAAU,CAAC;IACxB,OAAO,EAAE,OAAO,aAAa,CAAC;IAC9B,IAAI,EAAE,OAAO,UAAU,CAAC;IACxB,SAAS,EAAE,OAAO,eAAe,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,MAAM,EAOb,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/components/Select/styles.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAkBlE,eAAO,MAAM,qBAAqB;;;8EAsCjC,CAAC;AAIF,eAAO,MAAM,mBAAmB;;8EAkB/B,CAAC;AAIF,eAAO,MAAM,kBAAkB;;
|
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/components/Select/styles.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAkBlE,eAAO,MAAM,qBAAqB;;;8EAsCjC,CAAC;AAIF,eAAO,MAAM,mBAAmB;;8EAkB/B,CAAC;AAIF,eAAO,MAAM,kBAAkB;;8EAiB9B,CAAC;AAIF,eAAO,MAAM,qBAAqB,oFAWhC,CAAC;AAIH,eAAO,MAAM,kBAAkB;;8EAsB9B,CAAC;AAIF,eAAO,MAAM,uBAAuB;;8EAanC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,YAAY,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
|
|
@@ -4,5 +4,4 @@ export interface SwitchProps extends ISwitchProps, SwitchVariantProps {
|
|
|
4
4
|
className?: string;
|
|
5
5
|
}
|
|
6
6
|
export declare const Switch: import("@cdx-ui/primitives").ISwitchComponentType<import("./BaseSwitch").BaseSwitchProps & import("react").RefAttributes<import("react-native").Switch>, unknown>;
|
|
7
|
-
export type { SwitchVariantProps };
|
|
8
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/Switch/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAgB,MAAM,oBAAoB,CAAC;AAErE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAInD,MAAM,WAAW,WAAY,SAAQ,YAAY,EAAE,kBAAkB;IACnE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,MAAM,mKAAkB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/Switch/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAgB,MAAM,oBAAoB,CAAC;AAErE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAInD,MAAM,WAAW,WAAY,SAAQ,YAAY,EAAE,kBAAkB;IACnE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,MAAM,mKAAkB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACzC,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACzC,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC"}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
/// <reference types="uniwind/types" preserve="true" />
|
|
1
2
|
export * from './components';
|
|
3
|
+
export { View, ScrollView, KeyboardAvoidingView } from 'react-native';
|
|
4
|
+
export { SafeAreaView, useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
2
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AACA,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdx-ui/components",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.30",
|
|
4
4
|
"main": "lib/commonjs/index.js",
|
|
5
5
|
"module": "lib/module/index.js",
|
|
6
6
|
"react-native": "src/index.ts",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"react": "^18.2.0 || ^19.0.0",
|
|
46
46
|
"react-native": ">=0.76.0",
|
|
47
47
|
"react-native-reanimated": ">=3.0.0",
|
|
48
|
+
"react-native-safe-area-context": ">=4.0.0",
|
|
48
49
|
"react-native-web": ">=0.19.0"
|
|
49
50
|
},
|
|
50
51
|
"peerDependenciesMeta": {
|
|
@@ -65,9 +66,9 @@
|
|
|
65
66
|
"@gorhom/bottom-sheet": "^5.2.6",
|
|
66
67
|
"class-variance-authority": "^0.7.1",
|
|
67
68
|
"uniwind": "1.4.1",
|
|
68
|
-
"@cdx-ui/
|
|
69
|
-
"@cdx-ui/
|
|
70
|
-
"@cdx-ui/
|
|
69
|
+
"@cdx-ui/icons": "0.0.1-alpha.30",
|
|
70
|
+
"@cdx-ui/primitives": "0.0.1-alpha.30",
|
|
71
|
+
"@cdx-ui/utils": "0.0.1-alpha.30"
|
|
71
72
|
},
|
|
72
73
|
"devDependencies": {
|
|
73
74
|
"@types/react": "*",
|
|
@@ -106,6 +106,7 @@ const ButtonLabel = forwardRef<Text, ButtonTextProps>(
|
|
|
106
106
|
|
|
107
107
|
ButtonLabel.displayName = 'Button.Label';
|
|
108
108
|
|
|
109
|
+
// TODO: Use ButtonGroupVariantProps
|
|
109
110
|
export interface ButtonGroupProps extends Omit<ViewProps, 'children'> {
|
|
110
111
|
className?: string;
|
|
111
112
|
children: ReactElement | ReactElement[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { forwardRef } from 'react';
|
|
2
|
+
import { Text, TextProps, type GestureResponderEvent } from 'react-native';
|
|
3
|
+
import { composeEventHandlers, useFormControlContext } from '@cdx-ui/utils';
|
|
4
|
+
|
|
5
|
+
export type FormLabelRootProps = TextProps & {
|
|
6
|
+
/** @platform web — forwarded on web; ignored here (see `FormLabelRoot.web`). */
|
|
7
|
+
htmlFor?: string;
|
|
8
|
+
/** Optional; composed with label tap-to-focus on native. */
|
|
9
|
+
onPress?: ((event: GestureResponderEvent) => void) | null;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Native: `Text` label row — tap focuses the field input via form context
|
|
14
|
+
* (parity with `<label htmlFor>` on web).
|
|
15
|
+
*/
|
|
16
|
+
export const FormLabelRoot = forwardRef<Text, FormLabelRootProps>(
|
|
17
|
+
({ htmlFor: _omitHtmlFor, onPress, ...props }, ref) => {
|
|
18
|
+
void _omitHtmlFor;
|
|
19
|
+
|
|
20
|
+
const { focusInput, isDisabled } = useFormControlContext();
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<Text
|
|
24
|
+
ref={ref}
|
|
25
|
+
{...props}
|
|
26
|
+
disabled={Boolean(isDisabled)}
|
|
27
|
+
onPress={composeEventHandlers(onPress, () => focusInput?.())}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
FormLabelRoot.displayName = 'FormLabelRoot';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React, { forwardRef, type ReactNode } from 'react';
|
|
2
|
+
import type { ViewProps } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export type FormLabelRootProps = ViewProps & {
|
|
5
|
+
htmlFor?: string;
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
/** Mirrors field invalid state from form context (`data-[invalid=true]` styling). */
|
|
8
|
+
'data-invalid'?: string;
|
|
9
|
+
/** @platform native — ignored on DOM `<label>`; set by form primitive for Uniwind. */
|
|
10
|
+
dataSet?: Record<string, string>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** Real `<label>` so clicking the label focuses the associated control (`htmlFor` → input `id`). */
|
|
14
|
+
export const FormLabelRoot = forwardRef<HTMLLabelElement, FormLabelRootProps>((props, ref) => {
|
|
15
|
+
return <label ref={ref} {...(props as React.LabelHTMLAttributes<HTMLLabelElement>)} />;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
FormLabelRoot.displayName = 'FormLabelRoot';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { forwardRef } from 'react';
|
|
2
|
+
import { View, type ViewProps } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export type BaseFormRootProps = ViewProps & {
|
|
5
|
+
onSubmit?: (e: React.SyntheticEvent) => void;
|
|
6
|
+
action?: string | ((formData: FormData) => void | Promise<void>);
|
|
7
|
+
method?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const BaseFormRoot = forwardRef<View, BaseFormRootProps>(
|
|
11
|
+
({ onSubmit: _onSubmit, action: _action, method: _method, ...props }, ref) => {
|
|
12
|
+
void _onSubmit;
|
|
13
|
+
void _action;
|
|
14
|
+
void _method;
|
|
15
|
+
return <View ref={ref} {...props} />;
|
|
16
|
+
},
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
BaseFormRoot.displayName = 'BaseFormRoot';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
|
|
3
|
+
export type BaseFormRootProps = React.FormHTMLAttributes<HTMLFormElement> & {
|
|
4
|
+
className?: string;
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const BaseFormRoot = forwardRef<HTMLFormElement, BaseFormRootProps>((props, ref) => {
|
|
9
|
+
return <form ref={ref} {...props} />;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
BaseFormRoot.displayName = 'BaseFormRoot';
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { forwardRef, type ReactNode } from 'react';
|
|
2
|
+
import { Text, View, type ViewProps, type TextProps } from 'react-native';
|
|
3
|
+
import { createForm, type IFormProps, type IFormFieldProps } from '@cdx-ui/primitives';
|
|
4
|
+
import { cn, withStyleContext, useStyleContext } from '@cdx-ui/utils';
|
|
5
|
+
import { Icon, type IconProps } from '../Icon';
|
|
6
|
+
import { BaseFormRoot, type BaseFormRootProps } from './FormRoot';
|
|
7
|
+
import { FormLabelRoot } from './FormLabelRoot';
|
|
8
|
+
import {
|
|
9
|
+
formRootVariants,
|
|
10
|
+
formFieldVariants,
|
|
11
|
+
formLabelVariants,
|
|
12
|
+
formHelperVariants,
|
|
13
|
+
formHelperTextVariants,
|
|
14
|
+
formErrorVariants,
|
|
15
|
+
formErrorTextVariants,
|
|
16
|
+
formErrorIconVariants,
|
|
17
|
+
} from './styles';
|
|
18
|
+
|
|
19
|
+
// =============================================================================
|
|
20
|
+
// SCOPE + CONTEXT
|
|
21
|
+
// =============================================================================
|
|
22
|
+
|
|
23
|
+
const SCOPE = 'FORM';
|
|
24
|
+
|
|
25
|
+
const FieldRoot = withStyleContext(View, SCOPE);
|
|
26
|
+
|
|
27
|
+
interface FormFieldStyleContext {
|
|
28
|
+
size?: 'default' | 'small';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const useFormStyleContext = () => useStyleContext(SCOPE) as FormFieldStyleContext;
|
|
32
|
+
|
|
33
|
+
// =============================================================================
|
|
34
|
+
// PRIMITIVE
|
|
35
|
+
// =============================================================================
|
|
36
|
+
|
|
37
|
+
const FormPrimitive = createForm({
|
|
38
|
+
Root: BaseFormRoot,
|
|
39
|
+
Field: FieldRoot,
|
|
40
|
+
Error: View,
|
|
41
|
+
ErrorText: Text,
|
|
42
|
+
ErrorIcon: View,
|
|
43
|
+
Label: FormLabelRoot,
|
|
44
|
+
Helper: View,
|
|
45
|
+
HelperText: Text,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// =============================================================================
|
|
49
|
+
// FORM ROOT (container — <form> on web, <View> on RN)
|
|
50
|
+
// =============================================================================
|
|
51
|
+
|
|
52
|
+
export interface FormProps extends BaseFormRootProps, IFormProps {
|
|
53
|
+
className?: string;
|
|
54
|
+
children?: ReactNode;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const FormRoot = forwardRef<View, FormProps>(({ className, children, style, ...props }, ref) => {
|
|
58
|
+
const computedClassName = cn(formRootVariants(), className);
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<FormPrimitive ref={ref} className={computedClassName} style={style} {...props}>
|
|
62
|
+
{children}
|
|
63
|
+
</FormPrimitive>
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
FormRoot.displayName = 'Form';
|
|
68
|
+
|
|
69
|
+
// =============================================================================
|
|
70
|
+
// FORM FIELD (per-field wrapper — provides context for label/error/helper/input)
|
|
71
|
+
// =============================================================================
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Field wrapper + context. For **initial focus**, pass `autoFocus` on `Input.Field` (not here).
|
|
75
|
+
*/
|
|
76
|
+
export interface FormFieldProps extends Omit<ViewProps, 'id' | 'name'>, IFormFieldProps {
|
|
77
|
+
className?: string;
|
|
78
|
+
children?: ReactNode;
|
|
79
|
+
size?: 'default' | 'small';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const FormField = forwardRef<View, FormFieldProps>(
|
|
83
|
+
({ size = 'default', className, children, style, ...props }, ref) => {
|
|
84
|
+
const computedClassName = cn(formFieldVariants(), className);
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<FormPrimitive.Field
|
|
88
|
+
ref={ref}
|
|
89
|
+
className={computedClassName}
|
|
90
|
+
style={style}
|
|
91
|
+
context={{ size }}
|
|
92
|
+
{...props}
|
|
93
|
+
>
|
|
94
|
+
{children}
|
|
95
|
+
</FormPrimitive.Field>
|
|
96
|
+
);
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
FormField.displayName = 'Form.Field';
|
|
101
|
+
|
|
102
|
+
// =============================================================================
|
|
103
|
+
// FORM LABEL
|
|
104
|
+
// =============================================================================
|
|
105
|
+
|
|
106
|
+
export interface FormLabelProps extends ViewProps {
|
|
107
|
+
className?: string;
|
|
108
|
+
children?: ReactNode;
|
|
109
|
+
/** @platform web — passed to `<label htmlFor>`; defaults to the field input id. */
|
|
110
|
+
htmlFor?: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// TODO: Accept accessibility labels for required indicator as props to support i18n
|
|
114
|
+
|
|
115
|
+
const FormLabel = forwardRef<View, FormLabelProps>(
|
|
116
|
+
({ className, children, style, htmlFor, ...props }, ref) => {
|
|
117
|
+
const { size } = useFormStyleContext();
|
|
118
|
+
const labelClassName = cn(formLabelVariants({ size }), className);
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<FormPrimitive.Label
|
|
122
|
+
ref={ref}
|
|
123
|
+
className={labelClassName}
|
|
124
|
+
style={style}
|
|
125
|
+
htmlFor={htmlFor}
|
|
126
|
+
requiredIndicator={
|
|
127
|
+
<Text className="text-red-500" aria-hidden>
|
|
128
|
+
{' *'}
|
|
129
|
+
</Text>
|
|
130
|
+
}
|
|
131
|
+
{...props}
|
|
132
|
+
>
|
|
133
|
+
{children}
|
|
134
|
+
</FormPrimitive.Label>
|
|
135
|
+
);
|
|
136
|
+
},
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
FormLabel.displayName = 'Form.Label';
|
|
140
|
+
|
|
141
|
+
// =============================================================================
|
|
142
|
+
// FORM HELPER
|
|
143
|
+
// =============================================================================
|
|
144
|
+
|
|
145
|
+
export interface FormHelperProps extends ViewProps {
|
|
146
|
+
className?: string;
|
|
147
|
+
children?: ReactNode;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const FormHelper = forwardRef<View, FormHelperProps>(
|
|
151
|
+
({ className, children, style, ...props }, ref) => {
|
|
152
|
+
const computedClassName = cn(formHelperVariants(), className);
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<FormPrimitive.Helper ref={ref} className={computedClassName} style={style} {...props}>
|
|
156
|
+
{children}
|
|
157
|
+
</FormPrimitive.Helper>
|
|
158
|
+
);
|
|
159
|
+
},
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
FormHelper.displayName = 'Form.Helper';
|
|
163
|
+
|
|
164
|
+
// =============================================================================
|
|
165
|
+
// FORM HELPER TEXT
|
|
166
|
+
// =============================================================================
|
|
167
|
+
|
|
168
|
+
export interface FormHelperTextProps extends TextProps {
|
|
169
|
+
className?: string;
|
|
170
|
+
children?: ReactNode;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const FormHelperText = forwardRef<Text, FormHelperTextProps>(
|
|
174
|
+
({ className, children, style, ...props }, ref) => {
|
|
175
|
+
const { size } = useFormStyleContext();
|
|
176
|
+
const computedClassName = cn(formHelperTextVariants({ size }), className);
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<FormPrimitive.HelperText ref={ref} className={computedClassName} style={style} {...props}>
|
|
180
|
+
{children}
|
|
181
|
+
</FormPrimitive.HelperText>
|
|
182
|
+
);
|
|
183
|
+
},
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
FormHelperText.displayName = 'Form.HelperText';
|
|
187
|
+
|
|
188
|
+
// =============================================================================
|
|
189
|
+
// FORM ERROR
|
|
190
|
+
// =============================================================================
|
|
191
|
+
|
|
192
|
+
export interface FormErrorProps extends ViewProps {
|
|
193
|
+
className?: string;
|
|
194
|
+
children?: ReactNode;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const FormError = forwardRef<View, FormErrorProps>(
|
|
198
|
+
({ className, children, style, ...props }, ref) => {
|
|
199
|
+
const computedClassName = cn(formErrorVariants(), className);
|
|
200
|
+
|
|
201
|
+
return (
|
|
202
|
+
<FormPrimitive.Error ref={ref} className={computedClassName} style={style} {...props}>
|
|
203
|
+
{children}
|
|
204
|
+
</FormPrimitive.Error>
|
|
205
|
+
);
|
|
206
|
+
},
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
FormError.displayName = 'Form.Error';
|
|
210
|
+
|
|
211
|
+
// =============================================================================
|
|
212
|
+
// FORM ERROR TEXT
|
|
213
|
+
// =============================================================================
|
|
214
|
+
|
|
215
|
+
export interface FormErrorTextProps extends TextProps {
|
|
216
|
+
className?: string;
|
|
217
|
+
children?: ReactNode;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const FormErrorText = forwardRef<Text, FormErrorTextProps>(
|
|
221
|
+
({ className, children, style, ...props }, ref) => {
|
|
222
|
+
const { size } = useFormStyleContext();
|
|
223
|
+
const computedClassName = cn(formErrorTextVariants({ size }), className);
|
|
224
|
+
|
|
225
|
+
return (
|
|
226
|
+
<FormPrimitive.ErrorText ref={ref} className={computedClassName} style={style} {...props}>
|
|
227
|
+
{children}
|
|
228
|
+
</FormPrimitive.ErrorText>
|
|
229
|
+
);
|
|
230
|
+
},
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
FormErrorText.displayName = 'Form.ErrorText';
|
|
234
|
+
|
|
235
|
+
// =============================================================================
|
|
236
|
+
// FORM ERROR ICON
|
|
237
|
+
// =============================================================================
|
|
238
|
+
|
|
239
|
+
export interface FormErrorIconProps extends Omit<IconProps, 'children'> {}
|
|
240
|
+
|
|
241
|
+
const FormErrorIcon = ({ className, style, as, ...props }: FormErrorIconProps) => {
|
|
242
|
+
const { size } = useFormStyleContext();
|
|
243
|
+
const computedClassName = cn(formErrorIconVariants({ size }), className);
|
|
244
|
+
|
|
245
|
+
return <Icon as={as} className={computedClassName} style={style} {...props} />;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
FormErrorIcon.displayName = 'Form.ErrorIcon';
|
|
249
|
+
|
|
250
|
+
// =============================================================================
|
|
251
|
+
// COMPOUND EXPORT
|
|
252
|
+
// =============================================================================
|
|
253
|
+
|
|
254
|
+
type FormCompoundComponent = typeof FormRoot & {
|
|
255
|
+
Field: typeof FormField;
|
|
256
|
+
Label: typeof FormLabel;
|
|
257
|
+
Helper: typeof FormHelper;
|
|
258
|
+
HelperText: typeof FormHelperText;
|
|
259
|
+
Error: typeof FormError;
|
|
260
|
+
ErrorText: typeof FormErrorText;
|
|
261
|
+
ErrorIcon: typeof FormErrorIcon;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
export const Form = Object.assign(FormRoot, {
|
|
265
|
+
Field: FormField,
|
|
266
|
+
Label: FormLabel,
|
|
267
|
+
Helper: FormHelper,
|
|
268
|
+
HelperText: FormHelperText,
|
|
269
|
+
Error: FormError,
|
|
270
|
+
ErrorText: FormErrorText,
|
|
271
|
+
ErrorIcon: FormErrorIcon,
|
|
272
|
+
}) as FormCompoundComponent;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
2
|
+
import {
|
|
3
|
+
COLOR_TEXT_INVALID,
|
|
4
|
+
COLOR_TEXT_SECONDARY,
|
|
5
|
+
DISABLED_OPACITY,
|
|
6
|
+
} from '../../styles/primitives';
|
|
7
|
+
|
|
8
|
+
export const formRootVariants = cva(['flex-col gap-4']);
|
|
9
|
+
|
|
10
|
+
export const formFieldVariants = cva(['flex-col gap-1.5 mb-4', 'web:last:mb-0', DISABLED_OPACITY]);
|
|
11
|
+
|
|
12
|
+
export const formLabelVariants = cva(
|
|
13
|
+
[
|
|
14
|
+
'flex-row items-center',
|
|
15
|
+
DISABLED_OPACITY,
|
|
16
|
+
'web:cursor-pointer',
|
|
17
|
+
'font-medium data-[invalid=true]:text-red-600',
|
|
18
|
+
],
|
|
19
|
+
{
|
|
20
|
+
variants: {
|
|
21
|
+
size: {
|
|
22
|
+
default: 'text-sm',
|
|
23
|
+
small: 'text-xs',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
defaultVariants: {
|
|
27
|
+
size: 'default',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export const formHelperVariants = cva(['flex-row items-center']);
|
|
33
|
+
|
|
34
|
+
export const formHelperTextVariants = cva([COLOR_TEXT_SECONDARY], {
|
|
35
|
+
variants: {
|
|
36
|
+
size: {
|
|
37
|
+
default: 'text-xs',
|
|
38
|
+
small: 'text-[11px]',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
defaultVariants: {
|
|
42
|
+
size: 'default',
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
export const formErrorVariants = cva(['flex-row items-center gap-1']);
|
|
47
|
+
|
|
48
|
+
export const formErrorTextVariants = cva([COLOR_TEXT_INVALID, 'font-medium'], {
|
|
49
|
+
variants: {
|
|
50
|
+
size: {
|
|
51
|
+
default: 'text-xs',
|
|
52
|
+
small: 'text-[11px]',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
defaultVariants: {
|
|
56
|
+
size: 'default',
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export const formErrorIconVariants = cva([COLOR_TEXT_INVALID], {
|
|
61
|
+
variants: {
|
|
62
|
+
size: {
|
|
63
|
+
default: 'size-3.5',
|
|
64
|
+
small: 'size-3',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
defaultVariants: {
|
|
68
|
+
size: 'default',
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export type FormLabelVariantProps = VariantProps<typeof formLabelVariants>;
|
|
73
|
+
export type FormHelperTextVariantProps = VariantProps<typeof formHelperTextVariants>;
|
|
74
|
+
export type FormErrorTextVariantProps = VariantProps<typeof formErrorTextVariants>;
|
|
75
|
+
export type FormErrorIconVariantProps = VariantProps<typeof formErrorIconVariants>;
|