@k8slens/lds-form 0.52.0 → 0.52.2
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/README.md
CHANGED
|
@@ -1,29 +1,88 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @k8slens/lds-form
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Form components for the Lens Design System – structured form fields with built-in validation.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @k8slens/lds-form @k8slens/lds @k8slens/lds-tokens
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import "@k8slens/lds-tokens/lib/electron/font-face.css";
|
|
15
|
+
import "@k8slens/lds/lib/es/index.css";
|
|
16
|
+
import "@k8slens/lds/lib/es/typography.css";
|
|
17
|
+
import "@k8slens/lds-form/lib/es/index.css";
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### FormInput (with built-in validation)
|
|
5
23
|
|
|
6
|
-
|
|
24
|
+
`FormInput` is a complete form field that includes label, input, and error message handling:
|
|
7
25
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
26
|
+
```tsx
|
|
27
|
+
import { FormInput } from "@k8slens/lds-form";
|
|
28
|
+
|
|
29
|
+
export const MyForm = () => {
|
|
30
|
+
const [email, setEmail] = useState("");
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<FormInput
|
|
34
|
+
name="email"
|
|
35
|
+
type="email"
|
|
36
|
+
label="Email Address"
|
|
37
|
+
value={email}
|
|
38
|
+
onChange={setEmail}
|
|
39
|
+
required
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
```
|
|
11
44
|
|
|
12
|
-
###
|
|
13
|
-
- `./lib/cjs/index.js` - Main CommonJS module
|
|
14
|
-
- `./lib/cjs/ComponentName/ComponentName.js` - Individual CommonJS modules
|
|
45
|
+
### Building Custom Fields
|
|
15
46
|
|
|
16
|
-
|
|
17
|
-
- run `npm i -s @k8slens/lds @k8slens/lds-tokens`
|
|
18
|
-
- import `@k8slens/lds-tokens/lib/web/font-imports.css` in your React app to include fonts
|
|
19
|
-
- import `@k8slens/lds/index.css` in your React app to include core styles
|
|
20
|
-
- import `@k8slens/lds-form/index.css` in your React app to include form styles
|
|
21
|
-
- Use in a component:
|
|
47
|
+
For custom layouts, compose with individual components:
|
|
22
48
|
|
|
23
|
-
```
|
|
24
|
-
import {
|
|
49
|
+
```tsx
|
|
50
|
+
import { FormField, FormLabel, FormInput, FormErrorMessage } from "@k8slens/lds-form";
|
|
25
51
|
|
|
26
|
-
export const
|
|
27
|
-
<
|
|
52
|
+
export const CustomField = () => (
|
|
53
|
+
<FormField>
|
|
54
|
+
<FormLabel>Username</FormLabel>
|
|
55
|
+
<FormInput name="username" type="text" />
|
|
56
|
+
<FormErrorMessage>Username is required</FormErrorMessage>
|
|
57
|
+
</FormField>
|
|
28
58
|
);
|
|
29
59
|
```
|
|
60
|
+
|
|
61
|
+
### FormSwitchGroup
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import { FormSwitchGroup } from "@k8slens/lds-form";
|
|
65
|
+
|
|
66
|
+
<FormSwitchGroup
|
|
67
|
+
options={[
|
|
68
|
+
{ id: "email", label: "Email notifications" },
|
|
69
|
+
{ id: "sms", label: "SMS notifications" },
|
|
70
|
+
]}
|
|
71
|
+
value={selected}
|
|
72
|
+
onChange={setSelected}
|
|
73
|
+
/>;
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Documentation
|
|
77
|
+
|
|
78
|
+
Browse components at [lens-design-system.k8slens.dev](https://lens-design-system.k8slens.dev/?path=/docs/form).
|
|
79
|
+
|
|
80
|
+
## AI Assistance
|
|
81
|
+
|
|
82
|
+
This package includes an `llms.txt` file with API documentation optimized for LLMs. Add to your project's AI configuration (e.g., `CLAUDE.md`):
|
|
83
|
+
|
|
84
|
+
```markdown
|
|
85
|
+
Read node_modules/@k8slens/lds-form/llms.txt for form components reference.
|
|
86
|
+
|
|
87
|
+
Always use LDS form components and tokens. Search llms.txt before creating custom form fields.
|
|
88
|
+
```
|
|
@@ -20,9 +20,13 @@ export interface NumberFormInputProps<CustomError extends string> extends FormFi
|
|
|
20
20
|
}
|
|
21
21
|
export declare type FormInputProps<CustomError extends string> = NumberFormInputProps<CustomError> | TextFormInputProps<CustomError>;
|
|
22
22
|
/**
|
|
23
|
-
* Input
|
|
23
|
+
* Input with label, validation, and error handling. Wraps core Input in FormField.
|
|
24
24
|
*
|
|
25
|
-
*
|
|
25
|
+
* Usage: `import { FormInput } from "@k8slens/lds-form"`
|
|
26
|
+
*
|
|
27
|
+
* ```tsx
|
|
28
|
+
* <FormInput name="email" type="email" label="Email" value={email} onChange={setEmail} />
|
|
29
|
+
* ```
|
|
26
30
|
*/
|
|
27
31
|
declare function FormInput<CustomError extends string>({ id: _id, label, wrapperProps, labelProps, validate, errorParser, errorProps: errorComponentProps, value, onChange, type, ...inputProps }: PropsWithChildren<NumberFormInputProps<CustomError> | TextFormInputProps<CustomError>>): React.JSX.Element;
|
|
28
32
|
export default FormInput;
|
|
@@ -16,9 +16,13 @@ export interface FormSwitchGroupProps<CustomError extends string> extends Omit<F
|
|
|
16
16
|
errors?: Array<string>;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Multiple toggle switches with shared label and error handling.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
21
|
+
* Usage: `import { FormSwitchGroup } from "@k8slens/lds-form"`
|
|
22
|
+
*
|
|
23
|
+
* ```tsx
|
|
24
|
+
* <FormSwitchGroup label="Notifications" values={options} onChange={setOptions} />
|
|
25
|
+
* ```
|
|
22
26
|
*/
|
|
23
27
|
declare function FormSwitchGroup<CustomError extends string>({ id: _id, label, wrapperProps, labelProps, validate, errorProps: errorComponentProps, values, onChange, type, errors, disabled: allDisabled, ...switchProps }: PropsWithChildren<FormSwitchGroupProps<CustomError>>): React.JSX.Element;
|
|
24
28
|
export default FormSwitchGroup;
|
|
@@ -20,9 +20,13 @@ export interface NumberFormInputProps<CustomError extends string> extends FormFi
|
|
|
20
20
|
}
|
|
21
21
|
export declare type FormInputProps<CustomError extends string> = NumberFormInputProps<CustomError> | TextFormInputProps<CustomError>;
|
|
22
22
|
/**
|
|
23
|
-
* Input
|
|
23
|
+
* Input with label, validation, and error handling. Wraps core Input in FormField.
|
|
24
24
|
*
|
|
25
|
-
*
|
|
25
|
+
* Usage: `import { FormInput } from "@k8slens/lds-form"`
|
|
26
|
+
*
|
|
27
|
+
* ```tsx
|
|
28
|
+
* <FormInput name="email" type="email" label="Email" value={email} onChange={setEmail} />
|
|
29
|
+
* ```
|
|
26
30
|
*/
|
|
27
31
|
declare function FormInput<CustomError extends string>({ id: _id, label, wrapperProps, labelProps, validate, errorParser, errorProps: errorComponentProps, value, onChange, type, ...inputProps }: PropsWithChildren<NumberFormInputProps<CustomError> | TextFormInputProps<CustomError>>): React.JSX.Element;
|
|
28
32
|
export default FormInput;
|
|
@@ -16,9 +16,13 @@ export interface FormSwitchGroupProps<CustomError extends string> extends Omit<F
|
|
|
16
16
|
errors?: Array<string>;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Multiple toggle switches with shared label and error handling.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
21
|
+
* Usage: `import { FormSwitchGroup } from "@k8slens/lds-form"`
|
|
22
|
+
*
|
|
23
|
+
* ```tsx
|
|
24
|
+
* <FormSwitchGroup label="Notifications" values={options} onChange={setOptions} />
|
|
25
|
+
* ```
|
|
22
26
|
*/
|
|
23
27
|
declare function FormSwitchGroup<CustomError extends string>({ id: _id, label, wrapperProps, labelProps, validate, errorProps: errorComponentProps, values, onChange, type, errors, disabled: allDisabled, ...switchProps }: PropsWithChildren<FormSwitchGroupProps<CustomError>>): React.JSX.Element;
|
|
24
28
|
export default FormSwitchGroup;
|
package/llms.txt
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# @k8slens/lds-form
|
|
2
|
+
|
|
3
|
+
> Form components for the Lens Design System - structured form fields with validation support.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @k8slens/lds-form @k8slens/lds @k8slens/lds-tokens
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Peer Dependencies
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install react react-dom clsx lodash
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Setup
|
|
18
|
+
|
|
19
|
+
Import required styles in your app entry point:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import "@k8slens/lds-tokens/lib/electron/font-face.css";
|
|
23
|
+
import "@k8slens/lds/lib/es/index.css";
|
|
24
|
+
import "@k8slens/lds/lib/es/typography.css";
|
|
25
|
+
import "@k8slens/lds-form/lib/es/index.css";
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Components
|
|
29
|
+
|
|
30
|
+
### FormField
|
|
31
|
+
|
|
32
|
+
Wrapper component that groups label, input, and error message.
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { FormField, FormLabel, FormInput, FormErrorMessage } from "@k8slens/lds-form";
|
|
36
|
+
|
|
37
|
+
<FormField>
|
|
38
|
+
<FormLabel>Email</FormLabel>
|
|
39
|
+
<FormInput type="email" />
|
|
40
|
+
<FormErrorMessage>Please enter a valid email</FormErrorMessage>
|
|
41
|
+
</FormField>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### FormInput
|
|
45
|
+
|
|
46
|
+
Input with label, validation, and error handling. Wraps core Input in FormField.
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import { FormInput } from "@k8slens/lds-form";
|
|
50
|
+
|
|
51
|
+
<FormInput name="email" type="email" label="Email" value={email} onChange={setEmail} />
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### FormLabel
|
|
55
|
+
|
|
56
|
+
Label component for form fields.
|
|
57
|
+
|
|
58
|
+
### FormErrorMessage
|
|
59
|
+
|
|
60
|
+
Displays validation error messages.
|
|
61
|
+
|
|
62
|
+
### FormSwitchGroup
|
|
63
|
+
|
|
64
|
+
Multiple toggle switches with shared label and error handling.
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
import { FormSwitchGroup } from "@k8slens/lds-form";
|
|
68
|
+
|
|
69
|
+
<FormSwitchGroup label="Notifications" values={options} onChange={setOptions} />
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Hooks
|
|
73
|
+
|
|
74
|
+
Available via `common` export:
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
import { common } from "@k8slens/lds-form";
|
|
78
|
+
|
|
79
|
+
const { useFieldIds, useInputErrorProps, useFormComponentData, usePrevious, defaultErrorParser } = common;
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
- `useFieldIds` - Generate consistent IDs for form fields
|
|
83
|
+
- `useInputErrorProps` - Handle error state props
|
|
84
|
+
- `useFormComponentData` - Form state management
|
|
85
|
+
- `usePrevious` - Track previous values
|
|
86
|
+
- `defaultErrorParser` - Parse validation errors
|
|
87
|
+
|
|
88
|
+
## Dependencies
|
|
89
|
+
|
|
90
|
+
This package depends on `@k8slens/lds` core components.
|
|
91
|
+
|
|
92
|
+
## Documentation
|
|
93
|
+
|
|
94
|
+
- [Lens Design System](https://lens-design-system.k8slens.dev/)
|
|
95
|
+
|
|
96
|
+
## Optional
|
|
97
|
+
|
|
98
|
+
- [npm Package](https://www.npmjs.com/package/@k8slens/lds-form)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@k8slens/lds-form",
|
|
3
|
-
"version": "0.52.
|
|
3
|
+
"version": "0.52.2",
|
|
4
4
|
"description": "Lens Design System – React Form components",
|
|
5
5
|
"author": "Mirantis Inc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"types": "./lib/es/index.d.ts",
|
|
16
16
|
"type": "module",
|
|
17
17
|
"files": [
|
|
18
|
-
"lib/"
|
|
18
|
+
"lib/",
|
|
19
|
+
"llms.txt"
|
|
19
20
|
],
|
|
20
21
|
"scripts": {
|
|
21
22
|
"start": "npm run rollup-watch",
|
|
@@ -24,14 +25,14 @@
|
|
|
24
25
|
"rollup": "rollup -c",
|
|
25
26
|
"clean": "rimraf lib",
|
|
26
27
|
"test": "jest",
|
|
27
|
-
"lint": "
|
|
28
|
-
"format": "
|
|
28
|
+
"lint": "oxlint .",
|
|
29
|
+
"format": "oxlint --fix . && prettier --write ."
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@k8slens/lds": "^0.57.
|
|
32
|
+
"@k8slens/lds": "^0.57.2"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@k8slens/lds-tokens": "^0.58.
|
|
35
|
+
"@k8slens/lds-tokens": "^0.58.2",
|
|
35
36
|
"@rollup/plugin-node-resolve": "15.0.2",
|
|
36
37
|
"@storybook/react": "6.5.16",
|
|
37
38
|
"@testing-library/react": "14.0.0",
|
|
@@ -55,5 +56,5 @@
|
|
|
55
56
|
"\\.svg": "<rootDir>/../../__mocks__/SVGStub.js"
|
|
56
57
|
}
|
|
57
58
|
},
|
|
58
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "1edf9b6761a700920be41adb01f3de528320f639"
|
|
59
60
|
}
|