@thesquad-components/sqd-module-template 0.1.3 → 0.1.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.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
 
3
+ declare const HomeScreen: () => react_jsx_runtime.JSX.Element;
4
+
3
5
  type ActivityGaugeDatum = {
4
6
  name: string;
5
7
  value: number;
@@ -31,4 +33,4 @@ type GetTasksCountOptions = {
31
33
  };
32
34
  declare const getTasksCount: (daysBack: number, options?: GetTasksCountOptions) => Promise<number>;
33
35
 
34
- export { type ActivityGaugeDatum, ActivityGaugeLg, type ActivityGaugeProps, TasksActivityGauge, type TasksActivityGaugeProps, type TasksCountResponse, getTasksCount };
36
+ export { type ActivityGaugeDatum, ActivityGaugeLg, type ActivityGaugeProps, TasksActivityGauge, type TasksActivityGaugeProps, type TasksCountResponse, HomeScreen as default, getTasksCount };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
 
3
+ declare const HomeScreen: () => react_jsx_runtime.JSX.Element;
4
+
3
5
  type ActivityGaugeDatum = {
4
6
  name: string;
5
7
  value: number;
@@ -31,4 +33,4 @@ type GetTasksCountOptions = {
31
33
  };
32
34
  declare const getTasksCount: (daysBack: number, options?: GetTasksCountOptions) => Promise<number>;
33
35
 
34
- export { type ActivityGaugeDatum, ActivityGaugeLg, type ActivityGaugeProps, TasksActivityGauge, type TasksActivityGaugeProps, type TasksCountResponse, getTasksCount };
36
+ export { type ActivityGaugeDatum, ActivityGaugeLg, type ActivityGaugeProps, TasksActivityGauge, type TasksActivityGaugeProps, type TasksCountResponse, HomeScreen as default, getTasksCount };
package/dist/index.js CHANGED
@@ -1,11 +1,14 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+ var nextThemes = require('next-themes');
7
+ var icons = require('@untitledui/icons');
3
8
  var recharts = require('recharts');
4
9
  var tailwindMerge = require('tailwind-merge');
5
10
  var jsxRuntime = require('react/jsx-runtime');
6
- var react = require('react');
7
11
  var reactAriaComponents = require('react-aria-components');
8
- var icons = require('@untitledui/icons');
9
12
 
10
13
  var __defProp = Object.defineProperty;
11
14
  var __defProps = Object.defineProperties;
@@ -38,6 +41,32 @@ var __objRest = (source, exclude) => {
38
41
  }
39
42
  return target;
40
43
  };
44
+
45
+ // src/api/tasks.ts
46
+ var DEFAULT_API_BASE_URL = "https://api.thesqd.com";
47
+ var DEFAULT_MODULE_KEY = "e166f127e73167b6646eeaeff8837566d3c27d4002fb122bc49d4fb06d97d67e";
48
+ var getTasksCount = async (daysBack, options = {}) => {
49
+ var _a, _b, _c, _d, _e;
50
+ const resolvedDaysBack = Number.isFinite(daysBack) && daysBack > 0 ? Math.floor(daysBack) : 7;
51
+ const baseUrl = (_b = (_a = options.baseUrl) != null ? _a : process.env.NEXT_PUBLIC_SQD_API_BASE_URL) != null ? _b : DEFAULT_API_BASE_URL;
52
+ const moduleKey = (_d = (_c = options.moduleKey) != null ? _c : process.env.NEXT_PUBLIC_SQD_MODULE_KEY) != null ? _d : DEFAULT_MODULE_KEY;
53
+ const url = new URL("/module-template/task-count", baseUrl);
54
+ url.searchParams.set("daysBack", String(resolvedDaysBack));
55
+ const response = await fetch(url.toString(), {
56
+ method: "GET",
57
+ headers: {
58
+ "Content-Type": "application/json",
59
+ "x-sqd-module-key": moduleKey
60
+ },
61
+ cache: "no-store",
62
+ signal: options.signal
63
+ });
64
+ if (!response.ok) {
65
+ throw new Error(`Failed to fetch tasks count (${response.status})`);
66
+ }
67
+ const payload = await response.json();
68
+ return (_e = payload.count) != null ? _e : 0;
69
+ };
41
70
  var twMerge = tailwindMerge.extendTailwindMerge({
42
71
  extend: {
43
72
  theme: {
@@ -53,8 +82,9 @@ var ChartTooltipContent = ({ active, payload, label, isRadialChart }) => {
53
82
  if (!active || !payload || payload.length === 0) {
54
83
  return null;
55
84
  }
85
+ const showLabel = Boolean(label) && !isRadialChart;
56
86
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-lg border border-secondary bg-primary px-3 py-2 shadow-sm", children: [
57
- label && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs font-medium text-tertiary", children: label }),
87
+ showLabel && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs font-medium text-tertiary", children: label }),
58
88
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-1 space-y-1", children: payload.map((entry, index) => {
59
89
  var _a, _b, _c;
60
90
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-xs", children: [
@@ -145,32 +175,6 @@ var ActivityGaugeLg = ({
145
175
  ) });
146
176
  };
147
177
 
148
- // src/api/tasks.ts
149
- var DEFAULT_API_BASE_URL = "https://api.thesqd.com";
150
- var DEFAULT_MODULE_KEY = "e166f127e73167b6646eeaeff8837566d3c27d4002fb122bc49d4fb06d97d67e";
151
- var getTasksCount = async (daysBack, options = {}) => {
152
- var _a, _b, _c, _d, _e;
153
- const resolvedDaysBack = Number.isFinite(daysBack) && daysBack > 0 ? Math.floor(daysBack) : 7;
154
- const baseUrl = (_b = (_a = options.baseUrl) != null ? _a : process.env.NEXT_PUBLIC_SQD_API_BASE_URL) != null ? _b : DEFAULT_API_BASE_URL;
155
- const moduleKey = (_d = (_c = options.moduleKey) != null ? _c : process.env.NEXT_PUBLIC_SQD_MODULE_KEY) != null ? _d : DEFAULT_MODULE_KEY;
156
- const url = new URL("/module-template/task-count", baseUrl);
157
- url.searchParams.set("daysBack", String(resolvedDaysBack));
158
- const response = await fetch(url.toString(), {
159
- method: "GET",
160
- headers: {
161
- "Content-Type": "application/json",
162
- "x-sqd-module-key": moduleKey
163
- },
164
- cache: "no-store",
165
- signal: options.signal
166
- });
167
- if (!response.ok) {
168
- throw new Error(`Failed to fetch tasks count (${response.status})`);
169
- }
170
- const payload = await response.json();
171
- return (_e = payload.count) != null ? _e : 0;
172
- };
173
-
174
178
  // src/utils/is-react-component.ts
175
179
  var isFunctionComponent = (component) => {
176
180
  return typeof component === "function";
@@ -399,6 +403,110 @@ var Button = (_a) => {
399
403
  })
400
404
  );
401
405
  };
406
+ var ToggleBase = ({ className, isHovered, isDisabled, isFocusVisible, isSelected, slim, size = "sm" }) => {
407
+ const styles2 = {
408
+ default: {
409
+ sm: {
410
+ root: "h-5 w-9 p-0.5",
411
+ switch: cx("size-4", isSelected && "translate-x-4")
412
+ },
413
+ md: {
414
+ root: "h-6 w-11 p-0.5",
415
+ switch: cx("size-5", isSelected && "translate-x-5")
416
+ }
417
+ },
418
+ slim: {
419
+ sm: {
420
+ root: "h-4 w-8",
421
+ switch: cx("size-4", isSelected && "translate-x-4")
422
+ },
423
+ md: {
424
+ root: "h-5 w-10",
425
+ switch: cx("size-5", isSelected && "translate-x-5")
426
+ }
427
+ }
428
+ };
429
+ const classes = slim ? styles2.slim[size] : styles2.default[size];
430
+ return /* @__PURE__ */ jsxRuntime.jsx(
431
+ "div",
432
+ {
433
+ className: cx(
434
+ "cursor-pointer rounded-full bg-tertiary outline-focus-ring transition duration-150 ease-linear",
435
+ isSelected && "bg-brand-solid",
436
+ isSelected && isHovered && "bg-brand-solid_hover",
437
+ isDisabled && "cursor-not-allowed bg-disabled",
438
+ isFocusVisible && "outline-2 outline-offset-2",
439
+ slim && "ring-1 ring-secondary ring-inset",
440
+ slim && isSelected && "ring-transparent",
441
+ classes.root,
442
+ className
443
+ ),
444
+ children: /* @__PURE__ */ jsxRuntime.jsx(
445
+ "div",
446
+ {
447
+ style: {
448
+ transition: "transform 0.15s ease-in-out, translate 0.15s ease-in-out, border-color 0.1s linear, background-color 0.1s linear"
449
+ },
450
+ className: cx(
451
+ "rounded-full bg-fg-white shadow-sm",
452
+ isDisabled && "bg-toggle-button-fg_disabled",
453
+ slim && "shadow-xs",
454
+ slim && "border border-toggle-border",
455
+ slim && isSelected && "border-toggle-slim-border_pressed",
456
+ slim && isSelected && isHovered && "border-toggle-slim-border_pressed-hover",
457
+ classes.switch
458
+ )
459
+ }
460
+ )
461
+ }
462
+ );
463
+ };
464
+ var Toggle = (_a) => {
465
+ var _b = _a, { label, hint, className, size = "sm", slim } = _b, ariaSwitchProps = __objRest(_b, ["label", "hint", "className", "size", "slim"]);
466
+ const sizes = {
467
+ sm: {
468
+ root: "gap-2",
469
+ textWrapper: "",
470
+ label: "text-sm font-medium",
471
+ hint: "text-sm"
472
+ },
473
+ md: {
474
+ root: "gap-3",
475
+ textWrapper: "gap-0.5",
476
+ label: "text-md font-medium",
477
+ hint: "text-md"
478
+ }
479
+ };
480
+ return /* @__PURE__ */ jsxRuntime.jsx(
481
+ reactAriaComponents.Switch,
482
+ __spreadProps(__spreadValues({}, ariaSwitchProps), {
483
+ className: (renderProps) => cx(
484
+ "flex w-max items-start",
485
+ renderProps.isDisabled && "cursor-not-allowed",
486
+ sizes[size].root,
487
+ typeof className === "function" ? className(renderProps) : className
488
+ ),
489
+ children: ({ isSelected, isDisabled, isFocusVisible, isHovered }) => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
490
+ /* @__PURE__ */ jsxRuntime.jsx(
491
+ ToggleBase,
492
+ {
493
+ slim,
494
+ size,
495
+ isHovered,
496
+ isDisabled,
497
+ isFocusVisible,
498
+ isSelected,
499
+ className: slim ? "mt-0.5" : ""
500
+ }
501
+ ),
502
+ (label || hint) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cx("flex flex-col", sizes[size].textWrapper), children: [
503
+ label && /* @__PURE__ */ jsxRuntime.jsx("p", { className: cx("text-secondary select-none", sizes[size].label), children: label }),
504
+ hint && /* @__PURE__ */ jsxRuntime.jsx("span", { className: cx("text-tertiary", sizes[size].hint), onClick: (event) => event.stopPropagation(), children: hint })
505
+ ] })
506
+ ] })
507
+ })
508
+ );
509
+ };
402
510
  var HintText = (_a) => {
403
511
  var _b = _a, { isInvalid, className } = _b, props = __objRest(_b, ["isInvalid", "className"]);
404
512
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -729,6 +837,7 @@ var Input = (_a) => {
729
837
  };
730
838
  Input.displayName = "Input";
731
839
  var TasksActivityGauge = ({ daysBack = 14, maxValue = 1e3 }) => {
840
+ const { resolvedTheme, setTheme } = nextThemes.useTheme();
732
841
  const [count, setCount] = react.useState(null);
733
842
  const [error, setError] = react.useState(null);
734
843
  const [isLoading, setIsLoading] = react.useState(false);
@@ -789,6 +898,7 @@ var TasksActivityGauge = ({ daysBack = 14, maxValue = 1e3 }) => {
789
898
  setActiveDaysBack(Math.floor(parsed));
790
899
  }
791
900
  };
901
+ const isDarkMode = resolvedTheme === "dark";
792
902
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
793
903
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap items-end justify-between gap-3", children: [
794
904
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-w-[180px]", children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -814,12 +924,29 @@ var TasksActivityGauge = ({ daysBack = 14, maxValue = 1e3 }) => {
814
924
  }
