Skip to content

Commit 05dc85c

Browse files
[UIK-4738][bulk-textarea,website] udpate types for BulkTextarea.InputField (#2776)
## Changelog ### @semcore/bulk-textarea #### Fixed - Fixed types for `Bulktextarea.InputField`. <!--- Provide a general summary of your changes in the Title above --> ## Motivation and Context There was a disrepancy between types displayed in documentation and component's props. Now it's unified :) ## How has this been tested? Manually ## Screenshots (if appropriate): ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue). - [ ] New feature (non-breaking change which adds functionality). - [x] Breaking change (fix or feature that would cause existing functionality to not work as expected). - [x] Nice improve. ## Checklist: <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] I have updated the documentation accordingly. - [ ] I have added new tests on added of fixed functionality. Co-authored-by: ilyabrower <ilia.brauer@semrush.com>
1 parent 745c5bd commit 05dc85c

File tree

3 files changed

+116
-160
lines changed

3 files changed

+116
-160
lines changed

semcore/bulk-textarea/src/BulkTextarea.types.ts

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Intergalactic } from '@semcore/core';
55
import type { CounterProps } from './components/Counter';
66
import type { ErrorsNavigationProps } from './components/ErrorsNavigation';
77
import type { InputFieldProps } from './components/InputField/InputField';
8+
import type { PasteProps } from './components/InputField/InputField.types';
89

