dce-reactkit 4.2.4-beta-timestamp.2 → 4.2.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.
@@ -0,0 +1,347 @@
1
+ /**
2
+ * Customizable Progress Bar component using Bootstrap styles
3
+ * @author Allison Zhang
4
+ */
5
+
6
+ // Import React
7
+ import React from 'react';
8
+
9
+ // Import types
10
+ import Variant from '../types/Variant';
11
+ import ProgressBarSize from '../types/ProgressBarSize';
12
+
13
+ /*------------------------------------------------------------------------*/
14
+ /* -------------------------------- Types ------------------------------- */
15
+ /*------------------------------------------------------------------------*/
16
+
17
+ // Props definition
18
+ type Props = (
19
+ & (
20
+ // Percent
21
+ | {
22
+ // Percentage progress (0-100)
23
+ percentProgress: number,
24
+ // Num decimal places to show (default 0)
25
+ numDecimalPlaces?: number,
26
+ }
27
+ // Items
28
+ | {
29
+ // Current progress (number of items completed)
30
+ numComplete: number,
31
+ // Maximum progress (total number of items)
32
+ total: number,
33
+ }
34
+ )
35
+ & {
36
+ // Whether to show striped effect (default false)
37
+ striped?: boolean,
38
+ // Variant of the progress bar (default warning)
39
+ variant?: Variant,
40
+ // Background variants (default secondary subtle)
41
+ bgVariant?: Variant,
42
+ // Hide outline (default false)
43
+ showOutline?: boolean,
44
+ // Size of the progress bar (default md)
45
+ size?: ProgressBarSize,
46
+ }
47
+ );
48
+
49
+ // Progress status definition
50
+ type ProgressStatus = (
51
+ | {
52
+ // usePercent true
53
+ usePercent: true,
54
+ // Percentage progress (0-100)
55
+ percentProgress: number,
56
+ // Num decimal places to show (default 0)
57
+ numDecimalPlaces?: number,
58
+ }
59
+ // Items
60
+ | {
61
+ // usePercent false
62
+ usePercent: false,
63
+ // Current progress (number of items completed)
64
+ numComplete: number,
65
+ // Maximum progress (total number of items)
66
+ total: number,
67
+ }
68
+ );
69
+
70
+ /*------------------------------------------------------------------------*/
71
+ /* ------------------------------ Constants ----------------------------- */
72
+ /*------------------------------------------------------------------------*/
73
+
74
+ // Multiplier for calculating width of number of items
75
+ const ITEM_WIDTH_MULTIPLIER = 1.3;
76
+
77
+ // Constant for percent width
78
+ const PERCENT_WIDTH = 3;
79
+
80
+ // Constant for item width
81
+ const ITEM_WIDTH = 2;
82
+
83
+ /*------------------------------------------------------------------------*/
84
+ /* -------------------------------- Style ------------------------------- */
85
+ /*------------------------------------------------------------------------*/
86
+
87
+ // Base styles
88
+ let style = `
89
+ .ProgressBar-number-of,
90
+ .ProgressBar-percent {
91
+ flex: 0 0 auto;
92
+ white-space: nowrap;
93
+ padding-right: 0.5em;
94
+ padding-left: 0.25em;
95
+ text-align: right;
96
+ transition: width .25s ease;
97
+ }
98
+
99
+ .ProgressBar-background {
100
+ overflow: hidden;
101
+ }
102
+
103
+ .ProgressBar-bar {
104
+ transition: width 1s ease;
105
+ overflow: hidden;
106
+ }
107
+ `;
108
+
109
+ /*------------------------------------------------------------------------*/
110
+ /* ------------------------------ Component ----------------------------- */
111
+ /*------------------------------------------------------------------------*/
112
+
113
+ const ProgressBar: React.FC<Props> = (props) => {
114
+ /*------------------------------------------------------------------------*/
115
+ /* -------------------------------- Setup ------------------------------- */
116
+ /*------------------------------------------------------------------------*/
117
+
118
+ /* -------------- Props ------------- */
119
+
120
+ // Destructure props
121
+ const {
122
+ striped,
123
+ variant = Variant.Warning,
124
+ bgVariant = Variant.Secondary,
125
+ showOutline,
126
+ size = ProgressBarSize.Medium,
127
+ } = props;
128
+
129
+ /* -------------- Status ------------- */
130
+
131
+ // Determine progress status
132
+ let status: ProgressStatus;
133
+
134
+ // Check whether to use percent or items
135
+ if ('percentProgress' in props) {
136
+ // Percent
137
+ const {
138
+ percentProgress,
139
+ numDecimalPlaces,
140
+ } = props;
141
+ status = {
142
+ usePercent: true,
143
+ percentProgress,
144
+ numDecimalPlaces,
145
+ };
146
+ } else {
147
+ // Items
148
+ const {
149
+ numComplete,
150
+ total,
151
+ } = props;
152
+ status = {
153
+ usePercent: false,
154
+ numComplete,
155
+ total,
156
+ };
157
+ }
158
+
159
+ /*------------------------------------------------------------------------*/
160
+ /* ------------------------------- Render ------------------------------- */
161
+ /*------------------------------------------------------------------------*/
162
+
163
+ /*----------------------------------------*/
164
+ /* ---------------- Sizes --------------- */
165
+ /*----------------------------------------*/
166
+
167
+ // Size styles
168
+ switch (size) {
169
+ case ProgressBarSize.Small:
170
+ // Small size
171
+ style += `
172
+ .ProgressBar-container .ProgressBar-number-of, .ProgressBar-container .ProgressBar-percent {
173
+ font-size: 1em;
174
+ }
175
+ .ProgressBar-container .ProgressBar-background {
176
+ height: 1.5em;
177
+ border-radius: 0.5em;
178
+ }
179
+ .ProgressBar-container .ProgressBar-bar {
180
+ height: 1.5em;
181
+ border-radius: 0.5em;
182
+ }
183
+ .ProgressBar-percent {
184
+ min-width: ${((status.usePercent ? status.numDecimalPlaces ?? 0 : 0) * 1) + PERCENT_WIDTH}em;
185
+ max-width: ${((status.usePercent ? status.numDecimalPlaces ?? 0 : 0) * 1) + PERCENT_WIDTH}em;
186
+ }
187
+ .ProgressBar-number-of {
188
+ min-width: ${((!status.usePercent ? status.total?.toString().length || 1 : 0) * ITEM_WIDTH_MULTIPLIER) + ITEM_WIDTH}em;
189
+ max-width: ${((!status.usePercent ? status.total?.toString().length || 1 : 0) * ITEM_WIDTH_MULTIPLIER) + ITEM_WIDTH}em;
190
+ }
191
+ `;
192
+ break;
193
+ case ProgressBarSize.Medium:
194
+ // Medium size
195
+ style += `
196
+ .ProgressBar-container .ProgressBar-number-of, .ProgressBar-container .ProgressBar-percent {
197
+ font-size: 1.5em;
198
+ }
199
+ .ProgressBar-container .ProgressBar-background {
200
+ height: 2em;
201
+ border-radius: 0.7em;
202
+ }
203
+ .ProgressBar-container .ProgressBar-bar {
204
+ height: 2em;
205
+ border-radius: 0.7em;
206
+ }
207
+ .ProgressBar-percent {
208
+ min-width: ${((status.usePercent ? status.numDecimalPlaces ?? 0 : 0) * 1) + PERCENT_WIDTH}em;
209
+ max-width: ${((status.usePercent ? status.numDecimalPlaces ?? 0 : 0) * 1) + PERCENT_WIDTH}em;
210
+ }
211
+ .ProgressBar-number-of {
212
+ min-width: ${((!status.usePercent ? status.total?.toString().length || 1 : 0) * ITEM_WIDTH_MULTIPLIER) + ITEM_WIDTH}em;
213
+ max-width: ${((!status.usePercent ? status.total?.toString().length || 1 : 0) * ITEM_WIDTH_MULTIPLIER) + ITEM_WIDTH}em;
214
+ }
215
+ `;
216
+ break;
217
+ case ProgressBarSize.Large:
218
+ // Large size
219
+ style += `
220
+ .ProgressBar-container .ProgressBar-number-of, .ProgressBar-container .ProgressBar-percent {
221
+ font-size: 2em;
222
+ }
223
+ .ProgressBar-container .ProgressBar-background {
224
+ height: 3em;
225
+ border-radius: 1em;
226
+ }
227
+ .ProgressBar-container .ProgressBar-bar {
228
+ height: 3em;
229
+ border-radius: 1em;
230
+ }
231
+ .ProgressBar-percent {
232
+ min-width: ${((status.usePercent ? status.numDecimalPlaces ?? 0 : 0) * 1) + PERCENT_WIDTH}em;
233
+ max-width: ${((status.usePercent ? status.numDecimalPlaces ?? 0 : 0) * 1) + PERCENT_WIDTH}em;
234
+ }
235
+ .ProgressBar-number-of {
236
+ min-width: ${((!status.usePercent ? status.total?.toString().length || 1 : 0) * ITEM_WIDTH_MULTIPLIER) + ITEM_WIDTH}em;
237
+ max-width: ${((!status.usePercent ? status.total?.toString().length || 1 : 0) * ITEM_WIDTH_MULTIPLIER) + ITEM_WIDTH}em;
238
+ }
239
+ `;
240
+ break;
241
+ default:
242
+ break;
243
+ }
244
+
245
+ // Get the width of the outline based on size
246
+ const outlineWidth = (() => {
247
+ switch (size) {
248
+ case ProgressBarSize.Small: return '0.05em';
249
+ case ProgressBarSize.Medium: return '0.08em';
250
+ case ProgressBarSize.Large: return '0.1em';
251
+ default: return '0.05em';
252
+ }
253
+ })();
254
+
255
+ /*----------------------------------------*/
256
+ /* --------------- Stripes -------------- */
257
+ /*----------------------------------------*/
258
+
259
+ // Stripes style
260
+ const stripesStyle = `
261
+ .ProgressBar-stripes {
262
+ background-image: linear-gradient(315deg, #ffffff 25%, #000000 25%, #000000 50%, #ffffff 50%, #ffffff 75%, #000000 75%, #000000 100%);
263
+ background-size: 6em 6em;
264
+ animation: ProgressBar-stripe-animation 2.5s linear infinite;
265
+ opacity: 0.09;
266
+ }
267
+ @keyframes ProgressBar-stripe-animation {
268
+ 0% {
269
+ background-position: -6em 0;
270
+ }
271
+ 100% {
272
+ background-position: 0 0;
273
+ }
274
+ }
275
+ `;
276
+
277
+ // Stripes for striped effect
278
+ const stripes: React.ReactNode = (
279
+ <div>
280
+ <style>{stripesStyle}</style>
281
+ <div
282
+ className="ProgressBar-stripes position-absolute "
283
+ style={{
284
+ width: '200%',
285
+ height: '100%',
286
+ }}
287
+ >
288
+ &nbsp;
289
+ </div>
290
+ </div>
291
+ );
292
+
293
+ /*----------------------------------------*/
294
+ /* --------------- Main UI -------------- */
295
+ /*----------------------------------------*/
296
+
297
+ // Render the progress bar
298
+ return (
299
+ <div className="ProgressBar-container d-flex align-items-center">
300
+ {/* Style */}
301
+ <style>{style}</style>
302
+ {/* Use items */}
303
+ {!status.usePercent && status.numComplete && (
304
+ <span
305
+ className="ProgressBar-number-of pe-2 align-self-center"
306
+ >
307
+ {status.numComplete}
308
+ &nbsp;of&nbsp;
309
+ {status.total}
310
+ </span>
311
+ )}
312
+ {/* Use percentage */}
313
+ {status.usePercent && status.percentProgress && (
314
+ <span
315
+ className="ProgressBar-percent pe-2 align-self-center"
316
+ >
317
+ {status.percentProgress.toFixed(status?.numDecimalPlaces ?? 0)}
318
+ %
319
+ </span>
320
+ )}
321
+ <div
322
+ className={`ProgressBar-background bg-${bgVariant} w-100`}
323
+ style={{
324
+ boxShadow: `0 0 0 ${outlineWidth} ${showOutline ? '#000' : '#DEE2E6'}`,
325
+ }}
326
+ aria-valuenow={status.usePercent ? status.percentProgress : status.numComplete}
327
+ aria-valuemin={0}
328
+ aria-valuemax={status.usePercent ? 100 : status.total}
329
+ >
330
+ <div
331
+ className={
332
+ `ProgressBar-bar bg-${variant} text-start position-relative`
333
+ }
334
+ style={{
335
+ width: `${(status.usePercent ? status.percentProgress : (status.numComplete / status.total) * 100)}%`,
336
+ overflow: 'hidden',
337
+ }}
338
+ >
339
+ {striped && stripes}
340
+ &nbsp;
341
+ </div>
342
+ </div>
343
+ </div>
344
+ );
345
+ };
346
+
347
+ export default ProgressBar;
@@ -36,67 +36,21 @@ const getTimestampFromTimeInfoInET = (
36
36
  minute,
37
37
  } = opts;
