@pelatform/starter.ui 0.1.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/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # Pelatform Starter
2
+
3
+ A part of SaaS starter kit for Pelatform applications.
4
+
5
+ [![Version](https://img.shields.io/npm/v/@pelatform/starter.svg)](https://www.npmjs.com/package/@pelatform/starter)
@@ -0,0 +1,62 @@
1
+ "use client";
2
+
3
+ // src/hooks/use-copy-to-clipboard.ts
4
+ import * as React from "react";
5
+ function useCopyToClipboard({ timeout = 2e3, onCopy } = {}) {
6
+ const [copied, setCopied] = React.useState(false);
7
+ const copy = React.useCallback(
8
+ (value) => {
9
+ if (typeof window === "undefined" || !navigator.clipboard?.writeText) {
10
+ console.warn("Clipboard API not supported in this environment");
11
+ return;
12
+ }
13
+ if (!value) {
14
+ console.warn("Cannot copy empty value to clipboard");
15
+ return;
16
+ }
17
+ navigator.clipboard.writeText(value).then(
18
+ () => {
19
+ setCopied(true);
20
+ if (onCopy) {
21
+ onCopy();
22
+ }
23
+ setTimeout(() => {
24
+ setCopied(false);
25
+ }, timeout);
26
+ },
27
+ (error) => {
28
+ console.error("Failed to copy text to clipboard:", error);
29
+ }
30
+ );
31
+ },
32
+ [timeout, onCopy]
33
+ );
34
+ return {
35
+ /** Whether text was recently copied (true for timeout duration) */
36
+ copied,
37
+ /** Function to copy text to clipboard */
38
+ copy
39
+ };
40
+ }
41
+
42
+ // src/hooks/use-is-mobile.ts
43
+ import * as React2 from "react";
44
+ var DEFAULT_MOBILE_BREAKPOINT = 1024;
45
+ function useIsMobile(breakpoint = DEFAULT_MOBILE_BREAKPOINT) {
46
+ const [isMobile, setIsMobile] = React2.useState(void 0);
47
+ React2.useEffect(() => {
48
+ const mql = window.matchMedia(`(max-width: ${breakpoint - 1}px)`);
49
+ const onChange = () => {
50
+ setIsMobile(window.innerWidth < breakpoint);
51
+ };
52
+ mql.addEventListener("change", onChange);
53
+ setIsMobile(window.innerWidth < breakpoint);
54
+ return () => mql.removeEventListener("change", onChange);
55
+ }, [breakpoint]);
56
+ return !!isMobile;
57
+ }
58
+
59
+ export {
60
+ useCopyToClipboard,
61
+ useIsMobile
62
+ };