@justin_evo/evo-ui 1.0.1
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/dist/Alert/Alert.d.ts +11 -0
- package/dist/AutoComplete/AutoComplete.d.ts +95 -0
- package/dist/Badge/Badge.d.ts +23 -0
- package/dist/Breadcrumb/Breadcrumb.d.ts +16 -0
- package/dist/Button/Button.d.ts +54 -0
- package/dist/Card/Card.d.ts +60 -0
- package/dist/Checkbox/Checkbox.d.ts +16 -0
- package/dist/CommandPalette/CommandPalette.d.ts +17 -0
- package/dist/Container/Container.d.ts +10 -0
- package/dist/Divider/Divider.d.ts +7 -0
- package/dist/Form/Form.d.ts +61 -0
- package/dist/Grid/Grid.d.ts +23 -0
- package/dist/ImageCropper/ImageCropper.d.ts +111 -0
- package/dist/Input/Input.d.ts +12 -0
- package/dist/Modal/Modal.d.ts +26 -0
- package/dist/Nav/Nav.d.ts +63 -0
- package/dist/Notification/Notification.d.ts +186 -0
- package/dist/Pagination/Pagination.d.ts +10 -0
- package/dist/Radio/Radio.d.ts +20 -0
- package/dist/RichTextArea/RichTextArea.d.ts +70 -0
- package/dist/Select/Select.d.ts +44 -0
- package/dist/Skeleton/Skeleton.d.ts +23 -0
- package/dist/Stack/Stack.d.ts +16 -0
- package/dist/Table/Table.d.ts +77 -0
- package/dist/Tabs/Tabs.d.ts +28 -0
- package/dist/Theme/ThemeProvider.d.ts +96 -0
- package/dist/Theme/ThemeToggle.d.ts +22 -0
- package/dist/Toggle/Toggle.d.ts +11 -0
- package/dist/Tooltip/Tooltip.d.ts +10 -0
- package/dist/TopNav/TopNav.d.ts +76 -0
- package/dist/TreeSelect/TreeSelect.d.ts +50 -0
- package/dist/declarations.d.ts +6 -0
- package/dist/evo-ui.css +1 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.es.js +5688 -0
- package/package.json +52 -0
- package/src/Alert/Alert.tsx +49 -0
- package/src/AutoComplete/AutoComplete.tsx +810 -0
- package/src/Badge/Badge.tsx +53 -0
- package/src/Breadcrumb/Breadcrumb.tsx +53 -0
- package/src/Button/Button.tsx +125 -0
- package/src/Card/Card.tsx +257 -0
- package/src/Checkbox/Checkbox.tsx +59 -0
- package/src/CommandPalette/CommandPalette.tsx +185 -0
- package/src/Container/Container.tsx +31 -0
- package/src/Divider/Divider.tsx +31 -0
- package/src/Form/Form.tsx +185 -0
- package/src/Grid/Grid.tsx +66 -0
- package/src/ImageCropper/ImageCropper.tsx +911 -0
- package/src/Input/Input.tsx +74 -0
- package/src/Modal/Modal.tsx +77 -0
- package/src/Nav/Nav.tsx +626 -0
- package/src/Notification/Notification.tsx +1503 -0
- package/src/Pagination/Pagination.tsx +76 -0
- package/src/Radio/Radio.tsx +69 -0
- package/src/RichTextArea/RichTextArea.tsx +869 -0
- package/src/Select/Select.tsx +515 -0
- package/src/Skeleton/Skeleton.tsx +70 -0
- package/src/Stack/Stack.tsx +52 -0
- package/src/Table/Table.tsx +335 -0
- package/src/Tabs/Tabs.tsx +90 -0
- package/src/Theme/ThemeProvider.tsx +253 -0
- package/src/Theme/ThemeToggle.tsx +79 -0
- package/src/Toggle/Toggle.tsx +48 -0
- package/src/Tooltip/Tooltip.tsx +38 -0
- package/src/TopNav/TopNav.tsx +994 -0
- package/src/TreeSelect/TreeSelect.tsx +825 -0
- package/src/css/alert.module.scss +93 -0
- package/src/css/autocomplete.module.scss +416 -0
- package/src/css/badge.module.scss +82 -0
- package/src/css/base/_color.scss +159 -0
- package/src/css/base/_theme.scss +237 -0
- package/src/css/base/_variables.scss +161 -0
- package/src/css/breadcrumb.module.scss +50 -0
- package/src/css/button.module.scss +385 -0
- package/src/css/card.module.scss +217 -0
- package/src/css/checkbox.module.scss +120 -0
- package/src/css/commandpalette.module.scss +211 -0
- package/src/css/container.module.scss +18 -0
- package/src/css/divider.module.scss +41 -0
- package/src/css/form.module.scss +245 -0
- package/src/css/imagecropper.module.scss +397 -0
- package/src/css/input.module.scss +89 -0
- package/src/css/modal.module.scss +105 -0
- package/src/css/nav.module.scss +339 -0
- package/src/css/notification.module.scss +691 -0
- package/src/css/pagination.module.scss +63 -0
- package/src/css/radio.module.scss +89 -0
- package/src/css/richtextarea.module.scss +307 -0
- package/src/css/select.module.scss +525 -0
- package/src/css/skeleton.module.scss +30 -0
- package/src/css/table.module.scss +386 -0
- package/src/css/tabs.module.scss +63 -0
- package/src/css/theme-toggle.module.scss +83 -0
- package/src/css/toggle.module.scss +54 -0
- package/src/css/tooltip.module.scss +97 -0
- package/src/css/topnav.module.scss +396 -0
- package/src/css/treeselect.module.scss +558 -0
- package/src/css/utilities/_borders.scss +111 -0
- package/src/css/utilities/_colors.scss +66 -0
- package/src/css/utilities/_effects.scss +216 -0
- package/src/css/utilities/_layout.scss +181 -0
- package/src/css/utilities/_position.scss +75 -0
- package/src/css/utilities/_sizing.scss +138 -0
- package/src/css/utilities/_spacing.scss +99 -0
- package/src/css/utilities/_typography.scss +121 -0
- package/src/css/utilities/index.scss +24 -0
- package/src/declarations.d.ts +6 -0
- package/src/index.ts +60 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import React, { useState, useEffect, useRef, useCallback } from 'react';
|
|
2
|
+
import styles from '../css/commandpalette.module.scss';
|
|
3
|
+
|
|
4
|
+
export interface CommandPaletteItem {
|
|
5
|
+
label: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
group?: string;
|
|
8
|
+
icon?: React.ReactNode;
|
|
9
|
+
shortcut?: string[];
|
|
10
|
+
onSelect: () => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface EvoCommandPaletteProps {
|
|
14
|
+
items: CommandPaletteItem[];
|
|
15
|
+
placeholder?: string;
|
|
16
|
+
open?: boolean;
|
|
17
|
+
onClose?: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Detect Mac for shortcut display only — keyboard handler uses ctrlKey||metaKey for both
|
|
21
|
+
const isMac = typeof navigator !== 'undefined' && /Mac|iPhone|iPad|iPod/.test(navigator.userAgent);
|
|
22
|
+
|
|
23
|
+
const SearchIcon = () => (
|
|
24
|
+
<svg viewBox="0 0 16 16" fill="none" width="16" height="16">
|
|
25
|
+
<circle cx="7" cy="7" r="4.5" stroke="currentColor" strokeWidth="1.5" />
|
|
26
|
+
<path d="M10.5 10.5L13 13" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
|
|
27
|
+
</svg>
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export const EvoCommandPalette = ({
|
|
31
|
+
items,
|
|
32
|
+
placeholder = 'Search commands…',
|
|
33
|
+
open: controlledOpen,
|
|
34
|
+
onClose,
|
|
35
|
+
}: EvoCommandPaletteProps) => {
|
|
36
|
+
const [internalOpen, setInternalOpen] = useState(false);
|
|
37
|
+
const [query, setQuery] = useState('');
|
|
38
|
+
const [activeIdx, setActiveIdx] = useState(0);
|
|
39
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
40
|
+
const listRef = useRef<HTMLDivElement>(null);
|
|
41
|
+
|
|
42
|
+
const isControlled = controlledOpen !== undefined;
|
|
43
|
+
const isOpen = isControlled ? controlledOpen : internalOpen;
|
|
44
|
+
|
|
45
|
+
const close = useCallback(() => {
|
|
46
|
+
if (!isControlled) setInternalOpen(false);
|
|
47
|
+
onClose?.();
|
|
48
|
+
}, [isControlled, onClose]);
|
|
49
|
+
|
|
50
|
+
// Ctrl+K (Windows/Linux) / ⌘+K (Mac)
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const handler = (e: KeyboardEvent) => {
|
|
53
|
+
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
if (!isControlled) setInternalOpen(o => !o);
|
|
56
|
+
}
|
|
57
|
+
if (e.key === 'Escape' && isOpen) close();
|
|
58
|
+
};
|
|
59
|
+
document.addEventListener('keydown', handler);
|
|
60
|
+
return () => document.removeEventListener('keydown', handler);
|
|
61
|
+
}, [isControlled, isOpen, close]);
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (isOpen) {
|
|
65
|
+
setQuery('');
|
|
66
|
+
setActiveIdx(0);
|
|
67
|
+
// Small delay so the element is mounted before focus
|
|
68
|
+
const t = setTimeout(() => inputRef.current?.focus(), 30);
|
|
69
|
+
return () => clearTimeout(t);
|
|
70
|
+
}
|
|
71
|
+
}, [isOpen]);
|
|
72
|
+
|
|
73
|
+
const filtered = query.trim()
|
|
74
|
+
? items.filter(item =>
|
|
75
|
+
item.label.toLowerCase().includes(query.toLowerCase()) ||
|
|
76
|
+
item.description?.toLowerCase().includes(query.toLowerCase()) ||
|
|
77
|
+
item.group?.toLowerCase().includes(query.toLowerCase())
|
|
78
|
+
)
|
|
79
|
+
: items;
|
|
80
|
+
|
|
81
|
+
const grouped = filtered.reduce<Record<string, CommandPaletteItem[]>>((acc, item) => {
|
|
82
|
+
const g = item.group ?? 'Actions';
|
|
83
|
+
if (!acc[g]) acc[g] = [];
|
|
84
|
+
acc[g].push(item);
|
|
85
|
+
return acc;
|
|
86
|
+
}, {});
|
|
87
|
+
|
|
88
|
+
const flat = Object.values(grouped).flat();
|
|
89
|
+
|
|
90
|
+
const scrollActiveIntoView = (idx: number) => {
|
|
91
|
+
const el = listRef.current?.querySelector(`[data-idx="${idx}"]`) as HTMLElement | null;
|
|
92
|
+
el?.scrollIntoView({ block: 'nearest' });
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const handleKeyDown = (e: React.KeyboardEvent) => {
|
|
96
|
+
if (e.key === 'ArrowDown') {
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
setActiveIdx(i => {
|
|
99
|
+
const next = Math.min(i + 1, flat.length - 1);
|
|
100
|
+
scrollActiveIntoView(next);
|
|
101
|
+
return next;
|
|
102
|
+
});
|
|
103
|
+
} else if (e.key === 'ArrowUp') {
|
|
104
|
+
e.preventDefault();
|
|
105
|
+
setActiveIdx(i => {
|
|
106
|
+
const next = Math.max(i - 1, 0);
|
|
107
|
+
scrollActiveIntoView(next);
|
|
108
|
+
return next;
|
|
109
|
+
});
|
|
110
|
+
} else if (e.key === 'Enter' && flat[activeIdx]) {
|
|
111
|
+
flat[activeIdx].onSelect();
|
|
112
|
+
close();
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
if (!isOpen) return null;
|
|
117
|
+
|
|
118
|
+
let globalIdx = 0;
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<div className={styles.overlay} onClick={close} role="dialog" aria-modal="true">
|
|
122
|
+
<div
|
|
123
|
+
className={styles.palette}
|
|
124
|
+
onClick={e => e.stopPropagation()}
|
|
125
|
+
onKeyDown={handleKeyDown}
|
|
126
|
+
>
|
|
127
|
+
<div className={styles.searchRow}>
|
|
128
|
+
<span className={styles.searchIconWrap}><SearchIcon /></span>
|
|
129
|
+
<input
|
|
130
|
+
ref={inputRef}
|
|
131
|
+
className={styles.searchInput}
|
|
132
|
+
placeholder={placeholder}
|
|
133
|
+
value={query}
|
|
134
|
+
onChange={e => { setQuery(e.target.value); setActiveIdx(0); }}
|
|
135
|
+
aria-label="Command search"
|
|
136
|
+
/>
|
|
137
|
+
<kbd className={styles.escBadge}>Esc</kbd>
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
<div className={styles.results} ref={listRef}>
|
|
141
|
+
{flat.length === 0 && (
|
|
142
|
+
<div className={styles.empty}>No results for “{query}”</div>
|
|
143
|
+
)}
|
|
144
|
+
{Object.entries(grouped).map(([group, groupItems]) => (
|
|
145
|
+
<div key={group} className={styles.group}>
|
|
146
|
+
<div className={styles.groupLabel}>{group}</div>
|
|
147
|
+
{groupItems.map(item => {
|
|
148
|
+
const idx = globalIdx++;
|
|
149
|
+
return (
|
|
150
|
+
<button
|
|
151
|
+
key={item.label}
|
|
152
|
+
data-idx={idx}
|
|
153
|
+
className={[styles.resultItem, idx === activeIdx ? styles.resultActive : '']
|
|
154
|
+
.filter(Boolean)
|
|
155
|
+
.join(' ')}
|
|
156
|
+
onClick={() => { item.onSelect(); close(); }}
|
|
157
|
+
onMouseEnter={() => setActiveIdx(idx)}
|
|
158
|
+
>
|
|
159
|
+
{item.icon && <span className={styles.resultIcon}>{item.icon}</span>}
|
|
160
|
+
<span className={styles.resultLabel}>{item.label}</span>
|
|
161
|
+
{item.description && <span className={styles.resultDesc}>{item.description}</span>}
|
|
162
|
+
{item.shortcut && (
|
|
163
|
+
<span className={styles.resultShortcut}>
|
|
164
|
+
{item.shortcut.map((k, i) => <kbd key={i}>{k}</kbd>)}
|
|
165
|
+
</span>
|
|
166
|
+
)}
|
|
167
|
+
</button>
|
|
168
|
+
);
|
|
169
|
+
})}
|
|
170
|
+
</div>
|
|
171
|
+
))}
|
|
172
|
+
</div>
|
|
173
|
+
|
|
174
|
+
<div className={styles.footer}>
|
|
175
|
+
<span><kbd>↑</kbd><kbd>↓</kbd> navigate</span>
|
|
176
|
+
<span><kbd>↵</kbd> select</span>
|
|
177
|
+
<span><kbd>Esc</kbd> close</span>
|
|
178
|
+
<span className={styles.footerRight}>
|
|
179
|
+
<kbd>{isMac ? '⌘' : 'Ctrl'}</kbd><kbd>K</kbd> toggle
|
|
180
|
+
</span>
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
);
|
|
185
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styles from '../css/container.module.scss';
|
|
3
|
+
|
|
4
|
+
type ContainerSize = 'sm' | 'md' | 'lg' | 'xl' | 'full';
|
|
5
|
+
|
|
6
|
+
interface EvoContainerProps {
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
size?: ContainerSize;
|
|
9
|
+
centered?: boolean;
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const EvoContainer = ({
|
|
14
|
+
children,
|
|
15
|
+
size = 'lg',
|
|
16
|
+
centered = true,
|
|
17
|
+
className = '',
|
|
18
|
+
}: EvoContainerProps) => (
|
|
19
|
+
<div
|
|
20
|
+
className={[
|
|
21
|
+
styles.container,
|
|
22
|
+
styles[size],
|
|
23
|
+
centered ? styles.centered : '',
|
|
24
|
+
className,
|
|
25
|
+
]
|
|
26
|
+
.filter(Boolean)
|
|
27
|
+
.join(' ')}
|
|
28
|
+
>
|
|
29
|
+
{children}
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import styles from '../css/divider.module.scss';
|
|
2
|
+
|
|
3
|
+
interface EvoDividerProps {
|
|
4
|
+
orientation?: 'horizontal' | 'vertical';
|
|
5
|
+
label?: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const EvoDivider = ({ orientation = 'horizontal', label, className = '' }: EvoDividerProps) => {
|
|
10
|
+
if (label) {
|
|
11
|
+
return (
|
|
12
|
+
<div className={`${styles.labeled} ${className}`}>
|
|
13
|
+
<div className={styles.line} />
|
|
14
|
+
<span className={styles.labelText}>{label}</span>
|
|
15
|
+
<div className={styles.line} />
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div
|
|
22
|
+
className={[
|
|
23
|
+
styles.divider,
|
|
24
|
+
orientation === 'vertical' ? styles.vertical : styles.horizontal,
|
|
25
|
+
className,
|
|
26
|
+
]
|
|
27
|
+
.filter(Boolean)
|
|
28
|
+
.join(' ')}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import React, { createContext, useContext, useId } from 'react';
|
|
2
|
+
import styles from '../css/form.module.scss';
|
|
3
|
+
|
|
4
|
+
type FormSize = 'sm' | 'md' | 'lg';
|
|
5
|
+
type FormLayout = 'vertical' | 'horizontal';
|
|
6
|
+
|
|
7
|
+
interface FormContextType {
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
size?: FormSize;
|
|
10
|
+
layout?: FormLayout;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const FormContext = createContext<FormContextType>({});
|
|
14
|
+
|
|
15
|
+
export const useFormContext = () => useContext(FormContext);
|
|
16
|
+
|
|
17
|
+
const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(' ');
|
|
18
|
+
|
|
19
|
+
// ---------- Root ----------
|
|
20
|
+
interface EvoFormProps extends React.FormHTMLAttributes<HTMLFormElement> {
|
|
21
|
+
children: React.ReactNode;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
size?: FormSize;
|
|
24
|
+
layout?: FormLayout;
|
|
25
|
+
maxWidth?: number | string;
|
|
26
|
+
className?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const EvoForm = ({
|
|
30
|
+
children,
|
|
31
|
+
disabled = false,
|
|
32
|
+
size = 'md',
|
|
33
|
+
layout = 'vertical',
|
|
34
|
+
maxWidth,
|
|
35
|
+
className = '',
|
|
36
|
+
style,
|
|
37
|
+
...rest
|
|
38
|
+
}: EvoFormProps) => (
|
|
39
|
+
<FormContext.Provider value={{ disabled, size, layout }}>
|
|
40
|
+
<form
|
|
41
|
+
className={cx(styles.form, styles[`form_${size}`], styles[`form_${layout}`], className)}
|
|
42
|
+
style={maxWidth !== undefined ? { maxWidth, ...style } : style}
|
|
43
|
+
{...rest}
|
|
44
|
+
>
|
|
45
|
+
{children}
|
|
46
|
+
</form>
|
|
47
|
+
</FormContext.Provider>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
// ---------- Header ----------
|
|
51
|
+
interface EvoFormHeaderProps {
|
|
52
|
+
title?: React.ReactNode;
|
|
53
|
+
description?: React.ReactNode;
|
|
54
|
+
badge?: React.ReactNode;
|
|
55
|
+
children?: React.ReactNode;
|
|
56
|
+
className?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const EvoFormHeader = ({ title, description, badge, children, className = '' }: EvoFormHeaderProps) => (
|
|
60
|
+
<header className={cx(styles.header, className)}>
|
|
61
|
+
{badge && <div className={styles.headerBadge}>{badge}</div>}
|
|
62
|
+
{title && <h2 className={styles.headerTitle}>{title}</h2>}
|
|
63
|
+
{description && <p className={styles.headerDesc}>{description}</p>}
|
|
64
|
+
{children}
|
|
65
|
+
</header>
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// ---------- Section ----------
|
|
69
|
+
interface EvoFormSectionProps {
|
|
70
|
+
title?: React.ReactNode;
|
|
71
|
+
description?: React.ReactNode;
|
|
72
|
+
variant?: 'stacked' | 'split';
|
|
73
|
+
children: React.ReactNode;
|
|
74
|
+
className?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const EvoFormSection = ({
|
|
78
|
+
title,
|
|
79
|
+
description,
|
|
80
|
+
variant = 'stacked',
|
|
81
|
+
children,
|
|
82
|
+
className = '',
|
|
83
|
+
}: EvoFormSectionProps) => (
|
|
84
|
+
<section className={cx(styles.section, styles[`section_${variant}`], className)}>
|
|
85
|
+
{(title || description) && (
|
|
86
|
+
<div className={styles.sectionHead}>
|
|
87
|
+
{title && <h3 className={styles.sectionTitle}>{title}</h3>}
|
|
88
|
+
{description && <p className={styles.sectionDesc}>{description}</p>}
|
|
89
|
+
</div>
|
|
90
|
+
)}
|
|
91
|
+
<div className={styles.sectionBody}>{children}</div>
|
|
92
|
+
</section>
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
// ---------- Row (side-by-side fields) ----------
|
|
96
|
+
interface EvoFormRowProps {
|
|
97
|
+
children: React.ReactNode;
|
|
98
|
+
gap?: 'sm' | 'md' | 'lg';
|
|
99
|
+
align?: 'start' | 'center' | 'end';
|
|
100
|
+
className?: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const EvoFormRow = ({ children, gap = 'md', align = 'start', className = '' }: EvoFormRowProps) => (
|
|
104
|
+
<div className={cx(styles.row, styles[`row_${gap}`], styles[`row_align_${align}`], className)}>
|
|
105
|
+
{children}
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
// ---------- Field ----------
|
|
110
|
+
interface EvoFormFieldProps {
|
|
111
|
+
children: React.ReactNode;
|
|
112
|
+
label?: React.ReactNode;
|
|
113
|
+
description?: React.ReactNode;
|
|
114
|
+
error?: React.ReactNode;
|
|
115
|
+
required?: boolean;
|
|
116
|
+
htmlFor?: string;
|
|
117
|
+
className?: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const EvoFormField = ({
|
|
121
|
+
children,
|
|
122
|
+
label,
|
|
123
|
+
description,
|
|
124
|
+
error,
|
|
125
|
+
required,
|
|
126
|
+
htmlFor,
|
|
127
|
+
className = '',
|
|
128
|
+
}: EvoFormFieldProps) => {
|
|
129
|
+
const reactId = useId();
|
|
130
|
+
const fieldId = htmlFor ?? `evo-field-${reactId}`;
|
|
131
|
+
const hasMeta = label || description || error;
|
|
132
|
+
|
|
133
|
+
if (!hasMeta) {
|
|
134
|
+
return <div className={cx(styles.field, className)}>{children}</div>;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<div className={cx(styles.field, error ? styles.field_error : '', className)}>
|
|
139
|
+
{label && (
|
|
140
|
+
<label htmlFor={fieldId} className={styles.fieldLabel}>
|
|
141
|
+
{label}
|
|
142
|
+
{required && <span className={styles.fieldRequired} aria-hidden="true">*</span>}
|
|
143
|
+
</label>
|
|
144
|
+
)}
|
|
145
|
+
<div className={styles.fieldControl}>{children}</div>
|
|
146
|
+
{error ? (
|
|
147
|
+
<p className={styles.fieldError} role="alert">{error}</p>
|
|
148
|
+
) : description ? (
|
|
149
|
+
<p className={styles.fieldDesc}>{description}</p>
|
|
150
|
+
) : null}
|
|
151
|
+
</div>
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// ---------- Actions (footer) ----------
|
|
156
|
+
interface EvoFormActionsProps {
|
|
157
|
+
children: React.ReactNode;
|
|
158
|
+
align?: 'left' | 'right' | 'between' | 'center';
|
|
159
|
+
divider?: boolean;
|
|
160
|
+
className?: string;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const EvoFormActions = ({
|
|
164
|
+
children,
|
|
165
|
+
align = 'right',
|
|
166
|
+
divider = true,
|
|
167
|
+
className = '',
|
|
168
|
+
}: EvoFormActionsProps) => (
|
|
169
|
+
<div
|
|
170
|
+
className={cx(
|
|
171
|
+
styles.actions,
|
|
172
|
+
styles[`actions_${align}`],
|
|
173
|
+
divider ? styles.actions_divider : '',
|
|
174
|
+
className,
|
|
175
|
+
)}
|
|
176
|
+
>
|
|
177
|
+
{children}
|
|
178
|
+
</div>
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
EvoForm.Header = EvoFormHeader;
|
|
182
|
+
EvoForm.Section = EvoFormSection;
|
|
183
|
+
EvoForm.Row = EvoFormRow;
|
|
184
|
+
EvoForm.Field = EvoFormField;
|
|
185
|
+
EvoForm.Actions = EvoFormActions;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React, { CSSProperties } from 'react';
|
|
2
|
+
|
|
3
|
+
interface EvoGridProps {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
cols?: number | string;
|
|
6
|
+
rows?: number | string;
|
|
7
|
+
gap?: number | string;
|
|
8
|
+
colGap?: number | string;
|
|
9
|
+
rowGap?: number | string;
|
|
10
|
+
className?: string;
|
|
11
|
+
style?: CSSProperties;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface EvoGridItemProps {
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
colSpan?: number;
|
|
17
|
+
rowSpan?: number;
|
|
18
|
+
className?: string;
|
|
19
|
+
style?: CSSProperties;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const toSize = (v: number | string | undefined) =>
|
|
23
|
+
v === undefined ? undefined : typeof v === 'number' ? `${v}px` : v;
|
|
24
|
+
|
|
25
|
+
const EvoGridItem = ({ children, colSpan, rowSpan, className = '', style }: EvoGridItemProps) => (
|
|
26
|
+
<div
|
|
27
|
+
className={className}
|
|
28
|
+
style={{
|
|
29
|
+
gridColumn: colSpan ? `span ${colSpan}` : undefined,
|
|
30
|
+
gridRow: rowSpan ? `span ${rowSpan}` : undefined,
|
|
31
|
+
...style,
|
|
32
|
+
}}
|
|
33
|
+
>
|
|
34
|
+
{children}
|
|
35
|
+
</div>
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
export const EvoGrid = ({
|
|
39
|
+
children,
|
|
40
|
+
cols = 3,
|
|
41
|
+
rows,
|
|
42
|
+
gap = '1rem',
|
|
43
|
+
colGap,
|
|
44
|
+
rowGap,
|
|
45
|
+
className = '',
|
|
46
|
+
style,
|
|
47
|
+
}: EvoGridProps) => (
|
|
48
|
+
<div
|
|
49
|
+
className={className}
|
|
50
|
+
style={{
|
|
51
|
+
display: 'grid',
|
|
52
|
+
gridTemplateColumns: typeof cols === 'number' ? `repeat(${cols}, 1fr)` : cols,
|
|
53
|
+
gridTemplateRows: rows
|
|
54
|
+
? typeof rows === 'number' ? `repeat(${rows}, auto)` : rows
|
|
55
|
+
: undefined,
|
|
56
|
+
gap: toSize(gap),
|
|
57
|
+
columnGap: toSize(colGap),
|
|
58
|
+
rowGap: toSize(rowGap),
|
|
59
|
+
...style,
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
{children}
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
EvoGrid.Item = EvoGridItem;
|