@motor-hero/ui-kit 0.18.0 → 0.20.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 +41 -0
- package/dist/components/theme-provider.d.ts +3 -1
- package/dist/components/theme-provider.d.ts.map +1 -1
- package/dist/hooks/use-company-subdomain.d.ts +10 -0
- package/dist/hooks/use-company-subdomain.d.ts.map +1 -0
- package/dist/index.cjs +104 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +88 -15
- package/dist/index.js.map +1 -1
- package/dist/lib/company-theme.d.ts +15 -0
- package/dist/lib/company-theme.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/components/theme-provider.tsx +18 -8
- package/src/hooks/use-company-subdomain.ts +51 -0
- package/src/index.ts +7 -0
- package/src/lib/company-theme.ts +54 -0
package/dist/index.js
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
// src/components/theme-provider.tsx
|
|
2
2
|
import { createContext, useContext, useEffect, useState } from "react";
|
|
3
|
+
|
|
4
|
+
// src/lib/company-theme.ts
|
|
5
|
+
var VAR_MAP = {
|
|
6
|
+
primary: "--color-primary",
|
|
7
|
+
primaryForeground: "--color-primary-foreground",
|
|
8
|
+
secondary: "--color-secondary",
|
|
9
|
+
secondaryForeground: "--color-secondary-foreground",
|
|
10
|
+
accent: "--color-accent",
|
|
11
|
+
accentForeground: "--color-accent-foreground",
|
|
12
|
+
ring: "--color-ring"
|
|
13
|
+
};
|
|
14
|
+
function definedTokens(tokens) {
|
|
15
|
+
if (!tokens) return {};
|
|
16
|
+
return Object.fromEntries(
|
|
17
|
+
Object.entries(tokens).filter(([, value]) => value != null)
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
function applyCompanyTheme(root, companyTheme, mode) {
|
|
21
|
+
const tokens = companyTheme ? mode === "dark" ? { ...companyTheme.light, ...definedTokens(companyTheme.dark) } : companyTheme.light : {};
|
|
22
|
+
for (const key of Object.keys(VAR_MAP)) {
|
|
23
|
+
const value = tokens[key];
|
|
24
|
+
if (value) root.style.setProperty(VAR_MAP[key], value);
|
|
25
|
+
else root.style.removeProperty(VAR_MAP[key]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/components/theme-provider.tsx
|
|
3
30
|
import { jsx } from "react/jsx-runtime";
|
|
4
31
|
var initialState = {
|
|
5
32
|
theme: "system",
|
|
@@ -10,6 +37,7 @@ function ThemeProvider({
|
|
|
10
37
|
children,
|
|
11
38
|
defaultTheme = "system",
|
|
12
39
|
storageKey = "ui-theme",
|
|
40
|
+
companyTheme,
|
|
13
41
|
...props
|
|
14
42
|
}) {
|
|
15
43
|
const [theme, setTheme] = useState(
|
|
@@ -17,14 +45,20 @@ function ThemeProvider({
|
|
|
17
45
|
);
|
|
18
46
|
useEffect(() => {
|
|
19
47
|
const root = window.document.documentElement;
|
|
20
|
-
|
|
48
|
+
const applyResolved = (resolved) => {
|
|
49
|
+
root.classList.remove("light", "dark");
|
|
50
|
+
root.classList.add(resolved);
|
|
51
|
+
applyCompanyTheme(root, companyTheme, resolved);
|
|
52
|
+
};
|
|
21
53
|
if (theme === "system") {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
54
|
+
const mql = window.matchMedia("(prefers-color-scheme: dark)");
|
|
55
|
+
applyResolved(mql.matches ? "dark" : "light");
|
|
56
|
+
const onChange = (e) => applyResolved(e.matches ? "dark" : "light");
|
|
57
|
+
mql.addEventListener("change", onChange);
|
|
58
|
+
return () => mql.removeEventListener("change", onChange);
|
|
25
59
|
}
|
|
26
|
-
|
|
27
|
-
}, [theme]);
|
|
60
|
+
applyResolved(theme);
|
|
61
|
+
}, [theme, companyTheme]);
|
|
28
62
|
const value = {
|
|
29
63
|
theme,
|
|
30
64
|
setTheme: (theme2) => {
|
|
@@ -42,6 +76,42 @@ function useTheme() {
|
|
|
42
76
|
return context;
|
|
43
77
|
}
|
|
44
78
|
|
|
79
|
+
// src/hooks/use-company-subdomain.ts
|
|
80
|
+
import { useState as useState2 } from "react";
|
|
81
|
+
function getSubdomain(hostname) {
|
|
82
|
+
const labels = hostname.split(".");
|
|
83
|
+
if (labels.length < 2) return void 0;
|
|
84
|
+
const first = labels[0];
|
|
85
|
+
if (!first || first === "www" || first === "localhost") return void 0;
|
|
86
|
+
return first;
|
|
87
|
+
}
|
|
88
|
+
function resolveOverride(storageKey) {
|
|
89
|
+
if (typeof window === "undefined") return void 0;
|
|
90
|
+
const params = new URLSearchParams(window.location.search);
|
|
91
|
+
if (params.has("company")) {
|
|
92
|
+
const value = params.get("company");
|
|
93
|
+
if (value) {
|
|
94
|
+
window.localStorage.setItem(storageKey, value);
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
window.localStorage.removeItem(storageKey);
|
|
98
|
+
return void 0;
|
|
99
|
+
}
|
|
100
|
+
return window.localStorage.getItem(storageKey) ?? void 0;
|
|
101
|
+
}
|
|
102
|
+
function useCompanySubdomain(opts = {}) {
|
|
103
|
+
const { enableOverride = false, overrideStorageKey = "company-subdomain" } = opts;
|
|
104
|
+
const [subdomain] = useState2(() => {
|
|
105
|
+
if (enableOverride) {
|
|
106
|
+
const override = resolveOverride(overrideStorageKey);
|
|
107
|
+
if (override) return override;
|
|
108
|
+
}
|
|
109
|
+
if (typeof window === "undefined") return void 0;
|
|
110
|
+
return getSubdomain(window.location.hostname);
|
|
111
|
+
});
|
|
112
|
+
return { subdomain };
|
|
113
|
+
}
|
|
114
|
+
|
|
45
115
|
// src/components/mode-toggle.tsx
|
|
46
116
|
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
|
|
47
117
|
import { Moon, Sun, Monitor } from "lucide-react";
|
|
@@ -860,7 +930,7 @@ function Toaster(props) {
|
|
|
860
930
|
|
|
861
931
|
// src/components/app-shell.tsx
|
|
862
932
|
import { ChevronLeft, ChevronRight, Menu } from "lucide-react";
|
|
863
|
-
import { useState as
|
|
933
|
+
import { useState as useState7 } from "react";
|
|
864
934
|
|
|
865
935
|
// src/components/sidebar-nav.tsx
|
|
866
936
|
import { Fragment as Fragment3 } from "react";
|
|
@@ -909,7 +979,7 @@ function SidebarNav({
|
|
|
909
979
|
// src/components/user-menu.tsx
|
|
910
980
|
import * as DropdownMenu2 from "@radix-ui/react-dropdown-menu";
|
|
911
981
|
import { LogOut, User } from "lucide-react";
|
|
912
|
-
import { useState as
|
|
982
|
+
import { useState as useState6 } from "react";
|
|
913
983
|
import { Drawer as DrawerPrimitive2 } from "vaul";
|
|
914
984
|
import { Fragment as Fragment5, jsx as jsx24, jsxs as jsxs20 } from "react/jsx-runtime";
|
|
915
985
|
function initials(user) {
|
|
@@ -930,7 +1000,7 @@ function UserMenu({
|
|
|
930
1000
|
align = "end"
|
|
931
1001
|
}) {
|
|
932
1002
|
const isDesktop = useIsDesktop();
|
|
933
|
-
const [open, setOpen] =
|
|
1003
|
+
const [open, setOpen] = useState6(false);
|
|
934
1004
|
const label = initials(user);
|
|
935
1005
|
const trigger = /* @__PURE__ */ jsx24(
|
|
936
1006
|
"button",
|
|
@@ -1095,8 +1165,8 @@ function AppShell({
|
|
|
1095
1165
|
defaultCollapsed = false,
|
|
1096
1166
|
children
|
|
1097
1167
|
}) {
|
|
1098
|
-
const [collapsed, setCollapsed] =
|
|
1099
|
-
const [mobileOpen, setMobileOpen] =
|
|
1168
|
+
const [collapsed, setCollapsed] = useState7(defaultCollapsed);
|
|
1169
|
+
const [mobileOpen, setMobileOpen] = useState7(false);
|
|
1100
1170
|
const nav = (isCollapsed, onNavigate) => /* @__PURE__ */ jsx25(
|
|
1101
1171
|
SidebarNav,
|
|
1102
1172
|
{
|
|
@@ -1185,7 +1255,7 @@ function AppShell({
|
|
|
1185
1255
|
// src/components/row-actions-menu.tsx
|
|
1186
1256
|
import * as DropdownMenu3 from "@radix-ui/react-dropdown-menu";
|
|
1187
1257
|
import { MoreVertical } from "lucide-react";
|
|
1188
|
-
import { useState as
|
|
1258
|
+
import { useState as useState8 } from "react";
|
|
1189
1259
|
import { Drawer as DrawerPrimitive3 } from "vaul";
|
|
1190
1260
|
import { Fragment as Fragment6, jsx as jsx26, jsxs as jsxs22 } from "react/jsx-runtime";
|
|
1191
1261
|
var triggerClass = "inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50";
|
|
@@ -1199,7 +1269,7 @@ function RowActionsMenu({
|
|
|
1199
1269
|
renderLink = defaultRenderLink
|
|
1200
1270
|
}) {
|
|
1201
1271
|
const isDesktop = useIsDesktop();
|
|
1202
|
-
const [open, setOpen] =
|
|
1272
|
+
const [open, setOpen] = useState8(false);
|
|
1203
1273
|
if (actions.length === 0) return null;
|
|
1204
1274
|
const trigger = /* @__PURE__ */ jsx26(
|
|
1205
1275
|
"button",
|
|
@@ -1316,9 +1386,9 @@ function extractApiError(err, fallbackMessage = "Ocorreu um erro inesperado.") {
|
|
|
1316
1386
|
}
|
|
1317
1387
|
|
|
1318
1388
|
// src/hooks/use-disclosure.ts
|
|
1319
|
-
import { useCallback, useState as
|
|
1389
|
+
import { useCallback, useState as useState9 } from "react";
|
|
1320
1390
|
function useDisclosure(initial = false) {
|
|
1321
|
-
const [open, setOpen] =
|
|
1391
|
+
const [open, setOpen] = useState9(initial);
|
|
1322
1392
|
const onOpen = useCallback(() => setOpen(true), []);
|
|
1323
1393
|
const onClose = useCallback(() => setOpen(false), []);
|
|
1324
1394
|
const onToggle = useCallback(() => setOpen((v) => !v), []);
|
|
@@ -1377,10 +1447,13 @@ export {
|
|
|
1377
1447
|
ThemeProvider,
|
|
1378
1448
|
Toaster,
|
|
1379
1449
|
UserMenu,
|
|
1450
|
+
applyCompanyTheme,
|
|
1380
1451
|
cn,
|
|
1381
1452
|
defaultRenderLink,
|
|
1382
1453
|
extractApiError,
|
|
1454
|
+
getSubdomain,
|
|
1383
1455
|
toast,
|
|
1456
|
+
useCompanySubdomain,
|
|
1384
1457
|
useCustomToast,
|
|
1385
1458
|
useDisclosure,
|
|
1386
1459
|
useIsDesktop,
|