@majapisoftwares/ui 6.2.2 → 6.3.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/docs/STANDARDS.md
CHANGED
|
@@ -16,10 +16,14 @@ Primitivos shadcn ficam em src/components/ui (Button, Badge, Card, Input, Table,
|
|
|
16
16
|
|
|
17
17
|
## Comportamentos de UX
|
|
18
18
|
|
|
19
|
+
DataTable mantém os resets de paginação fora da avaliação de row models durante render. Mudanças de dados aplicam o reset após commit; filtros e ordenação preservam os handlers oficiais, e paginação manual permanece controlada pelo consumidor. Não adicione resets assíncronos durante render para contornar Suspense/StrictMode. `npm run test:data-table` verifica montagem concorrente, avanço de página e substituição dos dados.
|
|
20
|
+
|
|
19
21
|
- Ação primária destaca o objetivo; secundária usa outline/secondary; destrutiva usa variante própria e depende das autorizações do app.
|
|
20
22
|
- Busca, filtros, ordenação por coluna e paginação seguem DataTable (TanStack Table; origem: tabela da Numa). Filtros por coluna usam `meta.filter`; preferências do usuário persistem por `storageKey`. Telas centradas em uma tabela usam `AppShell fillHeight` + `DataTable fillHeight`: a tabela ocupa a altura restante e rola internamente, com cabeçalho, busca e paginação sempre visíveis.
|
|
21
23
|
- Áreas com rolagem interna usam `scroll-fade` do shadcn (só `scroll-fade-b` quando há cabeçalho fixo dentro do contêiner) e as barras de rolagem finas globais, que aparecem com o ponteiro sobre a área e seguem o tema (`color-scheme`).
|
|
22
24
|
- Espaçamento da página em uma escala só: padding, gap entre seções e entre cards de 16px no mobile e 24px a partir de md; o cabeçalho da página e o da sidebar têm a mesma altura (56px). Filtros de domínio são slots tipados do app. Não reconstruir tabelas por tela. Persistência não é habilitada por padrão para evitar guardar buscas sensíveis; quando necessária, deve evoluir como capacidade compartilhada com controle explícito.
|
|
25
|
+
- Não repetir o que já está na tela: o breadcrumb nomeia a página, então ela não ganha um título `PageHeader` com o mesmo nome. Na sidebar, o grupo abre a página principal da ferramenta, que não aparece de novo como subitem. O mesmo vale para títulos de diálogo, rótulos e descrições que repetem um texto visível.
|
|
26
|
+
- Rótulos curtos, em uma linha: botões, itens de menu, abas e badges não quebram linha. Menus se ajustam à largura do conteúdo (não à do botão que os abre); se o texto não couber, encurte-o.
|
|
23
27
|
- Estados com texto e cor: sucesso, aviso, erro e desconhecido. Nunca traduzir ausência de informação em zero ou sucesso.
|
|
24
28
|
- Carregamento usa Skeleton, vazio usa Empty, falhas usam Alert e detalhes usam DetailsSheet com título, descrição, foco preso ao overlay, Escape e devolução do foco ao fechar.
|
|
25
29
|
- Em telas pequenas, controles têm texto de pelo menos 16px e alvo de 44px, navegação se reorganiza e tabelas têm rolagem interna, sem rolagem horizontal da página.
|
|
@@ -41,3 +45,7 @@ AGENTS.md nos apps exige contribuição upstream antes de uso. O verificador est
|
|
|
41
45
|
- Field usa imports relativos. Button assume type=button para evitar submissões acidentais; formulários declaram type=submit. Badge inclui variantes success e warning reutilizadas por StatusBadge.
|
|
42
46
|
- Tokens de identidade, estados semânticos e padrões compostos são mantidos aqui.
|
|
43
47
|
- Mudanças posteriores no upstream devem ser avaliadas com o diff do CLI, preservando estas decisões e o contrato público.
|
|
48
|
+
|
|
49
|
+
## Contextual tool navigation
|
|
50
|
+
|
|
51
|
+
AppShell navigation items accept optional `children` for one level of related tool views. Only the active tool expands. The current destination alone receives aria-current. Navigation closes the mobile sidebar after selection. Sidebar subitems have 44px touch targets on mobile. Use route navigation here; reserve FilterTabs for filters or views of the current dataset. Use `fillHeight` for contained table/chat pages and ordinary page flow for long forms and card collections.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@majapisoftwares/ui",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.3.0",
|
|
4
4
|
"description": "Shared Majapi UI and UX standards based on shadcn/ui",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
"format:check": "prettier --check src examples scripts *.json *.ts *.md docs/*.md",
|
|
42
42
|
"check:standards": "node scripts/check-standards.mjs",
|
|
43
43
|
"normalize:ui": "node scripts/normalize-ui.mjs && prettier --write src/components/ui src/hooks",
|
|
44
|
-
"test:preferences": "tsx --test scripts/preferences.test.tsx"
|
|
44
|
+
"test:preferences": "tsx --test scripts/preferences.test.tsx",
|
|
45
|
+
"test:data-table": "tsx --test scripts/data-table.test.tsx"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
48
|
"react": "19.3.1",
|
|
@@ -41,7 +41,7 @@ function DropdownMenuContent({
|
|
|
41
41
|
<MenuPrimitive.Popup
|
|
42
42
|
data-slot="dropdown-menu-content"
|
|
43
43
|
className={cn(
|
|
44
|
-
"z-50 max-h-(--available-height) w-(--
|
|
44
|
+
"z-50 max-h-(--available-height) w-max max-w-(--available-width) min-w-[max(12rem,var(--anchor-width))] origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-3xl bg-popover p-1.5 text-popover-foreground shadow-lg ring-1 ring-foreground/5 duration-100 outline-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:ring-foreground/10 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:overflow-hidden data-closed:fade-out-0 data-closed:zoom-out-95",
|
|
45
45
|
className,
|
|
46
46
|
)}
|
|
47
47
|
{...props}
|
|
@@ -88,7 +88,11 @@ const subscribeNoop = () => () => {};
|
|
|
88
88
|
|
|
89
89
|
function SidebarRestoreScript() {
|
|
90
90
|
// Only SSR and hydration emit the script; React warns about client-created scripts, which never run.
|
|
91
|
-
const hydrating = React.useSyncExternalStore(
|
|
91
|
+
const hydrating = React.useSyncExternalStore(
|
|
92
|
+
subscribeNoop,
|
|
93
|
+
() => false,
|
|
94
|
+
() => true,
|
|
95
|
+
);
|
|
92
96
|
const script = `(function(){try{var m=document.cookie.match(/(?:^|; )${SIDEBAR_COOKIE_NAME}=([^;]*)/);if(!m)return;var p=m[1].split(":"),mode=p[0],w=Number(p[1]),wrap=document.currentScript.parentElement;if(w)wrap.setAttribute("style",(wrap.getAttribute("style")||"").replace(/--sidebar-width:[^;]*/,"--sidebar-width:"+Math.round(Math.min(${SIDEBAR_WIDTH_MAX},Math.max(${SIDEBAR_WIDTH_MIN},w)))+"px"));var sb=wrap.querySelector('[data-slot="sidebar"]');var r=wrap.querySelector('[data-slot="sidebar-rail"]');if(r)r.setAttribute("aria-valuenow",String(mode==="compact"?48:mode==="closed"?0:Math.round(Math.min(${SIDEBAR_WIDTH_MAX},Math.max(${SIDEBAR_WIDTH_MIN},w||${SIDEBAR_WIDTH})))));if(sb&&(mode==="compact"||mode==="closed")){sb.setAttribute("data-state","collapsed");sb.setAttribute("data-collapsible",mode==="closed"?"offcanvas":"icon")}}catch(e){}})()`;
|
|
93
97
|
if (!hydrating) return null;
|
|
94
98
|
return (
|
|
@@ -799,7 +803,7 @@ const sidebarMenuButtonVariants = cva(
|
|
|
799
803
|
"bg-background shadow-[0_0_0_1px_var(--sidebar-border)] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_var(--sidebar-accent)]",
|
|
800
804
|
},
|
|
801
805
|
size: {
|
|
802
|
-
default: "h-9 text-sm",
|
|
806
|
+
default: "h-11 text-base md:h-9 md:text-sm",
|
|
803
807
|
sm: "h-8 text-xs",
|
|
804
808
|
// Compact identity marks fill the button and cover its hover background.
|
|
805
809
|
// Paint feedback above the mark so images and opaque avatars respond too.
|
|
@@ -998,7 +1002,7 @@ function SidebarMenuSubButton({
|
|
|
998
1002
|
props: mergeProps<"a">(
|
|
999
1003
|
{
|
|
1000
1004
|
className: cn(
|
|
1001
|
-
"flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-xl px-3 text-sidebar-foreground ring-sidebar-ring outline-hidden group-data-[collapsible=icon]:hidden hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[size=md]:text-sm data-[size=sm]:text-xs data-active:bg-sidebar-accent data-active:text-sidebar-accent-foreground [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground",
|
|
1005
|
+
"flex h-11 md:h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-xl px-3 text-sidebar-foreground ring-sidebar-ring outline-hidden group-data-[collapsible=icon]:hidden hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[size=md]:text-sm data-[size=sm]:text-xs data-active:bg-sidebar-accent data-active:text-sidebar-accent-foreground [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground",
|
|
1002
1006
|
className,
|
|
1003
1007
|
),
|
|
1004
1008
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import type { ReactNode } from "react";
|
|
3
|
+
import type { MouseEvent, ReactNode } from "react";
|
|
4
4
|
import { cn } from "cn";
|
|
5
5
|
import {
|
|
6
6
|
Sidebar,
|
|
@@ -14,6 +14,10 @@ import {
|
|
|
14
14
|
SidebarMenuBadge,
|
|
15
15
|
SidebarMenuButton,
|
|
16
16
|
SidebarMenuItem,
|
|
17
|
+
SidebarMenuSub,
|
|
18
|
+
SidebarMenuSubItem,
|
|
19
|
+
SidebarMenuSubButton,
|
|
20
|
+
useSidebar,
|
|
17
21
|
SidebarProvider,
|
|
18
22
|
SidebarRail,
|
|
19
23
|
SidebarTrigger,
|
|
@@ -27,6 +31,10 @@ export interface NavigationItem {
|
|
|
27
31
|
label: string;
|
|
28
32
|
icon?: ReactNode;
|
|
29
33
|
count?: number;
|
|
34
|
+
/** Native destination; preserves open-in-new-tab and modified clicks. */
|
|
35
|
+
href?: string;
|
|
36
|
+
/** Related views shown under the active tool. One level of contextual navigation. */
|
|
37
|
+
children?: (Omit<NavigationItem, "children"> & { href: string })[];
|
|
30
38
|
}
|
|
31
39
|
export interface NavigationGroup {
|
|
32
40
|
label?: string;
|
|
@@ -88,6 +96,78 @@ function HeaderTrigger() {
|
|
|
88
96
|
);
|
|
89
97
|
}
|
|
90
98
|
|
|
99
|
+
function ShellNavigation({
|
|
100
|
+
navigation,
|
|
101
|
+
activeId,
|
|
102
|
+
onNavigate,
|
|
103
|
+
}: Pick<AppShellProps, "navigation" | "activeId" | "onNavigate">) {
|
|
104
|
+
const { isMobile, setOpenMobile } = useSidebar();
|
|
105
|
+
const navigate = (id: string, event: MouseEvent<HTMLElement>) => {
|
|
106
|
+
if (
|
|
107
|
+
event.button !== 0 ||
|
|
108
|
+
event.metaKey ||
|
|
109
|
+
event.ctrlKey ||
|
|
110
|
+
event.shiftKey ||
|
|
111
|
+
event.altKey
|
|
112
|
+
)
|
|
113
|
+
return;
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
onNavigate(id);
|
|
116
|
+
if (isMobile) setOpenMobile(false);
|
|
117
|
+
};
|
|
118
|
+
return navigation.map((group, index) => (
|
|
119
|
+
<SidebarGroup key={group.label ?? index}>
|
|
120
|
+
{group.label ? (
|
|
121
|
+
<SidebarGroupLabel>{group.label}</SidebarGroupLabel>
|
|
122
|
+
) : null}
|
|
123
|
+
<SidebarMenu>
|
|
124
|
+
{group.items.map((item) => {
|
|
125
|
+
const active =
|
|
126
|
+
item.id === activeId ||
|
|
127
|
+
Boolean(item.children?.some((child) => child.id === activeId));
|
|
128
|
+
return (
|
|
129
|
+
<SidebarMenuItem key={item.id}>
|
|
130
|
+
<div className="relative">
|
|
131
|
+
<SidebarMenuButton
|
|
132
|
+
isActive={active}
|
|
133
|
+
tooltip={item.label}
|
|
134
|
+
aria-current={item.id === activeId ? "page" : undefined}
|
|
135
|
+
render={item.href ? <a href={item.href} /> : undefined}
|
|
136
|
+
onClick={(event) => navigate(item.id, event)}
|
|
137
|
+
>
|
|
138
|
+
<ItemIcon item={item} />
|
|
139
|
+
<span>{item.label}</span>
|
|
140
|
+
</SidebarMenuButton>
|
|
141
|
+
{item.count !== undefined ? (
|
|
142
|
+
<SidebarMenuBadge>{item.count}</SidebarMenuBadge>
|
|
143
|
+
) : null}
|
|
144
|
+
</div>
|
|
145
|
+
{active && item.children?.length ? (
|
|
146
|
+
<SidebarMenuSub aria-label={item.label}>
|
|
147
|
+
{item.children.map((child) => (
|
|
148
|
+
<SidebarMenuSubItem key={child.id}>
|
|
149
|
+
<SidebarMenuSubButton
|
|
150
|
+
href={child.href}
|
|
151
|
+
isActive={child.id === activeId}
|
|
152
|
+
aria-current={
|
|
153
|
+
child.id === activeId ? "page" : undefined
|
|
154
|
+
}
|
|
155
|
+
onClick={(event) => navigate(child.id, event)}
|
|
156
|
+
>
|
|
157
|
+
<span>{child.label}</span>
|
|
158
|
+
</SidebarMenuSubButton>
|
|
159
|
+
</SidebarMenuSubItem>
|
|
160
|
+
))}
|
|
161
|
+
</SidebarMenuSub>
|
|
162
|
+
) : null}
|
|
163
|
+
</SidebarMenuItem>
|
|
164
|
+
);
|
|
165
|
+
})}
|
|
166
|
+
</SidebarMenu>
|
|
167
|
+
</SidebarGroup>
|
|
168
|
+
));
|
|
169
|
+
}
|
|
170
|
+
|
|
91
171
|
export function AppShell({
|
|
92
172
|
logo,
|
|
93
173
|
name,
|
|
@@ -125,31 +205,11 @@ export function AppShell({
|
|
|
125
205
|
<div className="p-2 pt-0">{sidebarHeader}</div>
|
|
126
206
|
) : null}
|
|
127
207
|
<SidebarContent>
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
<SidebarMenu>
|
|
134
|
-
{group.items.map((item) => (
|
|
135
|
-
<SidebarMenuItem key={item.id}>
|
|
136
|
-
<SidebarMenuButton
|
|
137
|
-
isActive={item.id === activeId}
|
|
138
|
-
tooltip={item.label}
|
|
139
|
-
aria-current={item.id === activeId ? "page" : undefined}
|
|
140
|
-
onClick={() => onNavigate(item.id)}
|
|
141
|
-
>
|
|
142
|
-
<ItemIcon item={item} />
|
|
143
|
-
<span>{item.label}</span>
|
|
144
|
-
</SidebarMenuButton>
|
|
145
|
-
{item.count !== undefined ? (
|
|
146
|
-
<SidebarMenuBadge>{item.count}</SidebarMenuBadge>
|
|
147
|
-
) : null}
|
|
148
|
-
</SidebarMenuItem>
|
|
149
|
-
))}
|
|
150
|
-
</SidebarMenu>
|
|
151
|
-
</SidebarGroup>
|
|
152
|
-
))}
|
|
208
|
+
<ShellNavigation
|
|
209
|
+
navigation={navigation}
|
|
210
|
+
activeId={activeId}
|
|
211
|
+
onNavigate={onNavigate}
|
|
212
|
+
/>
|
|
153
213
|
</SidebarContent>
|
|
154
214
|
{footer ? <SidebarFooter>{footer}</SidebarFooter> : null}
|
|
155
215
|
<SidebarRail />
|
|
@@ -1287,7 +1287,9 @@ export function DataTable<TData extends RowData>(props: DataTableProps<TData>) {
|
|
|
1287
1287
|
]);
|
|
1288
1288
|
|
|
1289
1289
|
const table = useDataTableInstance<TData>({
|
|
1290
|
-
|
|
1290
|
+
// TanStack schedules auto resets while evaluating row models during render.
|
|
1291
|
+
// Concurrent/Suspense renders may not have committed yet, so reset in an effect.
|
|
1292
|
+
autoResetPageIndex: false,
|
|
1291
1293
|
columnResizeMode: "onChange",
|
|
1292
1294
|
columns,
|
|
1293
1295
|
data,
|
|
@@ -1333,6 +1335,10 @@ export function DataTable<TData extends RowData>(props: DataTableProps<TData>) {
|
|
|
1333
1335
|
},
|
|
1334
1336
|
});
|
|
1335
1337
|
|
|
1338
|
+
React.useEffect(() => {
|
|
1339
|
+
if (!manualPagination) resetPaginationPage();
|
|
1340
|
+
}, [data, manualPagination, resetPaginationPage]);
|
|
1341
|
+
|
|
1336
1342
|
const handleDragEnd = (event: DragEndEvent) => {
|
|
1337
1343
|
const { active, over } = event;
|
|
1338
1344
|
|