superdesk-ui-framework 3.0.1-beta.3 → 3.0.1-beta.6

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.
Files changed (100) hide show
  1. package/app/styles/_sd-tag-input.scss +201 -296
  2. package/app/styles/components/_list-item.scss +13 -1
  3. package/app/styles/components/_sd-photo-preview.scss +1 -1
  4. package/app/styles/design-tokens/_new-colors.scss +1 -1
  5. package/app/styles/form-elements/_forms-general.scss +22 -7
  6. package/app/styles/form-elements/_inputs.scss +133 -54
  7. package/app-typescript/components/Badge.tsx +3 -2
  8. package/app-typescript/components/DatePicker.tsx +40 -52
  9. package/app-typescript/components/DurationInput.tsx +342 -0
  10. package/app-typescript/components/Form/InputBase.tsx +85 -0
  11. package/app-typescript/components/Form/InputNew.tsx +107 -0
  12. package/app-typescript/components/Form/InputWrapper.tsx +79 -0
  13. package/app-typescript/components/Form/index.tsx +3 -0
  14. package/app-typescript/components/Input.tsx +28 -45
  15. package/app-typescript/components/Label.tsx +49 -10
  16. package/app-typescript/components/Layouts/Layout.tsx +1 -1
  17. package/app-typescript/components/Lists/ContentList.tsx +4 -4
  18. package/app-typescript/components/MultiSelect.tsx +37 -50
  19. package/app-typescript/components/Navigation/BottomNav.tsx +3 -2
  20. package/app-typescript/components/Select.tsx +23 -41
  21. package/app-typescript/components/SelectWithTemplate.tsx +32 -7
  22. package/app-typescript/components/TimePicker.tsx +48 -16
  23. package/app-typescript/components/TreeSelect.tsx +423 -195
  24. package/app-typescript/index.ts +4 -1
  25. package/dist/examples.bundle.js +16733 -15633
  26. package/dist/playgrounds/react-playgrounds/CoreLayout.tsx +64 -54
  27. package/dist/playgrounds/react-playgrounds/RundownEditor.tsx +24 -16
  28. package/dist/playgrounds/react-playgrounds/TestGround.tsx +76 -1
  29. package/dist/playgrounds/react-playgrounds/components/Layout.tsx +1 -1
  30. package/dist/react/Badges.tsx +18 -0
  31. package/dist/react/ContentList.tsx +15 -9
  32. package/dist/react/DatePicker.tsx +21 -1
  33. package/dist/react/DurationInput.tsx +104 -0
  34. package/dist/react/Index.tsx +5 -0
  35. package/dist/react/Inputs.tsx +153 -2
  36. package/dist/react/Labels.tsx +51 -1
  37. package/dist/react/MultiSelect.tsx +4 -1
  38. package/dist/react/SelectWithTemplate.tsx +6 -1
  39. package/dist/react/TableList.tsx +22 -44
  40. package/dist/react/TimePicker.tsx +16 -8
  41. package/dist/react/TreeSelect.tsx +301 -48
  42. package/dist/react/tree-select/TreeSelect.tsx +273 -0
  43. package/dist/react/tree-select/example-1.tsx +71 -0
  44. package/dist/react/tree-select/example-2.tsx +59 -0
  45. package/dist/superdesk-ui.bundle.css +413 -370
  46. package/dist/superdesk-ui.bundle.js +15879 -14782
  47. package/dist/vendor.bundle.js +27 -27
  48. package/examples/pages/playgrounds/react-playgrounds/CoreLayout.tsx +64 -54
  49. package/examples/pages/playgrounds/react-playgrounds/RundownEditor.tsx +24 -16
  50. package/examples/pages/playgrounds/react-playgrounds/TestGround.tsx +76 -1
  51. package/examples/pages/playgrounds/react-playgrounds/components/Layout.tsx +1 -1
  52. package/examples/pages/react/Badges.tsx +18 -0
  53. package/examples/pages/react/ContentList.tsx +15 -9
  54. package/examples/pages/react/DatePicker.tsx +21 -1
  55. package/examples/pages/react/DurationInput.tsx +104 -0
  56. package/examples/pages/react/Index.tsx +5 -0
  57. package/examples/pages/react/Inputs.tsx +153 -2
  58. package/examples/pages/react/Labels.tsx +51 -1
  59. package/examples/pages/react/MultiSelect.tsx +4 -1
  60. package/examples/pages/react/SelectWithTemplate.tsx +6 -1
  61. package/examples/pages/react/TableList.tsx +22 -44
  62. package/examples/pages/react/TimePicker.tsx +16 -8
  63. package/examples/pages/react/TreeSelect.tsx +301 -48
  64. package/examples/pages/react/tree-select/TreeSelect.tsx +273 -0
  65. package/examples/pages/react/tree-select/example-1.tsx +71 -0
  66. package/examples/pages/react/tree-select/example-2.tsx +59 -0
  67. package/package.json +2 -1
  68. package/patches/@superdesk+primereact+5.0.2-4.patch +10 -1
  69. package/react/components/Badge.d.ts +1 -0
  70. package/react/components/Badge.js +2 -2
  71. package/react/components/DatePicker.d.ts +1 -0
  72. package/react/components/DatePicker.js +6 -22
  73. package/react/components/DurationInput.d.ts +41 -0
  74. package/react/components/DurationInput.js +303 -0
  75. package/react/components/Form/InputBase.d.ts +42 -0
  76. package/react/components/Form/InputBase.js +72 -0
  77. package/react/components/Form/InputNew.d.ts +45 -0
  78. package/react/components/Form/InputNew.js +75 -0
  79. package/react/components/Form/InputWrapper.d.ts +28 -0
  80. package/react/components/Form/InputWrapper.js +91 -0
  81. package/react/components/Form/index.d.ts +3 -0
  82. package/react/components/Form/index.js +7 -1
  83. package/react/components/Input.js +5 -34
  84. package/react/components/Label.d.ts +1 -0
  85. package/react/components/Label.js +18 -2
  86. package/react/components/Layouts/Layout.js +1 -1
  87. package/react/components/Lists/ContentList.d.ts +45 -0
  88. package/react/components/Lists/ContentList.js +85 -0
  89. package/react/components/Navigation/BottomNav.d.ts +1 -0
  90. package/react/components/Navigation/BottomNav.js +2 -2
  91. package/react/components/Select.d.ts +1 -1
  92. package/react/components/Select.js +4 -26
  93. package/react/components/SelectWithTemplate.d.ts +11 -1
  94. package/react/components/SelectWithTemplate.js +19 -10
  95. package/react/components/TimePicker.d.ts +15 -2
  96. package/react/components/TimePicker.js +15 -4
  97. package/react/components/TreeSelect.d.ts +75 -0
  98. package/react/components/TreeSelect.js +448 -0
  99. package/react/index.d.ts +4 -0
  100. package/react/index.js +10 -3
