@dt-dds/react-text-field 1.0.0-beta.100
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/CHANGELOG.md +1022 -0
- package/LICENSE.md +21 -0
- package/README.md +88 -0
- package/dist/index.d.mts +89 -0
- package/dist/index.d.ts +89 -0
- package/dist/index.js +515 -0
- package/dist/index.mjs +478 -0
- package/package.json +61 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Daimler Truck AG.
|
|
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,88 @@
|
|
|
1
|
+
# TextField Package
|
|
2
|
+
|
|
3
|
+
TextField allows users to enter and edit text. They typically appear in forms and modal windows.
|
|
4
|
+
|
|
5
|
+
## TextField Usage
|
|
6
|
+
|
|
7
|
+
```jsx
|
|
8
|
+
import { TextField } from '@dt-dds/react-text-field';
|
|
9
|
+
|
|
10
|
+
export const App = () => {
|
|
11
|
+
return <TextField label='My Field' message='Helpful hint' maxLength={40} />;
|
|
12
|
+
};
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Properties
|
|
16
|
+
|
|
17
|
+
| Property | Type | Default | Description |
|
|
18
|
+
| ----------------- | ---------------------------- | ---------- | ----------------------------------------------------------------------------------------------------- |
|
|
19
|
+
| `children` | `ReactNode` | - | Child components to be rendered inside input field. |
|
|
20
|
+
| `label` | `string` | - | A label to help users understand the scope of the text field. |
|
|
21
|
+
| `labelIcon` | `ReactNode` | - | Sets icon for label to provide guidance about the scope of the field. |
|
|
22
|
+
| `initialValue` | `string` | - | Sets the initial value of the text field. |
|
|
23
|
+
| `message` | `string` | - | The message to be displayed below the input field. Useful for hints or to display errors. |
|
|
24
|
+
| `hasError` | `boolean` | - | Set error state for text field. |
|
|
25
|
+
| `disabled` | `boolean` | - | Determines the disabled state of input field. |
|
|
26
|
+
| `name` | `string` | - | The attribute to specify the name of the text field. |
|
|
27
|
+
| `required` | `boolean` | - | Set error state with a message defined in `requiredMessage` |
|
|
28
|
+
| `requiredMessage` | `string` | - | The error message to show when the required validation is triggered |
|
|
29
|
+
| `style` | `CSSProperties` | - | Add css style directly to the text field. |
|
|
30
|
+
| `inputRef` | `RefObject` | - | Provides a way to access DOM node or React element reference. |
|
|
31
|
+
| `maxLength` | `number` | - | The maximum number of characters that user can enter. |
|
|
32
|
+
| `type` | `HTMLInputTypeAttribute` | `text` | Used to specify the type of element to display. |
|
|
33
|
+
| `onChange` | `function` | - | The triggered function when the input change. |
|
|
34
|
+
| `onResetInput` | `function` | - | The triggered function when clicked on the cross icon, when type is search |
|
|
35
|
+
| `variant` | `[outlined, bottomLine]` | `outlined` | Styles the input with outlined or with bottom line |
|
|
36
|
+
| `scale` | `[compact, standard]` | `standard` | Sets the spacing and size of the text field |
|
|
37
|
+
| `backgroundFill` | `[default, contrast, light]` | `default` | Styles the input with background color |
|
|
38
|
+
| `isFloatingLabel` | `boolean` | `false` | Sets the label floating or traditional on top of the input |
|
|
39
|
+
| `extraPrefix` | `ExtraComponent` | - | Component to be rendered on the left side inside the input field |
|
|
40
|
+
| `extraSuffix` | `ExtraComponent` | - | Component to be rendered on the right side inside the input field |
|
|
41
|
+
| `id` | `string` | - | The unique identifier used to link the element to the corresponding element via the htmlFor attribute |
|
|
42
|
+
| `dataTestId` | `string` | `label`-text-field | Customizable test identifier |
|
|
43
|
+
| `...` | `InputHTMLAttributes` | - | All available attributes from native html input |
|
|
44
|
+
|
|
45
|
+
## Stack
|
|
46
|
+
|
|
47
|
+
- [TypeScript](https://www.typescriptlang.org/) for static type checking
|
|
48
|
+
- [React](https://reactjs.org/) — JavaScript library for user interfaces
|
|
49
|
+
- [Emotion](https://emotion.sh/docs/introduction) — for writing css styles with JavaScript
|
|
50
|
+
- [Storybook](https://storybook.js.org/) — UI component environment powered by Vite
|
|
51
|
+
- [Jest](https://jestjs.io/) - JavaScript Testing Framework
|
|
52
|
+
- [React Testing Library](https://testing-library.com/) - to test UI components in a user-centric way
|
|
53
|
+
- [ESLint](https://eslint.org/) for code linting
|
|
54
|
+
- [Prettier](https://prettier.io) for code formatting
|
|
55
|
+
- [Tsup](https://github.com/egoist/tsup) — TypeScript bundler powered by esbuild
|
|
56
|
+
- [Yarn](https://yarnpkg.com/) from managing packages
|
|
57
|
+
|
|
58
|
+
## Commands
|
|
59
|
+
|
|
60
|
+
- `yarn build` - Build the package
|
|
61
|
+
- `yarn dev` - Run the package locally
|
|
62
|
+
- `yarn lint` - Lint all files within this package
|
|
63
|
+
- `yarn test` - Run all unit tests
|
|
64
|
+
- `yarn test:report` - Open the test coverage report
|
|
65
|
+
- `yarn test:update:snapshot` - Run all unit tests and update the snapshot
|
|
66
|
+
|
|
67
|
+
## Compilation
|
|
68
|
+
|
|
69
|
+
Running `yarn build` from the root of the package will use [tsup](https://tsup.egoist.dev/) to compile the raw TypeScript and React code to plain JavaScript.
|
|
70
|
+
|
|
71
|
+
The `/dist` folder contains the compiled output.
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
text-field
|
|
75
|
+
└── dist
|
|
76
|
+
├── index.d.ts <-- Types
|
|
77
|
+
├── index.js <-- CommonJS version
|
|
78
|
+
└── index.mjs <-- ES Modules version
|
|
79
|
+
...
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Versioning
|
|
83
|
+
|
|
84
|
+
Follows [semantic versioning](https://semver.org/)
|
|
85
|
+
|
|
86
|
+
## © License
|
|
87
|
+
|
|
88
|
+
Licensed under [MIT License](LICENSE.md)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { CustomTheme } from '@dt-dds/themes';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ReactNode, ComponentPropsWithoutRef, RefObject } from 'react';
|
|
4
|
+
import { BaseProps, Scale } from '@dt-dds/react-core';
|
|
5
|
+
import * as _emotion_styled from '@emotion/styled';
|
|
6
|
+
import * as _emotion_react from '@emotion/react';
|
|
7
|
+
|
|
8
|
+
type TextFieldVariant = 'outlined' | 'bottom-line';
|
|
9
|
+
type TextFieldBackgroundFill = 'default' | 'contrast' | 'light';
|
|
10
|
+
|
|
11
|
+
interface ExtraComponent {
|
|
12
|
+
onClick?: (text: string) => void;
|
|
13
|
+
component: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
interface TextFieldProps extends ComponentPropsWithoutRef<'input'>, BaseProps {
|
|
16
|
+
label: string;
|
|
17
|
+
labelIcon?: ReactNode;
|
|
18
|
+
isFloatingLabel?: boolean;
|
|
19
|
+
extraPrefix?: ExtraComponent;
|
|
20
|
+
extraSuffix?: ExtraComponent;
|
|
21
|
+
hasError?: boolean;
|
|
22
|
+
requiredMessage?: string;
|
|
23
|
+
initialValue?: string;
|
|
24
|
+
inputRef?: RefObject<HTMLInputElement>;
|
|
25
|
+
message?: string;
|
|
26
|
+
variant?: TextFieldVariant;
|
|
27
|
+
scale?: Scale;
|
|
28
|
+
backgroundFill?: TextFieldBackgroundFill;
|
|
29
|
+
onResetInput?: () => void;
|
|
30
|
+
isInputFocused?: boolean;
|
|
31
|
+
}
|
|
32
|
+
declare const TextField: react.ForwardRefExoticComponent<TextFieldProps & react.RefAttributes<HTMLDivElement>>;
|
|
33
|
+
|
|
34
|
+
interface TextFieldStyledProps {
|
|
35
|
+
isFloatingLabel?: boolean;
|
|
36
|
+
hasPrefix?: boolean;
|
|
37
|
+
}
|
|
38
|
+
interface InputFieldStyledProps {
|
|
39
|
+
isFloatingLabel: boolean;
|
|
40
|
+
scale: Scale;
|
|
41
|
+
isFocused: boolean;
|
|
42
|
+
}
|
|
43
|
+
interface InputWrapperStyledProps {
|
|
44
|
+
isFloatingLabel: boolean;
|
|
45
|
+
variant: TextFieldVariant;
|
|
46
|
+
backgroundFill: TextFieldBackgroundFill;
|
|
47
|
+
hasError: boolean;
|
|
48
|
+
}
|
|
49
|
+
declare const TextFieldStyled: _emotion_styled.StyledComponent<{
|
|
50
|
+
theme?: _emotion_react.Theme;
|
|
51
|
+
as?: React.ElementType;
|
|
52
|
+
} & TextFieldStyledProps, react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
53
|
+
declare const InputContainerStyled: _emotion_styled.StyledComponent<{
|
|
54
|
+
theme?: _emotion_react.Theme;
|
|
55
|
+
as?: React.ElementType;
|
|
56
|
+
} & {
|
|
57
|
+
isFloatingLabel: boolean;
|
|
58
|
+
}, react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
59
|
+
declare const InputFieldStyled: _emotion_styled.StyledComponent<{
|
|
60
|
+
theme?: _emotion_react.Theme;
|
|
61
|
+
as?: React.ElementType;
|
|
62
|
+
} & InputFieldStyledProps, react.DetailedHTMLProps<react.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, {}>;
|
|
63
|
+
declare const InputExtraPrefixStyled: _emotion_styled.StyledComponent<{
|
|
64
|
+
theme?: _emotion_react.Theme;
|
|
65
|
+
as?: React.ElementType;
|
|
66
|
+
} & {
|
|
67
|
+
isClickable?: boolean;
|
|
68
|
+
}, react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
69
|
+
declare const InputExtraSuffixStyled: _emotion_styled.StyledComponent<{
|
|
70
|
+
theme?: _emotion_react.Theme;
|
|
71
|
+
as?: React.ElementType;
|
|
72
|
+
} & {
|
|
73
|
+
isClickable?: boolean;
|
|
74
|
+
}, react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
75
|
+
declare const TextFieldMessageStyled: _emotion_styled.StyledComponent<{
|
|
76
|
+
theme?: _emotion_react.Theme;
|
|
77
|
+
as?: React.ElementType;
|
|
78
|
+
}, react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
79
|
+
declare const InputWrapperStyled: _emotion_styled.StyledComponent<{
|
|
80
|
+
theme?: _emotion_react.Theme;
|
|
81
|
+
as?: React.ElementType;
|
|
82
|
+
} & InputWrapperStyledProps, react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
83
|
+
|
|
84
|
+
declare module '@emotion/react' {
|
|
85
|
+
interface Theme extends CustomTheme {
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { type ExtraComponent, InputContainerStyled, InputExtraPrefixStyled, InputExtraSuffixStyled, InputFieldStyled, type InputFieldStyledProps, InputWrapperStyled, type InputWrapperStyledProps, TextField, TextFieldMessageStyled, type TextFieldProps, TextFieldStyled, type TextFieldStyledProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { CustomTheme } from '@dt-dds/themes';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ReactNode, ComponentPropsWithoutRef, RefObject } from 'react';
|
|
4
|
+
import { BaseProps, Scale } from '@dt-dds/react-core';
|
|
5
|
+
import * as _emotion_styled from '@emotion/styled';
|
|
6
|
+
import * as _emotion_react from '@emotion/react';
|
|
7
|
+
|
|
8
|
+
type TextFieldVariant = 'outlined' | 'bottom-line';
|
|
9
|
+
type TextFieldBackgroundFill = 'default' | 'contrast' | 'light';
|
|
10
|
+
|
|
11
|
+
interface ExtraComponent {
|
|
12
|
+
onClick?: (text: string) => void;
|
|
13
|
+
component: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
interface TextFieldProps extends ComponentPropsWithoutRef<'input'>, BaseProps {
|
|
16
|
+
label: string;
|
|
17
|
+
labelIcon?: ReactNode;
|
|
18
|
+
isFloatingLabel?: boolean;
|
|
19
|
+
extraPrefix?: ExtraComponent;
|
|
20
|
+
extraSuffix?: ExtraComponent;
|
|
21
|
+
hasError?: boolean;
|
|
22
|
+
requiredMessage?: string;
|
|
23
|
+
initialValue?: string;
|
|
24
|
+
inputRef?: RefObject<HTMLInputElement>;
|
|
25
|
+
message?: string;
|
|
26
|
+
variant?: TextFieldVariant;
|
|
27
|
+
scale?: Scale;
|
|
28
|
+
backgroundFill?: TextFieldBackgroundFill;
|
|
29
|
+
onResetInput?: () => void;
|
|
30
|
+
isInputFocused?: boolean;
|
|
31
|
+
}
|
|
32
|
+
declare const TextField: react.ForwardRefExoticComponent<TextFieldProps & react.RefAttributes<HTMLDivElement>>;
|
|
33
|
+
|
|
34
|
+
interface TextFieldStyledProps {
|
|
35
|
+
isFloatingLabel?: boolean;
|
|
36
|
+
hasPrefix?: boolean;
|
|
37
|
+
}
|
|
38
|
+
interface InputFieldStyledProps {
|
|
39
|
+
isFloatingLabel: boolean;
|
|
40
|
+
scale: Scale;
|
|
41
|
+
isFocused: boolean;
|
|
42
|
+
}
|
|
43
|
+
interface InputWrapperStyledProps {
|
|
44
|
+
isFloatingLabel: boolean;
|
|
45
|
+
variant: TextFieldVariant;
|
|
46
|
+
backgroundFill: TextFieldBackgroundFill;
|
|
47
|
+
hasError: boolean;
|
|
48
|
+
}
|
|
49
|
+
declare const TextFieldStyled: _emotion_styled.StyledComponent<{
|
|
50
|
+
theme?: _emotion_react.Theme;
|
|
51
|
+
as?: React.ElementType;
|
|
52
|
+
} & TextFieldStyledProps, react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
53
|
+
declare const InputContainerStyled: _emotion_styled.StyledComponent<{
|
|
54
|
+
theme?: _emotion_react.Theme;
|
|
55
|
+
as?: React.ElementType;
|
|
56
|
+
} & {
|
|
57
|
+
isFloatingLabel: boolean;
|
|
58
|
+
}, react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
59
|
+
declare const InputFieldStyled: _emotion_styled.StyledComponent<{
|
|
60
|
+
theme?: _emotion_react.Theme;
|
|
61
|
+
as?: React.ElementType;
|
|
62
|
+
} & InputFieldStyledProps, react.DetailedHTMLProps<react.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, {}>;
|
|
63
|
+
declare const InputExtraPrefixStyled: _emotion_styled.StyledComponent<{
|
|
64
|
+
theme?: _emotion_react.Theme;
|
|
65
|
+
as?: React.ElementType;
|
|
66
|
+
} & {
|
|
67
|
+
isClickable?: boolean;
|
|
68
|
+
}, react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
69
|
+
declare const InputExtraSuffixStyled: _emotion_styled.StyledComponent<{
|
|
70
|
+
theme?: _emotion_react.Theme;
|
|
71
|
+
as?: React.ElementType;
|
|
72
|
+
} & {
|
|
73
|
+
isClickable?: boolean;
|
|
74
|
+
}, react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
75
|
+
declare const TextFieldMessageStyled: _emotion_styled.StyledComponent<{
|
|
76
|
+
theme?: _emotion_react.Theme;
|
|
77
|
+
as?: React.ElementType;
|
|
78
|
+
}, react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
79
|
+
declare const InputWrapperStyled: _emotion_styled.StyledComponent<{
|
|
80
|
+
theme?: _emotion_react.Theme;
|
|
81
|
+
as?: React.ElementType;
|
|
82
|
+
} & InputWrapperStyledProps, react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
83
|
+
|
|
84
|
+
declare module '@emotion/react' {
|
|
85
|
+
interface Theme extends CustomTheme {
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { type ExtraComponent, InputContainerStyled, InputExtraPrefixStyled, InputExtraSuffixStyled, InputFieldStyled, type InputFieldStyledProps, InputWrapperStyled, type InputWrapperStyledProps, TextField, TextFieldMessageStyled, type TextFieldProps, TextFieldStyled, type TextFieldStyledProps };
|