38
38
 
39
+ // Determine if the date is in DST in Eastern Time
40
+ const tempDate = new Date(year, month - 1, day);
41
+ const janOffset = new Date(year, 0, 1).getTimezoneOffset();
42
+ const isDST = tempDate.getTimezoneOffset() < janOffset;
43
+ const etOffset = isDST ? '-04:00' : '-05:00';
44
+
39
45
  // Format with leading zeroes
40
46
  const mm = padZerosLeft(month, 2);
41
47
  const dd = padZerosLeft(day, 2);
42
48
  const hh = padZerosLeft(hour, 2);
43
49
  const min = padZerosLeft(minute, 2);
44
50
 
45
- // Use Intl.DateTimeFormat to get the ET offset and ET components
46
- const dateForET = new Date(Date.UTC(year, month - 1, day, hour, minute, 0));
47
- const options: Intl.DateTimeFormatOptions = {
48
- timeZone: 'America/New_York',
49
- year: 'numeric',
50
- month: '2-digit',
51
- day: '2-digit',
52
- hour: '2-digit',
53
- minute: '2-digit',
54
- second: '2-digit',
55
- hour12: false,
56
- timeZoneName: 'shortOffset',
57
- };
58
- const parts: Intl.DateTimeFormatPart[] = new Intl.DateTimeFormat('en-US', options).formatToParts(dateForET);
59
- const etYear: string | undefined = parts.find((p: Intl.DateTimeFormatPart) => {
60
- return p.type === 'year';
61
- })?.value;
62
- const etMonth: string | undefined = parts.find((p: Intl.DateTimeFormatPart) => {
63
- return p.type === 'month';
64
- })?.value;
65
- const etDay: string | undefined = parts.find((p: Intl.DateTimeFormatPart) => {
66
- return p.type === 'day';
67
- })?.value;
68
- const etHour: string | undefined = parts.find((p: Intl.DateTimeFormatPart) => {
69
- return p.type === 'hour';
70
- })?.value;
71
- const etMinute: string | undefined = parts.find((p: Intl.DateTimeFormatPart) => {
72
- return p.type === 'minute';
73
- })?.value;
74
- const etSecond: string | undefined = parts.find((p: Intl.DateTimeFormatPart) => {
75
- return p.type === 'second';
76
- })?.value;
77
- const tzName: string | undefined = parts.find((p: Intl.DateTimeFormatPart) => {
78
- return p.type === 'timeZoneName';
79
- })?.value;
80
-
81
- // Validate we got everything we need
82
- if (!etYear || !etMonth || !etDay || !etHour || !etMinute || !etSecond || !tzName) {
83
- throw new ErrorWithCode(
84
- 'Failed to parse date parts from Intl.DateTimeFormat',
85
- ReactKitErrorCode.ETTimestampInvalid,
86
- );
87
- }
88
-
89
- // Extract numeric offset from "GMT-4" or "UTC-5"
90
- const offsetNum = Number(tzName.replace(/^(GMT|UTC)/, ''));
91
- const sign = offsetNum >= 0 ? '+' : '-';
92
- const offset = `${sign}${padZerosLeft(Math.abs(offsetNum), 2)}:00`;
93
-
94
- // Build ISO string with offset
95
- const etDateString = `${etYear}-${etMonth}-${etDay}T${etHour}:${etMinute}:${etSecond}${offset}`;
96
-
97
- // Parse into ET timestamp
98
- const etDate = new Date(etDateString);
99
- const timestamp = etDate.getTime();
51
+ // Build ET ISO string and convert to UTC timestamp
52
+ const etISOString = `${year}-${mm}-${dd}T${hh}:${min}:00${etOffset}`;
53
+ const timestamp = (new Date(etISOString)).getTime();
100
54
 
