@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.
- package/README.md +36 -0
- package/dist/index.cjs +464 -0
- package/dist/index.d.cts +504 -0
- package/dist/index.d.ts +504 -0
- package/dist/index.js +421 -0
- package/package.json +75 -0
- package/src/components/badge.tsx +66 -0
- package/src/components/button.tsx +117 -0
- package/src/components/card.tsx +89 -0
- package/src/components/drawer-menu.tsx +252 -0
- package/src/components/drawer-menu.types.ts +87 -0
- package/src/components/drawer-menu.web.tsx +348 -0
- package/src/components/icons.tsx +164 -0
- package/src/components/icons.web.tsx +141 -0
- package/src/components/input.tsx +143 -0
- package/src/components/page-header.tsx +142 -0
- package/src/components/stat-card.tsx +81 -0
- package/src/global.css +82 -0
- package/src/index.ts +39 -0
- package/src/lib/cn.ts +15 -0
- package/src/navigation/types.test.ts +72 -0
- package/src/navigation/types.ts +152 -0
- package/tailwind.config.ts +97 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bordered content card and title/description header for dashboard layouts.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { ReactNode } from "react"
|
|
6
|
+
import { Text, View, type ViewProps } from "react-native"
|
|
7
|
+
|
|
8
|
+
import { cn } from "../lib/cn"
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Props for {@link Card}.
|
|
12
|
+
*/
|
|
13
|
+
type CardProps = ViewProps & {
|
|
14
|
+
/**
|
|
15
|
+
* Card body content.
|
|
16
|
+
*/
|
|
17
|
+
children: ReactNode
|
|
18
|
+
/**
|
|
19
|
+
* Extra classes merged onto the card surface.
|
|
20
|
+
*/
|
|
21
|
+
className?: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Elevated surface container with border and padding.
|
|
26
|
+
*
|
|
27
|
+
* @param props - Children, className, and View props.
|
|
28
|
+
* @returns A styled card `View`.
|
|
29
|
+
*/
|
|
30
|
+
export function Card({ children, className, ...props }: CardProps): React.JSX.Element {
|
|
31
|
+
return (
|
|
32
|
+
<View
|
|
33
|
+
className={cn(
|
|
34
|
+
"rounded-2xl min-h-[88px] border border-slate-200 bg-white p-5 dark:border-slate-800 dark:bg-slate-900",
|
|
35
|
+
className,
|
|
36
|
+
)}
|
|
37
|
+
{...props}
|
|
38
|
+
>
|
|
39
|
+
{children}
|
|
40
|
+
</View>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Props for {@link CardHeader}.
|
|
46
|
+
*/
|
|
47
|
+
type CardHeaderProps = {
|
|
48
|
+
/**
|
|
49
|
+
* Primary card title.
|
|
50
|
+
*/
|
|
51
|
+
title: string
|
|
52
|
+
/**
|
|
53
|
+
* Optional supporting description under the title.
|
|
54
|
+
*/
|
|
55
|
+
description?: string
|
|
56
|
+
/**
|
|
57
|
+
* Optional action slot aligned to the trailing edge.
|
|
58
|
+
*/
|
|
59
|
+
action?: ReactNode
|
|
60
|
+
/**
|
|
61
|
+
* Extra classes on the header row.
|
|
62
|
+
*/
|
|
63
|
+
className?: string
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Title row for use inside {@link Card}, with optional description and action.
|
|
68
|
+
*
|
|
69
|
+
* @param props - Title, description, action, and className.
|
|
70
|
+
* @returns A header row suitable for card tops.
|
|
71
|
+
*/
|
|
72
|
+
export function CardHeader({
|
|
73
|
+
title,
|
|
74
|
+
description,
|
|
75
|
+
action,
|
|
76
|
+
className,
|
|
77
|
+
}: CardHeaderProps): React.JSX.Element {
|
|
78
|
+
return (
|
|
79
|
+
<View className={cn("mb-4 flex-row items-start justify-between", className)}>
|
|
80
|
+
<View className="flex-1 pr-3">
|
|
81
|
+
<Text className="text-lg font-semibold text-slate-900 dark:text-slate-100">{title}</Text>
|
|
82
|
+
{description ? (
|
|
83
|
+
<Text className="mt-1 text-sm text-slate-500 dark:text-slate-400">{description}</Text>
|
|
84
|
+
) : null}
|
|
85
|
+
</View>
|
|
86
|
+
{action}
|
|
87
|
+
</View>
|
|
88
|
+
)
|
|
89
|
+
}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Native drawer panel for Expo / mobile consumers.
|
|
3
|
+
*
|
|
4
|
+
* Positioned below the sticky header so the header (and its close control) stay
|
|
5
|
+
* active. Re-exports navigation helpers used by host apps.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { useState } from "react"
|
|
9
|
+
import { Pressable, Text, View } from "react-native"
|
|
10
|
+
|
|
11
|
+
import { cn } from "../lib/cn"
|
|
12
|
+
import {
|
|
13
|
+
findActiveNavHref,
|
|
14
|
+
isItemHighlighted,
|
|
15
|
+
isNavItemOrChildActive,
|
|
16
|
+
} from "../navigation/types"
|
|
17
|
+
import type { DrawerMenuProps, NavItem } from "./drawer-menu.types"
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
findActiveNavHref,
|
|
21
|
+
isHighlightedNavItem,
|
|
22
|
+
isItemHighlighted,
|
|
23
|
+
isNavItemActive,
|
|
24
|
+
isNavItemOrChildActive,
|
|
25
|
+
} from "../navigation/types"
|
|
26
|
+
export type { DrawerLinkProps, DrawerMenuProps, NavItem } from "./drawer-menu.types"
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Docs sidebar width used as the drawer floor on larger phones.
|
|
30
|
+
* Matches fumadocs `--fd-sidebar-width: 286px`.
|
|
31
|
+
*/
|
|
32
|
+
const DOCS_SIDEBAR_WIDTH = 286
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Props for a single recursive drawer row.
|
|
36
|
+
*/
|
|
37
|
+
type DrawerItemProps = {
|
|
38
|
+
/**
|
|
39
|
+
* Nav item (leaf or branch) to render.
|
|
40
|
+
*/
|
|
41
|
+
item: NavItem
|
|
42
|
+
/**
|
|
43
|
+
* Current location pathname.
|
|
44
|
+
*/
|
|
45
|
+
pathname: string
|
|
46
|
+
/**
|
|
47
|
+
* Winning active href from {@link findActiveNavHref}.
|
|
48
|
+
*/
|
|
49
|
+
activeHref: string | null
|
|
50
|
+
/**
|
|
51
|
+
* Nesting depth; used for indent / rail styling.
|
|
52
|
+
*/
|
|
53
|
+
depth: number
|
|
54
|
+
/**
|
|
55
|
+
* Injected host link component.
|
|
56
|
+
*/
|
|
57
|
+
LinkComponent: DrawerMenuProps["LinkComponent"]
|
|
58
|
+
/**
|
|
59
|
+
* Optional icon renderer from {@link DrawerMenuProps}.
|
|
60
|
+
*/
|
|
61
|
+
renderIcon?: DrawerMenuProps["renderIcon"]
|
|
62
|
+
/**
|
|
63
|
+
* Invoked after a leaf navigation so the drawer can close.
|
|
64
|
+
*/
|
|
65
|
+
onNavigate: () => void
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Renders one nav row, expanding nested children when the branch is active.
|
|
70
|
+
*
|
|
71
|
+
* @param props - Item, pathname, active href, depth, and host callbacks.
|
|
72
|
+
* @returns A link row or an expand/collapse branch.
|
|
73
|
+
*/
|
|
74
|
+
function DrawerNavItem({
|
|
75
|
+
item,
|
|
76
|
+
pathname,
|
|
77
|
+
activeHref,
|
|
78
|
+
depth,
|
|
79
|
+
LinkComponent,
|
|
80
|
+
renderIcon,
|
|
81
|
+
onNavigate,
|
|
82
|
+
}: DrawerItemProps): React.JSX.Element {
|
|
83
|
+
const hasChildren = Boolean(item.children && item.children.length > 0)
|
|
84
|
+
const branchActive = isNavItemOrChildActive(pathname, item)
|
|
85
|
+
const highlighted = isItemHighlighted(pathname, item, activeHref)
|
|
86
|
+
const ancestorActive = branchActive && !highlighted
|
|
87
|
+
const [expanded, setExpanded] = useState(branchActive)
|
|
88
|
+
|
|
89
|
+
if (hasChildren && item.children) {
|
|
90
|
+
const open = expanded || branchActive
|
|
91
|
+
return (
|
|
92
|
+
<View className="gap-0.5">
|
|
93
|
+
<View className="flex-row items-stretch gap-1">
|
|
94
|
+
<LinkComponent href={item.href} onPress={onNavigate}>
|
|
95
|
+
<View
|
|
96
|
+
className={cn(
|
|
97
|
+
"relative mb-1 flex-1 flex-row items-center justify-start gap-3 rounded-xl px-3 py-2.5",
|
|
98
|
+
highlighted
|
|
99
|
+
? "bg-emerald-500/15"
|
|
100
|
+
: ancestorActive
|
|
101
|
+
? ""
|
|
102
|
+
: "active:bg-slate-100 dark:active:bg-slate-800",
|
|
103
|
+
)}
|
|
104
|
+
>
|
|
105
|
+
{highlighted && depth > 0 ? (
|
|
106
|
+
<View
|
|
107
|
+
className="absolute bottom-1.5 top-1.5 w-px bg-emerald-500"
|
|
108
|
+
style={{ left: -9 }}
|
|
109
|
+
/>
|
|
110
|
+
) : null}
|
|
111
|
+
{item.icon && renderIcon ? renderIcon(item.icon, highlighted) : null}
|
|
112
|
+
<Text
|
|
113
|
+
className={cn(
|
|
114
|
+
"text-left text-sm font-medium",
|
|
115
|
+
highlighted
|
|
116
|
+
? "text-emerald-500"
|
|
117
|
+
: ancestorActive
|
|
118
|
+
? "font-semibold text-slate-900 dark:text-slate-100"
|
|
119
|
+
: "text-slate-600 dark:text-slate-400",
|
|
120
|
+
)}
|
|
121
|
+
>
|
|
122
|
+
{item.label}
|
|
123
|
+
</Text>
|
|
124
|
+
</View>
|
|
125
|
+
</LinkComponent>
|
|
126
|
+
<Pressable
|
|
127
|
+
accessibilityLabel={open ? `Collapse ${item.label}` : `Expand ${item.label}`}
|
|
128
|
+
accessibilityRole="button"
|
|
129
|
+
onPress={() => {
|
|
130
|
+
setExpanded((value) => !value)
|
|
131
|
+
}}
|
|
132
|
+
className="items-center justify-center rounded-xl px-2.5 active:bg-slate-100 dark:active:bg-slate-800"
|
|
133
|
+
>
|
|
134
|
+
<Text className={cn("text-slate-500", (ancestorActive || highlighted) && "text-emerald-500")}>
|
|
135
|
+
{open ? "▾" : "▸"}
|
|
136
|
+
</Text>
|
|
137
|
+
</Pressable>
|
|
138
|
+
</View>
|
|
139
|
+
{open ? (
|
|
140
|
+
<View className="ml-3 border-l border-slate-200 pl-2 dark:border-slate-700">
|
|
141
|
+
{item.children.map((child) => (
|
|
142
|
+
<DrawerNavItem
|
|
143
|
+
key={`${child.href}-${child.label}`}
|
|
144
|
+
item={child}
|
|
145
|
+
pathname={pathname}
|
|
146
|
+
activeHref={activeHref}
|
|
147
|
+
depth={depth + 1}
|
|
148
|
+
LinkComponent={LinkComponent}
|
|
149
|
+
renderIcon={renderIcon}
|
|
150
|
+
onNavigate={onNavigate}
|
|
151
|
+
/>
|
|
152
|
+
))}
|
|
153
|
+
</View>
|
|
154
|
+
) : null}
|
|
155
|
+
</View>
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<LinkComponent href={item.href} onPress={onNavigate}>
|
|
161
|
+
<View
|
|
162
|
+
className={cn(
|
|
163
|
+
"relative mb-1 flex-row items-center justify-start gap-3 rounded-xl px-3 py-2.5",
|
|
164
|
+
highlighted ? "bg-emerald-500/15" : "active:bg-slate-100 dark:active:bg-slate-800",
|
|
165
|
+
)}
|
|
166
|
+
>
|
|
167
|
+
{highlighted && depth > 0 ? (
|
|
168
|
+
<View
|
|
169
|
+
className="absolute bottom-1.5 top-1.5 w-px bg-emerald-500"
|
|
170
|
+
style={{ left: -9 }}
|
|
171
|
+
/>
|
|
172
|
+
) : null}
|
|
173
|
+
{item.icon && renderIcon ? renderIcon(item.icon, highlighted) : null}
|
|
174
|
+
<Text
|
|
175
|
+
className={cn(
|
|
176
|
+
"text-left text-sm font-medium",
|
|
177
|
+
depth > 0 && "text-[13px]",
|
|
178
|
+
highlighted ? "text-emerald-500" : "text-slate-600 dark:text-slate-400",
|
|
179
|
+
)}
|
|
180
|
+
>
|
|
181
|
+
{item.label}
|
|
182
|
+
</Text>
|
|
183
|
+
</View>
|
|
184
|
+
</LinkComponent>
|
|
185
|
+
)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* React Native drawer panel for Expo / mobile consumers.
|
|
190
|
+
* Positioned below the sticky header so the header (and its close control) stay active.
|
|
191
|
+
*
|
|
192
|
+
* @param props - Open state, nav items, pathname, and injected link/icon renderers.
|
|
193
|
+
* @returns The drawer overlay when open, otherwise `null`.
|
|
194
|
+
*/
|
|
195
|
+
export function DrawerMenu({
|
|
196
|
+
open,
|
|
197
|
+
onOpenChange,
|
|
198
|
+
items,
|
|
199
|
+
pathname,
|
|
200
|
+
LinkComponent,
|
|
201
|
+
renderIcon,
|
|
202
|
+
footer,
|
|
203
|
+
topOffset = 0,
|
|
204
|
+
className,
|
|
205
|
+
}: DrawerMenuProps): React.JSX.Element | null {
|
|
206
|
+
if (!open) {
|
|
207
|
+
return null
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const activeHref = findActiveNavHref(pathname, items)
|
|
211
|
+
|
|
212
|
+
const closeDrawer = (): void => {
|
|
213
|
+
setTimeout(() => onOpenChange(false), 0)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return (
|
|
217
|
+
<View
|
|
218
|
+
className="absolute inset-x-0 bottom-0 z-40 flex-row justify-end"
|
|
219
|
+
style={{ top: topOffset }}
|
|
220
|
+
pointerEvents="box-none"
|
|
221
|
+
>
|
|
222
|
+
<Pressable
|
|
223
|
+
accessibilityLabel="Close navigation menu"
|
|
224
|
+
className="absolute inset-0 bg-slate-900/50"
|
|
225
|
+
onPress={() => onOpenChange(false)}
|
|
226
|
+
/>
|
|
227
|
+
<View
|
|
228
|
+
className={cn(
|
|
229
|
+
"h-full border-l border-slate-200 bg-white p-4 shadow-xl dark:border-slate-800 dark:bg-slate-900",
|
|
230
|
+
className,
|
|
231
|
+
)}
|
|
232
|
+
style={{ width: "80%", maxWidth: DOCS_SIDEBAR_WIDTH }}
|
|
233
|
+
>
|
|
234
|
+
<View className="flex-1 gap-1">
|
|
235
|
+
{items.map((item) => (
|
|
236
|
+
<DrawerNavItem
|
|
237
|
+
key={`${item.href}-${item.label}`}
|
|
238
|
+
item={item}
|
|
239
|
+
pathname={pathname}
|
|
240
|
+
activeHref={activeHref}
|
|
241
|
+
depth={0}
|
|
242
|
+
LinkComponent={LinkComponent}
|
|
243
|
+
renderIcon={renderIcon}
|
|
244
|
+
onNavigate={closeDrawer}
|
|
245
|
+
/>
|
|
246
|
+
))}
|
|
247
|
+
</View>
|
|
248
|
+
{footer ? <View className="mt-auto items-stretch gap-2 pt-4">{footer}</View> : null}
|
|
249
|
+
</View>
|
|
250
|
+
</View>
|
|
251
|
+
)
|
|
252
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared prop contracts for platform-specific drawer menu implementations.
|
|
3
|
+
*
|
|
4
|
+
* Link and icon rendering are injected so `\@limetry/ui` never imports
|
|
5
|
+
* `next/link` or `expo-router`.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ComponentType, ReactNode } from "react"
|
|
9
|
+
|
|
10
|
+
import type { NavItem } from "../navigation/types"
|
|
11
|
+
|
|
12
|
+
export type { NavItem }
|
|
13
|
+
export { isNavItemActive } from "../navigation/types"
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Props accepted by the injected drawer link component.
|
|
17
|
+
*/
|
|
18
|
+
export type DrawerLinkProps = {
|
|
19
|
+
/**
|
|
20
|
+
* Destination href passed through to the host router link.
|
|
21
|
+
*/
|
|
22
|
+
href: string
|
|
23
|
+
/**
|
|
24
|
+
* Web-style click handler (Next / DOM drawer).
|
|
25
|
+
*/
|
|
26
|
+
onClick?: () => void
|
|
27
|
+
/**
|
|
28
|
+
* Native press handler (React Native drawer).
|
|
29
|
+
*/
|
|
30
|
+
onPress?: () => void
|
|
31
|
+
/**
|
|
32
|
+
* Link contents (typically a row of icon + label).
|
|
33
|
+
*/
|
|
34
|
+
children: ReactNode
|
|
35
|
+
/**
|
|
36
|
+
* Optional Tailwind / NativeWind class names for the link root.
|
|
37
|
+
*/
|
|
38
|
+
className?: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Props for {@link DrawerMenu} on web and native.
|
|
43
|
+
*/
|
|
44
|
+
export type DrawerMenuProps = {
|
|
45
|
+
/**
|
|
46
|
+
* Whether the drawer panel is visible / interactive.
|
|
47
|
+
*/
|
|
48
|
+
open: boolean
|
|
49
|
+
/**
|
|
50
|
+
* Called when the drawer should open or close.
|
|
51
|
+
*
|
|
52
|
+
* @param open - Desired open state.
|
|
53
|
+
*/
|
|
54
|
+
onOpenChange: (open: boolean) => void
|
|
55
|
+
/**
|
|
56
|
+
* Hierarchical nav items rendered in the drawer.
|
|
57
|
+
*/
|
|
58
|
+
items: NavItem[]
|
|
59
|
+
/**
|
|
60
|
+
* Current location pathname used for active highlighting.
|
|
61
|
+
*/
|
|
62
|
+
pathname: string
|
|
63
|
+
/**
|
|
64
|
+
* Injected so the UI package never imports next/link or expo-router.
|
|
65
|
+
*/
|
|
66
|
+
LinkComponent: ComponentType<DrawerLinkProps>
|
|
67
|
+
/**
|
|
68
|
+
* Maps an icon id from NavItem.icon to a rendered node.
|
|
69
|
+
*
|
|
70
|
+
* @param icon - Icon id from the nav item.
|
|
71
|
+
* @param active - Whether the row is the highlighted active leaf.
|
|
72
|
+
* @returns Node to render beside the label, or nothing when omitted.
|
|
73
|
+
*/
|
|
74
|
+
renderIcon?: (icon: string, active: boolean) => ReactNode
|
|
75
|
+
/**
|
|
76
|
+
* Optional footer content pinned below the nav list.
|
|
77
|
+
*/
|
|
78
|
+
footer?: ReactNode
|
|
79
|
+
/**
|
|
80
|
+
* Offset in pixels below a sticky header. Web default is 64.
|
|
81
|
+
*/
|
|
82
|
+
topOffset?: number
|
|
83
|
+
/**
|
|
84
|
+
* Extra class names applied to the drawer panel surface.
|
|
85
|
+
*/
|
|
86
|
+
className?: string
|
|
87
|
+
}
|