@impulse-ui-native/form-field 2.7.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 ImpulseUI Native contributors
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 ADDED
@@ -0,0 +1,43 @@
1
+ # @impulse-ui-native/form-field
2
+
3
+ Accessible label, description, required-state, and validation composition for custom Impulse UI Native controls.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ pnpm add @impulse-ui-native/form-field
9
+ ```
10
+
11
+ Render `FormField` inside `ThemeProvider` from `@impulse-ui-native/theme`.
12
+
13
+ ## Usage
14
+
15
+ ```tsx
16
+ import { FormField } from "@impulse-ui-native/form-field";
17
+ import { Switch } from "@impulse-ui-native/switch";
18
+
19
+ <FormField
20
+ label="Notifications"
21
+ description="Receive updates about your account."
22
+ required
23
+ error={notificationError}
24
+ >
25
+ {({ controlProps }) => (
26
+ <Switch
27
+ {...controlProps}
28
+ checked={notificationsEnabled}
29
+ onCheckedChange={setNotificationsEnabled}
30
+ />
31
+ )}
32
+ </FormField>;
33
+ ```
34
+
35
+ The render function receives:
36
+
37
+ - `controlProps`: the generated native ID, accessible label, label relationship, hint, disabled state, and accessibility state to spread onto the control;
38
+ - `invalid`: whether the field currently has an error;
39
+ - `required`: the field's required state for custom visual treatment.
40
+
41
+ `FormField` renders validation feedback once outside the custom control. Use `invalid` only to map the field state into a control's own visual API; do not render the error a second time inside the control.
42
+
43
+ The required marker is both visible and included in the accessible label. Errors are announced as a polite live region and included in the control's accessibility hint. An explicit `nativeID` can be provided when stable IDs are required; otherwise, `FormField` generates one with React `useId`.
@@ -0,0 +1,9 @@
1
+ import * as react from 'react';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import { FormFieldProps } from '../types/form-field.types.mjs';
4
+ import 'react-native';
5
+ import '@impulse-ui-native/primitives';
6
+
7
+ declare const FormField: react.MemoExoticComponent<({ children, description, disabled, error, label, nativeID, required, style, ...props }: FormFieldProps) => react_jsx_runtime.JSX.Element>;
8
+
9
+ export { FormField };
@@ -0,0 +1,76 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { memo, useId, useMemo } from "react";
3
+ import { Control, Typography } from "@impulse-ui-native/primitives";
4
+ import { useThemedStyles } from "@impulse-ui-native/theme";
5
+ import { formFieldStyles } from "./form-field.styles";
6
+ const FormField = memo(function FormField2({
7
+ children,
8
+ description,
9
+ disabled = false,
10
+ error,
11
+ label,
12
+ nativeID,
13
+ required = false,
14
+ style,
15
+ ...props
16
+ }) {
17
+ const generatedId = useId();
18
+ const fieldId = nativeID ?? `form-field-${generatedId}`;
19
+ const labelId = `${fieldId}-label`;
20
+ const controlId = `${fieldId}-control`;
21
+ const descriptionId = `${fieldId}-description`;
22
+ const errorId = `${fieldId}-error`;
23
+ const invalid = Boolean(error);
24
+ const accessibleLabel = required ? `${label}, required` : label;
25
+ const accessibilityHint = [error, description].filter(Boolean).join(" ");
26
+ const styles = useThemedStyles(formFieldStyles, { disabled }, [disabled]);
27
+ const controlProps = useMemo(
28
+ () => ({
29
+ accessibilityHint: accessibilityHint || void 0,
30
+ accessibilityLabel: accessibleLabel,
31
+ accessibilityLabelledBy: labelId,
32
+ accessibilityState: { disabled },
33
+ disabled,
34
+ nativeID: controlId
35
+ }),
36
+ [accessibilityHint, accessibleLabel, controlId, disabled, labelId]
37
+ );
38
+ const renderProps = useMemo(
39
+ () => ({ controlProps, invalid, required }),
40
+ [controlProps, invalid, required]
41
+ );
42
+ return /* @__PURE__ */ jsx(
43
+ Control.Provider,
44
+ {
45
+ disabled,
46
+ error,
47
+ size: "medium",
48
+ variant: "outlined",
49
+ children: /* @__PURE__ */ jsxs(Control.Root, { ...props, nativeID: fieldId, style, children: [
50
+ /* @__PURE__ */ jsx(
51
+ Control.Label,
52
+ {
53
+ accessibilityLabel: accessibleLabel,
54
+ disabled,
55
+ nativeID: labelId,
56
+ children: required ? `${label} *` : label
57
+ }
58
+ ),
59
+ description ? /* @__PURE__ */ jsx(
60
+ Typography.Caption,
61
+ {
62
+ nativeID: descriptionId,
63
+ style: styles.description,
64
+ children: description
65
+ }
66
+ ) : null,
67
+ children(renderProps),
68
+ /* @__PURE__ */ jsx(Control.Error, { accessibilityLiveRegion: "polite", nativeID: errorId })
69
+ ] })
70
+ }
71
+ );
72
+ });
73
+ export {
74
+ FormField
75
+ };
76
+ //# sourceMappingURL=form-field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/form-field.tsx"],"sourcesContent":["import { memo, useId, useMemo } from \"react\";\n\nimport { Control, Typography } from \"@impulse-ui-native/primitives\";\nimport { useThemedStyles } from \"@impulse-ui-native/theme\";\n\nimport type {\n FormFieldControlProps,\n FormFieldProps,\n FormFieldRenderProps,\n} from \"../types\";\nimport { formFieldStyles } from \"./form-field.styles\";\n\nexport const FormField = memo(function FormField({\n children,\n description,\n disabled = false,\n error,\n label,\n nativeID,\n required = false,\n style,\n ...props\n}: FormFieldProps) {\n const generatedId = useId();\n const fieldId = nativeID ?? `form-field-${generatedId}`;\n const labelId = `${fieldId}-label`;\n const controlId = `${fieldId}-control`;\n const descriptionId = `${fieldId}-description`;\n const errorId = `${fieldId}-error`;\n const invalid = Boolean(error);\n const accessibleLabel = required ? `${label}, required` : label;\n const accessibilityHint = [error, description].filter(Boolean).join(\" \");\n const styles = useThemedStyles(formFieldStyles, { disabled }, [disabled]);\n\n const controlProps = useMemo<FormFieldControlProps>(\n () => ({\n accessibilityHint: accessibilityHint || undefined,\n accessibilityLabel: accessibleLabel,\n accessibilityLabelledBy: labelId,\n accessibilityState: { disabled },\n disabled,\n nativeID: controlId,\n }),\n [accessibilityHint, accessibleLabel, controlId, disabled, labelId],\n );\n const renderProps = useMemo<FormFieldRenderProps>(\n () => ({ controlProps, invalid, required }),\n [controlProps, invalid, required],\n );\n\n return (\n <Control.Provider\n disabled={disabled}\n error={error}\n size=\"medium\"\n variant=\"outlined\"\n >\n <Control.Root {...props} nativeID={fieldId} style={style}>\n <Control.Label\n accessibilityLabel={accessibleLabel}\n disabled={disabled}\n nativeID={labelId}\n >\n {required ? `${label} *` : label}\n </Control.Label>\n {description ? (\n <Typography.Caption\n nativeID={descriptionId}\n style={styles.description}\n >\n {description}\n </Typography.Caption>\n ) : null}\n {children(renderProps)}\n <Control.Error accessibilityLiveRegion=\"polite\" nativeID={errorId} />\n </Control.Root>\n </Control.Provider>\n );\n});\n"],"mappings":"AAyDM,SACE,KADF;AAzDN,SAAS,MAAM,OAAO,eAAe;AAErC,SAAS,SAAS,kBAAkB;AACpC,SAAS,uBAAuB;AAOhC,SAAS,uBAAuB;AAEzB,MAAM,YAAY,KAAK,SAASA,WAAU;AAAA,EAC/C;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX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SAAS,WAAW;AAAA,QACrB,oBAAC,QAAQ,OAAR,EAAc,yBAAwB,UAAS,UAAU,SAAS;AAAA,SACrE;AAAA;AAAA,EACF;AAEJ,CAAC;","names":["FormField"]}
@@ -0,0 +1,12 @@
1
+ import { AppTheme } from '@impulse-ui-native/theme';
2
+
3
+ declare function formFieldStyles(theme: AppTheme, { disabled }: {
4
+ disabled: boolean;
5
+ }): {
6
+ description: {
7
+ color: string;
8
+ marginBottom: number;
9
+ };
10
+ };
11
+
12
+ export { formFieldStyles };
@@ -0,0 +1,13 @@
1
+ import { StyleSheet } from "react-native";
2
+ function formFieldStyles(theme, { disabled }) {
3
+ return StyleSheet.create({
4
+ description: {
5
+ color: disabled ? theme.colors.text.disabled : theme.colors.text.secondary,
6
+ marginBottom: theme.space.xxs
7
+ }
8
+ });
9
+ }
10
+ export {
11
+ formFieldStyles
12
+ };
13
+ //# sourceMappingURL=form-field.styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/form-field.styles.ts"],"sourcesContent":["import { StyleSheet } from \"react-native\";\n\nimport type { AppTheme } from \"@impulse-ui-native/theme\";\n\nexport function formFieldStyles(\n theme: AppTheme,\n { disabled }: { disabled: boolean },\n) {\n return StyleSheet.create({\n description: {\n color: disabled\n ? theme.colors.text.disabled\n : theme.colors.text.secondary,\n marginBottom: theme.space.xxs,\n },\n });\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAIpB,SAAS,gBACd,OACA,EAAE,SAAS,GACX;AACA,SAAO,WAAW,OAAO;AAAA,IACvB,aAAa;AAAA,MACX,OAAO,WACH,MAAM,OAAO,KAAK,WAClB,MAAM,OAAO,KAAK;AAAA,MACtB,cAAc,MAAM,MAAM;AAAA,IAC5B;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,6 @@
1
+ export { FormField } from './form-field.mjs';
2
+ import 'react';
3
+ import 'react/jsx-runtime';
4
+ import '../types/form-field.types.mjs';
5
+ import 'react-native';
6
+ import '@impulse-ui-native/primitives';
@@ -0,0 +1,5 @@
1
+ import { FormField } from "./form-field";
2
+ export {
3
+ FormField
4
+ };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/index.ts"],"sourcesContent":["export { FormField } from \"./form-field\";\n"],"mappings":"AAAA,SAAS,iBAAiB;","names":[]}
@@ -0,0 +1,6 @@
1
+ export { FormField } from './components/form-field.mjs';
2
+ export { FormFieldControlProps, FormFieldProps, FormFieldRenderProps } from './types/form-field.types.mjs';
3
+ import 'react';
4
+ import 'react/jsx-runtime';
5
+ import 'react-native';
6
+ import '@impulse-ui-native/primitives';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./components";
2
+ export * from "./types";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./components\";\nexport * from \"./types\";\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
@@ -0,0 +1,27 @@
1
+ import { ReactNode } from 'react';
2
+ import { AccessibilityState } from 'react-native';
3
+ import { ViewProps } from '@impulse-ui-native/primitives';
4
+
5
+ interface FormFieldControlProps {
6
+ accessibilityHint?: string;
7
+ accessibilityLabel: string;
8
+ accessibilityLabelledBy: string;
9
+ accessibilityState: AccessibilityState;
10
+ disabled: boolean;
11
+ nativeID: string;
12
+ }
13
+ interface FormFieldRenderProps {
14
+ controlProps: FormFieldControlProps;
15
+ invalid: boolean;
16
+ required: boolean;
17
+ }
18
+ interface FormFieldProps extends Omit<ViewProps, "children"> {
19
+ children: (props: FormFieldRenderProps) => ReactNode;
20
+ description?: string;
21
+ disabled?: boolean;
22
+ error?: string;
23
+ label: string;
24
+ required?: boolean;
25
+ }
26
+
27
+ export type { FormFieldControlProps, FormFieldProps, FormFieldRenderProps };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=form-field.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,4 @@
1
+ export { FormFieldControlProps, FormFieldProps, FormFieldRenderProps } from './form-field.types.mjs';
2
+ import 'react';
3
+ import 'react-native';
4
+ import '@impulse-ui-native/primitives';
@@ -0,0 +1,2 @@
1
+ export * from "./form-field.types";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["export * from \"./form-field.types\";\n"],"mappings":"AAAA,cAAc;","names":[]}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@impulse-ui-native/form-field",
3
+ "version": "2.7.0",
4
+ "description": "Accessible form-field composition for Impulse UI Native controls.",
5
+ "keywords": [
6
+ "react-native",
7
+ "form-field",
8
+ "accessibility",
9
+ "validation",
10
+ "components",
11
+ "impulse-ui-native"
12
+ ],
13
+ "license": "MIT",
14
+ "source": "src/index.ts",
15
+ "module": "dist/index.js",
16
+ "types": "dist/index.d.mts",
17
+ "react-native": "src/index.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.mts",
21
+ "react-native": "./src/index.ts",
22
+ "import": "./dist/index.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "README.md",
28
+ "LICENSE"
29
+ ],
30
+ "sideEffects": false,
31
+ "dependencies": {
32
+ "@impulse-ui-native/theme": "2.7.0",
33
+ "@impulse-ui-native/primitives": "2.7.0"
34
+ },
35
+ "devDependencies": {
36
+ "@types/react": "~19.2.14",
37
+ "prettier": "^3.6.2",
38
+ "react": "19.2.3",
39
+ "react-native": "0.86.2",
40
+ "typescript": "~6.0.3",
41
+ "@impulse-ui-native/prettier-config": "1.0.0",
42
+ "@impulse-ui-native/tsconfig": "1.0.0"
43
+ },
44
+ "peerDependencies": {
45
+ "react": ">=18",
46
+ "react-native": ">=0.73"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "prettier": "@impulse-ui-native/prettier-config",
52
+ "scripts": {
53
+ "build": "tsup --config tsup.config.ts",
54
+ "typecheck": "tsc -p tsconfig.json --noEmit",
55
+ "format": "prettier --write \"./**/*.{ts,tsx,js,jsx,json,md}\" --ignore-path ../../.prettierignore"
56
+ }
57
+ }