@1doc/1ds-react 2.8.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 +1540 -0
- package/dist/components/AILabel/AILabel.js +1 -1
- package/dist/components/Accordion/Accordion.css +13 -0
- package/dist/components/Accordion/Accordion.d.ts +9 -2
- package/dist/components/Accordion/Accordion.js +1 -0
- package/dist/components/AppSubheader/AppSubheader.css +10 -1
- package/dist/components/AttachmentCard/AttachmentCard.css +26 -8
- package/dist/components/AttachmentCard/AttachmentCard.d.ts +22 -2
- package/dist/components/AttachmentCard/AttachmentCard.js +47 -3
- package/dist/components/Avatar/Avatar.css +7 -2
- package/dist/components/Avatar/AvatarGroup.d.ts +17 -0
- package/dist/components/Avatar/AvatarGroup.js +22 -8
- package/dist/components/Badge/Badge.css +67 -2
- package/dist/components/Badge/Badge.d.ts +23 -4
- package/dist/components/Badge/Badge.js +4 -0
- package/dist/components/Box/Box.css +83 -0
- package/dist/components/Box/Box.d.ts +82 -2
- package/dist/components/Box/Box.js +42 -2
- package/dist/components/Button/Button.css +29 -0
- package/dist/components/Button/Button.d.ts +4 -4
- package/dist/components/Button/Button.js +4 -1
- package/dist/components/Calendar/Calendar.css +245 -0
- package/dist/components/Calendar/Calendar.d.ts +126 -0
- package/dist/components/Calendar/Calendar.js +320 -0
- package/dist/components/Chips/Chips.css +38 -0
- package/dist/components/Chips/Chips.d.ts +5 -2
- package/dist/components/Chips/Chips.js +2 -1
- package/dist/components/Coachmark/Coachmark.css +128 -0
- package/dist/components/Coachmark/Coachmark.d.ts +87 -0
- package/dist/components/Coachmark/Coachmark.js +362 -0
- package/dist/components/CodeBlock/CodeBlock.css +96 -0
- package/dist/components/CodeBlock/CodeBlock.d.ts +47 -0
- package/dist/components/CodeBlock/CodeBlock.js +103 -0
- package/dist/components/ColorPicker/ColorPicker.css +140 -0
- package/dist/components/ColorPicker/ColorPicker.d.ts +73 -0
- package/dist/components/ColorPicker/ColorPicker.js +219 -0
- package/dist/components/Combobox/Combobox.css +8 -0
- package/dist/components/DataTable/DataTable.css +254 -0
- package/dist/components/DataTable/DataTable.d.ts +81 -5
- package/dist/components/DataTable/DataTable.js +335 -19
- package/dist/components/DatePicker/DatePicker.css +8 -0
- package/dist/components/DatePicker/DatePicker.js +10 -1
- package/dist/components/DescriptionList/DescriptionList.css +127 -0
- package/dist/components/DescriptionList/DescriptionList.d.ts +62 -0
- package/dist/components/DescriptionList/DescriptionList.js +52 -0
- package/dist/components/EmptyState/EmptyState.d.ts +4 -2
- package/dist/components/EmptyState/EmptyState.js +2 -2
- package/dist/components/FileInput/FileInput.css +16 -0
- package/dist/components/FileInput/FileInput.d.ts +4 -2
- package/dist/components/FileInput/FileInput.js +8 -2
- package/dist/components/Grid/Grid.js +5 -5
- package/dist/components/IconPicker/IconPicker.css +107 -0
- package/dist/components/IconPicker/IconPicker.d.ts +74 -0
- package/dist/components/IconPicker/IconPicker.js +194 -0
- package/dist/components/Input/Input.css +59 -0
- package/dist/components/Input/Input.d.ts +17 -1
- package/dist/components/Input/Input.js +67 -5
- package/dist/components/Kanban/Kanban.css +4 -0
- package/dist/components/Kbd/Kbd.css +66 -0
- package/dist/components/Kbd/Kbd.d.ts +32 -0
- package/dist/components/Kbd/Kbd.js +40 -0
- package/dist/components/List/List.css +136 -0
- package/dist/components/List/List.d.ts +82 -0
- package/dist/components/List/List.js +53 -0
- package/dist/components/List/ListItem.d.ts +97 -0
- package/dist/components/List/ListItem.js +82 -0
- package/dist/components/Modal/Modal.css +80 -0
- package/dist/components/Modal/Modal.d.ts +33 -6
- package/dist/components/Modal/Modal.js +101 -6
- package/dist/components/MultiSelect/MultiSelect.css +8 -0
- package/dist/components/MultiSelect/MultiSelect.js +10 -1
- package/dist/components/OrgChart/OrgChart.css +149 -0
- package/dist/components/OrgChart/OrgChart.d.ts +83 -0
- package/dist/components/OrgChart/OrgChart.js +297 -0
- package/dist/components/OtpInput/OtpInput.css +93 -0
- package/dist/components/OtpInput/OtpInput.d.ts +60 -0
- package/dist/components/OtpInput/OtpInput.js +215 -0
- package/dist/components/PhoneInput/PhoneInput.css +8 -0
- package/dist/components/Popover/Popover.d.ts +7 -0
- package/dist/components/Popover/Popover.js +11 -1
- package/dist/components/RichTextEditor/RichTextEditor.css +250 -0
- package/dist/components/RichTextEditor/RichTextEditor.d.ts +97 -0
- package/dist/components/RichTextEditor/RichTextEditor.js +951 -0
- package/dist/components/SegmentedControl/SegmentedControl.css +24 -0
- package/dist/components/SegmentedControl/SegmentedControl.d.ts +2 -0
- package/dist/components/SegmentedControl/SegmentedControl.js +10 -2
- package/dist/components/Select/Select.css +164 -0
- package/dist/components/Select/Select.d.ts +34 -0
- package/dist/components/Select/Select.js +258 -28
- package/dist/components/Stack/Stack.css +49 -0
- package/dist/components/Stack/Stack.d.ts +65 -7
- package/dist/components/Stack/Stack.js +30 -2
- package/dist/components/StatCard/StatCard.css +138 -0
- package/dist/components/StatCard/StatCard.d.ts +26 -0
- package/dist/components/StatCard/StatCard.js +13 -1
- package/dist/components/Tabs/Tab.d.ts +15 -0
- package/dist/components/Tabs/Tab.js +30 -1
- package/dist/components/Tabs/Tabs.css +132 -0
- package/dist/components/Tabs/Tabs.d.ts +7 -0
- package/dist/components/Tabs/Tabs.js +13 -2
- package/dist/components/Tag/Tag.css +85 -2
- package/dist/components/Tag/Tag.d.ts +13 -6
- package/dist/components/Tag/Tag.js +1 -0
- package/dist/components/Text/Text.js +2 -2
- package/dist/components/Textarea/Textarea.css +8 -0
- package/dist/components/TimePicker/TimePicker.css +8 -0
- 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/components/Tooltip/Tooltip.css +25 -0
- package/dist/components/Tooltip/Tooltip.d.ts +11 -0
- package/dist/components/Tooltip/Tooltip.js +18 -3
- package/dist/index.d.ts +25 -0
- package/dist/index.js +14 -0
- package/dist/teste/AILabel.test.d.ts +1 -0
- package/dist/teste/AILabel.test.js +33 -0
- package/dist/teste/AccordionConteudoLivre.test.d.ts +1 -0
- package/dist/teste/AccordionConteudoLivre.test.js +29 -0
- 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/AtributosRepassados.test.d.ts +1 -0
- package/dist/teste/AtributosRepassados.test.js +52 -0
- package/dist/teste/AttachmentCardIA.test.d.ts +1 -0
- package/dist/teste/AttachmentCardIA.test.js +89 -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/AvatarGroupOverlap.test.d.ts +1 -0
- package/dist/teste/AvatarGroupOverlap.test.js +56 -0
- package/dist/teste/BadgeNeutroColado.test.d.ts +1 -0
- package/dist/teste/BadgeNeutroColado.test.js +11 -0
- package/dist/teste/BadgeTag.test.d.ts +1 -0
- package/dist/teste/BadgeTag.test.js +55 -0
- package/dist/teste/BoxItemFlex.test.d.ts +1 -0
- package/dist/teste/BoxItemFlex.test.js +54 -0
- package/dist/teste/BoxLayout.test.d.ts +1 -0
- package/dist/teste/BoxLayout.test.js +35 -0
- package/dist/teste/Button.test.d.ts +1 -0
- package/dist/teste/Button.test.js +27 -0
- package/dist/teste/Calendar.test.d.ts +1 -0
- package/dist/teste/Calendar.test.js +221 -0
- package/dist/teste/CalendarCabecalho.test.d.ts +1 -0
- package/dist/teste/CalendarCabecalho.test.js +11 -0
- package/dist/teste/ChipsXs.test.d.ts +1 -0
- package/dist/teste/ChipsXs.test.js +31 -0
- package/dist/teste/Coachmark.test.d.ts +1 -0
- package/dist/teste/Coachmark.test.js +149 -0
- package/dist/teste/CoachmarkSemVeu.test.d.ts +1 -0
- package/dist/teste/CoachmarkSemVeu.test.js +85 -0
- package/dist/teste/ColorPicker.test.d.ts +1 -0
- package/dist/teste/ColorPicker.test.js +132 -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/DataTableCelulaLivre.test.d.ts +1 -0
- package/dist/teste/DataTableCelulaLivre.test.js +76 -0
- package/dist/teste/DataTableDocumento.test.d.ts +1 -0
- package/dist/teste/DataTableDocumento.test.js +92 -0
- package/dist/teste/DatePicker.test.js +23 -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/FileInputTrigger.test.d.ts +1 -0
- package/dist/teste/FileInputTrigger.test.js +53 -0
- package/dist/teste/IconPicker.test.d.ts +1 -0
- package/dist/teste/IconPicker.test.js +130 -0
- package/dist/teste/InputAgrupado.test.d.ts +1 -0
- package/dist/teste/InputAgrupado.test.js +24 -0
- package/dist/teste/InputMascaraEAfins.test.d.ts +1 -0
- package/dist/teste/InputMascaraEAfins.test.js +99 -0
- package/dist/teste/KbdCodeBlock.test.d.ts +1 -0
- package/dist/teste/KbdCodeBlock.test.js +95 -0
- package/dist/teste/List.test.d.ts +1 -0
- package/dist/teste/List.test.js +153 -0
- package/dist/teste/ListItemTooltipStandalone.test.d.ts +1 -0
- package/dist/teste/ListItemTooltipStandalone.test.js +39 -0
- package/dist/teste/ModalVariantes.test.d.ts +1 -0
- package/dist/teste/ModalVariantes.test.js +151 -0
- package/dist/teste/NomeAcessivelSsr.test.d.ts +1 -0
- package/dist/teste/NomeAcessivelSsr.test.js +88 -0
- package/dist/teste/OrgChart.test.d.ts +1 -0
- package/dist/teste/OrgChart.test.js +162 -0
- package/dist/teste/OtpInput.test.d.ts +1 -0
- package/dist/teste/OtpInput.test.js +143 -0
- package/dist/teste/PopoverMaxHeight.test.d.ts +1 -0
- package/dist/teste/PopoverMaxHeight.test.js +38 -0
- package/dist/teste/RichTextEditor.test.d.ts +1 -0
- package/dist/teste/RichTextEditor.test.js +287 -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/SelectPlacementFiltro.test.d.ts +1 -0
- package/dist/teste/SelectPlacementFiltro.test.js +88 -0
- package/dist/teste/Stack.test.d.ts +1 -0
- package/dist/teste/Stack.test.js +57 -0
- package/dist/teste/StatCardRotuloTopo.test.d.ts +1 -0
- package/dist/teste/StatCardRotuloTopo.test.js +34 -0
- package/dist/teste/StatCardSecundariaETom.test.d.ts +1 -0
- package/dist/teste/StatCardSecundariaETom.test.js +45 -0
- package/dist/teste/TabsContadorFechavel.test.d.ts +1 -0
- package/dist/teste/TabsContadorFechavel.test.js +79 -0
- package/dist/teste/ToastAcaoEDetalhes.test.d.ts +1 -0
- package/dist/teste/ToastAcaoEDetalhes.test.js +94 -0
- package/dist/teste/TooltipDark.test.d.ts +1 -0
- package/dist/teste/TooltipDark.test.js +31 -0
- package/dist/utils/calendario.d.ts +28 -0
- package/dist/utils/calendario.js +73 -0
- package/dist/utils/html-seguro.d.ts +45 -0
- package/dist/utils/html-seguro.js +208 -0
- package/dist/utils/paleta-de-cores.d.ts +26 -0
- package/dist/utils/paleta-de-cores.js +10 -0
- package/dist/utils/texto.d.ts +5 -0
- package/dist/utils/texto.js +5 -0
- package/dist/utils/toast.d.ts +10 -1
- package/dist/utils/toast.js +2 -1
- package/package.json +3 -3
- package/src/index.ts +26 -0
- package/src/teste/AILabel.test.tsx +41 -0
- package/src/teste/AccordionConteudoLivre.test.tsx +39 -0
- package/src/teste/AccordionTituloNeutro.test.tsx +25 -0
- package/src/teste/AppSubheaderRegiao.test.tsx +17 -0
- package/src/teste/AtributosRepassados.test.tsx +73 -0
- package/src/teste/AttachmentCardIA.test.tsx +126 -0
- package/src/teste/AttachmentCardLista.test.tsx +53 -0
- package/src/teste/AttachmentCardSm.test.tsx +29 -0
- package/src/teste/AvatarGroupOverlap.test.tsx +74 -0
- package/src/teste/BadgeNeutroColado.test.tsx +15 -0
- package/src/teste/BadgeTag.test.tsx +85 -0
- package/src/teste/BoxItemFlex.test.tsx +81 -0
- package/src/teste/BoxLayout.test.tsx +50 -0
- package/src/teste/Button.test.tsx +39 -0
- package/src/teste/Calendar.test.tsx +282 -0
- package/src/teste/CalendarCabecalho.test.tsx +11 -0
- package/src/teste/ChipsXs.test.tsx +41 -0
- package/src/teste/Coachmark.test.tsx +198 -0
- package/src/teste/CoachmarkSemVeu.test.tsx +101 -0
- package/src/teste/ColorPicker.test.tsx +153 -0
- package/src/teste/ColorPickerXs.test.tsx +22 -0
- package/src/teste/DataTableArvoreEVariantes.test.tsx +240 -0
- package/src/teste/DataTableCelulaLivre.test.tsx +103 -0
- package/src/teste/DataTableDocumento.test.tsx +102 -0
- package/src/teste/DatePicker.test.tsx +38 -0
- package/src/teste/DescriptionListCompacta.test.tsx +24 -0
- package/src/teste/EmptyStateTituloRico.test.tsx +34 -0
- package/src/teste/FileInputTrigger.test.tsx +89 -0
- package/src/teste/IconPicker.test.tsx +145 -0
- package/src/teste/InputAgrupado.test.tsx +26 -0
- package/src/teste/InputMascaraEAfins.test.tsx +124 -0
- package/src/teste/KbdCodeBlock.test.tsx +106 -0
- package/src/teste/List.test.tsx +269 -0
- package/src/teste/ListItemTooltipStandalone.test.tsx +64 -0
- package/src/teste/ModalVariantes.test.tsx +173 -0
- package/src/teste/NomeAcessivelSsr.test.tsx +110 -0
- package/src/teste/OrgChart.test.tsx +183 -0
- package/src/teste/OtpInput.test.tsx +163 -0
- package/src/teste/PopoverMaxHeight.test.tsx +47 -0
- package/src/teste/RichTextEditor.test.tsx +329 -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/SelectPlacementFiltro.test.tsx +110 -0
- package/src/teste/Stack.test.tsx +80 -0
- package/src/teste/StatCardRotuloTopo.test.tsx +44 -0
- package/src/teste/StatCardSecundariaETom.test.tsx +51 -0
- package/src/teste/TabsContadorFechavel.test.tsx +144 -0
- package/src/teste/ToastAcaoEDetalhes.test.tsx +109 -0
- package/src/teste/TooltipDark.test.tsx +51 -0
- package/src/utils/calendario.ts +78 -0
- package/src/utils/html-seguro.ts +197 -0
- package/src/utils/paleta-de-cores.ts +34 -0
- package/src/utils/texto.ts +5 -0
- package/src/utils/toast.ts +12 -2
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import './CodeBlock.css';
|
|
4
|
+
import { useState, useRef, useEffect } from "react";
|
|
5
|
+
import { faCheck, faCopy } from "@fortawesome/free-solid-svg-icons";
|
|
6
|
+
import Icon from "../Icon/Icon";
|
|
7
|
+
function CodeBlock(props) {
|
|
8
|
+
const codeRef = useRef(null);
|
|
9
|
+
const timerRef = useRef(null);
|
|
10
|
+
const [copied, setCopied] = useState(() => false);
|
|
11
|
+
function classes() {
|
|
12
|
+
return [
|
|
13
|
+
"umds-code-block",
|
|
14
|
+
props.wrap ? "umds-code-block--wrap" : "",
|
|
15
|
+
props.copyable ? "umds-code-block--copyable" : "",
|
|
16
|
+
props.className,
|
|
17
|
+
]
|
|
18
|
+
.filter(Boolean)
|
|
19
|
+
.join(" ");
|
|
20
|
+
}
|
|
21
|
+
function scrollStyle() {
|
|
22
|
+
return props.maxHeight
|
|
23
|
+
? {
|
|
24
|
+
maxHeight: props.maxHeight + "px",
|
|
25
|
+
}
|
|
26
|
+
: undefined;
|
|
27
|
+
}
|
|
28
|
+
function regionName() {
|
|
29
|
+
return props.ariaLabel || props.language || "Código";
|
|
30
|
+
}
|
|
31
|
+
function copyText() {
|
|
32
|
+
return props.copyLabel || "Copiar";
|
|
33
|
+
}
|
|
34
|
+
function copiedText() {
|
|
35
|
+
return props.copiedLabel || "Copiado";
|
|
36
|
+
}
|
|
37
|
+
function buttonName() {
|
|
38
|
+
return copied ? copiedText() : copyText();
|
|
39
|
+
}
|
|
40
|
+
function buttonIcon() {
|
|
41
|
+
return copied ? faCheck : faCopy;
|
|
42
|
+
}
|
|
43
|
+
function announce() {
|
|
44
|
+
return copied ? copiedText() : "";
|
|
45
|
+
}
|
|
46
|
+
function textoDoBloco() {
|
|
47
|
+
if (props.code !== undefined)
|
|
48
|
+
return props.code;
|
|
49
|
+
return codeRef.current ? codeRef.current.textContent || "" : "";
|
|
50
|
+
}
|
|
51
|
+
function copiarComFallback(texto) {
|
|
52
|
+
if (typeof document === "undefined")
|
|
53
|
+
return;
|
|
54
|
+
const campo = document.createElement("textarea");
|
|
55
|
+
campo.value = texto;
|
|
56
|
+
campo.setAttribute("readonly", "");
|
|
57
|
+
campo.style.position = "fixed";
|
|
58
|
+
campo.style.opacity = "0";
|
|
59
|
+
document.body.appendChild(campo);
|
|
60
|
+
campo.select();
|
|
61
|
+
try {
|
|
62
|
+
document.execCommand("copy");
|
|
63
|
+
}
|
|
64
|
+
catch (erro) {
|
|
65
|
+
// Sem como copiar neste navegador: o botão não confirma.
|
|
66
|
+
}
|
|
67
|
+
document.body.removeChild(campo);
|
|
68
|
+
}
|
|
69
|
+
function marcarCopiado(texto) {
|
|
70
|
+
setCopied(true);
|
|
71
|
+
if (props.onCopy)
|
|
72
|
+
props.onCopy(texto);
|
|
73
|
+
if (timerRef.current)
|
|
74
|
+
clearTimeout(timerRef.current);
|
|
75
|
+
timerRef.current = setTimeout(() => {
|
|
76
|
+
setCopied(false);
|
|
77
|
+
}, 2000);
|
|
78
|
+
}
|
|
79
|
+
function handleCopy() {
|
|
80
|
+
const texto = textoDoBloco();
|
|
81
|
+
if (typeof navigator !== "undefined" &&
|
|
82
|
+
navigator.clipboard &&
|
|
83
|
+
navigator.clipboard.writeText) {
|
|
84
|
+
navigator.clipboard.writeText(texto).then(() => marcarCopiado(texto), () => {
|
|
85
|
+
copiarComFallback(texto);
|
|
86
|
+
marcarCopiado(texto);
|
|
87
|
+
});
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
copiarComFallback(texto);
|
|
91
|
+
marcarCopiado(texto);
|
|
92
|
+
}
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
return () => {
|
|
95
|
+
if (timerRef.current) {
|
|
96
|
+
clearTimeout(timerRef.current);
|
|
97
|
+
timerRef.current = null;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}, []);
|
|
101
|
+
return (_jsxs("div", { id: props.id, className: classes(), children: [props.language || props.copyable ? (_jsxs("div", { className: "umds-code-block__header", children: [_jsx("span", { className: "umds-code-block__language", children: props.language }), props.copyable ? (_jsxs("button", { type: "button", className: "umds-code-block__copy", "aria-label": buttonName(), title: buttonName(), onClick: (event) => handleCopy(), children: [_jsx(Icon, { size: "sm", variant: "inherit", icon: buttonIcon() }), _jsx("span", { className: "umds-code-block__copy-text", children: buttonName() })] })) : null] })) : null, _jsx("pre", { role: "region", className: "umds-code-block__scroll", "aria-label": regionName(), tabIndex: 0, style: scrollStyle(), children: _jsxs("code", { className: "umds-code-block__code", ref: codeRef, children: [props.code, _jsx(_Fragment, { children: props.children })] }) }), _jsx("span", { role: "status", "aria-live": "polite", className: "umds-code-block__sr", children: announce() })] }));
|
|
102
|
+
}
|
|
103
|
+
export default CodeBlock;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/* ─────────────────────────────────────────────
|
|
2
|
+
COLOR PICKER
|
|
3
|
+
Grade de amostras da paleta do 1DS (primitivos de cor). Valor = nome do token.
|
|
4
|
+
|
|
5
|
+
Na paleta do DS a grade tem 7 colunas (os cinzas são 7) e a PRIMEIRA amostra
|
|
6
|
+
de cada família abre linha nova: uma linha por família, sem aninhar nada no
|
|
7
|
+
DOM — a ordem de Tab e das setas continua a da lista.
|
|
8
|
+
|
|
9
|
+
A amostra escolhida tem dois sinais além da cor: anel duplo e ícone de
|
|
10
|
+
marcação. O ícone usa primitivos (branco ou cinza escuro), porque a cor da
|
|
11
|
+
amostra é primitiva e não muda com o tema: o contraste fica o mesmo no escuro.
|
|
12
|
+
|
|
13
|
+
Cores: semânticos (e primitivos, na marcação) · Medidas: primitivos
|
|
14
|
+
───────────────────────────────────────────── */
|
|
15
|
+
|
|
16
|
+
.umds-color-picker {
|
|
17
|
+
display: inline-flex;
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
gap: var(--umds-primitive-spacing-nano); /* 8px */
|
|
20
|
+
font-family: var(--umds-semantic-font-family-base);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.umds-color-picker__label {
|
|
24
|
+
font-size: var(--umds-semantic-field-label-size);
|
|
25
|
+
font-weight: var(--umds-semantic-field-label-weight);
|
|
26
|
+
color: var(--umds-semantic-field-label-color);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* ── Grade ── */
|
|
30
|
+
.umds-color-picker__swatches {
|
|
31
|
+
display: flex;
|
|
32
|
+
flex-wrap: wrap;
|
|
33
|
+
gap: var(--umds-primitive-spacing-nano); /* 8px */
|
|
34
|
+
/* Folga para o anel de seleção (4px) não ser cortado por um overflow do pai. */
|
|
35
|
+
padding: var(--umds-primitive-spacing-quarck);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.umds-color-picker--sm .umds-color-picker__swatches,
|
|
39
|
+
.umds-color-picker--xs .umds-color-picker__swatches {
|
|
40
|
+
gap: var(--umds-primitive-spacing-quarck); /* 4px */
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.umds-color-picker__swatches--familias {
|
|
44
|
+
display: grid;
|
|
45
|
+
grid-template-columns: repeat(7, max-content);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.umds-color-picker__swatch--nova-linha {
|
|
49
|
+
grid-column-start: 1;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* ── Amostra ── */
|
|
53
|
+
.umds-color-picker__swatch {
|
|
54
|
+
display: inline-flex;
|
|
55
|
+
align-items: center;
|
|
56
|
+
justify-content: center;
|
|
57
|
+
box-sizing: border-box;
|
|
58
|
+
margin: 0;
|
|
59
|
+
padding: 0;
|
|
60
|
+
cursor: pointer;
|
|
61
|
+
/* Anel de 1px: amostra clara não some no fundo branco. */
|
|
62
|
+
border: var(--umds-primitive-border-width-hairline) solid var(--umds-semantic-color-neutral-light-down);
|
|
63
|
+
border-radius: var(--umds-primitive-border-radius-sm);
|
|
64
|
+
/* A cor da amostra vem do `style` (background-color); o ícone herda o branco. */
|
|
65
|
+
/* stylelint-disable-next-line 1ds/cor-por-token -- a amostra é primitivo (não muda com o tema); a marcação precisa do par fixo, senão o semântico inverte no escuro e perde o contraste */
|
|
66
|
+
color: var(--umds-primitive-white);
|
|
67
|
+
transition: box-shadow var(--umds-semantic-motion-duration-fast) var(--umds-semantic-motion-easing-standard);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.umds-color-picker--md .umds-color-picker__swatch {
|
|
71
|
+
width: var(--umds-primitive-spacing-xs); /* 32px */
|
|
72
|
+
height: var(--umds-primitive-spacing-xs);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.umds-color-picker--sm .umds-color-picker__swatch {
|
|
76
|
+
width: var(--umds-primitive-spacing-xxs); /* 24px */
|
|
77
|
+
height: var(--umds-primitive-spacing-xxs);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/* xs: 20px, o tamanho do CrisDoc (16 + 4, dois degraus da escala somados; sem token próprio). */
|
|
81
|
+
.umds-color-picker--xs .umds-color-picker__swatch {
|
|
82
|
+
width: calc(var(--umds-primitive-spacing-xxxs) + var(--umds-primitive-spacing-quarck)); /* 20px */
|
|
83
|
+
height: calc(var(--umds-primitive-spacing-xxxs) + var(--umds-primitive-spacing-quarck));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.umds-color-picker__swatch--on-light {
|
|
87
|
+
/* stylelint-disable-next-line 1ds/cor-por-token -- par fixo da marcação sobre amostra clara (ver acima) */
|
|
88
|
+
color: var(--umds-primitive-gray-darkest);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.umds-color-picker__swatch:hover:not(:disabled) {
|
|
92
|
+
box-shadow: 0 0 0 var(--umds-primitive-border-width-thin) var(--umds-semantic-color-neutral-light-down);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.umds-color-picker__swatch--selected,
|
|
96
|
+
.umds-color-picker__swatch--selected:hover:not(:disabled) {
|
|
97
|
+
/* Anel duplo: a cor do fundo da página por dentro e o primário por fora. */
|
|
98
|
+
box-shadow:
|
|
99
|
+
0 0 0 var(--umds-primitive-border-width-thin) var(--umds-semantic-color-background-white),
|
|
100
|
+
0 0 0 calc(var(--umds-primitive-border-width-thin) * 2) var(--umds-semantic-color-primary-pure);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.umds-color-picker__swatch:focus-visible {
|
|
104
|
+
outline: var(--umds-primitive-border-width-thin) solid var(--umds-semantic-color-primary-pure);
|
|
105
|
+
outline-offset: var(--umds-primitive-spacing-quarck);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.umds-color-picker__swatch:disabled {
|
|
109
|
+
cursor: not-allowed;
|
|
110
|
+
opacity: var(--umds-semantic-field-disabled-opacity);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* ── Cor livre ── */
|
|
114
|
+
.umds-color-picker__custom {
|
|
115
|
+
display: flex;
|
|
116
|
+
align-items: flex-end;
|
|
117
|
+
gap: var(--umds-primitive-spacing-nano); /* 8px */
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.umds-color-picker__custom-preview {
|
|
121
|
+
flex: none;
|
|
122
|
+
box-sizing: border-box;
|
|
123
|
+
width: var(--umds-primitive-spacing-xs); /* 32px, a altura do Input sm */
|
|
124
|
+
height: var(--umds-primitive-spacing-xs);
|
|
125
|
+
border: var(--umds-primitive-border-width-hairline) solid var(--umds-semantic-color-neutral-light-down);
|
|
126
|
+
border-radius: var(--umds-primitive-border-radius-sm);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/* ── Alto contraste: a marcação e a borda ficam, a cor é do usuário ── */
|
|
130
|
+
@media (forced-colors: active) {
|
|
131
|
+
.umds-color-picker__swatch {
|
|
132
|
+
forced-color-adjust: none;
|
|
133
|
+
border-color: CanvasText;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.umds-color-picker__swatch--selected {
|
|
137
|
+
outline: var(--umds-primitive-border-width-thin) solid Highlight;
|
|
138
|
+
outline-offset: var(--umds-primitive-border-width-thin);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import './ColorPicker.css';
|
|
2
|
+
/**
|
|
3
|
+
* Amostra do ColorPicker.
|
|
4
|
+
* @property {string} value - Nome da variável CSS (`--umds-primitive-blue-pure`) ou uma cor hexadecimal (`#0058DB`).
|
|
5
|
+
* @property {string} label - Nome da cor, para leitor de tela e tooltip.
|
|
6
|
+
* @property {boolean} onLight - Cor clara: o ícone de marcação sai escuro.
|
|
7
|
+
* @property {boolean} disabled - Desabilita só esta amostra.
|
|
8
|
+
*/
|
|
9
|
+
export interface ColorPickerSwatch {
|
|
10
|
+
value: string;
|
|
11
|
+
label: string;
|
|
12
|
+
onLight?: boolean;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* ColorPicker — escolha de UMA cor numa grade de amostras da paleta do 1DS.
|
|
18
|
+
*
|
|
19
|
+
* O valor é o NOME DO TOKEN (`--umds-primitive-blue-pure`), não o hexadecimal:
|
|
20
|
+
* guarde o nome e escreva `var(${valor})` onde pintar, e a cor acompanha a
|
|
21
|
+
* paleta do DS. As amostras são os primitivos de cor (6 famílias de 4 tons e
|
|
22
|
+
* os 7 cinzas), por isso a cor escolhida é a mesma no tema claro e no escuro,
|
|
23
|
+
* o que é o certo para cor de dado (marcador, tipo de documento, setor).
|
|
24
|
+
*
|
|
25
|
+
* É um `radiogroup`: um Tab entra na grade (na amostra escolhida, ou na
|
|
26
|
+
* primeira) e as setas movem a escolha, com Home e End nas pontas. Cada amostra
|
|
27
|
+
* tem nome acessível ("Azul escuro") e a escolhida ganha um ícone de marcação,
|
|
28
|
+
* então a seleção nunca depende só da cor.
|
|
29
|
+
*
|
|
30
|
+
* `allowCustom` liga o campo de cor livre (hexadecimal `#RRGGBB`). Vem
|
|
31
|
+
* DESLIGADO: cor fora da paleta foge do DS, e quem liga assume o desvio. O
|
|
32
|
+
* valor livre sai em maiúsculas (`#0058DB`) e se distingue do token por começar
|
|
33
|
+
* com `#`.
|
|
34
|
+
*
|
|
35
|
+
* Para um recorte da paleta (só azul e cinza) ou para traduzir os nomes, passe
|
|
36
|
+
* `swatches`; `COLOR_PALETTE` é a lista padrão, exportada para filtrar.
|
|
37
|
+
* @property {string} value - Valor escolhido (controlado): nome do token ou `#RRGGBB`
|
|
38
|
+
* @property {string} defaultValue - Valor inicial (não controlado)
|
|
39
|
+
* @property {string} label - Rótulo visível do grupo
|
|
40
|
+
* @property {string} ariaLabel - Nome acessível quando não há `label` visível
|
|
41
|
+
* @property {string} ariaLabelledby - Id do texto que nomeia o grupo
|
|
42
|
+
* @property {ColorPickerSwatch[]} swatches - Amostras no lugar da paleta do DS (ex.: nomes traduzidos)
|
|
43
|
+
* @property {string[]} families - Mostra só estas famílias da paleta do DS: 'blue' | 'red' | 'green' | 'orange' | 'yellow' | 'purple' | 'gray'
|
|
44
|
+
* @property {boolean} allowCustom - Liga o campo de cor livre (hexadecimal)
|
|
45
|
+
* @property {string} customLabel - Rótulo do campo de cor livre (padrão: "Cor livre (hexadecimal)")
|
|
46
|
+
* @property {string} customErrorMessage - Mensagem do hexadecimal inválido (padrão: "Use o formato #RRGGBB")
|
|
47
|
+
* @property {string} size - Tamanho da amostra: 'xs' (20px, o do CrisDoc) | 'sm' (24px) | 'md' (32px). A marcação de selecionada (o anel duplo) é a mesma nos três.
|
|
48
|
+
* @property {boolean} disabled - Desabilita o grupo inteiro
|
|
49
|
+
* @property {string} id - Base dos ids internos; passe em SSR para os ids já saírem no HTML do servidor
|
|
50
|
+
* @property {string} className - Classes CSS adicionais
|
|
51
|
+
* @property {function} onChange - Callback com o valor escolhido (nome do token ou `#RRGGBB`)
|
|
52
|
+
* @quandoUsar Escolher a cor de um marcador, de um tipo de documento, de um setor ou de uma série de dados, sempre dentro da paleta do DS.
|
|
53
|
+
* @quandoNaoUsar Para cor com PAPEL na interface (primária, erro, sucesso), use os tokens semânticos direto: não é escolha do usuário. Para escolher entre poucas opções que não são cor, use `SegmentedControl` ou `RadioGroup`. Para uma cor qualquer da web, ligue `allowCustom` sabendo que ela sai do DS.
|
|
54
|
+
*/
|
|
55
|
+
export interface ColorPickerProps {
|
|
56
|
+
value?: string;
|
|
57
|
+
defaultValue?: string;
|
|
58
|
+
label?: string;
|
|
59
|
+
ariaLabel?: string;
|
|
60
|
+
ariaLabelledby?: string;
|
|
61
|
+
swatches?: ColorPickerSwatch[];
|
|
62
|
+
families?: string[];
|
|
63
|
+
allowCustom?: boolean;
|
|
64
|
+
customLabel?: string;
|
|
65
|
+
customErrorMessage?: string;
|
|
66
|
+
size?: "xs" | "sm" | "md";
|
|
67
|
+
disabled?: boolean;
|
|
68
|
+
id?: string;
|
|
69
|
+
className?: string;
|
|
70
|
+
onChange?: (value: string) => void;
|
|
71
|
+
}
|
|
72
|
+
declare function ColorPicker(props: ColorPickerProps): import("react/jsx-runtime").JSX.Element;
|
|
73
|
+
export default ColorPicker;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import './ColorPicker.css';
|
|
4
|
+
import { useState, useRef, useEffect } from "react";
|
|
5
|
+
import { faCheck } from "@fortawesome/free-solid-svg-icons";
|
|
6
|
+
import Icon from "../Icon/Icon";
|
|
7
|
+
import Input from "../Input/Input";
|
|
8
|
+
import { gerarId } from "../../utils/id";
|
|
9
|
+
import { COLOR_PALETTE, isHexColor } from "../../utils/paleta-de-cores";
|
|
10
|
+
function ColorPicker(props) {
|
|
11
|
+
const groupRef = useRef(null);
|
|
12
|
+
const [internalValue, setInternalValue] = useState(() => props.defaultValue !== undefined ? props.defaultValue : "");
|
|
13
|
+
const [uid, setUid] = useState(() => "");
|
|
14
|
+
const [hexDraft, setHexDraft] = useState(() => "");
|
|
15
|
+
const [hexEditing, setHexEditing] = useState(() => false);
|
|
16
|
+
const [hexTouched, setHexTouched] = useState(() => false);
|
|
17
|
+
function baseId() {
|
|
18
|
+
return props.id || uid;
|
|
19
|
+
}
|
|
20
|
+
function labelId() {
|
|
21
|
+
return baseId() && props.label ? baseId() + "-label" : undefined;
|
|
22
|
+
}
|
|
23
|
+
function currentValue() {
|
|
24
|
+
return props.value !== undefined ? props.value : internalValue;
|
|
25
|
+
}
|
|
26
|
+
function swatchList() {
|
|
27
|
+
if (props.swatches && props.swatches.length)
|
|
28
|
+
return props.swatches;
|
|
29
|
+
const familias = props.families;
|
|
30
|
+
if (!familias || !familias.length)
|
|
31
|
+
return COLOR_PALETTE;
|
|
32
|
+
return COLOR_PALETTE.filter((cor) => familias.indexOf(cor.family) !== -1);
|
|
33
|
+
}
|
|
34
|
+
function usaPaletaDoDs() {
|
|
35
|
+
return !(props.swatches && props.swatches.length);
|
|
36
|
+
}
|
|
37
|
+
function groupClasses() {
|
|
38
|
+
return [
|
|
39
|
+
"umds-color-picker",
|
|
40
|
+
`umds-color-picker--${props.size || "md"}`,
|
|
41
|
+
props.disabled ? "umds-color-picker--disabled" : "",
|
|
42
|
+
props.className,
|
|
43
|
+
]
|
|
44
|
+
.filter(Boolean)
|
|
45
|
+
.join(" ");
|
|
46
|
+
}
|
|
47
|
+
function swatchesClasses() {
|
|
48
|
+
return [
|
|
49
|
+
"umds-color-picker__swatches",
|
|
50
|
+
usaPaletaDoDs() ? "umds-color-picker__swatches--familias" : "",
|
|
51
|
+
]
|
|
52
|
+
.filter(Boolean)
|
|
53
|
+
.join(" ");
|
|
54
|
+
}
|
|
55
|
+
function groupAriaLabel() {
|
|
56
|
+
if (props.ariaLabel)
|
|
57
|
+
return props.ariaLabel;
|
|
58
|
+
// Antes do onMount o label ainda não tem id para o aria-labelledby apontar.
|
|
59
|
+
return props.label && !labelId() ? props.label : undefined;
|
|
60
|
+
}
|
|
61
|
+
function groupLabelledBy() {
|
|
62
|
+
return props.ariaLabelledby || labelId();
|
|
63
|
+
}
|
|
64
|
+
function corCss(valor) {
|
|
65
|
+
if (!valor)
|
|
66
|
+
return "";
|
|
67
|
+
return valor.indexOf("--") === 0 ? "var(" + valor + ")" : valor;
|
|
68
|
+
}
|
|
69
|
+
function swatchStyle(swatch) {
|
|
70
|
+
return {
|
|
71
|
+
backgroundColor: corCss(swatch.value),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function swatchClasses(swatch) {
|
|
75
|
+
return [
|
|
76
|
+
"umds-color-picker__swatch",
|
|
77
|
+
swatch.onLight ? "umds-color-picker__swatch--on-light" : "",
|
|
78
|
+
estaEscolhida(swatch) ? "umds-color-picker__swatch--selected" : "",
|
|
79
|
+
]
|
|
80
|
+
.filter(Boolean)
|
|
81
|
+
.join(" ");
|
|
82
|
+
}
|
|
83
|
+
function novaLinha(swatch, index) {
|
|
84
|
+
if (!usaPaletaDoDs())
|
|
85
|
+
return false;
|
|
86
|
+
if (index === 0)
|
|
87
|
+
return true;
|
|
88
|
+
const anterior = swatchList()[index - 1];
|
|
89
|
+
return !!anterior && !!swatch.family && anterior.family !== swatch.family;
|
|
90
|
+
}
|
|
91
|
+
function swatchItemClasses(swatch, index) {
|
|
92
|
+
return [
|
|
93
|
+
swatchClasses(swatch),
|
|
94
|
+
novaLinha(swatch, index) ? "umds-color-picker__swatch--nova-linha" : "",
|
|
95
|
+
]
|
|
96
|
+
.filter(Boolean)
|
|
97
|
+
.join(" ");
|
|
98
|
+
}
|
|
99
|
+
function estaEscolhida(swatch) {
|
|
100
|
+
return (!!currentValue() &&
|
|
101
|
+
swatch.value.toLowerCase() === currentValue().toLowerCase());
|
|
102
|
+
}
|
|
103
|
+
function estaDesabilitada(swatch) {
|
|
104
|
+
return !!props.disabled || !!swatch.disabled;
|
|
105
|
+
}
|
|
106
|
+
function indiceDoTab() {
|
|
107
|
+
const lista = swatchList();
|
|
108
|
+
for (let i = 0; i < lista.length; i++) {
|
|
109
|
+
if (estaEscolhida(lista[i]) && !estaDesabilitada(lista[i]))
|
|
110
|
+
return i;
|
|
111
|
+
}
|
|
112
|
+
for (let i = 0; i < lista.length; i++) {
|
|
113
|
+
if (!estaDesabilitada(lista[i]))
|
|
114
|
+
return i;
|
|
115
|
+
}
|
|
116
|
+
return 0;
|
|
117
|
+
}
|
|
118
|
+
function tabIndexDa(index) {
|
|
119
|
+
return index === indiceDoTab() ? 0 : -1;
|
|
120
|
+
}
|
|
121
|
+
function emitir(valor) {
|
|
122
|
+
setInternalValue(valor);
|
|
123
|
+
if (props.onChange)
|
|
124
|
+
props.onChange(valor);
|
|
125
|
+
}
|
|
126
|
+
function escolher(swatch) {
|
|
127
|
+
if (estaDesabilitada(swatch))
|
|
128
|
+
return;
|
|
129
|
+
setHexEditing(false);
|
|
130
|
+
setHexDraft("");
|
|
131
|
+
setHexTouched(false);
|
|
132
|
+
emitir(swatch.value);
|
|
133
|
+
}
|
|
134
|
+
function handleKeyDown(event, index) {
|
|
135
|
+
if (!event || event.altKey || event.ctrlKey || event.metaKey)
|
|
136
|
+
return;
|
|
137
|
+
const lista = swatchList();
|
|
138
|
+
const total = lista.length;
|
|
139
|
+
if (!total)
|
|
140
|
+
return;
|
|
141
|
+
let passo = 0;
|
|
142
|
+
let alvo = index;
|
|
143
|
+
if (event.key === "ArrowRight" || event.key === "ArrowDown")
|
|
144
|
+
passo = 1;
|
|
145
|
+
else if (event.key === "ArrowLeft" || event.key === "ArrowUp")
|
|
146
|
+
passo = -1;
|
|
147
|
+
else if (event.key === "Home") {
|
|
148
|
+
passo = 1;
|
|
149
|
+
alvo = -1;
|
|
150
|
+
}
|
|
151
|
+
else if (event.key === "End") {
|
|
152
|
+
passo = -1;
|
|
153
|
+
alvo = total;
|
|
154
|
+
}
|
|
155
|
+
else
|
|
156
|
+
return;
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
for (let tentativa = 0; tentativa < total; tentativa++) {
|
|
159
|
+
alvo = (alvo + passo + total) % total;
|
|
160
|
+
if (!estaDesabilitada(lista[alvo]))
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
if (estaDesabilitada(lista[alvo]))
|
|
164
|
+
return;
|
|
165
|
+
escolher(lista[alvo]);
|
|
166
|
+
if (groupRef.current) {
|
|
167
|
+
const botoes = groupRef.current.querySelectorAll('[role="radio"]');
|
|
168
|
+
const botao = botoes[alvo];
|
|
169
|
+
if (botao)
|
|
170
|
+
botao.focus();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function hexText() {
|
|
174
|
+
if (hexEditing)
|
|
175
|
+
return hexDraft;
|
|
176
|
+
const atual = currentValue();
|
|
177
|
+
return atual && atual.indexOf("#") === 0 ? atual : "";
|
|
178
|
+
}
|
|
179
|
+
function hexInvalid() {
|
|
180
|
+
return hexTouched && !!hexText() && !isHexColor(hexText());
|
|
181
|
+
}
|
|
182
|
+
function customPreview() {
|
|
183
|
+
const texto = hexText();
|
|
184
|
+
return isHexColor(texto) ? corCss(normalizarHex(texto)) : "";
|
|
185
|
+
}
|
|
186
|
+
function customLabelText() {
|
|
187
|
+
return props.customLabel || "Cor livre (hexadecimal)";
|
|
188
|
+
}
|
|
189
|
+
function customErrorText() {
|
|
190
|
+
return hexInvalid()
|
|
191
|
+
? props.customErrorMessage || "Use o formato #RRGGBB"
|
|
192
|
+
: undefined;
|
|
193
|
+
}
|
|
194
|
+
function normalizarHex(texto) {
|
|
195
|
+
const limpo = texto.trim();
|
|
196
|
+
return (limpo.indexOf("#") === 0 ? limpo : "#" + limpo).toUpperCase();
|
|
197
|
+
}
|
|
198
|
+
function handleHexInput(texto) {
|
|
199
|
+
setHexEditing(true);
|
|
200
|
+
setHexDraft(texto);
|
|
201
|
+
if (isHexColor(texto))
|
|
202
|
+
emitir(normalizarHex(texto));
|
|
203
|
+
}
|
|
204
|
+
function handleHexBlur() {
|
|
205
|
+
setHexTouched(true);
|
|
206
|
+
if (isHexColor(hexDraft)) {
|
|
207
|
+
setHexEditing(false);
|
|
208
|
+
setHexDraft("");
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
useEffect(() => {
|
|
212
|
+
if (!props.id)
|
|
213
|
+
setUid(gerarId("umds-color-picker"));
|
|
214
|
+
}, []);
|
|
215
|
+
return (_jsxs("div", { className: groupClasses(), children: [props.label ? (_jsx("span", { className: "umds-color-picker__label", id: labelId(), children: props.label })) : null, _jsx("div", { role: "radiogroup", ref: groupRef, "aria-label": groupAriaLabel(), "aria-labelledby": groupLabelledBy(), className: swatchesClasses(), children: swatchList()?.map((swatch, index) => (_jsx("button", { type: "button", role: "radio", style: swatchStyle(swatch), "aria-checked": estaEscolhida(swatch) ? "true" : "false", "aria-label": swatch.label, title: swatch.label, disabled: estaDesabilitada(swatch), tabIndex: tabIndexDa(index), onClick: (event) => escolher(swatch), onKeyDown: (event) => handleKeyDown(event, index), className: swatchItemClasses(swatch, index), children: estaEscolhida(swatch) ? (_jsx(Icon, { size: "sm", variant: "inherit", icon: faCheck })) : null }, swatch.value))) }), props.allowCustom ? (_jsxs("div", { className: "umds-color-picker__custom", children: [_jsx("span", { "aria-hidden": "true", className: "umds-color-picker__custom-preview", style: {
|
|
216
|
+
backgroundColor: customPreview(),
|
|
217
|
+
} }), _jsx(Input, { size: "sm", placeholder: "#0058DB", label: customLabelText(), value: hexText(), disabled: props.disabled, errorMessage: customErrorText(), onChange: (texto) => handleHexInput(texto), onBlur: (event) => handleHexBlur() })] })) : null] }));
|
|
218
|
+
}
|
|
219
|
+
export default ColorPicker;
|
|
@@ -214,6 +214,14 @@
|
|
|
214
214
|
cursor: default;
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
+
/* Somente leitura não é desabilitado: o texto segue lido e a WCAG 1.4.3 vale
|
|
218
|
+
sem isenção. O placeholder padrão foi calibrado para fundo branco e cai para
|
|
219
|
+
~4,2:1 sobre o fundo de somente leitura; neutral-dark-down passa 4,5:1 em
|
|
220
|
+
todos os temas (1doc 6,78:1 · 1doc-dark 10,83:1 · alto contraste 16,48:1). */
|
|
221
|
+
.umds-combobox--readonly .umds-combobox__control::placeholder {
|
|
222
|
+
color: var(--umds-semantic-color-neutral-dark-down);
|
|
223
|
+
}
|
|
224
|
+
|
|
217
225
|
/* ── Dropdown (espelha .umds-select__dropdown) ── */
|
|
218
226
|
.umds-combobox__dropdown {
|
|
219
227
|
position: absolute;
|