@snapdragonsnursery/react-components 1.0.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.
@@ -0,0 +1,83 @@
1
+ import { trackDarkModeToggle } from "./telemetry";
2
+
3
+ function ThemeToggle({ theme, setTheme }) {
4
+ // For accessibility
5
+ const options = [
6
+ {
7
+ value: "system",
8
+ label: "System",
9
+ icon: (
10
+ <svg
11
+ className="w-5 h-5"
12
+ fill="none"
13
+ stroke="currentColor"
14
+ viewBox="0 0 24 24"
15
+ >
16
+ <rect x="3" y="4" width="18" height="14" rx="2" strokeWidth="2" />
17
+ <path d="M8 20h8" strokeWidth="2" />
18
+ </svg>
19
+ ),
20
+ },
21
+ {
22
+ value: "light",
23
+ label: "Light",
24
+ icon: (
25
+ <svg
26
+ className="w-5 h-5"
27
+ fill="none"
28
+ stroke="currentColor"
29
+ viewBox="0 0 20 20"
30
+ >
31
+ <path
32
+ fillRule="evenodd"
33
+ d="M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z"
34
+ clipRule="evenodd"
35
+ />
36
+ </svg>
37
+ ),
38
+ },
39
+ {
40
+ value: "dark",
41
+ label: "Dark",
42
+ icon: (
43
+ <svg
44
+ className="w-5 h-5"
45
+ fill="none"
46
+ stroke="currentColor"
47
+ viewBox="0 0 20 20"
48
+ >
49
+ <path d="M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z" />
50
+ </svg>
51
+ ),
52
+ },
53
+ ];
54
+
55
+ const handleThemeChange = (newTheme) => {
56
+ const oldTheme = theme;
57
+ setTheme(newTheme);
58
+ trackDarkModeToggle(oldTheme, newTheme);
59
+ };
60
+
61
+ return (
62
+ <div className="flex justify-center items-center bg-gray-200 dark:bg-gray-700 rounded-full p-1.5 w-full">
63
+ {options.map((opt) => (
64
+ <button
65
+ key={opt.value}
66
+ onClick={() => handleThemeChange(opt.value)}
67
+ className={`flex-1 flex items-center justify-center h-10 rounded-full transition-all duration-200 focus:outline-none
68
+ ${
69
+ theme === opt.value
70
+ ? "bg-white dark:bg-gray-900 shadow text-blue-600 dark:text-yellow-400"
71
+ : "bg-transparent text-gray-700 dark:text-gray-300 hover:bg-gray-300 dark:hover:bg-gray-600"
72
+ }`}
73
+ title={opt.label + " mode"}
74
+ aria-pressed={theme === opt.value}
75
+ >
76
+ {opt.icon}
77
+ </button>
78
+ ))}
79
+ </div>
80
+ );
81
+ }
82
+
83
+ export default ThemeToggle;
package/src/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { default as AuthButtons } from "./AuthButtons";
2
+ export { default as ThemeToggle } from "./ThemeToggle";
3
+ export { default as ChildSearchModal } from "./ChildSearchModal";
4
+ export { configureTelemetry } from "./telemetry";
@@ -0,0 +1,49 @@
1
+ // Default stub implementations
2
+ let _trackAuthEvent = () => {};
3
+ let _trackError = () => {};
4
+ let _setUserContext = () => {};
5
+ let _clearUserContext = () => {};
6
+ let _trackDarkModeToggle = () => {};
7
+ let _trackEvent = () => {};
8
+
9
+ // Configuration function to override telemetry implementations
10
+ export function configureTelemetry({
11
+ trackAuthEvent,
12
+ trackError,
13
+ setUserContext,
14
+ clearUserContext,
15
+ trackDarkModeToggle,
16
+ trackEvent,
17
+ }) {
18
+ if (trackAuthEvent) _trackAuthEvent = trackAuthEvent;
19
+ if (trackError) _trackError = trackError;
20
+ if (setUserContext) _setUserContext = setUserContext;
21
+ if (clearUserContext) _clearUserContext = clearUserContext;
22
+ if (trackDarkModeToggle) _trackDarkModeToggle = trackDarkModeToggle;
23
+ if (trackEvent) _trackEvent = trackEvent;
24
+ }
25
+
26
+ // Export the configurable functions
27
+ export function trackAuthEvent(...args) {
28
+ return _trackAuthEvent(...args);
29
+ }
30
+
31
+ export function trackError(...args) {
32
+ return _trackError(...args);
33
+ }
34
+
35
+ export function setUserContext(...args) {
36
+ return _setUserContext(...args);
37
+ }
38
+
39
+ export function clearUserContext(...args) {
40
+ return _clearUserContext(...args);
41
+ }
42
+
43
+ export function trackDarkModeToggle(...args) {
44
+ return _trackDarkModeToggle(...args);
45
+ }
46
+
47
+ export function trackEvent(...args) {
48
+ return _trackEvent(...args);
49
+ }