@archbase/components 3.0.25 → 4.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/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,384 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ArchbaseMentionInput — input com suporte a mentions (@user, #tag, etc.) integrado ao DataSource (v1/v2).
|
|
3
|
+
* Wrapper sobre react-mentions com tema Mantine e validacao.
|
|
4
|
+
* @status stable
|
|
5
|
+
*/
|
|
6
|
+
import { Input, MantineSize, useMantineColorScheme, useMantineTheme } from '@mantine/core';
|
|
7
|
+
import { useForceUpdate } from '@mantine/hooks';
|
|
8
|
+
import type { CSSProperties, FocusEventHandler } from 'react';
|
|
9
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
10
|
+
import type { DataSourceEvent, IArchbaseDataSourceBase } from '@archbase/data';
|
|
11
|
+
import { DataSourceEventNames, useArchbaseDidUpdate, useArchbaseV1V2Compatibility } from '@archbase/data';
|
|
12
|
+
import { useValidationErrors } from '@archbase/core';
|
|
13
|
+
import { MentionsInput, Mention } from 'react-mentions';
|
|
14
|
+
|
|
15
|
+
export interface ArchbaseMentionConfig {
|
|
16
|
+
/** Caractere gatilho da mention (ex: '@', '#') */
|
|
17
|
+
trigger: string;
|
|
18
|
+
/** Lista estatica ou funcao async que retorna sugestoes */
|
|
19
|
+
data:
|
|
20
|
+
| Array<{ id: string; display: string }>
|
|
21
|
+
| ((search: string, callback: (data: Array<{ id: string; display: string }>) => void) => void);
|
|
22
|
+
/** Markup template. Padrao: '[__display__](__id__)' */
|
|
23
|
+
markup?: string;
|
|
24
|
+
/** Funcao para transformar exibicao */
|
|
25
|
+
displayTransform?: (id: string, display: string) => string;
|
|
26
|
+
/** Permite espacos na busca */
|
|
27
|
+
allowSpaceInQuery?: boolean;
|
|
28
|
+
/** Estilos customizados para a mention */
|
|
29
|
+
style?: React.CSSProperties;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ArchbaseMentionInputProps<T, ID> {
|
|
33
|
+
/** Fonte de dados onde sera atribuido o valor (V1 ou V2) */
|
|
34
|
+
dataSource?: IArchbaseDataSourceBase<T>;
|
|
35
|
+
/** Campo onde devera ser atribuido o valor na fonte de dados */
|
|
36
|
+
dataField?: string;
|
|
37
|
+
/** Valor controlado (standalone) */
|
|
38
|
+
value?: string;
|
|
39
|
+
/** Valor padrao (standalone) */
|
|
40
|
+
defaultValue?: string;
|
|
41
|
+
/** Titulo do campo */
|
|
42
|
+
label?: string;
|
|
43
|
+
/** Descricao do campo */
|
|
44
|
+
description?: string;
|
|
45
|
+
/** Ultimo erro ocorrido */
|
|
46
|
+
error?: string;
|
|
47
|
+
/** Texto sugestao */
|
|
48
|
+
placeholder?: string;
|
|
49
|
+
/** Indicador se o preenchimento e obrigatorio */
|
|
50
|
+
required?: boolean;
|
|
51
|
+
/** Indicador se o campo esta desabilitado */
|
|
52
|
+
disabled?: boolean;
|
|
53
|
+
/** Indicador se o campo e somente leitura */
|
|
54
|
+
readOnly?: boolean;
|
|
55
|
+
/** Configuracoes de mention (triggers, data, etc.) */
|
|
56
|
+
mentions: ArchbaseMentionConfig[];
|
|
57
|
+
/** Modo linha unica */
|
|
58
|
+
singleLine?: boolean;
|
|
59
|
+
/** Permitir sugestoes acima do cursor */
|
|
60
|
+
allowSuggestionsAboveCursor?: boolean;
|
|
61
|
+
/** Evento quando o valor e alterado */
|
|
62
|
+
onChangeValue?: (value: string, event: any) => void;
|
|
63
|
+
/** Evento quando o campo recebe foco */
|
|
64
|
+
onFocusEnter?: FocusEventHandler<HTMLTextAreaElement | HTMLInputElement>;
|
|
65
|
+
/** Evento quando o foco sai do campo */
|
|
66
|
+
onFocusExit?: FocusEventHandler<HTMLTextAreaElement | HTMLInputElement>;
|
|
67
|
+
/** Referencia para o componente interno */
|
|
68
|
+
innerRef?: React.RefObject<HTMLTextAreaElement | HTMLInputElement>;
|
|
69
|
+
/** Estilos customizados */
|
|
70
|
+
style?: CSSProperties;
|
|
71
|
+
/** Classes CSS customizadas */
|
|
72
|
+
className?: string;
|
|
73
|
+
/** Largura do campo */
|
|
74
|
+
width?: string | number;
|
|
75
|
+
/** Altura do campo */
|
|
76
|
+
height?: string | number;
|
|
77
|
+
/** Tamanho do campo (Mantine) */
|
|
78
|
+
size?: MantineSize;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function ArchbaseMentionInput<T, ID>({
|
|
82
|
+
dataSource,
|
|
83
|
+
dataField,
|
|
84
|
+
value: valueProp,
|
|
85
|
+
defaultValue,
|
|
86
|
+
label,
|
|
87
|
+
description,
|
|
88
|
+
error,
|
|
89
|
+
placeholder,
|
|
90
|
+
required = false,
|
|
91
|
+
disabled = false,
|
|
92
|
+
readOnly = false,
|
|
93
|
+
mentions,
|
|
94
|
+
singleLine = false,
|
|
95
|
+
allowSuggestionsAboveCursor = true,
|
|
96
|
+
onChangeValue,
|
|
97
|
+
onFocusEnter,
|
|
98
|
+
onFocusExit,
|
|
99
|
+
innerRef,
|
|
100
|
+
style,
|
|
101
|
+
className,
|
|
102
|
+
width,
|
|
103
|
+
height,
|
|
104
|
+
size,
|
|
105
|
+
}: ArchbaseMentionInputProps<T, ID>) {
|
|
106
|
+
const v1v2Compatibility = useArchbaseV1V2Compatibility<string>(
|
|
107
|
+
'ArchbaseMentionInput',
|
|
108
|
+
dataSource,
|
|
109
|
+
dataField,
|
|
110
|
+
'',
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
const [currentValue, setCurrentValue] = useState<string>(valueProp ?? defaultValue ?? '');
|
|
114
|
+
const innerComponentRef = useRef<any>(null);
|
|
115
|
+
const theme = useMantineTheme();
|
|
116
|
+
const { colorScheme } = useMantineColorScheme();
|
|
117
|
+
const [internalError, setInternalError] = useState<string | undefined>(error);
|
|
118
|
+
const forceUpdate = useForceUpdate();
|
|
119
|
+
|
|
120
|
+
const validationContext = useValidationErrors();
|
|
121
|
+
const fieldKey = `${dataField}`;
|
|
122
|
+
const contextError = validationContext?.getError(fieldKey);
|
|
123
|
+
|
|
124
|
+
const isDark = colorScheme === 'dark';
|
|
125
|
+
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
if (error !== undefined && error !== internalError) {
|
|
128
|
+
setInternalError(error);
|
|
129
|
+
}
|
|
130
|
+
}, [error]);
|
|
131
|
+
|
|
132
|
+
// Sincronizar prop value quando nao tem datasource
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
if (!dataSource && valueProp !== undefined) {
|
|
135
|
+
setCurrentValue(valueProp);
|
|
136
|
+
}
|
|
137
|
+
}, [valueProp, dataSource]);
|
|
138
|
+
|
|
139
|
+
const loadDataSourceFieldValue = () => {
|
|
140
|
+
let initialValue: any = valueProp ?? defaultValue ?? '';
|
|
141
|
+
|
|
142
|
+
if (dataSource && dataField) {
|
|
143
|
+
initialValue = dataSource.getFieldValue(dataField);
|
|
144
|
+
if (!initialValue) {
|
|
145
|
+
initialValue = '';
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
setCurrentValue(initialValue);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const fieldChangedListener = useCallback(() => {
|
|
153
|
+
loadDataSourceFieldValue();
|
|
154
|
+
}, []);
|
|
155
|
+
|
|
156
|
+
const dataSourceEvent = useCallback(
|
|
157
|
+
(event: DataSourceEvent<T>) => {
|
|
158
|
+
if (dataSource && dataField) {
|
|
159
|
+
if (
|
|
160
|
+
event.type === DataSourceEventNames.dataChanged ||
|
|
161
|
+
event.type === DataSourceEventNames.recordChanged ||
|
|
162
|
+
event.type === DataSourceEventNames.afterScroll ||
|
|
163
|
+
event.type === DataSourceEventNames.afterCancel ||
|
|
164
|
+
event.type === DataSourceEventNames.afterEdit
|
|
165
|
+
) {
|
|
166
|
+
loadDataSourceFieldValue();
|
|
167
|
+
if (!v1v2Compatibility.isDataSourceV2) {
|
|
168
|
+
forceUpdate();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (event.type === DataSourceEventNames.onFieldError && event.fieldName === dataField) {
|
|
173
|
+
setInternalError(event.error);
|
|
174
|
+
validationContext?.setError(fieldKey, event.error);
|
|
175
|
+
if (!v1v2Compatibility.isDataSourceV2) {
|
|
176
|
+
forceUpdate();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
[v1v2Compatibility.isDataSourceV2, dataSource, dataField, loadDataSourceFieldValue, forceUpdate, validationContext, fieldKey],
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
const dataSourceEventRef = useRef(dataSourceEvent);
|
|
185
|
+
useEffect(() => {
|
|
186
|
+
dataSourceEventRef.current = dataSourceEvent;
|
|
187
|
+
}, [dataSourceEvent]);
|
|
188
|
+
|
|
189
|
+
const stableDataSourceEvent = useCallback((event: DataSourceEvent<T>) => {
|
|
190
|
+
dataSourceEventRef.current(event);
|
|
191
|
+
}, []);
|
|
192
|
+
|
|
193
|
+
useEffect(() => {
|
|
194
|
+
loadDataSourceFieldValue();
|
|
195
|
+
if (dataSource && dataField) {
|
|
196
|
+
const hasFieldListener = typeof (dataSource as any).addFieldChangeListener === 'function';
|
|
197
|
+
dataSource.addListener(stableDataSourceEvent);
|
|
198
|
+
if (hasFieldListener) {
|
|
199
|
+
(dataSource as any).addFieldChangeListener(dataField, fieldChangedListener);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return () => {
|
|
203
|
+
dataSource.removeListener(stableDataSourceEvent);
|
|
204
|
+
if (hasFieldListener) {
|
|
205
|
+
(dataSource as any).removeFieldChangeListener(dataField, fieldChangedListener);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
}, [dataSource, dataField, stableDataSourceEvent, fieldChangedListener]);
|
|
210
|
+
|
|
211
|
+
useArchbaseDidUpdate(() => {
|
|
212
|
+
loadDataSourceFieldValue();
|
|
213
|
+
}, []);
|
|
214
|
+
|
|
215
|
+
const handleChange = (event: any, newValue: string, newPlainTextValue: string, mentions: any[]) => {
|
|
216
|
+
const hasError = internalError || contextError;
|
|
217
|
+
if (hasError) {
|
|
218
|
+
setInternalError(undefined);
|
|
219
|
+
validationContext?.clearError(fieldKey);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
setCurrentValue(newValue);
|
|
223
|
+
|
|
224
|
+
if (dataSource && !dataSource.isBrowsing() && dataField && dataSource.getFieldValue(dataField) !== newValue) {
|
|
225
|
+
v1v2Compatibility.handleValueChange(newValue);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (onChangeValue) {
|
|
229
|
+
onChangeValue(newValue, event);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const handleOnFocusExit = (event: React.FocusEvent<HTMLTextAreaElement | HTMLInputElement>) => {
|
|
234
|
+
if (onFocusExit) {
|
|
235
|
+
onFocusExit(event);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const handleOnFocusEnter = (event: React.FocusEvent<HTMLTextAreaElement | HTMLInputElement>) => {
|
|
240
|
+
if (onFocusEnter) {
|
|
241
|
+
onFocusEnter(event);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const isReadOnly = () => {
|
|
246
|
+
return readOnly || v1v2Compatibility.isReadOnly;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const displayError = internalError || contextError;
|
|
250
|
+
|
|
251
|
+
// Tamanhos baseados no MantineSize
|
|
252
|
+
const sizeMap: Record<string, { fontSize: number; minHeight: number; padding: string }> = {
|
|
253
|
+
xs: { fontSize: 12, minHeight: 28, padding: '4px 8px' },
|
|
254
|
+
sm: { fontSize: 14, minHeight: 34, padding: '6px 10px' },
|
|
255
|
+
md: { fontSize: 14, minHeight: 36, padding: '8px 12px' },
|
|
256
|
+
lg: { fontSize: 16, minHeight: 42, padding: '10px 14px' },
|
|
257
|
+
xl: { fontSize: 18, minHeight: 48, padding: '12px 16px' },
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const currentSize = sizeMap[size || 'sm'] || sizeMap.sm;
|
|
261
|
+
|
|
262
|
+
const borderColor = displayError
|
|
263
|
+
? (theme.colors.red[isDark ? 4 : 6])
|
|
264
|
+
: (isDark ? theme.colors.dark[4] : theme.colors.gray[4]);
|
|
265
|
+
|
|
266
|
+
const focusBorderColor = displayError
|
|
267
|
+
? (theme.colors.red[isDark ? 4 : 6])
|
|
268
|
+
: (theme.colors[theme.primaryColor][isDark ? 5 : 6]);
|
|
269
|
+
|
|
270
|
+
const mentionsInputStyle: any = {
|
|
271
|
+
control: {
|
|
272
|
+
fontSize: currentSize.fontSize,
|
|
273
|
+
fontWeight: 'normal',
|
|
274
|
+
},
|
|
275
|
+
'&multiLine': {
|
|
276
|
+
control: {
|
|
277
|
+
minHeight: height || currentSize.minHeight,
|
|
278
|
+
},
|
|
279
|
+
highlighter: {
|
|
280
|
+
padding: currentSize.padding,
|
|
281
|
+
border: '1px solid transparent',
|
|
282
|
+
minHeight: height || currentSize.minHeight,
|
|
283
|
+
},
|
|
284
|
+
input: {
|
|
285
|
+
padding: currentSize.padding,
|
|
286
|
+
border: `1px solid ${borderColor}`,
|
|
287
|
+
borderRadius: theme.radius.sm,
|
|
288
|
+
backgroundColor: isDark ? theme.colors.dark[6] : theme.white,
|
|
289
|
+
color: isDark ? theme.colors.dark[0] : theme.black,
|
|
290
|
+
minHeight: height || currentSize.minHeight,
|
|
291
|
+
outline: 'none',
|
|
292
|
+
'&:focus': {
|
|
293
|
+
borderColor: focusBorderColor,
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
'&singleLine': {
|
|
298
|
+
display: 'inline-block',
|
|
299
|
+
width: '100%',
|
|
300
|
+
highlighter: {
|
|
301
|
+
padding: currentSize.padding,
|
|
302
|
+
border: '1px solid transparent',
|
|
303
|
+
},
|
|
304
|
+
input: {
|
|
305
|
+
padding: currentSize.padding,
|
|
306
|
+
border: `1px solid ${borderColor}`,
|
|
307
|
+
borderRadius: theme.radius.sm,
|
|
308
|
+
backgroundColor: isDark ? theme.colors.dark[6] : theme.white,
|
|
309
|
+
color: isDark ? theme.colors.dark[0] : theme.black,
|
|
310
|
+
height: height || currentSize.minHeight,
|
|
311
|
+
outline: 'none',
|
|
312
|
+
'&:focus': {
|
|
313
|
+
borderColor: focusBorderColor,
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
suggestions: {
|
|
318
|
+
list: {
|
|
319
|
+
backgroundColor: isDark ? theme.colors.dark[7] : theme.white,
|
|
320
|
+
border: `1px solid ${isDark ? theme.colors.dark[4] : theme.colors.gray[3]}`,
|
|
321
|
+
borderRadius: theme.radius.sm,
|
|
322
|
+
fontSize: currentSize.fontSize,
|
|
323
|
+
maxHeight: 200,
|
|
324
|
+
overflowY: 'auto',
|
|
325
|
+
boxShadow: theme.shadows.md,
|
|
326
|
+
zIndex: 1000,
|
|
327
|
+
},
|
|
328
|
+
item: {
|
|
329
|
+
padding: '6px 12px',
|
|
330
|
+
color: isDark ? theme.colors.dark[0] : theme.black,
|
|
331
|
+
'&focused': {
|
|
332
|
+
backgroundColor: isDark ? theme.colors.dark[4] : theme.colors[theme.primaryColor][0],
|
|
333
|
+
color: isDark ? theme.white : theme.black,
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
const defaultMentionStyle: React.CSSProperties = {
|
|
340
|
+
backgroundColor: isDark
|
|
341
|
+
? `${theme.colors[theme.primaryColor][9]}40`
|
|
342
|
+
: `${theme.colors[theme.primaryColor][1]}`,
|
|
343
|
+
borderRadius: '2px',
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
return (
|
|
347
|
+
<Input.Wrapper
|
|
348
|
+
label={label}
|
|
349
|
+
description={description}
|
|
350
|
+
error={displayError}
|
|
351
|
+
required={required}
|
|
352
|
+
size={size}
|
|
353
|
+
style={{ width, ...style }}
|
|
354
|
+
>
|
|
355
|
+
<MentionsInput
|
|
356
|
+
value={currentValue}
|
|
357
|
+
onChange={handleChange}
|
|
358
|
+
onBlur={handleOnFocusExit as any}
|
|
359
|
+
onFocus={handleOnFocusEnter as any}
|
|
360
|
+
placeholder={placeholder}
|
|
361
|
+
disabled={disabled}
|
|
362
|
+
readOnly={isReadOnly()}
|
|
363
|
+
singleLine={singleLine}
|
|
364
|
+
allowSuggestionsAboveCursor={allowSuggestionsAboveCursor}
|
|
365
|
+
inputRef={innerRef || innerComponentRef}
|
|
366
|
+
className={className}
|
|
367
|
+
style={mentionsInputStyle}
|
|
368
|
+
>
|
|
369
|
+
{mentions.map((mentionConfig, index) => (
|
|
370
|
+
<Mention
|
|
371
|
+
key={`${mentionConfig.trigger}-${index}`}
|
|
372
|
+
trigger={mentionConfig.trigger}
|
|
373
|
+
data={mentionConfig.data}
|
|
374
|
+
markup={mentionConfig.markup || '[__display__](__id__)'}
|
|
375
|
+
displayTransform={mentionConfig.displayTransform}
|
|
376
|
+
style={mentionConfig.style || defaultMentionStyle}
|
|
377
|
+
/>
|
|
378
|
+
))}
|
|
379
|
+
</MentionsInput>
|
|
380
|
+
</Input.Wrapper>
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
ArchbaseMentionInput.displayName = 'ArchbaseMentionInput';
|