@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,129 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "list-1",
|
|
3
|
+
"type": "registry:block",
|
|
4
|
+
"files": [
|
|
5
|
+
{
|
|
6
|
+
"path": "blocks/application/list/list-1/index.ts",
|
|
7
|
+
"type": "registry:file",
|
|
8
|
+
"content": "export { List1 } from './list-1'\nexport type {\n List1Labels,\n List1Metric,\n List1MetricKind,\n List1Props,\n} from './types'\n",
|
|
9
|
+
"target": "~/packages/ui/src/blocks/application/list/list-1/index.ts"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "blocks/application/list/list-1/labels.ts",
|
|
13
|
+
"type": "registry:file",
|
|
14
|
+
"content": "import { defaultListLoadLabels } from '../shared/labels'\nimport type { List1Labels } from './types'\n\nexport const defaultList1Labels: List1Labels = {\n ...defaultListLoadLabels,\n errorTitle: 'Não foi possível carregar as métricas',\n loading: 'Carregando métricas',\n emptyDescription: 'As métricas aparecem aqui quando houver dados.',\n emptyTitle: 'Nenhuma métrica ainda',\n title: 'Métricas',\n trend: { down: 'Queda de', flat: 'Sem variação', up: 'Alta de' },\n}\n",
|
|
15
|
+
"target": "~/packages/ui/src/blocks/application/list/list-1/labels.ts"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "blocks/application/list/list-1/list-1-skeleton.tsx",
|
|
19
|
+
"type": "registry:file",
|
|
20
|
+
"content": "import { ListRowsSkeleton, ListSkeleton } from '../shared/list-load-state'\n\nexport function List1Skeleton({ label }: Readonly<{ label: string }>) {\n return (\n <ListSkeleton label={label}>\n <ListRowsSkeleton count={4} end=\"amount\" />\n </ListSkeleton>\n )\n}\n",
|
|
21
|
+
"target": "~/packages/ui/src/blocks/application/list/list-1/list-1-skeleton.tsx"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "blocks/application/list/list-1/list-1.tsx",
|
|
25
|
+
"type": "registry:file",
|
|
26
|
+
"content": "import { getInitials } from '@tc96/ui/helpers/initials'\nimport { List } from '@tc96/ui/patterns/list/composition/list/list'\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 { cn } from '@tc96/utils'\nimport { listLoadState } from '../shared/list-load-state'\nimport { defaultList1Labels } from './labels'\nimport { List1Skeleton } from './list-1-skeleton'\nimport type { List1Metric, List1Props } from './types'\n\nfunction amountFormat(\n kind: List1Metric['kind'],\n currency: string,\n locale: string,\n) {\n if (kind === 'currency')\n return { currency, locale, style: 'currency' as const }\n if (kind === 'percent')\n return { locale, maximumFractionDigits: 1, style: 'percent' as const }\n return { locale, style: 'decimal' as const }\n}\n\nexport function List1({\n error,\n onRetry,\n pending,\n className,\n currency = 'BRL',\n labels: labelsProp,\n locale = 'pt-BR',\n metrics,\n}: Readonly<List1Props>) {\n const labels = { ...defaultList1Labels, ...labelsProp }\n const loadState = listLoadState({\n error,\n labels,\n onRetry,\n pending,\n skeleton: <List1Skeleton 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 (metrics.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 <ul\n aria-label={labels.title}\n className={cn('grid list-none gap-2', className)}\n >\n {metrics.map((metric) => (\n <List\n actions={\n <span className=\"flex items-center gap-3\">\n <Amount\n className=\"font-medium text-sm\"\n format={amountFormat(metric.kind, currency, locale)}\n value={metric.value}\n />\n {metric.change === undefined ? null : (\n <TrendIndicator\n format={{\n locale,\n maximumFractionDigits: 1,\n style: 'percent',\n }}\n labels={labels.trend}\n value={metric.change}\n />\n )}\n </span>\n }\n description={metric.description}\n icon={\n metric.icon ?? (\n <span className=\"font-medium text-xs\">\n {getInitials(metric.name)}\n </span>\n )\n }\n key={metric.id}\n render={<li data-metric={metric.id} />}\n title={metric.name}\n />\n ))}\n </ul>\n )\n}\n",
|
|
27
|
+
"target": "~/packages/ui/src/blocks/application/list/list-1/list-1.tsx"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "blocks/application/list/list-1/types.ts",
|
|
31
|
+
"type": "registry:file",
|
|
32
|
+
"content": "import type { ReactNode } from 'react'\nimport type { ListLoadLabels, ListLoadProps } from '../shared/types'\n\nexport type List1MetricKind = 'currency' | 'number' | 'percent'\n\nexport interface List1Metric {\n change?: number\n description?: string\n icon?: ReactNode\n id: string\n kind?: List1MetricKind\n name: string\n value: number\n}\n\nexport interface List1Labels extends ListLoadLabels {\n emptyDescription: string\n emptyTitle: string\n title: string\n trend: { down: string; flat: string; up: string }\n}\n\nexport interface List1Props extends ListLoadProps {\n className?: string\n currency?: string\n labels?: Partial<List1Labels>\n locale?: string\n metrics: List1Metric[]\n}\n",
|
|
33
|
+
"target": "~/packages/ui/src/blocks/application/list/list-1/types.ts"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "blocks/application/list/shared/labels.ts",
|
|
37
|
+
"type": "registry:file",
|
|
38
|
+
"content": "import type { ListLoadLabels } from './types'\n\nexport const defaultListLoadLabels: Pick<\n ListLoadLabels,\n 'errorDescription' | 'retry'\n> = {\n errorDescription: 'Verifique sua conexão e tente novamente.',\n retry: 'Tentar novamente',\n}\n",
|
|
39
|
+
"target": "~/packages/ui/src/blocks/application/list/shared/labels.ts"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "blocks/application/list/shared/list-load-state.tsx",
|
|
43
|
+
"type": "registry:file",
|
|
44
|
+
"content": "import { Button } from '@tc96/ui/button'\nimport { StateSurface } from '@tc96/ui/patterns/surfaces/state/composition/state-surface/state-surface'\nimport { Skeleton } from '@tc96/ui/skeleton'\nimport { cn } from '@tc96/utils'\nimport type { ReactNode } from 'react'\nimport type { ListLoadLabels, ListLoadProps } from './types'\n\nexport function ListSkeleton({\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=\"list-skeleton\"\n >\n {children}\n </output>\n )\n}\n\nexport function listLoadState({\n error,\n labels,\n onRetry,\n pending,\n skeleton,\n}: Readonly<\n ListLoadProps & { labels: ListLoadLabels; 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\nexport function ListRowsSkeleton({\n count,\n end,\n}: Readonly<{ count: number; end: 'amount' | 'button' | 'icon' }>) {\n return (\n <div className=\"grid gap-2\">\n {Array.from({ length: count }, (_, index) => `row-${index}`).map((id) => (\n <div\n className=\"flex items-center gap-3 rounded-lg border px-3 py-3\"\n key={id}\n >\n <Skeleton className=\"size-8 shrink-0 rounded-md\" />\n <div className=\"flex min-w-0 flex-1 flex-col gap-1.5\">\n <Skeleton className=\"h-4 w-36 max-w-full\" />\n <Skeleton className=\"h-3.5 w-52 max-w-full\" />\n </div>\n {end === 'amount' ? <Skeleton className=\"h-4 w-20 shrink-0\" /> : null}\n {end === 'button' ? <Skeleton className=\"h-8 w-24 shrink-0\" /> : null}\n {end === 'icon' ? <Skeleton className=\"size-8 shrink-0\" /> : null}\n </div>\n ))}\n </div>\n )\n}\n",
|
|
45
|
+
"target": "~/packages/ui/src/blocks/application/list/shared/list-load-state.tsx"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"path": "blocks/application/list/shared/types.ts",
|
|
49
|
+
"type": "registry:file",
|
|
50
|
+
"content": "export interface ListLoadLabels {\n errorDescription: string\n errorTitle: string\n loading: string\n retry: string\n}\n\nexport interface ListLoadProps {\n error?: boolean\n onRetry?: () => void\n pending?: boolean\n}\n",
|
|
51
|
+
"target": "~/packages/ui/src/blocks/application/list/shared/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": "helpers/initials.ts",
|
|
61
|
+
"type": "registry:file",
|
|
62
|
+
"content": "/**\n * Builds the initials shown in an avatar fallback: the first letter of the\n * first words of a label, upper-cased.\n *\n * @param label - A person or entity name; surrounding and repeated whitespace is ignored.\n * @param size - How many words contribute a letter. Defaults to two.\n * @returns The initials, or an empty string for a blank label.\n */\nexport function getInitials(label: string, size = 2): string {\n return label\n .split(/\\s+/)\n .filter(Boolean)\n .slice(0, size)\n .map((part) => part[0])\n .join('')\n .toUpperCase()\n}\n\n/**\n * Picks the text of an avatar fallback: the explicit fallback a person carries,\n * or the initials of its label when there is none.\n *\n * @param person - Anything with a `label` and an optional `fallback`.\n * @param size - How many words contribute a letter when the label is used. Defaults to two.\n * @returns The fallback as given (only `undefined` falls through, so an empty\n * string is kept), otherwise the initials of the label.\n */\nexport function resolveInitials(\n person: { label: string; fallback?: string },\n size = 2,\n): string {\n return person.fallback ?? getInitials(person.label, size)\n}\n",
|
|
63
|
+
"target": "~/packages/ui/src/helpers/initials.ts"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"path": "patterns/list/composition/list/list.tsx",
|
|
67
|
+
"type": "registry:file",
|
|
68
|
+
"content": "'use client'\n\nimport { useRender } from '@base-ui/react/use-render'\nimport { IconFrame } from '@tc96/ui/icon-frame'\nimport { Text } from '@tc96/ui/text'\nimport { cn } from '@tc96/utils'\nimport type { ReactElement } from 'react'\nimport type { ListProps } from '../../core'\nimport {\n listActionsClassName,\n listContentClassName,\n listDescriptionClassName,\n listRootVariants,\n} from '../../lib/variants'\n\nexport function List({\n actions,\n className,\n description,\n icon,\n iconColor,\n render,\n title,\n variant = 'outline',\n}: Readonly<ListProps>): ReactElement {\n return useRender({\n defaultTagName: 'div',\n props: {\n children: (\n <>\n <IconFrame color={iconColor} shape=\"rounded\" size=\"sm\">\n {icon}\n </IconFrame>\n <span className={listContentClassName} data-slot=\"list-content\">\n <Text data-slot=\"list-title\" size=\"sm\" truncate weight=\"medium\">\n {title}\n </Text>\n {description ? (\n <Text\n className={listDescriptionClassName}\n data-slot=\"list-description\"\n foreground=\"muted\"\n size=\"sm\"\n >\n {description}\n </Text>\n ) : null}\n </span>\n {actions ? (\n <span className={listActionsClassName} data-slot=\"list-actions\">\n {actions}\n </span>\n ) : null}\n </>\n ),\n className: cn(listRootVariants({ variant }), className),\n 'data-slot': 'list',\n 'data-variant': variant,\n },\n render,\n })\n}\n",
|
|
69
|
+
"target": "~/packages/ui/src/patterns/list/composition/list/list.tsx"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"path": "patterns/list/core.ts",
|
|
73
|
+
"type": "registry:file",
|
|
74
|
+
"content": "import type { useRender } from '@base-ui/react/use-render'\nimport type { ReactNode } from 'react'\n\nexport const listVariants = ['outline', 'plain'] as const\n\nexport type ListVariant = (typeof listVariants)[number]\n\nexport interface ListProps {\n actions?: ReactNode\n className?: string\n description?: ReactNode\n icon: ReactNode\n iconColor?: string\n render?: useRender.ComponentProps<'div'>['render']\n title: ReactNode\n variant?: ListVariant\n}\n",
|
|
75
|
+
"target": "~/packages/ui/src/patterns/list/core.ts"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"path": "patterns/list/lib/variants.ts",
|
|
79
|
+
"type": "registry:file",
|
|
80
|
+
"content": "import { cva } from 'class-variance-authority'\n\nexport const listRootVariants = cva(\n 'flex w-full min-w-0 items-center gap-3 px-3 py-3 text-start outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring [:is(a,button,label)&]:cursor-pointer [:is(a,button,label)&]:hover:bg-muted/50',\n {\n defaultVariants: { variant: 'outline' },\n variants: {\n variant: {\n outline: 'rounded-lg border [label&]:has-data-checked:border-primary',\n plain: '',\n },\n },\n },\n)\n\nexport const listContentClassName = 'flex min-w-0 flex-1 flex-col'\n\nexport const listDescriptionClassName = 'line-clamp-2'\n\nexport const listActionsClassName = 'flex shrink-0 items-center gap-1'\n",
|
|
81
|
+
"target": "~/packages/ui/src/patterns/list/lib/variants.ts"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"path": "patterns/surfaces/state/composition/state-surface/state-surface.tsx",
|
|
85
|
+
"type": "registry:file",
|
|
86
|
+
"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",
|
|
87
|
+
"target": "~/packages/ui/src/patterns/surfaces/state/composition/state-surface/state-surface.tsx"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"path": "patterns/surfaces/state/core.ts",
|
|
91
|
+
"type": "registry:file",
|
|
92
|
+
"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",
|
|
93
|
+
"target": "~/packages/ui/src/patterns/surfaces/state/core.ts"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"path": "patterns/widgets/shared/amount.tsx",
|
|
97
|
+
"type": "registry:file",
|
|
98
|
+
"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",
|
|
99
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/amount.tsx"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"path": "patterns/widgets/shared/trend-indicator.tsx",
|
|
103
|
+
"type": "registry:file",
|
|
104
|
+
"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",
|
|
105
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/trend-indicator.tsx"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"path": "patterns/widgets/types/index.ts",
|
|
109
|
+
"type": "registry:file",
|
|
110
|
+
"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",
|
|
111
|
+
"target": "~/packages/ui/src/patterns/widgets/types/index.ts"
|
|
112
|
+
}
|
|
113
|
+
],
|
|
114
|
+
"dependencies": [
|
|
115
|
+
"@base-ui/react@1.8.0",
|
|
116
|
+
"@phosphor-icons/react@2.1.10",
|
|
117
|
+
"class-variance-authority@0.7.1",
|
|
118
|
+
"react@19.1.1"
|
|
119
|
+
],
|
|
120
|
+
"registryDependencies": [
|
|
121
|
+
"@ui/badge",
|
|
122
|
+
"@ui/button",
|
|
123
|
+
"@ui/empty",
|
|
124
|
+
"@ui/icon-frame",
|
|
125
|
+
"@ui/skeleton",
|
|
126
|
+
"@ui/text"
|
|
127
|
+
],
|
|
128
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json"
|
|
129
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "list-2",
|
|
3
|
+
"type": "registry:block",
|
|
4
|
+
"files": [
|
|
5
|
+
{
|
|
6
|
+
"path": "blocks/application/list/list-2/index.ts",
|
|
7
|
+
"type": "registry:file",
|
|
8
|
+
"content": "export { List2 } from './list-2'\nexport type {\n List2Entry,\n List2Labels,\n List2Props,\n List2Range,\n} from './types'\n",
|
|
9
|
+
"target": "~/packages/ui/src/blocks/application/list/list-2/index.ts"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "blocks/application/list/list-2/labels.ts",
|
|
13
|
+
"type": "registry:file",
|
|
14
|
+
"content": "import { defaultListLoadLabels } from '../shared/labels'\nimport type { List2Labels } from './types'\n\nexport const defaultList2Labels: List2Labels = {\n ...defaultListLoadLabels,\n errorTitle: 'Não foi possível carregar o ranking',\n loading: 'Carregando ranking',\n emptyDescription: 'O ranking aparece aqui quando houver vendas no período.',\n emptyTitle: 'Nenhum resultado no período',\n range: 'Período',\n ranges: {\n '7d': 'Últimos 7 dias',\n '12m': 'Últimos 12 meses',\n '30d': 'Últimos 30 dias',\n },\n rank: (position) => `Posição ${position}`,\n title: 'Ranking de vendedores',\n}\n",
|
|
15
|
+
"target": "~/packages/ui/src/blocks/application/list/list-2/labels.ts"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "blocks/application/list/list-2/list-2-skeleton.tsx",
|
|
19
|
+
"type": "registry:file",
|
|
20
|
+
"content": "import { ListRowsSkeleton, ListSkeleton } from '../shared/list-load-state'\n\nexport function List2Skeleton({ label }: Readonly<{ label: string }>) {\n return (\n <ListSkeleton label={label}>\n <ListRowsSkeleton count={5} end=\"amount\" />\n </ListSkeleton>\n )\n}\n",
|
|
21
|
+
"target": "~/packages/ui/src/blocks/application/list/list-2/list-2-skeleton.tsx"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "blocks/application/list/list-2/list-2.tsx",
|
|
25
|
+
"type": "registry:file",
|
|
26
|
+
"content": "import { formatAmount } from '@tc96/ui/helpers/format'\nimport { getInitials } from '@tc96/ui/helpers/initials'\nimport { List } from '@tc96/ui/patterns/list/composition/list/list'\nimport { StateSurface } from '@tc96/ui/patterns/surfaces/state/composition/state-surface/state-surface'\nimport { Amount } from '@tc96/ui/patterns/widgets/shared/amount'\nimport {\n Select,\n SelectItem,\n SelectPopup,\n SelectTrigger,\n SelectValue,\n} from '@tc96/ui/select'\nimport { cn } from '@tc96/utils'\nimport { listLoadState } from '../shared/list-load-state'\nimport { defaultList2Labels } from './labels'\nimport { List2Skeleton } from './list-2-skeleton'\nimport type { List2Props, List2Range } from './types'\n\nconst defaultRanges: List2Range[] = ['7d', '30d', '12m']\n\nexport function List2({\n error,\n onRetry,\n pending,\n className,\n currency = 'BRL',\n entries,\n labels: labelsProp,\n locale = 'pt-BR',\n onRangeChange,\n range,\n ranges = defaultRanges,\n}: Readonly<List2Props>) {\n const labels = { ...defaultList2Labels, ...labelsProp }\n const loadState = listLoadState({\n error,\n labels,\n onRetry,\n pending,\n skeleton: <List2Skeleton label={labels.loading} />,\n })\n const items = ranges.map((value) => ({\n label: labels.ranges[value],\n value,\n }))\n\n return (\n <section aria-label={labels.title} className={cn('grid gap-3', className)}>\n <div className=\"flex flex-wrap items-center justify-between gap-3\">\n <h3 className=\"font-medium text-base\">{labels.title}</h3>\n <Select\n items={items}\n onValueChange={(next) => {\n if (next) onRangeChange?.(next as List2Range)\n }}\n value={range}\n >\n <SelectTrigger aria-label={labels.range} className=\"w-48\" 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 </div>\n {loadState ??\n (entries.length === 0 ? (\n <StateSurface\n description={labels.emptyDescription}\n kind=\"empty\"\n title={labels.emptyTitle}\n />\n ) : (\n <ol className=\"grid list-none gap-2\">\n {entries.map((entry, index) => (\n <li\n className=\"flex items-center gap-3\"\n data-entry={entry.id}\n key={entry.id}\n >\n <span className=\"w-6 shrink-0 text-center font-medium text-muted-foreground text-sm tabular-nums\">\n <span aria-hidden=\"true\">{index + 1}</span>\n <span className=\"sr-only\">{labels.rank(index + 1)}</span>\n </span>\n <List\n actions={\n <span className=\"flex items-center gap-3 text-sm\">\n <Amount\n className=\"font-medium\"\n format={{ currency, locale, style: 'currency' }}\n value={entry.amount}\n />\n <span\n className=\"w-12 text-end text-muted-foreground tabular-nums\"\n data-slot=\"list-2-share\"\n >\n {formatAmount(entry.share, {\n locale,\n maximumFractionDigits: 1,\n style: 'percent',\n })}\n </span>\n </span>\n }\n icon={\n entry.icon ?? (\n <span className=\"font-medium text-xs\">\n {getInitials(entry.name)}\n </span>\n )\n }\n title={entry.name}\n />\n </li>\n ))}\n </ol>\n ))}\n </section>\n )\n}\n",
|
|
27
|
+
"target": "~/packages/ui/src/blocks/application/list/list-2/list-2.tsx"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "blocks/application/list/list-2/types.ts",
|
|
31
|
+
"type": "registry:file",
|
|
32
|
+
"content": "import type { ReactNode } from 'react'\nimport type { ListLoadLabels, ListLoadProps } from '../shared/types'\n\nexport type List2Range = '7d' | '30d' | '12m'\n\nexport interface List2Entry {\n amount: number\n icon?: ReactNode\n id: string\n name: string\n share: number\n}\n\nexport interface List2Labels extends ListLoadLabels {\n emptyDescription: string\n emptyTitle: string\n range: string\n ranges: Record<List2Range, string>\n rank: (position: number) => string\n title: string\n}\n\nexport interface List2Props extends ListLoadProps {\n className?: string\n currency?: string\n entries: List2Entry[]\n labels?: Partial<List2Labels>\n locale?: string\n onRangeChange?: (range: List2Range) => void\n range: List2Range\n ranges?: List2Range[]\n}\n",
|
|
33
|
+
"target": "~/packages/ui/src/blocks/application/list/list-2/types.ts"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "blocks/application/list/shared/labels.ts",
|
|
37
|
+
"type": "registry:file",
|
|
38
|
+
"content": "import type { ListLoadLabels } from './types'\n\nexport const defaultListLoadLabels: Pick<\n ListLoadLabels,\n 'errorDescription' | 'retry'\n> = {\n errorDescription: 'Verifique sua conexão e tente novamente.',\n retry: 'Tentar novamente',\n}\n",
|
|
39
|
+
"target": "~/packages/ui/src/blocks/application/list/shared/labels.ts"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "blocks/application/list/shared/list-load-state.tsx",
|
|
43
|
+
"type": "registry:file",
|
|
44
|
+
"content": "import { Button } from '@tc96/ui/button'\nimport { StateSurface } from '@tc96/ui/patterns/surfaces/state/composition/state-surface/state-surface'\nimport { Skeleton } from '@tc96/ui/skeleton'\nimport { cn } from '@tc96/utils'\nimport type { ReactNode } from 'react'\nimport type { ListLoadLabels, ListLoadProps } from './types'\n\nexport function ListSkeleton({\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=\"list-skeleton\"\n >\n {children}\n </output>\n )\n}\n\nexport function listLoadState({\n error,\n labels,\n onRetry,\n pending,\n skeleton,\n}: Readonly<\n ListLoadProps & { labels: ListLoadLabels; 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\nexport function ListRowsSkeleton({\n count,\n end,\n}: Readonly<{ count: number; end: 'amount' | 'button' | 'icon' }>) {\n return (\n <div className=\"grid gap-2\">\n {Array.from({ length: count }, (_, index) => `row-${index}`).map((id) => (\n <div\n className=\"flex items-center gap-3 rounded-lg border px-3 py-3\"\n key={id}\n >\n <Skeleton className=\"size-8 shrink-0 rounded-md\" />\n <div className=\"flex min-w-0 flex-1 flex-col gap-1.5\">\n <Skeleton className=\"h-4 w-36 max-w-full\" />\n <Skeleton className=\"h-3.5 w-52 max-w-full\" />\n </div>\n {end === 'amount' ? <Skeleton className=\"h-4 w-20 shrink-0\" /> : null}\n {end === 'button' ? <Skeleton className=\"h-8 w-24 shrink-0\" /> : null}\n {end === 'icon' ? <Skeleton className=\"size-8 shrink-0\" /> : null}\n </div>\n ))}\n </div>\n )\n}\n",
|
|
45
|
+
"target": "~/packages/ui/src/blocks/application/list/shared/list-load-state.tsx"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"path": "blocks/application/list/shared/types.ts",
|
|
49
|
+
"type": "registry:file",
|
|
50
|
+
"content": "export interface ListLoadLabels {\n errorDescription: string\n errorTitle: string\n loading: string\n retry: string\n}\n\nexport interface ListLoadProps {\n error?: boolean\n onRetry?: () => void\n pending?: boolean\n}\n",
|
|
51
|
+
"target": "~/packages/ui/src/blocks/application/list/shared/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": "helpers/initials.ts",
|
|
61
|
+
"type": "registry:file",
|
|
62
|
+
"content": "/**\n * Builds the initials shown in an avatar fallback: the first letter of the\n * first words of a label, upper-cased.\n *\n * @param label - A person or entity name; surrounding and repeated whitespace is ignored.\n * @param size - How many words contribute a letter. Defaults to two.\n * @returns The initials, or an empty string for a blank label.\n */\nexport function getInitials(label: string, size = 2): string {\n return label\n .split(/\\s+/)\n .filter(Boolean)\n .slice(0, size)\n .map((part) => part[0])\n .join('')\n .toUpperCase()\n}\n\n/**\n * Picks the text of an avatar fallback: the explicit fallback a person carries,\n * or the initials of its label when there is none.\n *\n * @param person - Anything with a `label` and an optional `fallback`.\n * @param size - How many words contribute a letter when the label is used. Defaults to two.\n * @returns The fallback as given (only `undefined` falls through, so an empty\n * string is kept), otherwise the initials of the label.\n */\nexport function resolveInitials(\n person: { label: string; fallback?: string },\n size = 2,\n): string {\n return person.fallback ?? getInitials(person.label, size)\n}\n",
|
|
63
|
+
"target": "~/packages/ui/src/helpers/initials.ts"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"path": "patterns/list/composition/list/list.tsx",
|
|
67
|
+
"type": "registry:file",
|
|
68
|
+
"content": "'use client'\n\nimport { useRender } from '@base-ui/react/use-render'\nimport { IconFrame } from '@tc96/ui/icon-frame'\nimport { Text } from '@tc96/ui/text'\nimport { cn } from '@tc96/utils'\nimport type { ReactElement } from 'react'\nimport type { ListProps } from '../../core'\nimport {\n listActionsClassName,\n listContentClassName,\n listDescriptionClassName,\n listRootVariants,\n} from '../../lib/variants'\n\nexport function List({\n actions,\n className,\n description,\n icon,\n iconColor,\n render,\n title,\n variant = 'outline',\n}: Readonly<ListProps>): ReactElement {\n return useRender({\n defaultTagName: 'div',\n props: {\n children: (\n <>\n <IconFrame color={iconColor} shape=\"rounded\" size=\"sm\">\n {icon}\n </IconFrame>\n <span className={listContentClassName} data-slot=\"list-content\">\n <Text data-slot=\"list-title\" size=\"sm\" truncate weight=\"medium\">\n {title}\n </Text>\n {description ? (\n <Text\n className={listDescriptionClassName}\n data-slot=\"list-description\"\n foreground=\"muted\"\n size=\"sm\"\n >\n {description}\n </Text>\n ) : null}\n </span>\n {actions ? (\n <span className={listActionsClassName} data-slot=\"list-actions\">\n {actions}\n </span>\n ) : null}\n </>\n ),\n className: cn(listRootVariants({ variant }), className),\n 'data-slot': 'list',\n 'data-variant': variant,\n },\n render,\n })\n}\n",
|
|
69
|
+
"target": "~/packages/ui/src/patterns/list/composition/list/list.tsx"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"path": "patterns/list/core.ts",
|
|
73
|
+
"type": "registry:file",
|
|
74
|
+
"content": "import type { useRender } from '@base-ui/react/use-render'\nimport type { ReactNode } from 'react'\n\nexport const listVariants = ['outline', 'plain'] as const\n\nexport type ListVariant = (typeof listVariants)[number]\n\nexport interface ListProps {\n actions?: ReactNode\n className?: string\n description?: ReactNode\n icon: ReactNode\n iconColor?: string\n render?: useRender.ComponentProps<'div'>['render']\n title: ReactNode\n variant?: ListVariant\n}\n",
|
|
75
|
+
"target": "~/packages/ui/src/patterns/list/core.ts"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"path": "patterns/list/lib/variants.ts",
|
|
79
|
+
"type": "registry:file",
|
|
80
|
+
"content": "import { cva } from 'class-variance-authority'\n\nexport const listRootVariants = cva(\n 'flex w-full min-w-0 items-center gap-3 px-3 py-3 text-start outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring [:is(a,button,label)&]:cursor-pointer [:is(a,button,label)&]:hover:bg-muted/50',\n {\n defaultVariants: { variant: 'outline' },\n variants: {\n variant: {\n outline: 'rounded-lg border [label&]:has-data-checked:border-primary',\n plain: '',\n },\n },\n },\n)\n\nexport const listContentClassName = 'flex min-w-0 flex-1 flex-col'\n\nexport const listDescriptionClassName = 'line-clamp-2'\n\nexport const listActionsClassName = 'flex shrink-0 items-center gap-1'\n",
|
|
81
|
+
"target": "~/packages/ui/src/patterns/list/lib/variants.ts"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"path": "patterns/surfaces/state/composition/state-surface/state-surface.tsx",
|
|
85
|
+
"type": "registry:file",
|
|
86
|
+
"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",
|
|
87
|
+
"target": "~/packages/ui/src/patterns/surfaces/state/composition/state-surface/state-surface.tsx"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"path": "patterns/surfaces/state/core.ts",
|
|
91
|
+
"type": "registry:file",
|
|
92
|
+
"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",
|
|
93
|
+
"target": "~/packages/ui/src/patterns/surfaces/state/core.ts"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"path": "patterns/widgets/shared/amount.tsx",
|
|
97
|
+
"type": "registry:file",
|
|
98
|
+
"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",
|
|
99
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/amount.tsx"
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
"dependencies": [
|
|
103
|
+
"@base-ui/react@1.8.0",
|
|
104
|
+
"@phosphor-icons/react@2.1.10",
|
|
105
|
+
"class-variance-authority@0.7.1",
|
|
106
|
+
"react@19.1.1"
|
|
107
|
+
],
|
|
108
|
+
"registryDependencies": [
|
|
109
|
+
"@ui/button",
|
|
110
|
+
"@ui/empty",
|
|
111
|
+
"@ui/icon-frame",
|
|
112
|
+
"@ui/select",
|
|
113
|
+
"@ui/skeleton",
|
|
114
|
+
"@ui/text"
|
|
115
|
+
],
|
|
116
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json"
|
|
117
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "list-3",
|
|
3
|
+
"type": "registry:block",
|
|
4
|
+
"files": [
|
|
5
|
+
{
|
|
6
|
+
"path": "blocks/application/list/list-3/index.ts",
|
|
7
|
+
"type": "registry:file",
|
|
8
|
+
"content": "export { List3 } from './list-3'\nexport type {\n List3Labels,\n List3Period,\n List3Props,\n List3Transaction,\n} from './types'\n",
|
|
9
|
+
"target": "~/packages/ui/src/blocks/application/list/list-3/index.ts"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "blocks/application/list/list-3/labels.ts",
|
|
13
|
+
"type": "registry:file",
|
|
14
|
+
"content": "import { defaultListLoadLabels } from '../shared/labels'\nimport type { List3Labels } from './types'\n\nexport const defaultList3Labels: List3Labels = {\n ...defaultListLoadLabels,\n errorTitle: 'Não foi possível carregar as transações',\n loading: 'Carregando transações',\n credit: 'Entrada',\n debit: 'Saída',\n emptyDescription: 'As transações aparecem aqui quando houver movimentações.',\n emptyTitle: 'Nenhuma transação no período',\n period: 'Período',\n periods: { month: 'Mês', week: 'Semana', year: 'Ano' },\n title: 'Transações',\n}\n",
|
|
15
|
+
"target": "~/packages/ui/src/blocks/application/list/list-3/labels.ts"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "blocks/application/list/list-3/list-3-skeleton.tsx",
|
|
19
|
+
"type": "registry:file",
|
|
20
|
+
"content": "import { ListRowsSkeleton, ListSkeleton } from '../shared/list-load-state'\n\nexport function List3Skeleton({ label }: Readonly<{ label: string }>) {\n return (\n <ListSkeleton label={label}>\n <ListRowsSkeleton count={5} end=\"amount\" />\n </ListSkeleton>\n )\n}\n",
|
|
21
|
+
"target": "~/packages/ui/src/blocks/application/list/list-3/list-3-skeleton.tsx"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "blocks/application/list/list-3/list-3.tsx",
|
|
25
|
+
"type": "registry:file",
|
|
26
|
+
"content": "import { ArrowDownLeftIcon, ArrowUpRightIcon } from '@phosphor-icons/react'\nimport { formatShortDate, parseIsoDate } from '@tc96/ui/helpers/date'\nimport { List } from '@tc96/ui/patterns/list/composition/list/list'\nimport { StateSurface } from '@tc96/ui/patterns/surfaces/state/composition/state-surface/state-surface'\nimport { Amount } from '@tc96/ui/patterns/widgets/shared/amount'\nimport { Tabs, TabsList, TabsTab } from '@tc96/ui/tabs'\nimport { cn } from '@tc96/utils'\nimport { listLoadState } from '../shared/list-load-state'\nimport { defaultList3Labels } from './labels'\nimport { List3Skeleton } from './list-3-skeleton'\nimport type { List3Period, List3Props } from './types'\n\nconst defaultPeriods: List3Period[] = ['week', 'month', 'year']\n\nfunction formatDay(value: string, locale: string) {\n const date = parseIsoDate(value)\n return date ? formatShortDate(date, locale, 'UTC') : value\n}\n\nexport function List3({\n error,\n onRetry,\n pending,\n className,\n currency = 'BRL',\n labels: labelsProp,\n locale = 'pt-BR',\n onPeriodChange,\n period,\n periods = defaultPeriods,\n transactions,\n}: Readonly<List3Props>) {\n const labels = { ...defaultList3Labels, ...labelsProp }\n const loadState = listLoadState({\n error,\n labels,\n onRetry,\n pending,\n skeleton: <List3Skeleton label={labels.loading} />,\n })\n\n return (\n <section aria-label={labels.title} className={cn('grid gap-3', className)}>\n <div className=\"flex flex-wrap items-center justify-between gap-3\">\n <h3 className=\"font-medium text-base\">{labels.title}</h3>\n <Tabs\n onValueChange={(next) => onPeriodChange?.(next as List3Period)}\n value={period}\n >\n <TabsList aria-label={labels.period}>\n {periods.map((value) => (\n <TabsTab key={value} value={value}>\n {labels.periods[value]}\n </TabsTab>\n ))}\n </TabsList>\n </Tabs>\n </div>\n {loadState ??\n (transactions.length === 0 ? (\n <StateSurface\n description={labels.emptyDescription}\n kind=\"empty\"\n title={labels.emptyTitle}\n />\n ) : (\n <ul className=\"grid list-none gap-2\">\n {transactions.map((transaction) => {\n const kind = transaction.amount < 0 ? 'debit' : 'credit'\n const DefaultIcon =\n kind === 'debit' ? ArrowUpRightIcon : ArrowDownLeftIcon\n\n return (\n <List\n actions={\n <span\n className={cn(\n 'text-sm',\n kind === 'debit'\n ? 'text-destructive-foreground'\n : 'text-success-foreground',\n )}\n data-kind={kind}\n >\n <span className=\"sr-only\">{labels[kind]} </span>\n <Amount\n className=\"font-medium\"\n format={{\n currency,\n locale,\n signDisplay: 'always',\n style: 'currency',\n }}\n value={transaction.amount}\n />\n </span>\n }\n description={formatDay(transaction.date, locale)}\n icon={transaction.icon ?? <DefaultIcon aria-hidden=\"true\" />}\n key={transaction.id}\n render={<li data-transaction={transaction.id} />}\n title={transaction.description}\n />\n )\n })}\n </ul>\n ))}\n </section>\n )\n}\n",
|
|
27
|
+
"target": "~/packages/ui/src/blocks/application/list/list-3/list-3.tsx"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "blocks/application/list/list-3/types.ts",
|
|
31
|
+
"type": "registry:file",
|
|
32
|
+
"content": "import type { ReactNode } from 'react'\nimport type { ListLoadLabels, ListLoadProps } from '../shared/types'\n\nexport type List3Period = 'week' | 'month' | 'year'\n\nexport interface List3Transaction {\n amount: number\n date: string\n description: string\n icon?: ReactNode\n id: string\n}\n\nexport interface List3Labels extends ListLoadLabels {\n credit: string\n debit: string\n emptyDescription: string\n emptyTitle: string\n period: string\n periods: Record<List3Period, string>\n title: string\n}\n\nexport interface List3Props extends ListLoadProps {\n className?: string\n currency?: string\n labels?: Partial<List3Labels>\n locale?: string\n onPeriodChange?: (period: List3Period) => void\n period: List3Period\n periods?: List3Period[]\n transactions: List3Transaction[]\n}\n",
|
|
33
|
+
"target": "~/packages/ui/src/blocks/application/list/list-3/types.ts"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "blocks/application/list/shared/labels.ts",
|
|
37
|
+
"type": "registry:file",
|
|
38
|
+
"content": "import type { ListLoadLabels } from './types'\n\nexport const defaultListLoadLabels: Pick<\n ListLoadLabels,\n 'errorDescription' | 'retry'\n> = {\n errorDescription: 'Verifique sua conexão e tente novamente.',\n retry: 'Tentar novamente',\n}\n",
|
|
39
|
+
"target": "~/packages/ui/src/blocks/application/list/shared/labels.ts"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "blocks/application/list/shared/list-load-state.tsx",
|
|
43
|
+
"type": "registry:file",
|
|
44
|
+
"content": "import { Button } from '@tc96/ui/button'\nimport { StateSurface } from '@tc96/ui/patterns/surfaces/state/composition/state-surface/state-surface'\nimport { Skeleton } from '@tc96/ui/skeleton'\nimport { cn } from '@tc96/utils'\nimport type { ReactNode } from 'react'\nimport type { ListLoadLabels, ListLoadProps } from './types'\n\nexport function ListSkeleton({\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=\"list-skeleton\"\n >\n {children}\n </output>\n )\n}\n\nexport function listLoadState({\n error,\n labels,\n onRetry,\n pending,\n skeleton,\n}: Readonly<\n ListLoadProps & { labels: ListLoadLabels; 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\nexport function ListRowsSkeleton({\n count,\n end,\n}: Readonly<{ count: number; end: 'amount' | 'button' | 'icon' }>) {\n return (\n <div className=\"grid gap-2\">\n {Array.from({ length: count }, (_, index) => `row-${index}`).map((id) => (\n <div\n className=\"flex items-center gap-3 rounded-lg border px-3 py-3\"\n key={id}\n >\n <Skeleton className=\"size-8 shrink-0 rounded-md\" />\n <div className=\"flex min-w-0 flex-1 flex-col gap-1.5\">\n <Skeleton className=\"h-4 w-36 max-w-full\" />\n <Skeleton className=\"h-3.5 w-52 max-w-full\" />\n </div>\n {end === 'amount' ? <Skeleton className=\"h-4 w-20 shrink-0\" /> : null}\n {end === 'button' ? <Skeleton className=\"h-8 w-24 shrink-0\" /> : null}\n {end === 'icon' ? <Skeleton className=\"size-8 shrink-0\" /> : null}\n </div>\n ))}\n </div>\n )\n}\n",
|
|
45
|
+
"target": "~/packages/ui/src/blocks/application/list/shared/list-load-state.tsx"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"path": "blocks/application/list/shared/types.ts",
|
|
49
|
+
"type": "registry:file",
|
|
50
|
+
"content": "export interface ListLoadLabels {\n errorDescription: string\n errorTitle: string\n loading: string\n retry: string\n}\n\nexport interface ListLoadProps {\n error?: boolean\n onRetry?: () => void\n pending?: boolean\n}\n",
|
|
51
|
+
"target": "~/packages/ui/src/blocks/application/list/shared/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/list/composition/list/list.tsx",
|
|
79
|
+
"type": "registry:file",
|
|
80
|
+
"content": "'use client'\n\nimport { useRender } from '@base-ui/react/use-render'\nimport { IconFrame } from '@tc96/ui/icon-frame'\nimport { Text } from '@tc96/ui/text'\nimport { cn } from '@tc96/utils'\nimport type { ReactElement } from 'react'\nimport type { ListProps } from '../../core'\nimport {\n listActionsClassName,\n listContentClassName,\n listDescriptionClassName,\n listRootVariants,\n} from '../../lib/variants'\n\nexport function List({\n actions,\n className,\n description,\n icon,\n iconColor,\n render,\n title,\n variant = 'outline',\n}: Readonly<ListProps>): ReactElement {\n return useRender({\n defaultTagName: 'div',\n props: {\n children: (\n <>\n <IconFrame color={iconColor} shape=\"rounded\" size=\"sm\">\n {icon}\n </IconFrame>\n <span className={listContentClassName} data-slot=\"list-content\">\n <Text data-slot=\"list-title\" size=\"sm\" truncate weight=\"medium\">\n {title}\n </Text>\n {description ? (\n <Text\n className={listDescriptionClassName}\n data-slot=\"list-description\"\n foreground=\"muted\"\n size=\"sm\"\n >\n {description}\n </Text>\n ) : null}\n </span>\n {actions ? (\n <span className={listActionsClassName} data-slot=\"list-actions\">\n {actions}\n </span>\n ) : null}\n </>\n ),\n className: cn(listRootVariants({ variant }), className),\n 'data-slot': 'list',\n 'data-variant': variant,\n },\n render,\n })\n}\n",
|
|
81
|
+
"target": "~/packages/ui/src/patterns/list/composition/list/list.tsx"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"path": "patterns/list/core.ts",
|
|
85
|
+
"type": "registry:file",
|
|
86
|
+
"content": "import type { useRender } from '@base-ui/react/use-render'\nimport type { ReactNode } from 'react'\n\nexport const listVariants = ['outline', 'plain'] as const\n\nexport type ListVariant = (typeof listVariants)[number]\n\nexport interface ListProps {\n actions?: ReactNode\n className?: string\n description?: ReactNode\n icon: ReactNode\n iconColor?: string\n render?: useRender.ComponentProps<'div'>['render']\n title: ReactNode\n variant?: ListVariant\n}\n",
|
|
87
|
+
"target": "~/packages/ui/src/patterns/list/core.ts"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"path": "patterns/list/lib/variants.ts",
|
|
91
|
+
"type": "registry:file",
|
|
92
|
+
"content": "import { cva } from 'class-variance-authority'\n\nexport const listRootVariants = cva(\n 'flex w-full min-w-0 items-center gap-3 px-3 py-3 text-start outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring [:is(a,button,label)&]:cursor-pointer [:is(a,button,label)&]:hover:bg-muted/50',\n {\n defaultVariants: { variant: 'outline' },\n variants: {\n variant: {\n outline: 'rounded-lg border [label&]:has-data-checked:border-primary',\n plain: '',\n },\n },\n },\n)\n\nexport const listContentClassName = 'flex min-w-0 flex-1 flex-col'\n\nexport const listDescriptionClassName = 'line-clamp-2'\n\nexport const listActionsClassName = 'flex shrink-0 items-center gap-1'\n",
|
|
93
|
+
"target": "~/packages/ui/src/patterns/list/lib/variants.ts"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"path": "patterns/surfaces/state/composition/state-surface/state-surface.tsx",
|
|
97
|
+
"type": "registry:file",
|
|
98
|
+
"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",
|
|
99
|
+
"target": "~/packages/ui/src/patterns/surfaces/state/composition/state-surface/state-surface.tsx"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"path": "patterns/surfaces/state/core.ts",
|
|
103
|
+
"type": "registry:file",
|
|
104
|
+
"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",
|
|
105
|
+
"target": "~/packages/ui/src/patterns/surfaces/state/core.ts"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"path": "patterns/widgets/shared/amount.tsx",
|
|
109
|
+
"type": "registry:file",
|
|
110
|
+
"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",
|
|
111
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/amount.tsx"
|
|
112
|
+
}
|
|
113
|
+
],
|
|
114
|
+
"dependencies": [
|
|
115
|
+
"@base-ui/react@1.8.0",
|
|
116
|
+
"@phosphor-icons/react@2.1.10",
|
|
117
|
+
"class-variance-authority@0.7.1",
|
|
118
|
+
"react@19.1.1"
|
|
119
|
+
],
|
|
120
|
+
"registryDependencies": [
|
|
121
|
+
"@ui/button",
|
|
122
|
+
"@ui/empty",
|
|
123
|
+
"@ui/icon-frame",
|
|
124
|
+
"@ui/skeleton",
|
|
125
|
+
"@ui/tabs",
|
|
126
|
+
"@ui/text"
|
|
127
|
+
],
|
|
128
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json"
|
|
129
|
+
}
|