@schemavaults/ui 0.88.1 → 0.89.0
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/components/ui/index.d.ts +2 -0
- package/dist/components/ui/index.js +1 -0
- package/dist/components/ui/index.js.map +1 -1
- package/dist/components/ui/scroll-to-top/index.d.ts +3 -0
- package/dist/components/ui/scroll-to-top/index.js +3 -0
- package/dist/components/ui/scroll-to-top/index.js.map +1 -0
- package/dist/components/ui/scroll-to-top/scroll-to-top.d.ts +69 -0
- package/dist/components/ui/scroll-to-top/scroll-to-top.js +129 -0
- package/dist/components/ui/scroll-to-top/scroll-to-top.js.map +1 -0
- package/package.json +1 -1
|
@@ -200,6 +200,8 @@ export * from "./countdown";
|
|
|
200
200
|
export type * from "./countdown";
|
|
201
201
|
export * from "./floating-action-button";
|
|
202
202
|
export type * from "./floating-action-button";
|
|
203
|
+
export * from "./scroll-to-top";
|
|
204
|
+
export type * from "./scroll-to-top";
|
|
203
205
|
export * from "./notification-bell";
|
|
204
206
|
export type * from "./notification-bell";
|
|
205
207
|
export * from "./calendar";
|
|
@@ -99,6 +99,7 @@ export * from "./tree-view";
|
|
|
99
99
|
export * from "./carousel";
|
|
100
100
|
export * from "./countdown";
|
|
101
101
|
export * from "./floating-action-button";
|
|
102
|
+
export * from "./scroll-to-top";
|
|
102
103
|
export * from "./notification-bell";
|
|
103
104
|
export * from "./calendar";
|
|
104
105
|
export * from "./date-picker";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/ui/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AAGzB,cAAc,uBAAuB,CAAC;AAGtC,cAAc,aAAa,CAAC;AAG5B,cAAc,eAAe,CAAC;AAG9B,cAAc,SAAS,CAAC;AAGxB,cAAc,WAAW,CAAC;AAG1B,cAAc,cAAc,CAAC;AAG7B,cAAc,SAAS,CAAC;AAGxB,cAAc,m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9B,cAAc,eAAe,CAAC;AAG9B,cAAc,qBAAqB,CAAC;AAGpC,cAAc,WAAW,CAAC;AAG1B,cAAc,UAAU,CAAC;AAGzB,cAAc,QAAQ,CAAC;AAGvB,cAAc,cAAc,CAAC;AAG7B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,aAAa,CAAC;AAG5B,cAAc,gBAAgB,CAAC;AAG/B,cAAc,gBAAgB,CAAC;AAG/B,cAAc,oBAAoB,CAAC;AAGnC,cAAc,aAAa,CAAC;AAG5B,cAAc,aAAa,CAAC;AAG5B,cAAc,cAAc,CAAC;AAG7B,cAAc,eAAe,CAAC;AAG9B,cAAc,qBAAqB,CAAC;AAGpC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,aAAa,CAAC;AAG5B,cAAc,YAAY,CAAC;AAG3B,cAAc,aAAa,CAAC;AAG5B,cAAc,0BAA0B,CAAC;AAGzC,cAAc,iBAAiB,CAAC;AAGhC,cAAc,qBAAqB,CAAC;AAGpC,cAAc,YAAY,CAAC;AAG3B,cAAc,eAAe,CAAC;AAG9B,cAAc,qBAAqB,CAAC;AAGpC,cAAc,eAAe,CAAC;AAG9B,cAAc,QAAQ,CAAC;AAGvB,cAAc,qBAAqB,CAAC;AAGpC,cAAc,iBAAiB,CAAC;AAGhC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,eAAe,CAAC;AAG9B,cAAc,gBAAgB,CAAC;AAG/B,cAAc,UAAU,CAAC;AAGzB,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/ui/scroll-to-top/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAGhC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type ButtonHTMLAttributes, type ReactElement, type ReactNode, type Ref, type RefObject } from "react";
|
|
2
|
+
import { type VariantProps } from "class-variance-authority";
|
|
3
|
+
export declare const scrollToTopVariantIds: ["primary", "secondary", "outline", "ghost", "brand"];
|
|
4
|
+
export type ScrollToTopVariantId = (typeof scrollToTopVariantIds)[number];
|
|
5
|
+
export declare const scrollToTopSizeIds: ["sm", "default", "lg"];
|
|
6
|
+
export type ScrollToTopSizeId = (typeof scrollToTopSizeIds)[number];
|
|
7
|
+
export declare const scrollToTopPositionIds: ["bottom-right", "bottom-left", "bottom-center", "static"];
|
|
8
|
+
export type ScrollToTopPositionId = (typeof scrollToTopPositionIds)[number];
|
|
9
|
+
declare const scrollToTopVariants: (props?: ({
|
|
10
|
+
variant?: "primary" | "outline" | "ghost" | "secondary" | "brand" | null | undefined;
|
|
11
|
+
size?: "sm" | "default" | "lg" | null | undefined;
|
|
12
|
+
position?: "static" | "bottom-right" | "bottom-left" | "bottom-center" | null | undefined;
|
|
13
|
+
extended?: boolean | null | undefined;
|
|
14
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
15
|
+
export interface ScrollToTopProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "children">, VariantProps<typeof scrollToTopVariants> {
|
|
16
|
+
ref?: Ref<HTMLButtonElement>;
|
|
17
|
+
/**
|
|
18
|
+
* Pixel scroll offset at which the button becomes visible. Defaults to
|
|
19
|
+
* `320` — roughly a viewport of scroll on a laptop.
|
|
20
|
+
*/
|
|
21
|
+
threshold?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Ref to a scroll container to observe and scroll. When omitted, the
|
|
24
|
+
* component tracks and scrolls `window`. Useful for embedded scroll
|
|
25
|
+
* areas such as dialogs, sheets, and split panes.
|
|
26
|
+
*/
|
|
27
|
+
containerRef?: RefObject<HTMLElement | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Custom icon rendered inside the button. Defaults to lucide's `ArrowUp`.
|
|
30
|
+
*/
|
|
31
|
+
icon?: ReactNode;
|
|
32
|
+
/**
|
|
33
|
+
* Optional visible label. When provided, the button switches to its
|
|
34
|
+
* extended (pill) layout unless `extended` is explicitly overridden.
|
|
35
|
+
*/
|
|
36
|
+
label?: ReactNode;
|
|
37
|
+
/**
|
|
38
|
+
* Accessible label. Falls back to `label` (if string) or "Scroll to top".
|
|
39
|
+
*/
|
|
40
|
+
"aria-label"?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Scroll behaviour used when the button is clicked. Defaults to `"smooth"`
|
|
43
|
+
* and is automatically downgraded to `"auto"` when the user has
|
|
44
|
+
* `prefers-reduced-motion: reduce`.
|
|
45
|
+
*/
|
|
46
|
+
behavior?: ScrollBehavior;
|
|
47
|
+
/**
|
|
48
|
+
* When `true`, the button is always rendered regardless of scroll position.
|
|
49
|
+
* Useful for testing/showcasing in Storybook.
|
|
50
|
+
*/
|
|
51
|
+
alwaysVisible?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Called after the scroll-to-top action is invoked.
|
|
54
|
+
*/
|
|
55
|
+
onScrolledToTop?: () => void;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A floating "back to top" button that appears once the user scrolls past a
|
|
59
|
+
* configurable threshold and smoothly scrolls the page (or an embedded
|
|
60
|
+
* container) back to the top when clicked.
|
|
61
|
+
*
|
|
62
|
+
* Respects `prefers-reduced-motion` by falling back to an instant scroll.
|
|
63
|
+
*/
|
|
64
|
+
declare function ScrollToTop({ className, variant, size, position, extended, threshold, containerRef, icon, label, behavior, alwaysVisible, onScrolledToTop, onClick, type, ref, ...props }: ScrollToTopProps): ReactElement | null;
|
|
65
|
+
declare namespace ScrollToTop {
|
|
66
|
+
var displayName: string;
|
|
67
|
+
}
|
|
68
|
+
export { ScrollToTop, scrollToTopVariants };
|
|
69
|
+
export default ScrollToTop;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useCallback, useEffect, useState, } from "react";
|
|
4
|
+
import { cva } from "class-variance-authority";
|
|
5
|
+
import { ArrowUp } from "lucide-react";
|
|
6
|
+
import { cn } from "../../../lib/utils";
|
|
7
|
+
export const scrollToTopVariantIds = [
|
|
8
|
+
"primary",
|
|
9
|
+
"secondary",
|
|
10
|
+
"outline",
|
|
11
|
+
"ghost",
|
|
12
|
+
"brand",
|
|
13
|
+
];
|
|
14
|
+
export const scrollToTopSizeIds = [
|
|
15
|
+
"sm",
|
|
16
|
+
"default",
|
|
17
|
+
"lg",
|
|
18
|
+
];
|
|
19
|
+
export const scrollToTopPositionIds = [
|
|
20
|
+
"bottom-right",
|
|
21
|
+
"bottom-left",
|
|
22
|
+
"bottom-center",
|
|
23
|
+
"static",
|
|
24
|
+
];
|
|
25
|
+
const scrollToTopVariants = cva("group/scroll-to-top inline-flex items-center justify-center gap-2 rounded-full font-medium shadow-lg ring-offset-background transition-[background-color,border-color,color,box-shadow,opacity,transform] hover:shadow-xl active:scale-95 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 disabled:shadow-none z-40", {
|
|
26
|
+
variants: {
|
|
27
|
+
variant: {
|
|
28
|
+
primary: "bg-primary text-primary-foreground hover:bg-primary/90 shadow-primary/25",
|
|
29
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80 shadow-secondary/25",
|
|
30
|
+
outline: "border border-input bg-background text-foreground hover:bg-accent hover:text-accent-foreground",
|
|
31
|
+
ghost: "bg-background/70 text-foreground backdrop-blur-md border border-border/50 hover:bg-accent hover:text-accent-foreground",
|
|
32
|
+
brand: "bg-schemavaults-brand-blue text-primary-foreground hover:bg-schemavaults-brand-blue/90 shadow-schemavaults-brand-blue/30",
|
|
33
|
+
},
|
|
34
|
+
size: {
|
|
35
|
+
sm: "h-10 w-10 text-sm [&_svg]:size-4",
|
|
36
|
+
default: "h-12 w-12 text-base [&_svg]:size-5",
|
|
37
|
+
lg: "h-14 w-14 text-base [&_svg]:size-6",
|
|
38
|
+
},
|
|
39
|
+
position: {
|
|
40
|
+
"bottom-right": "fixed bottom-6 right-6",
|
|
41
|
+
"bottom-left": "fixed bottom-6 left-6",
|
|
42
|
+
"bottom-center": "fixed bottom-6 left-1/2 -translate-x-1/2",
|
|
43
|
+
static: "",
|
|
44
|
+
},
|
|
45
|
+
extended: {
|
|
46
|
+
true: "w-auto px-5",
|
|
47
|
+
false: "",
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
compoundVariants: [
|
|
51
|
+
{ extended: true, size: "sm", class: "h-10" },
|
|
52
|
+
{ extended: true, size: "default", class: "h-12" },
|
|
53
|
+
{ extended: true, size: "lg", class: "h-14" },
|
|
54
|
+
],
|
|
55
|
+
defaultVariants: {
|
|
56
|
+
variant: "primary",
|
|
57
|
+
size: "default",
|
|
58
|
+
position: "bottom-right",
|
|
59
|
+
extended: false,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
function readScrollTop(container) {
|
|
63
|
+
if (container)
|
|
64
|
+
return container.scrollTop;
|
|
65
|
+
if (typeof window === "undefined")
|
|
66
|
+
return 0;
|
|
67
|
+
return window.scrollY ?? window.pageYOffset ?? 0;
|
|
68
|
+
}
|
|
69
|
+
function prefersReducedMotion() {
|
|
70
|
+
if (typeof window === "undefined" || !window.matchMedia)
|
|
71
|
+
return false;
|
|
72
|
+
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A floating "back to top" button that appears once the user scrolls past a
|
|
76
|
+
* configurable threshold and smoothly scrolls the page (or an embedded
|
|
77
|
+
* container) back to the top when clicked.
|
|
78
|
+
*
|
|
79
|
+
* Respects `prefers-reduced-motion` by falling back to an instant scroll.
|
|
80
|
+
*/
|
|
81
|
+
function ScrollToTop({ className, variant, size, position, extended, threshold = 320, containerRef, icon, label, behavior = "smooth", alwaysVisible = false, onScrolledToTop, onClick, type = "button", ref, ...props }) {
|
|
82
|
+
const [visible, setVisible] = useState(alwaysVisible);
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
if (alwaysVisible) {
|
|
85
|
+
setVisible(true);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const container = containerRef?.current ?? null;
|
|
89
|
+
const target = container ?? (typeof window !== "undefined" ? window : null);
|
|
90
|
+
if (!target)
|
|
91
|
+
return;
|
|
92
|
+
function update() {
|
|
93
|
+
setVisible(readScrollTop(container) > threshold);
|
|
94
|
+
}
|
|
95
|
+
update();
|
|
96
|
+
target.addEventListener("scroll", update, { passive: true });
|
|
97
|
+
return () => {
|
|
98
|
+
target.removeEventListener("scroll", update);
|
|
99
|
+
};
|
|
100
|
+
}, [alwaysVisible, containerRef, threshold]);
|
|
101
|
+
const handleClick = useCallback((event) => {
|
|
102
|
+
onClick?.(event);
|
|
103
|
+
if (event.defaultPrevented)
|
|
104
|
+
return;
|
|
105
|
+
const resolvedBehavior = prefersReducedMotion()
|
|
106
|
+
? "auto"
|
|
107
|
+
: behavior;
|
|
108
|
+
const container = containerRef?.current ?? null;
|
|
109
|
+
if (container) {
|
|
110
|
+
container.scrollTo({ top: 0, left: 0, behavior: resolvedBehavior });
|
|
111
|
+
}
|
|
112
|
+
else if (typeof window !== "undefined") {
|
|
113
|
+
window.scrollTo({ top: 0, left: 0, behavior: resolvedBehavior });
|
|
114
|
+
}
|
|
115
|
+
onScrolledToTop?.();
|
|
116
|
+
}, [behavior, containerRef, onClick, onScrolledToTop]);
|
|
117
|
+
const isExtended = extended ?? Boolean(label);
|
|
118
|
+
const accessibleLabel = props["aria-label"] ??
|
|
119
|
+
(typeof label === "string" ? label : "Scroll to top");
|
|
120
|
+
const resolvedIcon = icon ?? _jsx(ArrowUp, { "aria-hidden": "true" });
|
|
121
|
+
if (!visible && position !== "static") {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
return (_jsxs("button", { ref: ref, type: type, "data-slot": "scroll-to-top", "data-visible": visible ? "true" : "false", "data-extended": isExtended || undefined, "aria-label": accessibleLabel, onClick: handleClick, className: cn(scrollToTopVariants({ variant, size, position, extended: isExtended }), !visible && "pointer-events-none opacity-0", visible && "opacity-100", className), ...props, children: [_jsx("span", { "aria-hidden": "true", "data-slot": "scroll-to-top-icon", className: "inline-flex shrink-0 items-center justify-center transition-transform group-hover/scroll-to-top:-translate-y-0.5", children: resolvedIcon }), isExtended && label != null ? (_jsx("span", { "data-slot": "scroll-to-top-label", className: "truncate", children: label })) : null] }));
|
|
125
|
+
}
|
|
126
|
+
ScrollToTop.displayName = "ScrollToTop";
|
|
127
|
+
export { ScrollToTop, scrollToTopVariants };
|
|
128
|
+
export default ScrollToTop;
|
|
129
|
+
//# sourceMappingURL=scroll-to-top.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scroll-to-top.js","sourceRoot":"","sources":["../../../../src/components/ui/scroll-to-top/scroll-to-top.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EACL,WAAW,EACX,SAAS,EACT,QAAQ,GAOT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,GAAG,EAAqB,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEjC,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,SAAS;IACT,WAAW;IACX,SAAS;IACT,OAAO;IACP,OAAO;CACoB,CAAC;AAI9B,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,IAAI;IACJ,SAAS;IACT,IAAI;CACuB,CAAC;AAI9B,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,cAAc;IACd,aAAa;IACb,eAAe;IACf,QAAQ;CACmB,CAAC;AAI9B,MAAM,mBAAmB,GAAG,GAAG,CAC7B,0ZAA0Z,EAC1Z;IACE,QAAQ,EAAE;QACR,OAAO,EAAE;YACP,OAAO,EACL,0EAA0E;YAC5E,SAAS,EACP,kFAAkF;YAC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