910
export type BulkTextareaProps<T extends string | string[]> = {
1011
/** The current value */
@@ -40,7 +41,7 @@ export type BulkTextareaProps<T extends string | string[]> = {
4041
/** List of errors */
4142
errors?: InputFieldProps<T>['errors'];
4243
/** Defines whether to show errors or not */
43-
showErrors?: boolean;
44+
showErrors?: InputFieldProps<T>['showErrors'];
4445
/** Internal */
4546
onErrorsChange?: InputFieldProps<T>['onErrorsChange'];
4647
/** Internal */
@@ -58,10 +59,91 @@ type BulkTextareaComponent = (<T extends string | string[]>(
5859
) => Intergalactic.InternalTypings.ComponentRenderingResults) &
5960
Intergalactic.InternalTypings.ComponentAdditive<'div', 'div', {}>;
6061

62+
export type BulkTextareaInputFieldProps<T extends string | string[] = string | string[]> = BoxProps & {
63+
/**
64+
* Unique id
65+
*/
66+
id?: string;
67+
/**
68+
* Placeholder for field
69+
*/
70+
placeholder?: string;
71+
/**
72+
* String to render in textarea. OnChanging value, it will go throw paste pipeline
73+
*/
74+
value?: T;
75+
/**
76+
* This component doesn't have default onChange callback, because we think that you need only the result after every changes/fixes
77+
*/
78+
onBlur?: (value: T, e: Event) => void;
79+
/**
80+
* Size of component
81+
* @default m
82+
*/
83+
size?: 'm' | 'l';
84+
/**
85+
* State for show errors or valid(green) borders
86+
* @default normal
87+
*/
88+
state?: 'normal' | 'valid' | 'invalid';
89+
/**
90+
* Flag for disabling field
91+
* @default false
92+
*/
93+
disabled?: boolean;
94+
/**
95+
* Flag for readonly field
96+
* @default false
97+
*/
98+
readonly?: boolean;
99+
/**
100+
* Min rows
101+
* @default 2
102+
*/
103+
minRows?: number;
104+
/**
105+
* Max rows
106+
* @default 10
107+
*/
108+
maxRows?: number;
109+
/**
110+
* List of available points to validate value
111+
* @default blur
112+
*/
113+
validateOn?: ('blur' | 'blurLine' | 'paste')[];
114+
/**
115+
* Function to validate line
116+
*/
117+
lineValidation?: (line: string, lines: string[]) => { isValid: boolean; errorMessage: string };
118+
/**
119+
* Message for display error about whole field, not only one line.
120+
* If set empty string, field will not have invalid state.
121+
*/
122+
commonErrorMessage: string;
123+
/**
124+
* Delimiters (event.key) for lines
125+
* @default Enter
126+
*/
127+
linesDelimiters?: string[];
128+
/**
129+
* Count of max lines in badge
130+
* @default 100
131+
*/
132+
maxLines?: number;
133+
/**
134+
* Paste props
135+
*/
136+
pasteProps?: PasteProps;
137+
/**
138+
* Function for process line after it was blurred
139+
*/
140+
lineProcessing?: (line: string, lines: string[]) => string;
141+
};
142+
61143
export type BulkTextareaType<T extends string | string[]> = BulkTextareaComponent & {
62144
InputField: Intergalactic.Component<
63145
'div',
64-
Pick<InputFieldProps<T>, 'commonErrorMessage' | 'id'> & Partial<BulkTextareaProps<T>> & BoxProps
146+
BulkTextareaInputFieldProps<T>
65147
>;
66148
Counter: Intergalactic.Component<'div', Partial<CounterProps>>;
67149
ClearAll: typeof Button;
Lines changed: 31 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
type PasteProps = {
1+
import type { BulkTextareaInputFieldProps } from '../../BulkTextarea.types';
2+
3+
export type PasteProps = {
24
/**
35
* @default '\n'
46
*/
@@ -19,162 +21,34 @@ export type ErrorItem = {
1921
errorMessage: string;
2022
};
2123

22-
export type InputFieldProps<T extends string | string[]> = {
23-
/**
24-
* Unique id
25-
*/
26-
id?: string;
27-
28-
/**
29-
* Placeholder for field
30-
*/
31-
placeholder?: string;
32-
/**
33-
* String to render in textarea. OnChanging value, it will go throw paste pipeline
34-
*/
35-
value: T;
36-
/**
37-
* This component doesn't have default onChange callback, because we think that you need only the result after every changes/fixes
38-
*/
39-
onBlur: (value: T, e: Event) => void;
40-
41-
/**
42-
* Size of component
43-
* @default m
44-
*/
45-
size: 'm' | 'l';
46-
/**
47-
* State for show errors or valid(green) borders
48-
* @default normal
49-
*/
50-
state: 'normal' | 'valid' | 'invalid';
51-
52-
/**
53-
* Flag for disabling field
54-
* @default false
55-
*/
56-
disabled?: boolean;
57-
58-
/**
59-
* Flag for readonly field
60-
* @default false
61-
*/
62-
readonly?: boolean;
63-
64-
/**
65-
* Min rows
66-
* @default 2
67-
*/
68-
minRows: number;
69-
/**
70-
* Max rows
71-
* @default 10
72-
*/
73-
maxRows: number;
74-
75-
/**
76-
* List of available points to validate value
77-
* @default blur
78-
*/
79-
validateOn: ('blur' | 'blurLine' | 'paste')[];
80-
81-
/**
82-
* Function to validate line
83-
*/
84-
lineValidation?: (line: string, lines: string[]) => { isValid: boolean; errorMessage: string };
85-
86-
/**
87-
* Message for display error about whole field, not only one line.
88-
* If set empty string, field will not have invalid state.
89-
*/
90-
commonErrorMessage: string;
91-
92-
/**
93-
* Delimiters (event.key) for lines
94-
* @default Enter
95-
*/
96-
linesDelimiters?: string[];
97-
98-
/**
99-
* Count of max lines in badge
100-
* @default 100
101-
*/
102-
maxLines: number;
103-
104-
/**
105-
* Paste props
106-
*/
107-
pasteProps: PasteProps;
108-
109-
/**
110-
* Function for process line after it was blurred
111-
*/
112-
lineProcessing?: (line: string, lines: string[]) => string;
113-
114-
/**
115-
* Internal
116-
*/
117-
prevError: ErrorItem;
118-
119-
/**
120-
* Internal
121-
*/
122-
currentLineIndex: number;
123-
124-
/**
125-
* Internal
126-
*/
127-
linesCount: number;
128-
/**
129-
* Internal
130-
*/
131-
onChangeLineIndex: (newIndex: number) => void;
132-
/**
133-
* Internal
134-
*/
135-
onChangeLinesCount: (rowsCount: number) => void;
136-
137-
/**
138-
* Internal
139-
*/
140-
showErrors: boolean;
141-
/**
142-
* Internal
143-
* List of errors in rows
144-
*/
145-
errors: ErrorItem[];
146-
/**
147-
* Internal
148-
* Select row with error
149-
*/
150-
errorIndex: number;
151-
/**
152-
* Internal
153-
* Flag for select all row
154-
*/
155-
highlightErrorIndex: boolean;
156-
/**
157-
* Internal
158-
*/
159-
onErrorsChange: (errors: ErrorItem[]) => void;
160-
/**
161-
* Internal
162-
*/
163-
onShowErrorsChange: (showErrors: boolean) => void;
164-
/**
165-
* Internal
166-
*/
167-
onErrorIndexChange: (errorIndex: number) => void;
168-
169-
/**
24+
export type InputFieldProps<T extends string | string[]> =
25+
BulkTextareaInputFieldProps<T>
26+
& Required<
27+
Pick<
28+
BulkTextareaInputFieldProps<T>,
29+
'value' | 'onBlur' | 'size' | 'state' | 'minRows' | 'maxRows' | 'validateOn' | 'maxLines' | 'pasteProps'
30+
>
31+
>
32+
& {
33+
prevError: ErrorItem;
34+
currentLineIndex: number;
35+
linesCount: number;
36+
onChangeLineIndex: (newIndex: number) => void;
37+
onChangeLinesCount: (rowsCount: number) => void;
38+
showErrors: boolean;
39+
/** List of errors in rows */
40+
errors: ErrorItem[];
41+
/** Select row with error */
42+
errorIndex: number;
43+
/** Flag for select all row */
44+
highlightErrorIndex: boolean;
45+
onErrorsChange: (errors: ErrorItem[]) => void;
46+
onShowErrorsChange: (showErrors: boolean) => void;
47+
onErrorIndexChange: (errorIndex: number) => void;
48+
/**
17049
* Return lines from textarea immediately they changed (uses mutation observer on textarea node under the hood)
17150
* Throttling may be required during processing this cb
172-
* Internal
17351
*/
174-
onImmediatelyChange?: (lines: string[], value: string) => void;
175-
} & {
176-
/**
177-
* Internal
178-
*/
179-
'aria-describedby'?: string;
180-
};
52+
onImmediatelyChange?: (lines: string[], value: string) => void;
53+
}
54+
& { 'aria-describedby'?: string };

website/docs/components/bulk-textarea/bulk-textarea-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import BulkTextarea from '@semcore/ui/bulk-textarea';
1919
<BulkTextarea.InputField />
2020
```
2121

22-
<TypesView type="InputFieldProps" :types={...types} />
22+
<TypesView type="BulkTextareaInputFieldProps" :types={...types} />
2323

2424
## BulkTextarea.ErrorsNavigation
2525

0 commit comments

Comments
 (0)