superdesk-ui-framework 4.0.45 → 4.0.47
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/.github/workflows/test.yml +1 -1
- package/app-typescript/components/DateTimePicker.tsx +169 -108
- package/app-typescript/components/TreeSelect/TreeSelect.tsx +1 -1
- package/app-typescript/components/avatar/avatar-group.tsx +1 -1
- package/app-typescript/index.ts +1 -1
- package/dist/examples.bundle.js +37045 -54795
- package/dist/playgrounds/react-playgrounds/Multiedit.tsx +1 -1
- package/dist/superdesk-ui.bundle.js +36537 -54287
- package/dist/vendor.bundle.js +19 -19
- package/examples/pages/playgrounds/react-playgrounds/Multiedit.tsx +1 -1
- package/package.json +1 -2
- package/react/components/DateTimePicker.d.ts +23 -1
- package/react/components/DateTimePicker.js +83 -26
- package/react/components/TreeSelect/TreeSelect.js +1 -1
- package/react/components/avatar/avatar-group.js +1 -1
- package/react/index.d.ts +1 -1
- package/react/index.js +1 -1
@@ -1,128 +1,189 @@
|
|
1
1
|
import * as React from "react";
|
2
2
|
import { DatePicker } from "../components/DatePicker";
|
3
|
-
import { Spacer } from
|
3
|
+
import { Spacer } from '@sourcefabric/common';
|
4
4
|
import { defaultTo } from "lodash";
|
5
5
|
import { TimePicker } from "./TimePicker";
|
6
6
|
import { IconButton } from "./IconButton";
|
7
7
|
import { InputWrapper } from "./Form";
|
8
8
|
import { IInputWrapper } from "./Form/InputWrapper";
|
9
9
|
import nextId from "react-id-generator";
|
10
|
+
import {format} from 'date-fns';
|
11
|
+
import {assertNever} from '../helpers';
|
10
12
|
|
11
|
-
interface
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
interface IPropsValueDate extends IInputWrapper {
|
14
|
+
valueType: 'date';
|
15
|
+
value: Date | null;
|
16
|
+
dateFormat: string;
|
17
|
+
onChange: (value: Date | null) => void;
|
18
|
+
preview?: boolean;
|
19
|
+
fullWidth?: boolean;
|
20
|
+
allowSeconds?: boolean;
|
21
|
+
required?: boolean;
|
22
|
+
disabled?: boolean;
|
23
|
+
ref?: React.LegacyRef<InputWrapper>;
|
24
|
+
'data-test-id'?: string;
|
22
25
|
}
|
23
26
|
|
24
|
-
|
25
|
-
private htmlId: string = nextId();
|
27
|
+
type IValue = {date?: string; time?: string};
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
interface IPropsValueObject extends IInputWrapper {
|
30
|
+
valueType: 'object';
|
31
|
+
value: IValue;
|
32
|
+
dateFormat: string;
|
33
|
+
onChange: (value: IValue) => void; //
|
34
|
+
preview?: boolean;
|
35
|
+
fullWidth?: boolean;
|
36
|
+
allowSeconds?: boolean;
|
37
|
+
required?: boolean;
|
38
|
+
disabled?: boolean;
|
39
|
+
ref?: React.LegacyRef<InputWrapper>;
|
40
|
+
'data-test-id'?: string;
|
41
|
+
}
|
32
42
|
|
33
|
-
|
43
|
+
type IProps = IPropsValueDate | IPropsValueObject;
|
34
44
|
|
35
|
-
|
36
|
-
|
45
|
+
export class DateTimePicker extends React.PureComponent<IProps> {
|
46
|
+
private htmlId: string = nextId();
|
37
47
|
|
38
|
-
|
39
|
-
|
40
|
-
|
48
|
+
handleTimeChange = (time: string) => {
|
49
|
+
if (this.props.valueType === 'date') {
|
50
|
+
const [hours, minutes] = time
|
51
|
+
.split(":")
|
52
|
+
.map((x) => defaultTo(parseInt(x, 10), 0));
|
53
|
+
const origDate = this.props.value ? new Date(this.props.value) : new Date();
|
41
54
|
|
42
|
-
|
55
|
+
origDate.setHours(hours, minutes);
|
56
|
+
|
57
|
+
this.props.onChange(origDate);
|
58
|
+
} else if (this.props.valueType === 'object') {
|
59
|
+
this.props.onChange({
|
60
|
+
...this.props.value,
|
61
|
+
time,
|
62
|
+
});
|
63
|
+
} else {
|
64
|
+
assertNever(this.props);
|
65
|
+
}
|
43
66
|
}
|
44
67
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
selectedDate.setHours(origDate.getHours(), origDate.getMinutes());
|
49
|
-
|
50
|
-
this.props.onChange(selectedDate);
|
51
|
-
}
|
52
|
-
|
53
|
-
prepareFormat(unitOfTime: number) {
|
54
|
-
return unitOfTime.toString().padStart(2, "0");
|
55
|
-
}
|
56
|
-
|
57
|
-
render() {
|
58
|
-
const convertedTimeValue =
|
59
|
-
this.props.value != null
|
60
|
-
? `${this.prepareFormat(
|
61
|
-
this.props.value.getHours(),
|
62
|
-
)}:${this.prepareFormat(this.props.value.getMinutes())}`
|
63
|
-
: "";
|
64
|
-
|
65
|
-
return (
|
66
|
-
<InputWrapper
|
67
|
-
label={this.props.label}
|
68
|
-
error={this.props.error}
|
69
|
-
invalid={this.props.error != null}
|
70
|
-
required={this.props.required}
|
71
|
-
disabled={this.props.disabled}
|
72
|
-
info={this.props.info}
|
73
|
-
inlineLabel={this.props.inlineLabel}
|
74
|
-
labelHidden={this.props.labelHidden}
|
75
|
-
htmlId={this.htmlId}
|
76
|
-
tabindex={this.props.tabindex}
|
77
|
-
fullWidth={this.props.fullWidth}
|
78
|
-
inputWrapper={this.props.inputWrapper}
|
79
|
-
data-test-id={this.props["data-test-id"]}
|
80
|
-
ref={this.props.ref}
|
81
|
-
>
|
82
|
-
<Spacer h gap="8" alignItems="end" noWrap>
|
83
|
-
<div style={{ flexGrow: 1 }}>
|
84
|
-
<DatePicker
|
85
|
-
disabled={this.props.disabled}
|
86
|
-
preview={this.props.preview}
|
87
|
-
required={this.props.required}
|
88
|
-
hideClearButton={true}
|
89
|
-
value={this.props.value}
|
90
|
-
onChange={(val) => {
|
91
|
-
this.handleDateChange(val);
|
92
|
-
}}
|
93
|
-
dateFormat={this.props.dateFormat}
|
94
|
-
inlineLabel
|
95
|
-
labelHidden
|
96
|
-
fullWidth={this.props.fullWidth}
|
97
|
-
/>
|
98
|
-
</div>
|
99
|
-
<div style={{ flexGrow: 1 }}>
|
100
|
-
<TimePicker
|
101
|
-
disabled={this.props.disabled}
|
102
|
-
preview={this.props.preview}
|
103
|
-
value={convertedTimeValue}
|
104
|
-
onChange={(val) => {
|
105
|
-
this.handleTimeChange(val);
|
106
|
-
}}
|
107
|
-
inlineLabel
|
108
|
-
labelHidden
|
109
|
-
allowSeconds={this.props.allowSeconds}
|
110
|
-
fullWidth={this.props.fullWidth}
|
111
|
-
required={this.props.required}
|
112
|
-
/>
|
113
|
-
</div>
|
114
|
-
{this.props.preview !== true && (
|
115
|
-
<IconButton
|
116
|
-
disabled={this.props.disabled}
|
117
|
-
icon="remove-sign"
|
118
|
-
onClick={() => {
|
68
|
+
handleDateChange = (date: Date | null) => {
|
69
|
+
if (this.props.valueType === 'date') {
|
70
|
+
if (date == null) {
|
119
71
|
this.props.onChange(null);
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
72
|
+
return;
|
73
|
+
}
|
74
|
+
|
75
|
+
const origDate = this.props.value ?? new Date();
|
76
|
+
const selectedDate = new Date(date);
|
77
|
+
|
78
|
+
selectedDate.setHours(origDate.getHours(), origDate.getMinutes());
|
79
|
+
|
80
|
+
this.props.onChange(selectedDate);
|
81
|
+
} else if (this.props.valueType === 'object') {
|
82
|
+
this.props.onChange({
|
83
|
+
...this.props.value,
|
84
|
+
date: date ? format(date, 'yyyy-MM-dd') : undefined,
|
85
|
+
});
|
86
|
+
} else {
|
87
|
+
assertNever(this.props);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
prepareFormat(unitOfTime: number) {
|
92
|
+
return unitOfTime.toString().padStart(2, "0");
|
93
|
+
}
|
94
|
+
|
95
|
+
getTimeValue(): string {
|
96
|
+
if (this.props.valueType === 'date') {
|
97
|
+
|
98
|
+
return this.props.value != null
|
99
|
+
? `${this.prepareFormat(this.props.value.getHours())}:${this.prepareFormat(this.props.value.getMinutes())}`
|
100
|
+
: "";
|
101
|
+
} else if (this.props.valueType === 'object') {
|
102
|
+
return this.props.value.time ?? '';
|
103
|
+
} else {
|
104
|
+
assertNever(this.props);
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
getDateValue(): Date | null {
|
109
|
+
if (this.props.valueType === 'date') {
|
110
|
+
return this.props.value;
|
111
|
+
} else if (this.props.valueType === 'object') {
|
112
|
+
return this.props.value.date ? new Date(this.props.value.date) : null;
|
113
|
+
} else {
|
114
|
+
assertNever(this.props);
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
handleClear = () => {
|
119
|
+
if (this.props.valueType === 'date') {
|
120
|
+
this.props.onChange(null);
|
121
|
+
} else if (this.props.valueType === 'object') {
|
122
|
+
this.props.onChange({date: undefined, time: undefined});
|
123
|
+
} else {
|
124
|
+
assertNever(this.props);
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
render() {
|
129
|
+
const timeValue = this.getTimeValue();
|
130
|
+
const dateValue = this.getDateValue();
|
131
|
+
|
132
|
+
return (
|
133
|
+
<InputWrapper
|
134
|
+
label={this.props.label}
|
135
|
+
error={this.props.error}
|
136
|
+
invalid={this.props.error != null}
|
137
|
+
required={this.props.required}
|
138
|
+
disabled={this.props.disabled}
|
139
|
+
info={this.props.info}
|
140
|
+
inlineLabel={this.props.inlineLabel}
|
141
|
+
labelHidden={this.props.labelHidden}
|
142
|
+
htmlId={this.htmlId}
|
143
|
+
tabindex={this.props.tabindex}
|
144
|
+
fullWidth={this.props.fullWidth}
|
145
|
+
inputWrapper={this.props.inputWrapper}
|
146
|
+
data-test-id={this.props["data-test-id"]}
|
147
|
+
ref={this.props.ref}
|
148
|
+
>
|
149
|
+
<Spacer h gap="8" alignItems="end" noWrap>
|
150
|
+
<div style={{ flexGrow: 1 }}>
|
151
|
+
<DatePicker
|
152
|
+
disabled={this.props.disabled}
|
153
|
+
preview={this.props.preview}
|
154
|
+
required={this.props.required}
|
155
|
+
hideClearButton={true}
|
156
|
+
value={dateValue}
|
157
|
+
onChange={this.handleDateChange}
|
158
|
+
dateFormat={this.props.dateFormat}
|
159
|
+
inlineLabel
|
160
|
+
labelHidden
|
161
|
+
fullWidth={this.props.fullWidth}
|
162
|
+
/>
|
163
|
+
</div>
|
164
|
+
<div style={{ flexGrow: 1 }}>
|
165
|
+
<TimePicker
|
166
|
+
disabled={this.props.disabled}
|
167
|
+
preview={this.props.preview}
|
168
|
+
value={timeValue}
|
169
|
+
onChange={this.handleTimeChange}
|
170
|
+
inlineLabel
|
171
|
+
labelHidden
|
172
|
+
allowSeconds={this.props.allowSeconds}
|
173
|
+
fullWidth={this.props.fullWidth}
|
174
|
+
required={this.props.required}
|
175
|
+
/>
|
176
|
+
</div>
|
177
|
+
{this.props.preview !== true && (
|
178
|
+
<IconButton
|
179
|
+
disabled={this.props.disabled}
|
180
|
+
icon="remove-sign"
|
181
|
+
onClick={this.handleClear}
|
182
|
+
ariaValue="Clear"
|
183
|
+
/>
|
184
|
+
)}
|
185
|
+
</Spacer>
|
186
|
+
</InputWrapper>
|
187
|
+
);
|
188
|
+
}
|
128
189
|
}
|
@@ -15,7 +15,7 @@ import {keyboardNavigation} from './KeyboardNavigation';
|
|
15
15
|
import {WithPortal} from '../WithPortal';
|
16
16
|
import { DragDropContext, Droppable, Draggable, DropResult } from "react-beautiful-dnd";
|
17
17
|
import {getNextZIndex} from '../../zIndex';
|
18
|
-
import {arrayMove} from '@
|
18
|
+
import {arrayMove} from '@sourcefabric/common';
|
19
19
|
|
20
20
|
interface IState<T> {
|
21
21
|
value: Array<T>;
|
@@ -4,7 +4,7 @@ import {Avatar, IPropsAvatar} from './avatar';
|
|
4
4
|
import {AvatarWrapper} from './avatar-wrapper';
|
5
5
|
import {AvatarContentNumber} from './avatar-number';
|
6
6
|
import {AvatarPlaceholder, IPropsAvatarPlaceholder} from './avatar-placeholder';
|
7
|
-
import {Spacer} from '@
|
7
|
+
import {Spacer} from '@sourcefabric/common';
|
8
8
|
import {WithPopover} from '../WithPopover';
|
9
9
|
|
10
10
|
export type IAvatarInGroup = Omit<IPropsAvatar, 'size'>;
|
package/app-typescript/index.ts
CHANGED
@@ -102,7 +102,7 @@ export { MultiSelect } from './components/MultiSelect';
|
|
102
102
|
export { ResizablePanels } from './components/ResizablePanels';
|
103
103
|
export { WithPopover } from './components/WithPopover';
|
104
104
|
export { PopupPositioner, showPopup } from './components/ShowPopup';
|
105
|
-
export { Spacer, SpacerBlock } from '@
|
105
|
+
export { Spacer, SpacerBlock } from '@sourcefabric/common';
|
106
106
|
export { ResizeObserverComponent } from './components/ResizeObserverComponent';
|
107
107
|
export { DragHandleDots } from './components/DragHandleDots';
|
108
108
|
export { DragHandle } from './components/DragHandle';
|