superdesk-ui-framework 3.0.35 → 3.0.38
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/app/styles/_sd-tag-input.scss +3 -5
- package/app/styles/_tag-labels.scss +0 -2
- package/app/styles/app.scss +1 -0
- package/app/styles/form-elements/_checkbox.scss +3 -0
- package/app/styles/form-elements/_input-preview.scss +70 -0
- package/app/styles/form-elements/_inputs.scss +10 -14
- package/app/styles/primereact/_pr-tag-input.scss +1 -1
- package/app-typescript/components/DatePicker.tsx +101 -101
- package/app-typescript/components/DurationInput.tsx +76 -76
- package/app-typescript/components/Form/InputNew.tsx +1 -1
- package/app-typescript/components/Form/InputWrapper.tsx +34 -18
- package/app-typescript/components/Input.tsx +38 -62
- package/app-typescript/components/MultiSelect.tsx +49 -47
- package/app-typescript/components/Select.tsx +13 -22
- package/app-typescript/components/SelectPreview.tsx +100 -0
- package/app-typescript/components/SelectWithTemplate.tsx +2 -12
- package/app-typescript/components/TagInput.tsx +25 -24
- package/app-typescript/components/TimePicker.tsx +13 -16
- package/app-typescript/components/TreeSelect.tsx +218 -158
- package/dist/examples.bundle.js +2400 -2258
- package/dist/react/Autocomplete.tsx +32 -31
- package/dist/react/DatePicker.tsx +56 -73
- package/dist/react/DurationInput.tsx +36 -47
- package/dist/react/Inputs.tsx +86 -248
- package/dist/react/MultiSelect.tsx +30 -23
- package/dist/react/Selects.tsx +12 -44
- package/dist/react/TagInputDocs.tsx +15 -21
- package/dist/react/TimePicker.tsx +25 -32
- package/dist/react/TreeSelect.tsx +97 -90
- package/dist/superdesk-ui.bundle.css +85 -18
- package/dist/superdesk-ui.bundle.js +1973 -1816
- package/dist/vendor.bundle.js +14 -14
- package/examples/pages/react/Autocomplete.tsx +32 -31
- package/examples/pages/react/DatePicker.tsx +56 -73
- package/examples/pages/react/DurationInput.tsx +36 -47
- package/examples/pages/react/Inputs.tsx +86 -248
- package/examples/pages/react/MultiSelect.tsx +30 -23
- package/examples/pages/react/Selects.tsx +12 -44
- package/examples/pages/react/TagInputDocs.tsx +15 -21
- package/examples/pages/react/TimePicker.tsx +25 -32
- package/examples/pages/react/TreeSelect.tsx +97 -90
- package/package.json +1 -1
- package/react/components/DatePicker.d.ts +2 -12
- package/react/components/DatePicker.js +14 -8
- package/react/components/DurationInput.d.ts +2 -11
- package/react/components/DurationInput.js +14 -4
- package/react/components/Form/InputNew.d.ts +1 -1
- package/react/components/Form/InputWrapper.d.ts +11 -5
- package/react/components/Form/InputWrapper.js +6 -9
- package/react/components/Input.d.ts +3 -19
- package/react/components/Input.js +8 -21
- package/react/components/MultiSelect.d.ts +4 -13
- package/react/components/MultiSelect.js +6 -2
- package/react/components/Select.d.ts +3 -15
- package/react/components/Select.js +7 -8
- package/react/components/SelectPreview.d.ts +17 -0
- package/react/components/SelectPreview.js +109 -0
- package/react/components/SelectWithTemplate.d.ts +2 -11
- package/react/components/SelectWithTemplate.js +0 -1
- package/react/components/TagInput.d.ts +3 -12
- package/react/components/TagInput.js +6 -2
- package/react/components/TimePicker.d.ts +2 -11
- package/react/components/TimePicker.js +6 -2
- package/react/components/TreeSelect.d.ts +5 -11
- package/react/components/TreeSelect.js +78 -47
@@ -1,21 +1,29 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import classNames from 'classnames';
|
3
3
|
|
4
|
-
interface
|
5
|
-
label
|
6
|
-
children: React.ReactNode;
|
7
|
-
maxLength?: number;
|
4
|
+
export interface IInputCommon {
|
5
|
+
label: string;
|
8
6
|
info?: string;
|
9
7
|
error?: string;
|
10
8
|
required?: boolean;
|
11
9
|
disabled?: boolean;
|
12
|
-
|
10
|
+
readonly?: boolean;
|
11
|
+
preview?: boolean;
|
13
12
|
inlineLabel?: boolean;
|
14
13
|
labelHidden?: boolean;
|
15
14
|
tabindex?: number;
|
16
15
|
fullWidth?: boolean;
|
17
16
|
boxedStyle?: boolean;
|
18
17
|
boxedLable?: boolean;
|
18
|
+
}
|
19
|
+
|
20
|
+
export interface IInputWrapper extends IInputCommon {
|
21
|
+
invalid?: boolean;
|
22
|
+
}
|
23
|
+
|
24
|
+
interface IPropsBase extends IInputWrapper {
|
25
|
+
children: React.ReactNode;
|
26
|
+
maxLength?: number;
|
19
27
|
value?: string | number;
|
20
28
|
htmlId?: string;
|
21
29
|
size?: 'medium' | 'large' | 'x-large'; // default: 'medium'
|
@@ -46,6 +54,7 @@ export class InputWrapper extends React.Component<IPropsBase, IState> {
|
|
46
54
|
'sd-input--boxed-style': this.props.boxedStyle,
|
47
55
|
'sd-input--boxed-label': this.props.boxedLable,
|
48
56
|
});
|
57
|
+
|
49
58
|
const labelClasses = classNames('sd-input__label', {
|
50
59
|
'a11y-only': this.props.labelHidden,
|
51
60
|
'sd-input__label--boxed': this.props.boxedLable,
|
@@ -53,25 +62,32 @@ export class InputWrapper extends React.Component<IPropsBase, IState> {
|
|
53
62
|
|
54
63
|
return (
|
55
64
|
<div className={classes}>
|
56
|
-
<label
|
57
|
-
|
65
|
+
<label
|
66
|
+
className={labelClasses}
|
67
|
+
htmlFor={this.props.htmlId}
|
68
|
+
id={this.props.htmlId + 'label'}
|
69
|
+
tabIndex={this.props.tabindex === undefined ? undefined : -1}
|
70
|
+
>
|
58
71
|
{this.props.label}
|
59
72
|
</label>
|
60
73
|
<div className="sd-input__input-container">
|
61
74
|
{this.props.children}
|
62
75
|
</div>
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
76
|
+
{
|
77
|
+
this.props.maxLength
|
78
|
+
&& <div className='sd-input__char-count'>
|
79
|
+
{this.props.value?.toString().length} / {this.props.maxLength}
|
80
|
+
</div>
|
81
|
+
}
|
68
82
|
<div className='sd-input__message-box'>
|
69
|
-
{
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
83
|
+
{
|
84
|
+
this.props.info && !this.props.invalid
|
85
|
+
&& <div className='sd-input__hint'>{this.props.info}</div>
|
86
|
+
}
|
87
|
+
{
|
88
|
+
this.props.invalid
|
89
|
+
&& <div className='sd-input__message'>{this.props.error}</div>
|
90
|
+
}
|
75
91
|
</div>
|
76
92
|
</div>
|
77
93
|
);
|
@@ -1,22 +1,9 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
// import classNames from 'classnames';
|
3
2
|
import nextId from "react-id-generator";
|
4
|
-
import { InputWrapper
|
3
|
+
import {IInputCommon, InputWrapper} from './Form/InputWrapper';
|
5
4
|
|
6
|
-
interface IPropsBase {
|
7
|
-
label?: string;
|
5
|
+
interface IPropsBase extends IInputCommon {
|
8
6
|
maxLength?: number;
|
9
|
-
info?: string;
|
10
|
-
error?: string;
|
11
|
-
required?: boolean;
|
12
|
-
disabled?: boolean;
|
13
|
-
invalid?: boolean;
|
14
|
-
inlineLabel?: boolean;
|
15
|
-
labelHidden?: boolean;
|
16
|
-
tabindex?: number;
|
17
|
-
fullWidth?: boolean;
|
18
|
-
boxedStyle?: boolean;
|
19
|
-
boxedLable?: boolean;
|
20
7
|
placeholder?: string;
|
21
8
|
size?: 'medium' | 'large' | 'x-large'; // default: 'medium'
|
22
9
|
}
|
@@ -41,73 +28,62 @@ interface IPropsNumber extends IPropsBase {
|
|
41
28
|
|
42
29
|
type IProps = IPropsText | IPropsNumber | IPropsPassword;
|
43
30
|
|
44
|
-
|
45
|
-
value: string | number;
|
46
|
-
invalid: boolean;
|
47
|
-
}
|
48
|
-
|
49
|
-
export class Input extends React.Component<IProps, IState> {
|
31
|
+
export class Input extends React.Component<IProps> {
|
50
32
|
constructor(props: IProps) {
|
51
33
|
super(props);
|
52
34
|
|
53
|
-
this.state = {
|
54
|
-
value: this.props.value ?? '',
|
55
|
-
invalid: this.props.invalid ?? false,
|
56
|
-
};
|
57
|
-
|
58
35
|
this.handleChange = this.handleChange.bind(this);
|
59
36
|
}
|
60
37
|
|
61
38
|
htmlId = nextId();
|
62
39
|
|
63
40
|
handleChange(event: React.ChangeEvent<HTMLInputElement>) {
|
64
|
-
this.setState({ value: event.target.value });
|
65
41
|
if (this.props.type === 'number') {
|
66
42
|
this.props.onChange(Number(event.target.value));
|
67
43
|
} else {
|
68
44
|
this.props.onChange(event.target.value);
|
69
45
|
}
|
70
|
-
|
71
|
-
if (this.props.maxLength && !this.props.invalid) {
|
72
|
-
this.setState({ invalid: event.target.value.length > this.props.maxLength });
|
73
|
-
}
|
74
|
-
}
|
75
|
-
|
76
|
-
componentDidUpdate(prevProps: any) {
|
77
|
-
if (prevProps.value !== this.props.value) {
|
78
|
-
this.setState({value: this.props.value ?? ''});
|
79
|
-
}
|
80
46
|
}
|
81
47
|
|
82
48
|
render() {
|
49
|
+
if (this.props.preview) {
|
50
|
+
return (
|
51
|
+
<div>
|
52
|
+
<span>{this.props.value}</span>
|
53
|
+
</div>
|
54
|
+
);
|
55
|
+
}
|
83
56
|
|
84
57
|
return (
|
85
58
|
<InputWrapper
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
59
|
+
label={this.props.label}
|
60
|
+
required={this.props.required}
|
61
|
+
disabled={this.props.disabled}
|
62
|
+
value={this.props.value}
|
63
|
+
invalid={this.props.error != null ? true : false}
|
64
|
+
error={this.props.error}
|
65
|
+
info={this.props.info}
|
66
|
+
maxLength={this.props.maxLength}
|
67
|
+
inlineLabel={this.props.inlineLabel}
|
68
|
+
labelHidden={this.props.labelHidden}
|
69
|
+
size={this.props.size ?? 'medium'}
|
70
|
+
fullWidth={this.props.fullWidth}
|
71
|
+
htmlId={this.htmlId}
|
72
|
+
boxedStyle={this.props.boxedStyle}
|
73
|
+
boxedLable={this.props.boxedLable}
|
74
|
+
tabindex={this.props.tabindex}
|
75
|
+
>
|
76
|
+
<input
|
77
|
+
className='sd-input__input'
|
78
|
+
type={this.props.type ?? 'text'}
|
79
|
+
id={this.htmlId}
|
80
|
+
value={this.props.value}
|
81
|
+
aria-describedby={this.htmlId + 'label'}
|
82
|
+
tabIndex={this.props.tabindex}
|
83
|
+
onChange={this.handleChange}
|
84
|
+
placeholder={this.props.placeholder}
|
85
|
+
disabled={this.props.disabled}
|
86
|
+
/>
|
111
87
|
</InputWrapper>
|
112
88
|
);
|
113
89
|
}
|
@@ -3,8 +3,10 @@ import { MultiSelect as PrimeMultiSelect } from "@superdesk/primereact/multisele
|
|
3
3
|
import classNames from 'classnames';
|
4
4
|
import nextId from "react-id-generator";
|
5
5
|
import { InputWrapper } from "./Form";
|
6
|
+
import {IInputWrapper} from './Form/InputWrapper';
|
7
|
+
import {SelectPreview} from './SelectPreview';
|
6
8
|
|
7
|
-
interface IProps<T> {
|
9
|
+
interface IProps<T> extends IInputWrapper {
|
8
10
|
value: Array<T>;
|
9
11
|
options: Array<T>;
|
10
12
|
placeholder?: string;
|
@@ -19,19 +21,9 @@ interface IProps<T> {
|
|
19
21
|
showSelectAll?: boolean;
|
20
22
|
zIndex?: number;
|
21
23
|
optionLabel: (option: T) => string;
|
22
|
-
itemTemplate?(item:
|
23
|
-
selectedItemTemplate?(value:
|
24
|
+
itemTemplate?(item: T): JSX.Element | undefined;
|
25
|
+
selectedItemTemplate?(value: T): JSX.Element | undefined;
|
24
26
|
onChange(newValue: Array<T>): void;
|
25
|
-
invalid?: boolean;
|
26
|
-
inlineLabel?: boolean;
|
27
|
-
labelHidden?: boolean;
|
28
|
-
tabindex?: number;
|
29
|
-
fullWidth?: boolean;
|
30
|
-
info?: string;
|
31
|
-
error?: string;
|
32
|
-
required?: boolean;
|
33
|
-
label?: string;
|
34
|
-
disabled?: boolean;
|
35
27
|
}
|
36
28
|
|
37
29
|
interface IState<T> {
|
@@ -46,54 +38,64 @@ export class MultiSelect<T> extends React.Component<IProps<T>, IState<T>> {
|
|
46
38
|
constructor(props: IProps<T>) {
|
47
39
|
super(props);
|
48
40
|
this.state = {
|
49
|
-
value: [],
|
41
|
+
value: this.props.value != null ? this.props.value : [],
|
50
42
|
options: [],
|
51
43
|
invalid: this.props.invalid ? this.props.invalid : false,
|
52
44
|
};
|
53
45
|
}
|
54
46
|
|
55
47
|
render() {
|
56
|
-
|
57
48
|
let classes = classNames({
|
58
49
|
'showSelectAll': this.props.showSelectAll,
|
59
50
|
'showFilter': this.props.filter,
|
60
51
|
});
|
61
52
|
|
53
|
+
if (this.props.preview) {
|
54
|
+
return (
|
55
|
+
<SelectPreview
|
56
|
+
kind={{mode: 'multi-select'}}
|
57
|
+
items={this.state.value}
|
58
|
+
valueTemplate={this.props.selectedItemTemplate}
|
59
|
+
getLabel={this.props.optionLabel}
|
60
|
+
/>
|
61
|
+
);
|
62
|
+
}
|
63
|
+
|
62
64
|
return (
|
63
65
|
<InputWrapper
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
disabled={this.props.disabled}
|
68
|
-
invalid={this.state.invalid}
|
69
|
-
info={this.props.info}
|
70
|
-
inlineLabel={this.props.inlineLabel}
|
71
|
-
labelHidden={this.props.labelHidden}
|
72
|
-
fullWidth={this.props.fullWidth}
|
73
|
-
htmlId={this.htmlId}
|
74
|
-
tabindex={this.props.tabindex}>
|
75
|
-
<PrimeMultiSelect
|
76
|
-
panelClassName={classes}
|
77
|
-
value={this.props.value}
|
78
|
-
options={this.props.options}
|
79
|
-
onChange={({value}) => this.props.onChange(value)}
|
80
|
-
display="chip"
|
81
|
-
zIndex={this.props.zIndex}
|
82
|
-
filter={this.props.filter}
|
83
|
-
appendTo={document.body}
|
84
|
-
placeholder={this.props.placeholder}
|
85
|
-
optionLabel={(option) => this.props.optionLabel(option)}
|
86
|
-
emptyFilterMessage={this.props.emptyFilterMessage}
|
87
|
-
filterPlaceholder={this.props.filterPlaceholder}
|
88
|
-
itemTemplate={this.props.itemTemplate}
|
89
|
-
selectedItemTemplate={this.props.selectedItemTemplate}
|
90
|
-
maxSelectedLabels={this.props.maxSelectedLabels ?? 4}
|
91
|
-
selectedItemsLabel={this.props.selectedItemsLabel}
|
92
|
-
ariaLabelledBy={this.htmlId + 'label'}
|
93
|
-
tabIndex={this.props.tabIndex ? this.props.tabIndex : '0'}
|
94
|
-
showClear={this.props.showClear}
|
66
|
+
label={this.props.label}
|
67
|
+
error={this.props.error}
|
68
|
+
required={this.props.required}
|
95
69
|
disabled={this.props.disabled}
|
96
|
-
|
70
|
+
info={this.props.info}
|
71
|
+
inlineLabel={this.props.inlineLabel}
|
72
|
+
labelHidden={this.props.labelHidden}
|
73
|
+
htmlId={this.htmlId}
|
74
|
+
tabindex={this.props.tabindex}
|
75
|
+
>
|
76
|
+
<PrimeMultiSelect
|
77
|
+
panelClassName={classes}
|
78
|
+
value={this.props.value}
|
79
|
+
options={this.props.options}
|
80
|
+
onChange={({value}) => this.props.onChange(value)}
|
81
|
+
display="chip"
|
82
|
+
zIndex={this.props.zIndex}
|
83
|
+
filter={this.props.filter}
|
84
|
+
appendTo={document.body}
|
85
|
+
placeholder={this.props.placeholder}
|
86
|
+
optionLabel={(option) => this.props.optionLabel(option)}
|
87
|
+
emptyFilterMessage={this.props.emptyFilterMessage}
|
88
|
+
filterPlaceholder={this.props.filterPlaceholder}
|
89
|
+
itemTemplate={this.props.itemTemplate}
|
90
|
+
selectedItemTemplate={this.props.selectedItemTemplate}
|
91
|
+
maxSelectedLabels={this.props.maxSelectedLabels ?? 4}
|
92
|
+
selectedItemsLabel={this.props.selectedItemsLabel}
|
93
|
+
ariaLabelledBy={this.htmlId + 'label'}
|
94
|
+
tabIndex={this.props.tabIndex ? this.props.tabIndex : '0'}
|
95
|
+
showClear={this.props.showClear}
|
96
|
+
disabled={this.props.disabled}
|
97
|
+
inputId={this.htmlId}
|
98
|
+
/>
|
97
99
|
</InputWrapper>
|
98
100
|
);
|
99
101
|
}
|
@@ -1,35 +1,18 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import nextId from "react-id-generator";
|
3
3
|
import { InputWrapper } from './Form';
|
4
|
+
import {IInputWrapper} from './Form/InputWrapper';
|
4
5
|
|
5
|
-
interface ISelect {
|
6
|
+
interface ISelect extends IInputWrapper {
|
6
7
|
value?: string;
|
7
|
-
label: string;
|
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
8
|
onChange(newValue: string): void;
|
18
9
|
}
|
19
10
|
|
20
|
-
|
21
|
-
invalid: boolean;
|
22
|
-
}
|
23
|
-
|
24
|
-
class Select extends React.Component<ISelect, IState> {
|
11
|
+
class Select extends React.Component<ISelect> {
|
25
12
|
private htmlId = nextId();
|
26
13
|
constructor(props: ISelect) {
|
27
14
|
super(props);
|
28
15
|
|
29
|
-
this.state = {
|
30
|
-
invalid: this.props.invalid ?? false,
|
31
|
-
};
|
32
|
-
|
33
16
|
this.handleChange = this.handleChange.bind(this);
|
34
17
|
}
|
35
18
|
|
@@ -38,13 +21,21 @@ class Select extends React.Component<ISelect, IState> {
|
|
38
21
|
}
|
39
22
|
|
40
23
|
render() {
|
24
|
+
if (this.props.preview) {
|
25
|
+
return (
|
26
|
+
<div>
|
27
|
+
<span>{this.props.value}</span>
|
28
|
+
</div>
|
29
|
+
);
|
30
|
+
}
|
31
|
+
|
41
32
|
return (
|
42
33
|
<InputWrapper
|
43
34
|
label={this.props.label}
|
44
35
|
error={this.props.error}
|
45
36
|
required={this.props.required}
|
46
37
|
disabled={this.props.disabled}
|
47
|
-
|
38
|
+
readonly={this.props.readonly}
|
48
39
|
info={this.props.info}
|
49
40
|
inlineLabel={this.props.inlineLabel}
|
50
41
|
labelHidden={this.props.labelHidden}
|
@@ -59,7 +50,7 @@ class Select extends React.Component<ISelect, IState> {
|
|
59
50
|
aria-describedby={this.htmlId}
|
60
51
|
tabIndex={this.props.tabindex}
|
61
52
|
onChange={this.handleChange}
|
62
|
-
disabled={this.props.disabled}
|
53
|
+
disabled={this.props.disabled || this.props.readonly}
|
63
54
|
>
|
64
55
|
{this.props.children}
|
65
56
|
</select>
|
@@ -0,0 +1,100 @@
|
|
1
|
+
import classNames from 'classnames';
|
2
|
+
import * as React from 'react';
|
3
|
+
import {getTextColor} from './Label';
|
4
|
+
|
5
|
+
interface IProps<T> {
|
6
|
+
items: Array<T>;
|
7
|
+
kind: {
|
8
|
+
mode: 'single-select'; getBorderColor?(item: T): string;
|
9
|
+
} | {
|
10
|
+
mode: 'multi-select'; getBackgroundColor?(item: T): string;
|
11
|
+
};
|
12
|
+
getLabel(item: T): string;
|
13
|
+
valueTemplate?(item: T, Wrapper?: React.ElementType): React.ComponentType<T> | JSX.Element | undefined;
|
14
|
+
}
|
15
|
+
|
16
|
+
export class SelectPreview<T> extends React.Component<IProps<T>> {
|
17
|
+
render() {
|
18
|
+
return (
|
19
|
+
<div className="tags-preview">
|
20
|
+
<ul className="tags-preview__tag-list">
|
21
|
+
{this.props.items.map((item, i: number) => {
|
22
|
+
const Wrapper: React.ComponentType<{backgroundColor?: string, borderColor?: string}>
|
23
|
+
= ({backgroundColor, borderColor, children}) => {
|
24
|
+
let classes = classNames('tags-preview__tag-item', {
|
25
|
+
'tags-preview__tag-item--single-select': this.props.kind.mode === 'single-select',
|
26
|
+
'tags-preview__tag-item--border': (
|
27
|
+
this.props.kind.mode === 'single-select' && this.props.kind.getBorderColor
|
28
|
+
)
|
29
|
+
|| borderColor,
|
30
|
+
});
|
31
|
+
|
32
|
+
return (
|
33
|
+
<li
|
34
|
+
className={classes}
|
35
|
+
style={(() => {
|
36
|
+
if (this.props.valueTemplate != null) {
|
37
|
+
return {backgroundColor, borderColor};
|
38
|
+
} else {
|
39
|
+
if (
|
40
|
+
this.props.kind.mode === 'multi-select'
|
41
|
+
&& this.props.kind.getBackgroundColor != null
|
42
|
+
) {
|
43
|
+
return {
|
44
|
+
backgroundColor: this.props.kind.getBackgroundColor(item),
|
45
|
+
};
|
46
|
+
} else if (
|
47
|
+
this.props.kind.mode === 'single-select'
|
48
|
+
&& this.props.kind.getBorderColor != null
|
49
|
+
) {
|
50
|
+
return {
|
51
|
+
borderLeftColor: this.props.kind.getBorderColor(item),
|
52
|
+
};
|
53
|
+
} else {
|
54
|
+
return undefined;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
})()}
|
58
|
+
>
|
59
|
+
<span
|
60
|
+
className="tags-input__helper-box"
|
61
|
+
style={(() => {
|
62
|
+
if (backgroundColor != null) {
|
63
|
+
return {color: getTextColor(backgroundColor)};
|
64
|
+
} else {
|
65
|
+
if (
|
66
|
+
this.props.kind.mode === 'multi-select'
|
67
|
+
&& this.props.kind.getBackgroundColor != null
|
68
|
+
) {
|
69
|
+
return {color: getTextColor(
|
70
|
+
this.props.kind.getBackgroundColor(item),
|
71
|
+
)};
|
72
|
+
} else {
|
73
|
+
return undefined;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
})()}
|
77
|
+
>
|
78
|
+
{children}
|
79
|
+
</span>
|
80
|
+
</li>
|
81
|
+
);
|
82
|
+
};
|
83
|
+
|
84
|
+
return (
|
85
|
+
<React.Fragment key={i}>
|
86
|
+
{this.props.valueTemplate
|
87
|
+
? this.props.valueTemplate(item, Wrapper)
|
88
|
+
: <Wrapper>
|
89
|
+
<span>{this.props.getLabel(item)}</span>
|
90
|
+
</Wrapper>
|
91
|
+
}
|
92
|
+
</React.Fragment>
|
93
|
+
);
|
94
|
+
|
95
|
+
})}
|
96
|
+
</ul>
|
97
|
+
</div>
|
98
|
+
);
|
99
|
+
}
|
100
|
+
}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import {Dropdown} from '@superdesk/primereact/dropdown';
|
3
|
-
// import classNames from 'classnames';
|
4
3
|
import nextId from "react-id-generator";
|
5
4
|
import { InputWrapper } from './Form';
|
5
|
+
import {IInputWrapper} from './Form/InputWrapper';
|
6
6
|
|
7
|
-
interface IProps<T> {
|
7
|
+
interface IProps<T> extends IInputWrapper {
|
8
8
|
// Don't forget to cancel unfinished requests every the prop is called.
|
9
9
|
getItems(searchString: string | null): Promise<Array<T>>;
|
10
10
|
value: T;
|
@@ -14,21 +14,11 @@ interface IProps<T> {
|
|
14
14
|
itemTemplate: React.ComponentType<{option: T | null}>;
|
15
15
|
noResultsFoundMessage: string;
|
16
16
|
filterPlaceholder?: string;
|
17
|
-
disabled?: boolean;
|
18
17
|
autoFocus?: boolean;
|
19
18
|
autoOpen?: boolean; // Avoid using this - the dropdown may cover important elements.
|
20
19
|
width?: 'min' | '100%'; // defaults to min
|
21
20
|
zIndex?: number;
|
22
21
|
'data-test-id'?: string;
|
23
|
-
inlineLabel?: boolean;
|
24
|
-
required?: boolean;
|
25
|
-
fullWidth?: boolean;
|
26
|
-
invalid?: boolean;
|
27
|
-
labelHidden?: boolean;
|
28
|
-
tabindex?: number;
|
29
|
-
label?: string;
|
30
|
-
info?: string;
|
31
|
-
error?: string;
|
32
22
|
}
|
33
23
|
|
34
24
|
interface IState<T> {
|
@@ -2,21 +2,13 @@ import * as React from 'react';
|
|
2
2
|
import { Chips } from '@superdesk/primereact/chips';
|
3
3
|
import {InputWrapper} from './Form';
|
4
4
|
import nextId from "react-id-generator";
|
5
|
+
import {IInputWrapper} from './Form/InputWrapper';
|
6
|
+
import {SelectPreview} from './SelectPreview';
|
5
7
|
|
6
|
-
interface IProps {
|
8
|
+
interface IProps extends IInputWrapper {
|
7
9
|
value: Array<string>;
|
8
10
|
onChange(value: Array<string>): void;
|
9
|
-
placeholder
|
10
|
-
invalid?: boolean;
|
11
|
-
inlineLabel?: boolean;
|
12
|
-
labelHidden?: boolean;
|
13
|
-
tabindex?: number;
|
14
|
-
fullWidth?: boolean;
|
15
|
-
info?: string;
|
16
|
-
error?: string;
|
17
|
-
required?: boolean;
|
18
|
-
label?: string;
|
19
|
-
disabled?: boolean;
|
11
|
+
placeholder?: string;
|
20
12
|
}
|
21
13
|
|
22
14
|
export class TagInput extends React.Component<IProps> {
|
@@ -25,26 +17,35 @@ export class TagInput extends React.Component<IProps> {
|
|
25
17
|
render() {
|
26
18
|
const {onChange, value, placeholder} = this.props;
|
27
19
|
|
20
|
+
if (this.props.preview) {
|
21
|
+
return (
|
22
|
+
<SelectPreview
|
23
|
+
kind={{mode: 'multi-select'}}
|
24
|
+
items={this.props.value}
|
25
|
+
getLabel={(item) => item}
|
26
|
+
/>
|
27
|
+
);
|
28
|
+
}
|
29
|
+
|
28
30
|
return (
|
29
31
|
<InputWrapper
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
tabindex={this.props.tabindex}>
|
32
|
+
label={this.props.label}
|
33
|
+
error={this.props.error}
|
34
|
+
required={this.props.required}
|
35
|
+
disabled={this.props.disabled}
|
36
|
+
info={this.props.info}
|
37
|
+
inlineLabel={this.props.inlineLabel}
|
38
|
+
labelHidden={this.props.labelHidden}
|
39
|
+
htmlId={this.htmlId}
|
40
|
+
tabindex={this.props.tabindex}
|
41
|
+
>
|
41
42
|
<Chips
|
42
43
|
className={`tags-input--multi-select sd-input__input ${this.props.disabled ? ' tags-input__padding-disabled' : ''}`}
|
43
44
|
allowDuplicate={false}
|
44
45
|
separator=","
|
45
46
|
onChange={(event) => onChange(event.value)}
|
46
47
|
value={value}
|
47
|
-
placeholder={placeholder}
|
48
|
+
placeholder={this.props.disabled ? undefined : placeholder}
|
48
49
|
disabled={this.props.disabled}
|
49
50
|
/>
|
50
51
|
</InputWrapper>
|