101
55
  // Verify that the timestamp is correct
102
56
  const timeInfoInET = getTimeInfoInET(timestamp);
@@ -108,9 +62,7 @@ const getTimestampFromTimeInfoInET = (
108
62
  || timeInfoInET.minute !== minute
109
63
  ) {
110
64
  throw new ErrorWithCode(
111
- `Timestamp mismatch: expected ${year}-${mm}-${dd} ${hh}:${min}, `
112
- + `got ${timeInfoInET.year}-${padZerosLeft(timeInfoInET.month, 2)}-${padZerosLeft(timeInfoInET.day, 2)} `
113
- + `${padZerosLeft(timeInfoInET.hour, 2)}:${padZerosLeft(timeInfoInET.minute, 2)}`,
65
+ `Timestamp mismatch: expected ${year}-${mm}-${dd} ${hh}:${min}, got ${timeInfoInET.year}-${padZerosLeft(timeInfoInET.month, 2)}-${padZerosLeft(timeInfoInET.day, 2)} ${padZerosLeft(timeInfoInET.hour, 2)}:${padZerosLeft(timeInfoInET.minute, 2)}`,
114
66
  ReactKitErrorCode.ETTimestampInvalid,
115
67
  );
116
68
  }
package/src/index.ts CHANGED
@@ -31,6 +31,7 @@ import ToggleSwitch from './components/ToggleSwitch';
31
31
  import AutoscrollToBottomContainer from './components/AutoscrollToBottomContainer';
32
32
  import MultiSwitch from './components/MultiSwitch';
33
33
  import Dropdown from './components/Dropdown';
34
+ import ProgressBar from './components/ProgressBar';
34
35
 
35
36
  // Import errors
36
37
  import ErrorWithCode from './errors/ErrorWithCode';
@@ -156,6 +157,7 @@ export {
156
157
  AutoscrollToBottomContainer,
157
158
  MultiSwitch,
158
159
  Dropdown,
160
+ ProgressBar,
159
161
  // Global functions
160
162
  alert,
161
163
  prompt,
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Progress bar sizes
3
+ * @author Allison Zhang
4
+ */
5
+ enum ProgressBarSize {
6
+ Small = 'Small',
7
+ Medium = 'Medium',
8
+ Large = 'Large',
9
+ }
10
+
11
+ export default ProgressBarSize;