@tc96/cli 0.0.0-stage → 0.28.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/LICENSE +21 -0
- package/README.md +213 -2
- package/cli.js +1450 -0
- package/package.json +35 -4
- package/registry/agenda-1.json +1297 -0
- package/registry/aggregate.json +4 -0
- package/registry/ai-chat-1.json +91 -0
- package/registry/app-shell-1.json +81 -0
- package/registry/app-shell-2.json +89 -0
- package/registry/app-shell-3.json +109 -0
- package/registry/app-shell-4.json +104 -0
- package/registry/card-1.json +104 -0
- package/registry/card-2.json +97 -0
- package/registry/card-3.json +104 -0
- package/registry/card-4.json +98 -0
- package/registry/card-5.json +85 -0
- package/registry/card-6.json +98 -0
- package/registry/card-7.json +104 -0
- package/registry/card-8.json +106 -0
- package/registry/card-9.json +92 -0
- package/registry/charts.json +30 -0
- package/registry/chat-assistant.json +110 -0
- package/registry/chats-panel.json +97 -0
- package/registry/checklist.json +321 -0
- package/registry/collection.json +1104 -0
- package/registry/crm-1.json +1317 -0
- package/registry/crm-2.json +1400 -0
- package/registry/dashboard-1.json +160 -0
- package/registry/dashboard-2.json +153 -0
- package/registry/dashboard-3.json +154 -0
- package/registry/dashboard-4.json +168 -0
- package/registry/dashboard-5.json +167 -0
- package/registry/dashboard-6.json +143 -0
- package/registry/dashboard-7.json +188 -0
- package/registry/documents-1.json +1322 -0
- package/registry/editable.json +36 -0
- package/registry/empty-state-1.json +40 -0
- package/registry/empty-state-2.json +39 -0
- package/registry/empty-state-3.json +61 -0
- package/registry/empty-state-4.json +39 -0
- package/registry/empty-state-5.json +47 -0
- package/registry/empty-state-6.json +40 -0
- package/registry/finance-1.json +845 -0
- package/registry/finance-2.json +973 -0
- package/registry/finance-3.json +1436 -0
- package/registry/flow-1.json +460 -0
- package/registry/flow-2.json +503 -0
- package/registry/flow-3.json +198 -0
- package/registry/flow-4.json +75 -0
- package/registry/flow-canvas.json +198 -0
- package/registry/flow-inspector.json +151 -0
- package/registry/flow-step-library.json +112 -0
- package/registry/forgot-password-1.json +73 -0
- package/registry/forgot-password-2.json +73 -0
- package/registry/inbox-1.json +1184 -0
- package/registry/inventory-1.json +828 -0
- package/registry/inventory-2.json +956 -0
- package/registry/legal-1.json +1345 -0
- package/registry/legal-2.json +1279 -0
- package/registry/legal-3.json +1273 -0
- package/registry/legal-4.json +1273 -0
- package/registry/legal-5.json +1393 -0
- package/registry/legal-6.json +1309 -0
- package/registry/legal-7.json +1315 -0
- package/registry/legal-8.json +1358 -0
- package/registry/legal-9.json +1381 -0
- package/registry/list-1.json +129 -0
- package/registry/list-2.json +117 -0
- package/registry/list-3.json +129 -0
- package/registry/list-4.json +105 -0
- package/registry/list-5.json +98 -0
- package/registry/list-6.json +92 -0
- package/registry/list.json +52 -0
- package/registry/login-1.json +89 -0
- package/registry/login-10.json +88 -0
- package/registry/login-2.json +81 -0
- package/registry/login-3.json +90 -0
- package/registry/login-4.json +81 -0
- package/registry/login-5.json +82 -0
- package/registry/login-6.json +88 -0
- package/registry/login-7.json +83 -0
- package/registry/login-8.json +81 -0
- package/registry/login-9.json +88 -0
- package/registry/magic-link-6.json +79 -0
- package/registry/marketing-1.json +833 -0
- package/registry/marketing-2.json +961 -0
- package/registry/navbar-1.json +66 -0
- package/registry/navbar-10.json +50 -0
- package/registry/navbar-11.json +48 -0
- package/registry/navbar-12.json +48 -0
- package/registry/navbar-2.json +48 -0
- package/registry/navbar-3.json +50 -0
- package/registry/navbar-4.json +39 -0
- package/registry/navbar-5.json +50 -0
- package/registry/navbar-6.json +48 -0
- package/registry/navbar-7.json +72 -0
- package/registry/navbar-8.json +50 -0
- package/registry/navbar-9.json +54 -0
- package/registry/onboarding-1.json +114 -0
- package/registry/onboarding-2.json +78 -0
- package/registry/onboarding-3.json +71 -0
- package/registry/otp-1.json +73 -0
- package/registry/projects-1.json +865 -0
- package/registry/projects-2.json +993 -0
- package/registry/projects-3.json +1346 -0
- package/registry/properties.json +530 -0
- package/registry/record-dialog.json +88 -0
- package/registry/record-group.json +194 -0
- package/registry/record-preview.json +70 -0
- package/registry/record-status-list.json +70 -0
- package/registry/reset-password-1.json +92 -0
- package/registry/reset-password-2.json +98 -0
- package/registry/reset-password-6.json +91 -0
- package/registry/revenue-1.json +834 -0
- package/registry/revenue-2.json +968 -0
- package/registry/revenue-3.json +821 -0
- package/registry/revenue-4.json +949 -0
- package/registry/rich-text-editor-1.json +172 -0
- package/registry/rich-text-editor-2.json +158 -0
- package/registry/rich-text-editor-3.json +198 -0
- package/registry/rich-text-editor-4.json +200 -0
- package/registry/rich-text-editor-5.json +237 -0
- package/registry/rich-text-editor.json +113 -0
- package/registry/settings-account-1.json +119 -0
- package/registry/settings-account-2.json +118 -0
- package/registry/settings-catalog-1.json +128 -0
- package/registry/settings-catalog-10.json +129 -0
- package/registry/settings-catalog-2.json +116 -0
- package/registry/settings-catalog-3.json +118 -0
- package/registry/settings-catalog-4.json +227 -0
- package/registry/settings-catalog-5.json +129 -0
- package/registry/settings-catalog-6.json +130 -0
- package/registry/settings-catalog-7.json +130 -0
- package/registry/settings-catalog-8.json +183 -0
- package/registry/settings-catalog-9.json +159 -0
- package/registry/settings-integration-1.json +125 -0
- package/registry/settings-integration-2.json +122 -0
- package/registry/settings-integration-3.json +118 -0
- package/registry/settings-integration-4.json +129 -0
- package/registry/settings-integration-5.json +122 -0
- package/registry/settings-integration-6.json +92 -0
- package/registry/settings-integration-7.json +122 -0
- package/registry/settings-integration-8.json +593 -0
- package/registry/settings-notification-channel-1.json +112 -0
- package/registry/settings-preference-1.json +123 -0
- package/registry/settings-preference-2.json +123 -0
- package/registry/settings-preference-3.json +116 -0
- package/registry/settings-role-permission-1.json +117 -0
- package/registry/settings-security-1.json +117 -0
- package/registry/settings-workspace-1.json +119 -0
- package/registry/settings-workspace-2.json +125 -0
- package/registry/settings.json +82 -0
- package/registry/signup-1.json +100 -0
- package/registry/signup-2.json +93 -0
- package/registry/signup-3.json +83 -0
- package/registry/signup-6.json +99 -0
- package/registry/state-surface.json +58 -0
- package/registry/stats-1.json +116 -0
- package/registry/stats-2.json +115 -0
- package/registry/stats-3.json +97 -0
- package/registry/stats-4.json +92 -0
- package/registry/stats-5.json +103 -0
- package/registry/stats-6.json +105 -0
- package/registry/stats-7.json +103 -0
- package/registry/stats.json +64 -0
- package/registry/support-1.json +853 -0
- package/registry/support-2.json +981 -0
- package/registry/support-3.json +762 -0
- package/registry/support-4.json +538 -0
- package/registry/team-1.json +829 -0
- package/registry/team-2.json +957 -0
- package/registry/timeline-1.json +97 -0
- package/registry/timeline-2.json +102 -0
- package/registry/timeline-3.json +68 -0
- package/registry/timeline-4.json +86 -0
- package/registry/ui/accordion.json +15 -0
- package/registry/ui/alert-dialog.json +14 -0
- package/registry/ui/alert.json +50 -0
- package/registry/ui/autocomplete.json +18 -0
- package/registry/ui/avatar.json +14 -0
- package/registry/ui/badge.json +51 -0
- package/registry/ui/breadcrumb.json +15 -0
- package/registry/ui/button.json +25 -0
- package/registry/ui/calendar.json +15 -0
- package/registry/ui/card.json +14 -0
- package/registry/ui/chat.json +115 -0
- package/registry/ui/checkbox-group.json +14 -0
- package/registry/ui/checkbox.json +14 -0
- package/registry/ui/collapsible.json +14 -0
- package/registry/ui/combobox.json +18 -0
- package/registry/ui/command.json +17 -0
- package/registry/ui/composer-clipboard.json +14 -0
- package/registry/ui/composer-document.json +14 -0
- package/registry/ui/composer-editor.json +16 -0
- package/registry/ui/composer-query.json +12 -0
- package/registry/ui/composer.json +17 -0
- package/registry/ui/context-menu.json +23 -0
- package/registry/ui/dialog.json +18 -0
- package/registry/ui/drawer.json +18 -0
- package/registry/ui/empty.json +14 -0
- package/registry/ui/field.json +22 -0
- package/registry/ui/fieldset.json +14 -0
- package/registry/ui/form.json +14 -0
- package/registry/ui/frame.json +12 -0
- package/registry/ui/gauge.json +31 -0
- package/registry/ui/group.json +17 -0
- package/registry/ui/icon-frame.json +31 -0
- package/registry/ui/input-group.json +17 -0
- package/registry/ui/input.json +14 -0
- package/registry/ui/kbd.json +12 -0
- package/registry/ui/label.json +14 -0
- package/registry/ui/menu.json +39 -0
- package/registry/ui/meter.json +14 -0
- package/registry/ui/number-field.json +17 -0
- package/registry/ui/otp-field.json +31 -0
- package/registry/ui/pagination.json +17 -0
- package/registry/ui/popover.json +14 -0
- package/registry/ui/preview-card.json +14 -0
- package/registry/ui/progress.json +14 -0
- package/registry/ui/property-meta.json +16 -0
- package/registry/ui/property-tone.json +12 -0
- package/registry/ui/radio-group.json +14 -0
- package/registry/ui/render-anchor.json +12 -0
- package/registry/ui/scroll-area.json +14 -0
- package/registry/ui/segmented-control.json +14 -0
- package/registry/ui/select.json +16 -0
- package/registry/ui/separator.json +14 -0
- package/registry/ui/sheet.json +18 -0
- package/registry/ui/sidebar.json +25 -0
- package/registry/ui/skeleton.json +24 -0
- package/registry/ui/slider.json +14 -0
- package/registry/ui/spinner.json +14 -0
- package/registry/ui/switch.json +14 -0
- package/registry/ui/table.json +14 -0
- package/registry/ui/tabs.json +16 -0
- package/registry/ui/text.json +31 -0
- package/registry/ui/textarea.json +14 -0
- package/registry/ui/toast.json +89 -0
- package/registry/ui/toggle-group.json +18 -0
- package/registry/ui/toggle.json +15 -0
- package/registry/ui/toolbar.json +14 -0
- package/registry/ui/tooltip.json +14 -0
- package/registry/ui/use-composer-editor.json +17 -0
- package/registry/ui/use-copy-to-clipboard.json +12 -0
- package/registry/ui/use-media-query.json +12 -0
- package/registry/view.json +1104 -0
- package/registry/widgets.json +319 -0
- package/registry/wizard.json +89 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "stats-1",
|
|
3
|
+
"type": "registry:block",
|
|
4
|
+
"files": [
|
|
5
|
+
{
|
|
6
|
+
"path": "blocks/application/stats/shared/labels.ts",
|
|
7
|
+
"type": "registry:file",
|
|
8
|
+
"content": "import type { StatsLoadLabels } from './types'\n\nexport const defaultStatsLoadLabels: Pick<\n StatsLoadLabels,\n 'errorDescription' | 'retry'\n> = {\n errorDescription: 'Verifique sua conexão e tente novamente.',\n retry: 'Tentar novamente',\n}\n",
|
|
9
|
+
"target": "~/packages/ui/src/blocks/application/stats/shared/labels.ts"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "blocks/application/stats/shared/stats-card-actions.tsx",
|
|
13
|
+
"type": "registry:file",
|
|
14
|
+
"content": "import { DotsThreeIcon } from '@phosphor-icons/react'\nimport { Button } from '@tc96/ui/button'\nimport { Menu, MenuItem, MenuPopup, MenuTrigger } from '@tc96/ui/menu'\nimport type { StatsAction } from './types'\n\nexport interface StatsCardActionsProps {\n actions: StatsAction[]\n label: string\n onAction: (actionId: string) => void\n}\n\nexport function StatsCardActions({\n actions,\n label,\n onAction,\n}: Readonly<StatsCardActionsProps>) {\n if (actions.length === 0) return null\n\n return (\n <Menu>\n <MenuTrigger\n aria-label={label}\n render={<Button size=\"icon-sm\" variant=\"ghost\" />}\n >\n <DotsThreeIcon aria-hidden=\"true\" />\n </MenuTrigger>\n <MenuPopup align=\"end\">\n {actions.map((action) => (\n <MenuItem\n key={action.id}\n onClick={() => onAction(action.id)}\n variant={action.destructive ? 'destructive' : undefined}\n >\n {action.label}\n </MenuItem>\n ))}\n </MenuPopup>\n </Menu>\n )\n}\n",
|
|
15
|
+
"target": "~/packages/ui/src/blocks/application/stats/shared/stats-card-actions.tsx"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "blocks/application/stats/shared/stats-load-state.tsx",
|
|
19
|
+
"type": "registry:file",
|
|
20
|
+
"content": "import { Button } from '@tc96/ui/button'\nimport { StateSurface } from '@tc96/ui/patterns/surfaces/state/composition/state-surface/state-surface'\nimport { cn } from '@tc96/utils'\nimport type { ReactNode } from 'react'\nimport type { StatsLoadLabels, StatsLoadProps } from './types'\n\nexport function StatsSkeleton({\n children,\n className,\n label,\n}: Readonly<{ children: ReactNode; className?: string; label: string }>) {\n return (\n <output\n aria-busy=\"true\"\n aria-label={label}\n className={cn('block', className)}\n data-slot=\"stats-skeleton\"\n >\n {children}\n </output>\n )\n}\n\nexport function statsLoadState({\n error,\n labels,\n onRetry,\n pending,\n skeleton,\n}: Readonly<\n StatsLoadProps & { labels: StatsLoadLabels; skeleton: ReactNode }\n>): ReactNode {\n if (pending) return skeleton\n if (error)\n return (\n <StateSurface\n actions={\n onRetry ? (\n <Button onClick={onRetry} size=\"sm\" variant=\"outline\">\n {labels.retry}\n </Button>\n ) : undefined\n }\n description={labels.errorDescription}\n kind=\"error\"\n title={labels.errorTitle}\n />\n )\n return null\n}\n",
|
|
21
|
+
"target": "~/packages/ui/src/blocks/application/stats/shared/stats-load-state.tsx"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "blocks/application/stats/shared/types.ts",
|
|
25
|
+
"type": "registry:file",
|
|
26
|
+
"content": "export interface StatsAction {\n destructive?: boolean\n id: string\n label: string\n}\n\nexport interface StatsLoadLabels {\n errorDescription: string\n errorTitle: string\n loading: string\n retry: string\n}\n\nexport interface StatsLoadProps {\n error?: boolean\n onRetry?: () => void\n pending?: boolean\n}\n",
|
|
27
|
+
"target": "~/packages/ui/src/blocks/application/stats/shared/types.ts"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "blocks/application/stats/stats-1/index.ts",
|
|
31
|
+
"type": "registry:file",
|
|
32
|
+
"content": "export { Stats1 } from './stats-1'\nexport type {\n Stats1Action,\n Stats1Labels,\n Stats1Props,\n Stats1Stat,\n Stats1ValueKind,\n} from './types'\n",
|
|
33
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-1/index.ts"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "blocks/application/stats/stats-1/labels.ts",
|
|
37
|
+
"type": "registry:file",
|
|
38
|
+
"content": "import { defaultStatsLoadLabels } from '../shared/labels'\nimport type { Stats1Labels } from './types'\n\nexport const defaultStats1Labels: Stats1Labels = {\n ...defaultStatsLoadLabels,\n errorTitle: 'Não foi possível carregar os indicadores',\n loading: 'Carregando indicadores',\n actions: (label) => `Ações de ${label}`,\n details: 'Ver detalhes',\n emptyDescription: 'Os indicadores aparecem aqui quando houver dados.',\n emptyTitle: 'Nenhum indicador ainda',\n export: 'Exportar',\n title: 'Indicadores',\n trend: { down: 'Queda de', flat: 'Sem variação', up: 'Alta de' },\n}\n",
|
|
39
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-1/labels.ts"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "blocks/application/stats/stats-1/stats-1-skeleton.tsx",
|
|
43
|
+
"type": "registry:file",
|
|
44
|
+
"content": "import { Card } from '@tc96/ui/card'\nimport { Skeleton } from '@tc96/ui/skeleton'\nimport { StatsSkeleton } from '../shared/stats-load-state'\n\nexport function Stats1Skeleton({ label }: Readonly<{ label: string }>) {\n return (\n <StatsSkeleton label={label}>\n <div className=\"grid gap-4 sm:grid-cols-2 xl:grid-cols-4\">\n {['a', 'b', 'c', 'd'].map((id) => (\n <Card key={id}>\n <div className=\"flex flex-col gap-3 p-6\">\n <Skeleton className=\"h-4 w-24\" />\n <Skeleton className=\"h-8 w-32\" />\n <Skeleton className=\"h-4 w-20\" />\n </div>\n </Card>\n ))}\n </div>\n </StatsSkeleton>\n )\n}\n",
|
|
45
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-1/stats-1-skeleton.tsx"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"path": "blocks/application/stats/stats-1/stats-1.tsx",
|
|
49
|
+
"type": "registry:file",
|
|
50
|
+
"content": "import { CardPanel } from '@tc96/ui/card'\nimport { StateSurface } from '@tc96/ui/patterns/surfaces/state/composition/state-surface/state-surface'\nimport { Amount } from '@tc96/ui/patterns/widgets/shared/amount'\nimport { TrendIndicator } from '@tc96/ui/patterns/widgets/shared/trend-indicator'\nimport { WidgetShell } from '@tc96/ui/patterns/widgets/shared/widget-shell'\nimport { cn } from '@tc96/utils'\nimport { useId } from 'react'\nimport { StatsCardActions } from '../shared/stats-card-actions'\nimport { statsLoadState } from '../shared/stats-load-state'\nimport { defaultStats1Labels } from './labels'\nimport { Stats1Skeleton } from './stats-1-skeleton'\nimport type {\n Stats1Action,\n Stats1Labels,\n Stats1Props,\n Stats1Stat,\n} from './types'\n\ninterface StatCardProps {\n currency: string\n labels: Stats1Labels\n locale: string\n onStatAction?: Stats1Props['onStatAction']\n stat: Stats1Stat\n}\n\nfunction StatCard({\n currency,\n labels,\n locale,\n onStatAction,\n stat,\n}: Readonly<StatCardProps>) {\n const titleId = useId()\n const kind = stat.kind ?? 'number'\n const format =\n kind === 'currency'\n ? { currency, locale, style: 'currency' as const }\n : kind === 'percent'\n ? { locale, maximumFractionDigits: 1, style: 'percent' as const }\n : { locale, style: 'decimal' as const }\n\n return (\n <WidgetShell aria-labelledby={titleId} data-stat={stat.id}>\n <CardPanel className=\"grid gap-3 p-5\">\n <div className=\"flex items-center justify-between gap-3\">\n <h3 className=\"truncate text-muted-foreground text-sm\" id={titleId}>\n {stat.label}\n </h3>\n {onStatAction ? (\n <StatsCardActions\n actions={[\n { id: 'details', label: labels.details },\n { id: 'export', label: labels.export },\n ]}\n label={labels.actions(stat.label)}\n onAction={(action) =>\n onStatAction(stat.id, action as Stats1Action)\n }\n />\n ) : null}\n </div>\n <Amount\n className=\"font-medium text-3xl leading-tight tracking-tight\"\n format={format}\n value={stat.value}\n />\n {stat.change === undefined ? null : (\n <div>\n <TrendIndicator\n format={{ locale, maximumFractionDigits: 1, style: 'percent' }}\n labels={labels.trend}\n value={stat.change}\n />\n </div>\n )}\n </CardPanel>\n </WidgetShell>\n )\n}\n\nexport function Stats1({\n error,\n onRetry,\n pending,\n className,\n currency = 'BRL',\n labels: labelsProp,\n locale = 'pt-BR',\n onStatAction,\n stats,\n}: Readonly<Stats1Props>) {\n const labels = { ...defaultStats1Labels, ...labelsProp }\n const loadState = statsLoadState({\n error,\n labels: labels,\n onRetry,\n pending,\n skeleton: <Stats1Skeleton label={labels.loading} />,\n })\n\n if (loadState)\n return (\n <section aria-label={labels.title} className={className}>\n {loadState}\n </section>\n )\n\n if (stats.length === 0) {\n return (\n <StateSurface\n className={className}\n description={labels.emptyDescription}\n kind=\"empty\"\n title={labels.emptyTitle}\n />\n )\n }\n\n return (\n <section aria-label={labels.title} className={className}>\n <ul\n className={cn(\n 'grid list-none gap-4 sm:grid-cols-2 xl:grid-cols-4',\n stats.length === 3 && 'xl:grid-cols-3',\n )}\n >\n {stats.map((stat) => (\n <li className=\"min-w-0\" key={stat.id}>\n <StatCard\n currency={currency}\n labels={labels}\n locale={locale}\n onStatAction={onStatAction}\n stat={stat}\n />\n </li>\n ))}\n </ul>\n </section>\n )\n}\n",
|
|
51
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-1/stats-1.tsx"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"path": "blocks/application/stats/stats-1/types.ts",
|
|
55
|
+
"type": "registry:file",
|
|
56
|
+
"content": "import type { TrendIndicatorLabels } from '@tc96/ui/patterns/widgets/shared/trend-indicator'\nimport type { StatsLoadLabels, StatsLoadProps } from '../shared/types'\n\nexport type Stats1ValueKind = 'currency' | 'number' | 'percent'\n\nexport interface Stats1Stat {\n change?: number\n id: string\n kind?: Stats1ValueKind\n label: string\n value: number\n}\n\nexport type Stats1Action = 'details' | 'export'\n\nexport interface Stats1Labels extends StatsLoadLabels {\n actions: (label: string) => string\n details: string\n emptyDescription: string\n emptyTitle: string\n export: string\n title: string\n trend: TrendIndicatorLabels\n}\n\nexport interface Stats1Props extends StatsLoadProps {\n className?: string\n currency?: string\n labels?: Partial<Stats1Labels>\n locale?: string\n onStatAction?: (statId: string, action: Stats1Action) => void\n stats: Stats1Stat[]\n}\n",
|
|
57
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-1/types.ts"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"path": "helpers/format.ts",
|
|
61
|
+
"type": "registry:file",
|
|
62
|
+
"content": "/**\n * Options accepted by the amount formatters. They mirror the subset of\n * `Intl.NumberFormat` options the widgets need; `locale`, `currency` and\n * `style` have defaults, everything else is passed through untouched.\n */\nexport interface AmountFormatOptions {\n currency?: string\n locale?: string\n maximumFractionDigits?: number\n minimumFractionDigits?: number\n minimumIntegerDigits?: number\n notation?: 'compact' | 'standard'\n signDisplay?: 'always' | 'auto' | 'exceptZero' | 'never'\n style?: 'currency' | 'decimal' | 'percent'\n}\n\n/** An amount split at its decimal separator; see {@link splitAmountAtDecimal}. */\nexport interface AmountParts {\n fraction: string\n integer: string\n}\n\n/** Locale used when `AmountFormatOptions.locale` is omitted. */\nexport const defaultAmountLocale = 'en-US'\n/** Currency used when `AmountFormatOptions.currency` is omitted. */\nexport const defaultAmountCurrency = 'USD'\n\nconst percentFractionDigits = {\n maximumFractionDigits: 2,\n minimumFractionDigits: 2,\n}\n\n/**\n * Creates the `Intl.NumberFormat` behind {@link formatAmount}. Percentages\n * get two fraction digits unless `maximumFractionDigits` is set, and the\n * currency is only forwarded for the `currency` style.\n *\n * @param options - Formatting options; defaults to US dollars in `en-US`.\n * @returns A reusable formatter for the resolved options.\n */\nexport function createAmountFormatter({\n currency = defaultAmountCurrency,\n locale = defaultAmountLocale,\n style = 'currency',\n ...options\n}: AmountFormatOptions = {}): Intl.NumberFormat {\n const usesPercentDefaults =\n style === 'percent' && options.maximumFractionDigits === undefined\n\n return new Intl.NumberFormat(locale, {\n ...options,\n ...(style === 'currency' ? { currency } : {}),\n ...(usesPercentDefaults ? percentFractionDigits : {}),\n style,\n })\n}\n\n/**\n * Formats a number as currency, decimal or percent. Percentages follow the\n * `Intl` convention: `0.0934` becomes `9.34%`.\n *\n * @param value - The amount to format. Percentages are ratios, not points.\n * @param options - Formatting options; defaults to US dollars in `en-US`.\n * @returns The formatted amount for the locale.\n */\nexport function formatAmount(\n value: number,\n options?: AmountFormatOptions,\n): string {\n return createAmountFormatter(options).format(value)\n}\n\n/** Concatenates the values of `Intl.NumberFormat` parts back into text. */\nfunction joinParts(parts: readonly Intl.NumberFormatPart[]): string {\n return parts.map((part) => part.value).join('')\n}\n\n/**\n * Formats an amount and splits it at the decimal separator, so the fraction\n * (separator, digits and any trailing suffix such as `%`) can be rendered\n * with a lighter style than the integer part.\n *\n * @param value - The amount to format.\n * @param options - Formatting options; defaults to US dollars in `en-US`.\n * @returns The integer part and the fraction; the fraction is empty when the\n * formatted amount has no decimal separator.\n */\nexport function splitAmountAtDecimal(\n value: number,\n options?: AmountFormatOptions,\n): AmountParts {\n const parts = createAmountFormatter(options).formatToParts(value)\n const decimalIndex = parts.findIndex((part) => part.type === 'decimal')\n\n if (decimalIndex === -1) return { fraction: '', integer: joinParts(parts) }\n\n return {\n fraction: joinParts(parts.slice(decimalIndex)),\n integer: joinParts(parts.slice(0, decimalIndex)),\n }\n}\n",
|
|
63
|
+
"target": "~/packages/ui/src/helpers/format.ts"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"path": "patterns/surfaces/state/composition/state-surface/state-surface.tsx",
|
|
67
|
+
"type": "registry:file",
|
|
68
|
+
"content": "import {\n FileMagnifyingGlassIcon,\n LockIcon,\n MagnifyingGlassIcon,\n TrayIcon,\n WarningIcon,\n} from '@phosphor-icons/react'\nimport {\n Empty,\n EmptyContent,\n EmptyDescription,\n EmptyHeader,\n EmptyMedia,\n EmptyTitle,\n} from '@tc96/ui/empty'\nimport { IconFrame } from '@tc96/ui/icon-frame'\nimport { cn } from '@tc96/utils'\nimport type { ReactNode } from 'react'\nimport {\n STATE_SURFACE_ICON_COLORS,\n STATE_SURFACE_ROLES,\n type StateSurfaceKind,\n type StateSurfaceProps,\n} from '../../core'\n\nconst KIND_ICONS = {\n empty: TrayIcon,\n error: WarningIcon,\n 'no-result': MagnifyingGlassIcon,\n 'not-found': FileMagnifyingGlassIcon,\n permission: LockIcon,\n} as const satisfies Record<StateSurfaceKind, typeof TrayIcon>\n\nexport function StateSurface({\n actions,\n className,\n description,\n icon,\n kind,\n title,\n}: StateSurfaceProps): ReactNode {\n const Icon = KIND_ICONS[kind]\n const iconColor = STATE_SURFACE_ICON_COLORS[kind]\n\n return (\n <Empty\n className={className}\n data-kind={kind}\n role={STATE_SURFACE_ROLES[kind]}\n >\n <EmptyHeader>\n {icon === null ? null : (\n <EmptyMedia>\n <IconFrame\n className={cn(!iconColor && 'bg-muted/60')}\n color={iconColor}\n shape=\"rounded\"\n size=\"xl\"\n >\n {icon === undefined ? <Icon aria-hidden=\"true\" /> : icon}\n </IconFrame>\n </EmptyMedia>\n )}\n <EmptyTitle>{title}</EmptyTitle>\n <EmptyDescription>{description}</EmptyDescription>\n </EmptyHeader>\n {actions ? (\n <EmptyContent className=\"flex-row flex-wrap justify-center gap-2\">\n {actions}\n </EmptyContent>\n ) : null}\n </Empty>\n )\n}\n",
|
|
69
|
+
"target": "~/packages/ui/src/patterns/surfaces/state/composition/state-surface/state-surface.tsx"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"path": "patterns/surfaces/state/core.ts",
|
|
73
|
+
"type": "registry:file",
|
|
74
|
+
"content": "import type { ReactNode } from 'react'\n\nexport const STATE_SURFACE_KINDS = [\n 'empty',\n 'no-result',\n 'error',\n 'permission',\n 'not-found',\n] as const\n\nexport type StateSurfaceKind = (typeof STATE_SURFACE_KINDS)[number]\n\nexport type StateGuardState = 'data' | 'loading' | StateSurfaceKind\n\nexport type StateSurfaceRole = 'alert' | 'status'\n\nexport const STATE_SURFACE_ROLES = {\n empty: 'status',\n error: 'alert',\n 'no-result': 'status',\n 'not-found': 'status',\n permission: 'alert',\n} as const satisfies Record<StateSurfaceKind, StateSurfaceRole>\n\nexport const STATE_SURFACE_ICON_COLORS: Partial<\n Record<StateSurfaceKind, string>\n> = {\n error: 'var(--destructive)',\n permission: 'var(--destructive)',\n}\n\nexport interface StateSurfaceProps {\n actions?: ReactNode\n className?: string\n description: ReactNode\n icon?: ReactNode\n kind: StateSurfaceKind\n title: ReactNode\n}\n\nexport type StateGuardProps = {\n children: ReactNode\n} & (\n | { state: 'data'; surface?: Omit<StateSurfaceProps, 'kind'> }\n | {\n state: 'loading'\n surface: Pick<StateSurfaceProps, 'className' | 'title'> & {\n description?: ReactNode\n }\n }\n | { state: StateSurfaceKind; surface: Omit<StateSurfaceProps, 'kind'> }\n)\n",
|
|
75
|
+
"target": "~/packages/ui/src/patterns/surfaces/state/core.ts"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"path": "patterns/widgets/shared/amount.tsx",
|
|
79
|
+
"type": "registry:file",
|
|
80
|
+
"content": "import {\n type AmountFormatOptions,\n splitAmountAtDecimal,\n} from '@tc96/ui/helpers/format'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement } from 'react'\n\nexport interface AmountProps extends Omit<ComponentProps<'span'>, 'children'> {\n /** Atenua o separador decimal, as casas e os sufixos. */\n dimFraction?: boolean\n format?: AmountFormatOptions\n value: number\n}\n\nexport function Amount({\n className,\n dimFraction = false,\n format,\n value,\n ...props\n}: Readonly<AmountProps>): ReactElement {\n const { fraction, integer } = splitAmountAtDecimal(value, format)\n\n return (\n <span\n className={cn('tabular-nums', className)}\n data-slot=\"amount\"\n {...props}\n >\n {integer}\n {fraction ? (\n <span className={dimFraction ? 'text-muted-foreground' : undefined}>\n {fraction}\n </span>\n ) : null}\n </span>\n )\n}\n",
|
|
81
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/amount.tsx"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"path": "patterns/widgets/shared/trend-indicator.tsx",
|
|
85
|
+
"type": "registry:file",
|
|
86
|
+
"content": "import { ArrowDownIcon, ArrowUpIcon, MinusIcon } from '@phosphor-icons/react'\nimport { Badge } from '@tc96/ui/badge'\nimport { type AmountFormatOptions, formatAmount } from '@tc96/ui/helpers/format'\nimport { cn } from '@tc96/utils'\nimport type { ReactElement } from 'react'\nimport type { TrendDirection } from '../types'\n\nexport interface TrendIndicatorLabels {\n down: string\n flat: string\n up: string\n}\n\nexport interface TrendIndicatorProps {\n className?: string\n /** Padrão: percentual com duas casas; o valor é uma razão (`0.0044`). */\n format?: AmountFormatOptions\n /** Prefixo lido por leitores de tela, já que a direção é só visual. */\n labels?: TrendIndicatorLabels\n /** `badge` usa o Badge do COSS; `plain` é texto colorido, para gráficos. */\n variant?: 'badge' | 'plain'\n value: number\n}\n\nconst defaultLabels: TrendIndicatorLabels = {\n down: 'Queda de',\n flat: 'Sem variação',\n up: 'Alta de',\n}\n\nexport function trendDirection(value: number): TrendDirection {\n if (value > 0) return 'up'\n if (value < 0) return 'down'\n return 'flat'\n}\n\nconst icons = {\n down: ArrowDownIcon,\n flat: MinusIcon,\n up: ArrowUpIcon,\n} as const\n\nconst badgeVariants = {\n down: 'error',\n flat: 'secondary',\n up: 'success',\n} as const\n\nconst plainTones = {\n down: 'text-destructive-foreground',\n flat: 'text-muted-foreground',\n up: 'text-success-foreground',\n} as const\n\nexport function TrendIndicator({\n className,\n format = { style: 'percent' },\n labels = defaultLabels,\n variant = 'badge',\n value,\n}: Readonly<TrendIndicatorProps>): ReactElement {\n const direction = trendDirection(value)\n const Icon = icons[direction]\n const content = (\n <>\n <Icon aria-hidden=\"true\" />\n <span className=\"sr-only\">{labels[direction]} </span>\n {formatAmount(Math.abs(value), format)}\n </>\n )\n\n if (variant === 'plain') {\n return (\n <span\n className={cn(\n 'inline-flex items-center gap-1 font-medium text-sm tabular-nums [&_svg]:size-3.5 [&_svg]:shrink-0',\n plainTones[direction],\n className,\n )}\n data-direction={direction}\n data-slot=\"trend-indicator\"\n >\n {content}\n </span>\n )\n }\n\n return (\n <Badge\n className={cn('tabular-nums', className)}\n data-direction={direction}\n data-slot=\"trend-indicator\"\n size=\"large\"\n variant={badgeVariants[direction]}\n >\n {content}\n </Badge>\n )\n}\n",
|
|
87
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/trend-indicator.tsx"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"path": "patterns/widgets/shared/widget-shell.tsx",
|
|
91
|
+
"type": "registry:file",
|
|
92
|
+
"content": "import { Card } from '@tc96/ui/card'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement } from 'react'\n\nexport interface WidgetShellProps extends ComponentProps<typeof Card> {}\n\nexport function WidgetShell({\n className,\n render = <section />,\n ...props\n}: Readonly<WidgetShellProps>): ReactElement {\n return (\n <Card\n className={cn('min-w-0 border-transparent', className)}\n render={render}\n {...props}\n />\n )\n}\n",
|
|
93
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/widget-shell.tsx"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"path": "patterns/widgets/types/index.ts",
|
|
97
|
+
"type": "registry:file",
|
|
98
|
+
"content": "export type TrendDirection = 'down' | 'flat' | 'up'\n\nexport interface WidgetPeriodOption<TPeriod extends string = string> {\n label: string\n value: TPeriod\n}\n\n/** Cor semântica do tema do consumidor. */\nexport type WidgetTone = 'destructive' | 'info' | 'success' | 'warning'\n",
|
|
99
|
+
"target": "~/packages/ui/src/patterns/widgets/types/index.ts"
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
"dependencies": [
|
|
103
|
+
"@phosphor-icons/react@2.1.10",
|
|
104
|
+
"react@19.1.1"
|
|
105
|
+
],
|
|
106
|
+
"registryDependencies": [
|
|
107
|
+
"@ui/badge",
|
|
108
|
+
"@ui/button",
|
|
109
|
+
"@ui/card",
|
|
110
|
+
"@ui/empty",
|
|
111
|
+
"@ui/icon-frame",
|
|
112
|
+
"@ui/menu",
|
|
113
|
+
"@ui/skeleton"
|
|
114
|
+
],
|
|
115
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json"
|
|
116
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "stats-2",
|
|
3
|
+
"type": "registry:block",
|
|
4
|
+
"files": [
|
|
5
|
+
{
|
|
6
|
+
"path": "blocks/application/stats/shared/labels.ts",
|
|
7
|
+
"type": "registry:file",
|
|
8
|
+
"content": "import type { StatsLoadLabels } from './types'\n\nexport const defaultStatsLoadLabels: Pick<\n StatsLoadLabels,\n 'errorDescription' | 'retry'\n> = {\n errorDescription: 'Verifique sua conexão e tente novamente.',\n retry: 'Tentar novamente',\n}\n",
|
|
9
|
+
"target": "~/packages/ui/src/blocks/application/stats/shared/labels.ts"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "blocks/application/stats/shared/stats-load-state.tsx",
|
|
13
|
+
"type": "registry:file",
|
|
14
|
+
"content": "import { Button } from '@tc96/ui/button'\nimport { StateSurface } from '@tc96/ui/patterns/surfaces/state/composition/state-surface/state-surface'\nimport { cn } from '@tc96/utils'\nimport type { ReactNode } from 'react'\nimport type { StatsLoadLabels, StatsLoadProps } from './types'\n\nexport function StatsSkeleton({\n children,\n className,\n label,\n}: Readonly<{ children: ReactNode; className?: string; label: string }>) {\n return (\n <output\n aria-busy=\"true\"\n aria-label={label}\n className={cn('block', className)}\n data-slot=\"stats-skeleton\"\n >\n {children}\n </output>\n )\n}\n\nexport function statsLoadState({\n error,\n labels,\n onRetry,\n pending,\n skeleton,\n}: Readonly<\n StatsLoadProps & { labels: StatsLoadLabels; skeleton: ReactNode }\n>): ReactNode {\n if (pending) return skeleton\n if (error)\n return (\n <StateSurface\n actions={\n onRetry ? (\n <Button onClick={onRetry} size=\"sm\" variant=\"outline\">\n {labels.retry}\n </Button>\n ) : undefined\n }\n description={labels.errorDescription}\n kind=\"error\"\n title={labels.errorTitle}\n />\n )\n return null\n}\n",
|
|
15
|
+
"target": "~/packages/ui/src/blocks/application/stats/shared/stats-load-state.tsx"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "blocks/application/stats/shared/types.ts",
|
|
19
|
+
"type": "registry:file",
|
|
20
|
+
"content": "export interface StatsAction {\n destructive?: boolean\n id: string\n label: string\n}\n\nexport interface StatsLoadLabels {\n errorDescription: string\n errorTitle: string\n loading: string\n retry: string\n}\n\nexport interface StatsLoadProps {\n error?: boolean\n onRetry?: () => void\n pending?: boolean\n}\n",
|
|
21
|
+
"target": "~/packages/ui/src/blocks/application/stats/shared/types.ts"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "blocks/application/stats/stats-2/index.ts",
|
|
25
|
+
"type": "registry:file",
|
|
26
|
+
"content": "export { Stats2 } from './stats-2'\nexport type { Stats2Labels, Stats2Props } from './types'\n",
|
|
27
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-2/index.ts"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "blocks/application/stats/stats-2/labels.ts",
|
|
31
|
+
"type": "registry:file",
|
|
32
|
+
"content": "import { defaultStatsLoadLabels } from '../shared/labels'\nimport type { Stats2Labels } from './types'\n\nexport const defaultStats2Labels: Stats2Labels = {\n ...defaultStatsLoadLabels,\n errorTitle: 'Não foi possível carregar o uso da API',\n loading: 'Carregando uso da API',\n billed: 'Cobrado neste ciclo',\n quota: 'Uso da cota',\n renewsOn: (date) => `Renova em ${date}`,\n title: 'Uso da API',\n upgrade: 'Fazer upgrade',\n usage: (used, limit) => `${used} de ${limit} requisições`,\n}\n",
|
|
33
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-2/labels.ts"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "blocks/application/stats/stats-2/stats-2-skeleton.tsx",
|
|
37
|
+
"type": "registry:file",
|
|
38
|
+
"content": "import { Skeleton } from '@tc96/ui/skeleton'\nimport { StatsSkeleton } from '../shared/stats-load-state'\n\nexport function Stats2Skeleton({ label }: Readonly<{ label: string }>) {\n return (\n <StatsSkeleton className=\"grid gap-5 px-6 pb-6\" label={label}>\n <div className=\"flex flex-col gap-2\">\n <Skeleton className=\"h-4 w-48\" />\n <Skeleton className=\"h-2 w-full rounded-full\" />\n </div>\n <div className=\"flex flex-col gap-2\">\n <Skeleton className=\"h-4 w-32\" />\n <Skeleton className=\"h-7 w-28\" />\n </div>\n </StatsSkeleton>\n )\n}\n",
|
|
39
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-2/stats-2-skeleton.tsx"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "blocks/application/stats/stats-2/stats-2.tsx",
|
|
43
|
+
"type": "registry:file",
|
|
44
|
+
"content": "import { Button } from '@tc96/ui/button'\nimport {\n CardAction,\n CardDescription,\n CardHeader,\n CardPanel,\n CardTitle,\n} from '@tc96/ui/card'\nimport { formatMediumDate } from '@tc96/ui/helpers/date'\nimport { formatAmount } from '@tc96/ui/helpers/format'\nimport { Meter, MeterLabel, MeterValue } from '@tc96/ui/meter'\nimport { Amount } from '@tc96/ui/patterns/widgets/shared/amount'\nimport { WidgetShell } from '@tc96/ui/patterns/widgets/shared/widget-shell'\nimport { useId } from 'react'\nimport { statsLoadState } from '../shared/stats-load-state'\nimport { defaultStats2Labels } from './labels'\nimport { Stats2Skeleton } from './stats-2-skeleton'\nimport type { Stats2Props } from './types'\n\nexport function Stats2({\n error,\n onRetry,\n pending,\n className,\n cost,\n currency = 'BRL',\n labels: labelsProp,\n limit,\n locale = 'pt-BR',\n onUpgrade,\n renewsAt,\n timeZone,\n used,\n}: Readonly<Stats2Props>) {\n const labels = { ...defaultStats2Labels, ...labelsProp }\n const loadState = statsLoadState({\n error,\n labels: labels,\n onRetry,\n pending,\n skeleton: <Stats2Skeleton label={labels.loading} />,\n })\n const titleId = useId()\n const count = (value: number) =>\n formatAmount(value, { locale, style: 'decimal' })\n const usageText = labels.usage(count(used), count(limit))\n\n return (\n <WidgetShell aria-labelledby={titleId} className={className}>\n <CardHeader>\n <CardTitle id={titleId}>{labels.title}</CardTitle>\n {loadState ? null : (\n <CardDescription>\n {labels.renewsOn(formatMediumDate(renewsAt, locale, timeZone))}\n </CardDescription>\n )}\n {onUpgrade ? (\n <CardAction>\n <Button onClick={onUpgrade} size=\"sm\" variant=\"outline\">\n {labels.upgrade}\n </Button>\n </CardAction>\n ) : null}\n </CardHeader>\n {loadState ?? (\n <CardPanel className=\"grid gap-5\">\n <Meter\n getAriaValueText={() => usageText}\n locale={locale}\n max={Math.max(limit, 1)}\n min={0}\n value={Math.min(Math.max(used, 0), Math.max(limit, 1))}\n >\n <div className=\"flex items-center justify-between gap-3\">\n <MeterLabel>{labels.quota}</MeterLabel>\n <MeterValue>{() => usageText}</MeterValue>\n </div>\n </Meter>\n <div className=\"grid gap-1\">\n <span className=\"text-muted-foreground text-sm\">\n {labels.billed}\n </span>\n <Amount\n className=\"font-medium text-3xl tracking-tight\"\n dimFraction\n format={{ currency, locale, style: 'currency' }}\n value={cost}\n />\n </div>\n </CardPanel>\n )}\n </WidgetShell>\n )\n}\n",
|
|
45
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-2/stats-2.tsx"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"path": "blocks/application/stats/stats-2/types.ts",
|
|
49
|
+
"type": "registry:file",
|
|
50
|
+
"content": "import type { StatsLoadLabels, StatsLoadProps } from '../shared/types'\nexport interface Stats2Labels extends StatsLoadLabels {\n billed: string\n quota: string\n renewsOn: (date: string) => string\n title: string\n upgrade: string\n usage: (used: string, limit: string) => string\n}\n\nexport interface Stats2Props extends StatsLoadProps {\n className?: string\n cost: number\n currency?: string\n labels?: Partial<Stats2Labels>\n limit: number\n locale?: string\n onUpgrade?: () => void\n renewsAt: Date\n timeZone?: string\n used: number\n}\n",
|
|
51
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-2/types.ts"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"path": "helpers/calendar-date.ts",
|
|
55
|
+
"type": "registry:file",
|
|
56
|
+
"content": "/** Span of days {@link calendarRange} produces around an anchor date. */\nexport type CalendarRangeMode = 'day' | 'month' | 'week'\n\n/**\n * A calendar day with no time and no time zone attached. `month` runs from\n * 1 to 12.\n */\nexport interface CalendarDate {\n day: number\n month: number\n year: number\n}\n\nconst DATE_KEY_PATTERN = /^(\\d{4})-(\\d{2})-(\\d{2})$/\n\n/**\n * Serializes a calendar date as `YYYY-MM-DD`, a stable key for maps and DOM\n * attributes.\n *\n * @param date - The calendar date to serialize.\n */\nexport function calendarDateKey(date: CalendarDate): string {\n const month = String(date.month).padStart(2, '0')\n const day = String(date.day).padStart(2, '0')\n\n return `${date.year}-${month}-${day}`\n}\n\n/**\n * Parses a `YYYY-MM-DD` key produced by {@link calendarDateKey}.\n *\n * @param key - The serialized date.\n * @returns The calendar date, or `null` when the text is malformed or names a\n * day that does not exist, such as February 30.\n */\nexport function parseCalendarDateKey(key: string): CalendarDate | null {\n const match = DATE_KEY_PATTERN.exec(key)\n if (!match) return null\n\n const candidate = {\n day: Number(match[3]),\n month: Number(match[2]),\n year: Number(match[1]),\n }\n\n return isSameCalendarDate(candidate, normalizeCalendarDate(candidate))\n ? candidate\n : null\n}\n\n/**\n * Reads the local calendar day of a `Date`, dropping its time.\n *\n * @param date - A valid date, such as the one a date picker selects.\n */\nexport function calendarDateFromDate(date: Date): CalendarDate {\n return {\n day: date.getDate(),\n month: date.getMonth() + 1,\n year: date.getFullYear(),\n }\n}\n\n/**\n * Builds the local midnight `Date` of a calendar date, the value a date\n * picker expects for a day.\n *\n * @param date - The calendar date to convert.\n */\nexport function calendarDateToDate(date: CalendarDate): Date {\n return new Date(date.year, date.month - 1, date.day)\n}\n\n/**\n * Moves a calendar date by a number of days, rolling over months and years.\n *\n * @param date - The starting date.\n * @param days - Days to add; negative values move backwards.\n */\nexport function addCalendarDays(\n date: CalendarDate,\n days: number,\n): CalendarDate {\n return normalizeCalendarDate({ ...date, day: date.day + days })\n}\n\n/**\n * Orders two calendar dates chronologically.\n *\n * @returns Negative when `a` is earlier, positive when later, zero when equal.\n */\nexport function compareCalendarDates(a: CalendarDate, b: CalendarDate): number {\n return a.year - b.year || a.month - b.month || a.day - b.day\n}\n\n/** Whether two calendar dates name the same day. */\nexport function isSameCalendarDate(a: CalendarDate, b: CalendarDate): boolean {\n return compareCalendarDates(a, b) === 0\n}\n\n/**\n * Day of the week of a calendar date.\n *\n * @returns `0` for Sunday through `6` for Saturday.\n */\nexport function calendarDayOfWeek(date: CalendarDate): number {\n return new Date(Date.UTC(date.year, date.month - 1, date.day)).getUTCDay()\n}\n\n/**\n * First day of the week that contains a calendar date.\n *\n * @param date - Any day of the week.\n * @param weekStartsOn - `0` when weeks start on Sunday, `1` on Monday.\n */\nexport function startOfWeek(\n date: CalendarDate,\n weekStartsOn: 0 | 1,\n): CalendarDate {\n const offset = (calendarDayOfWeek(date) - weekStartsOn + 7) % 7\n\n return addCalendarDays(date, -offset)\n}\n\n/**\n * Lists the days a calendar view shows for an anchor date. A month spans from\n * the first week containing the 1st to the last week containing the final day,\n * so adjacent days of neighbouring months are included.\n *\n * @param anchor - The date the view is centred on.\n * @param mode - Whether to list one day, one week or one month.\n * @param weekStartsOn - `0` when weeks start on Sunday, `1` on Monday.\n * @returns The visible days in chronological order.\n */\nexport function calendarRange(\n anchor: CalendarDate,\n mode: CalendarRangeMode,\n weekStartsOn: 0 | 1,\n): CalendarDate[] {\n if (mode === 'day') return [anchor]\n\n if (mode === 'week') {\n const first = startOfWeek(anchor, weekStartsOn)\n\n return Array.from({ length: 7 }, (_, index) =>\n addCalendarDays(first, index),\n )\n }\n\n const firstOfMonth = { ...anchor, day: 1 }\n const lastOfMonth = addCalendarDays(\n {\n ...normalizeCalendarDate({ ...anchor, day: 1, month: anchor.month + 1 }),\n },\n -1,\n )\n const first = startOfWeek(firstOfMonth, weekStartsOn)\n const last = addCalendarDays(startOfWeek(lastOfMonth, weekStartsOn), 6)\n const days: CalendarDate[] = []\n\n for (\n let day = first;\n compareCalendarDates(day, last) <= 0;\n day = addCalendarDays(day, 1)\n ) {\n days.push(day)\n }\n\n return days\n}\n\n/**\n * Normalizes an out-of-range day or month through `Date.UTC`, which rolls it\n * over into the right month and year. Arithmetic stays in year/month/day\n * rather than adding 86400 seconds to an instant, which would break across\n * daylight saving transitions.\n */\nfunction normalizeCalendarDate(date: CalendarDate): CalendarDate {\n const normalized = new Date(Date.UTC(date.year, date.month - 1, date.day))\n\n return {\n day: normalized.getUTCDate(),\n month: normalized.getUTCMonth() + 1,\n year: normalized.getUTCFullYear(),\n }\n}\n",
|
|
57
|
+
"target": "~/packages/ui/src/helpers/calendar-date.ts"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"path": "helpers/date.ts",
|
|
61
|
+
"type": "registry:file",
|
|
62
|
+
"content": "import type { CalendarDate } from './calendar-date'\nimport { toZonedDateTime } from './zoned-date-time'\n\nconst DATE_ONLY_PATTERN = /^\\d{4}-\\d{2}-\\d{2}$/\nconst MILLISECONDS_IN_DAY = 86_400_000\n\nconst DATE_FORMAT_OPTIONS = {\n dateTime: { dateStyle: 'long', timeStyle: 'short' },\n long: { dateStyle: 'long' },\n medium: { dateStyle: 'medium' },\n numeric: { day: '2-digit', month: '2-digit', year: 'numeric' },\n short: { day: 'numeric', month: 'short' },\n weekdayAndDay: { day: 'numeric', weekday: 'long' },\n} satisfies Record<string, Intl.DateTimeFormatOptions>\n\nconst dateFormatters = new Map<string, Intl.DateTimeFormat>()\nconst relativeDayFormatters = new Map<string, Intl.RelativeTimeFormat>()\n\n/**\n * Type guard for a `Date` whose time is not `NaN`.\n *\n * @param value - Any value, typically the result of parsing user input.\n */\nexport function isValidDate(value: unknown): value is Date {\n return value instanceof Date && !Number.isNaN(value.getTime())\n}\n\n/**\n * Parses an ISO 8601 string, such as the value stored by a date property.\n *\n * @param value - The serialized date; empty values are treated as absent.\n * @returns The parsed date, or `null` when the value is absent or invalid.\n */\nexport function parseIsoDate(value: string | null | undefined): Date | null {\n if (!value) return null\n const date = new Date(value)\n return isValidDate(date) ? date : null\n}\n\n/**\n * Coerces a cell value into a `Date`. A date-only string (`2026-08-04`) is\n * read as local midnight, because `new Date('2026-08-04')` is UTC midnight and\n * would display as the previous day in any negative time zone.\n *\n * @param value - A `Date`, a date string or anything `String()` can serialize.\n * @returns A date that may be invalid; check it with {@link isValidDate}.\n */\nexport function parseDateValue(value: unknown): Date {\n if (value instanceof Date) return value\n const raw = String(value)\n return DATE_ONLY_PATTERN.test(raw)\n ? new Date(`${raw}T00:00:00`)\n : new Date(raw)\n}\n\n/**\n * Serializes the local calendar day of a date as noon UTC, so the day survives\n * a round trip through any time zone.\n *\n * @param date - A date whose local year, month and day are kept.\n * @returns An ISO string such as `2026-06-19T12:00:00.000Z`.\n */\nexport function serializeIsoDay(date: Date): string {\n return new Date(\n Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), 12),\n ).toISOString()\n}\n\n/**\n * Formats a date as day and abbreviated month, without the year.\n *\n * @param date - A valid date.\n * @param locale - A BCP 47 locale tag such as `pt-BR`.\n * @param timeZone - An IANA time zone; when omitted the date is read in the\n * runtime's local zone, which suits local day markers.\n * @returns The formatted date, such as `Jun 19` or `19 de jun.`.\n */\nexport function formatShortDate(\n date: Date,\n locale: string,\n timeZone?: string,\n): string {\n return getDateFormatter('short', locale, timeZone).format(date)\n}\n\n/**\n * Formats a date as two-digit day and month with the full year, so a column\n * of dates aligns.\n *\n * @param date - A valid date.\n * @param locale - A BCP 47 locale tag such as `pt-BR`.\n * @param timeZone - An IANA time zone; when omitted the date is read in the\n * runtime's local zone.\n * @returns The formatted date, such as `11/09/2026` or `09/11/2026`.\n */\nexport function formatNumericDate(\n date: Date,\n locale: string,\n timeZone?: string,\n): string {\n return getDateFormatter('numeric', locale, timeZone).format(date)\n}\n\n/**\n * Formats a date with day, abbreviated month and year, as a date picker\n * trigger shows it.\n *\n * @param date - A valid date.\n * @param locale - A BCP 47 locale tag such as `pt-BR`.\n * @param timeZone - An IANA time zone; when omitted the date is read in the\n * runtime's local zone.\n * @returns The formatted date, such as `Oct 20, 2026` or `20 de out. de 2026`.\n */\nexport function formatMediumDate(\n date: Date,\n locale: string,\n timeZone?: string,\n): string {\n return getDateFormatter('medium', locale, timeZone).format(date)\n}\n\n/**\n * Formats a date with day, full month name and year.\n *\n * @param date - A valid date.\n * @param locale - A BCP 47 locale tag such as `pt-BR`.\n * @param timeZone - An IANA time zone; when omitted the date is read in the\n * runtime's local zone.\n * @returns The formatted date, such as `October 20, 2026` or\n * `20 de outubro de 2026`.\n */\nexport function formatLongDate(\n date: Date,\n locale: string,\n timeZone?: string,\n): string {\n return getDateFormatter('long', locale, timeZone).format(date)\n}\n\n/**\n * Formats a date with day, full month name, year and time of day, as a\n * tooltip over a short or relative date shows it.\n *\n * @param date - A valid date.\n * @param locale - A BCP 47 locale tag such as `pt-BR`.\n * @param timeZone - An IANA time zone; when omitted the date is read in the\n * runtime's local zone.\n * @returns The formatted date and time, such as `October 20, 2026 at 2:30 PM`\n * or `20 de outubro de 2026 às 14:30`.\n */\nexport function formatDateTime(\n date: Date,\n locale: string,\n timeZone?: string,\n): string {\n return getDateFormatter('dateTime', locale, timeZone).format(date)\n}\n\n/**\n * Formats the weekday name with the day of the month, as a day heading over a\n * list of time slots.\n *\n * @param date - A valid date.\n * @param locale - A BCP 47 locale tag such as `pt-BR`.\n * @param timeZone - An IANA time zone; when omitted the date is read in the\n * runtime's local zone.\n * @returns The formatted day, such as `Tuesday 20` or `terça-feira, 20`.\n */\nexport function formatWeekdayAndDay(\n date: Date,\n locale: string,\n timeZone?: string,\n): string {\n return getDateFormatter('weekdayAndDay', locale, timeZone).format(date)\n}\n\n/**\n * Counts the civil days between two instants as seen on the wall clock of a\n * time zone, so an instant just after midnight in that zone counts as the\n * next day even when it is still the previous day in UTC.\n *\n * @param from - The reference instant, usually now.\n * @param to - The instant being measured, such as a due date.\n * @param timeZone - An IANA time zone.\n * @returns Negative when `to` falls on an earlier day than `from`.\n */\nexport function dayOffsetInTimeZone(\n from: Date,\n to: Date,\n timeZone: string,\n): number {\n return (\n dayNumber(toZonedDateTime(to, timeZone).date) -\n dayNumber(toZonedDateTime(from, timeZone).date)\n )\n}\n\n/**\n * Names a day relative to today (`Yesterday`, `Today`, `Tomorrow`, `In 3\n * days`) with the first letter upper-cased for the locale.\n *\n * @param dayOffset - Civil days from today; see {@link dayOffsetInTimeZone}.\n * @param locale - A BCP 47 locale tag such as `pt-BR`.\n */\nexport function formatRelativeDay(dayOffset: number, locale: string): string {\n const label = getRelativeDayFormatter(locale).format(dayOffset, 'day')\n return label.charAt(0).toLocaleUpperCase(locale) + label.slice(1)\n}\n\n/**\n * Moves a date by a number of local calendar days, keeping its time of day.\n *\n * @param date - The starting date; it is not mutated.\n * @param days - Days to add; negative values move backwards.\n */\nexport function addDays(date: Date, days: number): Date {\n const next = new Date(date)\n next.setDate(next.getDate() + days)\n return next\n}\n\n/**\n * Moves a date by a number of months. When the target month is shorter, the\n * day is clamped to its last day, so January 31 plus one month is the end of\n * February instead of early March.\n *\n * @param date - The starting date; it is not mutated.\n * @param months - Months to add; negative values move backwards.\n */\nexport function addMonths(date: Date, months: number): Date {\n const next = new Date(date)\n next.setDate(1)\n next.setMonth(next.getMonth() + months)\n const lastDay = new Date(next.getFullYear(), next.getMonth() + 1, 0).getDate()\n next.setDate(Math.min(date.getDate(), lastDay))\n return next\n}\n\n/**\n * Moves a date by a number of years. February 29 becomes February 28 in a\n * common year.\n *\n * @param date - The starting date; it is not mutated.\n * @param years - Years to add; negative values move backwards.\n */\nexport function addYears(date: Date, years: number): Date {\n return addMonths(date, years * 12)\n}\n\n/** Building an `Intl` formatter costs ~50 formats, so one is kept per key. */\nfunction getDateFormatter(\n style: keyof typeof DATE_FORMAT_OPTIONS,\n locale: string,\n timeZone?: string,\n): Intl.DateTimeFormat {\n const key = `${style}|${locale}|${timeZone ?? ''}`\n const cached = dateFormatters.get(key)\n if (cached) return cached\n\n const formatter = new Intl.DateTimeFormat(locale, {\n ...DATE_FORMAT_OPTIONS[style],\n ...(timeZone ? { timeZone } : {}),\n })\n dateFormatters.set(key, formatter)\n\n return formatter\n}\n\nfunction getRelativeDayFormatter(locale: string): Intl.RelativeTimeFormat {\n const cached = relativeDayFormatters.get(locale)\n if (cached) return cached\n\n const formatter = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' })\n relativeDayFormatters.set(locale, formatter)\n\n return formatter\n}\n\n/** Days since the Unix epoch for a calendar date, ignoring time zones. */\nfunction dayNumber(date: CalendarDate): number {\n return Date.UTC(date.year, date.month - 1, date.day) / MILLISECONDS_IN_DAY\n}\n",
|
|
63
|
+
"target": "~/packages/ui/src/helpers/date.ts"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"path": "helpers/format.ts",
|
|
67
|
+
"type": "registry:file",
|
|
68
|
+
"content": "/**\n * Options accepted by the amount formatters. They mirror the subset of\n * `Intl.NumberFormat` options the widgets need; `locale`, `currency` and\n * `style` have defaults, everything else is passed through untouched.\n */\nexport interface AmountFormatOptions {\n currency?: string\n locale?: string\n maximumFractionDigits?: number\n minimumFractionDigits?: number\n minimumIntegerDigits?: number\n notation?: 'compact' | 'standard'\n signDisplay?: 'always' | 'auto' | 'exceptZero' | 'never'\n style?: 'currency' | 'decimal' | 'percent'\n}\n\n/** An amount split at its decimal separator; see {@link splitAmountAtDecimal}. */\nexport interface AmountParts {\n fraction: string\n integer: string\n}\n\n/** Locale used when `AmountFormatOptions.locale` is omitted. */\nexport const defaultAmountLocale = 'en-US'\n/** Currency used when `AmountFormatOptions.currency` is omitted. */\nexport const defaultAmountCurrency = 'USD'\n\nconst percentFractionDigits = {\n maximumFractionDigits: 2,\n minimumFractionDigits: 2,\n}\n\n/**\n * Creates the `Intl.NumberFormat` behind {@link formatAmount}. Percentages\n * get two fraction digits unless `maximumFractionDigits` is set, and the\n * currency is only forwarded for the `currency` style.\n *\n * @param options - Formatting options; defaults to US dollars in `en-US`.\n * @returns A reusable formatter for the resolved options.\n */\nexport function createAmountFormatter({\n currency = defaultAmountCurrency,\n locale = defaultAmountLocale,\n style = 'currency',\n ...options\n}: AmountFormatOptions = {}): Intl.NumberFormat {\n const usesPercentDefaults =\n style === 'percent' && options.maximumFractionDigits === undefined\n\n return new Intl.NumberFormat(locale, {\n ...options,\n ...(style === 'currency' ? { currency } : {}),\n ...(usesPercentDefaults ? percentFractionDigits : {}),\n style,\n })\n}\n\n/**\n * Formats a number as currency, decimal or percent. Percentages follow the\n * `Intl` convention: `0.0934` becomes `9.34%`.\n *\n * @param value - The amount to format. Percentages are ratios, not points.\n * @param options - Formatting options; defaults to US dollars in `en-US`.\n * @returns The formatted amount for the locale.\n */\nexport function formatAmount(\n value: number,\n options?: AmountFormatOptions,\n): string {\n return createAmountFormatter(options).format(value)\n}\n\n/** Concatenates the values of `Intl.NumberFormat` parts back into text. */\nfunction joinParts(parts: readonly Intl.NumberFormatPart[]): string {\n return parts.map((part) => part.value).join('')\n}\n\n/**\n * Formats an amount and splits it at the decimal separator, so the fraction\n * (separator, digits and any trailing suffix such as `%`) can be rendered\n * with a lighter style than the integer part.\n *\n * @param value - The amount to format.\n * @param options - Formatting options; defaults to US dollars in `en-US`.\n * @returns The integer part and the fraction; the fraction is empty when the\n * formatted amount has no decimal separator.\n */\nexport function splitAmountAtDecimal(\n value: number,\n options?: AmountFormatOptions,\n): AmountParts {\n const parts = createAmountFormatter(options).formatToParts(value)\n const decimalIndex = parts.findIndex((part) => part.type === 'decimal')\n\n if (decimalIndex === -1) return { fraction: '', integer: joinParts(parts) }\n\n return {\n fraction: joinParts(parts.slice(decimalIndex)),\n integer: joinParts(parts.slice(0, decimalIndex)),\n }\n}\n",
|
|
69
|
+
"target": "~/packages/ui/src/helpers/format.ts"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"path": "helpers/zoned-date-time.ts",
|
|
73
|
+
"type": "registry:file",
|
|
74
|
+
"content": "import type { CalendarDate } from './calendar-date'\n\n/**\n * A wall-clock reading in some time zone: the calendar day and the minutes\n * elapsed since local midnight.\n */\nexport interface ZonedDateTime {\n date: CalendarDate\n minutes: number\n}\n\nconst formatterCache = new Map<string, Intl.DateTimeFormat>()\n\n/**\n * Returns the formatter for a time zone. `Intl.DateTimeFormat` is expensive\n * to construct, so one instance per zone is kept for the life of the module.\n */\nfunction getFormatter(timeZone: string): Intl.DateTimeFormat {\n const cached = formatterCache.get(timeZone)\n if (cached) return cached\n\n const formatter = new Intl.DateTimeFormat('en-US', {\n day: '2-digit',\n hour: '2-digit',\n hourCycle: 'h23',\n minute: '2-digit',\n month: '2-digit',\n second: '2-digit',\n timeZone,\n year: 'numeric',\n })\n formatterCache.set(timeZone, formatter)\n\n return formatter\n}\n\n/** Numeric date and time fields of an instant, read in a time zone. */\ninterface WallClockParts {\n day: number\n hour: number\n minute: number\n month: number\n second: number\n year: number\n}\n\n/**\n * Reads the wall-clock fields of an instant in a time zone.\n *\n * @param instant - The UTC instant to project.\n * @param timeZone - An IANA time zone.\n */\nfunction wallClockPartsOf(instant: Date, timeZone: string): WallClockParts {\n const parts: Partial<WallClockParts> = {}\n\n for (const part of getFormatter(timeZone).formatToParts(instant)) {\n if (part.type === 'literal') continue\n if (part.type in partKeys)\n parts[partKeys[part.type as keyof typeof partKeys]] = Number(part.value)\n }\n\n return parts as WallClockParts\n}\n\nconst partKeys = {\n day: 'day',\n hour: 'hour',\n minute: 'minute',\n month: 'month',\n second: 'second',\n year: 'year',\n} as const\n\n/**\n * Projects a UTC instant onto the wall clock of a time zone.\n *\n * @param instant - The UTC instant to project.\n * @param timeZone - An IANA time zone.\n * @returns The calendar day and the minutes since local midnight.\n */\nexport function toZonedDateTime(\n instant: Date,\n timeZone: string,\n): ZonedDateTime {\n const parts = wallClockPartsOf(instant, timeZone)\n\n return {\n date: { day: parts.day, month: parts.month, year: parts.year },\n minutes: parts.hour * 60 + parts.minute,\n }\n}\n\n/**\n * Offset of a time zone from UTC at a given instant. The formatter stops at\n * seconds, so the instant is truncated to the second before comparing;\n * otherwise milliseconds would leak into the offset.\n *\n * @param instant - The UTC instant to measure at.\n * @param timeZone - An IANA time zone.\n * @returns The offset in milliseconds; positive east of UTC.\n */\nexport function getTimeZoneOffsetMs(instant: Date, timeZone: string): number {\n const parts = wallClockPartsOf(instant, timeZone)\n const wallAsUtc = Date.UTC(\n parts.year,\n parts.month - 1,\n parts.day,\n parts.hour,\n parts.minute,\n parts.second,\n )\n const truncated =\n instant.getTime() - (((instant.getTime() % 1000) + 1000) % 1000)\n\n return wallAsUtc - truncated\n}\n\n/**\n * Converts a wall-clock reading in a time zone back to a UTC instant without a\n * date library: the wall time is first treated as UTC and then corrected by the\n * zone offset. A second pass handles transition edges, since offsets only\n * change there: an ambiguous time (fall back) keeps the first offset found,\n * and a nonexistent time (spring forward) resolves to the instant after the\n * transition.\n *\n * @param zoned - The calendar day and minutes since local midnight.\n * @param timeZone - An IANA time zone.\n * @returns The UTC instant that shows that wall time in the zone.\n */\nexport function fromZonedDateTime(\n zoned: ZonedDateTime,\n timeZone: string,\n): Date {\n const { date, minutes } = zoned\n const guess = Date.UTC(date.year, date.month - 1, date.day, 0, minutes)\n const firstOffset = getTimeZoneOffsetMs(new Date(guess), timeZone)\n const candidate = guess - firstOffset\n const secondOffset = getTimeZoneOffsetMs(new Date(candidate), timeZone)\n\n if (firstOffset === secondOffset) return new Date(candidate)\n\n const corrected = guess - secondOffset\n const projected = toZonedDateTime(new Date(corrected), timeZone)\n const matchesWall =\n projected.minutes === ((minutes % 1440) + 1440) % 1440 &&\n projected.date.day === date.day &&\n projected.date.month === date.month &&\n projected.date.year === date.year\n\n return matchesWall ? new Date(corrected) : new Date(candidate)\n}\n",
|
|
75
|
+
"target": "~/packages/ui/src/helpers/zoned-date-time.ts"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"path": "patterns/surfaces/state/composition/state-surface/state-surface.tsx",
|
|
79
|
+
"type": "registry:file",
|
|
80
|
+
"content": "import {\n FileMagnifyingGlassIcon,\n LockIcon,\n MagnifyingGlassIcon,\n TrayIcon,\n WarningIcon,\n} from '@phosphor-icons/react'\nimport {\n Empty,\n EmptyContent,\n EmptyDescription,\n EmptyHeader,\n EmptyMedia,\n EmptyTitle,\n} from '@tc96/ui/empty'\nimport { IconFrame } from '@tc96/ui/icon-frame'\nimport { cn } from '@tc96/utils'\nimport type { ReactNode } from 'react'\nimport {\n STATE_SURFACE_ICON_COLORS,\n STATE_SURFACE_ROLES,\n type StateSurfaceKind,\n type StateSurfaceProps,\n} from '../../core'\n\nconst KIND_ICONS = {\n empty: TrayIcon,\n error: WarningIcon,\n 'no-result': MagnifyingGlassIcon,\n 'not-found': FileMagnifyingGlassIcon,\n permission: LockIcon,\n} as const satisfies Record<StateSurfaceKind, typeof TrayIcon>\n\nexport function StateSurface({\n actions,\n className,\n description,\n icon,\n kind,\n title,\n}: StateSurfaceProps): ReactNode {\n const Icon = KIND_ICONS[kind]\n const iconColor = STATE_SURFACE_ICON_COLORS[kind]\n\n return (\n <Empty\n className={className}\n data-kind={kind}\n role={STATE_SURFACE_ROLES[kind]}\n >\n <EmptyHeader>\n {icon === null ? null : (\n <EmptyMedia>\n <IconFrame\n className={cn(!iconColor && 'bg-muted/60')}\n color={iconColor}\n shape=\"rounded\"\n size=\"xl\"\n >\n {icon === undefined ? <Icon aria-hidden=\"true\" /> : icon}\n </IconFrame>\n </EmptyMedia>\n )}\n <EmptyTitle>{title}</EmptyTitle>\n <EmptyDescription>{description}</EmptyDescription>\n </EmptyHeader>\n {actions ? (\n <EmptyContent className=\"flex-row flex-wrap justify-center gap-2\">\n {actions}\n </EmptyContent>\n ) : null}\n </Empty>\n )\n}\n",
|
|
81
|
+
"target": "~/packages/ui/src/patterns/surfaces/state/composition/state-surface/state-surface.tsx"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"path": "patterns/surfaces/state/core.ts",
|
|
85
|
+
"type": "registry:file",
|
|
86
|
+
"content": "import type { ReactNode } from 'react'\n\nexport const STATE_SURFACE_KINDS = [\n 'empty',\n 'no-result',\n 'error',\n 'permission',\n 'not-found',\n] as const\n\nexport type StateSurfaceKind = (typeof STATE_SURFACE_KINDS)[number]\n\nexport type StateGuardState = 'data' | 'loading' | StateSurfaceKind\n\nexport type StateSurfaceRole = 'alert' | 'status'\n\nexport const STATE_SURFACE_ROLES = {\n empty: 'status',\n error: 'alert',\n 'no-result': 'status',\n 'not-found': 'status',\n permission: 'alert',\n} as const satisfies Record<StateSurfaceKind, StateSurfaceRole>\n\nexport const STATE_SURFACE_ICON_COLORS: Partial<\n Record<StateSurfaceKind, string>\n> = {\n error: 'var(--destructive)',\n permission: 'var(--destructive)',\n}\n\nexport interface StateSurfaceProps {\n actions?: ReactNode\n className?: string\n description: ReactNode\n icon?: ReactNode\n kind: StateSurfaceKind\n title: ReactNode\n}\n\nexport type StateGuardProps = {\n children: ReactNode\n} & (\n | { state: 'data'; surface?: Omit<StateSurfaceProps, 'kind'> }\n | {\n state: 'loading'\n surface: Pick<StateSurfaceProps, 'className' | 'title'> & {\n description?: ReactNode\n }\n }\n | { state: StateSurfaceKind; surface: Omit<StateSurfaceProps, 'kind'> }\n)\n",
|
|
87
|
+
"target": "~/packages/ui/src/patterns/surfaces/state/core.ts"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"path": "patterns/widgets/shared/amount.tsx",
|
|
91
|
+
"type": "registry:file",
|
|
92
|
+
"content": "import {\n type AmountFormatOptions,\n splitAmountAtDecimal,\n} from '@tc96/ui/helpers/format'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement } from 'react'\n\nexport interface AmountProps extends Omit<ComponentProps<'span'>, 'children'> {\n /** Atenua o separador decimal, as casas e os sufixos. */\n dimFraction?: boolean\n format?: AmountFormatOptions\n value: number\n}\n\nexport function Amount({\n className,\n dimFraction = false,\n format,\n value,\n ...props\n}: Readonly<AmountProps>): ReactElement {\n const { fraction, integer } = splitAmountAtDecimal(value, format)\n\n return (\n <span\n className={cn('tabular-nums', className)}\n data-slot=\"amount\"\n {...props}\n >\n {integer}\n {fraction ? (\n <span className={dimFraction ? 'text-muted-foreground' : undefined}>\n {fraction}\n </span>\n ) : null}\n </span>\n )\n}\n",
|
|
93
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/amount.tsx"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"path": "patterns/widgets/shared/widget-shell.tsx",
|
|
97
|
+
"type": "registry:file",
|
|
98
|
+
"content": "import { Card } from '@tc96/ui/card'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement } from 'react'\n\nexport interface WidgetShellProps extends ComponentProps<typeof Card> {}\n\nexport function WidgetShell({\n className,\n render = <section />,\n ...props\n}: Readonly<WidgetShellProps>): ReactElement {\n return (\n <Card\n className={cn('min-w-0 border-transparent', className)}\n render={render}\n {...props}\n />\n )\n}\n",
|
|
99
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/widget-shell.tsx"
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
"dependencies": [
|
|
103
|
+
"@phosphor-icons/react@2.1.10",
|
|
104
|
+
"react@19.1.1"
|
|
105
|
+
],
|
|
106
|
+
"registryDependencies": [
|
|
107
|
+
"@ui/button",
|
|
108
|
+
"@ui/card",
|
|
109
|
+
"@ui/empty",
|
|
110
|
+
"@ui/icon-frame",
|
|
111
|
+
"@ui/meter",
|
|
112
|
+
"@ui/skeleton"
|
|
113
|
+
],
|
|
114
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json"
|
|
115
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "stats-3",
|
|
3
|
+
"type": "registry:block",
|
|
4
|
+
"files": [
|
|
5
|
+
{
|
|
6
|
+
"path": "blocks/application/stats/shared/labels.ts",
|
|
7
|
+
"type": "registry:file",
|
|
8
|
+
"content": "import type { StatsLoadLabels } from './types'\n\nexport const defaultStatsLoadLabels: Pick<\n StatsLoadLabels,\n 'errorDescription' | 'retry'\n> = {\n errorDescription: 'Verifique sua conexão e tente novamente.',\n retry: 'Tentar novamente',\n}\n",
|
|
9
|
+
"target": "~/packages/ui/src/blocks/application/stats/shared/labels.ts"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "blocks/application/stats/shared/segmented-meter.tsx",
|
|
13
|
+
"type": "registry:file",
|
|
14
|
+
"content": "import { Gauge } from '@tc96/ui/gauge'\n\nexport interface SegmentedMeterProps {\n className?: string\n labelledBy: string\n max: number\n segments?: number\n value: number\n valueText: string\n}\n\nexport function filledSegments(value: number, max: number, segments: number) {\n if (max <= 0 || segments <= 0) return 0\n const ratio = Math.min(Math.max(value / max, 0), 1)\n return Math.round(ratio * segments)\n}\n\nexport function SegmentedMeter({\n className,\n labelledBy,\n max,\n segments = 10,\n value,\n valueText,\n}: Readonly<SegmentedMeterProps>) {\n const safeMax = Math.max(max, 1)\n const filled = filledSegments(value, max, segments)\n\n return (\n <Gauge\n aria-labelledby={labelledBy}\n className={className}\n data-filled={filled}\n data-slot=\"segmented-meter\"\n getAriaValueText={() => valueText}\n max={safeMax}\n segments={segments}\n size=\"lg\"\n value={Math.min(Math.max(value, 0), safeMax)}\n variant=\"segmented\"\n />\n )\n}\n",
|
|
15
|
+
"target": "~/packages/ui/src/blocks/application/stats/shared/segmented-meter.tsx"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "blocks/application/stats/shared/stats-load-state.tsx",
|
|
19
|
+
"type": "registry:file",
|
|
20
|
+
"content": "import { Button } from '@tc96/ui/button'\nimport { StateSurface } from '@tc96/ui/patterns/surfaces/state/composition/state-surface/state-surface'\nimport { cn } from '@tc96/utils'\nimport type { ReactNode } from 'react'\nimport type { StatsLoadLabels, StatsLoadProps } from './types'\n\nexport function StatsSkeleton({\n children,\n className,\n label,\n}: Readonly<{ children: ReactNode; className?: string; label: string }>) {\n return (\n <output\n aria-busy=\"true\"\n aria-label={label}\n className={cn('block', className)}\n data-slot=\"stats-skeleton\"\n >\n {children}\n </output>\n )\n}\n\nexport function statsLoadState({\n error,\n labels,\n onRetry,\n pending,\n skeleton,\n}: Readonly<\n StatsLoadProps & { labels: StatsLoadLabels; skeleton: ReactNode }\n>): ReactNode {\n if (pending) return skeleton\n if (error)\n return (\n <StateSurface\n actions={\n onRetry ? (\n <Button onClick={onRetry} size=\"sm\" variant=\"outline\">\n {labels.retry}\n </Button>\n ) : undefined\n }\n description={labels.errorDescription}\n kind=\"error\"\n title={labels.errorTitle}\n />\n )\n return null\n}\n",
|
|
21
|
+
"target": "~/packages/ui/src/blocks/application/stats/shared/stats-load-state.tsx"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "blocks/application/stats/shared/types.ts",
|
|
25
|
+
"type": "registry:file",
|
|
26
|
+
"content": "export interface StatsAction {\n destructive?: boolean\n id: string\n label: string\n}\n\nexport interface StatsLoadLabels {\n errorDescription: string\n errorTitle: string\n loading: string\n retry: string\n}\n\nexport interface StatsLoadProps {\n error?: boolean\n onRetry?: () => void\n pending?: boolean\n}\n",
|
|
27
|
+
"target": "~/packages/ui/src/blocks/application/stats/shared/types.ts"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "blocks/application/stats/stats-3/index.ts",
|
|
31
|
+
"type": "registry:file",
|
|
32
|
+
"content": "export { Stats3 } from './stats-3'\nexport type { Stats3Item, Stats3Labels, Stats3Props } from './types'\n",
|
|
33
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-3/index.ts"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "blocks/application/stats/stats-3/labels.ts",
|
|
37
|
+
"type": "registry:file",
|
|
38
|
+
"content": "import { defaultStatsLoadLabels } from '../shared/labels'\nimport type { Stats3Labels } from './types'\n\nexport const defaultStats3Labels: Stats3Labels = {\n ...defaultStatsLoadLabels,\n errorTitle: 'Não foi possível carregar a capacidade',\n loading: 'Carregando capacidade',\n ratio: (value, total) => `${value} / ${total}`,\n title: 'Capacidade',\n}\n",
|
|
39
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-3/labels.ts"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "blocks/application/stats/stats-3/stats-3-skeleton.tsx",
|
|
43
|
+
"type": "registry:file",
|
|
44
|
+
"content": "import { Skeleton } from '@tc96/ui/skeleton'\nimport { StatsSkeleton } from '../shared/stats-load-state'\n\nexport function Stats3Skeleton({ label }: Readonly<{ label: string }>) {\n return (\n <StatsSkeleton label={label}>\n <div className=\"grid divide-y sm:grid-cols-3 sm:divide-x sm:divide-y-0\">\n {['a', 'b', 'c'].map((id) => (\n <div className=\"flex flex-col gap-3 p-6\" key={id}>\n <Skeleton className=\"h-4 w-24\" />\n <Skeleton className=\"h-7 w-20\" />\n <Skeleton className=\"h-2 w-full\" />\n </div>\n ))}\n </div>\n </StatsSkeleton>\n )\n}\n",
|
|
45
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-3/stats-3-skeleton.tsx"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"path": "blocks/application/stats/stats-3/stats-3.tsx",
|
|
49
|
+
"type": "registry:file",
|
|
50
|
+
"content": "import { formatAmount } from '@tc96/ui/helpers/format'\nimport { WidgetShell } from '@tc96/ui/patterns/widgets/shared/widget-shell'\nimport { cn } from '@tc96/utils'\nimport { useId } from 'react'\nimport { SegmentedMeter } from '../shared/segmented-meter'\nimport { statsLoadState } from '../shared/stats-load-state'\nimport { defaultStats3Labels } from './labels'\nimport { Stats3Skeleton } from './stats-3-skeleton'\nimport type { Stats3Item, Stats3Labels, Stats3Props } from './types'\n\ninterface CapacityCellProps {\n item: Stats3Item\n labels: Stats3Labels\n locale: string\n segments: number\n}\n\nfunction CapacityCell({\n item,\n labels,\n locale,\n segments,\n}: Readonly<CapacityCellProps>) {\n const labelId = useId()\n const count = (value: number) =>\n formatAmount(value, { locale, style: 'decimal' })\n const ratio = labels.ratio(count(item.value), count(item.total))\n\n return (\n <div className=\"grid min-w-0 gap-3 p-5\" data-capacity={item.id}>\n <span className=\"truncate text-muted-foreground text-sm\" id={labelId}>\n {item.label}\n </span>\n <span className=\"font-medium text-2xl tabular-nums tracking-tight\">\n {ratio}\n </span>\n <SegmentedMeter\n labelledBy={labelId}\n max={item.total}\n segments={segments}\n value={item.value}\n valueText={ratio}\n />\n </div>\n )\n}\n\nexport function Stats3({\n error,\n onRetry,\n pending,\n className,\n items,\n labels: labelsProp,\n locale = 'pt-BR',\n segments = 10,\n}: Readonly<Stats3Props>) {\n const labels = { ...defaultStats3Labels, ...labelsProp }\n const loadState = statsLoadState({\n error,\n labels: labels,\n onRetry,\n pending,\n skeleton: <Stats3Skeleton label={labels.loading} />,\n })\n\n return (\n <WidgetShell aria-label={labels.title} className={className}>\n {loadState ?? (\n <div\n className={cn(\n 'grid divide-y sm:divide-x sm:divide-y-0',\n items.length === 3 ? 'sm:grid-cols-3' : 'sm:grid-flow-col',\n )}\n >\n {items.map((item) => (\n <CapacityCell\n item={item}\n key={item.id}\n labels={labels}\n locale={locale}\n segments={segments}\n />\n ))}\n </div>\n )}\n </WidgetShell>\n )\n}\n",
|
|
51
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-3/stats-3.tsx"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"path": "blocks/application/stats/stats-3/types.ts",
|
|
55
|
+
"type": "registry:file",
|
|
56
|
+
"content": "import type { StatsLoadLabels, StatsLoadProps } from '../shared/types'\nexport interface Stats3Item {\n id: string\n label: string\n total: number\n value: number\n}\n\nexport interface Stats3Labels extends StatsLoadLabels {\n ratio: (value: string, total: string) => string\n title: string\n}\n\nexport interface Stats3Props extends StatsLoadProps {\n className?: string\n items: Stats3Item[]\n labels?: Partial<Stats3Labels>\n locale?: string\n segments?: number\n}\n",
|
|
57
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-3/types.ts"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"path": "helpers/format.ts",
|
|
61
|
+
"type": "registry:file",
|
|
62
|
+
"content": "/**\n * Options accepted by the amount formatters. They mirror the subset of\n * `Intl.NumberFormat` options the widgets need; `locale`, `currency` and\n * `style` have defaults, everything else is passed through untouched.\n */\nexport interface AmountFormatOptions {\n currency?: string\n locale?: string\n maximumFractionDigits?: number\n minimumFractionDigits?: number\n minimumIntegerDigits?: number\n notation?: 'compact' | 'standard'\n signDisplay?: 'always' | 'auto' | 'exceptZero' | 'never'\n style?: 'currency' | 'decimal' | 'percent'\n}\n\n/** An amount split at its decimal separator; see {@link splitAmountAtDecimal}. */\nexport interface AmountParts {\n fraction: string\n integer: string\n}\n\n/** Locale used when `AmountFormatOptions.locale` is omitted. */\nexport const defaultAmountLocale = 'en-US'\n/** Currency used when `AmountFormatOptions.currency` is omitted. */\nexport const defaultAmountCurrency = 'USD'\n\nconst percentFractionDigits = {\n maximumFractionDigits: 2,\n minimumFractionDigits: 2,\n}\n\n/**\n * Creates the `Intl.NumberFormat` behind {@link formatAmount}. Percentages\n * get two fraction digits unless `maximumFractionDigits` is set, and the\n * currency is only forwarded for the `currency` style.\n *\n * @param options - Formatting options; defaults to US dollars in `en-US`.\n * @returns A reusable formatter for the resolved options.\n */\nexport function createAmountFormatter({\n currency = defaultAmountCurrency,\n locale = defaultAmountLocale,\n style = 'currency',\n ...options\n}: AmountFormatOptions = {}): Intl.NumberFormat {\n const usesPercentDefaults =\n style === 'percent' && options.maximumFractionDigits === undefined\n\n return new Intl.NumberFormat(locale, {\n ...options,\n ...(style === 'currency' ? { currency } : {}),\n ...(usesPercentDefaults ? percentFractionDigits : {}),\n style,\n })\n}\n\n/**\n * Formats a number as currency, decimal or percent. Percentages follow the\n * `Intl` convention: `0.0934` becomes `9.34%`.\n *\n * @param value - The amount to format. Percentages are ratios, not points.\n * @param options - Formatting options; defaults to US dollars in `en-US`.\n * @returns The formatted amount for the locale.\n */\nexport function formatAmount(\n value: number,\n options?: AmountFormatOptions,\n): string {\n return createAmountFormatter(options).format(value)\n}\n\n/** Concatenates the values of `Intl.NumberFormat` parts back into text. */\nfunction joinParts(parts: readonly Intl.NumberFormatPart[]): string {\n return parts.map((part) => part.value).join('')\n}\n\n/**\n * Formats an amount and splits it at the decimal separator, so the fraction\n * (separator, digits and any trailing suffix such as `%`) can be rendered\n * with a lighter style than the integer part.\n *\n * @param value - The amount to format.\n * @param options - Formatting options; defaults to US dollars in `en-US`.\n * @returns The integer part and the fraction; the fraction is empty when the\n * formatted amount has no decimal separator.\n */\nexport function splitAmountAtDecimal(\n value: number,\n options?: AmountFormatOptions,\n): AmountParts {\n const parts = createAmountFormatter(options).formatToParts(value)\n const decimalIndex = parts.findIndex((part) => part.type === 'decimal')\n\n if (decimalIndex === -1) return { fraction: '', integer: joinParts(parts) }\n\n return {\n fraction: joinParts(parts.slice(decimalIndex)),\n integer: joinParts(parts.slice(0, decimalIndex)),\n }\n}\n",
|
|
63
|
+
"target": "~/packages/ui/src/helpers/format.ts"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"path": "patterns/surfaces/state/composition/state-surface/state-surface.tsx",
|
|
67
|
+
"type": "registry:file",
|
|
68
|
+
"content": "import {\n FileMagnifyingGlassIcon,\n LockIcon,\n MagnifyingGlassIcon,\n TrayIcon,\n WarningIcon,\n} from '@phosphor-icons/react'\nimport {\n Empty,\n EmptyContent,\n EmptyDescription,\n EmptyHeader,\n EmptyMedia,\n EmptyTitle,\n} from '@tc96/ui/empty'\nimport { IconFrame } from '@tc96/ui/icon-frame'\nimport { cn } from '@tc96/utils'\nimport type { ReactNode } from 'react'\nimport {\n STATE_SURFACE_ICON_COLORS,\n STATE_SURFACE_ROLES,\n type StateSurfaceKind,\n type StateSurfaceProps,\n} from '../../core'\n\nconst KIND_ICONS = {\n empty: TrayIcon,\n error: WarningIcon,\n 'no-result': MagnifyingGlassIcon,\n 'not-found': FileMagnifyingGlassIcon,\n permission: LockIcon,\n} as const satisfies Record<StateSurfaceKind, typeof TrayIcon>\n\nexport function StateSurface({\n actions,\n className,\n description,\n icon,\n kind,\n title,\n}: StateSurfaceProps): ReactNode {\n const Icon = KIND_ICONS[kind]\n const iconColor = STATE_SURFACE_ICON_COLORS[kind]\n\n return (\n <Empty\n className={className}\n data-kind={kind}\n role={STATE_SURFACE_ROLES[kind]}\n >\n <EmptyHeader>\n {icon === null ? null : (\n <EmptyMedia>\n <IconFrame\n className={cn(!iconColor && 'bg-muted/60')}\n color={iconColor}\n shape=\"rounded\"\n size=\"xl\"\n >\n {icon === undefined ? <Icon aria-hidden=\"true\" /> : icon}\n </IconFrame>\n </EmptyMedia>\n )}\n <EmptyTitle>{title}</EmptyTitle>\n <EmptyDescription>{description}</EmptyDescription>\n </EmptyHeader>\n {actions ? (\n <EmptyContent className=\"flex-row flex-wrap justify-center gap-2\">\n {actions}\n </EmptyContent>\n ) : null}\n </Empty>\n )\n}\n",
|
|
69
|
+
"target": "~/packages/ui/src/patterns/surfaces/state/composition/state-surface/state-surface.tsx"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"path": "patterns/surfaces/state/core.ts",
|
|
73
|
+
"type": "registry:file",
|
|
74
|
+
"content": "import type { ReactNode } from 'react'\n\nexport const STATE_SURFACE_KINDS = [\n 'empty',\n 'no-result',\n 'error',\n 'permission',\n 'not-found',\n] as const\n\nexport type StateSurfaceKind = (typeof STATE_SURFACE_KINDS)[number]\n\nexport type StateGuardState = 'data' | 'loading' | StateSurfaceKind\n\nexport type StateSurfaceRole = 'alert' | 'status'\n\nexport const STATE_SURFACE_ROLES = {\n empty: 'status',\n error: 'alert',\n 'no-result': 'status',\n 'not-found': 'status',\n permission: 'alert',\n} as const satisfies Record<StateSurfaceKind, StateSurfaceRole>\n\nexport const STATE_SURFACE_ICON_COLORS: Partial<\n Record<StateSurfaceKind, string>\n> = {\n error: 'var(--destructive)',\n permission: 'var(--destructive)',\n}\n\nexport interface StateSurfaceProps {\n actions?: ReactNode\n className?: string\n description: ReactNode\n icon?: ReactNode\n kind: StateSurfaceKind\n title: ReactNode\n}\n\nexport type StateGuardProps = {\n children: ReactNode\n} & (\n | { state: 'data'; surface?: Omit<StateSurfaceProps, 'kind'> }\n | {\n state: 'loading'\n surface: Pick<StateSurfaceProps, 'className' | 'title'> & {\n description?: ReactNode\n }\n }\n | { state: StateSurfaceKind; surface: Omit<StateSurfaceProps, 'kind'> }\n)\n",
|
|
75
|
+
"target": "~/packages/ui/src/patterns/surfaces/state/core.ts"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"path": "patterns/widgets/shared/widget-shell.tsx",
|
|
79
|
+
"type": "registry:file",
|
|
80
|
+
"content": "import { Card } from '@tc96/ui/card'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement } from 'react'\n\nexport interface WidgetShellProps extends ComponentProps<typeof Card> {}\n\nexport function WidgetShell({\n className,\n render = <section />,\n ...props\n}: Readonly<WidgetShellProps>): ReactElement {\n return (\n <Card\n className={cn('min-w-0 border-transparent', className)}\n render={render}\n {...props}\n />\n )\n}\n",
|
|
81
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/widget-shell.tsx"
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
"dependencies": [
|
|
85
|
+
"@phosphor-icons/react@2.1.10",
|
|
86
|
+
"react@19.1.1"
|
|
87
|
+
],
|
|
88
|
+
"registryDependencies": [
|
|
89
|
+
"@ui/button",
|
|
90
|
+
"@ui/card",
|
|
91
|
+
"@ui/empty",
|
|
92
|
+
"@ui/gauge",
|
|
93
|
+
"@ui/icon-frame",
|
|
94
|
+
"@ui/skeleton"
|
|
95
|
+
],
|
|
96
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json"
|
|
97
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "stats-4",
|
|
3
|
+
"type": "registry:block",
|
|
4
|
+
"files": [
|
|
5
|
+
{
|
|
6
|
+
"path": "blocks/application/stats/shared/labels.ts",
|
|
7
|
+
"type": "registry:file",
|
|
8
|
+
"content": "import type { StatsLoadLabels } from './types'\n\nexport const defaultStatsLoadLabels: Pick<\n StatsLoadLabels,\n 'errorDescription' | 'retry'\n> = {\n errorDescription: 'Verifique sua conexão e tente novamente.',\n retry: 'Tentar novamente',\n}\n",
|
|
9
|
+
"target": "~/packages/ui/src/blocks/application/stats/shared/labels.ts"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "blocks/application/stats/shared/stats-load-state.tsx",
|
|
13
|
+
"type": "registry:file",
|
|
14
|
+
"content": "import { Button } from '@tc96/ui/button'\nimport { StateSurface } from '@tc96/ui/patterns/surfaces/state/composition/state-surface/state-surface'\nimport { cn } from '@tc96/utils'\nimport type { ReactNode } from 'react'\nimport type { StatsLoadLabels, StatsLoadProps } from './types'\n\nexport function StatsSkeleton({\n children,\n className,\n label,\n}: Readonly<{ children: ReactNode; className?: string; label: string }>) {\n return (\n <output\n aria-busy=\"true\"\n aria-label={label}\n className={cn('block', className)}\n data-slot=\"stats-skeleton\"\n >\n {children}\n </output>\n )\n}\n\nexport function statsLoadState({\n error,\n labels,\n onRetry,\n pending,\n skeleton,\n}: Readonly<\n StatsLoadProps & { labels: StatsLoadLabels; skeleton: ReactNode }\n>): ReactNode {\n if (pending) return skeleton\n if (error)\n return (\n <StateSurface\n actions={\n onRetry ? (\n <Button onClick={onRetry} size=\"sm\" variant=\"outline\">\n {labels.retry}\n </Button>\n ) : undefined\n }\n description={labels.errorDescription}\n kind=\"error\"\n title={labels.errorTitle}\n />\n )\n return null\n}\n",
|
|
15
|
+
"target": "~/packages/ui/src/blocks/application/stats/shared/stats-load-state.tsx"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "blocks/application/stats/shared/types.ts",
|
|
19
|
+
"type": "registry:file",
|
|
20
|
+
"content": "export interface StatsAction {\n destructive?: boolean\n id: string\n label: string\n}\n\nexport interface StatsLoadLabels {\n errorDescription: string\n errorTitle: string\n loading: string\n retry: string\n}\n\nexport interface StatsLoadProps {\n error?: boolean\n onRetry?: () => void\n pending?: boolean\n}\n",
|
|
21
|
+
"target": "~/packages/ui/src/blocks/application/stats/shared/types.ts"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "blocks/application/stats/stats-4/index.ts",
|
|
25
|
+
"type": "registry:file",
|
|
26
|
+
"content": "export { Stats4 } from './stats-4'\nexport type {\n Stats4Labels,\n Stats4Props,\n Stats4Range,\n Stats4Source,\n} from './types'\n",
|
|
27
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-4/index.ts"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "blocks/application/stats/stats-4/labels.ts",
|
|
31
|
+
"type": "registry:file",
|
|
32
|
+
"content": "import { defaultStatsLoadLabels } from '../shared/labels'\nimport type { Stats4Labels } from './types'\n\nexport const defaultStats4Labels: Stats4Labels = {\n ...defaultStatsLoadLabels,\n errorTitle: 'Não foi possível carregar os leads',\n loading: 'Carregando leads',\n goal: (goal) => `Meta de ${goal} leads`,\n goalProgress: (total, goal, percent) =>\n `${total} de ${goal} leads, ${percent} da meta`,\n range: 'Período',\n ranges: { '30d': '30 dias', '7d': '7 dias', '90d': '90 dias' },\n sources: 'Leads por origem',\n sourcesBar: 'Distribuição dos leads por origem',\n title: 'Visão geral de leads',\n total: (range) => `Leads nos últimos ${range}`,\n}\n",
|
|
33
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-4/labels.ts"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "blocks/application/stats/stats-4/stats-4-skeleton.tsx",
|
|
37
|
+
"type": "registry:file",
|
|
38
|
+
"content": "import { Skeleton } from '@tc96/ui/skeleton'\nimport { StatsSkeleton } from '../shared/stats-load-state'\n\nexport function Stats4Skeleton({ label }: Readonly<{ label: string }>) {\n return (\n <StatsSkeleton className=\"grid gap-6 px-6 pb-6\" label={label}>\n <div className=\"flex flex-col gap-2\">\n <Skeleton className=\"h-9 w-28\" />\n <Skeleton className=\"h-4 w-40\" />\n <Skeleton className=\"h-2 w-full rounded-full\" />\n </div>\n <div className=\"flex flex-col gap-3\">\n <Skeleton className=\"h-4 w-32\" />\n <Skeleton className=\"h-3 w-full rounded-full\" />\n {['a', 'b', 'c', 'd'].map((id) => (\n <div className=\"flex items-center justify-between gap-3\" key={id}>\n <Skeleton className=\"h-4 w-28\" />\n <Skeleton className=\"h-4 w-12\" />\n </div>\n ))}\n </div>\n </StatsSkeleton>\n )\n}\n",
|
|
39
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-4/stats-4-skeleton.tsx"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "blocks/application/stats/stats-4/stats-4.tsx",
|
|
43
|
+
"type": "registry:file",
|
|
44
|
+
"content": "import {\n CardAction,\n CardContent,\n CardDescription,\n CardHeader,\n CardTitle,\n} from '@tc96/ui/card'\nimport { formatAmount } from '@tc96/ui/helpers/format'\nimport { WidgetShell } from '@tc96/ui/patterns/widgets/shared/widget-shell'\nimport {\n Progress,\n ProgressIndicator,\n ProgressLabel,\n ProgressTrack,\n} from '@tc96/ui/progress'\nimport {\n Select,\n SelectItem,\n SelectPopup,\n SelectTrigger,\n SelectValue,\n} from '@tc96/ui/select'\nimport { cn } from '@tc96/utils'\nimport { statsLoadState } from '../shared/stats-load-state'\nimport { defaultStats4Labels } from './labels'\nimport { Stats4Skeleton } from './stats-4-skeleton'\nimport type { Stats4Props, Stats4Range } from './types'\n\nconst defaultRanges: Stats4Range[] = ['7d', '30d', '90d']\n\nexport function Stats4({\n error,\n onRetry,\n pending,\n className,\n goal,\n labels,\n locale = 'pt-BR',\n onRangeChange,\n range,\n ranges = defaultRanges,\n sources,\n total,\n}: Readonly<Stats4Props>) {\n const text = { ...defaultStats4Labels, ...labels }\n const loadState = statsLoadState({\n error,\n labels: text,\n onRetry,\n pending,\n skeleton: <Stats4Skeleton label={text.loading} />,\n })\n const number = (value: number) =>\n formatAmount(value, { locale, style: 'decimal' })\n const percent = (ratio: number) =>\n formatAmount(ratio, { locale, maximumFractionDigits: 0, style: 'percent' })\n const items = ranges.map((value) => ({ label: text.ranges[value], value }))\n const progress = goal > 0 ? Math.min(total / goal, 1) : 0\n const sourcesTotal = sources.reduce((sum, source) => sum + source.value, 0)\n\n return (\n <WidgetShell aria-label={text.title} className={className}>\n <CardHeader>\n <CardTitle>{text.title}</CardTitle>\n <CardDescription>{text.total(text.ranges[range])}</CardDescription>\n <CardAction>\n <Select\n items={items}\n onValueChange={(next) => {\n if (next) onRangeChange?.(next as Stats4Range)\n }}\n value={range}\n >\n <SelectTrigger aria-label={text.range} className=\"w-36\" size=\"sm\">\n <SelectValue />\n </SelectTrigger>\n <SelectPopup>\n {items.map((item) => (\n <SelectItem key={item.value} value={item.value}>\n {item.label}\n </SelectItem>\n ))}\n </SelectPopup>\n </Select>\n </CardAction>\n </CardHeader>\n {loadState ?? (\n <CardContent className=\"flex flex-col gap-6\">\n <div className=\"flex flex-col gap-3\">\n <p\n className=\"font-semibold text-4xl tabular-nums\"\n data-slot=\"stats-4-total\"\n >\n {number(total)}\n </p>\n <Progress\n getAriaValueText={() =>\n text.goalProgress(\n number(total),\n number(goal),\n percent(progress),\n )\n }\n max={1}\n value={progress}\n >\n <div className=\"flex items-center justify-between gap-2\">\n <ProgressLabel>{text.goal(number(goal))}</ProgressLabel>\n <span\n className=\"font-medium text-sm tabular-nums\"\n data-slot=\"stats-4-progress\"\n >\n {percent(progress)}\n </span>\n </div>\n <ProgressTrack>\n <ProgressIndicator />\n </ProgressTrack>\n </Progress>\n </div>\n <div className=\"flex flex-col gap-3\">\n <p className=\"font-medium text-sm\">{text.sources}</p>\n <div\n aria-label={text.sourcesBar}\n className=\"flex h-2.5 w-full gap-0.5 overflow-hidden rounded-full bg-input\"\n data-slot=\"stats-4-bar\"\n role=\"img\"\n >\n {sourcesTotal > 0\n ? sources\n .filter((source) => source.value > 0)\n .map((source) => (\n <span\n className={cn('h-full', source.colorClassName)}\n data-source={source.id}\n key={source.id}\n style={{\n width: `${(source.value / sourcesTotal) * 100}%`,\n }}\n />\n ))\n : null}\n </div>\n <ul\n className=\"grid gap-2 sm:grid-cols-2\"\n data-slot=\"stats-4-legend\"\n >\n {sources.map((source) => (\n <li className=\"flex items-center gap-2 text-sm\" key={source.id}>\n <span\n aria-hidden=\"true\"\n className={cn(\n 'size-2.5 shrink-0 rounded-full',\n source.colorClassName,\n )}\n />\n <span className=\"truncate\">{source.name}</span>\n <span className=\"ms-auto text-muted-foreground tabular-nums\">\n {number(source.value)} ·{' '}\n {percent(\n sourcesTotal > 0 ? source.value / sourcesTotal : 0,\n )}\n </span>\n </li>\n ))}\n </ul>\n </div>\n </CardContent>\n )}\n </WidgetShell>\n )\n}\n",
|
|
45
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-4/stats-4.tsx"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"path": "blocks/application/stats/stats-4/types.ts",
|
|
49
|
+
"type": "registry:file",
|
|
50
|
+
"content": "import type { StatsLoadLabels, StatsLoadProps } from '../shared/types'\nexport type Stats4Range = '7d' | '30d' | '90d'\n\nexport interface Stats4Source {\n colorClassName: string\n id: string\n name: string\n value: number\n}\n\nexport interface Stats4Labels extends StatsLoadLabels {\n goal: (goal: string) => string\n goalProgress: (total: string, goal: string, percent: string) => string\n range: string\n ranges: Record<Stats4Range, string>\n sources: string\n sourcesBar: string\n title: string\n total: (range: string) => string\n}\n\nexport interface Stats4Props extends StatsLoadProps {\n className?: string\n goal: number\n labels?: Partial<Stats4Labels>\n locale?: string\n onRangeChange?: (range: Stats4Range) => void\n range: Stats4Range\n ranges?: Stats4Range[]\n sources: Stats4Source[]\n total: number\n}\n",
|
|
51
|
+
"target": "~/packages/ui/src/blocks/application/stats/stats-4/types.ts"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"path": "helpers/format.ts",
|
|
55
|
+
"type": "registry:file",
|
|
56
|
+
"content": "/**\n * Options accepted by the amount formatters. They mirror the subset of\n * `Intl.NumberFormat` options the widgets need; `locale`, `currency` and\n * `style` have defaults, everything else is passed through untouched.\n */\nexport interface AmountFormatOptions {\n currency?: string\n locale?: string\n maximumFractionDigits?: number\n minimumFractionDigits?: number\n minimumIntegerDigits?: number\n notation?: 'compact' | 'standard'\n signDisplay?: 'always' | 'auto' | 'exceptZero' | 'never'\n style?: 'currency' | 'decimal' | 'percent'\n}\n\n/** An amount split at its decimal separator; see {@link splitAmountAtDecimal}. */\nexport interface AmountParts {\n fraction: string\n integer: string\n}\n\n/** Locale used when `AmountFormatOptions.locale` is omitted. */\nexport const defaultAmountLocale = 'en-US'\n/** Currency used when `AmountFormatOptions.currency` is omitted. */\nexport const defaultAmountCurrency = 'USD'\n\nconst percentFractionDigits = {\n maximumFractionDigits: 2,\n minimumFractionDigits: 2,\n}\n\n/**\n * Creates the `Intl.NumberFormat` behind {@link formatAmount}. Percentages\n * get two fraction digits unless `maximumFractionDigits` is set, and the\n * currency is only forwarded for the `currency` style.\n *\n * @param options - Formatting options; defaults to US dollars in `en-US`.\n * @returns A reusable formatter for the resolved options.\n */\nexport function createAmountFormatter({\n currency = defaultAmountCurrency,\n locale = defaultAmountLocale,\n style = 'currency',\n ...options\n}: AmountFormatOptions = {}): Intl.NumberFormat {\n const usesPercentDefaults =\n style === 'percent' && options.maximumFractionDigits === undefined\n\n return new Intl.NumberFormat(locale, {\n ...options,\n ...(style === 'currency' ? { currency } : {}),\n ...(usesPercentDefaults ? percentFractionDigits : {}),\n style,\n })\n}\n\n/**\n * Formats a number as currency, decimal or percent. Percentages follow the\n * `Intl` convention: `0.0934` becomes `9.34%`.\n *\n * @param value - The amount to format. Percentages are ratios, not points.\n * @param options - Formatting options; defaults to US dollars in `en-US`.\n * @returns The formatted amount for the locale.\n */\nexport function formatAmount(\n value: number,\n options?: AmountFormatOptions,\n): string {\n return createAmountFormatter(options).format(value)\n}\n\n/** Concatenates the values of `Intl.NumberFormat` parts back into text. */\nfunction joinParts(parts: readonly Intl.NumberFormatPart[]): string {\n return parts.map((part) => part.value).join('')\n}\n\n/**\n * Formats an amount and splits it at the decimal separator, so the fraction\n * (separator, digits and any trailing suffix such as `%`) can be rendered\n * with a lighter style than the integer part.\n *\n * @param value - The amount to format.\n * @param options - Formatting options; defaults to US dollars in `en-US`.\n * @returns The integer part and the fraction; the fraction is empty when the\n * formatted amount has no decimal separator.\n */\nexport function splitAmountAtDecimal(\n value: number,\n options?: AmountFormatOptions,\n): AmountParts {\n const parts = createAmountFormatter(options).formatToParts(value)\n const decimalIndex = parts.findIndex((part) => part.type === 'decimal')\n\n if (decimalIndex === -1) return { fraction: '', integer: joinParts(parts) }\n\n return {\n fraction: joinParts(parts.slice(decimalIndex)),\n integer: joinParts(parts.slice(0, decimalIndex)),\n }\n}\n",
|
|
57
|
+
"target": "~/packages/ui/src/helpers/format.ts"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"path": "patterns/surfaces/state/composition/state-surface/state-surface.tsx",
|
|
61
|
+
"type": "registry:file",
|
|
62
|
+
"content": "import {\n FileMagnifyingGlassIcon,\n LockIcon,\n MagnifyingGlassIcon,\n TrayIcon,\n WarningIcon,\n} from '@phosphor-icons/react'\nimport {\n Empty,\n EmptyContent,\n EmptyDescription,\n EmptyHeader,\n EmptyMedia,\n EmptyTitle,\n} from '@tc96/ui/empty'\nimport { IconFrame } from '@tc96/ui/icon-frame'\nimport { cn } from '@tc96/utils'\nimport type { ReactNode } from 'react'\nimport {\n STATE_SURFACE_ICON_COLORS,\n STATE_SURFACE_ROLES,\n type StateSurfaceKind,\n type StateSurfaceProps,\n} from '../../core'\n\nconst KIND_ICONS = {\n empty: TrayIcon,\n error: WarningIcon,\n 'no-result': MagnifyingGlassIcon,\n 'not-found': FileMagnifyingGlassIcon,\n permission: LockIcon,\n} as const satisfies Record<StateSurfaceKind, typeof TrayIcon>\n\nexport function StateSurface({\n actions,\n className,\n description,\n icon,\n kind,\n title,\n}: StateSurfaceProps): ReactNode {\n const Icon = KIND_ICONS[kind]\n const iconColor = STATE_SURFACE_ICON_COLORS[kind]\n\n return (\n <Empty\n className={className}\n data-kind={kind}\n role={STATE_SURFACE_ROLES[kind]}\n >\n <EmptyHeader>\n {icon === null ? null : (\n <EmptyMedia>\n <IconFrame\n className={cn(!iconColor && 'bg-muted/60')}\n color={iconColor}\n shape=\"rounded\"\n size=\"xl\"\n >\n {icon === undefined ? <Icon aria-hidden=\"true\" /> : icon}\n </IconFrame>\n </EmptyMedia>\n )}\n <EmptyTitle>{title}</EmptyTitle>\n <EmptyDescription>{description}</EmptyDescription>\n </EmptyHeader>\n {actions ? (\n <EmptyContent className=\"flex-row flex-wrap justify-center gap-2\">\n {actions}\n </EmptyContent>\n ) : null}\n </Empty>\n )\n}\n",
|
|
63
|
+
"target": "~/packages/ui/src/patterns/surfaces/state/composition/state-surface/state-surface.tsx"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"path": "patterns/surfaces/state/core.ts",
|
|
67
|
+
"type": "registry:file",
|
|
68
|
+
"content": "import type { ReactNode } from 'react'\n\nexport const STATE_SURFACE_KINDS = [\n 'empty',\n 'no-result',\n 'error',\n 'permission',\n 'not-found',\n] as const\n\nexport type StateSurfaceKind = (typeof STATE_SURFACE_KINDS)[number]\n\nexport type StateGuardState = 'data' | 'loading' | StateSurfaceKind\n\nexport type StateSurfaceRole = 'alert' | 'status'\n\nexport const STATE_SURFACE_ROLES = {\n empty: 'status',\n error: 'alert',\n 'no-result': 'status',\n 'not-found': 'status',\n permission: 'alert',\n} as const satisfies Record<StateSurfaceKind, StateSurfaceRole>\n\nexport const STATE_SURFACE_ICON_COLORS: Partial<\n Record<StateSurfaceKind, string>\n> = {\n error: 'var(--destructive)',\n permission: 'var(--destructive)',\n}\n\nexport interface StateSurfaceProps {\n actions?: ReactNode\n className?: string\n description: ReactNode\n icon?: ReactNode\n kind: StateSurfaceKind\n title: ReactNode\n}\n\nexport type StateGuardProps = {\n children: ReactNode\n} & (\n | { state: 'data'; surface?: Omit<StateSurfaceProps, 'kind'> }\n | {\n state: 'loading'\n surface: Pick<StateSurfaceProps, 'className' | 'title'> & {\n description?: ReactNode\n }\n }\n | { state: StateSurfaceKind; surface: Omit<StateSurfaceProps, 'kind'> }\n)\n",
|
|
69
|
+
"target": "~/packages/ui/src/patterns/surfaces/state/core.ts"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"path": "patterns/widgets/shared/widget-shell.tsx",
|
|
73
|
+
"type": "registry:file",
|
|
74
|
+
"content": "import { Card } from '@tc96/ui/card'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement } from 'react'\n\nexport interface WidgetShellProps extends ComponentProps<typeof Card> {}\n\nexport function WidgetShell({\n className,\n render = <section />,\n ...props\n}: Readonly<WidgetShellProps>): ReactElement {\n return (\n <Card\n className={cn('min-w-0 border-transparent', className)}\n render={render}\n {...props}\n />\n )\n}\n",
|
|
75
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/widget-shell.tsx"
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
"dependencies": [
|
|
79
|
+
"@phosphor-icons/react@2.1.10",
|
|
80
|
+
"react@19.1.1"
|
|
81
|
+
],
|
|
82
|
+
"registryDependencies": [
|
|
83
|
+
"@ui/button",
|
|
84
|
+
"@ui/card",
|
|
85
|
+
"@ui/empty",
|
|
86
|
+
"@ui/icon-frame",
|
|
87
|
+
"@ui/progress",
|
|
88
|
+
"@ui/select",
|
|
89
|
+
"@ui/skeleton"
|
|
90
|
+
],
|
|
91
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json"
|
|
92
|
+
}
|