@archbase/components 3.0.23 → 4.0.0
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/buttons/ArchbaseSpeedDial.d.ts +59 -0
- package/dist/buttons/index.d.ts +2 -0
- package/dist/charts/ArchbaseArcGauge.d.ts +55 -0
- package/dist/charts/ArchbaseGantt.d.ts +70 -0
- package/dist/charts/ArchbaseLinearGauge.d.ts +55 -0
- package/dist/charts/ArchbaseResourceTimeline.d.ts +61 -0
- package/dist/charts/ArchbaseSparkline.d.ts +45 -0
- package/dist/charts/index.d.ts +10 -0
- package/dist/containers/ArchbaseExpansionPanel.d.ts +60 -0
- package/dist/containers/ArchbaseFloatingPanel.d.ts +91 -0
- package/dist/containers/index.d.ts +4 -0
- package/dist/datagrid/export/ArchbaseDataGridExcelExport.d.ts +67 -0
- package/dist/datagrid/export/index.d.ts +2 -0
- package/dist/datagrid/index.d.ts +1 -0
- package/dist/display/ArchbaseAnimationWrapper.d.ts +73 -0
- package/dist/display/ArchbaseBarcodeGenerator.d.ts +50 -0
- package/dist/display/ArchbaseCarousel.d.ts +100 -0
- package/dist/display/ArchbaseCodeViewer.d.ts +63 -0
- package/dist/display/ArchbaseDiffViewer.d.ts +41 -0
- package/dist/display/ArchbaseJsonTree.d.ts +34 -0
- package/dist/display/ArchbaseLightbox.d.ts +89 -0
- package/dist/display/ArchbaseMarquee.d.ts +46 -0
- package/dist/display/ArchbasePhotoAlbum.d.ts +58 -0
- package/dist/display/ArchbaseQRCode.d.ts +44 -0
- package/dist/display/ArchbaseTooltipRich.d.ts +82 -0
- package/dist/display/ArchbaseVirtualList.d.ts +116 -0
- package/dist/display/index.d.ts +24 -0
- package/dist/editors/ArchbaseAIPromptInput.d.ts +69 -0
- package/dist/editors/ArchbaseAsyncMultiSelect.d.ts +1 -1
- package/dist/editors/ArchbaseAsyncSelect.d.ts +1 -1
- package/dist/editors/ArchbaseBarcodeScanner.d.ts +63 -0
- package/dist/editors/ArchbaseCepInput.d.ts +26 -0
- package/dist/editors/ArchbaseColorGradientPicker.d.ts +80 -0
- package/dist/editors/ArchbaseCpfCnpjInput.d.ts +21 -0
- package/dist/editors/ArchbaseCurrencyInput.d.ts +25 -0
- package/dist/editors/ArchbaseDualListbox.d.ts +61 -0
- package/dist/editors/ArchbaseInPlaceEditor.d.ts +67 -0
- package/dist/editors/ArchbaseLightGrid.d.ts +56 -0
- package/dist/editors/ArchbaseMentionInput.d.ts +75 -0
- package/dist/editors/ArchbaseMultiEmail.d.ts +53 -0
- package/dist/editors/ArchbaseMultiViewCalendar.d.ts +47 -0
- package/dist/editors/ArchbaseNumberStepper.d.ts +66 -0
- package/dist/editors/ArchbaseOTPInput.d.ts +27 -0
- package/dist/editors/ArchbasePhoneInput.d.ts +52 -0
- package/dist/editors/ArchbaseRangeSlider.d.ts +22 -0
- package/dist/editors/ArchbaseSignaturePad.d.ts +60 -0
- package/dist/editors/ArchbaseSpeechToTextInput.d.ts +106 -0
- package/dist/editors/ArchbaseSpreadsheet.d.ts +56 -0
- package/dist/editors/ArchbaseTagInput.d.ts +55 -0
- package/dist/editors/index.d.ts +40 -0
- package/dist/feedback/ArchbaseChunkProgressBar.d.ts +35 -0
- package/dist/feedback/ArchbaseRipple.d.ts +43 -0
- package/dist/feedback/ArchbaseSkeleton.d.ts +115 -0
- package/dist/feedback/index.d.ts +6 -0
- package/dist/filters/ArchbaseColumnSelector.d.ts +38 -0
- package/dist/filters/index.d.ts +2 -0
- package/dist/forms/ArchbaseFieldArray.d.ts +80 -0
- package/dist/forms/ArchbaseFormWizard.d.ts +73 -0
- package/dist/forms/ArchbaseStepper.d.ts +51 -0
- package/dist/forms/index.d.ts +8 -0
- package/dist/forms/useArchbaseFormWizard.d.ts +74 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useArchbaseConfirm.d.ts +59 -0
- package/dist/image/editor/index.d.ts +43 -4
- package/dist/image/index.d.ts +1 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +22510 -13820
- package/dist/list/ArchbaseTreeList.d.ts +76 -0
- package/dist/list/index.d.ts +2 -0
- package/dist/navigation/ArchbaseActionSheet.d.ts +70 -0
- package/dist/navigation/ArchbaseAppBar.d.ts +63 -0
- package/dist/navigation/ArchbaseBottomNavigation.d.ts +61 -0
- package/dist/navigation/ArchbaseContextMenu.d.ts +76 -0
- package/dist/navigation/ArchbaseKeyboardShortcuts.d.ts +85 -0
- package/dist/navigation/ArchbaseSpotlight.d.ts +69 -0
- package/dist/navigation/index.d.ts +12 -0
- package/dist/notification/ArchbaseNotificationCenter.d.ts +56 -0
- package/dist/notification/index.d.ts +2 -0
- package/dist/onboarding/ArchbaseOnboardingTour.d.ts +27 -76
- package/dist/viewers/ArchbaseDocViewer.d.ts +40 -0
- package/dist/viewers/ArchbasePdfBuilder.d.ts +53 -0
- package/dist/viewers/ArchbaseXmlViewer.d.ts +36 -0
- package/dist/viewers/index.d.ts +6 -0
- package/package.json +41 -18
- package/src/buttons/ArchbaseSpeedDial.tsx +282 -0
- package/src/buttons/index.ts +3 -0
- package/src/charts/ArchbaseArcGauge.tsx +325 -0
- package/src/charts/ArchbaseGantt.tsx +494 -0
- package/src/charts/ArchbaseLinearGauge.tsx +288 -0
- package/src/charts/ArchbaseResourceTimeline.tsx +433 -0
- package/src/charts/ArchbaseSparkline.tsx +193 -0
- package/src/charts/index.ts +20 -1
- package/src/containers/ArchbaseExpansionPanel.tsx +208 -0
- package/src/containers/ArchbaseFloatingPanel.tsx +448 -0
- package/src/containers/index.ts +17 -0
- package/src/datagrid/components/pagination/grid-pagination.tsx +2 -2
- package/src/datagrid/export/ArchbaseDataGridExcelExport.tsx +293 -0
- package/src/datagrid/export/index.ts +8 -0
- package/src/datagrid/index.tsx +2 -0
- package/src/display/ArchbaseAnimationWrapper.tsx +272 -0
- package/src/display/ArchbaseBarcodeGenerator.tsx +303 -0
- package/src/display/ArchbaseCarousel.tsx +679 -0
- package/src/display/ArchbaseCodeViewer.tsx +271 -0
- package/src/display/ArchbaseDiffViewer.tsx +108 -0
- package/src/display/ArchbaseJsonTree.tsx +150 -0
- package/src/display/ArchbaseLightbox.tsx +279 -0
- package/src/display/ArchbaseMarquee.tsx +268 -0
- package/src/display/ArchbasePhotoAlbum.tsx +415 -0
- package/src/display/ArchbaseQRCode.tsx +137 -0
- package/src/display/ArchbaseTooltipRich.tsx +317 -0
- package/src/display/ArchbaseVirtualList.tsx +618 -0
- package/src/display/index.ts +94 -1
- package/src/editors/ArchbaseAIPromptInput.tsx +432 -0
- package/src/editors/ArchbaseBarcodeScanner.tsx +570 -0
- package/src/editors/ArchbaseCepInput.tsx +173 -0
- package/src/editors/ArchbaseColorGradientPicker.tsx +460 -0
- package/src/editors/ArchbaseCpfCnpjInput.tsx +193 -0
- package/src/editors/ArchbaseCurrencyInput.tsx +100 -0
- package/src/editors/ArchbaseDualListbox.tsx +671 -0
- package/src/editors/ArchbaseInPlaceEditor.tsx +406 -0
- package/src/editors/ArchbaseLightGrid.tsx +538 -0
- package/src/editors/ArchbaseMentionInput.tsx +384 -0
- package/src/editors/ArchbaseMultiEmail.tsx +367 -0
- package/src/editors/ArchbaseMultiViewCalendar.tsx +439 -0
- package/src/editors/ArchbaseNumberStepper.tsx +219 -0
- package/src/editors/ArchbaseOTPInput.tsx +133 -0
- package/src/editors/ArchbaseOperationHoursEditor.tsx +1 -1
- package/src/editors/ArchbasePhoneInput.tsx +355 -0
- package/src/editors/ArchbaseRangeSlider.tsx +109 -0
- package/src/editors/ArchbaseSignaturePad.tsx +425 -0
- package/src/editors/ArchbaseSpeechToTextInput.tsx +444 -0
- package/src/editors/ArchbaseSpreadsheet.tsx +388 -0
- package/src/editors/ArchbaseTagInput.tsx +326 -0
- package/src/editors/index.tsx +92 -0
- package/src/feedback/ArchbaseChunkProgressBar.tsx +156 -0
- package/src/feedback/ArchbaseRipple.tsx +278 -0
- package/src/feedback/ArchbaseSkeleton.tsx +419 -0
- package/src/feedback/index.ts +22 -1
- package/src/filters/ArchbaseColumnSelector.tsx +268 -0
- package/src/filters/index.ts +2 -0
- package/src/forms/ArchbaseFieldArray.tsx +305 -0
- package/src/forms/ArchbaseFormWizard.tsx +284 -0
- package/src/forms/ArchbaseStepper.tsx +137 -0
- package/src/forms/index.ts +24 -2
- package/src/forms/useArchbaseFormWizard.ts +283 -0
- package/src/hooks/index.ts +12 -0
- package/src/hooks/useArchbaseConfirm.ts +293 -0
- package/src/image/editor/functions/image-processing.ts +5 -0
- package/src/image/editor/index.tsx +305 -391
- package/src/image/index.ts +1 -0
- package/src/index.ts +3 -0
- package/src/list/ArchbaseTreeList.tsx +422 -0
- package/src/list/index.ts +3 -0
- package/src/navigation/ArchbaseActionSheet.tsx +301 -0
- package/src/navigation/ArchbaseAppBar.tsx +233 -0
- package/src/navigation/ArchbaseBottomNavigation.tsx +243 -0
- package/src/navigation/ArchbaseContextMenu.tsx +298 -0
- package/src/navigation/ArchbaseKeyboardShortcuts.tsx +472 -0
- package/src/navigation/ArchbaseSpotlight.tsx +483 -0
- package/src/navigation/index.ts +48 -1
- package/src/notification/ArchbaseNotificationCenter.tsx +502 -0
- package/src/notification/index.ts +2 -0
- package/src/onboarding/ArchbaseOnboardingTour.tsx +229 -102
- package/src/viewers/ArchbaseDocViewer.tsx +584 -0
- package/src/viewers/ArchbasePdfBuilder.tsx +291 -0
- package/src/viewers/ArchbaseXmlViewer.tsx +142 -0
- package/src/viewers/index.ts +12 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import React, { useState, useCallback, useRef, useEffect, KeyboardEvent } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Text,
|
|
4
|
+
TextInput,
|
|
5
|
+
NumberInput,
|
|
6
|
+
Select,
|
|
7
|
+
Textarea,
|
|
8
|
+
Box,
|
|
9
|
+
Group,
|
|
10
|
+
ActionIcon,
|
|
11
|
+
Loader,
|
|
12
|
+
Tooltip,
|
|
13
|
+
} from '@mantine/core';
|
|
14
|
+
import { DateInput } from '@mantine/dates';
|
|
15
|
+
import { IconCheck, IconX, IconPencil } from '@tabler/icons-react';
|
|
16
|
+
import { useClickOutside } from '@mantine/hooks';
|
|
17
|
+
|
|
18
|
+
// =============================================================================
|
|
19
|
+
// Types
|
|
20
|
+
// =============================================================================
|
|
21
|
+
|
|
22
|
+
export type InPlaceEditorType = 'text' | 'number' | 'select' | 'textarea' | 'date';
|
|
23
|
+
|
|
24
|
+
export interface SelectOption {
|
|
25
|
+
value: string;
|
|
26
|
+
label: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ArchbaseInPlaceEditorProps {
|
|
30
|
+
/** Valor atual */
|
|
31
|
+
value: any;
|
|
32
|
+
/** Callback ao salvar */
|
|
33
|
+
onSave: (value: any) => void | Promise<void>;
|
|
34
|
+
/** Callback ao cancelar */
|
|
35
|
+
onCancel?: () => void;
|
|
36
|
+
/** Tipo do editor */
|
|
37
|
+
type?: InPlaceEditorType;
|
|
38
|
+
/** Opções para select */
|
|
39
|
+
options?: SelectOption[];
|
|
40
|
+
/** Formatador para exibição */
|
|
41
|
+
formatter?: (value: any) => string;
|
|
42
|
+
/** Validador */
|
|
43
|
+
validate?: (value: any) => boolean | string;
|
|
44
|
+
/** Placeholder do input */
|
|
45
|
+
placeholder?: string;
|
|
46
|
+
/** Texto quando vazio */
|
|
47
|
+
emptyText?: string;
|
|
48
|
+
/** Desabilitado */
|
|
49
|
+
disabled?: boolean;
|
|
50
|
+
/** Salvar ao perder foco */
|
|
51
|
+
saveOnBlur?: boolean;
|
|
52
|
+
/** Mostrar botões de ação */
|
|
53
|
+
showActions?: boolean;
|
|
54
|
+
/** Mostrar ícone de edição no hover */
|
|
55
|
+
showEditIcon?: boolean;
|
|
56
|
+
/** Tamanho do texto */
|
|
57
|
+
textSize?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
58
|
+
/** Peso do texto */
|
|
59
|
+
textWeight?: number;
|
|
60
|
+
/** Cor do texto */
|
|
61
|
+
textColor?: string;
|
|
62
|
+
/** Número de linhas para textarea */
|
|
63
|
+
textareaRows?: number;
|
|
64
|
+
/** Props do NumberInput */
|
|
65
|
+
numberProps?: {
|
|
66
|
+
min?: number;
|
|
67
|
+
max?: number;
|
|
68
|
+
step?: number;
|
|
69
|
+
decimalScale?: number;
|
|
70
|
+
prefix?: string;
|
|
71
|
+
suffix?: string;
|
|
72
|
+
};
|
|
73
|
+
/** Props do DateInput */
|
|
74
|
+
dateProps?: {
|
|
75
|
+
locale?: string;
|
|
76
|
+
valueFormat?: string;
|
|
77
|
+
minDate?: Date;
|
|
78
|
+
maxDate?: Date;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// =============================================================================
|
|
83
|
+
// Default Formatters
|
|
84
|
+
// =============================================================================
|
|
85
|
+
|
|
86
|
+
const defaultFormatters: Record<InPlaceEditorType, (value: any) => string> = {
|
|
87
|
+
text: (value) => String(value ?? ''),
|
|
88
|
+
number: (value) => {
|
|
89
|
+
if (value === null || value === undefined) return '';
|
|
90
|
+
return new Intl.NumberFormat('pt-BR').format(value);
|
|
91
|
+
},
|
|
92
|
+
select: (value) => String(value ?? ''),
|
|
93
|
+
textarea: (value) => String(value ?? ''),
|
|
94
|
+
date: (value) => {
|
|
95
|
+
if (!value) return '';
|
|
96
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
97
|
+
return date.toLocaleDateString('pt-BR');
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// =============================================================================
|
|
102
|
+
// ArchbaseInPlaceEditor Component
|
|
103
|
+
// =============================================================================
|
|
104
|
+
|
|
105
|
+
export function ArchbaseInPlaceEditor({
|
|
106
|
+
value,
|
|
107
|
+
onSave,
|
|
108
|
+
onCancel,
|
|
109
|
+
type = 'text',
|
|
110
|
+
options = [],
|
|
111
|
+
formatter,
|
|
112
|
+
validate,
|
|
113
|
+
placeholder = 'Clique para editar',
|
|
114
|
+
emptyText = 'Vazio',
|
|
115
|
+
disabled = false,
|
|
116
|
+
saveOnBlur = true,
|
|
117
|
+
showActions = true,
|
|
118
|
+
showEditIcon = true,
|
|
119
|
+
textSize = 'sm',
|
|
120
|
+
textWeight,
|
|
121
|
+
textColor,
|
|
122
|
+
textareaRows = 3,
|
|
123
|
+
numberProps = {},
|
|
124
|
+
dateProps = {},
|
|
125
|
+
}: ArchbaseInPlaceEditorProps) {
|
|
126
|
+
const [isEditing, setIsEditing] = useState(false);
|
|
127
|
+
const [editValue, setEditValue] = useState(value);
|
|
128
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
129
|
+
const [error, setError] = useState<string | null>(null);
|
|
130
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
131
|
+
|
|
132
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
133
|
+
const containerRef = useClickOutside(() => {
|
|
134
|
+
if (isEditing && saveOnBlur) {
|
|
135
|
+
handleSave();
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// Reset edit value when value prop changes
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (!isEditing) {
|
|
142
|
+
setEditValue(value);
|
|
143
|
+
}
|
|
144
|
+
}, [value, isEditing]);
|
|
145
|
+
|
|
146
|
+
// Focus input when entering edit mode
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
if (isEditing && inputRef.current) {
|
|
149
|
+
inputRef.current.focus();
|
|
150
|
+
inputRef.current.select?.();
|
|
151
|
+
}
|
|
152
|
+
}, [isEditing]);
|
|
153
|
+
|
|
154
|
+
// Format display value
|
|
155
|
+
const displayFormatter = formatter ?? defaultFormatters[type];
|
|
156
|
+
const displayValue = displayFormatter(value);
|
|
157
|
+
|
|
158
|
+
// Start editing
|
|
159
|
+
const handleStartEdit = useCallback(() => {
|
|
160
|
+
if (disabled) return;
|
|
161
|
+
setEditValue(value);
|
|
162
|
+
setError(null);
|
|
163
|
+
setIsEditing(true);
|
|
164
|
+
}, [disabled, value]);
|
|
165
|
+
|
|
166
|
+
// Cancel editing
|
|
167
|
+
const handleCancel = useCallback(() => {
|
|
168
|
+
setEditValue(value);
|
|
169
|
+
setError(null);
|
|
170
|
+
setIsEditing(false);
|
|
171
|
+
onCancel?.();
|
|
172
|
+
}, [value, onCancel]);
|
|
173
|
+
|
|
174
|
+
// Save value
|
|
175
|
+
const handleSave = useCallback(async () => {
|
|
176
|
+
// Validate
|
|
177
|
+
if (validate) {
|
|
178
|
+
const result = validate(editValue);
|
|
179
|
+
if (result !== true) {
|
|
180
|
+
setError(typeof result === 'string' ? result : 'Valor inválido');
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
setIsLoading(true);
|
|
186
|
+
setError(null);
|
|
187
|
+
|
|
188
|
+
try {
|
|
189
|
+
await onSave(editValue);
|
|
190
|
+
setIsEditing(false);
|
|
191
|
+
} catch (err) {
|
|
192
|
+
setError(err instanceof Error ? err.message : 'Erro ao salvar');
|
|
193
|
+
} finally {
|
|
194
|
+
setIsLoading(false);
|
|
195
|
+
}
|
|
196
|
+
}, [editValue, validate, onSave]);
|
|
197
|
+
|
|
198
|
+
// Handle keyboard
|
|
199
|
+
const handleKeyDown = useCallback(
|
|
200
|
+
(event: KeyboardEvent) => {
|
|
201
|
+
if (event.key === 'Enter' && type !== 'textarea') {
|
|
202
|
+
event.preventDefault();
|
|
203
|
+
handleSave();
|
|
204
|
+
} else if (event.key === 'Escape') {
|
|
205
|
+
event.preventDefault();
|
|
206
|
+
handleCancel();
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
[type, handleSave, handleCancel]
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
// Render input based on type
|
|
213
|
+
const renderInput = () => {
|
|
214
|
+
const commonProps = {
|
|
215
|
+
ref: inputRef,
|
|
216
|
+
value: editValue,
|
|
217
|
+
placeholder,
|
|
218
|
+
error: error ?? undefined,
|
|
219
|
+
disabled: isLoading,
|
|
220
|
+
onKeyDown: handleKeyDown,
|
|
221
|
+
size: 'sm' as const,
|
|
222
|
+
style: { flex: 1 },
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
switch (type) {
|
|
226
|
+
case 'number':
|
|
227
|
+
return (
|
|
228
|
+
<NumberInput
|
|
229
|
+
{...commonProps}
|
|
230
|
+
value={editValue ?? ''}
|
|
231
|
+
onChange={(val) => setEditValue(val)}
|
|
232
|
+
hideControls
|
|
233
|
+
{...numberProps}
|
|
234
|
+
/>
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
case 'select':
|
|
238
|
+
return (
|
|
239
|
+
<Select
|
|
240
|
+
{...commonProps}
|
|
241
|
+
value={editValue}
|
|
242
|
+
onChange={(val) => {
|
|
243
|
+
setEditValue(val);
|
|
244
|
+
if (saveOnBlur) {
|
|
245
|
+
// Auto-save on select
|
|
246
|
+
setTimeout(() => handleSave(), 0);
|
|
247
|
+
}
|
|
248
|
+
}}
|
|
249
|
+
data={options}
|
|
250
|
+
searchable
|
|
251
|
+
/>
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
case 'textarea':
|
|
255
|
+
return (
|
|
256
|
+
<Textarea
|
|
257
|
+
value={editValue ?? ''}
|
|
258
|
+
placeholder={placeholder}
|
|
259
|
+
error={error ?? undefined}
|
|
260
|
+
disabled={isLoading}
|
|
261
|
+
onKeyDown={handleKeyDown}
|
|
262
|
+
size="sm"
|
|
263
|
+
style={{ flex: 1 }}
|
|
264
|
+
onChange={(e) => setEditValue(e.target.value)}
|
|
265
|
+
rows={textareaRows}
|
|
266
|
+
autosize
|
|
267
|
+
minRows={textareaRows}
|
|
268
|
+
/>
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
case 'date':
|
|
272
|
+
return (
|
|
273
|
+
<DateInput
|
|
274
|
+
{...commonProps}
|
|
275
|
+
value={editValue ? new Date(editValue) : null}
|
|
276
|
+
onChange={(val) => setEditValue(val)}
|
|
277
|
+
{...dateProps}
|
|
278
|
+
/>
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
case 'text':
|
|
282
|
+
default:
|
|
283
|
+
return (
|
|
284
|
+
<TextInput
|
|
285
|
+
{...commonProps}
|
|
286
|
+
value={editValue ?? ''}
|
|
287
|
+
onChange={(e) => setEditValue(e.target.value)}
|
|
288
|
+
/>
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// Render viewing mode
|
|
294
|
+
if (!isEditing) {
|
|
295
|
+
const hasValue = value !== null && value !== undefined && value !== '';
|
|
296
|
+
const selectLabel = type === 'select'
|
|
297
|
+
? options.find(o => o.value === value)?.label
|
|
298
|
+
: null;
|
|
299
|
+
|
|
300
|
+
return (
|
|
301
|
+
<Box
|
|
302
|
+
ref={containerRef}
|
|
303
|
+
onMouseEnter={() => setIsHovered(true)}
|
|
304
|
+
onMouseLeave={() => setIsHovered(false)}
|
|
305
|
+
onClick={handleStartEdit}
|
|
306
|
+
style={{
|
|
307
|
+
cursor: disabled ? 'default' : 'pointer',
|
|
308
|
+
display: 'inline-flex',
|
|
309
|
+
alignItems: 'center',
|
|
310
|
+
gap: 4,
|
|
311
|
+
padding: '2px 4px',
|
|
312
|
+
borderRadius: 4,
|
|
313
|
+
backgroundColor: isHovered && !disabled ? 'var(--mantine-color-gray-1)' : 'transparent',
|
|
314
|
+
transition: 'background-color 150ms',
|
|
315
|
+
}}
|
|
316
|
+
>
|
|
317
|
+
<Text
|
|
318
|
+
size={textSize}
|
|
319
|
+
fw={textWeight}
|
|
320
|
+
c={hasValue ? textColor : 'dimmed'}
|
|
321
|
+
style={{
|
|
322
|
+
fontStyle: hasValue ? 'normal' : 'italic',
|
|
323
|
+
}}
|
|
324
|
+
>
|
|
325
|
+
{hasValue ? (selectLabel ?? displayValue) : emptyText}
|
|
326
|
+
</Text>
|
|
327
|
+
{showEditIcon && isHovered && !disabled && (
|
|
328
|
+
<IconPencil size={14} style={{ opacity: 0.5 }} />
|
|
329
|
+
)}
|
|
330
|
+
</Box>
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Render editing mode
|
|
335
|
+
return (
|
|
336
|
+
<Box ref={containerRef}>
|
|
337
|
+
<Group gap="xs" wrap="nowrap" align="flex-start">
|
|
338
|
+
{renderInput()}
|
|
339
|
+
{showActions && (
|
|
340
|
+
<Group gap={4} wrap="nowrap">
|
|
341
|
+
{isLoading ? (
|
|
342
|
+
<Loader size="xs" />
|
|
343
|
+
) : (
|
|
344
|
+
<>
|
|
345
|
+
<Tooltip label="Salvar (Enter)">
|
|
346
|
+
<ActionIcon
|
|
347
|
+
variant="light"
|
|
348
|
+
color="green"
|
|
349
|
+
size="sm"
|
|
350
|
+
onClick={handleSave}
|
|
351
|
+
>
|
|
352
|
+
<IconCheck size={14} />
|
|
353
|
+
</ActionIcon>
|
|
354
|
+
</Tooltip>
|
|
355
|
+
<Tooltip label="Cancelar (Esc)">
|
|
356
|
+
<ActionIcon
|
|
357
|
+
variant="light"
|
|
358
|
+
color="red"
|
|
359
|
+
size="sm"
|
|
360
|
+
onClick={handleCancel}
|
|
361
|
+
>
|
|
362
|
+
<IconX size={14} />
|
|
363
|
+
</ActionIcon>
|
|
364
|
+
</Tooltip>
|
|
365
|
+
</>
|
|
366
|
+
)}
|
|
367
|
+
</Group>
|
|
368
|
+
)}
|
|
369
|
+
</Group>
|
|
370
|
+
</Box>
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// =============================================================================
|
|
375
|
+
// Convenience Components
|
|
376
|
+
// =============================================================================
|
|
377
|
+
|
|
378
|
+
/** Editor inline de texto */
|
|
379
|
+
export function ArchbaseInPlaceTextEditor(
|
|
380
|
+
props: Omit<ArchbaseInPlaceEditorProps, 'type'>
|
|
381
|
+
) {
|
|
382
|
+
return <ArchbaseInPlaceEditor type="text" {...props} />;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/** Editor inline de número */
|
|
386
|
+
export function ArchbaseInPlaceNumberEditor(
|
|
387
|
+
props: Omit<ArchbaseInPlaceEditorProps, 'type'>
|
|
388
|
+
) {
|
|
389
|
+
return <ArchbaseInPlaceEditor type="number" {...props} />;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/** Editor inline de select */
|
|
393
|
+
export function ArchbaseInPlaceSelectEditor(
|
|
394
|
+
props: Omit<ArchbaseInPlaceEditorProps, 'type'>
|
|
395
|
+
) {
|
|
396
|
+
return <ArchbaseInPlaceEditor type="select" {...props} />;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** Editor inline de data */
|
|
400
|
+
export function ArchbaseInPlaceDateEditor(
|
|
401
|
+
props: Omit<ArchbaseInPlaceEditorProps, 'type'>
|
|
402
|
+
) {
|
|
403
|
+
return <ArchbaseInPlaceEditor type="date" {...props} />;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export default ArchbaseInPlaceEditor;
|