@limetry/ui 1.2.49

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,152 @@
1
+ /**
2
+ * Navigation item model and active-route helpers for drawer / tab chrome.
3
+ *
4
+ * Path matching strips Expo / Next route-group segments (for example `/(app)`)
5
+ * so highlight logic works against public pathnames.
6
+ */
7
+
8
+ /**
9
+ * A single navigable link, optionally nested under a section.
10
+ */
11
+ export type NavItem = {
12
+ /**
13
+ * Destination path (may include route-group segments that are normalized away).
14
+ */
15
+ href: string
16
+ /**
17
+ * Human-readable label shown in drawers and tabs.
18
+ */
19
+ label: string
20
+ /**
21
+ * Optional icon id consumed by drawer `renderIcon` callbacks.
22
+ */
23
+ icon?: string
24
+ /**
25
+ * When true, the item is eligible for mobile bottom-tab presentation.
26
+ */
27
+ mobileTab?: boolean
28
+ /**
29
+ * Nested items (for example Docs sections). Drawers render an expand/collapse group.
30
+ */
31
+ children?: NavItem[]
32
+ }
33
+
34
+ /**
35
+ * Strips Expo / Next route-group segments like `/(app)` from a path.
36
+ *
37
+ * @param pathname - Raw router pathname that may include parenthesized groups.
38
+ * @returns Normalized path beginning with `/`, or `"/"` when empty after stripping.
39
+ */
40
+ export function normalizePathname(pathname: string): string {
41
+ const normalized = pathname.replace(/\/\([^/]+\)/g, "")
42
+ return normalized.length > 0 ? normalized : "/"
43
+ }
44
+
45
+ /**
46
+ * Returns true when pathname matches the item href or a nested child path.
47
+ *
48
+ * Root (`"/"`) matches only the exact root path. Other targets match equality
49
+ * or a prefix followed by `/`.
50
+ *
51
+ * @param pathname - Current location pathname.
52
+ * @param href - Nav item href to test.
53
+ * @returns Whether the pathname is active for that href.
54
+ */
55
+ export function isNavItemActive(pathname: string, href: string): boolean {
56
+ const path = normalizePathname(pathname)
57
+ const target = normalizePathname(href)
58
+ if (target === "/") {
59
+ return path === "/"
60
+ }
61
+ return path === target || path.startsWith(`${target}/`)
62
+ }
63
+
64
+ /**
65
+ * True when pathname matches this item or any descendant.
66
+ *
67
+ * @param pathname - Current location pathname.
68
+ * @param item - Nav item that may contain nested `children`.
69
+ * @returns Whether this item or a child is active for the pathname.
70
+ */
71
+ export function isNavItemOrChildActive(pathname: string, item: NavItem): boolean {
72
+ if (isNavItemActive(pathname, item.href)) {
73
+ return true
74
+ }
75
+ return item.children?.some((child) => isNavItemOrChildActive(pathname, child)) ?? false
76
+ }
77
+
78
+ /**
79
+ * Returns the href of the single most specific nav item for pathname (longest match;
80
+ * deepest item wins ties). Used so only one drawer row gets active highlight.
81
+ *
82
+ * @param pathname - Current location pathname.
83
+ * @param items - Top-level nav tree to search.
84
+ * @returns Winning item `href`, or `null` when nothing matches.
85
+ */
86
+ export function findActiveNavHref(pathname: string, items: NavItem[]): string | null {
87
+ let bestHref: string | null = null
88
+ let bestLength = -1
89
+ let bestDepth = -1
90
+
91
+ const walk = (list: NavItem[], depth: number): void => {
92
+ for (const item of list) {
93
+ if (isNavItemActive(pathname, item.href)) {
94
+ const length = normalizePathname(item.href).length
95
+ if (length > bestLength || (length === bestLength && depth > bestDepth)) {
96
+ bestLength = length
97
+ bestDepth = depth
98
+ bestHref = item.href
99
+ }
100
+ }
101
+ if (item.children) {
102
+ walk(item.children, depth + 1)
103
+ }
104
+ }
105
+ }
106
+
107
+ walk(items, 0)
108
+ return bestHref
109
+ }
110
+
111
+ /**
112
+ * True when this specific NavItem is the single active highlighted leaf/target for pathname.
113
+ * If this item is a section/folder container and has an active child, it returns false so
114
+ * only the specific child page gets the active highlight.
115
+ *
116
+ * @param pathname - Current location pathname.
117
+ * @param item - Candidate nav item.
118
+ * @param activeHref - Result of {@link findActiveNavHref}, or `null` when none.
119
+ * @returns Whether this item alone should receive the active highlight styles.
120
+ */
121
+ export function isItemHighlighted(
122
+ pathname: string,
123
+ item: NavItem,
124
+ activeHref: string | null,
125
+ ): boolean {
126
+ if (activeHref === null) {
127
+ return false
128
+ }
129
+ const matches = normalizePathname(item.href) === normalizePathname(activeHref)
130
+ if (!matches) {
131
+ return false
132
+ }
133
+ const hasActiveChild =
134
+ item.children?.some((child) => isNavItemOrChildActive(pathname, child)) ?? false
135
+ return !hasActiveChild
136
+ }
137
+
138
+ /**
139
+ * True when this href is the single highlighted drawer item for pathname.
140
+ *
141
+ * @param pathname - Current location pathname.
142
+ * @param href - Href to compare against the winning active item.
143
+ * @param items - Top-level nav tree used to resolve the active href.
144
+ * @returns Whether `href` equals the single highlighted nav href.
145
+ */
146
+ export function isHighlightedNavItem(pathname: string, href: string, items: NavItem[]): boolean {
147
+ const activeHref = findActiveNavHref(pathname, items)
148
+ if (activeHref === null) {
149
+ return false
150
+ }
151
+ return normalizePathname(href) === normalizePathname(activeHref)
152
+ }
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Shared Tailwind / NativeWind theme for `\@limetry/ui` and `\@limetry/app`.
3
+ *
4
+ * Scans this package and the Expo app sources; extends brand, surface, and
5
+ * semantic color tokens used by the component library.
6
+ */
7
+
8
+ // @ts-expect-error nativewind preset has no type declarations in this package
9
+ import nativewindPreset from "nativewind/preset"
10
+ import type { Config } from "tailwindcss"
11
+
12
+ /**
13
+ * Default Tailwind config consumed by NativeWind-powered Limetry packages.
14
+ */
15
+ const config: Config = {
16
+ darkMode: "class",
17
+ content: [
18
+ "./src/**/*.{js,ts,jsx,tsx}",
19
+ "../app/src/**/*.{js,ts,jsx,tsx}",
20
+ ],
21
+ presets: [nativewindPreset],
22
+ theme: {
23
+ extend: {
24
+ colors: {
25
+ border: {
26
+ DEFAULT: "#e2e8f0",
27
+ dark: "#1e293b",
28
+ },
29
+ input: {
30
+ DEFAULT: "#e2e8f0",
31
+ dark: "#1e293b",
32
+ },
33
+ ring: {
34
+ DEFAULT: "#10b981",
35
+ },
36
+ background: {
37
+ DEFAULT: "#f8fafc",
38
+ dark: "#070d1a",
39
+ },
40
+ foreground: {
41
+ DEFAULT: "#0f172a",
42
+ dark: "#f1f5f9",
43
+ },
44
+ primary: {
45
+ DEFAULT: "#10b981",
46
+ foreground: "#ffffff",
47
+ },
48
+ secondary: {
49
+ DEFAULT: "#f1f5f9",
50
+ foreground: "#0f172a",
51
+ dark: "#1e293b",
52
+ "dark-foreground": "#f1f5f9",
53
+ },
54
+ destructive: {
55
+ DEFAULT: "#ef4444",
56
+ foreground: "#ffffff",
57
+ },
58
+ muted: {
59
+ DEFAULT: "#f1f5f9",
60
+ foreground: "#64748b",
61
+ dark: "#1e293b",
62
+ "dark-foreground": "#94a3b8",
63
+ },
64
+ accent: {
65
+ DEFAULT: "#10b981",
66
+ foreground: "#ffffff",
67
+ },
68
+ card: {
69
+ DEFAULT: "#ffffff",
70
+ foreground: "#0f172a",
71
+ dark: "#0d1525",
72
+ "dark-foreground": "#f1f5f9",
73
+ },
74
+ brand: {
75
+ DEFAULT: "#10b981",
76
+ dark: "#059669",
77
+ light: "#34d399",
78
+ },
79
+ surface: {
80
+ DEFAULT: "#f8fafc",
81
+ elevated: "#ffffff",
82
+ border: "#e2e8f0",
83
+ dark: "#0d1525",
84
+ "dark-elevated": "#1e293b",
85
+ "dark-border": "#1e293b",
86
+ },
87
+ },
88
+ fontFamily: {
89
+ sans: ["Inter", "system-ui", "sans-serif"],
90
+ mono: ["JetBrains Mono", "Menlo", "monospace"],
91
+ },
92
+ },
93
+ },
94
+ plugins: [],
95
+ }
96
+
97
+ export default config