superdesk-ui-framework 4.1.3 → 4.1.5

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.
@@ -1,294 +0,0 @@
1
- import * as React from 'react';
2
- import {classnames, Spacer} from '@sourcefabric/common';
3
- import {ContentDivider} from './ContentDivider';
4
- import {RadioButtonGroup} from './RadioButtonGroup';
5
- import {getOptionsForTimeUnit, ITimeUnit, padValue} from '../utils/time';
6
- import {assertNever} from '../helpers';
7
-
8
- interface IProps {
9
- closePopup: () => void;
10
- headerTemplate?: React.ReactNode;
11
- footerTemplate?: React.ReactNode;
12
- allowSeconds?: boolean;
13
- onChange: (nextValue: string) => void;
14
- value: string | null;
15
- }
16
-
17
- interface IPropsTimeValueHolder {
18
- isActive?: boolean;
19
- value: string;
20
- onClick(event: React.MouseEvent<HTMLSpanElement>): void;
21
- }
22
-
23
- class TimeValueHolder extends React.PureComponent<IPropsTimeValueHolder> {
24
- spanEl: React.RefObject<HTMLSpanElement>;
25
-
26
- constructor(props: IPropsTimeValueHolder) {
27
- super(props);
28
-
29
- this.spanEl = React.createRef();
30
- }
31
-
32
- public scrollToValue() {
33
- this.spanEl.current?.scrollIntoView({block: 'start', behavior: 'smooth'});
34
- }
35
-
36
- render() {
37
- return (
38
- <span
39
- ref={this.props.isActive ? this.spanEl : undefined}
40
- onClick={this.props.onClick}
41
- className={classnames('p-1 time-unit', {
42
- 'time-unit-highlight': this.props.isActive ?? false,
43
- })}
44
- >
45
- {this.props.value}
46
- </span>
47
- );
48
- }
49
- }
50
-
51
- function parseUnitOfTime(unit: ITimeUnit, value: string | null, is12HourFormat?: boolean): string {
52
- const [hour, minutes, seconds] = (value ?? '').split(':');
53
- const valueForUnit = (() => {
54
- if (unit === 'hours') {
55
- /**
56
- * Hour value is always in 24-hour format, so we need to adjust it
57
- * to 12-hour if needed.
58
- */
59
- if (is12HourFormat) {
60
- return hour === '00' ? '12' : hour;
61
- } else {
62
- return hour;
63
- }
64
- } else if (unit === 'minutes') {
65
- return minutes;
66
- } else if (unit === 'seconds') {
67
- return seconds;
68
- } else {
69
- assertNever(unit);
70
- }
71
- })();
72
-
73
- const valueParsed =
74
- is12HourFormat && unit === 'hours' && valueForUnit !== '12'
75
- ? parseInt(valueForUnit, 10) % 12
76
- : parseInt(valueForUnit, 10);
77
-
78
- return padValue(valueParsed);
79
- }
80
-
81
- export class TimePickerPopover extends React.PureComponent<IProps> {
82
- private is12HourFormat: boolean;
83
-
84
- // hour, minutes, seconds
85
- private inputRefs: Array<React.RefObject<TimeValueHolder>>;
86
-
87
- constructor(props: IProps) {
88
- super(props);
89
-
90
- this.inputRefs = [React.createRef(), React.createRef(), React.createRef()];
91
- this.handleChange = this.handleChange.bind(this);
92
-
93
- const hour = new Date().toLocaleTimeString([]);
94
- this.is12HourFormat = hour.includes('AM') || hour.includes('PM');
95
- }
96
-
97
- handleChange(unit: ITimeUnit, value: string) {
98
- const fallbackDate = new Date();
99
- const [hour, minutes, seconds] =
100
- this.props.value == null
101
- ? [
102
- padValue(fallbackDate.getHours()),
103
- padValue(fallbackDate.getMinutes()),
104
- padValue(fallbackDate.getSeconds()),
105
- ]
106
- : this.props.value.split(':');
107
- let nextValue = '';
108
-
109
- if (unit === 'hours') {
110
- nextValue = `${value}:${minutes}`;
111
- } else if (unit === 'minutes') {
112
- nextValue = `${hour}:${value}`;
113
- } else if (unit === 'seconds') {
114
- nextValue = `${hour}:${minutes}:${value}`;
115
- } else {
116
- assertNever(unit);
117
- }
118
-
119
- if (this.props.allowSeconds && unit !== 'seconds') {
120
- nextValue += `:${seconds}`;
121
- }
122
-
123
- this.props.onChange(nextValue);
124
- }
125
-
126
- componentDidMount(): void {
127
- this.inputRefs.forEach((unitOfTime) => unitOfTime?.current?.scrollToValue?.());
128
- }
129
-
130
- render(): React.ReactNode {
131
- const styleForColumnOfUnit: React.CSSProperties = {
132
- maxHeight: 190,
133
- overflowY: 'auto',
134
- scrollbarWidth: 'none',
135
- marginTop: 'var(--gap-1)',
136
- scrollBehavior: 'smooth',
137
- };
138
-
139
- return (
140
- <div
141
- className="sd-shadow--z2 radius-md"
142
- onBlur={this.props.closePopup}
143
- onKeyDown={(event) => {
144
- if (event.key === 'Enter' || event.key === 'Escape') {
145
- event.preventDefault();
146
- this.props.closePopup();
147
- }
148
- }}
149
- tabIndex={0}
150
- >
151
- <Spacer
152
- v
153
- gap="0"
154
- style={{
155
- minWidth: 200,
156
- maxWidth: 'max-content',
157
- backgroundColor: 'var(--color-dropdown-menu-Bg)',
158
- borderRadius: 'var(--b-radius--small)',
159
- }}
160
- >
161
- {this.props.headerTemplate && (
162
- <div className="px-1-5 py-1" style={{borderBottom: '1px solid var(--color-line-x-light)'}}>
163
- {this.props.headerTemplate}
164
- </div>
165
- )}
166
-
167
- <Spacer
168
- h
169
- gap="4"
170
- noWrap
171
- justifyContent="center"
172
- alignItems="start"
173
- style={{paddingInline: 'var(--gap-1)'}}
174
- >
175
- <Spacer v gap="4" style={styleForColumnOfUnit} alignItems="center" noWrap>
176
- {getOptionsForTimeUnit('hours', this.is12HourFormat).map((hour) => {
177
- const isActiveHour =
178
- hour === parseUnitOfTime('hours', this.props.value, this.is12HourFormat);
179
-
180
- return (
181
- <TimeValueHolder
182
- key={hour}
183
- ref={isActiveHour ? this.inputRefs[0] : undefined}
184
- onClick={() => {
185
- this.handleChange('hours', hour);
186
- }}
187
- isActive={isActiveHour}
188
- value={hour}
189
- />
190
- );
191
- })}
192
- </Spacer>
193
- <ContentDivider align="center" border type="solid" orientation="vertical" margin="none" />
194
- <Spacer v gap="4" style={styleForColumnOfUnit} alignItems="center" noWrap>
195
- {getOptionsForTimeUnit('minutes', this.is12HourFormat).map((minute) => {
196
- const isActiveMinute =
197
- minute === parseUnitOfTime('minutes', this.props.value, this.is12HourFormat);
198
-
199
- return (
200
- <TimeValueHolder
201
- key={minute}
202
- ref={isActiveMinute ? this.inputRefs[1] : undefined}
203
- isActive={isActiveMinute}
204
- value={minute}
205
- onClick={() => {
206
- this.handleChange('minutes', minute);
207
- }}
208
- />
209
- );
210
- })}
211
- </Spacer>
212
- {this.props.allowSeconds && (
213
- <>
214
- <ContentDivider
215
- align="center"
216
- border
217
- type="solid"
218
- orientation="vertical"
219
- margin="none"
220
- />
221
- <Spacer v gap="4" style={styleForColumnOfUnit} alignItems="center" noWrap>
222
- {getOptionsForTimeUnit('seconds', this.is12HourFormat).map((second) => {
223
- const isActiveMinute =
224
- second ===
225
- parseUnitOfTime('seconds', this.props.value, this.is12HourFormat);
226
-
227
- return (
228
- <TimeValueHolder
229
- key={second}
230
- ref={isActiveMinute ? this.inputRefs[2] : undefined}
231
- onClick={() => {
232
- this.handleChange('seconds', second);
233
- }}
234
- isActive={isActiveMinute}
235
- value={second}
236
- />
237
- );
238
- })}
239
- </Spacer>
240
- </>
241
- )}
242
- {this.is12HourFormat && (
243
- <div
244
- style={{
245
- marginTop: 'var(--gap-1)',
246
- }}
247
- >
248
- <RadioButtonGroup
249
- onChange={(nextValue) => {
250
- const [hour, minutes, seconds] = (this.props.value ?? '').split(':');
251
-
252
- if (nextValue === 'PM') {
253
- let newValue = `${padValue(parseInt(hour, 10) + 12)}:${minutes}`;
254
-
255
- if (this.props.allowSeconds) {
256
- newValue += `:${seconds}`;
257
- }
258
-
259
- this.props.onChange(newValue);
260
- } else {
261
- let newValue = `${padValue(parseInt(hour, 10) - 12)}:${minutes}`;
262
-
263
- if (this.props.allowSeconds) {
264
- newValue += `:${seconds}`;
265
- }
266
-
267
- this.props.onChange(newValue);
268
- }
269
- }}
270
- options={[
271
- {
272
- label: 'AM',
273
- value: 'AM',
274
- },
275
- {
276
- label: 'PM',
277
- value: 'PM',
278
- },
279
- ]}
280
- value={parseInt((this.props.value ?? '').split(':')[0], 10) < 12 ? 'AM' : 'PM'}
281
- />
282
- </div>
283
- )}
284
- </Spacer>
285
- {this.props.footerTemplate && (
286
- <div className="px-1-5 py-1" style={{borderTop: '1px solid var(--color-line-x-light)'}}>
287
- {this.props.footerTemplate}
288
- </div>
289
- )}
290
- </Spacer>
291
- </div>
292
- );
293
- }
294
- }
@@ -1,19 +0,0 @@
1
- import * as React from 'react';
2
- import { ITimeUnit } from '../utils/time';
3
- interface IProps {
4
- closePopup: () => void;
5
- headerTemplate?: React.ReactNode;
6
- footerTemplate?: React.ReactNode;
7
- allowSeconds?: boolean;
8
- onChange: (nextValue: string) => void;
9
- value: string | null;
10
- }
11
- export declare class TimePickerPopover extends React.PureComponent<IProps> {
12
- private is12HourFormat;
13
- private inputRefs;
14
- constructor(props: IProps);
15
- handleChange(unit: ITimeUnit, value: string): void;
16
- componentDidMount(): void;
17
- render(): React.ReactNode;
18
- }
19
- export {};
@@ -1,227 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- var desc = Object.getOwnPropertyDescriptor(m, k);
20
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
- desc = { enumerable: true, get: function() { return m[k]; } };
22
- }
23
- Object.defineProperty(o, k2, desc);
24
- }) : (function(o, m, k, k2) {
25
- if (k2 === undefined) k2 = k;
26
- o[k2] = m[k];
27
- }));
28
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
- Object.defineProperty(o, "default", { enumerable: true, value: v });
30
- }) : function(o, v) {
31
- o["default"] = v;
32
- });
33
- var __importStar = (this && this.__importStar) || (function () {
34
- var ownKeys = function(o) {
35
- ownKeys = Object.getOwnPropertyNames || function (o) {
36
- var ar = [];
37
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
38
- return ar;
39
- };
40
- return ownKeys(o);
41
- };
42
- return function (mod) {
43
- if (mod && mod.__esModule) return mod;
44
- var result = {};
45
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
46
- __setModuleDefault(result, mod);
47
- return result;
48
- };
49
- })();
50
- Object.defineProperty(exports, "__esModule", { value: true });
51
- exports.TimePickerPopover = void 0;
52
- var React = __importStar(require("react"));
53
- var common_1 = require("@sourcefabric/common");
54
- var ContentDivider_1 = require("./ContentDivider");
55
- var RadioButtonGroup_1 = require("./RadioButtonGroup");
56
- var time_1 = require("../utils/time");
57
- var helpers_1 = require("../helpers");
58
- var TimeValueHolder = /** @class */ (function (_super) {
59
- __extends(TimeValueHolder, _super);
60
- function TimeValueHolder(props) {
61
- var _this = _super.call(this, props) || this;
62
- _this.spanEl = React.createRef();
63
- return _this;
64
- }
65
- TimeValueHolder.prototype.scrollToValue = function () {
66
- var _a;
67
- (_a = this.spanEl.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ block: 'start', behavior: 'smooth' });
68
- };
69
- TimeValueHolder.prototype.render = function () {
70
- var _a;
71
- return (React.createElement("span", { ref: this.props.isActive ? this.spanEl : undefined, onClick: this.props.onClick, className: (0, common_1.classnames)('p-1 time-unit', {
72
- 'time-unit-highlight': (_a = this.props.isActive) !== null && _a !== void 0 ? _a : false,
73
- }) }, this.props.value));
74
- };
75
- return TimeValueHolder;
76
- }(React.PureComponent));
77
- function parseUnitOfTime(unit, value, is12HourFormat) {
78
- var _a = (value !== null && value !== void 0 ? value : '').split(':'), hour = _a[0], minutes = _a[1], seconds = _a[2];
79
- var valueForUnit = (function () {
80
- if (unit === 'hours') {
81
- /**
82
- * Hour value is always in 24-hour format, so we need to adjust it
83
- * to 12-hour if needed.
84
- */
85
- if (is12HourFormat) {
86
- return hour === '00' ? '12' : hour;
87
- }
88
- else {
89
- return hour;
90
- }
91
- }
92
- else if (unit === 'minutes') {
93
- return minutes;
94
- }
95
- else if (unit === 'seconds') {
96
- return seconds;
97
- }
98
- else {
99
- (0, helpers_1.assertNever)(unit);
100
- }
101
- })();
102
- var valueParsed = is12HourFormat && unit === 'hours' && valueForUnit !== '12'
103
- ? parseInt(valueForUnit, 10) % 12
104
- : parseInt(valueForUnit, 10);
105
- return (0, time_1.padValue)(valueParsed);
106
- }
107
- var TimePickerPopover = /** @class */ (function (_super) {
108
- __extends(TimePickerPopover, _super);
109
- function TimePickerPopover(props) {
110
- var _this = _super.call(this, props) || this;
111
- _this.inputRefs = [React.createRef(), React.createRef(), React.createRef()];
112
- _this.handleChange = _this.handleChange.bind(_this);
113
- var hour = new Date().toLocaleTimeString([]);
114
- _this.is12HourFormat = hour.includes('AM') || hour.includes('PM');
115
- return _this;
116
- }
117
- TimePickerPopover.prototype.handleChange = function (unit, value) {
118
- var fallbackDate = new Date();
119
- var _a = this.props.value == null
120
- ? [
121
- (0, time_1.padValue)(fallbackDate.getHours()),
122
- (0, time_1.padValue)(fallbackDate.getMinutes()),
123
- (0, time_1.padValue)(fallbackDate.getSeconds()),
124
- ]
125
- : this.props.value.split(':'), hour = _a[0], minutes = _a[1], seconds = _a[2];
126
- var nextValue = '';
127
- if (unit === 'hours') {
128
- nextValue = "".concat(value, ":").concat(minutes);
129
- }
130
- else if (unit === 'minutes') {
131
- nextValue = "".concat(hour, ":").concat(value);
132
- }
133
- else if (unit === 'seconds') {
134
- nextValue = "".concat(hour, ":").concat(minutes, ":").concat(value);
135
- }
136
- else {
137
- (0, helpers_1.assertNever)(unit);
138
- }
139
- if (this.props.allowSeconds && unit !== 'seconds') {
140
- nextValue += ":".concat(seconds);
141
- }
142
- this.props.onChange(nextValue);
143
- };
144
- TimePickerPopover.prototype.componentDidMount = function () {
145
- this.inputRefs.forEach(function (unitOfTime) { var _a, _b; return (_b = (_a = unitOfTime === null || unitOfTime === void 0 ? void 0 : unitOfTime.current) === null || _a === void 0 ? void 0 : _a.scrollToValue) === null || _b === void 0 ? void 0 : _b.call(_a); });
146
- };
147
- TimePickerPopover.prototype.render = function () {
148
- var _this = this;
149
- var _a;
150
- var styleForColumnOfUnit = {
151
- maxHeight: 190,
152
- overflowY: 'auto',
153
- scrollbarWidth: 'none',
154
- marginTop: 'var(--gap-1)',
155
- scrollBehavior: 'smooth',
156
- };
157
- return (React.createElement("div", { className: "sd-shadow--z2 radius-md", onBlur: this.props.closePopup, onKeyDown: function (event) {
158
- if (event.key === 'Enter' || event.key === 'Escape') {
159
- event.preventDefault();
160
- _this.props.closePopup();
161
- }
162
- }, tabIndex: 0 },
163
- React.createElement(common_1.Spacer, { v: true, gap: "0", style: {
164
- minWidth: 200,
165
- maxWidth: 'max-content',
166
- backgroundColor: 'var(--color-dropdown-menu-Bg)',
167
- borderRadius: 'var(--b-radius--small)',
168
- } },
169
- this.props.headerTemplate && (React.createElement("div", { className: "px-1-5 py-1", style: { borderBottom: '1px solid var(--color-line-x-light)' } }, this.props.headerTemplate)),
170
- React.createElement(common_1.Spacer, { h: true, gap: "4", noWrap: true, justifyContent: "center", alignItems: "start", style: { paddingInline: 'var(--gap-1)' } },
171
- React.createElement(common_1.Spacer, { v: true, gap: "4", style: styleForColumnOfUnit, alignItems: "center", noWrap: true }, (0, time_1.getOptionsForTimeUnit)('hours', this.is12HourFormat).map(function (hour) {
172
- var isActiveHour = hour === parseUnitOfTime('hours', _this.props.value, _this.is12HourFormat);
173
- return (React.createElement(TimeValueHolder, { key: hour, ref: isActiveHour ? _this.inputRefs[0] : undefined, onClick: function () {
174
- _this.handleChange('hours', hour);
175
- }, isActive: isActiveHour, value: hour }));
176
- })),
177
- React.createElement(ContentDivider_1.ContentDivider, { align: "center", border: true, type: "solid", orientation: "vertical", margin: "none" }),
178
- React.createElement(common_1.Spacer, { v: true, gap: "4", style: styleForColumnOfUnit, alignItems: "center", noWrap: true }, (0, time_1.getOptionsForTimeUnit)('minutes', this.is12HourFormat).map(function (minute) {
179
- var isActiveMinute = minute === parseUnitOfTime('minutes', _this.props.value, _this.is12HourFormat);
180
- return (React.createElement(TimeValueHolder, { key: minute, ref: isActiveMinute ? _this.inputRefs[1] : undefined, isActive: isActiveMinute, value: minute, onClick: function () {
181
- _this.handleChange('minutes', minute);
182
- } }));
183
- })),
184
- this.props.allowSeconds && (React.createElement(React.Fragment, null,
185
- React.createElement(ContentDivider_1.ContentDivider, { align: "center", border: true, type: "solid", orientation: "vertical", margin: "none" }),
186
- React.createElement(common_1.Spacer, { v: true, gap: "4", style: styleForColumnOfUnit, alignItems: "center", noWrap: true }, (0, time_1.getOptionsForTimeUnit)('seconds', this.is12HourFormat).map(function (second) {
187
- var isActiveMinute = second ===
188
- parseUnitOfTime('seconds', _this.props.value, _this.is12HourFormat);
189
- return (React.createElement(TimeValueHolder, { key: second, ref: isActiveMinute ? _this.inputRefs[2] : undefined, onClick: function () {
190
- _this.handleChange('seconds', second);
191
- }, isActive: isActiveMinute, value: second }));
192
- })))),
193
- this.is12HourFormat && (React.createElement("div", { style: {
194
- marginTop: 'var(--gap-1)',
195
- } },
196
- React.createElement(RadioButtonGroup_1.RadioButtonGroup, { onChange: function (nextValue) {
197
- var _a;
198
- var _b = ((_a = _this.props.value) !== null && _a !== void 0 ? _a : '').split(':'), hour = _b[0], minutes = _b[1], seconds = _b[2];
199
- if (nextValue === 'PM') {
200
- var newValue = "".concat((0, time_1.padValue)(parseInt(hour, 10) + 12), ":").concat(minutes);
201
- if (_this.props.allowSeconds) {
202
- newValue += ":".concat(seconds);
203
- }
204
- _this.props.onChange(newValue);
205
- }
206
- else {
207
- var newValue = "".concat((0, time_1.padValue)(parseInt(hour, 10) - 12), ":").concat(minutes);
208
- if (_this.props.allowSeconds) {
209
- newValue += ":".concat(seconds);
210
- }
211
- _this.props.onChange(newValue);
212
- }
213
- }, options: [
214
- {
215
- label: 'AM',
216
- value: 'AM',
217
- },
218
- {
219
- label: 'PM',
220
- value: 'PM',
221
- },
222
- ], value: parseInt(((_a = this.props.value) !== null && _a !== void 0 ? _a : '').split(':')[0], 10) < 12 ? 'AM' : 'PM' })))),
223
- this.props.footerTemplate && (React.createElement("div", { className: "px-1-5 py-1", style: { borderTop: '1px solid var(--color-line-x-light)' } }, this.props.footerTemplate)))));
224
- };
225
- return TimePickerPopover;
226
- }(React.PureComponent));
227
- exports.TimePickerPopover = TimePickerPopover;