@thesquad-components/sqd-module-template 0.1.0 → 0.1.2

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/dist/index.mjs CHANGED
@@ -1,8 +1,41 @@
1
- import { ResponsiveContainer, RadialBarChart, PolarAngleAxis, Legend, Tooltip, RadialBar } from 'recharts';
1
+ import { ResponsiveContainer, RadialBarChart, PolarAngleAxis, Tooltip, RadialBar } from 'recharts';
2
2
  import { extendTailwindMerge } from 'tailwind-merge';
3
- import { jsx, jsxs } from 'react/jsx-runtime';
4
- import { useState, useMemo, useEffect } from 'react';
3
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
4
+ import { createContext, useState, useMemo, useCallback, useEffect, isValidElement, useContext } from 'react';
5
+ import { Link, Button as Button$1, TextField as TextField$1, Label as Label$1, Group, Input as Input$1, Text, TooltipTrigger as TooltipTrigger$1, Tooltip as Tooltip$1, OverlayArrow } from 'react-aria-components';
6
+ import { HelpCircle, InfoCircle } from '@untitledui/icons';
5
7
 
8
+ var __defProp = Object.defineProperty;
9
+ var __defProps = Object.defineProperties;
10
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
11
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
12
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
13
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
14
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
+ var __spreadValues = (a, b) => {
16
+ for (var prop in b || (b = {}))
17
+ if (__hasOwnProp.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ if (__getOwnPropSymbols)
20
+ for (var prop of __getOwnPropSymbols(b)) {
21
+ if (__propIsEnum.call(b, prop))
22
+ __defNormalProp(a, prop, b[prop]);
23
+ }
24
+ return a;
25
+ };
26
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
27
+ var __objRest = (source, exclude) => {
28
+ var target = {};
29
+ for (var prop in source)
30
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
31
+ target[prop] = source[prop];
32
+ if (source != null && __getOwnPropSymbols)
33
+ for (var prop of __getOwnPropSymbols(source)) {
34
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
35
+ target[prop] = source[prop];
36
+ }
37
+ return target;
38
+ };
6
39
  var twMerge = extendTailwindMerge({
7
40
  extend: {
8
41
  theme: {
@@ -11,26 +44,9 @@ var twMerge = extendTailwindMerge({
11
44
  }
12
45
  });
13
46
  var cx = twMerge;
14
- var ChartLegendContent = ({ payload = [] }) => {
15
- if (payload.length === 0) {
16
- return null;
17
- }
18
- return /* @__PURE__ */ jsx("div", { className: "flex flex-wrap items-center justify-center gap-x-4 gap-y-2", children: payload.map((entry, index) => {
19
- var _a, _b;
20
- return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
21
- /* @__PURE__ */ jsx(
22
- "span",
23
- {
24
- className: cx(
25
- "size-2 rounded-full bg-utility-gray-300",
26
- ((_b = entry.payload) == null ? void 0 : _b.className) ? entry.payload.className.replace("text-", "bg-") : void 0
27
- )
28
- }
29
- ),
30
- /* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-secondary", children: entry.value })
31
- ] }, `${(_a = entry.value) != null ? _a : "item"}-${index}`);
32
- }) });
33
- };
47
+ function sortCx(classes) {
48
+ return classes;
49
+ }
34
50
  var ChartTooltipContent = ({ active, payload, label, isRadialChart }) => {
35
51
  if (!active || !payload || payload.length === 0) {
36
52
  return null;
@@ -57,18 +73,8 @@ var ChartTooltipContent = ({ active, payload, label, isRadialChart }) => {
57
73
  };
58
74
  var radialData = [
59
75
  {
60
- name: "Series 3",
61
- value: 660,
62
- className: "text-utility-brand-400"
63
- },
64
- {
65
- name: "Series 2",
66
- value: 774,
67
- className: "text-utility-brand-600"
68
- },
69
- {
70
- name: "Series 1",
71
- value: 866,
76
+ name: "Tasks",
77
+ value: 1e3,
72
78
  className: "text-utility-brand-700"
73
79
  }
74
80
  ];
@@ -96,7 +102,6 @@ var ActivityGaugeLg = ({
96
102
  },
97
103
  children: [
98
104
  /* @__PURE__ */ jsx(PolarAngleAxis, { tick: false, domain: [0, maxValue], type: "number", reversed: true }),
99
- /* @__PURE__ */ jsx(Legend, { verticalAlign: "bottom", align: "center", layout: "horizontal", content: /* @__PURE__ */ jsx(ChartLegendContent, {}) }),
100
105
  /* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(ChartTooltipContent, { isRadialChart: true }) }),
101
106
  /* @__PURE__ */ jsx(
102
107
  RadialBar,
@@ -143,7 +148,7 @@ var getTasksCount = async (daysBack, options = {}) => {
143
148
  const resolvedDaysBack = Number.isFinite(daysBack) && daysBack > 0 ? Math.floor(daysBack) : 7;
144
149
  const baseUrl = (_b = (_a = options.baseUrl) != null ? _a : process.env.NEXT_PUBLIC_SQD_API_BASE_URL) != null ? _b : DEFAULT_API_BASE_URL;
145
150
  const moduleKey = (_d = (_c = options.moduleKey) != null ? _c : process.env.NEXT_PUBLIC_SQD_MODULE_KEY) != null ? _d : DEFAULT_MODULE_KEY;
146
- const url = new URL("/api/tasks/count", baseUrl);
151
+ const url = new URL("/module-template/task-count", baseUrl);
147
152
  url.searchParams.set("daysBack", String(resolvedDaysBack));
148
153
  const response = await fetch(url.toString(), {
149
154
  method: "GET",
@@ -160,15 +165,592 @@ var getTasksCount = async (daysBack, options = {}) => {
160
165
  const payload = await response.json();
161
166
  return (_e = payload.count) != null ? _e : 0;
162
167
  };
163
- var TasksActivityGauge = ({ daysBack = 7 }) => {
168
+
169
+ // src/utils/is-react-component.ts
170
+ var isFunctionComponent = (component) => {
171
+ return typeof component === "function";
172
+ };
173
+ var isClassComponent = (component) => {
174
+ return typeof component === "function" && component.prototype && (!!component.prototype.isReactComponent || !!component.prototype.render);
175
+ };
176
+ var isForwardRefComponent = (component) => {
177
+ return typeof component === "object" && component !== null && component.$$typeof.toString() === "Symbol(react.forward_ref)";
178
+ };
179
+ var isReactComponent = (component) => {
180
+ return isFunctionComponent(component) || isForwardRefComponent(component) || isClassComponent(component);
181
+ };
182
+ var styles = sortCx({
183
+ common: {
184
+ root: [
185
+ "group relative inline-flex h-max cursor-pointer items-center justify-center whitespace-nowrap outline-brand transition duration-100 ease-linear before:absolute focus-visible:outline-2 focus-visible:outline-offset-2",
186
+ // When button is used within `InputGroup`
187
+ "in-data-input-wrapper:shadow-xs in-data-input-wrapper:focus:!z-50 in-data-input-wrapper:in-data-leading:-mr-px in-data-input-wrapper:in-data-leading:rounded-r-none in-data-input-wrapper:in-data-leading:before:rounded-r-none in-data-input-wrapper:in-data-trailing:-ml-px in-data-input-wrapper:in-data-trailing:rounded-l-none in-data-input-wrapper:in-data-trailing:before:rounded-l-none",
188
+ // Disabled styles
189
+ "disabled:cursor-not-allowed disabled:text-fg-disabled",
190
+ // Icon styles
191
+ "disabled:*:data-icon:text-fg-disabled_subtle",
192
+ // Same as `icon` but for SSR icons that cannot be passed to the client as functions.
193
+ "*:data-icon:pointer-events-none *:data-icon:size-5 *:data-icon:shrink-0 *:data-icon:transition-inherit-all"
194
+ ].join(" "),
195
+ icon: "pointer-events-none size-5 shrink-0 transition-inherit-all"
196
+ },
197
+ sizes: {
198
+ sm: {
199
+ root: [
200
+ "gap-1 rounded-lg px-3 py-2 text-sm font-semibold before:rounded-[7px] data-icon-only:p-2",
201
+ "in-data-input-wrapper:px-3.5 in-data-input-wrapper:py-2.5 in-data-input-wrapper:data-icon-only:p-2.5"
202
+ ].join(" "),
203
+ linkRoot: "gap-1"
204
+ },
205
+ md: {
206
+ root: [
207
+ "gap-1 rounded-lg px-3.5 py-2.5 text-sm font-semibold before:rounded-[7px] data-icon-only:p-2.5",
208
+ "in-data-input-wrapper:gap-1.5 in-data-input-wrapper:px-4 in-data-input-wrapper:text-md in-data-input-wrapper:data-icon-only:p-3"
209
+ ].join(" "),
210
+ linkRoot: "gap-1"
211
+ },
212
+ lg: {
213
+ root: "gap-1.5 rounded-lg px-4 py-2.5 text-md font-semibold before:rounded-[7px] data-icon-only:p-3",
214
+ linkRoot: "gap-1.5"
215
+ },
216
+ xl: {
217
+ root: "gap-1.5 rounded-lg px-4.5 py-3 text-md font-semibold before:rounded-[7px] data-icon-only:p-3.5",
218
+ linkRoot: "gap-1.5"
219
+ }
220
+ },
221
+ colors: {
222
+ primary: {
223
+ root: [
224
+ "bg-brand-solid text-white shadow-xs-skeumorphic ring-1 ring-transparent ring-inset hover:bg-brand-solid_hover data-loading:bg-brand-solid_hover",
225
+ // Inner border gradient
226
+ "before:absolute before:inset-px before:border before:border-white/12 before:mask-b-from-0%",
227
+ // Disabled styles
228
+ "disabled:bg-disabled disabled:shadow-xs disabled:ring-disabled_subtle",
229
+ // Icon styles
230
+ "*:data-icon:text-button-primary-icon hover:*:data-icon:text-button-primary-icon_hover"
231
+ ].join(" ")
232
+ },
233
+ secondary: {
234
+ root: [
235
+ "bg-primary text-secondary shadow-xs-skeumorphic ring-1 ring-primary ring-inset hover:bg-primary_hover hover:text-secondary_hover data-loading:bg-primary_hover",
236
+ // Disabled styles
237
+ "disabled:shadow-xs disabled:ring-disabled_subtle",
238
+ // Icon styles
239
+ "*:data-icon:text-fg-quaternary hover:*:data-icon:text-fg-quaternary_hover"
240
+ ].join(" ")
241
+ },
242
+ tertiary: {
243
+ root: [
244
+ "text-tertiary hover:bg-primary_hover hover:text-tertiary_hover data-loading:bg-primary_hover",
245
+ // Icon styles
246
+ "*:data-icon:text-fg-quaternary hover:*:data-icon:text-fg-quaternary_hover"
247
+ ].join(" ")
248
+ },
249
+ "link-gray": {
250
+ root: [
251
+ "justify-normal rounded p-0! text-tertiary hover:text-tertiary_hover",
252
+ // Inner text underline
253
+ "*:data-text:underline *:data-text:decoration-transparent *:data-text:underline-offset-2 hover:*:data-text:decoration-current",
254
+ // Icon styles
255
+ "*:data-icon:text-fg-quaternary hover:*:data-icon:text-fg-quaternary_hover"
256
+ ].join(" ")
257
+ },
258
+ "link-color": {
259
+ root: [
260
+ "justify-normal rounded p-0! text-brand-secondary hover:text-brand-secondary_hover",
261
+ // Inner text underline
262
+ "*:data-text:underline *:data-text:decoration-transparent *:data-text:underline-offset-2 hover:*:data-text:decoration-current",
263
+ // Icon styles
264
+ "*:data-icon:text-fg-brand-secondary_alt hover:*:data-icon:text-fg-brand-secondary_hover"
265
+ ].join(" ")
266
+ },
267
+ "primary-destructive": {
268
+ root: [
269
+ "bg-error-solid text-white shadow-xs-skeumorphic ring-1 ring-transparent outline-error ring-inset hover:bg-error-solid_hover data-loading:bg-error-solid_hover",
270
+ // Inner border gradient
271
+ "before:absolute before:inset-px before:border before:border-white/12 before:mask-b-from-0%",
272
+ // Disabled styles
273
+ "disabled:bg-disabled disabled:shadow-xs disabled:ring-disabled_subtle",
274
+ // Icon styles
275
+ "*:data-icon:text-button-destructive-primary-icon hover:*:data-icon:text-button-destructive-primary-icon_hover"
276
+ ].join(" ")
277
+ },
278
+ "secondary-destructive": {
279
+ root: [
280
+ "bg-primary text-error-primary shadow-xs-skeumorphic ring-1 ring-error_subtle outline-error ring-inset hover:bg-error-primary hover:text-error-primary_hover data-loading:bg-error-primary",
281
+ // Disabled styles
282
+ "disabled:bg-primary disabled:shadow-xs disabled:ring-disabled_subtle",
283
+ // Icon styles
284
+ "*:data-icon:text-fg-error-secondary hover:*:data-icon:text-fg-error-primary"
285
+ ].join(" ")
286
+ },
287
+ "tertiary-destructive": {
288
+ root: [
289
+ "text-error-primary outline-error hover:bg-error-primary hover:text-error-primary_hover data-loading:bg-error-primary",
290
+ // Icon styles
291
+ "*:data-icon:text-fg-error-secondary hover:*:data-icon:text-fg-error-primary"
292
+ ].join(" ")
293
+ },
294
+ "link-destructive": {
295
+ root: [
296
+ "justify-normal rounded p-0! text-error-primary outline-error hover:text-error-primary_hover",
297
+ // Inner text underline
298
+ "*:data-text:underline *:data-text:decoration-transparent *:data-text:underline-offset-2 hover:*:data-text:decoration-current",
299
+ // Icon styles
300
+ "*:data-icon:text-fg-error-secondary hover:*:data-icon:text-fg-error-primary"
301
+ ].join(" ")
302
+ }
303
+ }
304
+ });
305
+ var Button = (_a) => {
306
+ var _b = _a, {
307
+ size = "sm",
308
+ color = "primary",
309
+ children,
310
+ className,
311
+ noTextPadding,
312
+ iconLeading: IconLeading,
313
+ iconTrailing: IconTrailing,
314
+ isDisabled: disabled,
315
+ isLoading: loading,
316
+ showTextWhileLoading
317
+ } = _b, otherProps = __objRest(_b, [
318
+ "size",
319
+ "color",
320
+ "children",
321
+ "className",
322
+ "noTextPadding",
323
+ "iconLeading",
324
+ "iconTrailing",
325
+ "isDisabled",
326
+ "isLoading",
327
+ "showTextWhileLoading"
328
+ ]);
329
+ const href = "href" in otherProps ? otherProps.href : void 0;
330
+ const Component = href ? Link : Button$1;
331
+ const isIcon = (IconLeading || IconTrailing) && !children;
332
+ const isLinkType = ["link-gray", "link-color", "link-destructive"].includes(color);
333
+ noTextPadding = isLinkType || noTextPadding;
334
+ let props = {};
335
+ if (href) {
336
+ props = __spreadProps(__spreadValues({}, otherProps), {
337
+ href: disabled ? void 0 : href
338
+ });
339
+ } else {
340
+ props = __spreadProps(__spreadValues({}, otherProps), {
341
+ type: otherProps.type || "button",
342
+ isPending: loading
343
+ });
344
+ }
345
+ return /* @__PURE__ */ jsxs(
346
+ Component,
347
+ __spreadProps(__spreadValues({
348
+ "data-loading": loading ? true : void 0,
349
+ "data-icon-only": isIcon ? true : void 0
350
+ }, props), {
351
+ isDisabled: disabled,
352
+ className: cx(
353
+ styles.common.root,
354
+ styles.sizes[size].root,
355
+ styles.colors[color].root,
356
+ isLinkType && styles.sizes[size].linkRoot,
357
+ (loading || href && (disabled || loading)) && "pointer-events-none",
358
+ // If in `loading` state, hide everything except the loading icon (and text if `showTextWhileLoading` is true).
359
+ loading && (showTextWhileLoading ? "[&>*:not([data-icon=loading]):not([data-text])]:hidden" : "[&>*:not([data-icon=loading])]:invisible"),
360
+ className
361
+ ),
362
+ children: [
363
+ isValidElement(IconLeading) && IconLeading,
364
+ isReactComponent(IconLeading) && /* @__PURE__ */ jsx(IconLeading, { "data-icon": "leading", className: styles.common.icon }),
365
+ loading && /* @__PURE__ */ jsxs(
366
+ "svg",
367
+ {
368
+ fill: "none",
369
+ "data-icon": "loading",
370
+ viewBox: "0 0 20 20",
371
+ className: cx(styles.common.icon, !showTextWhileLoading && "absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2"),
372
+ children: [
373
+ /* @__PURE__ */ jsx("circle", { className: "stroke-current opacity-30", cx: "10", cy: "10", r: "8", fill: "none", strokeWidth: "2" }),
374
+ /* @__PURE__ */ jsx(
375
+ "circle",
376
+ {
377
+ className: "origin-center animate-spin stroke-current",
378
+ cx: "10",
379
+ cy: "10",
380
+ r: "8",
381
+ fill: "none",
382
+ strokeWidth: "2",
383
+ strokeDasharray: "12.5 50",
384
+ strokeLinecap: "round"
385
+ }
386
+ )
387
+ ]
388
+ }
389
+ ),
390
+ children && /* @__PURE__ */ jsx("span", { "data-text": true, className: cx("transition-inherit-all", !noTextPadding && "px-0.5"), children }),
391
+ isValidElement(IconTrailing) && IconTrailing,
392
+ isReactComponent(IconTrailing) && /* @__PURE__ */ jsx(IconTrailing, { "data-icon": "trailing", className: styles.common.icon })
393
+ ]
394
+ })
395
+ );
396
+ };
397
+ var HintText = (_a) => {
398
+ var _b = _a, { isInvalid, className } = _b, props = __objRest(_b, ["isInvalid", "className"]);
399
+ return /* @__PURE__ */ jsx(
400
+ Text,
401
+ __spreadProps(__spreadValues({}, props), {
402
+ slot: isInvalid ? "errorMessage" : "description",
403
+ className: cx(
404
+ "text-sm text-tertiary",
405
+ // Invalid state
406
+ isInvalid && "text-error-primary",
407
+ "group-invalid:text-error-primary",
408
+ className
409
+ )
410
+ })
411
+ );
412
+ };
413
+ HintText.displayName = "HintText";
414
+ var Tooltip2 = (_a) => {
415
+ var _b = _a, {
416
+ title,
417
+ description,
418
+ children,
419
+ arrow = false,
420
+ delay = 300,
421
+ closeDelay = 0,
422
+ trigger,
423
+ isDisabled,
424
+ isOpen,
425
+ defaultOpen,
426
+ offset = 6,
427
+ crossOffset,
428
+ placement = "top",
429
+ onOpenChange
430
+ } = _b, tooltipProps = __objRest(_b, [
431
+ "title",
432
+ "description",
433
+ "children",
434
+ "arrow",
435
+ "delay",
436
+ "closeDelay",
437
+ "trigger",
438
+ "isDisabled",
439
+ "isOpen",
440
+ "defaultOpen",
441
+ "offset",
442
+ "crossOffset",
443
+ "placement",
444
+ "onOpenChange"
445
+ ]);
446
+ const isTopOrBottomLeft = ["top left", "top end", "bottom left", "bottom end"].includes(placement);
447
+ const isTopOrBottomRight = ["top right", "top start", "bottom right", "bottom start"].includes(placement);
448
+ const calculatedCrossOffset = isTopOrBottomLeft ? -12 : isTopOrBottomRight ? 12 : 0;
449
+ return /* @__PURE__ */ jsxs(TooltipTrigger$1, __spreadProps(__spreadValues({}, { trigger, delay, closeDelay, isDisabled, isOpen, defaultOpen, onOpenChange }), { children: [
450
+ children,
451
+ /* @__PURE__ */ jsx(
452
+ Tooltip$1,
453
+ __spreadProps(__spreadValues({}, tooltipProps), {
454
+ offset,
455
+ placement,
456
+ crossOffset: crossOffset != null ? crossOffset : calculatedCrossOffset,
457
+ className: ({ isEntering, isExiting }) => cx(isEntering && "ease-out animate-in", isExiting && "ease-in animate-out"),
458
+ children: ({ isEntering, isExiting }) => /* @__PURE__ */ jsxs(
459
+ "div",
460
+ {
461
+ className: cx(
462
+ "z-50 flex max-w-xs origin-(--trigger-anchor-point) flex-col items-start gap-1 rounded-lg bg-primary-solid px-3 shadow-lg will-change-transform",
463
+ description ? "py-3" : "py-2",
464
+ isEntering && "ease-out animate-in fade-in zoom-in-95 in-placement-left:slide-in-from-right-0.5 in-placement-right:slide-in-from-left-0.5 in-placement-top:slide-in-from-bottom-0.5 in-placement-bottom:slide-in-from-top-0.5",
465
+ isExiting && "ease-in animate-out fade-out zoom-out-95 in-placement-left:slide-out-to-right-0.5 in-placement-right:slide-out-to-left-0.5 in-placement-top:slide-out-to-bottom-0.5 in-placement-bottom:slide-out-to-top-0.5"
466
+ ),
467
+ children: [
468
+ /* @__PURE__ */ jsx("span", { className: "text-xs font-semibold text-white", children: title }),
469
+ description && /* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-tooltip-supporting-text", children: description }),
470
+ arrow && /* @__PURE__ */ jsx(OverlayArrow, { children: /* @__PURE__ */ jsx(
471
+ "svg",
472
+ {
473
+ viewBox: "0 0 100 100",
474
+ className: "size-2.5 fill-bg-primary-solid in-placement-left:-rotate-90 in-placement-right:rotate-90 in-placement-top:rotate-0 in-placement-bottom:rotate-180",
475
+ children: /* @__PURE__ */ jsx("path", { d: "M0,0 L35.858,35.858 Q50,50 64.142,35.858 L100,0 Z" })
476
+ }
477
+ ) })
478
+ ]
479
+ }
480
+ )
481
+ })
482
+ )
483
+ ] }));
484
+ };
485
+ var TooltipTrigger = (_a) => {
486
+ var _b = _a, { children, className } = _b, buttonProps = __objRest(_b, ["children", "className"]);
487
+ return /* @__PURE__ */ jsx(Button$1, __spreadProps(__spreadValues({}, buttonProps), { className: (values) => cx("h-max w-max outline-hidden", typeof className === "function" ? className(values) : className), children }));
488
+ };
489
+ var Label = (_a) => {
490
+ var _b = _a, { isRequired, tooltip, tooltipDescription, className } = _b, props = __objRest(_b, ["isRequired", "tooltip", "tooltipDescription", "className"]);
491
+ return /* @__PURE__ */ jsxs(
492
+ Label$1,
493
+ __spreadProps(__spreadValues({
494
+ "data-label": "true"
495
+ }, props), {
496
+ className: cx("flex cursor-default items-center gap-0.5 text-sm font-medium text-secondary", className),
497
+ children: [
498
+ props.children,
499
+ /* @__PURE__ */ jsx("span", { className: cx("hidden text-brand-tertiary", isRequired && "block", typeof isRequired === "undefined" && "group-required:block"), children: "*" }),
500
+ tooltip && /* @__PURE__ */ jsx(Tooltip2, { title: tooltip, description: tooltipDescription, placement: "top", children: /* @__PURE__ */ jsx(
501
+ TooltipTrigger,
502
+ {
503
+ isDisabled: false,
504
+ className: "cursor-pointer text-fg-quaternary transition duration-200 hover:text-fg-quaternary_hover focus:text-fg-quaternary_hover",
505
+ children: /* @__PURE__ */ jsx(HelpCircle, { className: "size-4" })
506
+ }
507
+ ) })
508
+ ]
509
+ })
510
+ );
511
+ };
512
+ Label.displayName = "Label";
513
+ var InputBase = (_a) => {
514
+ var _b = _a, {
515
+ ref,
516
+ tooltip,
517
+ shortcut,
518
+ groupRef,
519
+ size = "sm",
520
+ isInvalid,
521
+ isDisabled,
522
+ icon: Icon,
523
+ placeholder,
524
+ wrapperClassName,
525
+ tooltipClassName,
526
+ inputClassName,
527
+ iconClassName,
528
+ isRequired: _isRequired
529
+ } = _b, inputProps = __objRest(_b, [
530
+ "ref",
531
+ "tooltip",
532
+ "shortcut",
533
+ "groupRef",
534
+ "size",
535
+ "isInvalid",
536
+ "isDisabled",
537
+ "icon",
538
+ "placeholder",
539
+ "wrapperClassName",
540
+ "tooltipClassName",
541
+ "inputClassName",
542
+ "iconClassName",
543
+ // Omit this prop to avoid invalid HTML attribute warning
544
+ "isRequired"
545
+ ]);
546
+ const hasTrailingIcon = tooltip || isInvalid;
547
+ const hasLeadingIcon = Icon;
548
+ const context = useContext(TextFieldContext);
549
+ const inputSize = (context == null ? void 0 : context.size) || size;
550
+ const sizes = sortCx({
551
+ sm: {
552
+ root: cx("px-3 py-2", hasTrailingIcon && "pr-9", hasLeadingIcon && "pl-10"),
553
+ iconLeading: "left-3",
554
+ iconTrailing: "right-3",
555
+ shortcut: "pr-2.5"
556
+ },
557
+ md: {
558
+ root: cx("px-3.5 py-2.5", hasTrailingIcon && "pr-9.5", hasLeadingIcon && "pl-10.5"),
559
+ iconLeading: "left-3.5",
560
+ iconTrailing: "right-3.5",
561
+ shortcut: "pr-3"
562
+ }
563
+ });
564
+ return /* @__PURE__ */ jsxs(
565
+ Group,
566
+ __spreadProps(__spreadValues({}, { isDisabled, isInvalid }), {
567
+ ref: groupRef,
568
+ className: ({ isFocusWithin, isDisabled: isDisabled2, isInvalid: isInvalid2 }) => cx(
569
+ "relative flex w-full flex-row place-content-center place-items-center rounded-lg bg-primary shadow-xs ring-1 ring-primary transition-shadow duration-100 ease-linear ring-inset",
570
+ isFocusWithin && !isDisabled2 && "ring-2 ring-brand",
571
+ // Disabled state styles
572
+ isDisabled2 && "cursor-not-allowed bg-disabled_subtle ring-disabled",
573
+ "group-disabled:cursor-not-allowed group-disabled:bg-disabled_subtle group-disabled:ring-disabled",
574
+ // Invalid state styles
575
+ isInvalid2 && "ring-error_subtle",
576
+ "group-invalid:ring-error_subtle",
577
+ // Invalid state with focus-within styles
578
+ isInvalid2 && isFocusWithin && "ring-2 ring-error",
579
+ isFocusWithin && "group-invalid:ring-2 group-invalid:ring-error",
580
+ context == null ? void 0 : context.wrapperClassName,
581
+ wrapperClassName
582
+ ),
583
+ children: [
584
+ Icon && /* @__PURE__ */ jsx(
585
+ Icon,
586
+ {
587
+ className: cx(
588
+ "pointer-events-none absolute size-5 text-fg-quaternary",
589
+ isDisabled && "text-fg-disabled",
590
+ sizes[inputSize].iconLeading,
591
+ context == null ? void 0 : context.iconClassName,
592
+ iconClassName
593
+ )
594
+ }
595
+ ),
596
+ /* @__PURE__ */ jsx(
597
+ Input$1,
598
+ __spreadProps(__spreadValues({}, inputProps), {
599
+ ref,
600
+ placeholder,
601
+ className: cx(
602
+ "m-0 w-full bg-transparent text-md text-primary ring-0 outline-hidden placeholder:text-placeholder autofill:rounded-lg autofill:text-primary",
603
+ isDisabled && "cursor-not-allowed text-disabled",
604
+ sizes[inputSize].root,
605
+ context == null ? void 0 : context.inputClassName,
606
+ inputClassName
607
+ )
608
+ })
609
+ ),
610
+ tooltip && !isInvalid && /* @__PURE__ */ jsx(Tooltip2, { title: tooltip, placement: "top", children: /* @__PURE__ */ jsx(
611
+ TooltipTrigger,
612
+ {
613
+ className: cx(
614
+ "absolute cursor-pointer text-fg-quaternary transition duration-200 hover:text-fg-quaternary_hover focus:text-fg-quaternary_hover",
615
+ sizes[inputSize].iconTrailing,
616
+ context == null ? void 0 : context.tooltipClassName,
617
+ tooltipClassName
618
+ ),
619
+ children: /* @__PURE__ */ jsx(HelpCircle, { className: "size-4" })
620
+ }
621
+ ) }),
622
+ isInvalid && /* @__PURE__ */ jsx(
623
+ InfoCircle,
624
+ {
625
+ className: cx(
626
+ "pointer-events-none absolute size-4 text-fg-error-secondary",
627
+ sizes[inputSize].iconTrailing,
628
+ context == null ? void 0 : context.tooltipClassName,
629
+ tooltipClassName
630
+ )
631
+ }
632
+ ),
633
+ shortcut && /* @__PURE__ */ jsx(
634
+ "div",
635
+ {
636
+ className: cx(
637
+ "pointer-events-none absolute inset-y-0.5 right-0.5 z-10 flex items-center rounded-r-[inherit] bg-linear-to-r from-transparent to-bg-primary to-40% pl-8",
638
+ sizes[inputSize].shortcut
639
+ ),
640
+ children: /* @__PURE__ */ jsx(
641
+ "span",
642
+ {
643
+ className: cx(
644
+ "pointer-events-none rounded px-1 py-px text-xs font-medium text-quaternary ring-1 ring-secondary select-none ring-inset",
645
+ isDisabled && "bg-transparent text-disabled"
646
+ ),
647
+ "aria-hidden": "true",
648
+ children: typeof shortcut === "string" ? shortcut : "\u2318K"
649
+ }
650
+ )
651
+ }
652
+ )
653
+ ]
654
+ })
655
+ );
656
+ };
657
+ InputBase.displayName = "InputBase";
658
+ var TextFieldContext = createContext({});
659
+ var TextField = (_a) => {
660
+ var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
661
+ return /* @__PURE__ */ jsx(TextFieldContext.Provider, { value: props, children: /* @__PURE__ */ jsx(
662
+ TextField$1,
663
+ __spreadProps(__spreadValues({}, props), {
664
+ "data-input-wrapper": true,
665
+ className: (state) => cx("group flex h-max w-full flex-col items-start justify-start gap-1.5", typeof className === "function" ? className(state) : className)
666
+ })
667
+ ) });
668
+ };
669
+ TextField.displayName = "TextField";
670
+ var Input = (_a) => {
671
+ var _b = _a, {
672
+ size = "sm",
673
+ placeholder,
674
+ icon: Icon,
675
+ label,
676
+ hint,
677
+ shortcut,
678
+ hideRequiredIndicator,
679
+ className,
680
+ ref,
681
+ groupRef,
682
+ tooltip,
683
+ iconClassName,
684
+ inputClassName,
685
+ wrapperClassName,
686
+ tooltipClassName
687
+ } = _b, props = __objRest(_b, [
688
+ "size",
689
+ "placeholder",
690
+ "icon",
691
+ "label",
692
+ "hint",
693
+ "shortcut",
694
+ "hideRequiredIndicator",
695
+ "className",
696
+ "ref",
697
+ "groupRef",
698
+ "tooltip",
699
+ "iconClassName",
700
+ "inputClassName",
701
+ "wrapperClassName",
702
+ "tooltipClassName"
703
+ ]);
704
+ return /* @__PURE__ */ jsx(TextField, __spreadProps(__spreadValues({ "aria-label": !label ? placeholder : void 0 }, props), { className, children: ({ isRequired, isInvalid }) => /* @__PURE__ */ jsxs(Fragment, { children: [
705
+ label && /* @__PURE__ */ jsx(Label, { isRequired: hideRequiredIndicator ? !hideRequiredIndicator : isRequired, children: label }),
706
+ /* @__PURE__ */ jsx(
707
+ InputBase,
708
+ __spreadValues({}, {
709
+ ref,
710
+ groupRef,
711
+ size,
712
+ placeholder,
713
+ icon: Icon,
714
+ shortcut,
715
+ iconClassName,
716
+ inputClassName,
717
+ wrapperClassName,
718
+ tooltipClassName,
719
+ tooltip
720
+ })
721
+ ),
722
+ hint && /* @__PURE__ */ jsx(HintText, { isInvalid, children: hint })
723
+ ] }) }));
724
+ };
725
+ Input.displayName = "Input";
726
+ var TasksActivityGauge = ({ daysBack = 14, maxValue = 1e3 }) => {
164
727
  const [count, setCount] = useState(null);
165
728
  const [error, setError] = useState(null);
166
- const subtitle = useMemo(() => `Tasks last ${daysBack} days`, [daysBack]);
729
+ const [isLoading, setIsLoading] = useState(false);
730
+ const [daysBackValue, setDaysBackValue] = useState(daysBack.toString());
731
+ const [activeDaysBack, setActiveDaysBack] = useState(daysBack);
732
+ const subtitle = useMemo(() => `Tasks last ${activeDaysBack} days`, [activeDaysBack]);
733
+ const fetchCount = useCallback(
734
+ async (value) => {
735
+ setIsLoading(true);
736
+ setError(null);
737
+ try {
738
+ const total = await getTasksCount(value);
739
+ setCount(total);
740
+ } catch (err) {
741
+ setError(err instanceof Error ? err.message : "Failed to load tasks count");
742
+ } finally {
743
+ setIsLoading(false);
744
+ }
745
+ },
746
+ []
747
+ );
167
748
  useEffect(() => {
168
749
  let isActive = true;
750
+ setIsLoading(true);
169
751
  setError(null);
170
752
  setCount(null);
171
- getTasksCount(daysBack).then((total) => {
753
+ getTasksCount(activeDaysBack).then((total) => {
172
754
  if (isActive) {
173
755
  setCount(total);
174
756
  }
@@ -176,13 +758,59 @@ var TasksActivityGauge = ({ daysBack = 7 }) => {
176
758
  if (isActive) {
177
759
  setError(err instanceof Error ? err.message : "Failed to load tasks count");
178
760
  }
761
+ }).finally(() => {
762
+ if (isActive) {
763
+ setIsLoading(false);
764
+ }
179
765
  });
180
766
  return () => {
181
767
  isActive = false;
182
768
  };
183
- }, [daysBack]);
769
+ }, [activeDaysBack]);
184
770
  const title = error ? "\u2014" : count === null ? "\u2026" : count.toLocaleString();
185
- return /* @__PURE__ */ jsx(ActivityGaugeLg, { title, subtitle });
771
+ const gaugeValue = count != null ? count : 0;
772
+ const computedMax = Math.max(maxValue, gaugeValue, 1);
773
+ const gaugeData = [
774
+ {
775
+ name: "Tasks",
776
+ value: gaugeValue,
777
+ className: "text-utility-brand-700"
778
+ }
779
+ ];
780
+ const handleDaysBackChange = (value) => {
781
+ setDaysBackValue(value);
782
+ const parsed = Number(value);
783
+ if (Number.isFinite(parsed) && parsed > 0) {
784
+ setActiveDaysBack(Math.floor(parsed));
785
+ }
786
+ };
787
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
788
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-end justify-between gap-3", children: [
789
+ /* @__PURE__ */ jsx("div", { className: "min-w-[180px]", children: /* @__PURE__ */ jsx(
790
+ Input,
791
+ {
792
+ label: "Days back",
793
+ type: "number",
794
+ value: daysBackValue,
795
+ onChange: handleDaysBackChange,
796
+ size: "sm",
797
+ placeholder: "14"
798
+ }
799
+ ) }),
800
+ /* @__PURE__ */ jsx(
801
+ Button,
802
+ {
803
+ color: "primary",
804
+ size: "sm",
805
+ isLoading,
806
+ showTextWhileLoading: true,
807
+ onClick: () => fetchCount(activeDaysBack),
808
+ children: "Refresh"
809
+ }
810
+ )
811
+ ] }),
812
+ /* @__PURE__ */ jsx(ActivityGaugeLg, { title, subtitle, data: gaugeData, maxValue: computedMax })
813
+ ] });
186
814
  };
187
815
 
188
816
  export { ActivityGaugeLg, TasksActivityGauge, getTasksCount };