@1doc/1ds-react 2.9.0 → 2.10.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/CHANGELOG.md +434 -0
- package/dist/components/Accordion/Accordion.css +13 -0
- package/dist/components/Accordion/Accordion.d.ts +3 -0
- package/dist/components/Accordion/Accordion.js +1 -0
- package/dist/components/AppSubheader/AppSubheader.css +10 -1
- package/dist/components/AttachmentCard/AttachmentCard.css +10 -8
- package/dist/components/AttachmentCard/AttachmentCard.d.ts +3 -0
- package/dist/components/AttachmentCard/AttachmentCard.js +8 -1
- package/dist/components/Badge/Badge.css +14 -1
- package/dist/components/Badge/Badge.d.ts +11 -2
- package/dist/components/Badge/Badge.js +3 -0
- package/dist/components/Calendar/Calendar.d.ts +7 -6
- package/dist/components/Coachmark/Coachmark.css +10 -0
- package/dist/components/Coachmark/Coachmark.d.ts +12 -0
- package/dist/components/Coachmark/Coachmark.js +46 -5
- package/dist/components/ColorPicker/ColorPicker.css +8 -1
- package/dist/components/ColorPicker/ColorPicker.d.ts +2 -2
- package/dist/components/DataTable/DataTable.css +174 -0
- package/dist/components/DataTable/DataTable.d.ts +63 -2
- package/dist/components/DataTable/DataTable.js +278 -6
- package/dist/components/DescriptionList/DescriptionList.css +14 -0
- package/dist/components/DescriptionList/DescriptionList.d.ts +3 -0
- package/dist/components/DescriptionList/DescriptionList.js +1 -0
- package/dist/components/EmptyState/EmptyState.d.ts +4 -2
- package/dist/components/EmptyState/EmptyState.js +2 -2
- package/dist/components/Input/Input.css +21 -0
- package/dist/components/Input/Input.d.ts +7 -0
- package/dist/components/Input/Input.js +2 -1
- package/dist/components/List/ListItem.d.ts +14 -2
- package/dist/components/List/ListItem.js +3 -2
- package/dist/components/RichTextEditor/RichTextEditor.css +47 -0
- package/dist/components/RichTextEditor/RichTextEditor.d.ts +22 -8
- package/dist/components/RichTextEditor/RichTextEditor.js +460 -3
- package/dist/components/SegmentedControl/SegmentedControl.css +24 -0
- package/dist/components/SegmentedControl/SegmentedControl.d.ts +2 -0
- package/dist/components/SegmentedControl/SegmentedControl.js +4 -1
- package/dist/components/Select/Select.css +94 -0
- package/dist/components/Select/Select.d.ts +26 -4
- package/dist/components/Select/Select.js +210 -35
- package/dist/components/StatCard/StatCard.css +65 -0
- package/dist/components/StatCard/StatCard.d.ts +9 -0
- package/dist/components/StatCard/StatCard.js +10 -1
- package/dist/components/Toast/Toast.css +32 -0
- package/dist/components/Toast/Toast.d.ts +18 -0
- package/dist/components/Toast/Toast.js +14 -1
- package/dist/components/Toast/ToastStack.js +8 -1
- package/dist/teste/AccordionTituloNeutro.test.d.ts +1 -0
- package/dist/teste/AccordionTituloNeutro.test.js +23 -0
- package/dist/teste/AppSubheaderRegiao.test.d.ts +1 -0
- package/dist/teste/AppSubheaderRegiao.test.js +13 -0
- package/dist/teste/AttachmentCardLista.test.d.ts +1 -0
- package/dist/teste/AttachmentCardLista.test.js +49 -0
- package/dist/teste/AttachmentCardSm.test.d.ts +1 -0
- package/dist/teste/AttachmentCardSm.test.js +26 -0
- package/dist/teste/BadgeNeutroColado.test.d.ts +1 -0
- package/dist/teste/BadgeNeutroColado.test.js +11 -0
- package/dist/teste/BadgeTag.test.js +13 -0
- package/dist/teste/CalendarCabecalho.test.d.ts +1 -0
- package/dist/teste/CalendarCabecalho.test.js +11 -0
- package/dist/teste/CoachmarkSemVeu.test.d.ts +1 -0
- package/dist/teste/CoachmarkSemVeu.test.js +85 -0
- package/dist/teste/ColorPickerXs.test.d.ts +1 -0
- package/dist/teste/ColorPickerXs.test.js +21 -0
- package/dist/teste/DataTableArvoreEVariantes.test.d.ts +1 -0
- package/dist/teste/DataTableArvoreEVariantes.test.js +190 -0
- package/dist/teste/DescriptionListCompacta.test.d.ts +1 -0
- package/dist/teste/DescriptionListCompacta.test.js +22 -0
- package/dist/teste/EmptyStateTituloRico.test.d.ts +1 -0
- package/dist/teste/EmptyStateTituloRico.test.js +23 -0
- package/dist/teste/InputAgrupado.test.d.ts +1 -0
- package/dist/teste/InputAgrupado.test.js +24 -0
- package/dist/teste/ListItemTooltipStandalone.test.d.ts +1 -0
- package/dist/teste/ListItemTooltipStandalone.test.js +39 -0
- package/dist/teste/RichTextEditorAlinhaImagemTabela.test.d.ts +1 -0
- package/dist/teste/RichTextEditorAlinhaImagemTabela.test.js +212 -0
- package/dist/teste/RichTextEditorEstiloDeTexto.test.d.ts +1 -0
- package/dist/teste/RichTextEditorEstiloDeTexto.test.js +120 -0
- package/dist/teste/SegmentedControlContador.test.d.ts +1 -0
- package/dist/teste/SegmentedControlContador.test.js +39 -0
- package/dist/teste/SelectAbertoControladoEFlutuante.test.d.ts +1 -0
- package/dist/teste/SelectAbertoControladoEFlutuante.test.js +145 -0
- package/dist/teste/SelectFiltroCorETamanho.test.d.ts +1 -0
- package/dist/teste/SelectFiltroCorETamanho.test.js +77 -0
- package/dist/teste/StatCardSecundariaETom.test.d.ts +1 -0
- package/dist/teste/StatCardSecundariaETom.test.js +45 -0
- package/dist/teste/ToastAcaoEDetalhes.test.d.ts +1 -0
- package/dist/teste/ToastAcaoEDetalhes.test.js +94 -0
- package/dist/utils/html-seguro.d.ts +19 -1
- package/dist/utils/html-seguro.js +113 -2
- package/dist/utils/toast.d.ts +10 -1
- package/dist/utils/toast.js +2 -1
- package/package.json +2 -2
- package/src/teste/AccordionTituloNeutro.test.tsx +25 -0
- package/src/teste/AppSubheaderRegiao.test.tsx +17 -0
- package/src/teste/AttachmentCardLista.test.tsx +53 -0
- package/src/teste/AttachmentCardSm.test.tsx +29 -0
- package/src/teste/BadgeNeutroColado.test.tsx +15 -0
- package/src/teste/BadgeTag.test.tsx +21 -0
- package/src/teste/CalendarCabecalho.test.tsx +11 -0
- package/src/teste/CoachmarkSemVeu.test.tsx +101 -0
- package/src/teste/ColorPickerXs.test.tsx +22 -0
- package/src/teste/DataTableArvoreEVariantes.test.tsx +240 -0
- package/src/teste/DescriptionListCompacta.test.tsx +24 -0
- package/src/teste/EmptyStateTituloRico.test.tsx +34 -0
- package/src/teste/InputAgrupado.test.tsx +26 -0
- package/src/teste/ListItemTooltipStandalone.test.tsx +64 -0
- package/src/teste/RichTextEditorAlinhaImagemTabela.test.tsx +238 -0
- package/src/teste/RichTextEditorEstiloDeTexto.test.tsx +137 -0
- package/src/teste/SegmentedControlContador.test.tsx +43 -0
- package/src/teste/SelectAbertoControladoEFlutuante.test.tsx +180 -0
- package/src/teste/SelectFiltroCorETamanho.test.tsx +90 -0
- package/src/teste/StatCardSecundariaETom.test.tsx +51 -0
- package/src/teste/ToastAcaoEDetalhes.test.tsx +109 -0
- package/src/utils/html-seguro.ts +105 -2
- package/src/utils/toast.ts +12 -2
|
@@ -3,13 +3,15 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
3
3
|
import './RichTextEditor.css';
|
|
4
4
|
import * as React from "react";
|
|
5
5
|
import { useState, useRef, useEffect } from "react";
|
|
6
|
-
import { faBold, faItalic, faUnderline, faStrikethrough, faListUl, faListOl, faLink, faRotateLeft, faRotateRight, faEraser, } from "@fortawesome/free-solid-svg-icons";
|
|
6
|
+
import { faBold, faItalic, faUnderline, faStrikethrough, faListUl, faListOl, faLink, faRotateLeft, faRotateRight, faEraser, faAlignLeft, faAlignCenter, faAlignRight, faAlignJustify, faImage, faTable, faFont, faTextHeight, faPalette, } from "@fortawesome/free-solid-svg-icons";
|
|
7
7
|
import Button from "../Button/Button";
|
|
8
|
+
import ColorPicker from "../ColorPicker/ColorPicker";
|
|
9
|
+
import Select from "../Select/Select";
|
|
8
10
|
import Icon from "../Icon/Icon";
|
|
9
11
|
import Input from "../Input/Input";
|
|
10
12
|
import Text from "../Text/Text";
|
|
11
13
|
import { gerarId } from "../../utils/id";
|
|
12
|
-
import { htmlDoLink, htmlVazio, normalizarEndereco, sanitizarHtml, } from "../../utils/html-seguro";
|
|
14
|
+
import { htmlDaImagem, htmlDaTabela, htmlDoLink, estiloDeTexto, htmlVazio, imagemSegura, normalizarEndereco, sanitizarHtml, } from "../../utils/html-seguro";
|
|
13
15
|
function RichTextEditor(props) {
|
|
14
16
|
const editorRef = useRef(null);
|
|
15
17
|
const toolbarRef = useRef(null);
|
|
@@ -18,12 +20,30 @@ function RichTextEditor(props) {
|
|
|
18
20
|
const selecaoRef = useRef(null);
|
|
19
21
|
const focoPendenteRef = useRef("");
|
|
20
22
|
const observadorRef = useRef(null);
|
|
23
|
+
const imageInputWrapRef = useRef(null);
|
|
24
|
+
const tableInputWrapRef = useRef(null);
|
|
25
|
+
const fileInputRef = useRef(null);
|
|
26
|
+
const celulaRef = useRef(null);
|
|
27
|
+
const styleWrapRef = useRef(null);
|
|
21
28
|
const [uid, setUid] = useState(() => "");
|
|
22
29
|
const [linkOpen, setLinkOpen] = useState(() => false);
|
|
23
30
|
const [linkUrl, setLinkUrl] = useState(() => "");
|
|
24
31
|
const [linkError, setLinkError] = useState(() => false);
|
|
25
32
|
const [toolFocus, setToolFocus] = useState(() => 0);
|
|
26
33
|
const [active, setActive] = useState(() => "");
|
|
34
|
+
const [styleOpen, setStyleOpen] = useState(() => "");
|
|
35
|
+
const [styleError, setStyleError] = useState(() => false);
|
|
36
|
+
const [imageOpen, setImageOpen] = useState(() => false);
|
|
37
|
+
const [imgUrl, setImgUrl] = useState(() => "");
|
|
38
|
+
const [imgAlt, setImgAlt] = useState(() => "");
|
|
39
|
+
const [imgData, setImgData] = useState(() => "");
|
|
40
|
+
const [imgFileName, setImgFileName] = useState(() => "");
|
|
41
|
+
const [imgError, setImgError] = useState(() => "");
|
|
42
|
+
const [tableOpen, setTableOpen] = useState(() => false);
|
|
43
|
+
const [tblRows, setTblRows] = useState(() => "3");
|
|
44
|
+
const [tblCols, setTblCols] = useState(() => "3");
|
|
45
|
+
const [tblError, setTblError] = useState(() => false);
|
|
46
|
+
const [inTable, setInTable] = useState(() => false);
|
|
27
47
|
function baseId() {
|
|
28
48
|
return props.id || uid;
|
|
29
49
|
}
|
|
@@ -99,6 +119,38 @@ function RichTextEditor(props) {
|
|
|
99
119
|
linkRemove: "Remover link",
|
|
100
120
|
linkCancel: "Cancelar",
|
|
101
121
|
linkInvalid: "Use um endereço http, https, mailto ou tel.",
|
|
122
|
+
alignLeft: "Alinhar à esquerda",
|
|
123
|
+
alignCenter: "Centralizar",
|
|
124
|
+
alignRight: "Alinhar à direita",
|
|
125
|
+
alignJustify: "Justificar",
|
|
126
|
+
image: "Imagem",
|
|
127
|
+
table: "Tabela",
|
|
128
|
+
imageUrl: "Endereço da imagem",
|
|
129
|
+
imageAlt: "Texto alternativo",
|
|
130
|
+
imageFile: "Escolher arquivo",
|
|
131
|
+
imageApply: "Inserir imagem",
|
|
132
|
+
imageCancel: "Cancelar",
|
|
133
|
+
imageInvalid: "Use um endereço http ou https, ou escolha um arquivo.",
|
|
134
|
+
imageType: "Use uma imagem PNG, JPEG, GIF ou WebP.",
|
|
135
|
+
imageTooLarge: "A imagem passa de 2 MB.",
|
|
136
|
+
tableRows: "Linhas",
|
|
137
|
+
tableCols: "Colunas",
|
|
138
|
+
tableApply: "Inserir tabela",
|
|
139
|
+
tableCancel: "Cancelar",
|
|
140
|
+
tableInvalid: "Use de 1 a 20 linhas e de 1 a 10 colunas.",
|
|
141
|
+
tableActions: "Tabela",
|
|
142
|
+
tableAddRow: "Adicionar linha",
|
|
143
|
+
tableRemoveRow: "Remover linha",
|
|
144
|
+
tableAddCol: "Adicionar coluna",
|
|
145
|
+
tableRemoveCol: "Remover coluna",
|
|
146
|
+
tableRemove: "Remover tabela",
|
|
147
|
+
fontFamily: "Fonte",
|
|
148
|
+
fontSize: "Tamanho da fonte",
|
|
149
|
+
textColor: "Cor do texto",
|
|
150
|
+
fontFamilyBase: "Padrão",
|
|
151
|
+
fontFamilyMono: "Monoespaçada",
|
|
152
|
+
styleClose: "Fechar",
|
|
153
|
+
styleNeedsSelection: "Selecione o texto antes de aplicar.",
|
|
102
154
|
};
|
|
103
155
|
const dado = props.labels || {};
|
|
104
156
|
return dado[chave] || padrao[chave];
|
|
@@ -172,6 +224,51 @@ function RichTextEditor(props) {
|
|
|
172
224
|
icon: faEraser,
|
|
173
225
|
toggle: false,
|
|
174
226
|
},
|
|
227
|
+
alignLeft: {
|
|
228
|
+
command: "justifyLeft",
|
|
229
|
+
icon: faAlignLeft,
|
|
230
|
+
toggle: true,
|
|
231
|
+
},
|
|
232
|
+
alignCenter: {
|
|
233
|
+
command: "justifyCenter",
|
|
234
|
+
icon: faAlignCenter,
|
|
235
|
+
toggle: true,
|
|
236
|
+
},
|
|
237
|
+
alignRight: {
|
|
238
|
+
command: "justifyRight",
|
|
239
|
+
icon: faAlignRight,
|
|
240
|
+
toggle: true,
|
|
241
|
+
},
|
|
242
|
+
alignJustify: {
|
|
243
|
+
command: "justifyFull",
|
|
244
|
+
icon: faAlignJustify,
|
|
245
|
+
toggle: true,
|
|
246
|
+
},
|
|
247
|
+
image: {
|
|
248
|
+
command: "image",
|
|
249
|
+
icon: faImage,
|
|
250
|
+
toggle: false,
|
|
251
|
+
},
|
|
252
|
+
table: {
|
|
253
|
+
command: "table",
|
|
254
|
+
icon: faTable,
|
|
255
|
+
toggle: false,
|
|
256
|
+
},
|
|
257
|
+
fontFamily: {
|
|
258
|
+
command: "fontFamily",
|
|
259
|
+
icon: faFont,
|
|
260
|
+
toggle: false,
|
|
261
|
+
},
|
|
262
|
+
fontSize: {
|
|
263
|
+
command: "fontSize",
|
|
264
|
+
icon: faTextHeight,
|
|
265
|
+
toggle: false,
|
|
266
|
+
},
|
|
267
|
+
textColor: {
|
|
268
|
+
command: "textColor",
|
|
269
|
+
icon: faPalette,
|
|
270
|
+
toggle: false,
|
|
271
|
+
},
|
|
175
272
|
};
|
|
176
273
|
const saida = [];
|
|
177
274
|
let posicao = 0;
|
|
@@ -239,12 +336,29 @@ function RichTextEditor(props) {
|
|
|
239
336
|
selecao.rangeCount > 0 &&
|
|
240
337
|
editorRef.current.contains(selecao.anchorNode));
|
|
241
338
|
}
|
|
339
|
+
function celulaAtual() {
|
|
340
|
+
if (typeof window === "undefined" ||
|
|
341
|
+
!window.getSelection ||
|
|
342
|
+
!editorRef.current)
|
|
343
|
+
return null;
|
|
344
|
+
const selecao = window.getSelection();
|
|
345
|
+
if (!selecao || selecao.rangeCount === 0)
|
|
346
|
+
return null;
|
|
347
|
+
const no = selecao.anchorNode;
|
|
348
|
+
const elemento = no && no.nodeType === 3 ? no.parentNode : no;
|
|
349
|
+
const celula = elemento && elemento.closest ? elemento.closest("td, th") : null;
|
|
350
|
+
return celula && editorRef.current.contains(celula) ? celula : null;
|
|
351
|
+
}
|
|
242
352
|
function lerEstados() {
|
|
243
353
|
if (typeof document === "undefined" ||
|
|
244
354
|
typeof document.queryCommandState !== "function")
|
|
245
355
|
return;
|
|
246
356
|
if (!selecaoNaArea())
|
|
247
357
|
return;
|
|
358
|
+
celulaRef.current = celulaAtual();
|
|
359
|
+
const dentro = !!celulaRef.current;
|
|
360
|
+
if (dentro !== inTable)
|
|
361
|
+
setInTable(dentro);
|
|
248
362
|
const comandos = [
|
|
249
363
|
"bold",
|
|
250
364
|
"italic",
|
|
@@ -252,6 +366,10 @@ function RichTextEditor(props) {
|
|
|
252
366
|
"strikeThrough",
|
|
253
367
|
"insertUnorderedList",
|
|
254
368
|
"insertOrderedList",
|
|
369
|
+
"justifyLeft",
|
|
370
|
+
"justifyCenter",
|
|
371
|
+
"justifyRight",
|
|
372
|
+
"justifyFull",
|
|
255
373
|
];
|
|
256
374
|
const ligados = [];
|
|
257
375
|
for (let i = 0; i < comandos.length; i++) {
|
|
@@ -320,6 +438,20 @@ function RichTextEditor(props) {
|
|
|
320
438
|
abrirLink();
|
|
321
439
|
return;
|
|
322
440
|
}
|
|
441
|
+
if (ferramenta.command === "image") {
|
|
442
|
+
abrirImagem();
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
if (ferramenta.command === "table") {
|
|
446
|
+
abrirTabela();
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
if (ferramenta.command === "fontFamily" ||
|
|
450
|
+
ferramenta.command === "fontSize" ||
|
|
451
|
+
ferramenta.command === "textColor") {
|
|
452
|
+
abrirEstilo(ferramenta.command);
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
323
455
|
if (editorRef.current && !selecaoNaArea())
|
|
324
456
|
editorRef.current.focus();
|
|
325
457
|
document.execCommand(ferramenta.command, false, undefined);
|
|
@@ -371,6 +503,9 @@ function RichTextEditor(props) {
|
|
|
371
503
|
}
|
|
372
504
|
setLinkUrl(enderecoAtual);
|
|
373
505
|
setLinkError(false);
|
|
506
|
+
setImageOpen(false);
|
|
507
|
+
setTableOpen(false);
|
|
508
|
+
setStyleOpen("");
|
|
374
509
|
setLinkOpen(true);
|
|
375
510
|
focoPendenteRef.current = "link";
|
|
376
511
|
}
|
|
@@ -435,6 +570,313 @@ function RichTextEditor(props) {
|
|
|
435
570
|
fecharLink();
|
|
436
571
|
}
|
|
437
572
|
}
|
|
573
|
+
function guardarSelecao() {
|
|
574
|
+
selecaoRef.current = null;
|
|
575
|
+
if (selecaoNaArea() && typeof window !== "undefined") {
|
|
576
|
+
const selecao = window.getSelection();
|
|
577
|
+
selecaoRef.current = selecao.getRangeAt(0).cloneRange();
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
function abrirImagem() {
|
|
581
|
+
if (!isEditable() || typeof window === "undefined" || imageOpen)
|
|
582
|
+
return;
|
|
583
|
+
guardarSelecao();
|
|
584
|
+
setImgUrl("");
|
|
585
|
+
setImgAlt("");
|
|
586
|
+
setImgData("");
|
|
587
|
+
setImgFileName("");
|
|
588
|
+
setImgError("");
|
|
589
|
+
setLinkOpen(false);
|
|
590
|
+
setTableOpen(false);
|
|
591
|
+
setStyleOpen("");
|
|
592
|
+
setImageOpen(true);
|
|
593
|
+
focoPendenteRef.current = "image";
|
|
594
|
+
}
|
|
595
|
+
function fecharImagem() {
|
|
596
|
+
setImageOpen(false);
|
|
597
|
+
setImgError("");
|
|
598
|
+
focoPendenteRef.current = "editor";
|
|
599
|
+
}
|
|
600
|
+
function handleImageUrl(texto) {
|
|
601
|
+
setImgUrl(texto);
|
|
602
|
+
setImgData("");
|
|
603
|
+
setImgFileName("");
|
|
604
|
+
if (imgError)
|
|
605
|
+
setImgError("");
|
|
606
|
+
}
|
|
607
|
+
function handleImageAlt(texto) {
|
|
608
|
+
setImgAlt(texto);
|
|
609
|
+
}
|
|
610
|
+
function escolherArquivo() {
|
|
611
|
+
if (fileInputRef.current)
|
|
612
|
+
fileInputRef.current.click();
|
|
613
|
+
}
|
|
614
|
+
function handleArquivo(event) {
|
|
615
|
+
const alvo = event && event.target ? event.target : null;
|
|
616
|
+
const arquivo = alvo && alvo.files ? alvo.files[0] : null;
|
|
617
|
+
if (!arquivo)
|
|
618
|
+
return;
|
|
619
|
+
if (!/^image\/(png|jpe?g|gif|webp)$/i.test(String(arquivo.type))) {
|
|
620
|
+
setImgError("type");
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
if (arquivo.size > 2 * 1024 * 1024) {
|
|
624
|
+
setImgError("size");
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
const leitor = new FileReader();
|
|
628
|
+
leitor.onload = () => {
|
|
629
|
+
setImgData(String(leitor.result || ""));
|
|
630
|
+
setImgFileName(arquivo.name);
|
|
631
|
+
setImgUrl("");
|
|
632
|
+
setImgError("");
|
|
633
|
+
};
|
|
634
|
+
leitor.readAsDataURL(arquivo);
|
|
635
|
+
}
|
|
636
|
+
function aplicarImagem() {
|
|
637
|
+
if (typeof document === "undefined")
|
|
638
|
+
return;
|
|
639
|
+
const origem = imagemSegura(imgData || normalizarEndereco(imgUrl));
|
|
640
|
+
if (!origem) {
|
|
641
|
+
setImgError("invalid");
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
restaurarSelecao();
|
|
645
|
+
document.execCommand("insertHTML", false, htmlDaImagem(origem, imgAlt));
|
|
646
|
+
setImageOpen(false);
|
|
647
|
+
focoPendenteRef.current = "editor";
|
|
648
|
+
handleInput();
|
|
649
|
+
}
|
|
650
|
+
function handleImageSubmit(event) {
|
|
651
|
+
if (event && event.preventDefault)
|
|
652
|
+
event.preventDefault();
|
|
653
|
+
aplicarImagem();
|
|
654
|
+
}
|
|
655
|
+
function handlePanelKeyDown(event) {
|
|
656
|
+
if (!event || event.key !== "Escape")
|
|
657
|
+
return;
|
|
658
|
+
event.preventDefault();
|
|
659
|
+
event.stopPropagation();
|
|
660
|
+
if (imageOpen)
|
|
661
|
+
fecharImagem();
|
|
662
|
+
else
|
|
663
|
+
fecharTabela();
|
|
664
|
+
}
|
|
665
|
+
function imageErrorText() {
|
|
666
|
+
if (imgError === "invalid")
|
|
667
|
+
return rotulo("imageInvalid");
|
|
668
|
+
if (imgError === "type")
|
|
669
|
+
return rotulo("imageType");
|
|
670
|
+
if (imgError === "size")
|
|
671
|
+
return rotulo("imageTooLarge");
|
|
672
|
+
return undefined;
|
|
673
|
+
}
|
|
674
|
+
function abrirTabela() {
|
|
675
|
+
if (!isEditable() || typeof window === "undefined" || tableOpen)
|
|
676
|
+
return;
|
|
677
|
+
guardarSelecao();
|
|
678
|
+
setTblError(false);
|
|
679
|
+
setLinkOpen(false);
|
|
680
|
+
setImageOpen(false);
|
|
681
|
+
setStyleOpen("");
|
|
682
|
+
setTableOpen(true);
|
|
683
|
+
focoPendenteRef.current = "table";
|
|
684
|
+
}
|
|
685
|
+
function fecharTabela() {
|
|
686
|
+
setTableOpen(false);
|
|
687
|
+
setTblError(false);
|
|
688
|
+
focoPendenteRef.current = "editor";
|
|
689
|
+
}
|
|
690
|
+
function handleTableRows(texto) {
|
|
691
|
+
setTblRows(texto);
|
|
692
|
+
if (tblError)
|
|
693
|
+
setTblError(false);
|
|
694
|
+
}
|
|
695
|
+
function handleTableCols(texto) {
|
|
696
|
+
setTblCols(texto);
|
|
697
|
+
if (tblError)
|
|
698
|
+
setTblError(false);
|
|
699
|
+
}
|
|
700
|
+
function aplicarTabela() {
|
|
701
|
+
if (typeof document === "undefined")
|
|
702
|
+
return;
|
|
703
|
+
const linhas = parseInt(tblRows, 10);
|
|
704
|
+
const colunas = parseInt(tblCols, 10);
|
|
705
|
+
if (!(linhas >= 1 && linhas <= 20 && colunas >= 1 && colunas <= 10)) {
|
|
706
|
+
setTblError(true);
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
restaurarSelecao();
|
|
710
|
+
document.execCommand("insertHTML", false, htmlDaTabela(linhas, colunas));
|
|
711
|
+
setTableOpen(false);
|
|
712
|
+
focoPendenteRef.current = "editor";
|
|
713
|
+
handleInput();
|
|
714
|
+
}
|
|
715
|
+
function handleTableSubmit(event) {
|
|
716
|
+
if (event && event.preventDefault)
|
|
717
|
+
event.preventDefault();
|
|
718
|
+
aplicarTabela();
|
|
719
|
+
}
|
|
720
|
+
function tableErrorText() {
|
|
721
|
+
return tblError ? rotulo("tableInvalid") : undefined;
|
|
722
|
+
}
|
|
723
|
+
function tableBarVisible() {
|
|
724
|
+
if (!inTable || !isEditable())
|
|
725
|
+
return false;
|
|
726
|
+
const lista = props.toolbar || [];
|
|
727
|
+
return lista.indexOf("table") !== -1;
|
|
728
|
+
}
|
|
729
|
+
function handleTableAction(acao) {
|
|
730
|
+
const celula = celulaRef.current;
|
|
731
|
+
if (!celula || !editorRef.current || !editorRef.current.contains(celula))
|
|
732
|
+
return;
|
|
733
|
+
const linha = celula.parentNode;
|
|
734
|
+
const tabela = celula.closest("table");
|
|
735
|
+
if (!linha || !tabela)
|
|
736
|
+
return;
|
|
737
|
+
const indice = celula.cellIndex;
|
|
738
|
+
const linhas = Array.prototype.slice.call(tabela.rows);
|
|
739
|
+
const nova = (tag) => {
|
|
740
|
+
const c = document.createElement(tag);
|
|
741
|
+
c.appendChild(document.createElement("br"));
|
|
742
|
+
return c;
|
|
743
|
+
};
|
|
744
|
+
if (acao === "addRow") {
|
|
745
|
+
const novaLinha = document.createElement("tr");
|
|
746
|
+
for (let i = 0; i < linha.cells.length; i++)
|
|
747
|
+
novaLinha.appendChild(nova("td"));
|
|
748
|
+
linha.parentNode.insertBefore(novaLinha, linha.nextSibling);
|
|
749
|
+
}
|
|
750
|
+
else if (acao === "removeRow") {
|
|
751
|
+
if (linhas.length <= 1)
|
|
752
|
+
tabela.parentNode.removeChild(tabela);
|
|
753
|
+
else
|
|
754
|
+
linha.parentNode.removeChild(linha);
|
|
755
|
+
}
|
|
756
|
+
else if (acao === "addCol") {
|
|
757
|
+
for (let i = 0; i < linhas.length; i++) {
|
|
758
|
+
const ref = linhas[i].cells[indice];
|
|
759
|
+
const tag = ref && ref.tagName === "TH" ? "th" : "td";
|
|
760
|
+
const novaCelula = nova(tag);
|
|
761
|
+
if (ref)
|
|
762
|
+
linhas[i].insertBefore(novaCelula, ref.nextSibling);
|
|
763
|
+
else
|
|
764
|
+
linhas[i].appendChild(novaCelula);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
else if (acao === "removeCol") {
|
|
768
|
+
if (linha.cells.length <= 1)
|
|
769
|
+
tabela.parentNode.removeChild(tabela);
|
|
770
|
+
else {
|
|
771
|
+
for (let i = 0; i < linhas.length; i++) {
|
|
772
|
+
const ref = linhas[i].cells[indice];
|
|
773
|
+
if (ref)
|
|
774
|
+
linhas[i].removeChild(ref);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
else if (acao === "removeTable") {
|
|
779
|
+
tabela.parentNode.removeChild(tabela);
|
|
780
|
+
}
|
|
781
|
+
celulaRef.current = null;
|
|
782
|
+
setInTable(false);
|
|
783
|
+
handleInput();
|
|
784
|
+
if (editorRef.current)
|
|
785
|
+
editorRef.current.focus();
|
|
786
|
+
}
|
|
787
|
+
function fontFamilyOptions() {
|
|
788
|
+
return [
|
|
789
|
+
{
|
|
790
|
+
label: rotulo("fontFamilyBase"),
|
|
791
|
+
value: "var(--umds-semantic-font-family-base)",
|
|
792
|
+
},
|
|
793
|
+
{
|
|
794
|
+
label: rotulo("fontFamilyMono"),
|
|
795
|
+
value: "var(--umds-semantic-font-family-mono)",
|
|
796
|
+
},
|
|
797
|
+
];
|
|
798
|
+
}
|
|
799
|
+
function fontSizeOptions() {
|
|
800
|
+
return [
|
|
801
|
+
{
|
|
802
|
+
label: "12",
|
|
803
|
+
value: "var(--umds-primitive-font-size-xxxs)",
|
|
804
|
+
},
|
|
805
|
+
{
|
|
806
|
+
label: "14",
|
|
807
|
+
value: "var(--umds-primitive-font-size-xxs)",
|
|
808
|
+
},
|
|
809
|
+
{
|
|
810
|
+
label: "16",
|
|
811
|
+
value: "var(--umds-primitive-font-size-xs)",
|
|
812
|
+
},
|
|
813
|
+
{
|
|
814
|
+
label: "20",
|
|
815
|
+
value: "var(--umds-primitive-font-size-sm)",
|
|
816
|
+
},
|
|
817
|
+
{
|
|
818
|
+
label: "24",
|
|
819
|
+
value: "var(--umds-primitive-font-size-md)",
|
|
820
|
+
},
|
|
821
|
+
];
|
|
822
|
+
}
|
|
823
|
+
function abrirEstilo(qual) {
|
|
824
|
+
if (!isEditable() || typeof window === "undefined")
|
|
825
|
+
return;
|
|
826
|
+
guardarSelecao();
|
|
827
|
+
setStyleError(false);
|
|
828
|
+
setLinkOpen(false);
|
|
829
|
+
setImageOpen(false);
|
|
830
|
+
setTableOpen(false);
|
|
831
|
+
setStyleOpen(qual);
|
|
832
|
+
focoPendenteRef.current = "style";
|
|
833
|
+
}
|
|
834
|
+
function fecharEstilo() {
|
|
835
|
+
setStyleOpen("");
|
|
836
|
+
setStyleError(false);
|
|
837
|
+
focoPendenteRef.current = "editor";
|
|
838
|
+
}
|
|
839
|
+
function aplicarEstilo(propriedade, valor) {
|
|
840
|
+
if (typeof document === "undefined" || typeof window === "undefined")
|
|
841
|
+
return;
|
|
842
|
+
const declaracao = estiloDeTexto(propriedade, valor);
|
|
843
|
+
if (!declaracao)
|
|
844
|
+
return;
|
|
845
|
+
restaurarSelecao();
|
|
846
|
+
const selecao = window.getSelection();
|
|
847
|
+
if (!selecao || selecao.rangeCount === 0 || selecao.isCollapsed) {
|
|
848
|
+
setStyleError(true);
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
const molde = document.createElement("div");
|
|
852
|
+
molde.appendChild(selecao.getRangeAt(0).cloneContents());
|
|
853
|
+
document.execCommand("insertHTML", false, '<span style="' + declaracao + '">' + molde.innerHTML + "</span>");
|
|
854
|
+
setStyleOpen("");
|
|
855
|
+
setStyleError(false);
|
|
856
|
+
focoPendenteRef.current = "editor";
|
|
857
|
+
handleInput();
|
|
858
|
+
}
|
|
859
|
+
function aplicarCor(token) {
|
|
860
|
+
if (!token || token.indexOf("--") !== 0)
|
|
861
|
+
return;
|
|
862
|
+
aplicarEstilo("color", "var(" + token + ")");
|
|
863
|
+
}
|
|
864
|
+
function handleStyleKeyDown(event) {
|
|
865
|
+
if (!event || event.key !== "Escape")
|
|
866
|
+
return;
|
|
867
|
+
// O Select aberto já tratou o Esc (fechou a lista e deu preventDefault): o painel fica para o próximo.
|
|
868
|
+
if (event.defaultPrevented)
|
|
869
|
+
return;
|
|
870
|
+
event.preventDefault();
|
|
871
|
+
event.stopPropagation();
|
|
872
|
+
fecharEstilo();
|
|
873
|
+
}
|
|
874
|
+
function styleErrorText() {
|
|
875
|
+
return styleError ? rotulo("styleNeedsSelection") : undefined;
|
|
876
|
+
}
|
|
877
|
+
function stylePanelLabel() {
|
|
878
|
+
return styleOpen ? rotulo(styleOpen) : "";
|
|
879
|
+
}
|
|
438
880
|
function linkErrorText() {
|
|
439
881
|
return linkError ? rotulo("linkInvalid") : undefined;
|
|
440
882
|
}
|
|
@@ -479,6 +921,21 @@ function RichTextEditor(props) {
|
|
|
479
921
|
if (campo)
|
|
480
922
|
campo.focus();
|
|
481
923
|
}
|
|
924
|
+
else if (alvo === "image" && imageInputWrapRef.current) {
|
|
925
|
+
const campo = imageInputWrapRef.current.querySelector("input");
|
|
926
|
+
if (campo)
|
|
927
|
+
campo.focus();
|
|
928
|
+
}
|
|
929
|
+
else if (alvo === "table" && tableInputWrapRef.current) {
|
|
930
|
+
const campo = tableInputWrapRef.current.querySelector("input");
|
|
931
|
+
if (campo)
|
|
932
|
+
campo.focus();
|
|
933
|
+
}
|
|
934
|
+
else if (alvo === "style" && styleWrapRef.current) {
|
|
935
|
+
const campo = styleWrapRef.current.querySelector('[role="combobox"], [role="radio"], button');
|
|
936
|
+
if (campo)
|
|
937
|
+
campo.focus();
|
|
938
|
+
}
|
|
482
939
|
}
|
|
483
940
|
});
|
|
484
941
|
useEffect(() => {
|
|
@@ -489,6 +946,6 @@ function RichTextEditor(props) {
|
|
|
489
946
|
}
|
|
490
947
|
};
|
|
491
948
|
}, []);
|
|
492
|
-
return (_jsxs("div", { className: classes(), children: [props.label ? (_jsx("span", { className: "umds-rte__label", id: labelId(), children: props.label })) : null, _jsxs("div", { className: "umds-rte__frame", children: [showToolbar() ? (_jsx("div", { role: "toolbar", className: "umds-rte__toolbar", ref: toolbarRef, "aria-label": toolbarName(), "aria-controls": editorId(), onKeyDown: (event) => handleToolbarKeyDown(event), children: tools()?.map((ferramenta) => (_jsxs(React.Fragment, { children: [ferramenta.separator ? (_jsx("span", { role: "separator", "aria-orientation": "vertical", className: "umds-rte__separator" })) : null, !ferramenta.separator ? (_jsx("button", { type: "button", "aria-label": ferramenta.label, title: ferramenta.label, "aria-pressed": pressedText(ferramenta), tabIndex: toolTabIndex(ferramenta), disabled: !isEditable(), onMouseDown: (event) => handleToolMouseDown(event), onClick: (event) => handleToolClick(ferramenta), onFocus: (event) => handleToolFocus(ferramenta), className: toolClasses(ferramenta), children: _jsx(Icon, { size: "sm", variant: "inherit", icon: ferramenta.icon }) })) : null] }, ferramenta.key))) })) : null, linkOpen ? (_jsxs("form", { className: "umds-rte__link", noValidate: true, onSubmit: (event) => handleLinkSubmit(event), onKeyDown: (event) => handleLinkKeyDown(event), children: [_jsx("div", { className: "umds-rte__link-field", ref: linkInputWrapRef, children: _jsx(Input, { size: "sm", type: "url", placeholder: "https://", label: rotulo("linkAddress"), value: linkUrl, errorMessage: linkErrorText(), onChange: (texto) => handleLinkInput(texto) }) }), _jsxs("div", { className: "umds-rte__link-actions", children: [_jsx(Button, { variant: "primary", size: "sm", type: "submit", children: rotulo("linkApply") }), linkRemoveVisible() ? (_jsx(Button, { variant: "secondary", size: "sm", onClick: (event) => removerLink(), children: rotulo("linkRemove") })) : null, _jsx(Button, { variant: "text", size: "sm", onClick: (event) => fecharLink(), children: rotulo("linkCancel") })] })] })) : null, _jsx("div", { role: "textbox", "aria-multiline": "true", className: "umds-rte__editor", ref: editorRef, id: editorId(), "aria-label": editorAriaLabel(), "aria-labelledby": labelId(), "aria-describedby": describedBy(), "aria-invalid": isInvalid() ? "true" : undefined, "aria-readonly": props.readOnly ? "true" : undefined, "aria-disabled": props.disabled ? "true" : undefined, "aria-placeholder": props.placeholder, "data-placeholder": props.placeholder, contentEditable: editableText(), tabIndex: props.disabled ? -1 : 0, style: editorStyle(), onInput: (event) => handleInput(), onPaste: (event) => handlePaste(event), onKeyDown: (event) => handleEditorKeyDown(event), onBlur: (event) => handleBlur(event) }), props.footer ? (_jsx("div", { className: "umds-rte__footer", children: _jsx(_Fragment, { children: props.footer }) })) : null] }), props.errorMessage ? (_jsx(Text, { as: "span", variant: "caption", color: "negative", id: errorId(), children: props.errorMessage })) : null, props.helperText ? (_jsx(Text, { as: "span", variant: "caption", color: "secondary", id: helperId(), children: props.helperText })) : null] }));
|
|
949
|
+
return (_jsxs("div", { className: classes(), children: [props.label ? (_jsx("span", { className: "umds-rte__label", id: labelId(), children: props.label })) : null, _jsxs("div", { className: "umds-rte__frame", children: [showToolbar() ? (_jsx("div", { role: "toolbar", className: "umds-rte__toolbar", ref: toolbarRef, "aria-label": toolbarName(), "aria-controls": editorId(), onKeyDown: (event) => handleToolbarKeyDown(event), children: tools()?.map((ferramenta) => (_jsxs(React.Fragment, { children: [ferramenta.separator ? (_jsx("span", { role: "separator", "aria-orientation": "vertical", className: "umds-rte__separator" })) : null, !ferramenta.separator ? (_jsx("button", { type: "button", "aria-label": ferramenta.label, title: ferramenta.label, "aria-pressed": pressedText(ferramenta), tabIndex: toolTabIndex(ferramenta), disabled: !isEditable(), onMouseDown: (event) => handleToolMouseDown(event), onClick: (event) => handleToolClick(ferramenta), onFocus: (event) => handleToolFocus(ferramenta), className: toolClasses(ferramenta), children: _jsx(Icon, { size: "sm", variant: "inherit", icon: ferramenta.icon }) })) : null] }, ferramenta.key))) })) : null, linkOpen ? (_jsxs("form", { className: "umds-rte__link", noValidate: true, onSubmit: (event) => handleLinkSubmit(event), onKeyDown: (event) => handleLinkKeyDown(event), children: [_jsx("div", { className: "umds-rte__link-field", ref: linkInputWrapRef, children: _jsx(Input, { size: "sm", type: "url", placeholder: "https://", label: rotulo("linkAddress"), value: linkUrl, errorMessage: linkErrorText(), onChange: (texto) => handleLinkInput(texto) }) }), _jsxs("div", { className: "umds-rte__link-actions", children: [_jsx(Button, { variant: "primary", size: "sm", type: "submit", children: rotulo("linkApply") }), linkRemoveVisible() ? (_jsx(Button, { variant: "secondary", size: "sm", onClick: (event) => removerLink(), children: rotulo("linkRemove") })) : null, _jsx(Button, { variant: "text", size: "sm", onClick: (event) => fecharLink(), children: rotulo("linkCancel") })] })] })) : null, imageOpen ? (_jsxs("form", { className: "umds-rte__link", noValidate: true, onSubmit: (event) => handleImageSubmit(event), onKeyDown: (event) => handlePanelKeyDown(event), children: [_jsx("div", { className: "umds-rte__link-field", ref: imageInputWrapRef, children: _jsx(Input, { size: "sm", type: "url", placeholder: "https://", label: rotulo("imageUrl"), value: imgUrl, errorMessage: imageErrorText(), onChange: (texto) => handleImageUrl(texto) }) }), _jsx("div", { className: "umds-rte__link-field", children: _jsx(Input, { size: "sm", label: rotulo("imageAlt"), value: imgAlt, onChange: (texto) => handleImageAlt(texto) }) }), _jsxs("div", { className: "umds-rte__link-actions", children: [_jsx(Button, { variant: "secondary", size: "sm", onClick: (event) => escolherArquivo(), children: rotulo("imageFile") }), _jsx("input", { type: "file", accept: "image/png,image/jpeg,image/gif,image/webp", ref: fileInputRef, hidden: true, onChange: (event) => handleArquivo(event) }), imgFileName ? (_jsx(Text, { as: "span", variant: "caption", color: "secondary", children: imgFileName })) : null, _jsx(Button, { variant: "primary", size: "sm", type: "submit", children: rotulo("imageApply") }), _jsx(Button, { variant: "text", size: "sm", onClick: (event) => fecharImagem(), children: rotulo("imageCancel") })] })] })) : null, tableOpen ? (_jsxs("form", { className: "umds-rte__link", noValidate: true, onSubmit: (event) => handleTableSubmit(event), onKeyDown: (event) => handlePanelKeyDown(event), children: [_jsx("div", { className: "umds-rte__table-field", ref: tableInputWrapRef, children: _jsx(Input, { size: "sm", type: "number", label: rotulo("tableRows"), value: tblRows, errorMessage: tableErrorText(), onChange: (texto) => handleTableRows(texto) }) }), _jsx("div", { className: "umds-rte__table-field", children: _jsx(Input, { size: "sm", type: "number", label: rotulo("tableCols"), value: tblCols, onChange: (texto) => handleTableCols(texto) }) }), _jsxs("div", { className: "umds-rte__link-actions", children: [_jsx(Button, { variant: "primary", size: "sm", type: "submit", children: rotulo("tableApply") }), _jsx(Button, { variant: "text", size: "sm", onClick: (event) => fecharTabela(), children: rotulo("tableCancel") })] })] })) : null, styleOpen !== "" ? (_jsxs("div", { role: "group", className: "umds-rte__link", "aria-label": stylePanelLabel(), onKeyDown: (event) => handleStyleKeyDown(event), children: [_jsxs("div", { className: "umds-rte__style-field", ref: styleWrapRef, children: [styleOpen === "fontFamily" ? (_jsx(Select, { size: "sm", ariaLabel: rotulo("fontFamily"), placeholder: rotulo("fontFamily"), options: fontFamilyOptions(), onChange: (valor) => aplicarEstilo("font-family", String(valor)) })) : null, styleOpen === "fontSize" ? (_jsx(Select, { size: "sm", ariaLabel: rotulo("fontSize"), placeholder: rotulo("fontSize"), options: fontSizeOptions(), onChange: (valor) => aplicarEstilo("font-size", String(valor)) })) : null, styleOpen === "textColor" ? (_jsx(ColorPicker, { size: "xs", ariaLabel: rotulo("textColor"), onChange: (token) => aplicarCor(token) })) : null] }), _jsx("div", { className: "umds-rte__link-actions", children: _jsx(Button, { variant: "text", size: "sm", onClick: (event) => fecharEstilo(), children: rotulo("styleClose") }) }), styleErrorText() ? (_jsx(Text, { as: "span", variant: "caption", color: "negative", role: "alert", children: styleErrorText() })) : null] })) : null, tableBarVisible() ? (_jsxs("div", { role: "group", className: "umds-rte__table-bar", "aria-label": rotulo("tableActions"), children: [_jsx(Button, { variant: "text", size: "sm", onClick: (event) => handleTableAction("addRow"), children: rotulo("tableAddRow") }), _jsx(Button, { variant: "text", size: "sm", onClick: (event) => handleTableAction("removeRow"), children: rotulo("tableRemoveRow") }), _jsx(Button, { variant: "text", size: "sm", onClick: (event) => handleTableAction("addCol"), children: rotulo("tableAddCol") }), _jsx(Button, { variant: "text", size: "sm", onClick: (event) => handleTableAction("removeCol"), children: rotulo("tableRemoveCol") }), _jsx(Button, { variant: "text", size: "sm", onClick: (event) => handleTableAction("removeTable"), children: rotulo("tableRemove") })] })) : null, _jsx("div", { role: "textbox", "aria-multiline": "true", className: "umds-rte__editor", ref: editorRef, id: editorId(), "aria-label": editorAriaLabel(), "aria-labelledby": labelId(), "aria-describedby": describedBy(), "aria-invalid": isInvalid() ? "true" : undefined, "aria-readonly": props.readOnly ? "true" : undefined, "aria-disabled": props.disabled ? "true" : undefined, "aria-placeholder": props.placeholder, "data-placeholder": props.placeholder, contentEditable: editableText(), tabIndex: props.disabled ? -1 : 0, style: editorStyle(), onInput: (event) => handleInput(), onPaste: (event) => handlePaste(event), onKeyDown: (event) => handleEditorKeyDown(event), onBlur: (event) => handleBlur(event) }), props.footer ? (_jsx("div", { className: "umds-rte__footer", children: _jsx(_Fragment, { children: props.footer }) })) : null] }), props.errorMessage ? (_jsx(Text, { as: "span", variant: "caption", color: "negative", id: errorId(), children: props.errorMessage })) : null, props.helperText ? (_jsx(Text, { as: "span", variant: "caption", color: "secondary", id: helperId(), children: props.helperText })) : null] }));
|
|
493
950
|
}
|
|
494
951
|
export default RichTextEditor;
|
|
@@ -184,3 +184,27 @@
|
|
|
184
184
|
[data-density="touch"] .umds-segmented__item {
|
|
185
185
|
min-height: var(--umds-semantic-field-height);
|
|
186
186
|
}
|
|
187
|
+
|
|
188
|
+
/* ── Contador em pílula (count) ──
|
|
189
|
+
Mesmos 18px da pílula do Tab (16 + 2, dois degraus do DS somados; sem token
|
|
190
|
+
próprio): cinza no segmento solto, branco sobre o azul do escolhido. */
|
|
191
|
+
.umds-segmented__count {
|
|
192
|
+
display: inline-flex;
|
|
193
|
+
align-items: center;
|
|
194
|
+
justify-content: center;
|
|
195
|
+
box-sizing: border-box;
|
|
196
|
+
height: calc(var(--umds-primitive-spacing-xxxs) + var(--umds-primitive-spacing-micro)); /* 18px */
|
|
197
|
+
min-width: calc(var(--umds-primitive-spacing-xxxs) + var(--umds-primitive-spacing-micro)); /* 18px */
|
|
198
|
+
padding: 0 var(--umds-primitive-spacing-quarck); /* 4px */
|
|
199
|
+
border-radius: var(--umds-primitive-border-radius-pill);
|
|
200
|
+
background-color: var(--umds-semantic-color-neutral-light-medium);
|
|
201
|
+
color: var(--umds-semantic-color-neutral-dark-down);
|
|
202
|
+
font-size: var(--umds-primitive-font-size-xxxs); /* 12px */
|
|
203
|
+
font-weight: var(--umds-primitive-font-weight-semibold);
|
|
204
|
+
line-height: 1;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.umds-segmented__input:checked + .umds-segmented__item .umds-segmented__count {
|
|
208
|
+
background-color: var(--umds-semantic-color-neutral-light-pure);
|
|
209
|
+
color: var(--umds-semantic-color-primary-pure);
|
|
210
|
+
}
|
|
@@ -6,6 +6,7 @@ import './SegmentedControl.css';
|
|
|
6
6
|
* @property {any} icon - Ícone Font Awesome antes do texto. Com `label` vazio, o segmento vira só o ícone — e aí `ariaLabel` é obrigatório.
|
|
7
7
|
* @property {string} ariaLabel - Nome acessível do segmento quando não há texto visível.
|
|
8
8
|
* @property {boolean} disabled - Desabilita só este segmento.
|
|
9
|
+
* @property {number|string} count - Contador em pílula depois do texto (ex.: "Todas 31"), como o da `Tab`: cinza no segmento solto, branco sobre o azul do escolhido. É lido junto do nome do segmento. 0 aparece; vazio e `undefined` não.
|
|
9
10
|
*/
|
|
10
11
|
export interface SegmentedControlOption {
|
|
11
12
|
label?: string;
|
|
@@ -13,6 +14,7 @@ export interface SegmentedControlOption {
|
|
|
13
14
|
icon?: any;
|
|
14
15
|
ariaLabel?: string;
|
|
15
16
|
disabled?: boolean;
|
|
17
|
+
count?: number | string;
|
|
16
18
|
[key: string]: any;
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
@@ -63,6 +63,9 @@ function SegmentedControl(props) {
|
|
|
63
63
|
function estaEscolhido(option) {
|
|
64
64
|
return option.value === currentValue();
|
|
65
65
|
}
|
|
66
|
+
function temContador(option) {
|
|
67
|
+
return (option.count !== undefined && option.count !== null && option.count !== "");
|
|
68
|
+
}
|
|
66
69
|
function estaDesabilitado(option) {
|
|
67
70
|
return !!props.disabled || !!option.disabled;
|
|
68
71
|
}
|
|
@@ -88,6 +91,6 @@ function SegmentedControl(props) {
|
|
|
88
91
|
if (!props.id)
|
|
89
92
|
setUid(gerarId("umds-segmented"));
|
|
90
93
|
}, []);
|
|
91
|
-
return (_jsxs("div", { className: groupClasses(), children: [props.label ? (_jsxs("span", { className: "umds-segmented__group-label", id: labelId(), children: [props.label, props.required ? (_jsx("span", { className: "umds-segmented__required", children: " *" })) : null] })) : null, _jsx("div", { role: "radiogroup", className: "umds-segmented__track", "aria-labelledby": labelledByText(), "aria-label": groupAriaLabel(), "aria-describedby": describedByText(), "aria-invalid": ariaInvalidText(), "aria-required": ariaRequiredText(), children: optionList()?.map((option, index) => (_jsxs(React.Fragment, { children: [_jsx("input", { type: "radio", className: "umds-segmented__input", id: inputId(index), name: groupName(), value: option.value, checked: estaEscolhido(option), disabled: estaDesabilitado(option), "aria-label": rotuloDoSegmento(option), onChange: (event) => handleChange(option) }), _jsx("label", { className: "umds-segmented__item", htmlFor: inputId(index), children: _jsxs("span", { className: "umds-segmented__conteudo", children: [option.icon ? (_jsx(Icon, { size: "sm", variant: "inherit", icon: option.icon })) : null, option.label ? (_jsx("span", { className: "umds-segmented__texto", children: option.label })) : null] }) })] }, option.value))) }), props.errorMessage ? (_jsx(Text, { as: "span", variant: "caption", color: "negative", className: "umds-segmented__error-message", id: errorId(), children: props.errorMessage })) : null] }));
|
|
94
|
+
return (_jsxs("div", { className: groupClasses(), children: [props.label ? (_jsxs("span", { className: "umds-segmented__group-label", id: labelId(), children: [props.label, props.required ? (_jsx("span", { className: "umds-segmented__required", children: " *" })) : null] })) : null, _jsx("div", { role: "radiogroup", className: "umds-segmented__track", "aria-labelledby": labelledByText(), "aria-label": groupAriaLabel(), "aria-describedby": describedByText(), "aria-invalid": ariaInvalidText(), "aria-required": ariaRequiredText(), children: optionList()?.map((option, index) => (_jsxs(React.Fragment, { children: [_jsx("input", { type: "radio", className: "umds-segmented__input", id: inputId(index), name: groupName(), value: option.value, checked: estaEscolhido(option), disabled: estaDesabilitado(option), "aria-label": rotuloDoSegmento(option), onChange: (event) => handleChange(option) }), _jsx("label", { className: "umds-segmented__item", htmlFor: inputId(index), children: _jsxs("span", { className: "umds-segmented__conteudo", children: [option.icon ? (_jsx(Icon, { size: "sm", variant: "inherit", icon: option.icon })) : null, option.label ? (_jsx("span", { className: "umds-segmented__texto", children: option.label })) : null, temContador(option) ? (_jsx("span", { className: "umds-segmented__count", children: option.count })) : null] }) })] }, option.value))) }), props.errorMessage ? (_jsx(Text, { as: "span", variant: "caption", color: "negative", className: "umds-segmented__error-message", id: errorId(), children: props.errorMessage })) : null] }));
|
|
92
95
|
}
|
|
93
96
|
export default SegmentedControl;
|