@tooark/react 1.9.4 → 1.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/README.md +70 -5
- package/README.pt-BR.md +70 -5
- package/dist/ark-accordion.d.ts +28 -0
- package/dist/ark-accordion.js +65 -0
- package/dist/ark-alert.d.ts +2 -2
- package/dist/ark-alert.js +5 -3
- package/dist/ark-avatar.d.ts +1 -1
- package/dist/ark-avatar.js +3 -2
- package/dist/ark-badge.d.ts +6 -2
- package/dist/ark-badge.js +23 -6
- package/dist/ark-breadcrumb.d.ts +38 -0
- package/dist/ark-breadcrumb.js +48 -0
- package/dist/ark-button.d.ts +7 -3
- package/dist/ark-button.js +9 -6
- package/dist/ark-calendar.d.ts +2 -2
- package/dist/ark-calendar.js +3 -2
- package/dist/ark-card.d.ts +10 -2
- package/dist/ark-card.js +22 -5
- package/dist/ark-carousel.d.ts +1 -1
- package/dist/ark-carousel.js +3 -2
- package/dist/ark-checkbox.d.ts +2 -2
- package/dist/ark-checkbox.js +5 -3
- package/dist/ark-clock.d.ts +2 -2
- package/dist/ark-clock.js +3 -2
- package/dist/ark-color-swatches.d.ts +2 -2
- package/dist/ark-color-swatches.js +3 -2
- package/dist/ark-combobox.d.ts +54 -0
- package/dist/ark-combobox.js +44 -0
- package/dist/ark-command-palette.d.ts +3 -3
- package/dist/ark-command-palette.js +12 -6
- package/dist/ark-copy-button.d.ts +6 -2
- package/dist/ark-copy-button.js +7 -4
- package/dist/ark-data-view.d.ts +1 -1
- package/dist/ark-data-view.js +5 -3
- package/dist/ark-datepicker.d.ts +2 -2
- package/dist/ark-datepicker.js +11 -4
- package/dist/ark-dialog.d.ts +2 -2
- package/dist/ark-dialog.js +5 -3
- package/dist/ark-drawer.d.ts +2 -2
- package/dist/ark-drawer.js +5 -3
- package/dist/ark-empty.d.ts +1 -1
- package/dist/ark-empty.js +5 -3
- package/dist/ark-file-input.d.ts +7 -3
- package/dist/ark-file-input.js +16 -4
- package/dist/ark-input.d.ts +2 -2
- package/dist/ark-input.js +5 -3
- package/dist/ark-kbd.d.ts +1 -1
- package/dist/ark-kbd.js +5 -3
- package/dist/ark-kv-editor.d.ts +2 -2
- package/dist/ark-kv-editor.js +3 -2
- package/dist/ark-mark.d.ts +1 -1
- package/dist/ark-mark.js +3 -2
- package/dist/ark-menu.d.ts +1 -1
- package/dist/ark-menu.js +9 -7
- package/dist/ark-nav.d.ts +4 -4
- package/dist/ark-nav.js +9 -7
- package/dist/ark-otp-input.d.ts +40 -0
- package/dist/ark-otp-input.js +38 -0
- package/dist/ark-pagination.d.ts +1 -1
- package/dist/ark-pagination.js +3 -2
- package/dist/ark-popover.d.ts +24 -0
- package/dist/ark-popover.js +42 -0
- package/dist/ark-progress.d.ts +2 -2
- package/dist/ark-progress.js +3 -2
- package/dist/ark-radio.d.ts +3 -3
- package/dist/ark-radio.js +7 -5
- package/dist/ark-scheduler.d.ts +1 -1
- package/dist/ark-scheduler.js +3 -2
- package/dist/ark-select.d.ts +2 -2
- package/dist/ark-select.js +5 -3
- package/dist/ark-shape-picker.d.ts +2 -2
- package/dist/ark-shape-picker.js +3 -2
- package/dist/ark-skeleton.d.ts +1 -1
- package/dist/ark-skeleton.js +5 -3
- package/dist/ark-slider.d.ts +45 -0
- package/dist/ark-slider.js +49 -0
- package/dist/ark-spinner.d.ts +1 -1
- package/dist/ark-spinner.js +3 -2
- package/dist/ark-split-pane.d.ts +1 -1
- package/dist/ark-split-pane.js +5 -3
- package/dist/ark-status-dot.d.ts +1 -1
- package/dist/ark-status-dot.js +3 -2
- package/dist/ark-stepper.d.ts +50 -0
- package/dist/ark-stepper.js +57 -0
- package/dist/ark-switch.d.ts +2 -2
- package/dist/ark-switch.js +8 -5
- package/dist/ark-tabs.d.ts +19 -3
- package/dist/ark-tabs.js +20 -5
- package/dist/ark-textarea.d.ts +6 -2
- package/dist/ark-textarea.js +7 -4
- package/dist/ark-time.d.ts +1 -1
- package/dist/ark-time.js +3 -2
- package/dist/ark-timeline.d.ts +32 -0
- package/dist/ark-timeline.js +26 -0
- package/dist/ark-timer.d.ts +26 -0
- package/dist/ark-timer.js +41 -0
- package/dist/ark-toaster.d.ts +1 -1
- package/dist/ark-toaster.js +3 -2
- package/dist/ark-toggle.d.ts +1 -1
- package/dist/ark-toggle.js +7 -5
- package/dist/ark-tooltip.d.ts +1 -1
- package/dist/ark-tooltip.js +5 -3
- package/dist/ark-tree.d.ts +3 -3
- package/dist/ark-tree.js +7 -5
- package/dist/code.d.ts +1 -1
- package/dist/elements.d.ts +104 -0
- package/dist/elements.js +52 -0
- package/dist/index.d.ts +1 -85
- package/dist/index.js +7 -43
- package/dist/jsx-intrinsics.d.ts +190 -0
- package/dist/register-elements.d.ts +8 -0
- package/dist/register-elements.js +22 -0
- package/dist/text-child.d.ts +3 -0
- package/dist/text-child.js +8 -0
- package/package.json +17 -7
package/README.md
CHANGED
|
@@ -28,10 +28,10 @@ Typed React wrappers for the Tooark Web Components: camelCase props, custom even
|
|
|
28
28
|
|
|
29
29
|
The `@tooark/react` package provides:
|
|
30
30
|
|
|
31
|
-
- one component per element (
|
|
31
|
+
- one component per element (66 wrappers: `ArkAlert`, `ArkAvatar`, `ArkBadge`, `ArkButton`, `ArkCalendar`, `ArkCard`, …) with typed props that extend the `Ark*StyleOptions` from `@tooark/core`;
|
|
32
32
|
- camelCase props map to attributes; booleans are passed as present/absent; object props (`events`, `rows`, `options`, and `localeJson` on `ArkCalendar`/`ArkDatepicker`) are serialized or assigned as properties for you (on the other wrappers `localeJson` is a JSON string);
|
|
33
33
|
- custom events become handlers receiving the `CustomEvent` (`onChange`, `onClose`, `onSelect`, …) or, on the calendar, datepicker, clock, carousel and scheduler, its `detail`; every props type also takes React's DOM attributes and handlers (`id`, `style`, `title`, `tabIndex`, `aria-*`, `data-*`, `onClick`, `onKeyDown`, `onFocus`, …), typed and forwarded to the element; what the wrapper defines wins over the React prop of the same name (`onChange` is the element's `CustomEvent`), and a `disabled` or `loading` button never fires `onClick`;
|
|
34
|
-
- the elements register themselves on first render
|
|
34
|
+
- the elements register themselves on first render, browser only, so SSR frameworks are fine: every element from `@tooark/react`, only the wrapper's own from `@tooark/react/elements` (see [Configuration](#️-configuration));
|
|
35
35
|
- `IntrinsicElements` typings for every `ark-*` tag, for the side packages or when you prefer the raw element;
|
|
36
36
|
- `toast`, `showToast`, `dismissToast` and `setArkLocale`, `getArkLocale`, `observeArkLocale` (the app-wide default language) re-exported from `@tooark/core`.
|
|
37
37
|
|
|
@@ -57,6 +57,12 @@ Import the stylesheet once, in `main.tsx` or your root layout; nothing else to c
|
|
|
57
57
|
import "@tooark/web-components/styles.css";
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
+
**Smaller bundles: `@tooark/react/elements`.** The main entry registers every element on the first wrapper, so a raw `ark-*` tag next to a wrapper just works, and the bundle carries all of them: about 481 kB minified and before compression, React and `@tooark/core` not counted. `@tooark/react/elements` exports the same wrappers and types, and each one registers only its own element and what it creates inside or coordinates (the items of a menu, the input and calendar of a datepicker): about 22 kB for `ArkButton`, 39 kB for `ArkButton`, `ArkDialog` and `ArkInput`. Import every wrapper from it: one import from `@tooark/react` anywhere in the app, yours or a dependency's, brings back the registration of every element. A raw `ark-*` tag you write without its wrapper is then yours to define, with `registerTooarkElements` from `@tooark/web-components`.
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
import { ArkButton, ArkDialog } from "@tooark/react/elements";
|
|
64
|
+
```
|
|
65
|
+
|
|
60
66
|
---
|
|
61
67
|
|
|
62
68
|
## 📦 Components
|
|
@@ -65,7 +71,7 @@ One wrapper per element, named after it: `ark-button` → `ArkButton`, `ark-kv-e
|
|
|
65
71
|
|
|
66
72
|
- Props: the element's attributes in camelCase (`iconOnly`, `stepMinutes`, `localeJson`), `className`, plus the element's JS properties where they matter (`events`, `rows`, `options`, `sizes`, `colors`, and `valueField` on `ArkKvEditor`, which must be a stable function: `useCallback`). `ArkDataView` is generic over your record type (`<ArkDataView<User> rows={users} columns={columns} />` types the column `render` and `event.detail.row`) and draws a column's `render` as JSX, through portals into the cells: it returns what a component would (elements, your components, text, `null` for nothing) and runs again on every render, so `columns` needs no `useMemo` (the element only redraws its cells when the column data changes); `cardRender` does the same for a card body.
|
|
67
73
|
- Events: `on<Event>` for the custom events, receiving the `CustomEvent` (`onChange` on `ArkSelect`/`ArkKvEditor`, `onClose` on `ArkDialog`/`ArkDrawer`, `onSelect` on `ArkMenu`/`ArkCommandPalette`, …); `onChange` on `ArkCalendar`/`ArkDatepicker`/`ArkClock`, `onSlideChange` on `ArkCarousel` and `onEventClick`/`onSlotClick`/`onViewChange`/`onRangeChange` on `ArkScheduler` receive the `detail` itself. Native events bubble from the inner control (`onInput` on `ArkInput`: read `event.target.value`).
|
|
68
|
-
- State: attributes like `open` are the source of truth (`ArkDialog open={bool}` + `onClose`), so controlled rendering works and the exit still animates. `onOpen`/`onClose` on `ArkDialog`, `ArkDrawer`, `ArkCommandPalette` and `
|
|
74
|
+
- State: attributes like `open` are the source of truth (`ArkDialog open={bool}` + `onClose`), so controlled rendering works and the exit still animates. `onOpen`/`onClose` on `ArkDialog`, `ArkDrawer`, `ArkCommandPalette`, `ArkMenu` and `ArkPopover` fire only for the element's own event, and `onClose` on `ArkTabs` only for its own tabs: `ark-open` and `ark-close` bubble, and the ones of an overlay inside (an `ArkMenu` in a dialog) do not reach the outer handler. `onToggle` on `ArkAccordion` fires only for its own sections and on `ArkAccordionItem` only for itself (an accordion nested in a panel keeps its own). `onQuery` on `ArkCommandPalette` and `ArkCombobox` fires only for the element's own `ark-query` (both elements emit it). The same holds for `onResize` on `ArkSplitPane`, `onSlideChange` on `ArkCarousel`, `onCollapse` on `ArkNav`, `onChange` on `ArkStepper`, `onToggle` on `ArkNavGroup` and the handlers of `ArkTree` and `ArkDataView`: one of them inside another (a split pane in a panel of another one) does not call the outer handler. `onInput`/`onChange` on `ArkInput` are the native events of the field, and a control of your own in `slot="prefix"`/`slot="suffix"` sends its own through the same host: check `event.target` when you put one there.
|
|
69
75
|
- Ref: every wrapper forwards `ref` to its `ark-*` element (React 18 and 19), typed as the element class from `@tooark/web-components`, so its methods and properties are typed. Object and callback refs both work (including React 19 callback refs that return a cleanup), and the wrapper's own events and properties keep working.
|
|
70
76
|
|
|
71
77
|
```tsx
|
|
@@ -147,6 +153,65 @@ export function ProfileForm() {
|
|
|
147
153
|
}
|
|
148
154
|
```
|
|
149
155
|
|
|
156
|
+
### Routing `ark-navigate` through your router
|
|
157
|
+
|
|
158
|
+
`ark-navigate` bubbles from every `ark-*` link (`ArkNavItem`, `ArkButton`, `ArkCard` and `ArkBreadcrumbItem` with `href`), so one listener at the root routes all of them, raw tags included. It only fires for a plain click: a click with a modifier, `target="_blank"` or `download` never emits it and stays with the browser, as with your router's own links. Links to another site are left to the browser too.
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
import { useEffect } from "react";
|
|
162
|
+
|
|
163
|
+
// Routes the plain clicks of every ark-* link through the app's router.
|
|
164
|
+
export function useArkNavigate(go: (path: string) => void): void {
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
const handler = (event: Event): void => {
|
|
167
|
+
if (event.defaultPrevented) return; // already routed by a handler of the app's own
|
|
168
|
+
const { href } = (event as CustomEvent<{ href: string | null }>).detail;
|
|
169
|
+
if (!href) return; // a nav item without href: route by `event.detail.value` in the nav's own handler
|
|
170
|
+
const url = new URL(href, window.location.href);
|
|
171
|
+
if (url.origin !== window.location.origin) return; // another site: the browser follows the link
|
|
172
|
+
event.preventDefault();
|
|
173
|
+
go(url.pathname + url.search + url.hash);
|
|
174
|
+
};
|
|
175
|
+
document.addEventListener("ark-navigate", handler);
|
|
176
|
+
return () => document.removeEventListener("ark-navigate", handler);
|
|
177
|
+
}, [go]);
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
React Router (`react-router` 7; `react-router-dom` on 6), in the root layout, inside the router. The nav's `value` follows the route, so the current item follows it too.
|
|
182
|
+
|
|
183
|
+
```tsx
|
|
184
|
+
import { ArkNav, ArkNavItem } from "@tooark/react";
|
|
185
|
+
import { Outlet, useLocation, useNavigate } from "react-router";
|
|
186
|
+
|
|
187
|
+
export function Layout() {
|
|
188
|
+
const navigate = useNavigate();
|
|
189
|
+
useArkNavigate((path) => navigate(path));
|
|
190
|
+
const { pathname } = useLocation();
|
|
191
|
+
return (
|
|
192
|
+
<>
|
|
193
|
+
<ArkNav value={pathname}>
|
|
194
|
+
<ArkNavItem href="/courses">Courses</ArkNavItem>
|
|
195
|
+
<ArkNavItem href="/settings">Settings</ArkNavItem>
|
|
196
|
+
</ArkNav>
|
|
197
|
+
<Outlet />
|
|
198
|
+
</>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
TanStack Router takes the path already built in `href`:
|
|
204
|
+
|
|
205
|
+
```tsx
|
|
206
|
+
import { useLocation, useNavigate } from "@tanstack/react-router";
|
|
207
|
+
|
|
208
|
+
const navigate = useNavigate();
|
|
209
|
+
useArkNavigate((path) => navigate({ href: path }));
|
|
210
|
+
const pathname = useLocation({ select: (location) => location.pathname });
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
With a base path (`basename`, `basepath`, `createWebHistory("/app/")`, `<base href>`), the `href` in the page includes it, and the router expects the path without it: strip it before routing.
|
|
214
|
+
|
|
150
215
|
### A raw element from a side package
|
|
151
216
|
|
|
152
217
|
```tsx
|
|
@@ -171,8 +236,8 @@ Installed automatically unless marked as peer; peer dependencies are yours to in
|
|
|
171
236
|
|
|
172
237
|
| Package | Version | Description |
|
|
173
238
|
| -------------------------------------------------------------------------------- | ----------------------- | ---------------------------------------------------------------- |
|
|
174
|
-
| [`@tooark/core`](https://www.npmjs.com/package/@tooark/core) | ^1.
|
|
175
|
-
| [`@tooark/web-components`](https://www.npmjs.com/package/@tooark/web-components) | ^1.
|
|
239
|
+
| [`@tooark/core`](https://www.npmjs.com/package/@tooark/core) | ^1.10.0 | Types, i18n, toast/announce services, motion and overlay helpers |
|
|
240
|
+
| [`@tooark/web-components`](https://www.npmjs.com/package/@tooark/web-components) | ^1.10.0 | The `ark-*` Custom Elements and their stylesheet |
|
|
176
241
|
| [`react`](https://www.npmjs.com/package/react) | >=18 (peer) | React 18 or 19 |
|
|
177
242
|
| [`react-dom`](https://www.npmjs.com/package/react-dom) | >=18 (peer) | React DOM renderer |
|
|
178
243
|
| [`@tooark/chart`](https://www.npmjs.com/package/@tooark/chart) | >=1.0.0 (optional peer) | ark-chart, for the `/chart` subpath |
|
package/README.pt-BR.md
CHANGED
|
@@ -28,10 +28,10 @@ Wrappers React tipados dos Tooark Web Components: props camelCase, eventos custo
|
|
|
28
28
|
|
|
29
29
|
O pacote `@tooark/react` fornece:
|
|
30
30
|
|
|
31
|
-
- um componente por elemento (
|
|
31
|
+
- um componente por elemento (66 wrappers: `ArkAlert`, `ArkAvatar`, `ArkBadge`, `ArkButton`, `ArkCalendar`, `ArkCard`, …) com props tipadas que estendem os `Ark*StyleOptions` do `@tooark/core`;
|
|
32
32
|
- props camelCase viram atributos; booleanos vão como presente/ausente; props de objeto (`events`, `rows`, `options` e o `localeJson` de `ArkCalendar`/`ArkDatepicker`) são serializadas ou atribuídas como propriedade para você (nos demais wrappers o `localeJson` é uma string JSON);
|
|
33
33
|
- eventos customizados viram handlers que recebem o `CustomEvent` (`onChange`, `onClose`, `onSelect`, …) ou, no calendário, datepicker, relógio, carrossel e agenda, o `detail` dele; todo tipo de props também aceita os atributos e handlers DOM do React (`id`, `style`, `title`, `tabIndex`, `aria-*`, `data-*`, `onClick`, `onKeyDown`, `onFocus`, …), tipados e repassados ao elemento; o que o wrapper define vale sobre a prop do React de mesmo nome (`onChange` é o `CustomEvent` do elemento), e um botão `disabled` ou `loading` nunca dispara o `onClick`;
|
|
34
|
-
- os elementos se registram no primeiro render
|
|
34
|
+
- os elementos se registram no primeiro render, só no navegador, então frameworks com SSR funcionam: todos pelo `@tooark/react`, só o do wrapper pelo `@tooark/react/elements` (veja [Configuração](#️-configuração));
|
|
35
35
|
- tipagens `IntrinsicElements` de toda tag `ark-*`, para os pacotes laterais ou quando você preferir o elemento cru;
|
|
36
36
|
- `toast`, `showToast`, `dismissToast` e `setArkLocale`, `getArkLocale`, `observeArkLocale` (o idioma padrão do app) reexportados do `@tooark/core`.
|
|
37
37
|
|
|
@@ -57,6 +57,12 @@ Importe a folha de estilo uma vez, no `main.tsx` ou no layout raiz; nada mais a
|
|
|
57
57
|
import "@tooark/web-components/styles.css";
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
+
**Bundles menores: `@tooark/react/elements`.** A entrada principal registra todos os elementos no primeiro wrapper, então uma tag `ark-*` crua ao lado de um wrapper simplesmente funciona, e o bundle leva todos eles: cerca de 481 kB minificado e antes da compressão, sem contar o React e o `@tooark/core`. O `@tooark/react/elements` exporta os mesmos wrappers e tipos, e cada um registra só o próprio elemento e o que ele cria por dentro ou coordena (os itens de um menu, o input e o calendário de um datepicker): cerca de 22 kB para o `ArkButton`, 39 kB para `ArkButton`, `ArkDialog` e `ArkInput`. Importe todos os wrappers dela: um import do `@tooark/react` em qualquer lugar do app, seu ou de uma dependência, traz de volta o registro de todos os elementos. Uma tag `ark-*` crua que você escreve sem o wrapper fica, então, por sua conta, com o `registerTooarkElements` do `@tooark/web-components`.
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
import { ArkButton, ArkDialog } from "@tooark/react/elements";
|
|
64
|
+
```
|
|
65
|
+
|
|
60
66
|
---
|
|
61
67
|
|
|
62
68
|
## 📦 Componentes
|
|
@@ -65,7 +71,7 @@ Um wrapper por elemento, com o nome dele: `ark-button` → `ArkButton`, `ark-kv-
|
|
|
65
71
|
|
|
66
72
|
- Props: os atributos do elemento em camelCase (`iconOnly`, `stepMinutes`, `localeJson`), `className`, mais as propriedades JS do elemento onde importam (`events`, `rows`, `options`, `sizes`, `colors`, e `valueField` no `ArkKvEditor`, que precisa ser uma função estável: `useCallback`). O `ArkDataView` é genérico no tipo do registro (`<ArkDataView<User> rows={users} columns={columns} />` tipa o `render` da coluna e o `event.detail.row`) e desenha o `render` de uma coluna como JSX, por portais nas células: ele devolve o que um componente devolveria (elementos, componentes seus, texto, `null` para nada) e roda de novo a cada render, então `columns` não precisa de `useMemo` (o elemento só refaz as células quando os dados das colunas mudam); `cardRender` faz o mesmo para o corpo de um card.
|
|
67
73
|
- Eventos: `on<Evento>` para os eventos customizados, recebendo o `CustomEvent` (`onChange` em `ArkSelect`/`ArkKvEditor`, `onClose` em `ArkDialog`/`ArkDrawer`, `onSelect` em `ArkMenu`/`ArkCommandPalette`, …); `onChange` em `ArkCalendar`/`ArkDatepicker`/`ArkClock`, `onSlideChange` em `ArkCarousel` e `onEventClick`/`onSlotClick`/`onViewChange`/`onRangeChange` em `ArkScheduler` recebem o próprio `detail`. Eventos nativos sobem do controle interno (`onInput` em `ArkInput`: leia `event.target.value`).
|
|
68
|
-
- Estado: atributos como `open` são a fonte da verdade (`ArkDialog open={bool}` + `onClose`), então renderização controlada funciona e a saída continua animando. `onOpen`/`onClose` em `ArkDialog`, `ArkDrawer`, `ArkCommandPalette` e `
|
|
74
|
+
- Estado: atributos como `open` são a fonte da verdade (`ArkDialog open={bool}` + `onClose`), então renderização controlada funciona e a saída continua animando. `onOpen`/`onClose` em `ArkDialog`, `ArkDrawer`, `ArkCommandPalette`, `ArkMenu` e `ArkPopover` só disparam para o evento do próprio elemento, e `onClose` em `ArkTabs` só para as abas dele: `ark-open` e `ark-close` borbulham, e os de um overlay de dentro (um `ArkMenu` num diálogo) não chegam ao handler de fora. O `onToggle` do `ArkAccordion` dispara só para as seções dele e o do `ArkAccordionItem` só para ela mesma (um accordion aninhado num painel fica com os seus). O `onQuery` em `ArkCommandPalette` e `ArkCombobox` só dispara para o `ark-query` do próprio elemento (os dois elementos o emitem). O mesmo vale para `onResize` em `ArkSplitPane`, `onSlideChange` em `ArkCarousel`, `onCollapse` em `ArkNav`, `onChange` em `ArkStepper`, `onToggle` em `ArkNavGroup` e os handlers de `ArkTree` e `ArkDataView`: um deles dentro de outro (um split pane num painel de outro) não chama o handler de fora. `onInput`/`onChange` em `ArkInput` são os eventos nativos do campo, e um controle seu em `slot="prefix"`/`slot="suffix"` manda os dele pelo mesmo host: confira `event.target` quando puser um ali.
|
|
69
75
|
- Ref: todo wrapper encaminha a `ref` ao seu elemento `ark-*` (React 18 e 19), tipada como a classe do elemento de `@tooark/web-components`, então métodos e propriedades dele são tipados. Ref de objeto e callback ref funcionam (inclusive a callback ref do React 19 que devolve uma limpeza), e os eventos e propriedades do próprio wrapper continuam funcionando.
|
|
70
76
|
|
|
71
77
|
```tsx
|
|
@@ -147,6 +153,65 @@ export function FormularioPerfil() {
|
|
|
147
153
|
}
|
|
148
154
|
```
|
|
149
155
|
|
|
156
|
+
### Rotear o `ark-navigate` pelo seu router
|
|
157
|
+
|
|
158
|
+
O `ark-navigate` borbulha de todo link `ark-*` (`ArkNavItem`, `ArkButton`, `ArkCard` e `ArkBreadcrumbItem` com `href`), então um listener na raiz roteia todos eles, tags cruas incluídas. Ele só dispara num clique simples: um clique com modificador, `target="_blank"` ou `download` nunca o emite e fica com o navegador, como os links do próprio router. Links para outro site também ficam com o navegador.
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
import { useEffect } from "react";
|
|
162
|
+
|
|
163
|
+
// Roteia os cliques simples de todo link ark-* pelo router do app.
|
|
164
|
+
export function useArkNavigate(go: (path: string) => void): void {
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
const handler = (event: Event): void => {
|
|
167
|
+
if (event.defaultPrevented) return; // um handler próprio do app já roteou
|
|
168
|
+
const { href } = (event as CustomEvent<{ href: string | null }>).detail;
|
|
169
|
+
if (!href) return; // um item de nav sem href: roteie pelo `event.detail.value` no handler do próprio nav
|
|
170
|
+
const url = new URL(href, window.location.href);
|
|
171
|
+
if (url.origin !== window.location.origin) return; // outro site: o navegador segue o link
|
|
172
|
+
event.preventDefault();
|
|
173
|
+
go(url.pathname + url.search + url.hash);
|
|
174
|
+
};
|
|
175
|
+
document.addEventListener("ark-navigate", handler);
|
|
176
|
+
return () => document.removeEventListener("ark-navigate", handler);
|
|
177
|
+
}, [go]);
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
React Router (`react-router` 7; `react-router-dom` na 6), no layout raiz, dentro do router. O `value` do nav segue a rota, então o item atual segue junto.
|
|
182
|
+
|
|
183
|
+
```tsx
|
|
184
|
+
import { ArkNav, ArkNavItem } from "@tooark/react";
|
|
185
|
+
import { Outlet, useLocation, useNavigate } from "react-router";
|
|
186
|
+
|
|
187
|
+
export function Layout() {
|
|
188
|
+
const navigate = useNavigate();
|
|
189
|
+
useArkNavigate((path) => navigate(path));
|
|
190
|
+
const { pathname } = useLocation();
|
|
191
|
+
return (
|
|
192
|
+
<>
|
|
193
|
+
<ArkNav value={pathname}>
|
|
194
|
+
<ArkNavItem href="/courses">Cursos</ArkNavItem>
|
|
195
|
+
<ArkNavItem href="/settings">Configurações</ArkNavItem>
|
|
196
|
+
</ArkNav>
|
|
197
|
+
<Outlet />
|
|
198
|
+
</>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
O TanStack Router recebe o caminho já montado em `href`:
|
|
204
|
+
|
|
205
|
+
```tsx
|
|
206
|
+
import { useLocation, useNavigate } from "@tanstack/react-router";
|
|
207
|
+
|
|
208
|
+
const navigate = useNavigate();
|
|
209
|
+
useArkNavigate((path) => navigate({ href: path }));
|
|
210
|
+
const pathname = useLocation({ select: (location) => location.pathname });
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Com um caminho base (`basename`, `basepath`, `createWebHistory("/app/")`, `<base href>`), o `href` da página o inclui, e o router espera o caminho sem ele: tire-o antes de rotear.
|
|
214
|
+
|
|
150
215
|
### Um elemento cru de um pacote lateral
|
|
151
216
|
|
|
152
217
|
```tsx
|
|
@@ -171,8 +236,8 @@ Instaladas automaticamente, salvo as marcadas como peer, que ficam por sua conta
|
|
|
171
236
|
|
|
172
237
|
| Pacote | Versão | Descrição |
|
|
173
238
|
| -------------------------------------------------------------------------------- | ----------------------- | -------------------------------------------------------------------- |
|
|
174
|
-
| [`@tooark/core`](https://www.npmjs.com/package/@tooark/core) | ^1.
|
|
175
|
-
| [`@tooark/web-components`](https://www.npmjs.com/package/@tooark/web-components) | ^1.
|
|
239
|
+
| [`@tooark/core`](https://www.npmjs.com/package/@tooark/core) | ^1.10.0 | Tipos, i18n, serviços de toast/announce, motion e helpers de overlay |
|
|
240
|
+
| [`@tooark/web-components`](https://www.npmjs.com/package/@tooark/web-components) | ^1.10.0 | Os Custom Elements `ark-*` e a folha de estilo deles |
|
|
176
241
|
| [`react`](https://www.npmjs.com/package/react) | >=18 (peer) | React 18 ou 19 |
|
|
177
242
|
| [`react-dom`](https://www.npmjs.com/package/react-dom) | >=18 (peer) | Renderizador React DOM |
|
|
178
243
|
| [`@tooark/chart`](https://www.npmjs.com/package/@tooark/chart) | >=1.0.0 (peer opcional) | ark-chart, para a subpath `/chart` |
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ArkAccordionItemStyleOptions, ArkAccordionStyleOptions, ArkAccordionToggleDetail } from "@tooark/core";
|
|
2
|
+
import { ArkAccordion as ArkAccordionElement, ArkAccordionItem as ArkAccordionItemElement } from "@tooark/web-components";
|
|
3
|
+
import React, { type PropsWithChildren } from "react";
|
|
4
|
+
import { type ArkDomProps } from "./dom-props.js";
|
|
5
|
+
export type ArkAccordionProps = PropsWithChildren<ArkDomProps<ArkAccordionStyleOptions & {
|
|
6
|
+
className?: string;
|
|
7
|
+
/** `ark-toggle` de uma seção deste accordion (as de um accordion aninhado ficam com ele). */
|
|
8
|
+
onToggle?: (event: CustomEvent<ArkAccordionToggleDetail>) => void;
|
|
9
|
+
}>>;
|
|
10
|
+
export declare const ArkAccordion: React.ForwardRefExoticComponent<ArkAccordionStyleOptions & {
|
|
11
|
+
className?: string;
|
|
12
|
+
/** `ark-toggle` de uma seção deste accordion (as de um accordion aninhado ficam com ele). */
|
|
13
|
+
onToggle?: (event: CustomEvent<ArkAccordionToggleDetail>) => void;
|
|
14
|
+
} & Omit<React.HTMLAttributes<HTMLElement>, "children" | "className" | "onToggle" | keyof ArkAccordionStyleOptions> & {
|
|
15
|
+
children?: React.ReactNode | undefined;
|
|
16
|
+
} & React.RefAttributes<ArkAccordionElement>>;
|
|
17
|
+
export type ArkAccordionItemProps = PropsWithChildren<ArkDomProps<ArkAccordionItemStyleOptions & {
|
|
18
|
+
className?: string;
|
|
19
|
+
/** A pessoa abriu ou fechou esta seção (ou ela fechou porque outra abriu, numa por vez). */
|
|
20
|
+
onToggle?: (event: CustomEvent<ArkAccordionToggleDetail>) => void;
|
|
21
|
+
}>>;
|
|
22
|
+
export declare const ArkAccordionItem: React.ForwardRefExoticComponent<ArkAccordionItemStyleOptions & {
|
|
23
|
+
className?: string;
|
|
24
|
+
/** A pessoa abriu ou fechou esta seção (ou ela fechou porque outra abriu, numa por vez). */
|
|
25
|
+
onToggle?: (event: CustomEvent<ArkAccordionToggleDetail>) => void;
|
|
26
|
+
} & Omit<React.HTMLAttributes<HTMLElement>, "children" | "className" | "onToggle" | keyof ArkAccordionItemStyleOptions> & {
|
|
27
|
+
children?: React.ReactNode | undefined;
|
|
28
|
+
} & React.RefAttributes<ArkAccordionItemElement>>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ArkAccordion as ArkAccordionElement, ArkAccordionItem as ArkAccordionItemElement } from "@tooark/web-components";
|
|
2
|
+
import { createElement, forwardRef, useEffect } from "react";
|
|
3
|
+
import { domAttrs } from "./dom-props.js";
|
|
4
|
+
import { ensureTooarkElementsRegistered } from "./register-elements.js";
|
|
5
|
+
import { textChild } from "./text-child.js";
|
|
6
|
+
import { useForwardedRef } from "./use-forwarded-ref.js";
|
|
7
|
+
import { useIsomorphicLayoutEffect } from "./use-isomorphic-layout-effect.js";
|
|
8
|
+
export const ArkAccordion = forwardRef(function ArkAccordion(props, forwardedRef) {
|
|
9
|
+
const { children, className, multiple, headingLevel, onToggle, ...rest } = props;
|
|
10
|
+
const [ref, setRef] = useForwardedRef(forwardedRef);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
ensureTooarkElementsRegistered(ArkAccordionElement);
|
|
13
|
+
}, []);
|
|
14
|
+
useIsomorphicLayoutEffect(() => {
|
|
15
|
+
const el = ref.current;
|
|
16
|
+
if (!el)
|
|
17
|
+
return;
|
|
18
|
+
// Só as seções deste accordion: o ark-toggle borbulha, vem também de um accordion aninhado e de outros
|
|
19
|
+
// componentes (ark-nav-group, ark-tree).
|
|
20
|
+
const handleToggle = (event) => {
|
|
21
|
+
const item = event.target;
|
|
22
|
+
if (item.localName === "ark-accordion-item" && item.closest("ark-accordion") === event.currentTarget) {
|
|
23
|
+
onToggle?.(event);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
el.addEventListener("ark-toggle", handleToggle);
|
|
27
|
+
return () => el.removeEventListener("ark-toggle", handleToggle);
|
|
28
|
+
}, [ref, onToggle]);
|
|
29
|
+
const attrs = {
|
|
30
|
+
...domAttrs(rest),
|
|
31
|
+
ref: setRef,
|
|
32
|
+
class: className,
|
|
33
|
+
multiple: multiple ? "" : undefined,
|
|
34
|
+
"heading-level": headingLevel
|
|
35
|
+
};
|
|
36
|
+
return createElement("ark-accordion", attrs, textChild(children));
|
|
37
|
+
});
|
|
38
|
+
export const ArkAccordionItem = forwardRef(function ArkAccordionItem(props, forwardedRef) {
|
|
39
|
+
const { children, className, open, disabled, headingLevel, onToggle, ...rest } = props;
|
|
40
|
+
const [ref, setRef] = useForwardedRef(forwardedRef);
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
ensureTooarkElementsRegistered(ArkAccordionItemElement);
|
|
43
|
+
}, []);
|
|
44
|
+
useIsomorphicLayoutEffect(() => {
|
|
45
|
+
const el = ref.current;
|
|
46
|
+
if (!el)
|
|
47
|
+
return;
|
|
48
|
+
// Só o desta seção: o de uma seção de um accordion no painel também borbulha até aqui.
|
|
49
|
+
const handleToggle = (event) => {
|
|
50
|
+
if (event.target === event.currentTarget)
|
|
51
|
+
onToggle?.(event);
|
|
52
|
+
};
|
|
53
|
+
el.addEventListener("ark-toggle", handleToggle);
|
|
54
|
+
return () => el.removeEventListener("ark-toggle", handleToggle);
|
|
55
|
+
}, [ref, onToggle]);
|
|
56
|
+
const attrs = {
|
|
57
|
+
...domAttrs(rest),
|
|
58
|
+
ref: setRef,
|
|
59
|
+
class: className,
|
|
60
|
+
open: open ? "" : undefined,
|
|
61
|
+
disabled: disabled ? "" : undefined,
|
|
62
|
+
"heading-level": headingLevel
|
|
63
|
+
};
|
|
64
|
+
return createElement("ark-accordion-item", attrs, textChild(children));
|
|
65
|
+
});
|
package/dist/ark-alert.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ArkAlertStyleOptions } from "@tooark/core";
|
|
2
|
-
import
|
|
2
|
+
import { ArkAlert as ArkAlertElement } from "@tooark/web-components";
|
|
3
3
|
import React, { type PropsWithChildren } from "react";
|
|
4
4
|
import { type ArkDomProps } from "./dom-props.js";
|
|
5
5
|
export type ArkAlertProps = PropsWithChildren<ArkDomProps<ArkAlertStyleOptions & {
|
|
@@ -19,6 +19,6 @@ export declare const ArkAlert: React.ForwardRefExoticComponent<ArkAlertStyleOpti
|
|
|
19
19
|
className?: string;
|
|
20
20
|
/** Depois da saída animada: o host ganha `hidden`; desmontar é do app. */
|
|
21
21
|
onDismiss?: (event: CustomEvent) => void;
|
|
22
|
-
} & Omit<React.HTMLAttributes<HTMLElement>, "children" | "className" | keyof ArkAlertStyleOptions | "
|
|
22
|
+
} & Omit<React.HTMLAttributes<HTMLElement>, "children" | "className" | "heading" | keyof ArkAlertStyleOptions | "dismissible" | "onDismiss"> & {
|
|
23
23
|
children?: React.ReactNode | undefined;
|
|
24
24
|
} & React.RefAttributes<ArkAlertElement>>;
|
package/dist/ark-alert.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { ArkAlert as ArkAlertElement } from "@tooark/web-components";
|
|
1
2
|
import { createElement, forwardRef, useEffect } from "react";
|
|
2
3
|
import { domAttrs } from "./dom-props.js";
|
|
3
|
-
import {
|
|
4
|
+
import { ensureTooarkElementsRegistered } from "./register-elements.js";
|
|
5
|
+
import { textChild } from "./text-child.js";
|
|
4
6
|
import { useForwardedRef } from "./use-forwarded-ref.js";
|
|
5
7
|
export const ArkAlert = forwardRef(function ArkAlert(props, forwardedRef) {
|
|
6
8
|
const { children, className, localeJson, dismissible, onDismiss, ...rest } = props;
|
|
7
9
|
const [ref, setRef] = useForwardedRef(forwardedRef);
|
|
8
10
|
useEffect(() => {
|
|
9
|
-
|
|
11
|
+
ensureTooarkElementsRegistered(ArkAlertElement);
|
|
10
12
|
}, []);
|
|
11
13
|
useEffect(() => {
|
|
12
14
|
const el = ref.current;
|
|
@@ -23,5 +25,5 @@ export const ArkAlert = forwardRef(function ArkAlert(props, forwardedRef) {
|
|
|
23
25
|
dismissible: dismissible ? "" : undefined,
|
|
24
26
|
"locale-json": localeJson
|
|
25
27
|
};
|
|
26
|
-
return createElement("ark-alert", attrs, children);
|
|
28
|
+
return createElement("ark-alert", attrs, textChild(children));
|
|
27
29
|
});
|
package/dist/ark-avatar.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ArkAvatarStyleOptions } from "@tooark/core";
|
|
2
|
-
import
|
|
2
|
+
import { ArkAvatar as ArkAvatarElement } from "@tooark/web-components";
|
|
3
3
|
import type React from "react";
|
|
4
4
|
import { type ArkDomProps } from "./dom-props.js";
|
|
5
5
|
export type ArkAvatarProps = ArkDomProps<ArkAvatarStyleOptions & {
|
package/dist/ark-avatar.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { ArkAvatar as ArkAvatarElement } from "@tooark/web-components";
|
|
1
2
|
import { createElement, forwardRef, useEffect } from "react";
|
|
2
3
|
import { domAttrs } from "./dom-props.js";
|
|
3
|
-
import {
|
|
4
|
+
import { ensureTooarkElementsRegistered } from "./register-elements.js";
|
|
4
5
|
export const ArkAvatar = forwardRef(function ArkAvatar(props, forwardedRef) {
|
|
5
6
|
const { className, ...rest } = props;
|
|
6
7
|
useEffect(() => {
|
|
7
|
-
|
|
8
|
+
ensureTooarkElementsRegistered(ArkAvatarElement);
|
|
8
9
|
}, []);
|
|
9
10
|
const attrs = {
|
|
10
11
|
...domAttrs(rest),
|
package/dist/ark-badge.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import type { ArkBadgeStyleOptions } from "@tooark/core";
|
|
2
|
-
import
|
|
2
|
+
import { ArkBadge as ArkBadgeElement } from "@tooark/web-components";
|
|
3
3
|
import React, { type PropsWithChildren } from "react";
|
|
4
4
|
import { type ArkDomProps } from "./dom-props.js";
|
|
5
5
|
export type ArkBadgeProps = PropsWithChildren<ArkDomProps<ArkBadgeStyleOptions & {
|
|
6
6
|
className?: string;
|
|
7
|
+
/** Clique no botão de remover (com `removable`): tire o badge do estado do app. */
|
|
8
|
+
onRemove?: (event: CustomEvent) => void;
|
|
7
9
|
}>>;
|
|
8
10
|
export declare const ArkBadge: React.ForwardRefExoticComponent<ArkBadgeStyleOptions & {
|
|
9
11
|
className?: string;
|
|
10
|
-
|
|
12
|
+
/** Clique no botão de remover (com `removable`): tire o badge do estado do app. */
|
|
13
|
+
onRemove?: (event: CustomEvent) => void;
|
|
14
|
+
} & Omit<React.HTMLAttributes<HTMLElement>, "children" | "className" | keyof ArkBadgeStyleOptions | "onRemove"> & {
|
|
11
15
|
children?: React.ReactNode | undefined;
|
|
12
16
|
} & React.RefAttributes<ArkBadgeElement>>;
|
package/dist/ark-badge.js
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
|
+
import { ArkBadge as ArkBadgeElement } from "@tooark/web-components";
|
|
1
2
|
import { createElement, forwardRef, useEffect } from "react";
|
|
2
3
|
import { domAttrs } from "./dom-props.js";
|
|
3
|
-
import {
|
|
4
|
+
import { ensureTooarkElementsRegistered } from "./register-elements.js";
|
|
5
|
+
import { textChild } from "./text-child.js";
|
|
6
|
+
import { useForwardedRef } from "./use-forwarded-ref.js";
|
|
4
7
|
export const ArkBadge = forwardRef(function ArkBadge(props, forwardedRef) {
|
|
5
|
-
const { children, className, ...rest } = props;
|
|
8
|
+
const { children, className, removable, localeJson, onRemove, ...rest } = props;
|
|
9
|
+
const [ref, setRef] = useForwardedRef(forwardedRef);
|
|
6
10
|
useEffect(() => {
|
|
7
|
-
|
|
11
|
+
ensureTooarkElementsRegistered(ArkBadgeElement);
|
|
8
12
|
}, []);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const el = ref.current;
|
|
15
|
+
if (!el || !onRemove)
|
|
16
|
+
return;
|
|
17
|
+
const handleRemove = (event) => {
|
|
18
|
+
if (event.target === event.currentTarget)
|
|
19
|
+
onRemove(event);
|
|
20
|
+
};
|
|
21
|
+
el.addEventListener("ark-remove", handleRemove);
|
|
22
|
+
return () => el.removeEventListener("ark-remove", handleRemove);
|
|
23
|
+
}, [ref, onRemove]);
|
|
9
24
|
const attrs = {
|
|
10
25
|
...domAttrs(rest),
|
|
11
|
-
ref:
|
|
12
|
-
class: className
|
|
26
|
+
ref: setRef,
|
|
27
|
+
class: className,
|
|
28
|
+
removable: removable ? "" : undefined,
|
|
29
|
+
"locale-json": localeJson
|
|
13
30
|
};
|
|
14
|
-
return createElement("ark-badge", attrs, children);
|
|
31
|
+
return createElement("ark-badge", attrs, textChild(children));
|
|
15
32
|
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ArkBreadcrumbItemStyleOptions, ArkBreadcrumbNavigateDetail, ArkBreadcrumbStyleOptions } from "@tooark/core";
|
|
2
|
+
import { ArkBreadcrumb as ArkBreadcrumbElement, ArkBreadcrumbItem as ArkBreadcrumbItemElement } from "@tooark/web-components";
|
|
3
|
+
import React, { type PropsWithChildren } from "react";
|
|
4
|
+
import { type ArkDomProps } from "./dom-props.js";
|
|
5
|
+
export type ArkBreadcrumbProps = PropsWithChildren<ArkDomProps<ArkBreadcrumbStyleOptions & {
|
|
6
|
+
/** Nome do landmark (vira `aria-label`). Padrão: a string do idioma. */
|
|
7
|
+
label?: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
/** Clique simples num link deste breadcrumb, cancelável: `preventDefault()` e roteie pelo app. */
|
|
10
|
+
onNavigate?: (event: CustomEvent<ArkBreadcrumbNavigateDetail>) => void;
|
|
11
|
+
}>>;
|
|
12
|
+
export declare const ArkBreadcrumb: React.ForwardRefExoticComponent<ArkBreadcrumbStyleOptions & {
|
|
13
|
+
/** Nome do landmark (vira `aria-label`). Padrão: a string do idioma. */
|
|
14
|
+
label?: string;
|
|
15
|
+
className?: string;
|
|
16
|
+
/** Clique simples num link deste breadcrumb, cancelável: `preventDefault()` e roteie pelo app. */
|
|
17
|
+
onNavigate?: (event: CustomEvent<ArkBreadcrumbNavigateDetail>) => void;
|
|
18
|
+
} & Omit<React.HTMLAttributes<HTMLElement>, "children" | "className" | "label" | keyof ArkBreadcrumbStyleOptions | "onNavigate"> & {
|
|
19
|
+
children?: React.ReactNode | undefined;
|
|
20
|
+
} & React.RefAttributes<ArkBreadcrumbElement>>;
|
|
21
|
+
export type ArkBreadcrumbItemProps = PropsWithChildren<ArkDomProps<ArkBreadcrumbItemStyleOptions & {
|
|
22
|
+
/** Destino do link; sem ele o item é só texto. */
|
|
23
|
+
href?: string;
|
|
24
|
+
target?: string;
|
|
25
|
+
/** Página atual (sem link, `aria-current="page"`). Padrão: a última do breadcrumb. */
|
|
26
|
+
current?: boolean;
|
|
27
|
+
className?: string;
|
|
28
|
+
}>>;
|
|
29
|
+
export declare const ArkBreadcrumbItem: React.ForwardRefExoticComponent<ArkBreadcrumbItemStyleOptions & {
|
|
30
|
+
/** Destino do link; sem ele o item é só texto. */
|
|
31
|
+
href?: string;
|
|
32
|
+
target?: string;
|
|
33
|
+
/** Página atual (sem link, `aria-current="page"`). Padrão: a última do breadcrumb. */
|
|
34
|
+
current?: boolean;
|
|
35
|
+
className?: string;
|
|
36
|
+
} & Omit<React.HTMLAttributes<HTMLElement>, "children" | "className" | keyof ArkBreadcrumbItemStyleOptions | "href" | "target" | "current"> & {
|
|
37
|
+
children?: React.ReactNode | undefined;
|
|
38
|
+
} & React.RefAttributes<ArkBreadcrumbItemElement>>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ArkBreadcrumb as ArkBreadcrumbElement, ArkBreadcrumbItem as ArkBreadcrumbItemElement } from "@tooark/web-components";
|
|
2
|
+
import { createElement, forwardRef, useEffect } from "react";
|
|
3
|
+
import { domAttrs } from "./dom-props.js";
|
|
4
|
+
import { ensureTooarkElementsRegistered } from "./register-elements.js";
|
|
5
|
+
import { textChild } from "./text-child.js";
|
|
6
|
+
import { useForwardedRef } from "./use-forwarded-ref.js";
|
|
7
|
+
import { useIsomorphicLayoutEffect } from "./use-isomorphic-layout-effect.js";
|
|
8
|
+
export const ArkBreadcrumb = forwardRef(function ArkBreadcrumb(props, forwardedRef) {
|
|
9
|
+
const { children, className, localeJson, onNavigate, ...rest } = props;
|
|
10
|
+
const [ref, setRef] = useForwardedRef(forwardedRef);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
ensureTooarkElementsRegistered(ArkBreadcrumbElement);
|
|
13
|
+
}, []);
|
|
14
|
+
useIsomorphicLayoutEffect(() => {
|
|
15
|
+
const el = ref.current;
|
|
16
|
+
if (!el)
|
|
17
|
+
return;
|
|
18
|
+
// Só os itens deste breadcrumb: o ark-navigate borbulha e vem também de ark-button e ark-nav-item.
|
|
19
|
+
const handleNavigate = (event) => {
|
|
20
|
+
const item = event.target;
|
|
21
|
+
if (item.localName === "ark-breadcrumb-item" && item.closest("ark-breadcrumb") === event.currentTarget) {
|
|
22
|
+
onNavigate?.(event);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
el.addEventListener("ark-navigate", handleNavigate);
|
|
26
|
+
return () => el.removeEventListener("ark-navigate", handleNavigate);
|
|
27
|
+
}, [ref, onNavigate]);
|
|
28
|
+
const attrs = {
|
|
29
|
+
...domAttrs(rest),
|
|
30
|
+
ref: setRef,
|
|
31
|
+
class: className,
|
|
32
|
+
"locale-json": localeJson
|
|
33
|
+
};
|
|
34
|
+
return createElement("ark-breadcrumb", attrs, textChild(children));
|
|
35
|
+
});
|
|
36
|
+
export const ArkBreadcrumbItem = forwardRef(function ArkBreadcrumbItem(props, forwardedRef) {
|
|
37
|
+
const { children, className, current, ...rest } = props;
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
ensureTooarkElementsRegistered(ArkBreadcrumbItemElement);
|
|
40
|
+
}, []);
|
|
41
|
+
const attrs = {
|
|
42
|
+
...domAttrs(rest),
|
|
43
|
+
ref: forwardedRef,
|
|
44
|
+
class: className,
|
|
45
|
+
current: current ? "" : undefined
|
|
46
|
+
};
|
|
47
|
+
return createElement("ark-breadcrumb-item", attrs, textChild(children));
|
|
48
|
+
});
|
package/dist/ark-button.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ArkButtonGroupStyleOptions, ArkButtonNavigateDetail, ArkButtonStyleOptions, ArkButtonType } from "@tooark/core";
|
|
2
|
-
import
|
|
2
|
+
import { ArkButton as ArkButtonElement, ArkButtonGroup as ArkButtonGroupElement } from "@tooark/web-components";
|
|
3
3
|
import type React from "react";
|
|
4
4
|
import { type PropsWithChildren } from "react";
|
|
5
5
|
import { type ArkDomProps } from "./dom-props.js";
|
|
@@ -7,6 +7,8 @@ import { type ArkDomProps } from "./dom-props.js";
|
|
|
7
7
|
export type ArkButtonProps = PropsWithChildren<ArkDomProps<ArkButtonStyleOptions & {
|
|
8
8
|
type?: ArkButtonType;
|
|
9
9
|
disabled?: boolean;
|
|
10
|
+
/** Desabilitado só para a ação: continua no Tab e sob o ponteiro, para um tooltip dizer o motivo. */
|
|
11
|
+
softDisabled?: boolean;
|
|
10
12
|
/** Id do formulário a que o botão pertence quando fica fora dele, como no `<button form>` nativo. */
|
|
11
13
|
form?: string;
|
|
12
14
|
/** Clique simples no link (`href`), cancelável: `event.preventDefault()` e o roteamento da SPA. */
|
|
@@ -15,11 +17,13 @@ export type ArkButtonProps = PropsWithChildren<ArkDomProps<ArkButtonStyleOptions
|
|
|
15
17
|
export declare const ArkButton: React.ForwardRefExoticComponent<ArkButtonStyleOptions & {
|
|
16
18
|
type?: ArkButtonType;
|
|
17
19
|
disabled?: boolean;
|
|
20
|
+
/** Desabilitado só para a ação: continua no Tab e sob o ponteiro, para um tooltip dizer o motivo. */
|
|
21
|
+
softDisabled?: boolean;
|
|
18
22
|
/** Id do formulário a que o botão pertence quando fica fora dele, como no `<button form>` nativo. */
|
|
19
23
|
form?: string;
|
|
20
24
|
/** Clique simples no link (`href`), cancelável: `event.preventDefault()` e o roteamento da SPA. */
|
|
21
25
|
onNavigate?: (event: CustomEvent<ArkButtonNavigateDetail>) => void;
|
|
22
|
-
} & Omit<React.HTMLAttributes<HTMLElement>, "children" | "form" | keyof ArkButtonStyleOptions | "type" | "
|
|
26
|
+
} & Omit<React.HTMLAttributes<HTMLElement>, "children" | "disabled" | "form" | "onNavigate" | keyof ArkButtonStyleOptions | "type" | "softDisabled"> & {
|
|
23
27
|
children?: React.ReactNode | undefined;
|
|
24
28
|
} & React.RefAttributes<ArkButtonElement>>;
|
|
25
29
|
/** Props do ArkButtonGroup: variant, intent, size, rounded e theme valem para todos os botões do grupo. */
|
|
@@ -36,6 +40,6 @@ export declare const ArkButtonGroup: React.ForwardRefExoticComponent<ArkButtonGr
|
|
|
36
40
|
/** Nome do grupo (vira `aria-label`). */
|
|
37
41
|
label?: string;
|
|
38
42
|
className?: string;
|
|
39
|
-
} & Omit<React.HTMLAttributes<HTMLElement>, "children" | "className" | "
|
|
43
|
+
} & Omit<React.HTMLAttributes<HTMLElement>, "children" | "className" | "disabled" | "label" | keyof ArkButtonGroupStyleOptions> & {
|
|
40
44
|
children?: React.ReactNode | undefined;
|
|
41
45
|
} & React.RefAttributes<ArkButtonGroupElement>>;
|
package/dist/ark-button.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { ArkButton as ArkButtonElement, ArkButtonGroup as ArkButtonGroupElement } from "@tooark/web-components";
|
|
1
2
|
import { createElement, forwardRef, useEffect } from "react";
|
|
2
3
|
import { domAttrs } from "./dom-props.js";
|
|
3
|
-
import {
|
|
4
|
+
import { ensureTooarkElementsRegistered } from "./register-elements.js";
|
|
5
|
+
import { textChild } from "./text-child.js";
|
|
4
6
|
import { useForwardedRef } from "./use-forwarded-ref.js";
|
|
5
7
|
export const ArkButton = forwardRef(function ArkButton(props, forwardedRef) {
|
|
6
|
-
const { children, className, textColor, loading, statusLabel, iconOnly, fullWidth, disabled, download, onNavigate, ...rest } = props;
|
|
8
|
+
const { children, className, textColor, loading, statusLabel, iconOnly, fullWidth, disabled, softDisabled, download, onNavigate, ...rest } = props;
|
|
7
9
|
useEffect(() => {
|
|
8
|
-
|
|
10
|
+
ensureTooarkElementsRegistered(ArkButtonElement);
|
|
9
11
|
}, []);
|
|
10
12
|
const [ref, setRef] = useForwardedRef(forwardedRef);
|
|
11
13
|
useEffect(() => {
|
|
@@ -24,18 +26,19 @@ export const ArkButton = forwardRef(function ArkButton(props, forwardedRef) {
|
|
|
24
26
|
class: className,
|
|
25
27
|
"text-color": textColor,
|
|
26
28
|
disabled: disabled ? "" : undefined,
|
|
29
|
+
"soft-disabled": softDisabled ? "" : undefined,
|
|
27
30
|
loading: loading ? "" : undefined,
|
|
28
31
|
"status-label": statusLabel,
|
|
29
32
|
"icon-only": iconOnly ? "" : undefined,
|
|
30
33
|
"full-width": fullWidth ? "" : undefined,
|
|
31
34
|
download: download === true ? "" : download || undefined
|
|
32
35
|
};
|
|
33
|
-
return createElement("ark-button", attrs, children);
|
|
36
|
+
return createElement("ark-button", attrs, textChild(children));
|
|
34
37
|
});
|
|
35
38
|
export const ArkButtonGroup = forwardRef(function ArkButtonGroup(props, forwardedRef) {
|
|
36
39
|
const { children, className, spaced, fullWidth, disabled, ...rest } = props;
|
|
37
40
|
useEffect(() => {
|
|
38
|
-
|
|
41
|
+
ensureTooarkElementsRegistered(ArkButtonGroupElement);
|
|
39
42
|
}, []);
|
|
40
43
|
const attrs = {
|
|
41
44
|
...domAttrs(rest),
|
|
@@ -45,5 +48,5 @@ export const ArkButtonGroup = forwardRef(function ArkButtonGroup(props, forwarde
|
|
|
45
48
|
"full-width": fullWidth ? "" : undefined,
|
|
46
49
|
disabled: disabled ? "" : undefined
|
|
47
50
|
};
|
|
48
|
-
return createElement("ark-button-group", attrs, children);
|
|
51
|
+
return createElement("ark-button-group", attrs, textChild(children));
|
|
49
52
|
});
|