@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,143 @@
1
+ /**
2
+ * Labeled text fields and form section headings for NativeWind forms.
3
+ */
4
+
5
+ import type { ReactNode } from "react"
6
+ import { Text, TextInput, type TextInputProps,View } from "react-native"
7
+
8
+ import { cn } from "../lib/cn"
9
+
10
+ /**
11
+ * Props for {@link Input}, extending React Native `TextInputProps`.
12
+ */
13
+ type InputProps = TextInputProps & {
14
+ /**
15
+ * Optional field label rendered above the control.
16
+ */
17
+ label?: string
18
+ /**
19
+ * Helper text shown when `error` is absent.
20
+ */
21
+ hint?: string
22
+ /**
23
+ * Validation message; when set, overrides `hint` and styles the border red.
24
+ */
25
+ error?: string
26
+ /**
27
+ * Extra classes on the outer field wrapper.
28
+ */
29
+ containerClassName?: string
30
+ /**
31
+ * Extra classes on the `TextInput`.
32
+ */
33
+ className?: string
34
+ }
35
+
36
+ /**
37
+ * Single-line (or host-controlled) text input with label, hint, and error.
38
+ *
39
+ * @param props - Label/hint/error, container classes, and TextInput props.
40
+ * @returns A labeled field column.
41
+ */
42
+ export function Input({
43
+ label,
44
+ hint,
45
+ error,
46
+ containerClassName,
47
+ className,
48
+ editable = true,
49
+ ...props
50
+ }: InputProps): React.JSX.Element {
51
+ return (
52
+ <View className={cn("mb-4", containerClassName)}>
53
+ {label ? (
54
+ <Text className="mb-2 text-sm font-medium text-slate-900 dark:text-slate-100">{label}</Text>
55
+ ) : null}
56
+ <TextInput
57
+ className={cn(
58
+ "rounded-xl border border-slate-200 bg-slate-50 px-4 py-3 text-base text-slate-900 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-100",
59
+ !editable && "opacity-60",
60
+ error && "border-red-500 dark:border-red-500",
61
+ className,
62
+ )}
63
+ editable={editable}
64
+ placeholderTextColor="#94a3b8"
65
+ {...props}
66
+ />
67
+ {error ? (
68
+ <Text className="mt-1.5 text-xs text-red-500 dark:text-red-400">{error}</Text>
69
+ ) : hint ? (
70
+ <Text className="mt-1.5 text-xs text-slate-500 dark:text-slate-400">{hint}</Text>
71
+ ) : null}
72
+ </View>
73
+ )
74
+ }
75
+
76
+ /**
77
+ * Props for {@link TextArea}.
78
+ */
79
+ type TextAreaProps = InputProps & {
80
+ /**
81
+ * Approximate visible line count (`numberOfLines`); defaults to `4`.
82
+ */
83
+ rows?: number
84
+ }
85
+
86
+ /**
87
+ * Multiline text field built on {@link Input} with mono-friendly styling.
88
+ *
89
+ * @param props - Input props plus optional `rows`.
90
+ * @returns A multiline labeled field.
91
+ */
92
+ export function TextArea({
93
+ label,
94
+ hint,
95
+ error,
96
+ containerClassName,
97
+ className,
98
+ rows = 4,
99
+ ...props
100
+ }: TextAreaProps): React.JSX.Element {
101
+ return (
102
+ <Input
103
+ containerClassName={containerClassName}
104
+ error={error}
105
+ hint={hint}
106
+ label={label}
107
+ multiline
108
+ numberOfLines={rows}
109
+ className={cn("min-h-[100px] py-3 font-mono text-sm", className)}
110
+ textAlignVertical="top"
111
+ {...props}
112
+ />
113
+ )
114
+ }
115
+
116
+ /**
117
+ * Props for {@link FormSection}.
118
+ */
119
+ type FormSectionProps = {
120
+ /**
121
+ * Section heading above the child fields.
122
+ */
123
+ title: string
124
+ /**
125
+ * Field controls rendered under the title.
126
+ */
127
+ children: ReactNode
128
+ }
129
+
130
+ /**
131
+ * Groups related form controls under a section title.
132
+ *
133
+ * @param props - Title and child fields.
134
+ * @returns A titled form block.
135
+ */
136
+ export function FormSection({ title, children }: FormSectionProps): React.JSX.Element {
137
+ return (
138
+ <View className="mb-6">
139
+ <Text className="mb-4 text-lg font-semibold text-slate-900 dark:text-slate-100">{title}</Text>
140
+ {children}
141
+ </View>
142
+ )
143
+ }
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Page chrome helpers: headers, empty placeholders, and alert banners.
3
+ */
4
+
5
+ import type { ReactNode } from "react"
6
+ import { Text, View } from "react-native"
7
+
8
+ import { cn } from "../lib/cn"
9
+
10
+ /**
11
+ * Props for {@link PageHeader}.
12
+ */
13
+ type PageHeaderProps = {
14
+ /**
15
+ * Page title.
16
+ */
17
+ title: string
18
+ /**
19
+ * Optional subtitle under the title.
20
+ */
21
+ description?: string
22
+ /**
23
+ * Optional trailing action (for example a primary button).
24
+ */
25
+ action?: ReactNode
26
+ /**
27
+ * Extra classes on the header row.
28
+ */
29
+ className?: string
30
+ }
31
+
32
+ /**
33
+ * Top-of-page title row with optional description and action slot.
34
+ *
35
+ * @param props - Title, description, action, and className.
36
+ * @returns A page header row.
37
+ */
38
+ export function PageHeader({
39
+ title,
40
+ description,
41
+ action,
42
+ className,
43
+ }: PageHeaderProps): React.JSX.Element {
44
+ return (
45
+ <View className={cn("mb-6 flex-row items-start justify-between", className)}>
46
+ <View className="flex-1 pr-4">
47
+ <Text className="text-2xl font-bold tracking-tight text-slate-900 dark:text-slate-100 md:text-3xl">
48
+ {title}
49
+ </Text>
50
+ {description ? (
51
+ <Text className="mt-1 text-base text-slate-500 dark:text-slate-400">{description}</Text>
52
+ ) : null}
53
+ </View>
54
+ {action}
55
+ </View>
56
+ )
57
+ }
58
+
59
+ /**
60
+ * Props for {@link EmptyState}.
61
+ */
62
+ type EmptyStateProps = {
63
+ /**
64
+ * Empty-state heading.
65
+ */
66
+ title: string
67
+ /**
68
+ * Supporting explanation centered under the title.
69
+ */
70
+ description: string
71
+ /**
72
+ * Optional CTA rendered below the description.
73
+ */
74
+ action?: ReactNode
75
+ }
76
+
77
+ /**
78
+ * Dashed placeholder for lists or tables with no rows yet.
79
+ *
80
+ * @param props - Title, description, and optional action.
81
+ * @returns A centered empty-state block.
82
+ */
83
+ export function EmptyState({
84
+ title,
85
+ description,
86
+ action,
87
+ }: EmptyStateProps): React.JSX.Element {
88
+ return (
89
+ <View className="items-center rounded-2xl border border-dashed border-slate-200 bg-white px-6 py-16 dark:border-slate-700 dark:bg-slate-900">
90
+ <Text className="text-lg font-semibold text-slate-900 dark:text-slate-100">{title}</Text>
91
+ <Text className="mt-2 max-w-sm text-center text-sm text-slate-500 dark:text-slate-400">
92
+ {description}
93
+ </Text>
94
+ {action ? <View className="mt-6">{action}</View> : null}
95
+ </View>
96
+ )
97
+ }
98
+
99
+ /**
100
+ * Props for {@link AlertBanner}.
101
+ */
102
+ type AlertBannerProps = {
103
+ /**
104
+ * Banner message text.
105
+ */
106
+ message: string
107
+ /**
108
+ * Semantic coloring; defaults to `"info"`.
109
+ */
110
+ variant?: "success" | "error" | "info"
111
+ }
112
+
113
+ const alertStyles = {
114
+ success: "border-emerald-500/30 bg-emerald-500/10",
115
+ error: "border-red-500/30 bg-red-500/10",
116
+ info: "border-emerald-500/30 bg-emerald-500/10",
117
+ }
118
+
119
+ const alertTextStyles = {
120
+ success: "text-emerald-600 dark:text-emerald-400",
121
+ error: "text-red-600 dark:text-red-400",
122
+ info: "text-emerald-600 dark:text-emerald-400",
123
+ }
124
+
125
+ /**
126
+ * Inline status banner for success, error, or informational messages.
127
+ *
128
+ * @param props - Message and optional variant.
129
+ * @returns A bordered alert strip.
130
+ */
131
+ export function AlertBanner({
132
+ message,
133
+ variant = "info",
134
+ }: AlertBannerProps): React.JSX.Element {
135
+ return (
136
+ <View className={cn("mb-4 rounded-xl border px-4 py-3", alertStyles[variant])}>
137
+ <Text className={cn("text-sm font-medium", alertTextStyles[variant])}>
138
+ {message}
139
+ </Text>
140
+ </View>
141
+ )
142
+ }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Metric summary card with optional trend change and trailing icon.
3
+ */
4
+
5
+ import type { ReactNode } from "react"
6
+ import { Text, View } from "react-native"
7
+
8
+ import { cn } from "../lib/cn"
9
+
10
+ /**
11
+ * Props for {@link StatCard}.
12
+ */
13
+ type StatCardProps = {
14
+ /**
15
+ * Short metric label above the value.
16
+ */
17
+ label: string
18
+ /**
19
+ * Primary numeric or string metric.
20
+ */
21
+ value: string | number
22
+ /**
23
+ * Optional change caption under the value (for example `"+12%"`).
24
+ */
25
+ change?: string
26
+ /**
27
+ * Colors the change caption; defaults to `"neutral"`.
28
+ */
29
+ trend?: "up" | "down" | "neutral"
30
+ /**
31
+ * Optional icon rendered opposite the label.
32
+ */
33
+ icon?: ReactNode
34
+ /**
35
+ * Extra classes on the card surface.
36
+ */
37
+ className?: string
38
+ }
39
+
40
+ const trendColors = {
41
+ up: "text-emerald-500 dark:text-emerald-400",
42
+ down: "text-red-500 dark:text-red-400",
43
+ neutral: "text-slate-500 dark:text-slate-400",
44
+ }
45
+
46
+ /**
47
+ * Dashboard metric tile showing label, value, and optional trend text.
48
+ *
49
+ * @param props - Label, value, optional change/trend/icon, and className.
50
+ * @returns A bordered metric card.
51
+ */
52
+ export function StatCard({
53
+ label,
54
+ value,
55
+ change,
56
+ trend = "neutral",
57
+ icon,
58
+ className,
59
+ }: StatCardProps): React.JSX.Element {
60
+ return (
61
+ <View
62
+ className={cn(
63
+ "rounded-2xl border border-slate-200 bg-white p-5 dark:border-slate-800 dark:bg-slate-900",
64
+ className,
65
+ )}
66
+ >
67
+ <View className="mb-3 flex-row items-center justify-between">
68
+ <Text className="text-sm font-medium text-slate-500 dark:text-slate-400">{label}</Text>
69
+ {icon ? <View className="opacity-80">{icon}</View> : null}
70
+ </View>
71
+ <Text className="text-3xl font-bold tracking-tight text-slate-900 dark:text-slate-100">
72
+ {value}
73
+ </Text>
74
+ {change ? (
75
+ <Text className={cn("mt-2 text-xs font-medium", trendColors[trend])}>
76
+ {change}
77
+ </Text>
78
+ ) : null}
79
+ </View>
80
+ )
81
+ }
package/src/global.css ADDED
@@ -0,0 +1,82 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
4
+
5
+ @layer base {
6
+ :root {
7
+ --background: 0 0% 100%;
8
+ --foreground: 222 47% 11%;
9
+ --card: 0 0% 100%;
10
+ --card-foreground: 222 47% 11%;
11
+ --popover: 0 0% 100%;
12
+ --popover-foreground: 222 47% 11%;
13
+ --muted: 210 40% 96%;
14
+ --muted-foreground: 215 16% 47%;
15
+ --accent: 160 84% 39%;
16
+ --accent-foreground: 0 0% 100%;
17
+ --destructive: 0 72% 51%;
18
+ --destructive-foreground: 0 0% 100%;
19
+ --border: 214 32% 91%;
20
+ --input: 214 32% 91%;
21
+ --primary: 160 84% 39%;
22
+ --primary-foreground: 0 0% 100%;
23
+ --secondary: 210 40% 96%;
24
+ --secondary-foreground: 222 47% 11%;
25
+ --ring: 160 84% 39%;
26
+ --surface: 210 40% 98%;
27
+ --surface-elevated: 0 0% 100%;
28
+ --surface-border: 214 32% 91%;
29
+ }
30
+
31
+ .dark {
32
+ --background: 222 47% 6%;
33
+ --foreground: 210 40% 98%;
34
+ --card: 222 47% 9%;
35
+ --card-foreground: 210 40% 98%;
36
+ --popover: 222 47% 9%;
37
+ --popover-foreground: 210 40% 98%;
38
+ --muted: 217 33% 14%;
39
+ --muted-foreground: 215 20% 65%;
40
+ --accent: 160 84% 39%;
41
+ --accent-foreground: 210 40% 98%;
42
+ --destructive: 0 72% 51%;
43
+ --destructive-foreground: 210 40% 98%;
44
+ --border: 217 33% 18%;
45
+ --input: 217 33% 18%;
46
+ --primary: 160 84% 39%;
47
+ --primary-foreground: 222 47% 6%;
48
+ --secondary: 217 33% 14%;
49
+ --secondary-foreground: 210 40% 98%;
50
+ --ring: 160 84% 39%;
51
+ --surface: 222 47% 9%;
52
+ --surface-elevated: 217 33% 14%;
53
+ --surface-border: 217 33% 18%;
54
+ }
55
+
56
+ @media (prefers-color-scheme: dark) {
57
+ :root {
58
+ --background: 222 47% 6%;
59
+ --foreground: 210 40% 98%;
60
+ --card: 222 47% 9%;
61
+ --card-foreground: 210 40% 98%;
62
+ --popover: 222 47% 9%;
63
+ --popover-foreground: 210 40% 98%;
64
+ --muted: 217 33% 14%;
65
+ --muted-foreground: 215 20% 65%;
66
+ --accent: 160 84% 39%;
67
+ --accent-foreground: 210 40% 98%;
68
+ --destructive: 0 72% 51%;
69
+ --destructive-foreground: 210 40% 98%;
70
+ --border: 217 33% 18%;
71
+ --input: 217 33% 18%;
72
+ --primary: 160 84% 39%;
73
+ --primary-foreground: 222 47% 6%;
74
+ --secondary: 217 33% 14%;
75
+ --secondary-foreground: 210 40% 98%;
76
+ --ring: 160 84% 39%;
77
+ --surface: 222 47% 9%;
78
+ --surface-elevated: 217 33% 14%;
79
+ --surface-border: 217 33% 18%;
80
+ }
81
+ }
82
+ }
package/src/index.ts ADDED
@@ -0,0 +1,39 @@
1
+ /// <reference types="react-native-css-interop/types" />
2
+
3
+ /**
4
+ * Shared NativeWind / React Native UI primitives for Limetry web and Expo apps
5
+ * (`\@limetry/ui`).
6
+ *
7
+ * Re-exports buttons, form controls, layout chrome, navigation helpers, and
8
+ * platform-resolved Lucide icon wrappers used by `\@limetry/web` and the Expo app.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+
13
+ export { Badge } from "./components/badge"
14
+ export { Button } from "./components/button"
15
+ export { Card, CardHeader } from "./components/card"
16
+ export {
17
+ ChartIcon,
18
+ HomeIcon,
19
+ KeyIcon,
20
+ MenuIcon,
21
+ RulesIcon,
22
+ ShieldIcon,
23
+ TerminalIcon,
24
+ UserIcon,
25
+ XIcon,
26
+ } from "./components/icons"
27
+ export { FormSection, Input, TextArea } from "./components/input"
28
+ export { AlertBanner, EmptyState, PageHeader } from "./components/page-header"
29
+ export { StatCard } from "./components/stat-card"
30
+ export { cn } from "./lib/cn"
31
+ export {
32
+ findActiveNavHref,
33
+ isHighlightedNavItem,
34
+ isItemHighlighted,
35
+ isNavItemActive,
36
+ isNavItemOrChildActive,
37
+ type NavItem,
38
+ normalizePathname,
39
+ } from "./navigation/types"
package/src/lib/cn.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { type ClassValue,clsx } from "clsx"
2
+ import { twMerge } from "tailwind-merge"
3
+
4
+ /**
5
+ * Merges conditional class names with Tailwind conflict resolution.
6
+ *
7
+ * Combines `clsx` for conditional lists and `tailwind-merge` so later utilities
8
+ * override earlier conflicting ones (for example `p-2` vs `p-4`).
9
+ *
10
+ * @param inputs - Class values accepted by `clsx` (strings, arrays, objects).
11
+ * @returns A single space-separated class string safe for NativeWind / Tailwind.
12
+ */
13
+ export function cn(...inputs: ClassValue[]): string {
14
+ return twMerge(clsx(inputs))
15
+ }
@@ -0,0 +1,72 @@
1
+ import { describe, expect, it } from "vitest"
2
+
3
+ import {
4
+ findActiveNavHref,
5
+ isItemHighlighted,
6
+ isNavItemOrChildActive,
7
+ type NavItem,
8
+ } from "./types.js"
9
+
10
+ describe("Navigation Types & Drawer Highlight", () => {
11
+ const docsTree: NavItem[] = [
12
+ { href: "/", label: "Home" },
13
+ { href: "/blog", label: "Blog" },
14
+ {
15
+ href: "/docs/introduction",
16
+ label: "Docs",
17
+ children: [
18
+ { href: "/docs/introduction", label: "Introduction" },
19
+ { href: "/docs/quick-start", label: "Quick Start" },
20
+ {
21
+ href: "/docs/server/self-hosting",
22
+ label: "Server",
23
+ children: [
24
+ { href: "/docs/server/self-hosting", label: "Self Hosted" },
25
+ { href: "/docs/server/docker", label: "Docker" },
26
+ ],
27
+ },
28
+ ],
29
+ },
30
+ ]
31
+
32
+ it("identifies deepest matching nav item href", () => {
33
+ const active = findActiveNavHref("/docs/server/self-hosting", docsTree)
34
+ expect(active).toBe("/docs/server/self-hosting")
35
+ })
36
+
37
+ it("highlights ONLY the specific leaf child and not the parent section with same href", () => {
38
+ const pathname = "/docs/server/self-hosting"
39
+ const activeHref = findActiveNavHref(pathname, docsTree)
40
+ expect(activeHref).toBe("/docs/server/self-hosting")
41
+
42
+ const docsRoot = docsTree[2]!
43
+ const serverFolder = docsRoot.children![2]!
44
+ const selfHostedPage = serverFolder.children![0]!
45
+ const dockerPage = serverFolder.children![1]!
46
+
47
+ // Docs root container
48
+ expect(isNavItemOrChildActive(pathname, docsRoot)).toBe(true)
49
+ expect(isItemHighlighted(pathname, docsRoot, activeHref)).toBe(false)
50
+
51
+ // Server folder (has same href as selfHostedPage)
52
+ expect(isNavItemOrChildActive(pathname, serverFolder)).toBe(true)
53
+ expect(isItemHighlighted(pathname, serverFolder, activeHref)).toBe(false)
54
+
55
+ // Self Hosted leaf page
56
+ expect(isNavItemOrChildActive(pathname, selfHostedPage)).toBe(true)
57
+ expect(isItemHighlighted(pathname, selfHostedPage, activeHref)).toBe(true)
58
+
59
+ // Docker sibling page
60
+ expect(isNavItemOrChildActive(pathname, dockerPage)).toBe(false)
61
+ expect(isItemHighlighted(pathname, dockerPage, activeHref)).toBe(false)
62
+ })
63
+
64
+ it("highlights the top-level route correctly when navigating to home or blog", () => {
65
+ const home = docsTree[0]!
66
+ const blog = docsTree[1]!
67
+
68
+ const blogActiveHref = findActiveNavHref("/blog", docsTree)
69
+ expect(isItemHighlighted("/blog", blog, blogActiveHref)).toBe(true)
70
+ expect(isItemHighlighted("/blog", home, blogActiveHref)).toBe(false)
71
+ })
72
+ })