@processdynamics/components 0.1.6 → 0.1.8
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/README.md +1 -0
- package/dist/index.cjs +240 -3
- package/dist/index.d.cts +99 -3
- package/dist/index.d.ts +99 -3
- package/dist/index.js +235 -2
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -200,6 +200,7 @@ The packages the components import are declared as `peerDependencies` in `packag
|
|
|
200
200
|
- `lucide-react` for icons
|
|
201
201
|
- `class-variance-authority` for button variants
|
|
202
202
|
- `cn` for class merging
|
|
203
|
+
- `sonner` for the toaster
|
|
203
204
|
|
|
204
205
|
They are also dev dependencies here so Storybook and the tests can run.
|
|
205
206
|
|
package/dist/index.cjs
CHANGED
|
@@ -33,7 +33,11 @@ var index_exports = {};
|
|
|
33
33
|
__export(index_exports, {
|
|
34
34
|
DatePicker: () => DatePicker,
|
|
35
35
|
DebouncedInput: () => DebouncedInput,
|
|
36
|
-
JobCard: () => JobCard
|
|
36
|
+
JobCard: () => JobCard,
|
|
37
|
+
PullToRefreshArea: () => PullToRefreshArea,
|
|
38
|
+
Toaster: () => Toaster2,
|
|
39
|
+
toast: () => import_sonner2.toast,
|
|
40
|
+
toastColors: () => toastColors
|
|
37
41
|
});
|
|
38
42
|
module.exports = __toCommonJS(index_exports);
|
|
39
43
|
|
|
@@ -427,7 +431,7 @@ var DatePicker = ({
|
|
|
427
431
|
// src/components/debounceInput/DebouncedInput.tsx
|
|
428
432
|
var import_react2 = require("react");
|
|
429
433
|
|
|
430
|
-
// src/
|
|
434
|
+
// src/components/debounceInput/debounce.ts
|
|
431
435
|
function debounce(fn, delayMs) {
|
|
432
436
|
let timeout = null;
|
|
433
437
|
let latestArgs = null;
|
|
@@ -702,9 +706,242 @@ var JobCard = ({
|
|
|
702
706
|
}
|
|
703
707
|
);
|
|
704
708
|
};
|
|
709
|
+
|
|
710
|
+
// src/components/toaster/Toaster.tsx
|
|
711
|
+
var import_sonner2 = require("sonner");
|
|
712
|
+
|
|
713
|
+
// src/components/ui/sonner.tsx
|
|
714
|
+
var import_sonner = require("sonner");
|
|
715
|
+
var import_lucide_react3 = require("lucide-react");
|
|
716
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
717
|
+
var Toaster = ({ icons, ...props }) => {
|
|
718
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
719
|
+
import_sonner.Toaster,
|
|
720
|
+
{
|
|
721
|
+
className: "toaster group",
|
|
722
|
+
icons: {
|
|
723
|
+
success: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react3.CircleCheckIcon, { className: "size-4" }),
|
|
724
|
+
info: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react3.InfoIcon, { className: "size-4" }),
|
|
725
|
+
warning: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react3.TriangleAlertIcon, { className: "size-4" }),
|
|
726
|
+
error: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react3.OctagonXIcon, { className: "size-4" }),
|
|
727
|
+
loading: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_lucide_react3.Loader2Icon, { className: "size-4 animate-spin" }),
|
|
728
|
+
...icons
|
|
729
|
+
},
|
|
730
|
+
style: {
|
|
731
|
+
"--normal-bg": "var(--popover)",
|
|
732
|
+
"--normal-text": "var(--popover-foreground)",
|
|
733
|
+
"--normal-border": "var(--border)",
|
|
734
|
+
"--border-radius": "var(--radius)"
|
|
735
|
+
},
|
|
736
|
+
toastOptions: {
|
|
737
|
+
classNames: {
|
|
738
|
+
toast: "cn-toast"
|
|
739
|
+
}
|
|
740
|
+
},
|
|
741
|
+
...props
|
|
742
|
+
}
|
|
743
|
+
);
|
|
744
|
+
};
|
|
745
|
+
|
|
746
|
+
// src/components/toaster/Toaster.tsx
|
|
747
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
748
|
+
function toastColors({
|
|
749
|
+
background,
|
|
750
|
+
text,
|
|
751
|
+
border
|
|
752
|
+
}) {
|
|
753
|
+
return {
|
|
754
|
+
...background && { "--normal-bg": background },
|
|
755
|
+
...text && { "--normal-text": text },
|
|
756
|
+
...border && { "--normal-border": border }
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
function Toaster2({ position = "top-center", ...props }) {
|
|
760
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Toaster, { position, ...props });
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// src/components/pullToRefreshArea/PullToRefreshArea.tsx
|
|
764
|
+
var import_react4 = require("react");
|
|
765
|
+
|
|
766
|
+
// src/components/pullToRefreshArea/usePullToRefresh.ts
|
|
767
|
+
var import_react3 = require("react");
|
|
768
|
+
|
|
769
|
+
// src/components/pullToRefreshArea/pullToRefresh.ts
|
|
770
|
+
var DEAD_ZONE_PX = 8;
|
|
771
|
+
var RESISTANCE = 0.5;
|
|
772
|
+
var MAX_PULL_PX = 120;
|
|
773
|
+
var REFRESH_THRESHOLD_PX = 64;
|
|
774
|
+
var REFRESHING_HEIGHT_PX = 48;
|
|
775
|
+
function getPullDistance(fingerDeltaY) {
|
|
776
|
+
if (fingerDeltaY <= DEAD_ZONE_PX) return 0;
|
|
777
|
+
return Math.min((fingerDeltaY - DEAD_ZONE_PX) * RESISTANCE, MAX_PULL_PX);
|
|
778
|
+
}
|
|
779
|
+
function isPastThreshold(pullDistance) {
|
|
780
|
+
return pullDistance >= REFRESH_THRESHOLD_PX;
|
|
781
|
+
}
|
|
782
|
+
var IGNORED_SELECTOR = "input, textarea, select, [contenteditable='true'], [data-no-pull-refresh]";
|
|
783
|
+
function isScrolledVertically(element) {
|
|
784
|
+
const { overflowY } = getComputedStyle(element);
|
|
785
|
+
const canScroll = overflowY === "auto" || overflowY === "scroll";
|
|
786
|
+
return canScroll && element.scrollHeight > element.clientHeight && element.scrollTop > 0;
|
|
787
|
+
}
|
|
788
|
+
function shouldIgnoreTouchTarget(target, container) {
|
|
789
|
+
for (let element = target; element && element !== container; element = element.parentElement) {
|
|
790
|
+
if (element.matches(IGNORED_SELECTOR)) return true;
|
|
791
|
+
if (element instanceof HTMLElement && isScrolledVertically(element)) return true;
|
|
792
|
+
}
|
|
793
|
+
return false;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
// src/components/pullToRefreshArea/usePullToRefresh.ts
|
|
797
|
+
var RELOAD_MESSAGE_DELAY_MS = 700;
|
|
798
|
+
var MIN_REFRESH_DISPLAY_MS = 500;
|
|
799
|
+
function wait(milliseconds) {
|
|
800
|
+
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
801
|
+
}
|
|
802
|
+
function usePullToRefresh({ containerRef, isEnabled, onRefresh, onReload }) {
|
|
803
|
+
const [pullDistance, setPullDistance] = (0, import_react3.useState)(0);
|
|
804
|
+
const [phase, setPhase] = (0, import_react3.useState)("idle");
|
|
805
|
+
const onRefreshRef = (0, import_react3.useRef)(onRefresh);
|
|
806
|
+
const onReloadRef = (0, import_react3.useRef)(onReload);
|
|
807
|
+
(0, import_react3.useEffect)(() => {
|
|
808
|
+
onRefreshRef.current = onRefresh;
|
|
809
|
+
onReloadRef.current = onReload;
|
|
810
|
+
});
|
|
811
|
+
(0, import_react3.useEffect)(() => {
|
|
812
|
+
const container = containerRef.current;
|
|
813
|
+
if (!container || !isEnabled) return;
|
|
814
|
+
let startY = 0;
|
|
815
|
+
let distance = 0;
|
|
816
|
+
let isTracking = false;
|
|
817
|
+
let isBusy = false;
|
|
818
|
+
function reset() {
|
|
819
|
+
distance = 0;
|
|
820
|
+
setPullDistance(0);
|
|
821
|
+
setPhase("idle");
|
|
822
|
+
}
|
|
823
|
+
function handleTouchStart(event) {
|
|
824
|
+
if (isBusy || event.touches.length !== 1 || !container || container.scrollTop > 0) return;
|
|
825
|
+
if (shouldIgnoreTouchTarget(event.target, container)) return;
|
|
826
|
+
startY = event.touches[0].clientY;
|
|
827
|
+
distance = 0;
|
|
828
|
+
isTracking = true;
|
|
829
|
+
}
|
|
830
|
+
function handleTouchMove(event) {
|
|
831
|
+
if (!isTracking || !container) return;
|
|
832
|
+
if (container.scrollTop > 0) {
|
|
833
|
+
isTracking = false;
|
|
834
|
+
reset();
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
distance = getPullDistance(event.touches[0].clientY - startY);
|
|
838
|
+
if (distance > 0) event.preventDefault();
|
|
839
|
+
setPullDistance(distance);
|
|
840
|
+
setPhase(distance === 0 ? "idle" : isPastThreshold(distance) ? "ready" : "pulling");
|
|
841
|
+
}
|
|
842
|
+
async function handleTouchEnd() {
|
|
843
|
+
if (!isTracking) return;
|
|
844
|
+
isTracking = false;
|
|
845
|
+
if (!isPastThreshold(distance)) {
|
|
846
|
+
reset();
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
isBusy = true;
|
|
850
|
+
setPhase("refreshing");
|
|
851
|
+
setPullDistance(REFRESHING_HEIGHT_PX);
|
|
852
|
+
const startedAt = Date.now();
|
|
853
|
+
let outcome = "refreshed";
|
|
854
|
+
try {
|
|
855
|
+
outcome = await onRefreshRef.current();
|
|
856
|
+
} catch (error) {
|
|
857
|
+
console.error("Pull-down refresh failed:", error);
|
|
858
|
+
}
|
|
859
|
+
if (outcome === "reloading") {
|
|
860
|
+
setPhase("reloading");
|
|
861
|
+
await wait(RELOAD_MESSAGE_DELAY_MS);
|
|
862
|
+
(onReloadRef.current ?? (() => window.location.reload()))();
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
await wait(Math.max(0, MIN_REFRESH_DISPLAY_MS - (Date.now() - startedAt)));
|
|
866
|
+
isBusy = false;
|
|
867
|
+
reset();
|
|
868
|
+
}
|
|
869
|
+
function handleTouchCancel() {
|
|
870
|
+
if (!isTracking) return;
|
|
871
|
+
isTracking = false;
|
|
872
|
+
reset();
|
|
873
|
+
}
|
|
874
|
+
container.addEventListener("touchstart", handleTouchStart, { passive: true });
|
|
875
|
+
container.addEventListener("touchmove", handleTouchMove, { passive: false });
|
|
876
|
+
container.addEventListener("touchend", handleTouchEnd, { passive: true });
|
|
877
|
+
container.addEventListener("touchcancel", handleTouchCancel, { passive: true });
|
|
878
|
+
return () => {
|
|
879
|
+
container.removeEventListener("touchstart", handleTouchStart);
|
|
880
|
+
container.removeEventListener("touchmove", handleTouchMove);
|
|
881
|
+
container.removeEventListener("touchend", handleTouchEnd);
|
|
882
|
+
container.removeEventListener("touchcancel", handleTouchCancel);
|
|
883
|
+
};
|
|
884
|
+
}, [containerRef, isEnabled]);
|
|
885
|
+
return { pullDistance, phase };
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
// src/components/pullToRefreshArea/PullToRefreshArea.tsx
|
|
889
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
890
|
+
var LABELS = {
|
|
891
|
+
idle: "",
|
|
892
|
+
pulling: "Pull down to refresh",
|
|
893
|
+
ready: "Release to refresh",
|
|
894
|
+
refreshing: "Refreshing\u2026",
|
|
895
|
+
reloading: "Updating to the new version\u2026"
|
|
896
|
+
};
|
|
897
|
+
function PullToRefreshArea({
|
|
898
|
+
isEnabled,
|
|
899
|
+
onRefresh,
|
|
900
|
+
onReload,
|
|
901
|
+
className,
|
|
902
|
+
children
|
|
903
|
+
}) {
|
|
904
|
+
const containerRef = (0, import_react4.useRef)(null);
|
|
905
|
+
const { pullDistance, phase } = usePullToRefresh({
|
|
906
|
+
containerRef,
|
|
907
|
+
isEnabled,
|
|
908
|
+
onRefresh,
|
|
909
|
+
onReload
|
|
910
|
+
});
|
|
911
|
+
const isDragging = phase === "pulling" || phase === "ready";
|
|
912
|
+
const isWorking = phase === "refreshing" || phase === "reloading";
|
|
913
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { ref: containerRef, className: (0, import_cn6.cn)(className, isEnabled && "overscroll-y-contain"), children: [
|
|
914
|
+
isEnabled && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
915
|
+
"div",
|
|
916
|
+
{
|
|
917
|
+
role: "status",
|
|
918
|
+
"aria-live": "polite",
|
|
919
|
+
className: "flex items-end justify-center overflow-hidden text-sm text-muted-foreground",
|
|
920
|
+
style: { height: pullDistance, transition: isDragging ? "none" : "height 200ms ease" },
|
|
921
|
+
children: phase !== "idle" && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("span", { className: "flex items-center gap-2 pb-2", children: [
|
|
922
|
+
isWorking ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "h-4 w-4 animate-spin rounded-full border-2 border-muted border-t-primary" }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
923
|
+
"span",
|
|
924
|
+
{
|
|
925
|
+
"aria-hidden": "true",
|
|
926
|
+
className: "inline-block transition-transform",
|
|
927
|
+
style: { transform: phase === "ready" ? "rotate(180deg)" : "none" },
|
|
928
|
+
children: "\u2193"
|
|
929
|
+
}
|
|
930
|
+
),
|
|
931
|
+
LABELS[phase]
|
|
932
|
+
] })
|
|
933
|
+
}
|
|
934
|
+
),
|
|
935
|
+
children
|
|
936
|
+
] });
|
|
937
|
+
}
|
|
705
938
|
// Annotate the CommonJS export names for ESM import in node:
|
|
706
939
|
0 && (module.exports = {
|
|
707
940
|
DatePicker,
|
|
708
941
|
DebouncedInput,
|
|
709
|
-
JobCard
|
|
942
|
+
JobCard,
|
|
943
|
+
PullToRefreshArea,
|
|
944
|
+
Toaster,
|
|
945
|
+
toast,
|
|
946
|
+
toastColors
|
|
710
947
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ComponentProps, FocusEventHandler, ReactNode } from 'react';
|
|
2
|
+
import { ComponentProps, FocusEventHandler, ReactNode, CSSProperties } from 'react';
|
|
3
|
+
import { ToasterProps as ToasterProps$1 } from 'sonner';
|
|
4
|
+
export { toast } from 'sonner';
|
|
3
5
|
|
|
4
6
|
interface IDatePicker {
|
|
5
7
|
/**
|
|
@@ -209,5 +211,99 @@ interface JobCardProps {
|
|
|
209
211
|
*/
|
|
210
212
|
declare const JobCard: ({ job, onClick, action, leadingContent, expandedContent, className, }: JobCardProps) => react.JSX.Element;
|
|
211
213
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
+
declare const Toaster$1: ({ icons, ...props }: ToasterProps$1) => react.JSX.Element;
|
|
215
|
+
|
|
216
|
+
type SonnerToasterProps = ComponentProps<typeof Toaster$1>;
|
|
217
|
+
/**
|
|
218
|
+
* Props for `Toaster`. Any other Sonner toaster prop (`duration`, `richColors`,
|
|
219
|
+
* `closeButton` and so on) is passed straight through.
|
|
220
|
+
*/
|
|
221
|
+
interface ToasterProps extends SonnerToasterProps {
|
|
222
|
+
/**
|
|
223
|
+
* Where on the screen toasts appear: a vertical edge and a horizontal place,
|
|
224
|
+
* such as `"top-center"` or `"bottom-right"`. Default `"top-center"`.
|
|
225
|
+
*/
|
|
226
|
+
position?: SonnerToasterProps["position"];
|
|
227
|
+
/**
|
|
228
|
+
* `"light"`, `"dark"` or `"system"`. It is not read from the app, so pass it
|
|
229
|
+
* if toasts should follow a theme. Default is Sonner's own (light).
|
|
230
|
+
*/
|
|
231
|
+
theme?: SonnerToasterProps["theme"];
|
|
232
|
+
/**
|
|
233
|
+
* Replaces the icon for a type of toast: `success`, `info`, `warning`,
|
|
234
|
+
* `error`, `loading` or `close`. Optional, and only the types given change,
|
|
235
|
+
* the others keep their default icon. A single toast can also set its own
|
|
236
|
+
* with `toast("Saved", { icon: <StarIcon /> })`.
|
|
237
|
+
*/
|
|
238
|
+
icons?: SonnerToasterProps["icons"];
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Colors for one toast. Every field is optional, and one left out keeps the
|
|
242
|
+
* theme's color. Each is any CSS color, or a theme variable such as
|
|
243
|
+
* `var(--primary)`.
|
|
244
|
+
*/
|
|
245
|
+
interface ToastColors {
|
|
246
|
+
/** Background of the toast. */
|
|
247
|
+
background?: string;
|
|
248
|
+
/** Color of the message and the icon. */
|
|
249
|
+
text?: string;
|
|
250
|
+
/** Color of the toast's border. */
|
|
251
|
+
border?: string;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Turns colors into the `style` of a single toast:
|
|
255
|
+
* `toast("Saved", { style: toastColors({ background: "var(--primary)" }) })`.
|
|
256
|
+
*
|
|
257
|
+
* It sets the toast's own color variables, which is why the color names are
|
|
258
|
+
* not needed by the caller. With the `richColors` prop on, the success, error,
|
|
259
|
+
* warning and info toasts use their own colors instead, and these are ignored.
|
|
260
|
+
*/
|
|
261
|
+
declare function toastColors({ background, text, border, }: ToastColors): CSSProperties;
|
|
262
|
+
/**
|
|
263
|
+
* Where toasts appear and how they look. Mount it once near the root of the
|
|
264
|
+
* app, then show a toast from anywhere by calling `toast`.
|
|
265
|
+
*
|
|
266
|
+
* `position` defaults to `"top-center"`. The theme is not read from the app:
|
|
267
|
+
* pass `theme` (`"light"`, `"dark"` or `"system"`) if it should follow one.
|
|
268
|
+
*/
|
|
269
|
+
declare function Toaster({ position, ...props }: ToasterProps): react.JSX.Element;
|
|
270
|
+
|
|
271
|
+
/** What a refresh reports back: the data was refreshed, or a new version of the app is about to replace the page. */
|
|
272
|
+
type RefreshOutcome = "refreshed" | "reloading";
|
|
273
|
+
type PullPhase = "idle" | "pulling" | "ready" | "refreshing" | "reloading";
|
|
274
|
+
|
|
275
|
+
interface PullToRefreshAreaProps {
|
|
276
|
+
/**
|
|
277
|
+
* Turns the pull gesture on or off. Turn it off where a refresh can't work,
|
|
278
|
+
* for example when the app can't reach its version check. When off, the area
|
|
279
|
+
* renders its children and nothing else. Not controlled by the area.
|
|
280
|
+
*/
|
|
281
|
+
isEnabled: boolean;
|
|
282
|
+
/**
|
|
283
|
+
* Runs when the user pulls past the threshold and lets go. Resolve with
|
|
284
|
+
* `"refreshed"` once the data is up to date, or `"reloading"` when a newer
|
|
285
|
+
* version of the app is live: the area then shows its updating message and
|
|
286
|
+
* calls `onReload`. If it rejects, the error is logged and the area resets.
|
|
287
|
+
*/
|
|
288
|
+
onRefresh: () => Promise<RefreshOutcome>;
|
|
289
|
+
/**
|
|
290
|
+
* Called after the updating message has been shown, when `onRefresh`
|
|
291
|
+
* resolved with `"reloading"`. Defaults to reloading the browser page.
|
|
292
|
+
*/
|
|
293
|
+
onReload?: () => void;
|
|
294
|
+
/** Classes for the scrolling container. Give it a fixed height or a flex size, because the area itself is what scrolls. */
|
|
295
|
+
className?: string;
|
|
296
|
+
/** The page content. */
|
|
297
|
+
children: ReactNode;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* The scrolling page area, with a quiet strip that opens at the top while you
|
|
301
|
+
* pull down. The pull only starts when the area is scrolled to the top, and it
|
|
302
|
+
* ignores touches that begin on fields, inside lists that are scrolled down, or
|
|
303
|
+
* inside anything marked `data-no-pull-refresh`. What a refresh does is up to
|
|
304
|
+
* the app, through `onRefresh`.
|
|
305
|
+
*/
|
|
306
|
+
declare function PullToRefreshArea({ isEnabled, onRefresh, onReload, className, children, }: PullToRefreshAreaProps): react.JSX.Element;
|
|
307
|
+
|
|
308
|
+
export { DatePicker, DebouncedInput, JobCard, PullToRefreshArea, Toaster, toastColors };
|
|
309
|
+
export type { DebouncedInputProps, JobCardAction, JobCardBadge, JobCardBanner, JobCardColor, JobCardData, JobCardPill, JobCardPillTone, JobCardProps, JobCardStage, JobCardTone, PullPhase, PullToRefreshAreaProps, RefreshOutcome, ToastColors, ToasterProps };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import { ComponentProps, FocusEventHandler, ReactNode } from 'react';
|
|
2
|
+
import { ComponentProps, FocusEventHandler, ReactNode, CSSProperties } from 'react';
|
|
3
|
+
import { ToasterProps as ToasterProps$1 } from 'sonner';
|
|
4
|
+
export { toast } from 'sonner';
|
|
3
5
|
|
|
4
6
|
interface IDatePicker {
|
|
5
7
|
/**
|
|
@@ -209,5 +211,99 @@ interface JobCardProps {
|
|
|
209
211
|
*/
|
|
210
212
|
declare const JobCard: ({ job, onClick, action, leadingContent, expandedContent, className, }: JobCardProps) => react.JSX.Element;
|
|
211
213
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
+
declare const Toaster$1: ({ icons, ...props }: ToasterProps$1) => react.JSX.Element;
|
|
215
|
+
|
|
216
|
+
type SonnerToasterProps = ComponentProps<typeof Toaster$1>;
|
|
217
|
+
/**
|
|
218
|
+
* Props for `Toaster`. Any other Sonner toaster prop (`duration`, `richColors`,
|
|
219
|
+
* `closeButton` and so on) is passed straight through.
|
|
220
|
+
*/
|
|
221
|
+
interface ToasterProps extends SonnerToasterProps {
|
|
222
|
+
/**
|
|
223
|
+
* Where on the screen toasts appear: a vertical edge and a horizontal place,
|
|
224
|
+
* such as `"top-center"` or `"bottom-right"`. Default `"top-center"`.
|
|
225
|
+
*/
|
|
226
|
+
position?: SonnerToasterProps["position"];
|
|
227
|
+
/**
|
|
228
|
+
* `"light"`, `"dark"` or `"system"`. It is not read from the app, so pass it
|
|
229
|
+
* if toasts should follow a theme. Default is Sonner's own (light).
|
|
230
|
+
*/
|
|
231
|
+
theme?: SonnerToasterProps["theme"];
|
|
232
|
+
/**
|
|
233
|
+
* Replaces the icon for a type of toast: `success`, `info`, `warning`,
|
|
234
|
+
* `error`, `loading` or `close`. Optional, and only the types given change,
|
|
235
|
+
* the others keep their default icon. A single toast can also set its own
|
|
236
|
+
* with `toast("Saved", { icon: <StarIcon /> })`.
|
|
237
|
+
*/
|
|
238
|
+
icons?: SonnerToasterProps["icons"];
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Colors for one toast. Every field is optional, and one left out keeps the
|
|
242
|
+
* theme's color. Each is any CSS color, or a theme variable such as
|
|
243
|
+
* `var(--primary)`.
|
|
244
|
+
*/
|
|
245
|
+
interface ToastColors {
|
|
246
|
+
/** Background of the toast. */
|
|
247
|
+
background?: string;
|
|
248
|
+
/** Color of the message and the icon. */
|
|
249
|
+
text?: string;
|
|
250
|
+
/** Color of the toast's border. */
|
|
251
|
+
border?: string;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Turns colors into the `style` of a single toast:
|
|
255
|
+
* `toast("Saved", { style: toastColors({ background: "var(--primary)" }) })`.
|
|
256
|
+
*
|
|
257
|
+
* It sets the toast's own color variables, which is why the color names are
|
|
258
|
+
* not needed by the caller. With the `richColors` prop on, the success, error,
|
|
259
|
+
* warning and info toasts use their own colors instead, and these are ignored.
|
|
260
|
+
*/
|
|
261
|
+
declare function toastColors({ background, text, border, }: ToastColors): CSSProperties;
|
|
262
|
+
/**
|
|
263
|
+
* Where toasts appear and how they look. Mount it once near the root of the
|
|
264
|
+
* app, then show a toast from anywhere by calling `toast`.
|
|
265
|
+
*
|
|
266
|
+
* `position` defaults to `"top-center"`. The theme is not read from the app:
|
|
267
|
+
* pass `theme` (`"light"`, `"dark"` or `"system"`) if it should follow one.
|
|
268
|
+
*/
|
|
269
|
+
declare function Toaster({ position, ...props }: ToasterProps): react.JSX.Element;
|
|
270
|
+
|
|
271
|
+
/** What a refresh reports back: the data was refreshed, or a new version of the app is about to replace the page. */
|
|
272
|
+
type RefreshOutcome = "refreshed" | "reloading";
|
|
273
|
+
type PullPhase = "idle" | "pulling" | "ready" | "refreshing" | "reloading";
|
|
274
|
+
|
|
275
|
+
interface PullToRefreshAreaProps {
|
|
276
|
+
/**
|
|
277
|
+
* Turns the pull gesture on or off. Turn it off where a refresh can't work,
|
|
278
|
+
* for example when the app can't reach its version check. When off, the area
|
|
279
|
+
* renders its children and nothing else. Not controlled by the area.
|
|
280
|
+
*/
|
|
281
|
+
isEnabled: boolean;
|
|
282
|
+
/**
|
|
283
|
+
* Runs when the user pulls past the threshold and lets go. Resolve with
|
|
284
|
+
* `"refreshed"` once the data is up to date, or `"reloading"` when a newer
|
|
285
|
+
* version of the app is live: the area then shows its updating message and
|
|
286
|
+
* calls `onReload`. If it rejects, the error is logged and the area resets.
|
|
287
|
+
*/
|
|
288
|
+
onRefresh: () => Promise<RefreshOutcome>;
|
|
289
|
+
/**
|
|
290
|
+
* Called after the updating message has been shown, when `onRefresh`
|
|
291
|
+
* resolved with `"reloading"`. Defaults to reloading the browser page.
|
|
292
|
+
*/
|
|
293
|
+
onReload?: () => void;
|
|
294
|
+
/** Classes for the scrolling container. Give it a fixed height or a flex size, because the area itself is what scrolls. */
|
|
295
|
+
className?: string;
|
|
296
|
+
/** The page content. */
|
|
297
|
+
children: ReactNode;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* The scrolling page area, with a quiet strip that opens at the top while you
|
|
301
|
+
* pull down. The pull only starts when the area is scrolled to the top, and it
|
|
302
|
+
* ignores touches that begin on fields, inside lists that are scrolled down, or
|
|
303
|
+
* inside anything marked `data-no-pull-refresh`. What a refresh does is up to
|
|
304
|
+
* the app, through `onRefresh`.
|
|
305
|
+
*/
|
|
306
|
+
declare function PullToRefreshArea({ isEnabled, onRefresh, onReload, className, children, }: PullToRefreshAreaProps): react.JSX.Element;
|
|
307
|
+
|
|
308
|
+
export { DatePicker, DebouncedInput, JobCard, PullToRefreshArea, Toaster, toastColors };
|
|
309
|
+
export type { DebouncedInputProps, JobCardAction, JobCardBadge, JobCardBanner, JobCardColor, JobCardData, JobCardPill, JobCardPillTone, JobCardProps, JobCardStage, JobCardTone, PullPhase, PullToRefreshAreaProps, RefreshOutcome, ToastColors, ToasterProps };
|
package/dist/index.js
CHANGED
|
@@ -397,7 +397,7 @@ import {
|
|
|
397
397
|
useState as useState2
|
|
398
398
|
} from "react";
|
|
399
399
|
|
|
400
|
-
// src/
|
|
400
|
+
// src/components/debounceInput/debounce.ts
|
|
401
401
|
function debounce(fn, delayMs) {
|
|
402
402
|
let timeout = null;
|
|
403
403
|
let latestArgs = null;
|
|
@@ -672,8 +672,241 @@ var JobCard = ({
|
|
|
672
672
|
}
|
|
673
673
|
);
|
|
674
674
|
};
|
|
675
|
+
|
|
676
|
+
// src/components/toaster/Toaster.tsx
|
|
677
|
+
import { toast } from "sonner";
|
|
678
|
+
|
|
679
|
+
// src/components/ui/sonner.tsx
|
|
680
|
+
import { Toaster as Sonner } from "sonner";
|
|
681
|
+
import { CircleCheckIcon, InfoIcon, TriangleAlertIcon, OctagonXIcon, Loader2Icon } from "lucide-react";
|
|
682
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
683
|
+
var Toaster = ({ icons, ...props }) => {
|
|
684
|
+
return /* @__PURE__ */ jsx11(
|
|
685
|
+
Sonner,
|
|
686
|
+
{
|
|
687
|
+
className: "toaster group",
|
|
688
|
+
icons: {
|
|
689
|
+
success: /* @__PURE__ */ jsx11(CircleCheckIcon, { className: "size-4" }),
|
|
690
|
+
info: /* @__PURE__ */ jsx11(InfoIcon, { className: "size-4" }),
|
|
691
|
+
warning: /* @__PURE__ */ jsx11(TriangleAlertIcon, { className: "size-4" }),
|
|
692
|
+
error: /* @__PURE__ */ jsx11(OctagonXIcon, { className: "size-4" }),
|
|
693
|
+
loading: /* @__PURE__ */ jsx11(Loader2Icon, { className: "size-4 animate-spin" }),
|
|
694
|
+
...icons
|
|
695
|
+
},
|
|
696
|
+
style: {
|
|
697
|
+
"--normal-bg": "var(--popover)",
|
|
698
|
+
"--normal-text": "var(--popover-foreground)",
|
|
699
|
+
"--normal-border": "var(--border)",
|
|
700
|
+
"--border-radius": "var(--radius)"
|
|
701
|
+
},
|
|
702
|
+
toastOptions: {
|
|
703
|
+
classNames: {
|
|
704
|
+
toast: "cn-toast"
|
|
705
|
+
}
|
|
706
|
+
},
|
|
707
|
+
...props
|
|
708
|
+
}
|
|
709
|
+
);
|
|
710
|
+
};
|
|
711
|
+
|
|
712
|
+
// src/components/toaster/Toaster.tsx
|
|
713
|
+
import { jsx as jsx12 } from "react/jsx-runtime";
|
|
714
|
+
function toastColors({
|
|
715
|
+
background,
|
|
716
|
+
text,
|
|
717
|
+
border
|
|
718
|
+
}) {
|
|
719
|
+
return {
|
|
720
|
+
...background && { "--normal-bg": background },
|
|
721
|
+
...text && { "--normal-text": text },
|
|
722
|
+
...border && { "--normal-border": border }
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
function Toaster2({ position = "top-center", ...props }) {
|
|
726
|
+
return /* @__PURE__ */ jsx12(Toaster, { position, ...props });
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// src/components/pullToRefreshArea/PullToRefreshArea.tsx
|
|
730
|
+
import { useRef as useRef4 } from "react";
|
|
731
|
+
|
|
732
|
+
// src/components/pullToRefreshArea/usePullToRefresh.ts
|
|
733
|
+
import { useEffect as useEffect3, useRef as useRef3, useState as useState3 } from "react";
|
|
734
|
+
|
|
735
|
+
// src/components/pullToRefreshArea/pullToRefresh.ts
|
|
736
|
+
var DEAD_ZONE_PX = 8;
|
|
737
|
+
var RESISTANCE = 0.5;
|
|
738
|
+
var MAX_PULL_PX = 120;
|
|
739
|
+
var REFRESH_THRESHOLD_PX = 64;
|
|
740
|
+
var REFRESHING_HEIGHT_PX = 48;
|
|
741
|
+
function getPullDistance(fingerDeltaY) {
|
|
742
|
+
if (fingerDeltaY <= DEAD_ZONE_PX) return 0;
|
|
743
|
+
return Math.min((fingerDeltaY - DEAD_ZONE_PX) * RESISTANCE, MAX_PULL_PX);
|
|
744
|
+
}
|
|
745
|
+
function isPastThreshold(pullDistance) {
|
|
746
|
+
return pullDistance >= REFRESH_THRESHOLD_PX;
|
|
747
|
+
}
|
|
748
|
+
var IGNORED_SELECTOR = "input, textarea, select, [contenteditable='true'], [data-no-pull-refresh]";
|
|
749
|
+
function isScrolledVertically(element) {
|
|
750
|
+
const { overflowY } = getComputedStyle(element);
|
|
751
|
+
const canScroll = overflowY === "auto" || overflowY === "scroll";
|
|
752
|
+
return canScroll && element.scrollHeight > element.clientHeight && element.scrollTop > 0;
|
|
753
|
+
}
|
|
754
|
+
function shouldIgnoreTouchTarget(target, container) {
|
|
755
|
+
for (let element = target; element && element !== container; element = element.parentElement) {
|
|
756
|
+
if (element.matches(IGNORED_SELECTOR)) return true;
|
|
757
|
+
if (element instanceof HTMLElement && isScrolledVertically(element)) return true;
|
|
758
|
+
}
|
|
759
|
+
return false;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
// src/components/pullToRefreshArea/usePullToRefresh.ts
|
|
763
|
+
var RELOAD_MESSAGE_DELAY_MS = 700;
|
|
764
|
+
var MIN_REFRESH_DISPLAY_MS = 500;
|
|
765
|
+
function wait(milliseconds) {
|
|
766
|
+
return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
767
|
+
}
|
|
768
|
+
function usePullToRefresh({ containerRef, isEnabled, onRefresh, onReload }) {
|
|
769
|
+
const [pullDistance, setPullDistance] = useState3(0);
|
|
770
|
+
const [phase, setPhase] = useState3("idle");
|
|
771
|
+
const onRefreshRef = useRef3(onRefresh);
|
|
772
|
+
const onReloadRef = useRef3(onReload);
|
|
773
|
+
useEffect3(() => {
|
|
774
|
+
onRefreshRef.current = onRefresh;
|
|
775
|
+
onReloadRef.current = onReload;
|
|
776
|
+
});
|
|
777
|
+
useEffect3(() => {
|
|
778
|
+
const container = containerRef.current;
|
|
779
|
+
if (!container || !isEnabled) return;
|
|
780
|
+
let startY = 0;
|
|
781
|
+
let distance = 0;
|
|
782
|
+
let isTracking = false;
|
|
783
|
+
let isBusy = false;
|
|
784
|
+
function reset() {
|
|
785
|
+
distance = 0;
|
|
786
|
+
setPullDistance(0);
|
|
787
|
+
setPhase("idle");
|
|
788
|
+
}
|
|
789
|
+
function handleTouchStart(event) {
|
|
790
|
+
if (isBusy || event.touches.length !== 1 || !container || container.scrollTop > 0) return;
|
|
791
|
+
if (shouldIgnoreTouchTarget(event.target, container)) return;
|
|
792
|
+
startY = event.touches[0].clientY;
|
|
793
|
+
distance = 0;
|
|
794
|
+
isTracking = true;
|
|
795
|
+
}
|
|
796
|
+
function handleTouchMove(event) {
|
|
797
|
+
if (!isTracking || !container) return;
|
|
798
|
+
if (container.scrollTop > 0) {
|
|
799
|
+
isTracking = false;
|
|
800
|
+
reset();
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
distance = getPullDistance(event.touches[0].clientY - startY);
|
|
804
|
+
if (distance > 0) event.preventDefault();
|
|
805
|
+
setPullDistance(distance);
|
|
806
|
+
setPhase(distance === 0 ? "idle" : isPastThreshold(distance) ? "ready" : "pulling");
|
|
807
|
+
}
|
|
808
|
+
async function handleTouchEnd() {
|
|
809
|
+
if (!isTracking) return;
|
|
810
|
+
isTracking = false;
|
|
811
|
+
if (!isPastThreshold(distance)) {
|
|
812
|
+
reset();
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
isBusy = true;
|
|
816
|
+
setPhase("refreshing");
|
|
817
|
+
setPullDistance(REFRESHING_HEIGHT_PX);
|
|
818
|
+
const startedAt = Date.now();
|
|
819
|
+
let outcome = "refreshed";
|
|
820
|
+
try {
|
|
821
|
+
outcome = await onRefreshRef.current();
|
|
822
|
+
} catch (error) {
|
|
823
|
+
console.error("Pull-down refresh failed:", error);
|
|
824
|
+
}
|
|
825
|
+
if (outcome === "reloading") {
|
|
826
|
+
setPhase("reloading");
|
|
827
|
+
await wait(RELOAD_MESSAGE_DELAY_MS);
|
|
828
|
+
(onReloadRef.current ?? (() => window.location.reload()))();
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
await wait(Math.max(0, MIN_REFRESH_DISPLAY_MS - (Date.now() - startedAt)));
|
|
832
|
+
isBusy = false;
|
|
833
|
+
reset();
|
|
834
|
+
}
|
|
835
|
+
function handleTouchCancel() {
|
|
836
|
+
if (!isTracking) return;
|
|
837
|
+
isTracking = false;
|
|
838
|
+
reset();
|
|
839
|
+
}
|
|
840
|
+
container.addEventListener("touchstart", handleTouchStart, { passive: true });
|
|
841
|
+
container.addEventListener("touchmove", handleTouchMove, { passive: false });
|
|
842
|
+
container.addEventListener("touchend", handleTouchEnd, { passive: true });
|
|
843
|
+
container.addEventListener("touchcancel", handleTouchCancel, { passive: true });
|
|
844
|
+
return () => {
|
|
845
|
+
container.removeEventListener("touchstart", handleTouchStart);
|
|
846
|
+
container.removeEventListener("touchmove", handleTouchMove);
|
|
847
|
+
container.removeEventListener("touchend", handleTouchEnd);
|
|
848
|
+
container.removeEventListener("touchcancel", handleTouchCancel);
|
|
849
|
+
};
|
|
850
|
+
}, [containerRef, isEnabled]);
|
|
851
|
+
return { pullDistance, phase };
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// src/components/pullToRefreshArea/PullToRefreshArea.tsx
|
|
855
|
+
import { jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
856
|
+
var LABELS = {
|
|
857
|
+
idle: "",
|
|
858
|
+
pulling: "Pull down to refresh",
|
|
859
|
+
ready: "Release to refresh",
|
|
860
|
+
refreshing: "Refreshing\u2026",
|
|
861
|
+
reloading: "Updating to the new version\u2026"
|
|
862
|
+
};
|
|
863
|
+
function PullToRefreshArea({
|
|
864
|
+
isEnabled,
|
|
865
|
+
onRefresh,
|
|
866
|
+
onReload,
|
|
867
|
+
className,
|
|
868
|
+
children
|
|
869
|
+
}) {
|
|
870
|
+
const containerRef = useRef4(null);
|
|
871
|
+
const { pullDistance, phase } = usePullToRefresh({
|
|
872
|
+
containerRef,
|
|
873
|
+
isEnabled,
|
|
874
|
+
onRefresh,
|
|
875
|
+
onReload
|
|
876
|
+
});
|
|
877
|
+
const isDragging = phase === "pulling" || phase === "ready";
|
|
878
|
+
const isWorking = phase === "refreshing" || phase === "reloading";
|
|
879
|
+
return /* @__PURE__ */ jsxs6("div", { ref: containerRef, className: cn6(className, isEnabled && "overscroll-y-contain"), children: [
|
|
880
|
+
isEnabled && /* @__PURE__ */ jsx13(
|
|
881
|
+
"div",
|
|
882
|
+
{
|
|
883
|
+
role: "status",
|
|
884
|
+
"aria-live": "polite",
|
|
885
|
+
className: "flex items-end justify-center overflow-hidden text-sm text-muted-foreground",
|
|
886
|
+
style: { height: pullDistance, transition: isDragging ? "none" : "height 200ms ease" },
|
|
887
|
+
children: phase !== "idle" && /* @__PURE__ */ jsxs6("span", { className: "flex items-center gap-2 pb-2", children: [
|
|
888
|
+
isWorking ? /* @__PURE__ */ jsx13("span", { className: "h-4 w-4 animate-spin rounded-full border-2 border-muted border-t-primary" }) : /* @__PURE__ */ jsx13(
|
|
889
|
+
"span",
|
|
890
|
+
{
|
|
891
|
+
"aria-hidden": "true",
|
|
892
|
+
className: "inline-block transition-transform",
|
|
893
|
+
style: { transform: phase === "ready" ? "rotate(180deg)" : "none" },
|
|
894
|
+
children: "\u2193"
|
|
895
|
+
}
|
|
896
|
+
),
|
|
897
|
+
LABELS[phase]
|
|
898
|
+
] })
|
|
899
|
+
}
|
|
900
|
+
),
|
|
901
|
+
children
|
|
902
|
+
] });
|
|
903
|
+
}
|
|
675
904
|
export {
|
|
676
905
|
DatePicker,
|
|
677
906
|
DebouncedInput,
|
|
678
|
-
JobCard
|
|
907
|
+
JobCard,
|
|
908
|
+
PullToRefreshArea,
|
|
909
|
+
Toaster2 as Toaster,
|
|
910
|
+
toast,
|
|
911
|
+
toastColors
|
|
679
912
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@processdynamics/components",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Process Dynamics React component library, built on shadcn (Radix) and Tailwind CSS v4.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
"react-day-picker": "^10.0.2",
|
|
85
85
|
"react-dom": "19.3.0",
|
|
86
86
|
"shadcn": "^4.23.0",
|
|
87
|
+
"sonner": "^2.0.8",
|
|
87
88
|
"storybook": "^10.6.5",
|
|
88
89
|
"tailwindcss": "^4",
|
|
89
90
|
"tsup": "^9.0.0",
|
|
@@ -101,6 +102,7 @@
|
|
|
101
102
|
"radix-ui": "^1.8.1",
|
|
102
103
|
"react": "^19.0.0",
|
|
103
104
|
"react-day-picker": "^10.0.2",
|
|
104
|
-
"react-dom": "^19.0.0"
|
|
105
|
+
"react-dom": "^19.0.0",
|
|
106
|
+
"sonner": "^2.0.8"
|
|
105
107
|
}
|
|
106
108
|
}
|