dce-reactkit 5.0.0 → 5.0.1

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.
@@ -3,7 +3,6 @@
3
3
  * @author Allison Zhang
4
4
  */
5
5
  declare enum ProgressBarSize {
6
- Small = "Small",
7
6
  Medium = "Medium",
8
7
  Large = "Large"
9
8
  }
package/dist/index.d.ts CHANGED
@@ -726,7 +726,6 @@ declare const Dropdown: React$1.FC<Props$1>;
726
726
  * @author Allison Zhang
727
727
  */
728
728
  declare enum ProgressBarSize {
729
- Small = "Small",
730
729
  Medium = "Medium",
731
730
  Large = "Large"
732
731
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dce-reactkit",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "description": "Shared components for Harvard DCE apps",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -10,6 +10,12 @@ import React from 'react';
10
10
  import Variant from '../types/Variant';
11
11
  import ProgressBarSize from '../types/ProgressBarSize';
12
12
 
13
+ // Import helpers
14
+ import {
15
+ roundToNumDecimals,
16
+ padDecimalZeros,
17
+ } from 'dce-commonkit';
18
+
13
19
  /*------------------------------------------------------------------------*/
14
20
  /* -------------------------------- Types ------------------------------- */
15
21
  /*------------------------------------------------------------------------*/
@@ -75,7 +81,7 @@ type ProgressStatus = (
75
81
  const ITEM_WIDTH_MULTIPLIER = 1.3;
76
82
 
77
83
  // Constant for percent width
78
- const PERCENT_WIDTH = 3;
84
+ const PERCENT_WIDTH = 2.7;
79
85
 
80
86
  // Constant for item width
81
87
  const ITEM_WIDTH = 2;
@@ -88,11 +94,9 @@ const ITEM_WIDTH = 2;
88
94
  let style = `
89
95
  .ProgressBar-number-of,
90
96
  .ProgressBar-percent {
91
- flex: 0 0 auto;
92
97
  white-space: nowrap;
93
- padding-right: 0.5em;
94
- padding-left: 0.25em;
95
- text-align: right;
98
+ padding-right: 0.3em;
99
+ text-align: left;
96
100
  transition: width .25s ease;
97
101
  }
98
102
 
@@ -164,10 +168,20 @@ const ProgressBar: React.FC<Props> = (props) => {
164
168
  /* ---------------- Sizes --------------- */
165
169
  /*----------------------------------------*/
166
170
 
171
+ // Add dynamic general style
172
+ style += `
173
+ .ProgressBar-percent {
174
+ min-width: ${(status.usePercent ? status.numDecimalPlaces ?? 0 : 0) + PERCENT_WIDTH}em;
175
+ }
176
+ .ProgressBar-number-of {
177
+ min-width: ${((!status.usePercent ? String(status.total ?? 0).length || 1 : 0) * ITEM_WIDTH_MULTIPLIER) + ITEM_WIDTH}em;
178
+ }
179
+ `;
180
+
167
181
  // Size styles
168
182
  switch (size) {
169
- case ProgressBarSize.Small:
170
- // Small size
183
+ case ProgressBarSize.Medium:
184
+ // Medium size
171
185
  style += `
172
186
  .ProgressBar-container .ProgressBar-number-of, .ProgressBar-container .ProgressBar-percent {
173
187
  font-size: 1em;
@@ -180,18 +194,10 @@ const ProgressBar: React.FC<Props> = (props) => {
180
194
  height: 1.5em;
181
195
  border-radius: 0.5em;
182
196
  }
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
197
  `;
192
198
  break;
193
- case ProgressBarSize.Medium:
194
- // Medium size
199
+ case ProgressBarSize.Large:
200
+ // Large size
195
201
  style += `
196
202
  .ProgressBar-container .ProgressBar-number-of, .ProgressBar-container .ProgressBar-percent {
197
203
  font-size: 1.5em;
@@ -204,38 +210,6 @@ const ProgressBar: React.FC<Props> = (props) => {
204
210
  height: 2em;
205
211
  border-radius: 0.7em;
206
212
  }
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
213
  `;
240
214
  break;
241
215
  default:
@@ -245,9 +219,8 @@ const ProgressBar: React.FC<Props> = (props) => {
245
219
  // Get the width of the outline based on size
246
220
  const outlineWidth = (() => {
247
221
  switch (size) {
248
- case ProgressBarSize.Small: return '0.05em';
249
- case ProgressBarSize.Medium: return '0.08em';
250
- case ProgressBarSize.Large: return '0.1em';
222
+ case ProgressBarSize.Medium: return '0.05em';
223
+ case ProgressBarSize.Large: return '0.08em';
251
224
  default: return '0.05em';
252
225
  }
253
226
  })();
@@ -275,25 +248,38 @@ const ProgressBar: React.FC<Props> = (props) => {
275
248
  `;
276
249
 
277
250
  // 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;
251
+ let stripes: React.ReactNode = null;
252
+ if (striped) {
253
+ stripes = (
254
+ <div>
255
+ <style>{stripesStyle}</style>
256
+ <div
257
+ className="ProgressBar-stripes position-absolute"
258
+ style={{
259
+ width: '200%',
260
+ height: '100%',
261
+ }}
262
+ >
263
+ &nbsp;
264
+ </div>
289
265
  </div>
290
- </div>
291
- );
266
+ );
267
+ }
292
268
 
293
269
  /*----------------------------------------*/
294
270
  /* --------------- Main UI -------------- */
295
271
  /*----------------------------------------*/
296
272
 
273
+ // Calculate the width of the progress bar
274
+ let progressBarWidthPercent = 0;
275
+ if (status.usePercent) {
276
+ // Use percent progress directly
277
+ progressBarWidthPercent = status.percentProgress;
278
+ } else if (status.total > 0) {
279
+ // Calculate percent progress from items
280
+ progressBarWidthPercent = (status.numComplete / status.total) * 100;
281
+ }
282
+
297
283
  // Render the progress bar
298
284
  return (
299
285
  <div className="ProgressBar-container d-flex align-items-center">
@@ -301,25 +287,27 @@ const ProgressBar: React.FC<Props> = (props) => {
301
287
  <style>{style}</style>
302
288
  {/* Use items */}
303
289
  {!status.usePercent && status.numComplete && (
304
- <span
305
- className="ProgressBar-number-of pe-2 align-self-center"
306
- >
290
+ <span className="ProgressBar-number-of">
307
291
  {status.numComplete}
308
292
  &nbsp;of&nbsp;
309
293
  {status.total}
310
294
  </span>
311
295
  )}
312
296
  {/* 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)}
297
+ {status.usePercent && (
298
+ <span className="ProgressBar-percent">
299
+ {
300
+ padDecimalZeros(
301
+ roundToNumDecimals(status.percentProgress ?? 0, status?.numDecimalPlaces ?? 0),
302
+ status?.numDecimalPlaces ?? 0,
303
+ )
304
+ }
318
305
  %
319
306
  </span>
320
307
  )}
308
+ {/* Progress Bar Filled Area */}
321
309
  <div
322
- className={`ProgressBar-background bg-${bgVariant} w-100`}
310
+ className={`ProgressBar-background bg-${bgVariant} flex-grow-1`}
323
311
  style={{
324
312
  boxShadow: `0 0 0 ${outlineWidth} ${showOutline ? '#000' : '#DEE2E6'}`,
325
313
  }}
@@ -332,11 +320,13 @@ const ProgressBar: React.FC<Props> = (props) => {
332
320
  `ProgressBar-bar bg-${variant} text-start position-relative`
333
321
  }
334
322
  style={{
335
- width: `${(status.usePercent ? status.percentProgress : (status.numComplete / status.total) * 100)}%`,
323
+ width: `${progressBarWidthPercent}%`,
336
324
  overflow: 'hidden',
337
325
  }}
338
326
  >
339
- {striped && stripes}
327
+ {/* Show Strips (if they exist) */}
328
+ {stripes}
329
+ {/* Space so the bar has some content */}
340
330
  &nbsp;
341
331
  </div>
342
332
  </div>
@@ -3,7 +3,6 @@
3
3
  * @author Allison Zhang
4
4
  */
5
5
  enum ProgressBarSize {
6
- Small = 'Small',
7
6
  Medium = 'Medium',
8
7
  Large = 'Large',
9
8
  }