@@ -0,0 +1,342 @@
1
+ import * as React from 'react';
2
+ import classNames from 'classnames';
3
+ import moment from 'moment';
4
+ import nextId from "react-id-generator";
5
+ import { InputWrapper } from './Form';
6
+
7
+ interface IProps {
8
+ hours?: number;
9
+ minutes?: number;
10
+ seconds?: number;
11
+ disabled?: boolean;
12
+ inlineLabel?: boolean;
13
+ required?: boolean;
14
+ fullWidth?: boolean;
15
+ invalid?: boolean;
16
+ labelHidden?: boolean;
17
+ tabindex?: number;
18
+ label?: string;
19
+ info?: string;
20
+ error?: string;
21
+ onChange(e: number): void;
22
+ }
23
+
24
+ interface IState {
25
+ hours?: any;
26
+ minutes?: any;
27
+ seconds?: any;
28
+ }
29
+
30
+ export class DurationInput extends React.PureComponent<IProps, IState> {
31
+ hourRef: React.RefObject<HTMLInputElement>;
32
+ minuteRef: React.RefObject<HTMLInputElement>;
33
+ secondRef: React.RefObject<HTMLInputElement>;
34
+ private htmlId = nextId();
35
+ constructor(props: IProps) {
36
+ super(props);
37
+ this.state = {
38
+ hours: this.stateUpdate('hours', this.props.hours, this.props.minutes, this.props.seconds),
39
+ minutes: this.stateUpdate('minutes', this.props.minutes, this.props.seconds),
40
+ seconds: this.stateUpdate('seconds', this.props.seconds),
41
+ };
42
+
43
+ this.hourRef = React.createRef();
44
+ this.minuteRef = React.createRef();
45
+ this.secondRef = React.createRef();
46
+ this.handleKeyDown = this.handleKeyDown.bind(this);
47
+ this.zeroPad = this.zeroPad.bind(this);
48
+ this.handleChange = this.handleChange.bind(this);
49
+ this.handleFocusOnKeyUp = this.handleFocusOnKeyUp.bind(this);
50
+ this.handleKeyValue = this.handleKeyValue.bind(this);
51
+ this.valueUpdate = this.valueUpdate.bind(this);
52
+ this.stateUpdate = this.stateUpdate.bind(this);
53
+ }
54
+
55
+ stateUpdate(state: string, parametar1?: number, parametar2?: number, parametar3?: number) {
56
+ let value;
57
+ if (state === 'hours') {
58
+ value = parametar1
59
+ ? parametar1 + Math.floor((parametar2 || 0) / 60) + Math.floor((parametar3 || 0) / 3600)
60
+ : Math.floor((parametar2 || 0) / 60) + Math.floor((parametar3 || 0) / 3600);
61
+ } else if (state === 'minutes') {
62
+ value = parametar1
63
+ ? (parametar1 % 60) + Math.floor((parametar2 || 0) % 3600 / 60)
64
+ : Math.floor((parametar2 || 0) % 3600 / 60);
65
+ } else {
66
+ value = parametar1 ? parametar1 % 60 : 0;
67
+ }
68
+ return this.zeroPad(value);
69
+ }
70
+
71
+ componentDidUpdate(_: any, prevState: IState) {
72
+ if (!this.hourRef.current || !this.minuteRef.current || !this.secondRef.current ) {
73
+ return;
74
+ }
75
+ if (this.state.hours !== prevState.hours) {
76
+ if (Number(this.hourRef.current.value) > 99) {
77
+ this.setState({
78
+ hours: this.zeroPad(99),
79
+ });
80
+ }
81
+ }
82
+ if (this.state.minutes !== prevState.minutes) {
83
+ if (Number(this.minuteRef.current.value) > 59) {
84
+ this.setState({
85
+ hours: this.zeroPad(Number(this.state.hours) + 1),
86
+ minutes: this.zeroPad(this.state.minutes % 60),
87
+ });
88
+ }
89
+ if (Number(this.minuteRef.current.value) < 0) {
90
+ this.setState({
91
+ hours: this.zeroPad(Number(this.state.hours)) > 0
92
+ ? this.zeroPad(Number(this.state.hours) - 1)
93
+ : this.zeroPad(Number(this.state.hours)),
94
+ minutes: 59,
95
+ });
96
+ }
97
+ }
98
+ if (this.state.seconds !== prevState.seconds) {
99
+ if (Number(this.secondRef.current.value) > 59) {
100
+ this.setState({
101
+ minutes: this.zeroPad(Number(this.state.minutes) + 1),
102
+ seconds: this.zeroPad(this.state.seconds % 60),
103
+ });
104
+ }
105
+ if (Number(this.secondRef.current.value) < 0) {
106
+ this.setState({
107
+ minutes: this.zeroPad(Number(this.state.minutes) - 1),
108
+ seconds: 59,
109
+ });
110
+ }
111
+ }
112
+ }
113
+
114
+ valueUpdate() {
115
+ if (this.props.onChange) {
116
+ this.props.onChange(moment.duration(`${this.state.hours}:${this.state.minutes}:${this.state.seconds}`)
117
+ .asSeconds());
118
+ }
119
+ }
120
+
121
+ handleKeyDown(event: React.KeyboardEvent<HTMLInputElement>) {
122
+ if (!(event.target instanceof HTMLInputElement)) {
123
+ return;
124
+ }
125
+ if (event.target.id === 'hours') {
126
+ if (event.key === 'ArrowRight') {
127
+ if (event.target.selectionEnd === event.target.value.length) {
128
+ this.handleFocus(this.minuteRef.current, event.target.id);
129
+ }
130
+ }
131
+ if (event.key === 'ArrowLeft') {
132
+ if (event.target.selectionStart === 0) {
133
+ this.handleFocus(this.secondRef.current, event.target.id);
134
+ }
135
+ }
136
+ }
137
+ if (event.target.id === 'minutes') {
138
+ if (event.key === 'ArrowRight') {
139
+ if (event.target.selectionEnd === event.target.value.length) {
140
+ this.handleFocus(this.secondRef.current, event.target.id);
141
+ }
142
+ }
143
+ if (event.key === 'ArrowLeft') {
144
+ if (event.target.selectionStart === 0) {
145
+ this.handleFocus(this.hourRef.current, event.target.id);
146
+ }
147
+ }
148
+ }
149
+ if (event.target.id === 'seconds') {
150
+ if (event.key === 'ArrowRight') {
151
+ if (event.target.selectionEnd === event.target.value.length) {
152
+ this.handleFocus(this.hourRef.current, event.target.id);
153
+ }
154
+ }
155
+ if (event.key === 'ArrowLeft') {
156
+ if (event.target.selectionStart === 0) {
157
+ this.handleFocus(this.minuteRef.current, event.target.id);
158
+ }
159
+ }
160
+ }
161
+ if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
162
+ this.handleKeyValue(event, event.target.id as 'hours' | 'minutes' | 'seconds');
163
+ setTimeout(this.valueUpdate);
164
+ }
165
+ if (event.key === 'ArrowRight' || event.key === 'ArrowLeft') {
166
+ if (!this.state.hours || !this.state.minutes || !this.state.seconds) {
167
+ setTimeout(this.valueUpdate);
168
+ }
169
+ }
170
+ }
171
+
172
+ handleKeyValue(event: React.KeyboardEvent<HTMLInputElement>, state: 'hours' | 'minutes' | 'seconds') {
173
+ if (!(event.target instanceof HTMLInputElement)) {
174
+ return;
175
+ }
176
+ if (!this.state[state]) {
177
+ return;
178
+ }
179
+ event.preventDefault();
180
+ event.stopPropagation();
181
+
182
+ let stateClone: IState = {};
183
+ if (event.key === 'ArrowUp') {
184
+ if (event.target.id === 'hours') {
185
+ stateClone[state] = this.state[state] < 99
186
+ ? this.zeroPad(Number(this.state[state]) + 1)
187
+ : this.zeroPad(99);
188
+ } else {
189
+ stateClone[state] = this.zeroPad(Number(this.state[state]) + 1);
190
+ }
191
+ } else if (event.key === 'ArrowDown') {
192
+ if (event.target.id === 'hours') {
193
+ stateClone[state] = this.state[state] > 0
194
+ ? this.zeroPad(Number(this.state[state]) - 1)
195
+ : this.zeroPad(0);
196
+ } else {
197
+ stateClone[state] = this.zeroPad(Number(this.state[state]) - 1);
198
+ }
199
+ }
200
+ this.setState(stateClone);
201
+ }
202
+
203
+ zeroPad(value: number | string) {
204
+ if (value.toString().length === 1 || value === 0) {
205
+ return `0${value}`;
206
+ } else if (!value) {
207
+ return '00';
208
+ } else {
209
+ return value;
210
+ }
211
+ }
212
+
213
+ handleChange(event: React.ChangeEvent<HTMLInputElement>, state: 'hours' | 'minutes' | 'seconds') {
214
+ let stateClone: IState = {};
215
+ if (event.target.value.length >= 2) {
216
+ stateClone[state] = event.target.value.slice(0, 2);
217
+ } else {
218
+ stateClone[state] = event.target.value;
219
+ }
220
+ this.setState(stateClone);
221
+ setTimeout(this.valueUpdate);
222
+ }
223
+
224
+ handleFocus(ref: HTMLInputElement | null, state: 'hours' | 'minutes' | 'seconds') {
225
+ ref?.focus();
226
+ setTimeout(() => {
227
+ ref?.setSelectionRange(0, 2);
228
+ });
229
+ let stateClone: IState = {};
230
+ stateClone[state] = this.zeroPad(this.state[state]);
231
+ this.setState(stateClone);
232
+ }
233
+
234
+ handleFocusOnKeyUp(event: React.KeyboardEvent<HTMLInputElement>, ref: HTMLInputElement | null) {
235
+ if (event.key !== 'ArrowRight' && event.key !== 'ArrowLeft' && event.key !== 'ArrowUp' && event.key !== 'ArrowDown' && event.key !== 'Backspace') {
236
+ if ((event.keyCode > 46 && event.keyCode < 58) || (event.keyCode > 95 && event.keyCode < 106)) {
237
+ const target = event.target as HTMLInputElement;
238
+ if (target.value.length >= 2) {
239
+ ref?.focus();
240
+ setTimeout(() => {
241
+ ref?.setSelectionRange(0, 2);
242
+ });
243
+ }
244
+ }
245
+ }
246
+ }
247
+
248
+ render() {
249
+ let InputClasses = classNames('sd-input__duration-input');
250
+
251
+ return (
252
+ <InputWrapper
253
+ label={this.props.label}
254
+ error={this.props.error}
255
+ required={this.props.required}
256
+ disabled={this.props.disabled}
257
+ invalid={this.props.invalid}
258
+ info={this.props.info}
259
+ inlineLabel={this.props.inlineLabel}
260
+ labelHidden={this.props.labelHidden}
261
+ fullWidth={this.props.fullWidth}
262
+ htmlId={this.htmlId}
263
+ tabindex={this.props.tabindex}>
264
+ <div className={InputClasses}>
265
+ <input
266
+ className='duration-input'
267
+ type='text'
268
+ id='hours'
269
+ max={99}
270
+ min={0}
271
+ ref={this.hourRef}
272
+ value={this.state.hours}
273
+ disabled={this.props.disabled}
274
+ onKeyDown={(event) => this.handleKeyDown(event)}
275
+ onKeyUp={(event) => this.handleFocusOnKeyUp(event, this.minuteRef.current)}
276
+ onChange={(event) => { this.handleChange(event, 'hours'); }}
277
+ onBlur={(event) => this.setState({hours: this.zeroPad(event.target.value)})}
278
+ onKeyPress={(event) => {
279
+ if (!/[0-9]/.test(event.key)) {
280
+ event.preventDefault();
281
+ }
282
+ }} />
283
+ <span className='sd-input__suffix'>h</span>
284
+
285
+ <input
286
+ className='duration-input'
287
+ type='text'
288
+ id='minutes'
289
+ ref={this.minuteRef}
290
+ value={this.state.minutes}
291
+ disabled={this.props.disabled}
292
+ onKeyDown={(event) => this.handleKeyDown(event)}
293
+ onKeyUp={(event) => this.handleFocusOnKeyUp(event, this.secondRef.current)}
294
+ onChange={(event) => { this.handleChange(event, 'minutes'); }}
295
+ onBlur={(event) => this.setState({minutes: this.zeroPad(event.target.value)})}
296
+ onKeyPress={(event) => {
297
+ if (!/[0-9]/.test(event.key)) {
298
+ event.preventDefault();
299
+ }
300
+ }} />
301
+ <span className='sd-input__suffix'>m</span>
302
+
303
+ <input
304
+ className='duration-input'
305
+ type='text'
306
+ id='seconds'
307
+ ref={this.secondRef}
308
+ value={this.state.seconds}
309
+ disabled={this.props.disabled}
310
+ onKeyDown={(event) => this.handleKeyDown(event)}
311
+ onKeyUp={(event) => this.handleFocusOnKeyUp(event, this.hourRef.current)}
312
+ onChange={(event) => { this.handleChange(event, 'seconds'); }}
313
+ onBlur={(event) => this.setState({seconds: this.zeroPad(event.target.value)})}
314
+ onKeyPress={(event) => {
315
+ if (!/[0-9]/.test(event.key)) {
316
+ event.preventDefault();
317
+ }
318
+ }} />
319
+ <span className='sd-input__suffix'>s</span>
320
+ </div>
321
+ </InputWrapper>
322
+ );
323
+ }
324
+ }
325
+
326
+ export function getDurationString(seconds: number) {
327
+ function zeroPad(value: number | string) {
328
+ if (value.toString().length === 1 || value === 0) {
329
+ return `0${value}`;
330
+ } else if (!value) {
331
+ return '00';
332
+ } else {
333
+ return value;
334
+ }
335
+ }
336
+
337
+ let hour = zeroPad(Math.floor(seconds / 3600));
338
+ let minute = zeroPad(Math.floor((seconds % 3600) / 60));
339
+ let second = zeroPad(Math.floor(seconds % 60));
340
+
341
+ return `${hour}h ${minute}m ${second}s`;
342
+ }
@@ -0,0 +1,85 @@
1
+ import * as React from 'react';
2
+
3
+ interface IPropsBase {
4
+ error?: string;
5
+ required?: boolean;
6
+ disabled?: boolean;
7
+ invalid?: boolean;
8
+ tabIndex?: number;
9
+ fullWidth?: boolean;
10
+ boxedStyle?: boolean;
11
+ boxedLable?: boolean;
12
+ placeholder?: string;
13
+ htmlId?: string;
14
+ id?: string;
15
+ size?: 'medium' | 'large' | 'x-large'; // default: 'medium'
16
+ }
17
+
18
+ interface IPropsText extends IPropsBase {
19
+ type: 'text';
20
+ value: string;
21
+ onChange(newValue: string): void;
22
+ }
23
+
24
+ interface IPropsPassword extends IPropsBase {
25
+ type: 'password';
26
+ value: string;
27
+ onChange(newValue: string): void;
28
+ }
29
+
30
+ interface IPropsNumber extends IPropsBase {
31
+ type: 'number';
32
+ value: number;
33
+ onChange(newValue: number): void;
34
+ }
35
+
36
+ type IProps = IPropsText | IPropsNumber | IPropsPassword;
37
+
38
+ interface IState {
39
+ value: string | number;
40
+ invalid: boolean;
41
+ }
42
+
43
+ export class InputBase extends React.Component<IProps, IState> {
44
+ constructor(props: IProps) {
45
+ super(props);
46
+
47
+ this.state = {
48
+ value: this.props.value ?? '',
49
+ invalid: this.props.invalid ?? false,
50
+ };
51
+
52
+ this.handleChange = this.handleChange.bind(this);
53
+ }
54
+
55
+ // htmlId = nextId();
56
+
57
+ handleChange(event: React.ChangeEvent<HTMLInputElement>) {
58
+ this.setState({ value: event.target.value });
59
+ if (this.props.type === 'number') {
60
+ this.props.onChange(Number(event.target.value));
61
+ } else {
62
+ this.props.onChange(event.target.value);
63
+ }
64
+ }
65
+
66
+ componentDidUpdate(prevProps: any) {
67
+ if (prevProps.value !== this.props.value) {
68
+ this.setState({value: this.props.value});
69
+ }
70
+ }
71
+
72
+ render() {
73
+ return (
74
+ <input className='sd-input__input'
75
+ type={this.props.type ?? 'text'}
76
+ id={this.props.htmlId}
77
+ value={this.state.value}
78
+ aria-describedby={this.props.htmlId + 'label'}
79
+ tabIndex={this.props.tabIndex}
80
+ onChange={this.handleChange}
81
+ placeholder={this.props.placeholder}
82
+ disabled={this.props.disabled} />
83
+ );
84
+ }
85
+ }
@@ -0,0 +1,107 @@
1
+ import * as React from 'react';
2
+ import nextId from "react-id-generator";
3
+
4
+ import {
5
+ InputBase,
6
+ InputWrapper
7
+ } from '.';
8
+
9
+ interface IPropsBase {
10
+ label?: string;
11
+ maxLength?: number;
12
+ info?: string;
13
+ inlineLabel?: boolean;
14
+ labelHidden?: boolean;
15
+ error?: string;
16
+ required?: boolean;
17
+ disabled?: boolean;
18
+ invalid?: boolean;
19
+ tabindex?: number;
20
+ fullWidth?: boolean;
21
+ boxedStyle?: boolean;
22
+ boxedLable?: boolean;
23
+ placeholder?: string;
24
+ size?: 'medium' | 'large' | 'x-large'; // default: 'medium'
25
+ }
26
+
27
+ interface IPropsText extends IPropsBase {
28
+ type: 'text';
29
+ value: string;
30
+ onChange(newValue: string): void;
31
+ }
32
+
33
+ interface IPropsPassword extends IPropsBase {
34
+ type: 'password';
35
+ value: string;
36
+ onChange(newValue: string): void;
37
+ }
38
+
39
+ interface IPropsNumber extends IPropsBase {
40
+ type: 'number';
41
+ value: string;
42
+ onChange(newValue: string): void;
43
+ }
44
+
45
+ type IProps = IPropsText | IPropsNumber | IPropsPassword;
46
+
47
+ interface IState {
48
+ value: string;
49
+ invalid: boolean;
50
+ }
51
+
52
+ export class InputNew extends React.PureComponent<IProps, IState> {
53
+ constructor(props: IProps) {
54
+ super(props);
55
+
56
+ this.state = {
57
+ value: this.props.value ?? '',
58
+ invalid: this.props.invalid ?? false,
59
+ };
60
+ }
61
+
62
+ componentDidUpdate(prevProps: any) {
63
+ if (prevProps.value !== this.props.value) {
64
+ this.setState({ value: this.props.value });
65
+ }
66
+ }
67
+
68
+ htmlId = nextId();
69
+
70
+ render() {
71
+ return (
72
+ <InputWrapper
73
+ label={this.props.label}
74
+ error={this.props.error}
75
+ required={this.props.required}
76
+ disabled={this.props.disabled}
77
+ value={this.state.value}
78
+ invalid={this.state.invalid}
79
+ info={this.props.info}
80
+ maxLength={this.props.maxLength}
81
+ inlineLabel={this.props.inlineLabel}
82
+ labelHidden={this.props.labelHidden}
83
+ size={this.props.size ?? 'medium'}
84
+ fullWidth={this.props.fullWidth}
85
+ htmlId={this.htmlId}
86
+ boxedStyle={this.props.boxedStyle}
87
+ boxedLable={this.props.boxedLable}
88
+ tabindex={this.props.tabindex}>
89
+ <InputBase
90
+ type="text"
91
+ onChange={(value: string) => {
92
+ this.setState({ value: value });
93
+ this.setState({ invalid: this.props.maxLength
94
+ ? (value as string).length > this.props.maxLength
95
+ : false });
96
+ this.props.onChange(value as string);
97
+ }}
98
+ disabled={this.props.disabled}
99
+ htmlId={this.htmlId}
100
+ value={this.state.value}
101
+ aria-describedby={this.htmlId + 'label'}
102
+ tabIndex={this.props.tabindex}
103
+ placeholder={this.props.placeholder} />
104
+ </InputWrapper>
105
+ );
106
+ }
107
+ }
@@ -0,0 +1,79 @@
1
+ import * as React from 'react';
2
+ import classNames from 'classnames';
3
+
4
+ interface IPropsBase {
5
+ label?: string;
6
+ children: React.ReactNode;
7
+ maxLength?: number;
8
+ info?: string;
9
+ error?: string;
10
+ required?: boolean;
11
+ disabled?: boolean;
12
+ invalid?: boolean;
13
+ inlineLabel?: boolean;
14
+ labelHidden?: boolean;
15
+ tabindex?: number;
16
+ fullWidth?: boolean;
17
+ boxedStyle?: boolean;
18
+ boxedLable?: boolean;
19
+ value?: string | number;
20
+ htmlId?: string;
21
+ size?: 'medium' | 'large' | 'x-large'; // default: 'medium'
22
+ }
23
+
24
+ interface IState {
25
+ value: string | number;
26
+ }
27
+
28
+ export class InputWrapper extends React.Component<IPropsBase, IState> {
29
+ constructor(props: IPropsBase) {
30
+ super(props);
31
+
32
+ this.state = {
33
+ value: this.props.value ?? '',
34
+ };
35
+ }
36
+
37
+ render() {
38
+ const classes = classNames('sd-input', {
39
+ 'sd-input--inline-label': this.props.inlineLabel,
40
+ 'sd-input--required': this.props.required,
41
+ 'sd-input--disabled': this.props.disabled,
42
+ 'sd-input--full-width': this.props.fullWidth,
43
+ 'sd-input--invalid': this.props.invalid,
44
+ 'sd-input--medium': this.props.size === undefined,
45
+ [`sd-input--${this.props.size}`]: this.props.size || this.props.size !== undefined,
46
+ 'sd-input--boxed-style': this.props.boxedStyle,
47
+ 'sd-input--boxed-label': this.props.boxedLable,
48
+ });
49
+ const labelClasses = classNames('sd-input__label', {
50
+ 'a11y-only': this.props.labelHidden,
51
+ 'sd-input__label--boxed': this.props.boxedLable,
52
+ });
53
+
54
+ return (
55
+ <div className={classes}>
56
+ <label className={labelClasses} htmlFor={this.props.htmlId} id={this.props.htmlId + 'label'}
57
+ tabIndex={this.props.tabindex === undefined ? undefined : -1}>
58
+ {this.props.label}
59
+ </label>
60
+ <div className="sd-input__input-container">
61
+ {this.props.children}
62
+ </div>
63
+ {this.props.maxLength
64
+ ? <div className='sd-input__char-count'>
65
+ {this.props.value?.toString().length} / {this.props.maxLength}
66
+ </div>
67
+ : null}
68
+ <div className='sd-input__message-box'>
69
+ {this.props.info && !this.props.invalid && !this.props.invalid
70
+ ? <div className='sd-input__hint'>{this.props.info}</div>
71
+ : null}
72
+ {this.props.invalid || this.props.invalid
73
+ ? <div className='sd-input__message'>{this.props.error}</div>
74
+ : null}
75
+ </div>
76
+ </div>
77
+ );
78
+ }
79
+ }
@@ -3,3 +3,6 @@ export { FormGroup } from './FormGroup';
3
3
  export { FormItem } from './FormItem';
4
4
  export { FormText } from './FormText';
5
5
  export { FormLabel } from './FormLabel';
6
+ export { InputWrapper } from './InputWrapper';
7
+ export { InputBase } from './InputBase';
8
+ export { InputNew } from './InputNew';