@1doc/1ds-react 2.8.0 → 2.9.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 +1106 -0
- package/dist/components/AILabel/AILabel.js +1 -1
- package/dist/components/Accordion/Accordion.d.ts +6 -2
- package/dist/components/AttachmentCard/AttachmentCard.css +16 -0
- package/dist/components/AttachmentCard/AttachmentCard.d.ts +19 -2
- package/dist/components/AttachmentCard/AttachmentCard.js +40 -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 +54 -2
- package/dist/components/Badge/Badge.d.ts +14 -4
- package/dist/components/Badge/Badge.js +1 -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 +125 -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 +118 -0
- package/dist/components/Coachmark/Coachmark.d.ts +75 -0
- package/dist/components/Coachmark/Coachmark.js +321 -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 +133 -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 +80 -0
- package/dist/components/DataTable/DataTable.d.ts +19 -4
- package/dist/components/DataTable/DataTable.js +59 -15
- package/dist/components/DatePicker/DatePicker.css +8 -0
- package/dist/components/DatePicker/DatePicker.js +10 -1
- package/dist/components/DescriptionList/DescriptionList.css +113 -0
- package/dist/components/DescriptionList/DescriptionList.d.ts +59 -0
- package/dist/components/DescriptionList/DescriptionList.js +51 -0
- 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 +38 -0
- package/dist/components/Input/Input.d.ts +10 -1
- package/dist/components/Input/Input.js +66 -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 +85 -0
- package/dist/components/List/ListItem.js +81 -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 +203 -0
- package/dist/components/RichTextEditor/RichTextEditor.d.ts +83 -0
- package/dist/components/RichTextEditor/RichTextEditor.js +494 -0
- package/dist/components/SegmentedControl/SegmentedControl.js +7 -2
- package/dist/components/Select/Select.css +70 -0
- package/dist/components/Select/Select.d.ts +12 -0
- package/dist/components/Select/Select.js +59 -4
- 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 +73 -0
- package/dist/components/StatCard/StatCard.d.ts +17 -0
- package/dist/components/StatCard/StatCard.js +4 -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/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/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/AvatarGroupOverlap.test.d.ts +1 -0
- package/dist/teste/AvatarGroupOverlap.test.js +56 -0
- package/dist/teste/BadgeTag.test.d.ts +1 -0
- package/dist/teste/BadgeTag.test.js +42 -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/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/ColorPicker.test.d.ts +1 -0
- package/dist/teste/ColorPicker.test.js +132 -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/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/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/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/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/TabsContadorFechavel.test.d.ts +1 -0
- package/dist/teste/TabsContadorFechavel.test.js +79 -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 +27 -0
- package/dist/utils/html-seguro.js +97 -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/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/AtributosRepassados.test.tsx +73 -0
- package/src/teste/AttachmentCardIA.test.tsx +126 -0
- package/src/teste/AvatarGroupOverlap.test.tsx +74 -0
- package/src/teste/BadgeTag.test.tsx +64 -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/ChipsXs.test.tsx +41 -0
- package/src/teste/Coachmark.test.tsx +198 -0
- package/src/teste/ColorPicker.test.tsx +153 -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/FileInputTrigger.test.tsx +89 -0
- package/src/teste/IconPicker.test.tsx +145 -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/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/SelectPlacementFiltro.test.tsx +110 -0
- package/src/teste/Stack.test.tsx +80 -0
- package/src/teste/StatCardRotuloTopo.test.tsx +44 -0
- package/src/teste/TabsContadorFechavel.test.tsx +144 -0
- package/src/teste/TooltipDark.test.tsx +51 -0
- package/src/utils/calendario.ts +78 -0
- package/src/utils/html-seguro.ts +94 -0
- package/src/utils/paleta-de-cores.ts +34 -0
- package/src/utils/texto.ts +5 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import './Coachmark.css';
|
|
4
|
+
import { useState, useRef, useEffect } from "react";
|
|
5
|
+
import { computePosition, autoUpdate, offset, flip, shift, } from "@floating-ui/dom";
|
|
6
|
+
import Button from "../Button/Button";
|
|
7
|
+
import Portal from "../Portal/Portal";
|
|
8
|
+
import Text from "../Text/Text";
|
|
9
|
+
import { gerarId } from "../../utils/id";
|
|
10
|
+
function Coachmark(props) {
|
|
11
|
+
const cardRef = useRef(null);
|
|
12
|
+
const cleanupRef = useRef(null);
|
|
13
|
+
const previousFocusRef = useRef(null);
|
|
14
|
+
const attachedRef = useRef(null);
|
|
15
|
+
const [internalStep, setInternalStep] = useState(() => props.defaultStep || 0);
|
|
16
|
+
const [uid, setUid] = useState(() => "");
|
|
17
|
+
const [active, setActive] = useState(() => false);
|
|
18
|
+
const [hasTarget, setHasTarget] = useState(() => false);
|
|
19
|
+
const [positioned, setPositioned] = useState(() => false);
|
|
20
|
+
const [rectTop, setRectTop] = useState(() => 0);
|
|
21
|
+
const [rectLeft, setRectLeft] = useState(() => 0);
|
|
22
|
+
const [rectWidth, setRectWidth] = useState(() => 0);
|
|
23
|
+
const [rectHeight, setRectHeight] = useState(() => 0);
|
|
24
|
+
const [posX, setPosX] = useState(() => 0);
|
|
25
|
+
const [posY, setPosY] = useState(() => 0);
|
|
26
|
+
const [tentativas, setTentativas] = useState(() => 0);
|
|
27
|
+
function stepList() {
|
|
28
|
+
return props.steps || [];
|
|
29
|
+
}
|
|
30
|
+
function stepCount() {
|
|
31
|
+
return stepList().length;
|
|
32
|
+
}
|
|
33
|
+
function index() {
|
|
34
|
+
const bruto = props.step !== undefined ? props.step : internalStep;
|
|
35
|
+
const max = stepCount() > 0 ? stepCount() - 1 : 0;
|
|
36
|
+
return Math.max(0, Math.min(bruto, max));
|
|
37
|
+
}
|
|
38
|
+
function currentStep() {
|
|
39
|
+
return (stepList()[index()] || {
|
|
40
|
+
title: "",
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function isFirst() {
|
|
44
|
+
return index() === 0;
|
|
45
|
+
}
|
|
46
|
+
function isLast() {
|
|
47
|
+
return index() === stepCount() - 1;
|
|
48
|
+
}
|
|
49
|
+
function baseId() {
|
|
50
|
+
return uid || "umds-coachmark";
|
|
51
|
+
}
|
|
52
|
+
function titleId() {
|
|
53
|
+
return baseId() + "-title";
|
|
54
|
+
}
|
|
55
|
+
function contentId() {
|
|
56
|
+
return baseId() + "-content";
|
|
57
|
+
}
|
|
58
|
+
function counterText() {
|
|
59
|
+
const modelo = props.counterLabel || "{current} de {total}";
|
|
60
|
+
return modelo
|
|
61
|
+
.replace("{current}", String(index() + 1))
|
|
62
|
+
.replace("{total}", String(stepCount()));
|
|
63
|
+
}
|
|
64
|
+
function announceText() {
|
|
65
|
+
return counterText() + ": " + currentStep().title;
|
|
66
|
+
}
|
|
67
|
+
function nextText() {
|
|
68
|
+
if (isLast())
|
|
69
|
+
return props.finishLabel || "Concluir";
|
|
70
|
+
return props.nextLabel || "Próximo";
|
|
71
|
+
}
|
|
72
|
+
function previousText() {
|
|
73
|
+
return props.previousLabel || "Anterior";
|
|
74
|
+
}
|
|
75
|
+
function skipText() {
|
|
76
|
+
return props.skipLabel || "Sair do tour";
|
|
77
|
+
}
|
|
78
|
+
function showSkip() {
|
|
79
|
+
return !props.hideSkip;
|
|
80
|
+
}
|
|
81
|
+
function show() {
|
|
82
|
+
return !!props.open && stepCount() > 0;
|
|
83
|
+
}
|
|
84
|
+
function rootClasses() {
|
|
85
|
+
return [
|
|
86
|
+
"umds-coachmark",
|
|
87
|
+
hasTarget ? "" : "umds-coachmark--no-target",
|
|
88
|
+
positioned ? "umds-coachmark--ready" : "",
|
|
89
|
+
]
|
|
90
|
+
.filter(Boolean)
|
|
91
|
+
.join(" ");
|
|
92
|
+
}
|
|
93
|
+
function cardClasses() {
|
|
94
|
+
return [
|
|
95
|
+
"umds-coachmark__card",
|
|
96
|
+
hasTarget ? "" : "umds-coachmark__card--centered",
|
|
97
|
+
props.className,
|
|
98
|
+
]
|
|
99
|
+
.filter(Boolean)
|
|
100
|
+
.join(" ");
|
|
101
|
+
}
|
|
102
|
+
function cutoutStyle() {
|
|
103
|
+
const folga = props.padding !== undefined ? props.padding : 8;
|
|
104
|
+
return {
|
|
105
|
+
top: rectTop - folga + "px",
|
|
106
|
+
left: rectLeft - folga + "px",
|
|
107
|
+
width: rectWidth + folga * 2 + "px",
|
|
108
|
+
height: rectHeight + folga * 2 + "px",
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function cardStyle() {
|
|
112
|
+
if (!hasTarget)
|
|
113
|
+
return undefined;
|
|
114
|
+
// Opacidade, e não `visibility`: o cartão precisa poder receber o foco antes de ser posicionado.
|
|
115
|
+
return {
|
|
116
|
+
transform: "translate(" + posX + "px, " + posY + "px)",
|
|
117
|
+
opacity: positioned ? 1 : 0,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function resolverAlvo(alvo) {
|
|
121
|
+
if (!alvo || typeof document === "undefined")
|
|
122
|
+
return null;
|
|
123
|
+
if (typeof alvo === "string") {
|
|
124
|
+
try {
|
|
125
|
+
return document.querySelector(alvo);
|
|
126
|
+
}
|
|
127
|
+
catch (erro) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (typeof alvo === "function")
|
|
132
|
+
return resolverAlvo(alvo());
|
|
133
|
+
if (alvo.nodeType === 1)
|
|
134
|
+
return alvo;
|
|
135
|
+
if (alvo.current !== undefined)
|
|
136
|
+
return resolverAlvo(alvo.current);
|
|
137
|
+
if (alvo.value !== undefined)
|
|
138
|
+
return resolverAlvo(alvo.value);
|
|
139
|
+
if (alvo.$el)
|
|
140
|
+
return alvo.$el.nodeType === 1 ? alvo.$el : null;
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
function atualizar(alvo) {
|
|
144
|
+
if (!alvo || !cardRef.current)
|
|
145
|
+
return;
|
|
146
|
+
const caixa = alvo.getBoundingClientRect();
|
|
147
|
+
setRectTop(caixa.top);
|
|
148
|
+
setRectLeft(caixa.left);
|
|
149
|
+
setRectWidth(caixa.width);
|
|
150
|
+
setRectHeight(caixa.height);
|
|
151
|
+
const lado = (currentStep().placement || "bottom");
|
|
152
|
+
computePosition(alvo, cardRef.current, {
|
|
153
|
+
placement: lado,
|
|
154
|
+
strategy: "fixed",
|
|
155
|
+
middleware: [
|
|
156
|
+
offset(16),
|
|
157
|
+
flip(),
|
|
158
|
+
shift({
|
|
159
|
+
padding: 16,
|
|
160
|
+
}),
|
|
161
|
+
],
|
|
162
|
+
}).then((posicao) => {
|
|
163
|
+
const dpr = typeof window !== "undefined" ? window.devicePixelRatio || 1 : 1;
|
|
164
|
+
setPosX(Math.round(posicao.x * dpr) / dpr);
|
|
165
|
+
setPosY(Math.round(posicao.y * dpr) / dpr);
|
|
166
|
+
setPositioned(true);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function ligar() {
|
|
170
|
+
desligar();
|
|
171
|
+
const alvo = resolverAlvo(currentStep().target);
|
|
172
|
+
attachedRef.current = index();
|
|
173
|
+
if (!alvo) {
|
|
174
|
+
setHasTarget(false);
|
|
175
|
+
setPositioned(true);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
setHasTarget(true);
|
|
179
|
+
if (alvo.scrollIntoView) {
|
|
180
|
+
const caixa = alvo.getBoundingClientRect();
|
|
181
|
+
const altura = typeof window !== "undefined" ? window.innerHeight : 0;
|
|
182
|
+
if (caixa.top < 0 || caixa.bottom > altura) {
|
|
183
|
+
alvo.scrollIntoView({
|
|
184
|
+
block: "center",
|
|
185
|
+
inline: "nearest",
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (cardRef.current) {
|
|
190
|
+
cleanupRef.current = autoUpdate(alvo, cardRef.current, () => atualizar(alvo));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function desligar() {
|
|
194
|
+
if (cleanupRef.current) {
|
|
195
|
+
cleanupRef.current();
|
|
196
|
+
cleanupRef.current = null;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function sincronizar() {
|
|
200
|
+
if (typeof document === "undefined")
|
|
201
|
+
return;
|
|
202
|
+
if (show() && !active && !cardRef.current) {
|
|
203
|
+
if (tentativas < 30) {
|
|
204
|
+
requestAnimationFrame(() => {
|
|
205
|
+
setTentativas(tentativas + 1);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (show() && !active) {
|
|
211
|
+
setActive(true);
|
|
212
|
+
setTentativas(0);
|
|
213
|
+
previousFocusRef.current = document.activeElement;
|
|
214
|
+
ligar();
|
|
215
|
+
if (cardRef.current)
|
|
216
|
+
cardRef.current.focus({
|
|
217
|
+
preventScroll: true,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
else if (show() && active && attachedRef.current !== index()) {
|
|
221
|
+
ligar();
|
|
222
|
+
}
|
|
223
|
+
else if (!show() && active) {
|
|
224
|
+
setActive(false);
|
|
225
|
+
desligar();
|
|
226
|
+
attachedRef.current = null;
|
|
227
|
+
setHasTarget(false);
|
|
228
|
+
setPositioned(false);
|
|
229
|
+
if (props.step === undefined)
|
|
230
|
+
setInternalStep(props.defaultStep || 0);
|
|
231
|
+
if (previousFocusRef.current && previousFocusRef.current.focus) {
|
|
232
|
+
previousFocusRef.current.focus();
|
|
233
|
+
previousFocusRef.current = null;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function irPara(proximo) {
|
|
238
|
+
if (proximo < 0 || proximo > stepCount() - 1)
|
|
239
|
+
return;
|
|
240
|
+
setInternalStep(proximo);
|
|
241
|
+
if (props.onStepChange)
|
|
242
|
+
props.onStepChange(proximo);
|
|
243
|
+
}
|
|
244
|
+
function fechar(motivo) {
|
|
245
|
+
if (props.onClose)
|
|
246
|
+
props.onClose(motivo);
|
|
247
|
+
}
|
|
248
|
+
function handleNext() {
|
|
249
|
+
if (isLast())
|
|
250
|
+
fechar("finish");
|
|
251
|
+
else
|
|
252
|
+
irPara(index() + 1);
|
|
253
|
+
}
|
|
254
|
+
function handlePrevious() {
|
|
255
|
+
irPara(index() - 1);
|
|
256
|
+
}
|
|
257
|
+
function handleKeyDown(event) {
|
|
258
|
+
if (!event)
|
|
259
|
+
return;
|
|
260
|
+
if (event.key === "Escape") {
|
|
261
|
+
event.preventDefault();
|
|
262
|
+
fechar("escape");
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (event.altKey || event.ctrlKey || event.metaKey)
|
|
266
|
+
return;
|
|
267
|
+
if (event.key === "ArrowRight") {
|
|
268
|
+
event.preventDefault();
|
|
269
|
+
handleNext();
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (event.key === "ArrowLeft") {
|
|
273
|
+
event.preventDefault();
|
|
274
|
+
handlePrevious();
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (event.key !== "Tab" || !cardRef.current)
|
|
278
|
+
return;
|
|
279
|
+
// Foco preso: Tab e Shift+Tab giram dentro do cartão.
|
|
280
|
+
const focaveis = cardRef.current.querySelectorAll("button:not([disabled])");
|
|
281
|
+
if (focaveis.length === 0) {
|
|
282
|
+
event.preventDefault();
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const primeiro = focaveis[0];
|
|
286
|
+
const ultimo = focaveis[focaveis.length - 1];
|
|
287
|
+
const ativo = document.activeElement;
|
|
288
|
+
if (event.shiftKey) {
|
|
289
|
+
if (ativo === primeiro || ativo === cardRef.current) {
|
|
290
|
+
event.preventDefault();
|
|
291
|
+
ultimo.focus();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
else if (ativo === ultimo) {
|
|
295
|
+
event.preventDefault();
|
|
296
|
+
primeiro.focus();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function handleVeilMouseDown(event) {
|
|
300
|
+
if (event && event.preventDefault)
|
|
301
|
+
event.preventDefault();
|
|
302
|
+
if (cardRef.current)
|
|
303
|
+
cardRef.current.focus({
|
|
304
|
+
preventScroll: true,
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
useEffect(() => {
|
|
308
|
+
setUid(gerarId("umds-coachmark"));
|
|
309
|
+
sincronizar();
|
|
310
|
+
}, []);
|
|
311
|
+
useEffect(() => {
|
|
312
|
+
sincronizar();
|
|
313
|
+
});
|
|
314
|
+
useEffect(() => {
|
|
315
|
+
return () => {
|
|
316
|
+
desligar();
|
|
317
|
+
};
|
|
318
|
+
}, []);
|
|
319
|
+
return (_jsx(_Fragment, { children: show() ? (_jsx(_Fragment, { children: _jsx(Portal, { children: _jsxs("div", { className: rootClasses(), children: [_jsx("div", { "aria-hidden": "true", className: "umds-coachmark__veil", onMouseDown: (event) => handleVeilMouseDown(event) }), hasTarget ? (_jsx("div", { "aria-hidden": "true", className: "umds-coachmark__cutout", style: cutoutStyle() })) : null, _jsxs("div", { role: "dialog", "aria-modal": "true", ref: cardRef, style: cardStyle(), "aria-labelledby": titleId(), "aria-describedby": contentId(), tabIndex: -1, onKeyDown: (event) => handleKeyDown(event), className: cardClasses(), children: [_jsx("span", { "aria-live": "polite", className: "umds-coachmark__sr", children: announceText() }), _jsx(Text, { as: "span", variant: "body2", weight: "bold", color: "primary", "aria-hidden": "true", children: counterText() }), _jsx(Text, { as: "h2", variant: "subtitle1", weight: "bold", id: titleId(), children: currentStep().title }), currentStep().content ? (_jsx(Text, { as: "p", variant: "body2", color: "secondary", id: contentId(), children: currentStep().content })) : null, _jsxs("div", { className: "umds-coachmark__footer", children: [showSkip() ? (_jsx(Button, { variant: "text", size: "sm", onClick: (event) => fechar("skip"), children: skipText() })) : null, _jsxs("span", { className: "umds-coachmark__actions", children: [!isFirst() ? (_jsx(Button, { variant: "secondary", size: "md", onClick: (event) => handlePrevious(), children: previousText() })) : null, _jsx(Button, { variant: "primary", size: "md", onClick: (event) => handleNext(), children: nextText() })] })] })] })] }) }) })) : null }));
|
|
320
|
+
}
|
|
321
|
+
export default Coachmark;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/* ─────────────────────────────────────────────
|
|
2
|
+
CODE BLOCK
|
|
3
|
+
Texto em fonte monoespaçada, com borda, rolagem e botão de copiar.
|
|
4
|
+
|
|
5
|
+
Fundo claro e texto escuro (contraste de texto, nos temas claro e escuro: os
|
|
6
|
+
dois vêm dos semânticos). Sem cor de sintaxe.
|
|
7
|
+
|
|
8
|
+
Cores: semânticos · Medidas: primitivos
|
|
9
|
+
───────────────────────────────────────────── */
|
|
10
|
+
|
|
11
|
+
.umds-code-block {
|
|
12
|
+
display: flex;
|
|
13
|
+
flex-direction: column;
|
|
14
|
+
min-width: 0;
|
|
15
|
+
background: var(--umds-semantic-color-background-light);
|
|
16
|
+
border: var(--umds-primitive-border-width-hairline) solid var(--umds-semantic-color-neutral-light-down);
|
|
17
|
+
border-radius: var(--umds-primitive-border-radius-sm);
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.umds-code-block__header {
|
|
22
|
+
display: flex;
|
|
23
|
+
align-items: center;
|
|
24
|
+
justify-content: space-between;
|
|
25
|
+
gap: var(--umds-primitive-spacing-nano); /* 8px */
|
|
26
|
+
padding: var(--umds-primitive-spacing-quarck) var(--umds-primitive-spacing-nano); /* 4px 8px */
|
|
27
|
+
border-bottom: var(--umds-primitive-border-width-hairline) solid var(--umds-semantic-color-neutral-light-down);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.umds-code-block__language {
|
|
31
|
+
font-family: var(--umds-semantic-font-family-mono);
|
|
32
|
+
font-size: var(--umds-primitive-font-size-xxxs); /* 12px */
|
|
33
|
+
font-weight: var(--umds-primitive-font-weight-semibold);
|
|
34
|
+
color: var(--umds-semantic-color-neutral-dark-down);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.umds-code-block__copy {
|
|
38
|
+
display: inline-flex;
|
|
39
|
+
align-items: center;
|
|
40
|
+
gap: var(--umds-primitive-spacing-quarck); /* 4px */
|
|
41
|
+
margin: 0 0 0 auto;
|
|
42
|
+
padding: var(--umds-primitive-spacing-quarck) var(--umds-primitive-spacing-nano); /* 4px 8px */
|
|
43
|
+
border: none;
|
|
44
|
+
border-radius: var(--umds-primitive-border-radius-sm);
|
|
45
|
+
background: transparent;
|
|
46
|
+
font: inherit;
|
|
47
|
+
font-size: var(--umds-primitive-font-size-xxxs); /* 12px */
|
|
48
|
+
font-weight: var(--umds-primitive-font-weight-semibold);
|
|
49
|
+
color: var(--umds-semantic-color-neutral-dark-down);
|
|
50
|
+
cursor: pointer;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.umds-code-block__copy:hover {
|
|
54
|
+
background: var(--umds-semantic-color-neutral-light-medium);
|
|
55
|
+
color: var(--umds-semantic-color-neutral-dark-pure);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.umds-code-block__copy:focus-visible,
|
|
59
|
+
.umds-code-block__scroll:focus-visible {
|
|
60
|
+
outline: var(--umds-primitive-border-width-thin) solid var(--umds-semantic-color-primary-pure);
|
|
61
|
+
outline-offset: calc(var(--umds-primitive-border-width-thin) * -1);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.umds-code-block__scroll {
|
|
65
|
+
margin: 0;
|
|
66
|
+
padding: var(--umds-primitive-spacing-mini) var(--umds-primitive-spacing-xxxs); /* 12px 16px */
|
|
67
|
+
overflow: auto;
|
|
68
|
+
font-family: var(--umds-semantic-font-family-mono);
|
|
69
|
+
font-size: var(--umds-primitive-font-size-xxs); /* 14px */
|
|
70
|
+
line-height: var(--umds-primitive-font-line-height-lg);
|
|
71
|
+
color: var(--umds-semantic-color-neutral-dark-pure);
|
|
72
|
+
white-space: pre;
|
|
73
|
+
tab-size: 2;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.umds-code-block--wrap .umds-code-block__scroll {
|
|
77
|
+
white-space: pre-wrap;
|
|
78
|
+
overflow-wrap: anywhere;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.umds-code-block__code {
|
|
82
|
+
font-family: inherit;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.umds-code-block__sr {
|
|
86
|
+
position: absolute;
|
|
87
|
+
width: 1px;
|
|
88
|
+
height: 1px;
|
|
89
|
+
padding: 0;
|
|
90
|
+
margin: -1px;
|
|
91
|
+
overflow: hidden;
|
|
92
|
+
clip: rect(0, 0, 0, 0);
|
|
93
|
+
clip-path: inset(50%);
|
|
94
|
+
white-space: nowrap;
|
|
95
|
+
border: 0;
|
|
96
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import './CodeBlock.css';
|
|
2
|
+
/**
|
|
3
|
+
* CodeBlock — trecho de código (ou JSON, ou um log) em fonte monoespaçada, com
|
|
4
|
+
* borda, rolagem e botão de copiar.
|
|
5
|
+
*
|
|
6
|
+
* O texto vem por `code` ou como conteúdo (`<CodeBlock>{...}</CodeBlock>`); o
|
|
7
|
+
* espaço e as quebras de linha são mantidos. Linha longa rola na horizontal
|
|
8
|
+
* (ou quebra, com `wrap`), e `maxHeight` limita a altura e rola na vertical. A
|
|
9
|
+
* área de rolagem é focável (Tab) e tem nome (`ariaLabel`), para quem usa o
|
|
10
|
+
* teclado poder rolar.
|
|
11
|
+
*
|
|
12
|
+
* `copyable` põe o botão de copiar no canto: copia o texto inteiro (não o que
|
|
13
|
+
* está à vista), troca o ícone por "Copiado" por dois segundos e anuncia isso ao
|
|
14
|
+
* leitor de tela. `onCopy` recebe o texto. Os textos são props.
|
|
15
|
+
*
|
|
16
|
+
* É só texto: não colore sintaxe (isso pede uma biblioteca, e o bloco do 1Doc
|
|
17
|
+
* mostra JSON e logs, que ficam bem em uma cor só).
|
|
18
|
+
* @property {string} code - O texto (ou passe como conteúdo)
|
|
19
|
+
* @property {string} language - Nome da linguagem, mostrado no topo (ex.: "JSON"). É só rótulo
|
|
20
|
+
* @property {boolean} wrap - Quebra a linha longa em vez de rolar
|
|
21
|
+
* @property {number} maxHeight - Altura máxima, em px (rola dentro dela)
|
|
22
|
+
* @property {boolean} copyable - Mostra o botão de copiar
|
|
23
|
+
* @property {string} copyLabel - Nome do botão de copiar (padrão "Copiar")
|
|
24
|
+
* @property {string} copiedLabel - Nome do botão e anúncio depois de copiar (padrão "Copiado")
|
|
25
|
+
* @property {string} ariaLabel - Nome da área de rolagem (padrão: a linguagem, ou "Código")
|
|
26
|
+
* @property {string} className - Classes CSS adicionais
|
|
27
|
+
* @property {function} onCopy - Chamado com o texto depois de copiar
|
|
28
|
+
* @quandoUsar Mostrar JSON de uma resposta, um comando, um log, um exemplo de uso: texto que se lê em fonte monoespaçada e se copia.
|
|
29
|
+
* @quandoNaoUsar Para uma tecla ou atalho, use `Kbd`. Para código dentro de uma frase, use `<code>` direto. Para editar código, use um editor especializado: este bloco só mostra.
|
|
30
|
+
*/
|
|
31
|
+
export interface CodeBlockProps {
|
|
32
|
+
code?: string;
|
|
33
|
+
language?: string;
|
|
34
|
+
wrap?: boolean;
|
|
35
|
+
maxHeight?: number;
|
|
36
|
+
copyable?: boolean;
|
|
37
|
+
copyLabel?: string;
|
|
38
|
+
copiedLabel?: string;
|
|
39
|
+
ariaLabel?: string;
|
|
40
|
+
className?: string;
|
|
41
|
+
id?: string;
|
|
42
|
+
onCopy?: (code: string) => void;
|
|
43
|
+
/** O texto, quando não vem por `code`. */
|
|
44
|
+
children?: any;
|
|
45
|
+
}
|
|
46
|
+
declare function CodeBlock(props: CodeBlockProps): import("react/jsx-runtime").JSX.Element;
|
|
47
|
+
export default CodeBlock;
|
|
@@ -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;
|