@alepha/ui 0.10.6 → 0.10.7

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,121 @@
1
+ import {
2
+ IconAt,
3
+ IconCalendar,
4
+ IconClock,
5
+ IconColorPicker,
6
+ IconFile,
7
+ IconHash,
8
+ IconKey,
9
+ IconLetterCase,
10
+ IconLink,
11
+ IconList,
12
+ IconMail,
13
+ IconPalette,
14
+ IconPhone,
15
+ IconSelector,
16
+ IconToggleLeft,
17
+ } from "@tabler/icons-react";
18
+ import type { ReactNode } from "react";
19
+
20
+ /**
21
+ * Icon size presets following Mantine's size conventions
22
+ */
23
+ export const ICON_SIZES = {
24
+ xs: 12,
25
+ sm: 16,
26
+ md: 20,
27
+ lg: 24,
28
+ xl: 28,
29
+ } as const;
30
+
31
+ export type IconSize = keyof typeof ICON_SIZES;
32
+
33
+ /**
34
+ * Get the default icon for an input based on its type, format, or name.
35
+ */
36
+ export const getDefaultIcon = (params: {
37
+ type?: string;
38
+ format?: string;
39
+ name?: string;
40
+ isEnum?: boolean;
41
+ isArray?: boolean;
42
+ size?: IconSize;
43
+ }): ReactNode => {
44
+ const { type, format, name, isEnum, isArray, size = "sm" } = params;
45
+ const iconSize = ICON_SIZES[size];
46
+
47
+ // Format-based icons (highest priority)
48
+ if (format) {
49
+ switch (format) {
50
+ case "email":
51
+ return <IconMail size={iconSize} />;
52
+ case "url":
53
+ case "uri":
54
+ return <IconLink size={iconSize} />;
55
+ case "tel":
56
+ case "phone":
57
+ return <IconPhone size={iconSize} />;
58
+ case "date":
59
+ return <IconCalendar size={iconSize} />;
60
+ case "date-time":
61
+ return <IconCalendar size={iconSize} />;
62
+ case "time":
63
+ return <IconClock size={iconSize} />;
64
+ case "color":
65
+ return <IconColorPicker size={iconSize} />;
66
+ case "uuid":
67
+ return <IconKey size={iconSize} />;
68
+ }
69
+ }
70
+
71
+ // Name-based icons (medium priority)
72
+ if (name) {
73
+ const nameLower = name.toLowerCase();
74
+ if (nameLower.includes("password") || nameLower.includes("secret")) {
75
+ return <IconKey size={iconSize} />;
76
+ }
77
+ if (nameLower.includes("email") || nameLower.includes("mail")) {
78
+ return <IconMail size={iconSize} />;
79
+ }
80
+ if (nameLower.includes("url") || nameLower.includes("link")) {
81
+ return <IconLink size={iconSize} />;
82
+ }
83
+ if (nameLower.includes("phone") || nameLower.includes("tel")) {
84
+ return <IconPhone size={iconSize} />;
85
+ }
86
+ if (nameLower.includes("color")) {
87
+ return <IconPalette size={iconSize} />;
88
+ }
89
+ if (nameLower.includes("file") || nameLower.includes("upload")) {
90
+ return <IconFile size={iconSize} />;
91
+ }
92
+ if (nameLower.includes("date")) {
93
+ return <IconCalendar size={iconSize} />;
94
+ }
95
+ if (nameLower.includes("time")) {
96
+ return <IconClock size={iconSize} />;
97
+ }
98
+ }
99
+
100
+ // Type-based icons (lowest priority)
101
+ if (isEnum || isArray) {
102
+ return <IconSelector size={iconSize} />;
103
+ }
104
+
105
+ if (type) {
106
+ switch (type) {
107
+ case "boolean":
108
+ return <IconToggleLeft size={iconSize} />;
109
+ case "number":
110
+ case "integer":
111
+ return <IconHash size={iconSize} />;
112
+ case "array":
113
+ return <IconList size={iconSize} />;
114
+ case "string":
115
+ return <IconLetterCase size={iconSize} />;
116
+ }
117
+ }
118
+
119
+ // Default icon
120
+ return <IconAt size={iconSize} />;
121
+ };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Capitalizes the first letter of a string.
3
+ *
4
+ * @example
5
+ * capitalize("hello") // "Hello"
6
+ */
7
+ export const capitalize = (str: string): string => {
8
+ return str.charAt(0).toUpperCase() + str.slice(1);
9
+ };
10
+
11
+ /**
12
+ * Converts a path or identifier string into a pretty display name.
13
+ * Removes slashes and capitalizes the first letter.
14
+ *
15
+ * @example
16
+ * prettyName("/userName") // "UserName"
17
+ * prettyName("email") // "Email"
18
+ */
19
+ export const prettyName = (name: string): string => {
20
+ return capitalize(name.replaceAll("/", ""));
21
+ };