815
925
  )
816
926
  ] }),
817
- /* @__PURE__ */ jsxRuntime.jsx(ActivityGaugeLg, { title, subtitle, data: gaugeData, maxValue: computedMax })
927
+ /* @__PURE__ */ jsxRuntime.jsx(ActivityGaugeLg, { title, subtitle, data: gaugeData, maxValue: computedMax }),
928
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "fixed bottom-4 right-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 rounded-full border border-secondary bg-primary px-3 py-2 shadow-lg", children: [
929
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Sun, { className: "size-4 text-tertiary" }),
930
+ /* @__PURE__ */ jsxRuntime.jsx(
931
+ Toggle,
932
+ {
933
+ size: "md",
934
+ "aria-label": "Toggle theme",
935
+ isSelected: isDarkMode,
936
+ onChange: (value) => setTheme(value ? "dark" : "light")
937
+ }
938
+ ),
939
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Moon01, { className: "size-4 text-tertiary" })
940
+ ] }) })
818
941
  ] });
819
942
  };
943
+ var HomeScreen = () => {
944
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-dvh items-center justify-center px-4", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full max-w-md", children: /* @__PURE__ */ jsxRuntime.jsx(TasksActivityGauge, { daysBack: 7 }) }) });
945
+ };
820
946
 
821
947
  exports.ActivityGaugeLg = ActivityGaugeLg;
822
948
  exports.TasksActivityGauge = TasksActivityGauge;
949
+ exports.default = HomeScreen;
823
950
  exports.getTasksCount = getTasksCount;
824
951
  //# sourceMappingURL=index.js.map
825
952
  //# sourceMappingURL=index.js.map