@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,319 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "widgets",
|
|
3
|
+
"type": "registry:block",
|
|
4
|
+
"files": [
|
|
5
|
+
{
|
|
6
|
+
"path": "helpers/calendar-date.ts",
|
|
7
|
+
"type": "registry:file",
|
|
8
|
+
"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",
|
|
9
|
+
"target": "~/packages/ui/src/helpers/calendar-date.ts"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"path": "helpers/clipboard.ts",
|
|
13
|
+
"type": "registry:file",
|
|
14
|
+
"content": "/**\n * Writes text to the system clipboard through the async Clipboard API.\n *\n * @param value - The text to copy.\n * @returns The pending write, or `undefined` when the browser exposes no\n * clipboard (insecure context or unsupported environment).\n */\nexport function copyToClipboard(value: string): Promise<void> | undefined {\n return navigator.clipboard?.writeText(value)\n}\n",
|
|
15
|
+
"target": "~/packages/ui/src/helpers/clipboard.ts"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "helpers/format.ts",
|
|
19
|
+
"type": "registry:file",
|
|
20
|
+
"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",
|
|
21
|
+
"target": "~/packages/ui/src/helpers/format.ts"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "helpers/initials.ts",
|
|
25
|
+
"type": "registry:file",
|
|
26
|
+
"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",
|
|
27
|
+
"target": "~/packages/ui/src/helpers/initials.ts"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "helpers/time.ts",
|
|
31
|
+
"type": "registry:file",
|
|
32
|
+
"content": "export interface TimeOfDayOptions {\n hourCycle?: 'h11' | 'h12' | 'h23' | 'h24'\n locale?: string\n timeZone?: string\n}\n\nexport interface TimeOfDayParts {\n dayPeriod: string\n hourMinute: string\n second: string\n}\n\nfunction timeFormatter(\n options: TimeOfDayOptions,\n withSeconds: boolean,\n): Intl.DateTimeFormat {\n return new Intl.DateTimeFormat(options.locale ?? 'en-US', {\n hour: 'numeric',\n minute: '2-digit',\n ...(withSeconds ? { second: '2-digit' } : {}),\n ...(options.hourCycle ? { hourCycle: options.hourCycle } : {}),\n ...(options.timeZone ? { timeZone: options.timeZone } : {}),\n })\n}\n\n/**\n * Formats the wall-clock time of an instant, such as `9:11 PM` or `21:11`.\n *\n * @param date - The instant to format.\n * @param options - Locale (defaults to `en-US`), IANA time zone (defaults to\n * the runtime's zone) and hour cycle (defaults to the locale's).\n */\nexport function formatTimeOfDay(\n date: Date,\n options: TimeOfDayOptions = {},\n): string {\n return timeFormatter(options, false).format(date)\n}\n\n/**\n * Splits a wall-clock time into the pieces a clock renders at different\n * weights: hour and minute, the seconds with their separator, and the day\n * period with its leading space.\n *\n * @param date - The instant to split.\n * @param options - See {@link formatTimeOfDay}.\n * @returns For `en-US` at 21:11:20, `{ hourMinute: '9:11', second: ':20',\n * dayPeriod: ' PM' }`; `second` and `dayPeriod` are empty when the locale\n * omits them.\n */\nexport function splitTimeOfDay(\n date: Date,\n options: TimeOfDayOptions = {},\n): TimeOfDayParts {\n const parts = timeFormatter(options, true).formatToParts(date)\n const secondIndex = parts.findIndex((part) => part.type === 'second')\n const periodIndex = parts.findIndex((part) => part.type === 'dayPeriod')\n const text = (from: number, to: number) =>\n parts\n .slice(from, to)\n .map((part) => part.value)\n .join('')\n const hourMinuteEnd =\n secondIndex > 0\n ? secondIndex - 1\n : periodIndex > 0\n ? periodIndex\n : parts.length\n const periodStart = periodIndex > 0 ? periodIndex - 1 : parts.length\n return {\n dayPeriod: text(periodStart, parts.length).replace(/^\\s+/, ' '),\n hourMinute: text(0, hourMinuteEnd).trim(),\n second:\n secondIndex > 0\n ? text(secondIndex - 1, Math.min(periodStart, secondIndex + 1))\n : '',\n }\n}\n",
|
|
33
|
+
"target": "~/packages/ui/src/helpers/time.ts"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "patterns/widgets/crm/activity-feed-widget.tsx",
|
|
37
|
+
"type": "registry:file",
|
|
38
|
+
"content": "import { CardPanel } from '@tc96/ui/card'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId } from 'react'\nimport type { WidgetExpandProps } from '../shared/expandable-list'\nimport { WidgetHeader } from '../shared/widget-header'\nimport { WidgetShell } from '../shared/widget-shell'\nimport { type Activity, ActivityTimeline } from './activity-timeline'\n\nexport interface ActivityFeedWidgetProps\n extends Omit<ComponentProps<'div'>, 'children' | 'title'> {\n action?: ReactNode\n activities: readonly Activity[]\n expand?: WidgetExpandProps\n emptyLabel?: ReactNode\n listLabel?: string\n title: ReactNode\n}\n\nexport function ActivityFeedWidget({\n action,\n activities,\n className,\n expand,\n emptyLabel,\n listLabel,\n title,\n ...props\n}: Readonly<ActivityFeedWidgetProps>): ReactElement {\n const titleId = useId()\n\n return (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-widget=\"activity-feed\"\n {...props}\n >\n <WidgetHeader action={action} title={title} titleId={titleId} />\n <CardPanel className=\"grid gap-5 px-5 pb-5\">\n <ActivityTimeline\n activities={activities}\n aria-label={\n listLabel ?? (typeof title === 'string' ? title : 'Atividades')\n }\n {...(emptyLabel === undefined ? {} : { emptyLabel })}\n {...(expand ? { expand } : {})}\n />\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
39
|
+
"target": "~/packages/ui/src/patterns/widgets/crm/activity-feed-widget.tsx"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "patterns/widgets/crm/activity-timeline.tsx",
|
|
43
|
+
"type": "registry:file",
|
|
44
|
+
"content": "import { Avatar, AvatarFallback, AvatarImage } from '@tc96/ui/avatar'\nimport { resolveInitials } from '@tc96/ui/helpers/initials'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport type { AvatarStackPerson } from '../shared/avatar-stack'\nimport {\n ExpandableList,\n type WidgetExpandProps,\n} from '../shared/expandable-list'\nimport type { WidgetTone } from '../types'\n\nexport interface Activity {\n description?: ReactNode\n icon?: ReactNode\n id: string\n person: AvatarStackPerson\n timeLabel: ReactNode\n title: ReactNode\n tone?: WidgetTone\n}\n\nconst iconTones: Record<WidgetTone, string> = {\n destructive: 'text-destructive-foreground',\n info: 'text-info-foreground',\n success: 'text-success-foreground',\n warning: 'text-warning-foreground',\n}\n\nexport interface ActivityTimelineProps\n extends Omit<ComponentProps<'ol'>, 'children'> {\n 'aria-label': string\n activities: readonly Activity[]\n emptyLabel?: ReactNode\n expand?: WidgetExpandProps\n}\n\nexport function ActivityTimeline({\n activities,\n className,\n emptyLabel = 'Sem atividades',\n expand,\n ...props\n}: Readonly<ActivityTimelineProps>): ReactElement {\n if (!activities.length)\n return (\n <p\n className={cn('text-muted-foreground text-sm', className)}\n data-slot=\"activity-feed-empty\"\n >\n {emptyLabel}\n </p>\n )\n\n return (\n <ExpandableList items={activities} {...expand}>\n {(shown) => (\n <ol className={className} data-slot=\"activity-feed-list\" {...props}>\n {shown.map((activity) => (\n <li\n className=\"relative grid grid-cols-[auto_1fr] gap-3 pb-5 last:pb-0 not-last:before:absolute not-last:before:start-4 not-last:before:top-9 not-last:before:bottom-0 not-last:before:w-px not-last:before:bg-border/60\"\n data-slot=\"activity-feed-item\"\n key={activity.id}\n >\n <span className=\"relative flex size-8\">\n <span className=\"flex rounded-full border border-input bg-card\">\n <Avatar>\n {activity.person.imageUrl ? (\n <AvatarImage alt=\"\" src={activity.person.imageUrl} />\n ) : null}\n <AvatarFallback>\n {resolveInitials(activity.person)}\n </AvatarFallback>\n </Avatar>\n </span>\n {activity.icon ? (\n <span\n aria-hidden=\"true\"\n className={cn(\n '-end-1.5 -bottom-1.5 absolute inline-flex size-5 items-center justify-center rounded-full bg-muted text-foreground [&_svg:not([class*=size-])]:size-3',\n activity.tone ? iconTones[activity.tone] : undefined,\n )}\n data-slot=\"activity-feed-icon\"\n >\n {activity.icon}\n </span>\n ) : null}\n </span>\n <div className=\"grid min-w-0 gap-1\">\n <div className=\"flex items-baseline justify-between gap-3\">\n <span className=\"min-w-0 text-sm\">\n <span className=\"font-medium\">{activity.person.label}</span>{' '}\n {activity.title}\n </span>\n <span className=\"shrink-0 text-muted-foreground text-xs\">\n {activity.timeLabel}\n </span>\n </div>\n {activity.description ? (\n <p className=\"text-muted-foreground text-sm\">\n {activity.description}\n </p>\n ) : null}\n </div>\n </li>\n ))}\n </ol>\n )}\n </ExpandableList>\n )\n}\n",
|
|
45
|
+
"target": "~/packages/ui/src/patterns/widgets/crm/activity-timeline.tsx"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"path": "patterns/widgets/crm/contact-widget.tsx",
|
|
49
|
+
"type": "registry:file",
|
|
50
|
+
"content": "import {\n ChatCircleIcon,\n EnvelopeSimpleIcon,\n PhoneIcon,\n} from '@phosphor-icons/react'\nimport { Avatar, AvatarFallback, AvatarImage } from '@tc96/ui/avatar'\nimport { Badge } from '@tc96/ui/badge'\nimport { Button } from '@tc96/ui/button'\nimport { CardPanel } from '@tc96/ui/card'\nimport { resolveInitials } from '@tc96/ui/helpers/initials'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId } from 'react'\nimport type { AvatarStackPerson } from '../shared/avatar-stack'\nimport type { WidgetExpandProps } from '../shared/expandable-list'\nimport { WidgetShell } from '../shared/widget-shell'\nimport { type Activity, ActivityTimeline } from './activity-timeline'\n\nexport interface ContactChannelLabels {\n email: string\n phone: string\n whatsapp: string\n}\n\nexport interface ContactTag {\n id: string\n label: ReactNode\n}\n\nexport interface ContactWidgetProps\n extends Omit<ComponentProps<'div'>, 'children' | 'title'> {\n action?: ReactNode\n activities?: readonly Activity[]\n activitiesLabel?: string\n channelLabels?: ContactChannelLabels\n company?: ReactNode\n email?: string\n expand?: WidgetExpandProps\n emptyLabel?: ReactNode\n person: AvatarStackPerson\n phone?: string\n jobTitle?: ReactNode\n tags?: readonly ContactTag[]\n whatsapp?: string\n}\n\nconst defaultChannelLabels: ContactChannelLabels = {\n email: 'E-mail',\n phone: 'Ligar',\n whatsapp: 'WhatsApp',\n}\n\nexport function whatsappHref(phone: string): string {\n return `https://wa.me/${phone.replace(/\\D/g, '')}`\n}\n\nexport function ContactWidget({\n action,\n activities,\n activitiesLabel = 'Atividade recente',\n channelLabels = defaultChannelLabels,\n className,\n company,\n email,\n expand,\n emptyLabel,\n jobTitle,\n person,\n phone,\n tags,\n whatsapp,\n ...props\n}: Readonly<ContactWidgetProps>): ReactElement {\n const titleId = useId()\n const channels = [\n email\n ? {\n href: `mailto:${email}`,\n icon: EnvelopeSimpleIcon,\n id: 'email' as const,\n }\n : null,\n phone\n ? { href: `tel:${phone}`, icon: PhoneIcon, id: 'phone' as const }\n : null,\n whatsapp\n ? {\n href: whatsappHref(whatsapp),\n icon: ChatCircleIcon,\n id: 'whatsapp' as const,\n }\n : null,\n ].filter((channel) => channel !== null)\n\n return (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-widget=\"contact\"\n {...props}\n >\n <CardPanel className=\"grid gap-5 p-5\">\n <div className=\"flex items-start gap-3\">\n <span className=\"flex shrink-0 rounded-full border border-input bg-card\">\n <Avatar className=\"[--avatar-size:--spacing(12)]\">\n {person.imageUrl ? (\n <AvatarImage alt=\"\" src={person.imageUrl} />\n ) : null}\n <AvatarFallback>{resolveInitials(person)}</AvatarFallback>\n </Avatar>\n </span>\n <div className=\"grid min-w-0 flex-1 gap-1\">\n <h3 className=\"truncate font-semibold text-base\" id={titleId}>\n {person.label}\n </h3>\n {jobTitle || company ? (\n <p className=\"truncate text-muted-foreground text-sm\">\n {jobTitle}\n {jobTitle && company ? ' · ' : null}\n {company}\n </p>\n ) : null}\n {tags?.length ? (\n <ul\n className=\"flex flex-wrap gap-1 pt-1\"\n data-slot=\"contact-tags\"\n >\n {tags.map((tag) => (\n <li key={tag.id}>\n <Badge variant=\"outline\">{tag.label}</Badge>\n </li>\n ))}\n </ul>\n ) : null}\n </div>\n {action}\n </div>\n {channels.length ? (\n <div className=\"flex flex-wrap gap-2\" data-slot=\"contact-channels\">\n {channels.map((channel) => (\n <Button\n data-channel={channel.id}\n key={channel.id}\n render={\n <a\n href={channel.href}\n {...(channel.id === 'whatsapp'\n ? { rel: 'noreferrer', target: '_blank' }\n : {})}\n />\n }\n size=\"sm\"\n variant=\"outline\"\n >\n <channel.icon aria-hidden=\"true\" />\n {channelLabels[channel.id]}\n </Button>\n ))}\n </div>\n ) : null}\n {activities ? (\n <div className=\"grid gap-3\">\n <h4\n className=\"text-muted-foreground text-sm\"\n id={`${titleId}-activities`}\n >\n {activitiesLabel}\n </h4>\n <ActivityTimeline\n activities={activities}\n aria-label={activitiesLabel}\n {...(emptyLabel === undefined ? {} : { emptyLabel })}\n {...(expand ? { expand } : {})}\n {...(expand ? { expand } : {})}\n />\n </div>\n ) : null}\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
51
|
+
"target": "~/packages/ui/src/patterns/widgets/crm/contact-widget.tsx"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"path": "patterns/widgets/crm/deals-widget.tsx",
|
|
55
|
+
"type": "registry:file",
|
|
56
|
+
"content": "import { Badge } from '@tc96/ui/badge'\nimport { CardPanel } from '@tc96/ui/card'\nimport { type AmountFormatOptions, formatAmount } from '@tc96/ui/helpers/format'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId } from 'react'\nimport { AvatarStack, type AvatarStackPerson } from '../shared/avatar-stack'\nimport {\n ExpandableList,\n type WidgetExpandProps,\n} from '../shared/expandable-list'\nimport { WidgetHeader } from '../shared/widget-header'\nimport { WidgetShell } from '../shared/widget-shell'\nimport type { WidgetTone } from '../types'\n\nexport interface DealStage {\n label: ReactNode\n tone?: WidgetTone\n}\n\nexport interface Deal {\n closeLabel?: ReactNode\n company?: ReactNode\n icon?: ReactNode\n id: string\n name: ReactNode\n owner?: AvatarStackPerson\n stage?: DealStage\n value: number\n}\n\nconst stageVariants: Record<\n WidgetTone,\n 'error' | 'info' | 'success' | 'warning'\n> = {\n destructive: 'error',\n info: 'info',\n success: 'success',\n warning: 'warning',\n}\n\nexport interface DealListProps extends ComponentProps<'ul'> {}\n\nexport function DealList({\n className,\n ...props\n}: Readonly<DealListProps>): ReactElement {\n return (\n <ul\n className={cn('divide-y divide-border/40', className)}\n data-slot=\"deal-list\"\n {...props}\n />\n )\n}\n\nexport interface DealListItemProps\n extends Omit<ComponentProps<'li'>, 'children' | 'title'> {\n closeLabel?: ReactNode\n company?: ReactNode\n format?: AmountFormatOptions\n icon?: ReactNode\n name: ReactNode\n owner?: AvatarStackPerson\n ownerLabel?: string\n stage?: DealStage\n value: number\n}\n\nexport function DealListItem({\n className,\n closeLabel,\n company,\n format,\n icon,\n name,\n owner,\n ownerLabel = 'Responsável',\n stage,\n value,\n ...props\n}: Readonly<DealListItemProps>): ReactElement {\n return (\n <li\n className={cn(\n 'flex min-w-0 items-center gap-3 py-3 first:pt-0 last:pb-0',\n className,\n )}\n data-slot=\"deal-list-item\"\n {...props}\n >\n {icon}\n <div className=\"grid min-w-0 flex-1 gap-1\">\n <div className=\"flex min-w-0 items-center gap-2\">\n <span className=\"truncate font-medium text-sm\">{name}</span>\n {stage ? (\n <Badge\n data-slot=\"deal-stage\"\n data-tone={stage.tone ?? 'info'}\n variant={stageVariants[stage.tone ?? 'info']}\n >\n {stage.label}\n </Badge>\n ) : null}\n </div>\n {company || closeLabel ? (\n <span className=\"flex min-w-0 items-center gap-1.5 text-muted-foreground text-xs\">\n {company ? <span className=\"truncate\">{company}</span> : null}\n {company && closeLabel ? <span aria-hidden=\"true\">·</span> : null}\n {closeLabel ? (\n <span className=\"shrink-0 truncate\">{closeLabel}</span>\n ) : null}\n </span>\n ) : null}\n </div>\n <div className=\"flex shrink-0 items-center gap-3\">\n <span className=\"font-semibold text-sm tabular-nums\">\n {formatAmount(value, format)}\n </span>\n {owner ? (\n <AvatarStack aria-label={ownerLabel} people={[owner]} size=\"sm\" />\n ) : null}\n </div>\n </li>\n )\n}\n\nexport interface DealsWidgetProps\n extends Omit<ComponentProps<'div'>, 'children' | 'title'> {\n action?: ReactNode\n deals: readonly Deal[]\n emptyLabel?: ReactNode\n expand?: WidgetExpandProps\n format?: AmountFormatOptions\n listLabel?: string\n ownerLabel?: string\n title: ReactNode\n}\n\nexport function DealsWidget({\n action,\n className,\n deals,\n emptyLabel = 'Sem negócios',\n expand,\n format,\n listLabel,\n ownerLabel,\n title,\n ...props\n}: Readonly<DealsWidgetProps>): ReactElement {\n const titleId = useId()\n\n return (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-widget=\"deals\"\n {...props}\n >\n <WidgetHeader action={action} title={title} titleId={titleId} />\n <CardPanel className=\"grid gap-5 px-5 pb-5\">\n {deals.length ? (\n <ExpandableList items={deals} {...expand}>\n {(shown) => (\n <DealList\n aria-label={\n listLabel ?? (typeof title === 'string' ? title : 'Negócios')\n }\n >\n {shown.map(({ id, ...deal }) => (\n <DealListItem\n key={id}\n {...deal}\n {...(format ? { format } : {})}\n {...(ownerLabel ? { ownerLabel } : {})}\n />\n ))}\n </DealList>\n )}\n </ExpandableList>\n ) : (\n <p className=\"text-muted-foreground text-sm\" data-slot=\"deals-empty\">\n {emptyLabel}\n </p>\n )}\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
57
|
+
"target": "~/packages/ui/src/patterns/widgets/crm/deals-widget.tsx"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"path": "patterns/widgets/crm/index.ts",
|
|
61
|
+
"type": "registry:file",
|
|
62
|
+
"content": "export type { ActivityFeedWidgetProps } from './activity-feed-widget'\nexport { ActivityFeedWidget } from './activity-feed-widget'\nexport type { Activity, ActivityTimelineProps } from './activity-timeline'\nexport { ActivityTimeline } from './activity-timeline'\nexport type {\n ContactChannelLabels,\n ContactTag,\n ContactWidgetProps,\n} from './contact-widget'\nexport { ContactWidget, whatsappHref } from './contact-widget'\nexport type {\n Deal,\n DealListItemProps,\n DealListProps,\n DealStage,\n DealsWidgetProps,\n} from './deals-widget'\nexport { DealList, DealListItem, DealsWidget } from './deals-widget'\nexport type { PipelineStage, PipelineWidgetProps } from './pipeline-widget'\nexport { PipelineWidget } from './pipeline-widget'\n",
|
|
63
|
+
"target": "~/packages/ui/src/patterns/widgets/crm/index.ts"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"path": "patterns/widgets/crm/pipeline-widget.tsx",
|
|
67
|
+
"type": "registry:file",
|
|
68
|
+
"content": "'use client'\n\nimport { CardPanel } from '@tc96/ui/card'\nimport { type AmountFormatOptions, formatAmount } from '@tc96/ui/helpers/format'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId } from 'react'\nimport { Amount } from '../shared/amount'\nimport {\n ExpandableList,\n type WidgetExpandProps,\n} from '../shared/expandable-list'\nimport { WidgetHeader } from '../shared/widget-header'\nimport { WidgetPeriodToggle } from '../shared/widget-period-toggle'\nimport { WidgetShell } from '../shared/widget-shell'\nimport type { WidgetPeriodOption } from '../types'\n\nexport interface PipelineStage {\n color?: string\n count: number\n id: string\n label: ReactNode\n value: number\n}\n\nexport interface PipelineWidgetProps<TPeriod extends string = string>\n extends Omit<ComponentProps<'div'>, 'children' | 'title'> {\n action?: ReactNode\n countLabel?: (count: number) => ReactNode\n expand?: WidgetExpandProps\n format?: AmountFormatOptions\n listLabel?: string\n onPeriodChange?: (period: TPeriod) => void\n period?: TPeriod\n periodLabel?: string\n periods?: readonly WidgetPeriodOption<TPeriod>[]\n stages: readonly PipelineStage[]\n title: ReactNode\n totalLabel?: ReactNode\n}\n\nfunction stageColor(stage: PipelineStage, index: number) {\n return stage.color ?? `var(--chart-${(index % 5) + 1})`\n}\n\nexport function PipelineWidget<TPeriod extends string = string>({\n action,\n className,\n countLabel = (count) => `${count}`,\n expand,\n format,\n listLabel,\n onPeriodChange,\n period,\n periodLabel,\n periods,\n stages,\n title,\n totalLabel = 'Total no funil',\n ...props\n}: Readonly<PipelineWidgetProps<TPeriod>>): ReactElement {\n const titleId = useId()\n const total = stages.reduce((sum, stage) => sum + Math.max(0, stage.value), 0)\n const peak = stages.reduce((max, stage) => Math.max(max, stage.value), 0)\n const headerAction = periods?.length ? (\n <WidgetPeriodToggle\n options={periods}\n {...(period === undefined ? {} : { value: period })}\n {...(onPeriodChange ? { onValueChange: onPeriodChange } : {})}\n {...(periodLabel ? { 'aria-label': periodLabel } : {})}\n />\n ) : (\n action\n )\n\n return (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-widget=\"pipeline\"\n {...props}\n >\n <WidgetHeader action={headerAction} title={title} titleId={titleId} />\n <CardPanel className=\"grid gap-5 px-5 pb-5\">\n <div className=\"grid gap-1\">\n <Amount\n className=\"font-medium text-4xl leading-tight tracking-tight\"\n dimFraction\n value={total}\n {...(format ? { format } : {})}\n />\n <p className=\"text-muted-foreground text-sm\">{totalLabel}</p>\n </div>\n <ExpandableList items={stages} {...expand}>\n {(shown) => (\n <ol\n aria-label={\n listLabel ?? (typeof title === 'string' ? title : 'Etapas')\n }\n className=\"grid gap-4\"\n data-slot=\"pipeline-stages\"\n >\n {shown.map((stage, index) => {\n const share = total ? Math.max(0, stage.value) / total : 0\n const width = peak ? (Math.max(0, stage.value) / peak) * 100 : 0\n return (\n <li\n className=\"grid gap-2\"\n data-slot=\"pipeline-stage\"\n key={stage.id}\n >\n <div className=\"flex items-baseline justify-between gap-3\">\n <span className=\"flex min-w-0 items-baseline gap-1.5\">\n <span className=\"truncate text-sm\">{stage.label}</span>\n <span className=\"text-muted-foreground text-xs tabular-nums\">\n {countLabel(stage.count)}\n </span>\n </span>\n <span className=\"shrink-0 font-medium text-sm tabular-nums\">\n {formatAmount(stage.value, format)}\n </span>\n </div>\n <div\n aria-hidden=\"true\"\n className=\"h-2 overflow-hidden rounded-full bg-muted\"\n >\n <div\n className=\"h-full rounded-full transition-[width] duration-500\"\n style={{\n backgroundColor: stageColor(stage, index),\n width: `${width}%`,\n }}\n />\n </div>\n <span className=\"sr-only\">\n {formatAmount(share, {\n style: 'percent',\n ...(format?.locale ? { locale: format.locale } : {}),\n })}\n </span>\n </li>\n )\n })}\n </ol>\n )}\n </ExpandableList>\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
69
|
+
"target": "~/packages/ui/src/patterns/widgets/crm/pipeline-widget.tsx"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"path": "patterns/widgets/finance/asset-list.tsx",
|
|
73
|
+
"type": "registry:file",
|
|
74
|
+
"content": "import { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\n\nexport interface AssetListProps extends ComponentProps<'ul'> {}\n\nexport function AssetList({\n className,\n ...props\n}: Readonly<AssetListProps>): ReactElement {\n return (\n <ul\n className={cn('divide-y divide-border/40', className)}\n data-slot=\"asset-list\"\n {...props}\n />\n )\n}\n\nexport interface AssetListItemProps\n extends Omit<ComponentProps<'li'>, 'title' | 'value'> {\n icon?: ReactNode\n /** Informação secundária à direita, como a variação em 24h. */\n meta?: ReactNode\n name: ReactNode\n value: ReactNode\n}\n\nexport function AssetListItem({\n className,\n icon,\n meta,\n name,\n value,\n ...props\n}: Readonly<AssetListItemProps>): ReactElement {\n return (\n <li\n className={cn(\n 'flex min-w-0 items-center gap-3 py-3 first:pt-0 last:pb-0',\n className,\n )}\n data-slot=\"asset-list-item\"\n {...props}\n >\n {icon}\n <div className=\"grid min-w-0 flex-1 gap-0.5\">\n <span className=\"truncate text-muted-foreground text-sm\">{name}</span>\n <span className=\"truncate font-semibold text-sm tabular-nums\">\n {value}\n </span>\n </div>\n {meta ? (\n <div className=\"shrink-0 self-end text-muted-foreground text-sm tabular-nums\">\n {meta}\n </div>\n ) : null}\n </li>\n )\n}\n",
|
|
75
|
+
"target": "~/packages/ui/src/patterns/widgets/finance/asset-list.tsx"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"path": "patterns/widgets/finance/asset-stat-widget.tsx",
|
|
79
|
+
"type": "registry:file",
|
|
80
|
+
"content": "import { CardPanel } from '@tc96/ui/card'\nimport type { AmountFormatOptions } from '@tc96/ui/helpers/format'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId } from 'react'\nimport { Amount } from '../shared/amount'\nimport { TrendIndicator } from '../shared/trend-indicator'\nimport { WidgetShell } from '../shared/widget-shell'\n\nexport interface AssetStatWidgetProps\n extends Omit<ComponentProps<'div'>, 'children' | 'title'> {\n change?: number\n changeFormat?: AmountFormatOptions\n format?: AmountFormatOptions\n icon?: ReactNode\n label: ReactNode\n name: ReactNode\n symbol?: ReactNode\n tone?: 'default' | 'inverted'\n value: number\n}\n\nexport function AssetStatWidget({\n change,\n changeFormat,\n className,\n format,\n icon,\n label,\n name,\n symbol,\n tone = 'default',\n value,\n ...props\n}: Readonly<AssetStatWidgetProps>): ReactElement {\n const titleId = useId()\n const card = (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-widget=\"asset-stat\"\n data-tone={tone}\n {...props}\n >\n <CardPanel className=\"grid gap-5 p-5\">\n <div className=\"flex items-center justify-between gap-3\">\n {icon}\n {change === undefined ? null : (\n <TrendIndicator\n className=\"ms-auto\"\n value={change}\n {...(changeFormat ? { format: changeFormat } : {})}\n />\n )}\n </div>\n <div className=\"grid gap-3\">\n <h3 className=\"truncate font-semibold text-sm\" id={titleId}>\n {name}\n {symbol ? (\n <span className=\"ms-1.5 font-normal text-muted-foreground text-sm\">\n {symbol}\n </span>\n ) : null}\n </h3>\n <div className=\"grid gap-1\">\n <p className=\"text-muted-foreground text-sm\">{label}</p>\n <Amount\n className=\"font-medium text-4xl leading-tight tracking-tight\"\n dimFraction\n value={value}\n {...(format ? { format } : {})}\n />\n </div>\n </div>\n </CardPanel>\n </WidgetShell>\n )\n\n return tone === 'inverted' ? (\n <div className=\"dark contents\" data-slot=\"asset-stat-widget-scope\">\n {card}\n </div>\n ) : (\n card\n )\n}\n",
|
|
81
|
+
"target": "~/packages/ui/src/patterns/widgets/finance/asset-stat-widget.tsx"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"path": "patterns/widgets/finance/balance-widget.tsx",
|
|
85
|
+
"type": "registry:file",
|
|
86
|
+
"content": "'use client'\n\nimport { CardPanel } from '@tc96/ui/card'\nimport { type AmountFormatOptions, formatAmount } from '@tc96/ui/helpers/format'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId } from 'react'\nimport {\n Area,\n AreaChart,\n ResponsiveContainer,\n Tooltip,\n XAxis,\n YAxis,\n} from 'recharts'\nimport { Amount } from '../shared/amount'\nimport { TrendIndicator } from '../shared/trend-indicator'\nimport { WidgetHeader } from '../shared/widget-header'\nimport { WidgetPeriodToggle } from '../shared/widget-period-toggle'\nimport { WidgetShell } from '../shared/widget-shell'\nimport type { WidgetPeriodOption } from '../types'\n\nexport interface BalancePoint {\n label: string\n value: number\n}\n\nexport interface BalanceWidgetProps<TPeriod extends string = string>\n extends Omit<ComponentProps<'div'>, 'children' | 'title'> {\n change?: number\n changeFormat?: AmountFormatOptions\n changeLabel?: ReactNode\n chartLabel?: string\n color?: string\n data: readonly BalancePoint[]\n format?: AmountFormatOptions\n height?: number\n onPeriodChange?: (period: TPeriod) => void\n period?: TPeriod\n periodLabel?: string\n periods?: readonly WidgetPeriodOption<TPeriod>[]\n title: ReactNode\n value: number\n}\n\nfunction BalanceTooltip({\n active,\n format,\n payload,\n}: {\n active?: boolean\n format?: AmountFormatOptions\n payload?: readonly { payload?: unknown }[]\n}): ReactElement | null {\n const point = payload?.[0]?.payload as BalancePoint | undefined\n if (!active || !point) return null\n\n return (\n <div className=\"grid gap-0.5 rounded-lg border bg-popover px-2.5 py-1.5 text-popover-foreground text-xs shadow-md/5\">\n <span className=\"text-muted-foreground\">{point.label}</span>\n <span className=\"font-medium tabular-nums\">\n {formatAmount(point.value, format)}\n </span>\n </div>\n )\n}\n\nexport function BalanceWidget<TPeriod extends string = string>({\n change,\n changeFormat,\n changeLabel,\n chartLabel,\n className,\n color = 'var(--chart-1)',\n data,\n format,\n height = 160,\n onPeriodChange,\n period,\n periodLabel,\n periods,\n title,\n value,\n ...props\n}: Readonly<BalanceWidgetProps<TPeriod>>): ReactElement {\n const titleId = useId()\n const gradientId = `balance-gradient-${useId().replace(/[^a-zA-Z0-9]/g, '')}`\n\n return (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-widget=\"balance\"\n {...props}\n >\n <WidgetHeader\n action={\n periods?.length ? (\n <WidgetPeriodToggle\n options={periods}\n {...(period === undefined ? {} : { value: period })}\n {...(onPeriodChange ? { onValueChange: onPeriodChange } : {})}\n {...(periodLabel ? { 'aria-label': periodLabel } : {})}\n />\n ) : null\n }\n title={title}\n titleId={titleId}\n />\n <CardPanel className=\"grid gap-5 px-5 pb-5\">\n <div className=\"grid gap-2\">\n <Amount\n className=\"font-medium text-4xl leading-tight tracking-tight\"\n dimFraction\n value={value}\n {...(format ? { format } : {})}\n />\n {change === undefined ? null : (\n <div className=\"flex items-center gap-2 text-muted-foreground text-sm\">\n <TrendIndicator\n value={change}\n {...(changeFormat ? { format: changeFormat } : {})}\n />\n {changeLabel}\n </div>\n )}\n </div>\n <div\n aria-label={\n chartLabel ?? (typeof title === 'string' ? title : 'Gráfico')\n }\n className=\"-mx-1 min-w-0\"\n data-slot=\"balance-widget-chart\"\n role=\"img\"\n style={{ height }}\n >\n <ResponsiveContainer\n height=\"100%\"\n initialDimension={{ height, width: 320 }}\n width=\"100%\"\n >\n <AreaChart\n accessibilityLayer={false}\n data={[...data]}\n margin={{ bottom: 0, left: 4, right: 4, top: 4 }}\n >\n <defs>\n <linearGradient id={gradientId} x1=\"0\" x2=\"0\" y1=\"0\" y2=\"1\">\n <stop offset=\"0%\" stopColor={color} stopOpacity={0.24} />\n <stop offset=\"100%\" stopColor={color} stopOpacity={0} />\n </linearGradient>\n </defs>\n <XAxis\n axisLine={false}\n dataKey=\"label\"\n interval=\"preserveStartEnd\"\n minTickGap={24}\n tick={{ fill: 'var(--muted-foreground)', fontSize: 12 }}\n tickLine={false}\n tickMargin={8}\n />\n <YAxis domain={['dataMin', 'dataMax']} hide />\n <Tooltip\n content={(tooltip) => (\n <BalanceTooltip\n {...tooltip}\n {...(format ? { format } : {})}\n />\n )}\n cursor={{ stroke: 'var(--border)' }}\n />\n <Area\n activeDot={{ fill: color, r: 4, stroke: 'var(--card)' }}\n dataKey=\"value\"\n fill={`url(#${gradientId})`}\n isAnimationActive={false}\n stroke={color}\n strokeWidth={2}\n type=\"monotone\"\n />\n </AreaChart>\n </ResponsiveContainer>\n </div>\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
87
|
+
"target": "~/packages/ui/src/patterns/widgets/finance/balance-widget.tsx"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"path": "patterns/widgets/finance/budget-widget.tsx",
|
|
91
|
+
"type": "registry:file",
|
|
92
|
+
"content": "import { CardPanel } from '@tc96/ui/card'\nimport { Gauge } from '@tc96/ui/gauge'\nimport { type AmountFormatOptions, formatAmount } from '@tc96/ui/helpers/format'\nimport { IconFrame } from '@tc96/ui/icon-frame'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId } from 'react'\nimport { Amount } from '../shared/amount'\nimport {\n ExpandableList,\n type WidgetExpandProps,\n} from '../shared/expandable-list'\nimport { WidgetHeader } from '../shared/widget-header'\nimport { WidgetPeriodToggle } from '../shared/widget-period-toggle'\nimport { WidgetShell } from '../shared/widget-shell'\nimport type { WidgetPeriodOption } from '../types'\n\nexport interface BudgetCategory {\n color?: string\n icon?: ReactNode\n id: string\n label: string\n limit: number\n spent: number\n}\n\nexport interface BudgetWidgetProps<TPeriod extends string = string>\n extends Omit<ComponentProps<'div'>, 'children' | 'title'> {\n action?: ReactNode\n categories: readonly BudgetCategory[]\n expand?: WidgetExpandProps\n format?: AmountFormatOptions\n limitLabel?: ReactNode\n locale?: string\n onPeriodChange?: (period: TPeriod) => void\n period?: TPeriod\n periodLabel?: string\n periods?: readonly WidgetPeriodOption<TPeriod>[]\n spentLabel?: ReactNode\n title: ReactNode\n}\n\nfunction categoryColor(category: BudgetCategory, index: number) {\n return category.color ?? `var(--chart-${(index % 5) + 1})`\n}\n\nexport function BudgetWidget<TPeriod extends string = string>({\n action,\n categories,\n className,\n expand,\n format,\n limitLabel = 'Limite',\n locale,\n onPeriodChange,\n period,\n periodLabel,\n periods,\n spentLabel = 'Gasto',\n title,\n ...props\n}: Readonly<BudgetWidgetProps<TPeriod>>): ReactElement {\n const titleId = useId()\n const totalSpent = categories.reduce((sum, item) => sum + item.spent, 0)\n const totalLimit = categories.reduce((sum, item) => sum + item.limit, 0)\n const headerAction = periods?.length ? (\n <WidgetPeriodToggle\n options={periods}\n {...(period === undefined ? {} : { value: period })}\n {...(onPeriodChange ? { onValueChange: onPeriodChange } : {})}\n {...(periodLabel ? { 'aria-label': periodLabel } : {})}\n />\n ) : (\n action\n )\n\n return (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-widget=\"budget\"\n {...props}\n >\n <WidgetHeader action={headerAction} title={title} titleId={titleId} />\n <CardPanel className=\"grid gap-5 px-5 pb-5\">\n <div className=\"grid gap-1\">\n <p className=\"text-muted-foreground text-sm\">{spentLabel}</p>\n <Amount\n className=\"font-medium text-4xl leading-tight tracking-tight\"\n dimFraction\n value={totalSpent}\n {...(format ? { format } : {})}\n />\n <p className=\"text-muted-foreground text-sm\">\n {limitLabel}{' '}\n <span className=\"tabular-nums\">\n {formatAmount(totalLimit, format)}\n </span>\n </p>\n </div>\n <ExpandableList items={categories} {...expand}>\n {(shown) => (\n <ul className=\"grid gap-4\" data-slot=\"budget-list\">\n {shown.map((category, index) => {\n const over = category.spent > category.limit\n const share = category.limit\n ? category.spent / category.limit\n : 0\n const color = categoryColor(category, index)\n return (\n <li\n className=\"grid gap-2\"\n data-over={over ? 'true' : undefined}\n data-slot=\"budget-category\"\n key={category.id}\n >\n <div className=\"flex min-w-0 items-center gap-3\">\n {category.icon ? (\n <IconFrame color={color}>{category.icon}</IconFrame>\n ) : null}\n <span className=\"min-w-0 flex-1 truncate text-sm\">\n {category.label}\n </span>\n <span className=\"shrink-0 text-sm tabular-nums\">\n <span\n className={cn(\n 'font-medium',\n over && 'text-destructive-foreground',\n )}\n >\n {formatAmount(category.spent, format)}\n </span>\n <span className=\"text-muted-foreground\">\n {' / '}\n {formatAmount(category.limit, format)}\n </span>\n </span>\n </div>\n <Gauge\n aria-label={category.label}\n data-slot=\"budget-meter\"\n max={category.limit}\n size=\"sm\"\n value={Math.min(category.spent, category.limit)}\n {...(over ? { tone: 'destructive' as const } : { color })}\n />\n <span className=\"sr-only\">\n {formatAmount(share, {\n style: 'percent',\n ...(locale ? { locale } : {}),\n })}\n </span>\n </li>\n )\n })}\n </ul>\n )}\n </ExpandableList>\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
93
|
+
"target": "~/packages/ui/src/patterns/widgets/finance/budget-widget.tsx"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"path": "patterns/widgets/finance/cash-flow-widget.tsx",
|
|
97
|
+
"type": "registry:file",
|
|
98
|
+
"content": "'use client'\n\nimport { CardPanel } from '@tc96/ui/card'\nimport { type AmountFormatOptions, formatAmount } from '@tc96/ui/helpers/format'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId } from 'react'\nimport {\n Bar,\n BarChart,\n ResponsiveContainer,\n Tooltip,\n XAxis,\n YAxis,\n} from 'recharts'\nimport { Amount } from '../shared/amount'\nimport { StatList } from '../shared/stat-list'\nimport { WidgetHeader } from '../shared/widget-header'\nimport { WidgetPeriodToggle } from '../shared/widget-period-toggle'\nimport { WidgetShell } from '../shared/widget-shell'\nimport type { WidgetPeriodOption } from '../types'\n\nexport interface CashFlowPoint {\n expenses: number\n income: number\n label: string\n}\n\nexport interface CashFlowWidgetProps<TPeriod extends string = string>\n extends Omit<ComponentProps<'div'>, 'children' | 'title'> {\n chartLabel?: string\n data: readonly CashFlowPoint[]\n expensesColor?: string\n expensesLabel?: ReactNode\n format?: AmountFormatOptions\n height?: number\n incomeColor?: string\n incomeLabel?: ReactNode\n netLabel?: ReactNode\n onPeriodChange?: (period: TPeriod) => void\n period?: TPeriod\n periodLabel?: string\n periods?: readonly WidgetPeriodOption<TPeriod>[]\n title: ReactNode\n}\n\nfunction CashFlowTooltip({\n active,\n expensesColor,\n expensesLabel,\n format,\n incomeColor,\n incomeLabel,\n payload,\n}: {\n active?: boolean\n expensesColor: string\n expensesLabel: ReactNode\n format?: AmountFormatOptions\n incomeColor: string\n incomeLabel: ReactNode\n payload?: readonly { payload?: unknown }[]\n}): ReactElement | null {\n const point = payload?.[0]?.payload as CashFlowPoint | undefined\n if (!active || !point) return null\n\n return (\n <div className=\"grid gap-1 rounded-lg border bg-popover px-2.5 py-1.5 text-popover-foreground text-xs shadow-md/5\">\n <span className=\"text-muted-foreground\">{point.label}</span>\n <span className=\"flex items-center gap-1.5 tabular-nums\">\n <span\n aria-hidden=\"true\"\n className=\"size-2 rounded-sm\"\n style={{ backgroundColor: incomeColor }}\n />\n {incomeLabel}{' '}\n <span className=\"font-medium\">\n {formatAmount(point.income, format)}\n </span>\n </span>\n <span className=\"flex items-center gap-1.5 tabular-nums\">\n <span\n aria-hidden=\"true\"\n className=\"size-2 rounded-sm\"\n style={{ backgroundColor: expensesColor }}\n />\n {expensesLabel}{' '}\n <span className=\"font-medium\">\n {formatAmount(point.expenses, format)}\n </span>\n </span>\n </div>\n )\n}\n\nexport function CashFlowWidget<TPeriod extends string = string>({\n chartLabel,\n className,\n data,\n expensesColor = 'var(--chart-2)',\n expensesLabel = 'Saídas',\n format,\n height = 160,\n incomeColor = 'var(--chart-1)',\n incomeLabel = 'Entradas',\n netLabel = 'Saldo',\n onPeriodChange,\n period,\n periodLabel,\n periods,\n title,\n ...props\n}: Readonly<CashFlowWidgetProps<TPeriod>>): ReactElement {\n const titleId = useId()\n const income = data.reduce((sum, point) => sum + point.income, 0)\n const expenses = data.reduce((sum, point) => sum + point.expenses, 0)\n const net = income - expenses\n const amount = (value: number) => (\n <Amount value={value} {...(format ? { format } : {})} />\n )\n\n return (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-widget=\"cash-flow\"\n {...props}\n >\n <WidgetHeader\n action={\n periods?.length ? (\n <WidgetPeriodToggle\n options={periods}\n {...(period === undefined ? {} : { value: period })}\n {...(onPeriodChange ? { onValueChange: onPeriodChange } : {})}\n {...(periodLabel ? { 'aria-label': periodLabel } : {})}\n />\n ) : null\n }\n title={title}\n titleId={titleId}\n />\n <CardPanel className=\"grid gap-5 px-5 pb-5\">\n <StatList\n className=\"justify-center text-center\"\n stats={[\n { id: 'income', label: incomeLabel, value: amount(income) },\n { id: 'expenses', label: expensesLabel, value: amount(expenses) },\n {\n id: 'net',\n label: netLabel,\n value: (\n <span\n className={\n net < 0 ? 'text-destructive-foreground' : undefined\n }\n >\n {amount(net)}\n </span>\n ),\n },\n ]}\n />\n <div className=\"grid gap-3\">\n <div\n aria-label={\n chartLabel ?? (typeof title === 'string' ? title : 'Gráfico')\n }\n className=\"-mx-1 min-w-0\"\n data-slot=\"cash-flow-widget-chart\"\n role=\"img\"\n style={{ height }}\n >\n <ResponsiveContainer\n height=\"100%\"\n initialDimension={{ height, width: 320 }}\n width=\"100%\"\n >\n <BarChart\n accessibilityLayer={false}\n barGap={4}\n data={[...data]}\n margin={{ bottom: 0, left: 4, right: 4, top: 4 }}\n >\n <XAxis\n axisLine={false}\n dataKey=\"label\"\n interval=\"preserveStartEnd\"\n minTickGap={24}\n tick={{ fill: 'var(--muted-foreground)', fontSize: 12 }}\n tickLine={false}\n tickMargin={8}\n />\n <YAxis hide />\n <Tooltip\n content={(tooltip) => (\n <CashFlowTooltip\n {...tooltip}\n expensesColor={expensesColor}\n expensesLabel={expensesLabel}\n incomeColor={incomeColor}\n incomeLabel={incomeLabel}\n {...(format ? { format } : {})}\n />\n )}\n cursor={{ fill: 'var(--muted)' }}\n />\n <Bar\n dataKey=\"income\"\n fill={incomeColor}\n isAnimationActive={false}\n radius={[4, 4, 0, 0]}\n />\n <Bar\n dataKey=\"expenses\"\n fill={expensesColor}\n isAnimationActive={false}\n radius={[4, 4, 0, 0]}\n />\n </BarChart>\n </ResponsiveContainer>\n </div>\n <ul\n className=\"flex flex-wrap justify-center gap-x-4 gap-y-1 text-muted-foreground text-xs\"\n data-slot=\"cash-flow-legend\"\n >\n <li className=\"flex items-center gap-1.5\">\n <span\n aria-hidden=\"true\"\n className=\"size-2 rounded-sm\"\n style={{ backgroundColor: incomeColor }}\n />\n {incomeLabel}\n </li>\n <li className=\"flex items-center gap-1.5\">\n <span\n aria-hidden=\"true\"\n className=\"size-2 rounded-sm\"\n style={{ backgroundColor: expensesColor }}\n />\n {expensesLabel}\n </li>\n </ul>\n </div>\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
99
|
+
"target": "~/packages/ui/src/patterns/widgets/finance/cash-flow-widget.tsx"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"path": "patterns/widgets/finance/index.ts",
|
|
103
|
+
"type": "registry:file",
|
|
104
|
+
"content": "export type { AssetListItemProps, AssetListProps } from './asset-list'\nexport { AssetList, AssetListItem } from './asset-list'\nexport type { AssetStatWidgetProps } from './asset-stat-widget'\nexport { AssetStatWidget } from './asset-stat-widget'\nexport type { BalancePoint, BalanceWidgetProps } from './balance-widget'\nexport { BalanceWidget } from './balance-widget'\nexport type { BudgetCategory, BudgetWidgetProps } from './budget-widget'\nexport { BudgetWidget } from './budget-widget'\nexport type { CashFlowPoint, CashFlowWidgetProps } from './cash-flow-widget'\nexport { CashFlowWidget } from './cash-flow-widget'\nexport type {\n InvoiceStatus,\n InvoiceStatusWidgetProps,\n} from './invoice-status-widget'\nexport { InvoiceStatusWidget } from './invoice-status-widget'\nexport type {\n MarketShareSegment,\n MarketShareWidgetProps,\n ShareBarProps,\n} from './market-share-widget'\nexport { MarketShareWidget, ShareBar } from './market-share-widget'\nexport type { RiskScoreStat, RiskScoreWidgetProps } from './risk-score-widget'\nexport { RiskScoreWidget } from './risk-score-widget'\nexport type {\n Transaction,\n TransactionKind,\n TransactionListItemProps,\n TransactionListProps,\n TransactionsWidgetProps,\n} from './transactions-widget'\nexport {\n TransactionList,\n TransactionListItem,\n TransactionsWidget,\n transactionKind,\n} from './transactions-widget'\n",
|
|
105
|
+
"target": "~/packages/ui/src/patterns/widgets/finance/index.ts"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"path": "patterns/widgets/finance/invoice-status-widget.tsx",
|
|
109
|
+
"type": "registry:file",
|
|
110
|
+
"content": "import { CardPanel } from '@tc96/ui/card'\nimport { type AmountFormatOptions, formatAmount } from '@tc96/ui/helpers/format'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId } from 'react'\nimport { Amount } from '../shared/amount'\nimport {\n ExpandableList,\n type WidgetExpandProps,\n} from '../shared/expandable-list'\nimport { WidgetHeader } from '../shared/widget-header'\nimport { WidgetShell } from '../shared/widget-shell'\nimport type { WidgetTone } from '../types'\nimport { ShareBar } from './market-share-widget'\n\nexport interface InvoiceStatus {\n count?: number\n id: string\n label: string\n tone: WidgetTone\n value: number\n}\n\nexport interface InvoiceStatusWidgetProps\n extends Omit<ComponentProps<'div'>, 'children' | 'title'> {\n action?: ReactNode\n countLabel?: (count: number) => ReactNode\n expand?: WidgetExpandProps\n format?: AmountFormatOptions\n locale?: string\n statuses: readonly InvoiceStatus[]\n title: ReactNode\n totalLabel?: ReactNode\n}\n\nconst toneColors: Record<WidgetTone, string> = {\n destructive: 'var(--destructive)',\n info: 'var(--info)',\n success: 'var(--success)',\n warning: 'var(--warning)',\n}\n\nexport function InvoiceStatusWidget({\n action,\n className,\n countLabel,\n expand,\n format,\n locale,\n statuses,\n title,\n totalLabel = 'Total em aberto',\n ...props\n}: Readonly<InvoiceStatusWidgetProps>): ReactElement {\n const titleId = useId()\n const total = statuses.reduce((sum, status) => sum + status.value, 0)\n\n return (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-widget=\"invoice-status\"\n {...props}\n >\n <WidgetHeader action={action} title={title} titleId={titleId} />\n <CardPanel className=\"grid gap-5 px-5 pb-5\">\n <div className=\"grid gap-1\">\n <p className=\"text-muted-foreground text-sm\">{totalLabel}</p>\n <Amount\n className=\"font-medium text-4xl leading-tight tracking-tight\"\n dimFraction\n value={total}\n {...(format ? { format } : {})}\n />\n </div>\n <ShareBar\n segments={statuses.map((status) => ({\n color: toneColors[status.tone],\n id: status.id,\n label: status.label,\n value: status.value,\n }))}\n {...(locale ? { locale } : {})}\n />\n <ExpandableList items={statuses} {...expand}>\n {(shown) => (\n <ul className=\"grid gap-3\" data-slot=\"invoice-status-list\">\n {shown.map((status) => (\n <li\n className=\"flex min-w-0 items-center gap-3\"\n data-slot=\"invoice-status-item\"\n data-tone={status.tone}\n key={status.id}\n >\n <span\n aria-hidden=\"true\"\n className=\"size-2 shrink-0 rounded-full\"\n style={{ backgroundColor: toneColors[status.tone] }}\n />\n <span className=\"min-w-0 flex-1 truncate text-sm\">\n {status.label}\n {status.count === undefined ? null : (\n <span className=\"ms-2 text-muted-foreground text-xs tabular-nums\">\n {countLabel ? countLabel(status.count) : status.count}\n </span>\n )}\n </span>\n <span className=\"shrink-0 font-medium tabular-nums\">\n {formatAmount(status.value, format)}\n </span>\n </li>\n ))}\n </ul>\n )}\n </ExpandableList>\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
111
|
+
"target": "~/packages/ui/src/patterns/widgets/finance/invoice-status-widget.tsx"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"path": "patterns/widgets/finance/market-share-widget.tsx",
|
|
115
|
+
"type": "registry:file",
|
|
116
|
+
"content": "'use client'\n\nimport { CardPanel } from '@tc96/ui/card'\nimport { type AmountFormatOptions, formatAmount } from '@tc96/ui/helpers/format'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId } from 'react'\nimport { TrendIndicator } from '../shared/trend-indicator'\nimport { WidgetHeader } from '../shared/widget-header'\nimport { WidgetPeriodToggle } from '../shared/widget-period-toggle'\nimport { WidgetShell } from '../shared/widget-shell'\nimport type { WidgetPeriodOption } from '../types'\n\nexport interface MarketShareSegment {\n /** Variação do período, como razão (`0.0044`). */\n change?: number\n /** Qualquer cor CSS. Padrão: a paleta `--chart-1` a `--chart-5` do tema. */\n color?: string\n id: string\n label: string\n /** Peso do segmento; a participação é calculada sobre a soma. */\n value: number\n}\n\nexport interface ShareBarProps extends Omit<ComponentProps<'ul'>, 'children'> {\n changeFormat?: AmountFormatOptions\n locale?: string\n segments: readonly MarketShareSegment[]\n}\n\nfunction segmentColor(segment: MarketShareSegment, index: number) {\n return segment.color ?? `var(--chart-${(index % 5) + 1})`\n}\n\nexport function ShareBar({\n changeFormat,\n className,\n locale,\n segments,\n ...props\n}: Readonly<ShareBarProps>): ReactElement {\n const total = segments.reduce(\n (sum, segment) => sum + Math.max(0, segment.value),\n 0,\n )\n\n return (\n <ul\n className={cn('flex min-w-0 gap-0.5', className)}\n data-slot=\"share-bar\"\n {...props}\n >\n {segments.map((segment, index) => {\n const share = total ? Math.max(0, segment.value) / total : 0\n return (\n // Sem min-w-0: um segmento estreito cresce até caber a variação.\n <li\n className=\"flex flex-col\"\n data-slot=\"share-bar-segment\"\n key={segment.id}\n style={{ flex: `${share} 1 0%` }}\n >\n <div className=\"flex h-8 items-start border-border/40 border-s ps-2\">\n {segment.change === undefined ? null : (\n <TrendIndicator\n className=\"whitespace-nowrap pe-1\"\n value={segment.change}\n variant=\"plain\"\n {...(changeFormat ? { format: changeFormat } : {})}\n />\n )}\n </div>\n <div\n aria-hidden=\"true\"\n className=\"h-7 rounded-md\"\n style={{ backgroundColor: segmentColor(segment, index) }}\n />\n <span className=\"sr-only\">\n {segment.label}:{' '}\n {formatAmount(share, {\n style: 'percent',\n ...(locale ? { locale } : {}),\n })}\n </span>\n </li>\n )\n })}\n </ul>\n )\n}\n\nexport interface MarketShareWidgetProps<TPeriod extends string = string>\n extends Omit<ComponentProps<'div'>, 'title' | 'children'> {\n /** Conteúdo abaixo da barra, em geral um `AssetList`. */\n children?: ReactNode\n changeFormat?: AmountFormatOptions\n endLabel?: ReactNode\n locale?: string\n onPeriodChange?: (period: TPeriod) => void\n period?: TPeriod\n periodLabel?: string\n periods?: readonly WidgetPeriodOption<TPeriod>[]\n segments: readonly MarketShareSegment[]\n startLabel?: ReactNode\n title: ReactNode\n}\n\nexport function MarketShareWidget<TPeriod extends string = string>({\n changeFormat,\n children,\n className,\n endLabel,\n locale,\n onPeriodChange,\n period,\n periodLabel,\n periods,\n segments,\n startLabel,\n title,\n ...props\n}: Readonly<MarketShareWidgetProps<TPeriod>>): ReactElement {\n const titleId = useId()\n\n return (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-widget=\"market-share\"\n {...props}\n >\n <WidgetHeader\n action={\n periods?.length ? (\n <WidgetPeriodToggle\n options={periods}\n {...(period === undefined ? {} : { value: period })}\n {...(onPeriodChange ? { onValueChange: onPeriodChange } : {})}\n {...(periodLabel ? { 'aria-label': periodLabel } : {})}\n />\n ) : null\n }\n title={title}\n titleId={titleId}\n />\n <CardPanel className=\"grid gap-5 px-5 pb-5\">\n <div className=\"grid gap-2\">\n <ShareBar\n segments={segments}\n {...(changeFormat ? { changeFormat } : {})}\n {...(locale ? { locale } : {})}\n />\n {startLabel || endLabel ? (\n <div className=\"flex justify-between gap-3 text-muted-foreground text-xs\">\n <span>{startLabel}</span>\n <span>{endLabel}</span>\n </div>\n ) : null}\n </div>\n {children}\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
117
|
+
"target": "~/packages/ui/src/patterns/widgets/finance/market-share-widget.tsx"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"path": "patterns/widgets/finance/risk-score-widget.tsx",
|
|
121
|
+
"type": "registry:file",
|
|
122
|
+
"content": "import { CardPanel } from '@tc96/ui/card'\nimport { MeterPrimitive } from '@tc96/ui/meter'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId } from 'react'\nimport { StatList, type WidgetStat } from '../shared/stat-list'\nimport { WidgetHeader } from '../shared/widget-header'\nimport { WidgetShell } from '../shared/widget-shell'\nimport type { WidgetTone } from '../types'\n\nexport type RiskScoreStat = WidgetStat\n\nexport interface RiskScoreWidgetProps\n extends Omit<ComponentProps<'div'>, 'children' | 'title'> {\n /** Ação no cabeçalho, como um `Button` do COSS. */\n action?: ReactNode\n highLabel?: ReactNode\n lowLabel?: ReactNode\n max?: number\n /** Nome acessível do medidor. Padrão: o título, quando for texto. */\n meterLabel?: string\n min?: number\n score: number\n stats?: readonly RiskScoreStat[]\n title: ReactNode\n /**\n * Cor do trecho preenchido. O widget não interpreta a pontuação: qual faixa\n * é boa ou ruim é regra do consumidor.\n */\n tone?: WidgetTone\n}\n\nconst indicatorTones: Record<WidgetTone, string> = {\n destructive: 'bg-destructive',\n info: 'bg-info',\n success: 'bg-success',\n warning: 'bg-warning',\n}\n\nexport function RiskScoreWidget({\n action,\n className,\n highLabel = 'Risco alto',\n lowLabel = 'Risco baixo',\n max = 100,\n meterLabel,\n min = 0,\n score,\n stats,\n title,\n tone = 'success',\n ...props\n}: Readonly<RiskScoreWidgetProps>): ReactElement {\n const titleId = useId()\n const accessibleMeterLabel =\n meterLabel ?? (typeof title === 'string' ? title : 'Pontuação')\n\n return (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-widget=\"risk-score\"\n {...props}\n >\n <WidgetHeader action={action} title={title} titleId={titleId} />\n <CardPanel className=\"grid gap-5 px-5 pb-5\">\n {stats?.length ? <StatList stats={stats} /> : null}\n <MeterPrimitive.Root\n aria-label={accessibleMeterLabel}\n className=\"grid gap-2\"\n data-slot=\"risk-score-meter\"\n max={max}\n min={min}\n value={score}\n >\n <MeterPrimitive.Track className=\"relative block h-7 overflow-hidden rounded-md bg-[repeating-linear-gradient(90deg,var(--border)_0_2px,transparent_2px_5px)]\">\n <MeterPrimitive.Indicator\n className={cn(\n 'block h-full rounded-md transition-[width] duration-500',\n indicatorTones[tone],\n )}\n data-tone={tone}\n />\n </MeterPrimitive.Track>\n <div className=\"flex justify-between gap-3 text-muted-foreground text-xs\">\n <span>{lowLabel}</span>\n <span>{highLabel}</span>\n </div>\n </MeterPrimitive.Root>\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
123
|
+
"target": "~/packages/ui/src/patterns/widgets/finance/risk-score-widget.tsx"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"path": "patterns/widgets/finance/transactions-widget.tsx",
|
|
127
|
+
"type": "registry:file",
|
|
128
|
+
"content": "'use client'\n\nimport { Button } from '@tc96/ui/button'\nimport { CardPanel } from '@tc96/ui/card'\nimport { type AmountFormatOptions, formatAmount } from '@tc96/ui/helpers/format'\nimport { ScrollAreaPrimitive, ScrollBar } from '@tc96/ui/scroll-area'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId, useState } from 'react'\nimport { WidgetHeader } from '../shared/widget-header'\nimport { WidgetShell } from '../shared/widget-shell'\n\nexport type TransactionKind = 'credit' | 'debit'\n\nexport interface Transaction {\n amount: number\n icon?: ReactNode\n id: string\n kind?: TransactionKind\n meta?: ReactNode\n name: ReactNode\n status?: ReactNode\n}\n\nexport interface TransactionListProps extends ComponentProps<'ul'> {}\n\nexport function TransactionList({\n className,\n ...props\n}: Readonly<TransactionListProps>): ReactElement {\n return (\n <ul\n className={cn('divide-y divide-border/40', className)}\n data-slot=\"transaction-list\"\n {...props}\n />\n )\n}\n\nexport interface TransactionListItemProps\n extends Omit<ComponentProps<'li'>, 'title'> {\n amount: number\n format?: AmountFormatOptions\n icon?: ReactNode\n kind?: TransactionKind\n meta?: ReactNode\n name: ReactNode\n status?: ReactNode\n}\n\nexport function transactionKind(amount: number): TransactionKind {\n return amount >= 0 ? 'credit' : 'debit'\n}\n\nexport function TransactionListItem({\n amount,\n className,\n format,\n icon,\n kind = transactionKind(amount),\n meta,\n name,\n status,\n ...props\n}: Readonly<TransactionListItemProps>): ReactElement {\n const credit = kind === 'credit'\n\n return (\n <li\n className={cn(\n 'flex min-w-0 items-center gap-3 py-3 first:pt-0 last:pb-0',\n className,\n )}\n data-kind={kind}\n data-slot=\"transaction-list-item\"\n {...props}\n >\n {icon}\n <div className=\"grid min-w-0 flex-1 gap-0.5\">\n <span className=\"truncate font-medium text-sm\">{name}</span>\n {meta ? (\n <span className=\"truncate text-muted-foreground text-xs\">{meta}</span>\n ) : null}\n </div>\n <div className=\"grid shrink-0 justify-items-end gap-1\">\n <span\n className={cn(\n 'font-semibold text-sm tabular-nums',\n credit && 'text-success-foreground',\n )}\n data-slot=\"transaction-amount\"\n >\n {formatAmount(credit ? Math.abs(amount) : amount, {\n ...(credit ? { signDisplay: 'always' } : {}),\n ...format,\n })}\n </span>\n {status}\n </div>\n </li>\n )\n}\n\nexport interface TransactionsWidgetProps\n extends Omit<ComponentProps<'div'>, 'children' | 'title'> {\n action?: ReactNode\n collapseLabel?: ReactNode\n defaultExpanded?: boolean\n emptyLabel?: ReactNode\n expandLabel?: (hidden: number) => ReactNode\n expanded?: boolean\n format?: AmountFormatOptions\n listLabel?: string\n maxHeight?: number\n onExpandedChange?: (expanded: boolean) => void\n title: ReactNode\n transactions: readonly Transaction[]\n visibleCount?: number\n}\n\nfunction defaultExpandLabel(hidden: number): ReactNode {\n return `Ver todas (+${hidden})`\n}\n\nexport function TransactionsWidget({\n action,\n className,\n collapseLabel = 'Ver menos',\n defaultExpanded = false,\n emptyLabel = 'Sem transações',\n expandLabel = defaultExpandLabel,\n expanded: controlledExpanded,\n format,\n listLabel,\n maxHeight = 420,\n onExpandedChange,\n title,\n transactions,\n visibleCount = 5,\n ...props\n}: Readonly<TransactionsWidgetProps>): ReactElement {\n const titleId = useId()\n const [uncontrolledExpanded, setUncontrolledExpanded] =\n useState(defaultExpanded)\n const expanded = controlledExpanded ?? uncontrolledExpanded\n const hidden = Math.max(0, transactions.length - visibleCount)\n const collapsed = hidden > 0 && !expanded\n const shown = collapsed ? transactions.slice(0, visibleCount) : transactions\n\n function setExpanded(next: boolean) {\n if (controlledExpanded === undefined) setUncontrolledExpanded(next)\n onExpandedChange?.(next)\n }\n\n const list = (\n <TransactionList\n aria-label={listLabel ?? (typeof title === 'string' ? title : undefined)}\n >\n {shown.map(({ id, ...transaction }) => (\n <TransactionListItem\n key={id}\n {...transaction}\n {...(format ? { format } : {})}\n />\n ))}\n </TransactionList>\n )\n\n return (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-expanded={hidden > 0 ? String(expanded) : undefined}\n data-widget=\"transactions\"\n {...props}\n >\n <WidgetHeader action={action} title={title} titleId={titleId} />\n <CardPanel className=\"px-5 pb-5\">\n {transactions.length === 0 ? (\n <p\n className=\"py-6 text-center text-muted-foreground text-sm\"\n data-slot=\"transactions-empty\"\n >\n {emptyLabel}\n </p>\n ) : collapsed ? (\n <div className=\"relative\" data-slot=\"transactions-collapsed\">\n {list}\n <div className=\"pointer-events-none absolute inset-x-0 bottom-0 flex h-24 items-end justify-center bg-linear-to-t from-card from-35% to-transparent\">\n <Button\n className=\"pointer-events-auto\"\n onClick={() => setExpanded(true)}\n size=\"sm\"\n type=\"button\"\n variant=\"outline\"\n >\n {expandLabel(hidden)}\n </Button>\n </div>\n </div>\n ) : hidden > 0 ? (\n <div className=\"grid gap-3\">\n <ScrollAreaPrimitive.Root\n className=\"relative\"\n data-slot=\"transactions-scroll\"\n >\n <ScrollAreaPrimitive.Viewport\n className=\"rounded-md outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n data-slot=\"scroll-area-viewport\"\n style={{ maxHeight }}\n >\n <ScrollAreaPrimitive.Content\n className=\"pe-3\"\n data-slot=\"scroll-area-content\"\n style={{ minWidth: 0 }}\n >\n {list}\n </ScrollAreaPrimitive.Content>\n </ScrollAreaPrimitive.Viewport>\n <ScrollBar orientation=\"vertical\" />\n </ScrollAreaPrimitive.Root>\n {collapseLabel ? (\n <Button\n className=\"justify-self-center\"\n onClick={() => setExpanded(false)}\n size=\"sm\"\n type=\"button\"\n variant=\"ghost\"\n >\n {collapseLabel}\n </Button>\n ) : null}\n </div>\n ) : (\n list\n )}\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
129
|
+
"target": "~/packages/ui/src/patterns/widgets/finance/transactions-widget.tsx"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"path": "patterns/widgets/gamification/achievements-widget.tsx",
|
|
133
|
+
"type": "registry:file",
|
|
134
|
+
"content": "import { LockKeyIcon } from '@phosphor-icons/react'\nimport { CardPanel } from '@tc96/ui/card'\nimport { IconFrame } from '@tc96/ui/icon-frame'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId } from 'react'\nimport {\n ExpandableList,\n type WidgetExpandProps,\n} from '../shared/expandable-list'\nimport { WidgetHeader } from '../shared/widget-header'\nimport { WidgetShell } from '../shared/widget-shell'\nimport type { Achievement } from './types'\n\nexport interface AchievementsWidgetProps\n extends Omit<ComponentProps<'div'>, 'children' | 'title'> {\n achievements: readonly Achievement[]\n action?: ReactNode\n color?: string\n countLabel?: (unlocked: number, total: number) => ReactNode\n expand?: WidgetExpandProps\n lockedLabel?: string\n title: ReactNode\n unlockedLabel?: string\n}\n\nexport function AchievementsWidget({\n achievements,\n action,\n className,\n color = 'var(--warning-foreground)',\n countLabel = (unlocked, total) => `${unlocked} de ${total}`,\n expand,\n lockedLabel = 'bloqueada',\n title,\n unlockedLabel = 'conquistada',\n ...props\n}: Readonly<AchievementsWidgetProps>): ReactElement {\n const titleId = useId()\n const unlocked = achievements.filter((item) => item.unlocked).length\n const headerAction = action ?? (\n <span className=\"text-muted-foreground text-sm tabular-nums\">\n {countLabel(unlocked, achievements.length)}\n </span>\n )\n\n return (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-widget=\"achievements\"\n {...props}\n >\n <WidgetHeader action={headerAction} title={title} titleId={titleId} />\n <CardPanel className=\"grid gap-5 px-5 pb-5\">\n <ExpandableList items={achievements} visibleCount={6} {...expand}>\n {(shown) => (\n <ul\n className=\"grid grid-cols-2 gap-4 sm:grid-cols-3\"\n data-slot=\"achievement-list\"\n >\n {shown.map((achievement) => (\n <li\n className=\"flex flex-col items-center gap-2 text-center\"\n data-slot=\"achievement\"\n data-unlocked={achievement.unlocked ? 'true' : undefined}\n key={achievement.id}\n >\n {achievement.unlocked ? (\n <IconFrame color={color} size=\"xl\">\n {achievement.icon}\n </IconFrame>\n ) : (\n <IconFrame\n className=\"border border-input border-dashed text-muted-foreground\"\n size=\"xl\"\n variant=\"plain\"\n >\n <LockKeyIcon aria-hidden=\"true\" />\n </IconFrame>\n )}\n <span className=\"font-medium text-sm\">\n {achievement.label}\n </span>\n <span className=\"text-muted-foreground text-xs\">\n {achievement.detail}\n {!achievement.unlocked && achievement.progress ? (\n <span className=\"block tabular-nums\">\n {achievement.progress.current}/\n {achievement.progress.target}\n </span>\n ) : null}\n </span>\n <span className=\"sr-only\">\n {achievement.unlocked ? unlockedLabel : lockedLabel}\n </span>\n </li>\n ))}\n </ul>\n )}\n </ExpandableList>\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
135
|
+
"target": "~/packages/ui/src/patterns/widgets/gamification/achievements-widget.tsx"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"path": "patterns/widgets/gamification/index.ts",
|
|
139
|
+
"type": "registry:file",
|
|
140
|
+
"content": "export type { AchievementsWidgetProps } from './achievements-widget'\nexport { AchievementsWidget } from './achievements-widget'\nexport type { LevelWidgetProps } from './level-widget'\nexport { LevelWidget } from './level-widget'\nexport type {\n ProgressFooterMetric,\n ProgressFooterProps,\n ProgressFooterScore,\n} from './progress-footer'\nexport { ProgressFooter } from './progress-footer'\nexport type { ProgressHudProps } from './progress-hud'\nexport { ProgressHud } from './progress-hud'\nexport type { QuestsWidgetProps } from './quests-widget'\nexport { orderQuests, QuestsWidget } from './quests-widget'\nexport type { StreakWidgetProps } from './streak-widget'\nexport { StreakWidget } from './streak-widget'\nexport type { Achievement, Quest, StreakDay, XpProgress } from './types'\n",
|
|
141
|
+
"target": "~/packages/ui/src/patterns/widgets/gamification/index.ts"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"path": "patterns/widgets/gamification/level-widget.tsx",
|
|
145
|
+
"type": "registry:file",
|
|
146
|
+
"content": "import { CardPanel } from '@tc96/ui/card'\nimport { type AmountFormatOptions, formatAmount } from '@tc96/ui/helpers/format'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId } from 'react'\nimport { clampRatio, ProgressRing } from '../shared/progress-ring'\nimport { WidgetHeader } from '../shared/widget-header'\nimport { WidgetShell } from '../shared/widget-shell'\nimport type { XpProgress } from './types'\nimport { XpMeter } from './xp-meter'\n\nexport interface LevelWidgetProps\n extends Omit<ComponentProps<'div'>, 'children' | 'title'> {\n action?: ReactNode\n format?: AmountFormatOptions\n level: number\n levelLabel?: (level: number) => ReactNode\n meterLabel?: (nextLevel: number) => string\n remainingLabel?: (remaining: string, nextLevel: number) => ReactNode\n ringLabel?: ReactNode\n title: ReactNode\n totalLabel?: (total: string) => ReactNode\n xp: XpProgress\n}\n\nconst defaultFormat: AmountFormatOptions = {\n maximumFractionDigits: 0,\n style: 'decimal',\n}\n\nexport function LevelWidget({\n action,\n className,\n format = defaultFormat,\n level,\n levelLabel = (value) => `Nível ${value}`,\n meterLabel = (next) => `Progresso para o nível ${next}`,\n remainingLabel = (remaining, next) => (\n <>\n Faltam <span className=\"font-medium text-foreground\">{remaining} XP</span>{' '}\n para o nível {next}.\n </>\n ),\n ringLabel = 'Nível',\n title,\n totalLabel = (total) => `${total} XP no total`,\n xp,\n ...props\n}: Readonly<LevelWidgetProps>): ReactElement {\n const titleId = useId()\n const nextLevel = level + 1\n const remaining = Math.max(xp.target - xp.current, 0)\n\n return (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-widget=\"level\"\n {...props}\n >\n <WidgetHeader action={action} title={title} titleId={titleId} />\n <CardPanel className=\"grid gap-5 px-5 pb-5\">\n <div className=\"flex flex-col items-center gap-5 sm:flex-row sm:gap-6\">\n <ProgressRing\n className=\"size-28\"\n ratio={clampRatio(xp.current, xp.target)}\n strokeWidth={8}\n >\n <span className=\"text-muted-foreground text-xs uppercase tracking-widest\">\n {ringLabel}\n </span>\n <span className=\"font-medium text-4xl leading-tight tabular-nums tracking-tight\">\n {level}\n </span>\n </ProgressRing>\n <div className=\"grid w-full min-w-0 flex-1 gap-3\">\n <div className=\"flex items-baseline justify-between gap-3\">\n <p className=\"font-semibold text-lg tracking-tight\">\n {levelLabel(level)}\n </p>\n <p className=\"text-muted-foreground text-sm tabular-nums\">\n {totalLabel(formatAmount(xp.total, format))}\n </p>\n </div>\n <XpMeter\n aria-label={meterLabel(nextLevel)}\n current={xp.current}\n target={xp.target}\n />\n <p className=\"text-muted-foreground text-sm\">\n {remainingLabel(formatAmount(remaining, format), nextLevel)}\n </p>\n </div>\n </div>\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
147
|
+
"target": "~/packages/ui/src/patterns/widgets/gamification/level-widget.tsx"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"path": "patterns/widgets/gamification/progress-footer.tsx",
|
|
151
|
+
"type": "registry:file",
|
|
152
|
+
"content": "import { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { MetricPill, type MetricPillTone } from '../shared/metric-pill'\nimport { clampRatio, ProgressRing } from '../shared/progress-ring'\n\nexport interface ProgressFooterMetric {\n icon: ReactNode\n id: string\n tone?: MetricPillTone\n value: ReactNode\n}\n\nexport interface ProgressFooterScore {\n display: ReactNode\n max: number\n srLabel: string\n value: number | null\n}\n\nexport interface ProgressFooterProps\n extends Omit<ComponentProps<'div'>, 'children'> {\n metrics: readonly ProgressFooterMetric[]\n score: ProgressFooterScore\n}\n\nexport function ProgressFooter({\n className,\n metrics,\n score,\n ...props\n}: Readonly<ProgressFooterProps>): ReactElement {\n return (\n <div\n className={cn(\n 'flex items-center justify-between gap-3 text-sm',\n className,\n )}\n data-widget=\"progress-footer\"\n {...props}\n >\n <ul className=\"flex min-w-0 items-center gap-2\">\n {metrics.map((metric) => (\n <MetricPill\n as=\"li\"\n className=\"min-w-0\"\n key={metric.id}\n {...(metric.tone ? { tone: metric.tone } : {})}\n >\n {metric.icon}\n <span className=\"truncate\">{metric.value}</span>\n </MetricPill>\n ))}\n </ul>\n <span\n className={cn(\n 'inline-flex shrink-0 items-center gap-2 font-medium tabular-nums',\n score.value === null && 'text-muted-foreground',\n )}\n data-slot=\"progress-footer-score\"\n >\n <ProgressRing\n className=\"size-7\"\n empty={score.value === null}\n ratio={score.value === null ? 0 : clampRatio(score.value, score.max)}\n strokeWidth={12}\n />\n {score.display}\n {score.value === null ? null : (\n <span className=\"sr-only\"> {score.srLabel}</span>\n )}\n </span>\n </div>\n )\n}\n",
|
|
153
|
+
"target": "~/packages/ui/src/patterns/widgets/gamification/progress-footer.tsx"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"path": "patterns/widgets/gamification/progress-hud.tsx",
|
|
157
|
+
"type": "registry:file",
|
|
158
|
+
"content": "import { FireIcon, TrophyIcon } from '@phosphor-icons/react'\nimport { type AmountFormatOptions, formatAmount } from '@tc96/ui/helpers/format'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { MetricPill } from '../shared/metric-pill'\nimport { clampRatio, ProgressRing } from '../shared/progress-ring'\nimport type { XpProgress } from './types'\nimport { XpMeter } from './xp-meter'\n\nexport interface ProgressHudProps\n extends Omit<ComponentProps<'section'>, 'children'> {\n achievements?: { total: number; unlocked: number }\n achievementsLabel?: string\n 'aria-label': string\n format?: AmountFormatOptions\n level: number\n levelLabel?: (level: number) => ReactNode\n meterLabel?: (nextLevel: number) => string\n streakDays?: number\n streakLabel?: (days: number) => string\n xp: XpProgress\n}\n\nconst defaultFormat: AmountFormatOptions = {\n maximumFractionDigits: 0,\n style: 'decimal',\n}\n\nexport function ProgressHud({\n achievements,\n achievementsLabel = 'conquistas',\n 'aria-label': ariaLabel,\n className,\n format = defaultFormat,\n level,\n levelLabel = (value) => `Nível ${value}`,\n meterLabel = (next) => `Progresso para o nível ${next}`,\n streakDays,\n streakLabel = (days) => (days === 1 ? 'dia seguido' : 'dias seguidos'),\n xp,\n ...props\n}: Readonly<ProgressHudProps>): ReactElement {\n return (\n <section\n aria-label={ariaLabel}\n className={cn(\n 'flex items-center gap-3 rounded-full border border-border/80 bg-card py-1.5 ps-1.5 pe-2 text-card-foreground',\n className,\n )}\n data-widget=\"progress-hud\"\n {...props}\n >\n <ProgressRing\n className=\"size-10\"\n ratio={clampRatio(xp.current, xp.target)}\n >\n <span className=\"font-semibold text-sm tabular-nums\">{level}</span>\n </ProgressRing>\n <div className=\"grid min-w-24 flex-1 gap-1\">\n <div className=\"flex items-baseline justify-between gap-2 text-xs\">\n <span className=\"font-medium\">{levelLabel(level)}</span>\n <span className=\"text-muted-foreground tabular-nums\">\n {formatAmount(xp.current, format)}/{formatAmount(xp.target, format)}{' '}\n XP\n </span>\n </div>\n <XpMeter\n aria-label={meterLabel(level + 1)}\n className=\"w-full\"\n current={xp.current}\n target={xp.target}\n />\n </div>\n {streakDays === undefined ? null : (\n <MetricPill className=\"shrink-0\" data-slot=\"hud-streak\" tone=\"warning\">\n <FireIcon aria-hidden=\"true\" />\n {streakDays}\n <span className=\"sr-only\"> {streakLabel(streakDays)}</span>\n </MetricPill>\n )}\n {achievements ? (\n <MetricPill\n className=\"shrink-0\"\n data-slot=\"hud-achievements\"\n tone=\"primary\"\n >\n <TrophyIcon aria-hidden=\"true\" />\n {achievements.unlocked}/{achievements.total}\n <span className=\"sr-only\"> {achievementsLabel}</span>\n </MetricPill>\n ) : null}\n </section>\n )\n}\n",
|
|
159
|
+
"target": "~/packages/ui/src/patterns/widgets/gamification/progress-hud.tsx"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"path": "patterns/widgets/gamification/quests-widget.tsx",
|
|
163
|
+
"type": "registry:file",
|
|
164
|
+
"content": "import { CheckIcon } from '@phosphor-icons/react'\nimport { Badge } from '@tc96/ui/badge'\nimport { CardPanel } from '@tc96/ui/card'\nimport { Gauge } from '@tc96/ui/gauge'\nimport { IconFrame } from '@tc96/ui/icon-frame'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId } from 'react'\nimport {\n ExpandableList,\n type WidgetExpandProps,\n} from '../shared/expandable-list'\nimport { WidgetHeader } from '../shared/widget-header'\nimport { WidgetShell } from '../shared/widget-shell'\nimport type { Quest } from './types'\n\nexport interface QuestsWidgetProps\n extends Omit<ComponentProps<'div'>, 'children' | 'title'> {\n action?: ReactNode\n description?: ReactNode\n doneColor?: string\n doneLabel?: ReactNode\n expand?: WidgetExpandProps\n quests: readonly Quest[]\n title: ReactNode\n}\n\nexport function orderQuests(quests: readonly Quest[]): Quest[] {\n return [\n ...quests.filter((quest) => !quest.done),\n ...quests.filter((quest) => quest.done),\n ]\n}\n\nexport function QuestsWidget({\n action,\n className,\n description,\n doneColor = 'var(--success-foreground)',\n doneLabel = 'Concluída',\n expand,\n quests,\n title,\n ...props\n}: Readonly<QuestsWidgetProps>): ReactElement {\n const titleId = useId()\n const ordered = orderQuests(quests)\n const headerAction =\n action ??\n (description ? (\n <span className=\"text-muted-foreground text-sm tabular-nums\">\n {description}\n </span>\n ) : null)\n\n return (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-widget=\"quests\"\n {...props}\n >\n <WidgetHeader action={headerAction} title={title} titleId={titleId} />\n <CardPanel className=\"grid gap-5 px-5 pb-5\">\n <ExpandableList items={ordered} {...expand}>\n {(shown) => (\n <ul className=\"grid gap-4\" data-slot=\"quest-list\">\n {shown.map((quest) => (\n <li\n className=\"flex items-center gap-3\"\n data-done={quest.done ? 'true' : undefined}\n data-slot=\"quest\"\n key={quest.id}\n >\n {quest.done ? (\n <IconFrame color={doneColor} shape=\"rounded\">\n <CheckIcon aria-hidden=\"true\" />\n </IconFrame>\n ) : (\n <IconFrame shape=\"rounded\">{quest.icon}</IconFrame>\n )}\n <div className=\"grid min-w-0 flex-1 gap-1.5\">\n <div className=\"flex items-baseline justify-between gap-3\">\n <p\n className={cn(\n 'truncate font-medium text-sm',\n quest.done && 'text-muted-foreground line-through',\n )}\n >\n {quest.label}\n </p>\n {quest.done ? (\n <Badge variant=\"success\">{doneLabel}</Badge>\n ) : quest.progress ? (\n <span className=\"shrink-0 text-muted-foreground text-xs tabular-nums\">\n {quest.progress.current}/{quest.progress.target}\n </span>\n ) : null}\n </div>\n {!quest.done && quest.progress ? (\n <Gauge\n aria-label={quest.label}\n data-slot=\"quest-meter\"\n max={Math.max(quest.progress.target, 1)}\n size=\"sm\"\n value={Math.min(\n quest.progress.current,\n quest.progress.target,\n )}\n />\n ) : quest.detail ? (\n <p className=\"text-muted-foreground text-xs\">\n {quest.detail}\n </p>\n ) : null}\n </div>\n </li>\n ))}\n </ul>\n )}\n </ExpandableList>\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
165
|
+
"target": "~/packages/ui/src/patterns/widgets/gamification/quests-widget.tsx"
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"path": "patterns/widgets/gamification/streak-widget.tsx",
|
|
169
|
+
"type": "registry:file",
|
|
170
|
+
"content": "import { FireIcon } from '@phosphor-icons/react'\nimport { CardPanel } from '@tc96/ui/card'\nimport { IconFrame } from '@tc96/ui/icon-frame'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId } from 'react'\nimport { WidgetHeader } from '../shared/widget-header'\nimport { WidgetShell } from '../shared/widget-shell'\nimport type { StreakDay } from './types'\n\nexport interface StreakWidgetProps\n extends Omit<ComponentProps<'div'>, 'children' | 'title'> {\n action?: ReactNode\n activeLabel?: string\n color?: string\n days: number\n daysLabel?: (days: number) => ReactNode\n inactiveLabel?: string\n listLabel?: string\n title: ReactNode\n todayLabel?: string\n week: readonly StreakDay[]\n weekLabel?: ReactNode\n}\n\nexport function StreakWidget({\n action,\n activeLabel = 'estudou',\n className,\n color = 'var(--warning-foreground)',\n days,\n daysLabel = (value) => (value === 1 ? 'dia seguido' : 'dias seguidos'),\n inactiveLabel = 'sem estudo',\n listLabel = 'Dias de estudo',\n title,\n todayLabel = 'hoje',\n week,\n weekLabel = 'Últimos 7 dias',\n ...props\n}: Readonly<StreakWidgetProps>): ReactElement {\n const titleId = useId()\n\n return (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-widget=\"streak\"\n {...props}\n >\n <WidgetHeader action={action} title={title} titleId={titleId} />\n <CardPanel className=\"grid gap-5 px-5 pb-5\">\n <div className=\"flex items-center gap-3\">\n <IconFrame color={color} size=\"lg\">\n <FireIcon aria-hidden=\"true\" />\n </IconFrame>\n <div className=\"grid gap-0.5\">\n <span className=\"font-medium text-4xl leading-tight tabular-nums tracking-tight\">\n {days}\n </span>\n <span className=\"text-muted-foreground text-sm\">\n {daysLabel(days)}\n </span>\n </div>\n </div>\n <div className=\"grid gap-3\">\n <p className=\"text-muted-foreground text-xs\">{weekLabel}</p>\n <ol\n aria-label={listLabel}\n className=\"grid grid-cols-7 gap-2\"\n data-slot=\"streak-week\"\n >\n {week.map((day) => (\n <li\n className=\"flex flex-col items-center gap-1.5\"\n data-active={day.active ? 'true' : undefined}\n data-today={day.today ? 'true' : undefined}\n key={day.id}\n >\n {day.active ? (\n <IconFrame\n className={cn(\n day.today &&\n 'ring-2 ring-ring ring-offset-2 ring-offset-card',\n )}\n color={color}\n >\n <FireIcon aria-hidden=\"true\" />\n </IconFrame>\n ) : (\n <IconFrame\n className={cn(\n 'border border-input border-dashed text-muted-foreground',\n day.today &&\n 'ring-2 ring-ring ring-offset-2 ring-offset-card',\n )}\n variant=\"plain\"\n >\n <FireIcon aria-hidden=\"true\" className=\"opacity-40\" />\n </IconFrame>\n )}\n <span className=\"text-muted-foreground text-xs\">\n {day.label}\n </span>\n <span className=\"sr-only\">\n {day.today ? `, ${todayLabel}` : ''}:{' '}\n {day.active ? activeLabel : inactiveLabel}\n </span>\n </li>\n ))}\n </ol>\n </div>\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
171
|
+
"target": "~/packages/ui/src/patterns/widgets/gamification/streak-widget.tsx"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"path": "patterns/widgets/gamification/types.ts",
|
|
175
|
+
"type": "registry:file",
|
|
176
|
+
"content": "import type { ReactNode } from 'react'\n\nexport interface XpProgress {\n current: number\n target: number\n total: number\n}\n\nexport interface StreakDay {\n active: boolean\n id: string\n label: string\n today?: boolean\n}\n\nexport interface Achievement {\n detail: string\n icon: ReactNode\n id: string\n label: string\n progress?: { current: number; target: number }\n unlocked: boolean\n}\n\nexport interface Quest {\n detail?: ReactNode\n done: boolean\n icon: ReactNode\n id: string\n label: string\n progress?: { current: number; target: number }\n}\n",
|
|
177
|
+
"target": "~/packages/ui/src/patterns/widgets/gamification/types.ts"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"path": "patterns/widgets/gamification/xp-meter.tsx",
|
|
181
|
+
"type": "registry:file",
|
|
182
|
+
"content": "import { Gauge } from '@tc96/ui/gauge'\nimport type { ReactElement } from 'react'\n\nexport function XpMeter({\n 'aria-label': ariaLabel,\n className,\n current,\n target,\n}: Readonly<{\n 'aria-label': string\n className?: string\n current: number\n target: number\n}>): ReactElement {\n return (\n <Gauge\n aria-label={ariaLabel}\n className={className}\n data-slot=\"xp-meter\"\n max={Math.max(target, 1)}\n value={Math.max(current, 0)}\n />\n )\n}\n",
|
|
183
|
+
"target": "~/packages/ui/src/patterns/widgets/gamification/xp-meter.tsx"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
"path": "patterns/widgets/index.ts",
|
|
187
|
+
"type": "registry:file",
|
|
188
|
+
"content": "export * from './crm/index'\nexport * from './finance/index'\nexport * from './gamification/index'\nexport * from './productivity/index'\nexport * from './shared/index'\nexport type { TrendDirection, WidgetPeriodOption, WidgetTone } from './types'\n",
|
|
189
|
+
"target": "~/packages/ui/src/patterns/widgets/index.ts"
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"path": "patterns/widgets/productivity/agenda-widget.tsx",
|
|
193
|
+
"type": "registry:file",
|
|
194
|
+
"content": "'use client'\n\nimport { Calendar } from '@tc96/ui/calendar'\nimport { CardPanel } from '@tc96/ui/card'\nimport { calendarDateKey } from '@tc96/ui/helpers/calendar-date'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId, useState } from 'react'\nimport {\n ExpandableList,\n type WidgetExpandProps,\n} from '../shared/expandable-list'\nimport { WidgetHeader } from '../shared/widget-header'\nimport { WidgetShell } from '../shared/widget-shell'\n\nexport interface AgendaEvent {\n color?: string\n date: string\n endLabel?: ReactNode\n id: string\n startLabel?: ReactNode\n title: ReactNode\n}\n\nexport interface AgendaWidgetProps\n extends Omit<ComponentProps<'div'>, 'children' | 'onSelect' | 'title'> {\n action?: ReactNode\n calendarProps?: Omit<\n ComponentProps<typeof Calendar>,\n 'mode' | 'modifiers' | 'modifiersClassNames' | 'onSelect' | 'selected'\n >\n defaultSelected?: Date\n emptyLabel?: ReactNode\n expand?: WidgetExpandProps\n events: readonly AgendaEvent[]\n listLabel?: string\n onSelect?: (date: Date) => void\n selected?: Date\n title: ReactNode\n}\n\nfunction dayKeyOf(date: Date): string {\n return calendarDateKey({\n day: date.getDate(),\n month: date.getMonth() + 1,\n year: date.getFullYear(),\n })\n}\n\nfunction dateOfKey(key: string): Date {\n const [year = 0, month = 1, day = 1] = key.split('-').map(Number)\n return new Date(year, month - 1, day)\n}\n\nexport function AgendaWidget({\n action,\n calendarProps,\n className,\n defaultSelected = new Date(),\n emptyLabel = 'Sem eventos',\n expand,\n events,\n listLabel = 'Eventos do dia',\n onSelect,\n selected,\n title,\n ...props\n}: Readonly<AgendaWidgetProps>): ReactElement {\n const titleId = useId()\n const [internalSelected, setInternalSelected] = useState(defaultSelected)\n const current = selected ?? internalSelected\n const currentKey = dayKeyOf(current)\n const busyDays = [...new Set(events.map((event) => event.date))].map(\n dateOfKey,\n )\n const dayEvents = events.filter((event) => event.date === currentKey)\n\n return (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-widget=\"agenda\"\n {...props}\n >\n <WidgetHeader action={action} title={title} titleId={titleId} />\n <CardPanel className=\"grid gap-5 px-5 pb-5\">\n <Calendar\n className=\"mx-auto\"\n defaultMonth={current}\n {...calendarProps}\n mode=\"single\"\n modifiers={{ busy: busyDays }}\n modifiersClassNames={{\n busy: 'font-semibold underline underline-offset-4',\n }}\n onSelect={(date) => {\n if (!date) return\n if (selected === undefined) setInternalSelected(date)\n onSelect?.(date)\n }}\n selected={current}\n />\n {dayEvents.length ? (\n <ExpandableList items={dayEvents} {...expand}>\n {(shown) => (\n <ul\n aria-label={listLabel}\n className=\"divide-y divide-border/40\"\n data-slot=\"agenda-events\"\n >\n {shown.map((event) => (\n <li\n className=\"flex items-center gap-3 py-3 first:pt-0 last:pb-0\"\n data-slot=\"agenda-event\"\n key={event.id}\n >\n <span\n aria-hidden=\"true\"\n className=\"size-2 shrink-0 rounded-full\"\n style={{\n backgroundColor: event.color ?? 'var(--chart-1)',\n }}\n />\n <span className=\"min-w-0 flex-1 truncate font-medium text-sm\">\n {event.title}\n </span>\n {event.startLabel || event.endLabel ? (\n <span className=\"shrink-0 text-muted-foreground text-xs tabular-nums\">\n {event.startLabel}\n {event.startLabel && event.endLabel ? ' – ' : null}\n {event.endLabel}\n </span>\n ) : null}\n </li>\n ))}\n </ul>\n )}\n </ExpandableList>\n ) : (\n <p className=\"text-muted-foreground text-sm\" data-slot=\"agenda-empty\">\n {emptyLabel}\n </p>\n )}\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
195
|
+
"target": "~/packages/ui/src/patterns/widgets/productivity/agenda-widget.tsx"
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
"path": "patterns/widgets/productivity/index.ts",
|
|
199
|
+
"type": "registry:file",
|
|
200
|
+
"content": "export type { AgendaEvent, AgendaWidgetProps } from './agenda-widget'\nexport { AgendaWidget } from './agenda-widget'\nexport type {\n ProjectCardWidgetProps,\n ProjectSubtask,\n ProjectTag,\n} from './project-card-widget'\nexport { ProjectCardWidget } from './project-card-widget'\nexport type {\n TaskProgressPoint,\n TaskProgressWidgetProps,\n} from './task-progress-widget'\nexport { TaskProgressWidget } from './task-progress-widget'\nexport type { UpcomingEventWidgetProps } from './upcoming-event-widget'\nexport { UpcomingEventWidget } from './upcoming-event-widget'\nexport type { WorldClock, WorldClockWidgetProps } from './world-clock-widget'\nexport { WorldClockWidget } from './world-clock-widget'\n",
|
|
201
|
+
"target": "~/packages/ui/src/patterns/widgets/productivity/index.ts"
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"path": "patterns/widgets/productivity/project-card-widget.tsx",
|
|
205
|
+
"type": "registry:file",
|
|
206
|
+
"content": "'use client'\n\nimport { Badge } from '@tc96/ui/badge'\nimport { CardPanel } from '@tc96/ui/card'\nimport { Checkbox } from '@tc96/ui/checkbox'\nimport { Gauge } from '@tc96/ui/gauge'\nimport { formatAmount } from '@tc96/ui/helpers/format'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId } from 'react'\nimport { AvatarStack, type AvatarStackPerson } from '../shared/avatar-stack'\nimport {\n ExpandableList,\n type WidgetExpandProps,\n} from '../shared/expandable-list'\nimport { WidgetHeader } from '../shared/widget-header'\nimport { WidgetShell } from '../shared/widget-shell'\n\nexport interface ProjectSubtask {\n done: boolean\n id: string\n label: string\n}\n\nexport interface ProjectTag {\n id: string\n label: ReactNode\n}\n\nexport interface ProjectCardWidgetProps\n extends Omit<ComponentProps<'div'>, 'children' | 'title'> {\n action?: ReactNode\n description?: ReactNode\n endLabel?: ReactNode\n expand?: WidgetExpandProps\n footer?: ReactNode\n locale?: string\n meta?: ReactNode\n onSubtaskToggle?: (id: string, done: boolean) => void\n people?: readonly AvatarStackPerson[]\n peopleLabel?: string\n progress?: number\n progressLabel?: ReactNode\n startLabel?: ReactNode\n subtasks?: readonly ProjectSubtask[]\n subtasksLabel?: string\n tags?: readonly ProjectTag[]\n title: ReactNode\n}\n\nexport function ProjectCardWidget({\n action,\n className,\n description,\n endLabel,\n expand,\n footer,\n locale,\n meta,\n onSubtaskToggle,\n people,\n peopleLabel,\n progress,\n progressLabel = 'Progresso',\n startLabel,\n subtasks,\n subtasksLabel = 'Subtarefas',\n tags,\n title,\n ...props\n}: Readonly<ProjectCardWidgetProps>): ReactElement {\n const titleId = useId()\n const done = subtasks?.filter((subtask) => subtask.done).length ?? 0\n const total = subtasks?.length ?? 0\n const ratio = progress ?? (total ? done / total : 0)\n const value = Math.round(Math.min(1, Math.max(0, ratio)) * 100)\n\n return (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-widget=\"project-card\"\n {...props}\n >\n <WidgetHeader action={action} title={title} titleId={titleId} />\n <CardPanel className=\"grid gap-5 px-5 pb-5\">\n {tags?.length || description ? (\n <div className=\"grid gap-3\">\n {tags?.length ? (\n <ul\n className=\"flex flex-wrap gap-1.5\"\n data-slot=\"project-card-tags\"\n >\n {tags.map((tag) => (\n <li key={tag.id}>\n <Badge variant=\"outline\">{tag.label}</Badge>\n </li>\n ))}\n </ul>\n ) : null}\n {description ? (\n <p className=\"text-muted-foreground text-sm\">{description}</p>\n ) : null}\n </div>\n ) : null}\n {subtasks?.length ? (\n <ExpandableList items={subtasks} {...expand}>\n {(shown) => (\n <ul\n aria-label={subtasksLabel}\n className=\"grid gap-2.5\"\n data-slot=\"project-card-subtasks\"\n >\n {shown.map((subtask) => {\n const subtaskId = `${titleId}-${subtask.id}`\n return (\n <li className=\"flex items-center gap-2.5\" key={subtask.id}>\n <Checkbox\n checked={subtask.done}\n id={subtaskId}\n {...(onSubtaskToggle\n ? {\n onCheckedChange: (checked: boolean) =>\n onSubtaskToggle(subtask.id, checked),\n }\n : { readOnly: true })}\n />\n <label\n className={cn(\n 'text-sm',\n subtask.done && 'text-muted-foreground line-through',\n )}\n htmlFor={subtaskId}\n >\n {subtask.label}\n </label>\n </li>\n )\n })}\n </ul>\n )}\n </ExpandableList>\n ) : null}\n <div className=\"grid gap-2\">\n <div className=\"flex items-center justify-between gap-3\">\n <span\n className=\"text-muted-foreground text-sm\"\n id={`${titleId}-progress`}\n >\n {progressLabel}\n </span>\n <span className=\"font-medium text-foreground text-sm tabular-nums\">\n {formatAmount(value / 100, {\n maximumFractionDigits: 0,\n style: 'percent',\n ...(locale ? { locale } : {}),\n })}\n </span>\n </div>\n <Gauge\n aria-labelledby={`${titleId}-progress`}\n data-slot=\"project-card-progress\"\n value={value}\n />\n {startLabel || endLabel ? (\n <div className=\"flex justify-between gap-3 text-muted-foreground text-xs\">\n <span>{startLabel}</span>\n <span>{endLabel}</span>\n </div>\n ) : null}\n </div>\n {people?.length || meta || footer ? (\n <div className=\"flex items-center justify-between gap-3\">\n {people?.length ? (\n <AvatarStack\n people={people}\n {...(peopleLabel ? { 'aria-label': peopleLabel } : {})}\n />\n ) : (\n <span />\n )}\n {meta ? (\n <div\n className=\"flex items-center gap-3 text-muted-foreground text-sm tabular-nums\"\n data-slot=\"project-card-meta\"\n >\n {meta}\n </div>\n ) : null}\n </div>\n ) : null}\n {footer}\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
207
|
+
"target": "~/packages/ui/src/patterns/widgets/productivity/project-card-widget.tsx"
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
"path": "patterns/widgets/productivity/task-progress-widget.tsx",
|
|
211
|
+
"type": "registry:file",
|
|
212
|
+
"content": "'use client'\n\nimport { CardPanel } from '@tc96/ui/card'\nimport { type AmountFormatOptions, formatAmount } from '@tc96/ui/helpers/format'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId } from 'react'\nimport { Bar, BarChart, ResponsiveContainer, Tooltip, XAxis } from 'recharts'\nimport { StatList, type WidgetStat } from '../shared/stat-list'\nimport { TrendIndicator } from '../shared/trend-indicator'\nimport { WidgetHeader } from '../shared/widget-header'\nimport { WidgetPeriodToggle } from '../shared/widget-period-toggle'\nimport { WidgetShell } from '../shared/widget-shell'\nimport type { WidgetPeriodOption } from '../types'\n\nexport interface TaskProgressPoint {\n label: string\n value: number\n}\n\nexport interface TaskProgressWidgetProps<TPeriod extends string = string>\n extends Omit<ComponentProps<'div'>, 'children' | 'title'> {\n change?: number\n changeFormat?: AmountFormatOptions\n changeLabel?: ReactNode\n chartLabel?: string\n color?: string\n data: readonly TaskProgressPoint[]\n format?: AmountFormatOptions\n height?: number\n onPeriodChange?: (period: TPeriod) => void\n period?: TPeriod\n periodLabel?: string\n periods?: readonly WidgetPeriodOption<TPeriod>[]\n stats?: readonly WidgetStat[]\n title: ReactNode\n tone?: 'default' | 'inverted'\n}\n\nfunction TaskProgressTooltip({\n active,\n format,\n payload,\n}: {\n active?: boolean\n format?: AmountFormatOptions\n payload?: readonly { payload?: unknown }[]\n}): ReactElement | null {\n const point = payload?.[0]?.payload as TaskProgressPoint | undefined\n if (!active || !point) return null\n\n return (\n <div className=\"grid gap-0.5 rounded-lg border bg-popover px-2.5 py-1.5 text-popover-foreground text-xs shadow-md/5\">\n <span className=\"text-muted-foreground\">{point.label}</span>\n <span className=\"font-medium tabular-nums\">\n {formatAmount(point.value, format ?? { style: 'decimal' })}\n </span>\n </div>\n )\n}\n\nexport function TaskProgressWidget<TPeriod extends string = string>({\n change,\n changeFormat,\n changeLabel,\n chartLabel,\n className,\n color = 'var(--chart-1)',\n data,\n format,\n height = 140,\n onPeriodChange,\n period,\n periodLabel,\n periods,\n stats,\n title,\n tone = 'default',\n ...props\n}: Readonly<TaskProgressWidgetProps<TPeriod>>): ReactElement {\n const titleId = useId()\n const card = (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-tone={tone}\n data-widget=\"task-progress\"\n {...props}\n >\n <WidgetHeader\n action={\n periods?.length ? (\n <WidgetPeriodToggle\n options={periods}\n {...(period === undefined ? {} : { value: period })}\n {...(onPeriodChange ? { onValueChange: onPeriodChange } : {})}\n {...(periodLabel ? { 'aria-label': periodLabel } : {})}\n />\n ) : change === undefined ? null : (\n <div className=\"flex items-center gap-2 text-muted-foreground text-sm\">\n <TrendIndicator\n value={change}\n {...(changeFormat ? { format: changeFormat } : {})}\n />\n {changeLabel}\n </div>\n )\n }\n title={title}\n titleId={titleId}\n />\n <CardPanel className=\"grid gap-5 px-5 pb-5\">\n {periods?.length && change !== undefined ? (\n <div className=\"flex items-center gap-2 text-muted-foreground text-sm\">\n <TrendIndicator\n value={change}\n {...(changeFormat ? { format: changeFormat } : {})}\n />\n {changeLabel}\n </div>\n ) : null}\n <div\n aria-label={\n chartLabel ?? (typeof title === 'string' ? title : 'Gráfico')\n }\n className=\"-mx-1 min-w-0\"\n data-slot=\"task-progress-chart\"\n role=\"img\"\n style={{ height }}\n >\n <ResponsiveContainer\n height=\"100%\"\n initialDimension={{ height, width: 320 }}\n width=\"100%\"\n >\n <BarChart\n accessibilityLayer={false}\n barCategoryGap=\"28%\"\n data={[...data]}\n margin={{ bottom: 0, left: 4, right: 4, top: 4 }}\n >\n <XAxis\n axisLine={false}\n dataKey=\"label\"\n interval=\"preserveStartEnd\"\n tick={{ fill: 'var(--muted-foreground)', fontSize: 12 }}\n tickLine={false}\n tickMargin={8}\n />\n <Tooltip\n content={(tooltip) => (\n <TaskProgressTooltip\n {...tooltip}\n {...(format ? { format } : {})}\n />\n )}\n cursor={{ fill: 'var(--muted)' }}\n />\n <Bar\n dataKey=\"value\"\n fill={color}\n isAnimationActive={false}\n radius={[6, 6, 6, 6]}\n />\n </BarChart>\n </ResponsiveContainer>\n </div>\n {stats?.length ? <StatList stats={stats} /> : null}\n </CardPanel>\n </WidgetShell>\n )\n\n return tone === 'inverted' ? (\n <div className=\"dark contents\" data-slot=\"task-progress-widget-scope\">\n {card}\n </div>\n ) : (\n card\n )\n}\n",
|
|
213
|
+
"target": "~/packages/ui/src/patterns/widgets/productivity/task-progress-widget.tsx"
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"path": "patterns/widgets/productivity/upcoming-event-widget.tsx",
|
|
217
|
+
"type": "registry:file",
|
|
218
|
+
"content": "'use client'\n\nimport { CopyIcon } from '@phosphor-icons/react'\nimport { Button } from '@tc96/ui/button'\nimport { CardPanel } from '@tc96/ui/card'\nimport { copyToClipboard } from '@tc96/ui/helpers/clipboard'\nimport { formatTimeOfDay, type TimeOfDayOptions } from '@tc96/ui/helpers/time'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useId } from 'react'\nimport { WidgetShell } from '../shared/widget-shell'\n\nconst halfHourMs = 30 * 60 * 1000\n\nexport interface UpcomingEventWidgetProps\n extends Omit<ComponentProps<'div'>, 'children' | 'onCopy' | 'title'>,\n TimeOfDayOptions {\n copyLabel?: string\n end: Date\n eyebrow?: ReactNode\n joinHref?: string\n joinLabel?: ReactNode\n joinText?: ReactNode\n live?: boolean\n onCopy?: (href: string) => void\n provider?: ReactNode\n start: Date\n timelineLabel?: string\n title: ReactNode\n windowEnd?: Date\n windowStart?: Date\n}\n\nfunction ratio(instant: Date, from: Date, to: Date): number {\n const span = to.getTime() - from.getTime()\n if (span <= 0) return 0\n return Math.min(1, Math.max(0, (instant.getTime() - from.getTime()) / span))\n}\n\nfunction percent(value: number): string {\n return `${(value * 100).toFixed(3)}%`\n}\n\nexport function UpcomingEventWidget({\n className,\n copyLabel = 'Copiar link',\n end,\n eyebrow,\n hourCycle,\n joinHref,\n joinLabel = 'Entrar na reunião',\n joinText,\n live = false,\n locale,\n onCopy,\n provider,\n start,\n timeZone,\n timelineLabel,\n title,\n windowEnd = new Date(end.getTime() + halfHourMs),\n windowStart = new Date(start.getTime() - halfHourMs),\n ...props\n}: Readonly<UpcomingEventWidgetProps>): ReactElement {\n const titleId = useId()\n const timeOptions: TimeOfDayOptions = {\n ...(hourCycle ? { hourCycle } : {}),\n ...(locale ? { locale } : {}),\n ...(timeZone ? { timeZone } : {}),\n }\n const format = (instant: Date) => formatTimeOfDay(instant, timeOptions)\n const startRatio = ratio(start, windowStart, windowEnd)\n const endRatio = ratio(end, windowStart, windowEnd)\n const tickCount = Math.floor(\n (windowEnd.getTime() - windowStart.getTime()) / halfHourMs,\n )\n const ticks = Array.from({ length: Math.max(0, tickCount - 1) }, (_, index) =>\n percent((index + 1) / tickCount),\n )\n const labels = [\n { id: 'window-start', instant: windowStart, ratio: 0 },\n { id: 'start', instant: start, ratio: startRatio },\n { id: 'end', instant: end, ratio: endRatio },\n { id: 'window-end', instant: windowEnd, ratio: 1 },\n ].filter(\n (label, index, all) =>\n all.findIndex((other) => other.ratio === label.ratio) === index,\n )\n\n return (\n <WidgetShell\n aria-labelledby={titleId}\n className={className}\n data-widget=\"upcoming-event\"\n {...props}\n >\n <CardPanel className=\"grid gap-5 p-5\">\n <div className=\"grid gap-1\">\n {eyebrow ? (\n <p className=\"flex items-center gap-2 text-muted-foreground text-sm\">\n {live ? (\n <span\n aria-hidden=\"true\"\n className=\"size-2 shrink-0 rounded-full bg-destructive\"\n data-slot=\"upcoming-event-live\"\n />\n ) : null}\n {eyebrow}\n </p>\n ) : null}\n <h3 className=\"font-semibold text-base\" id={titleId}>\n {title}\n </h3>\n </div>\n <div\n aria-label={timelineLabel ?? `${format(start)} – ${format(end)}`}\n className=\"grid gap-2\"\n data-slot=\"upcoming-event-timeline\"\n role=\"img\"\n >\n <div className=\"relative h-12 overflow-hidden rounded-md bg-muted/40\">\n {ticks.map((left) => (\n <span\n className=\"absolute inset-y-0 w-px bg-border\"\n key={left}\n style={{ left }}\n />\n ))}\n <span\n className=\"absolute inset-y-1.5 rounded-md border border-info/40 bg-info/10 bg-[repeating-linear-gradient(90deg,var(--info)_0_1px,transparent_1px_8px)] opacity-80\"\n data-slot=\"upcoming-event-slot\"\n style={{\n left: percent(startRatio),\n width: percent(Math.max(0, endRatio - startRatio)),\n }}\n />\n </div>\n <div className=\"relative h-4 text-muted-foreground text-xs tabular-nums\">\n {labels.map((label) => (\n <span\n className={cn(\n 'absolute top-0',\n label.ratio === 0\n ? 'start-0'\n : label.ratio === 1\n ? 'end-0'\n : '-translate-x-1/2',\n )}\n key={label.id}\n style={\n label.ratio > 0 && label.ratio < 1\n ? { left: percent(label.ratio) }\n : undefined\n }\n >\n {format(label.instant)}\n </span>\n ))}\n </div>\n </div>\n {joinHref ? (\n <div className=\"flex items-center gap-3\">\n <div className=\"grid min-w-0 flex-1 gap-0.5\">\n <a\n className=\"truncate font-semibold text-sm underline-offset-4 hover:underline\"\n data-slot=\"upcoming-event-join\"\n href={joinHref}\n >\n {joinLabel}\n </a>\n {joinText ? (\n <span className=\"flex min-w-0 items-center gap-1 text-muted-foreground text-sm\">\n <span className=\"truncate\">{joinText}</span>\n <Button\n aria-label={copyLabel}\n onClick={() => {\n void copyToClipboard(joinHref)?.catch(() => undefined)\n onCopy?.(joinHref)\n }}\n size=\"icon-xs\"\n type=\"button\"\n variant=\"ghost\"\n >\n <CopyIcon aria-hidden=\"true\" />\n </Button>\n </span>\n ) : null}\n </div>\n {provider ? (\n <span\n className=\"inline-flex size-10 shrink-0 items-center justify-center rounded-lg bg-muted [&_svg:not([class*='size-'])]:size-5\"\n data-slot=\"upcoming-event-provider\"\n >\n {provider}\n </span>\n ) : null}\n </div>\n ) : null}\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
219
|
+
"target": "~/packages/ui/src/patterns/widgets/productivity/upcoming-event-widget.tsx"
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"path": "patterns/widgets/productivity/world-clock-widget.tsx",
|
|
223
|
+
"type": "registry:file",
|
|
224
|
+
"content": "'use client'\n\nimport { CardPanel } from '@tc96/ui/card'\nimport { splitTimeOfDay, type TimeOfDayOptions } from '@tc96/ui/helpers/time'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\nimport { useEffect, useState } from 'react'\nimport { WidgetShell } from '../shared/widget-shell'\n\nexport interface WorldClock {\n id: string\n label: ReactNode\n meta?: ReactNode\n timeZone: string\n}\n\nexport interface WorldClockWidgetProps\n extends Omit<ComponentProps<'div'>, 'children' | 'title'>,\n Omit<TimeOfDayOptions, 'timeZone'> {\n clocks: readonly WorldClock[]\n label?: string\n now?: Date\n showSeconds?: boolean\n}\n\nfunction useTickingNow(now: Date | undefined): Date {\n const [ticking, setTicking] = useState(() => now ?? new Date())\n\n useEffect(() => {\n if (now) return\n const interval = setInterval(() => setTicking(new Date()), 1000)\n return () => clearInterval(interval)\n }, [now])\n\n return now ?? ticking\n}\n\nexport function WorldClockWidget({\n className,\n clocks,\n hourCycle,\n label = 'Relógios',\n locale,\n now,\n showSeconds = true,\n ...props\n}: Readonly<WorldClockWidgetProps>): ReactElement {\n const instant = useTickingNow(now)\n const dateTime = instant.toISOString()\n\n return (\n <WidgetShell\n aria-label={label}\n className={className}\n data-widget=\"world-clock\"\n {...props}\n >\n <CardPanel className=\"py-5\">\n <div className=\"grid auto-cols-fr grid-flow-col divide-x divide-border/40\">\n {clocks.map((clock) => {\n const parts = splitTimeOfDay(instant, {\n timeZone: clock.timeZone,\n ...(hourCycle ? { hourCycle } : {}),\n ...(locale ? { locale } : {}),\n })\n return (\n <div\n className=\"grid min-w-0 gap-1 px-5\"\n data-slot=\"world-clock-item\"\n key={clock.id}\n >\n <time\n className=\"whitespace-nowrap font-medium text-3xl leading-tight tracking-tight tabular-nums\"\n dateTime={dateTime}\n >\n {parts.hourMinute}\n <span\n className={cn(\n 'text-base text-muted-foreground',\n showSeconds ? undefined : 'sr-only',\n )}\n >\n {showSeconds ? parts.second : null}\n {parts.dayPeriod}\n </span>\n </time>\n <span className=\"truncate text-sm\">{clock.label}</span>\n {clock.meta ? (\n <span className=\"truncate text-muted-foreground text-xs\">\n {clock.meta}\n </span>\n ) : null}\n </div>\n )\n })}\n </div>\n </CardPanel>\n </WidgetShell>\n )\n}\n",
|
|
225
|
+
"target": "~/packages/ui/src/patterns/widgets/productivity/world-clock-widget.tsx"
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
"path": "patterns/widgets/shared/amount.tsx",
|
|
229
|
+
"type": "registry:file",
|
|
230
|
+
"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",
|
|
231
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/amount.tsx"
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"path": "patterns/widgets/shared/avatar-stack.tsx",
|
|
235
|
+
"type": "registry:file",
|
|
236
|
+
"content": "import { Avatar, AvatarFallback, AvatarImage } from '@tc96/ui/avatar'\nimport { resolveInitials } from '@tc96/ui/helpers/initials'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement } from 'react'\n\nexport interface AvatarStackPerson {\n fallback?: string\n id: string\n imageUrl?: string\n label: string\n}\n\nexport type AvatarStackSize = 'default' | 'sm'\n\nconst avatarClassNames: Record<AvatarStackSize, string | undefined> = {\n default: undefined,\n sm: '[--avatar-size:--spacing(6)] text-[0.625rem]',\n}\n\nconst overflowClassNames: Record<AvatarStackSize, string> = {\n default: 'size-8 text-xs',\n sm: 'size-6 text-[0.625rem]',\n}\n\nexport interface AvatarStackProps\n extends Omit<ComponentProps<'ul'>, 'children'> {\n 'aria-label'?: string\n max?: number\n people: readonly AvatarStackPerson[]\n size?: AvatarStackSize\n}\n\nexport function AvatarStack({\n 'aria-label': ariaLabel = 'Pessoas',\n className,\n max = 3,\n people,\n size = 'default',\n ...props\n}: Readonly<AvatarStackProps>): ReactElement {\n const shown = people.slice(0, max)\n const hidden = people.slice(max)\n\n return (\n <ul\n aria-label={ariaLabel}\n className={cn('flex items-center -space-x-2', className)}\n data-slot=\"avatar-stack\"\n {...props}\n >\n {shown.map((person) => (\n <li\n className=\"flex rounded-full border border-input bg-card\"\n key={person.id}\n >\n <Avatar className={avatarClassNames[size]} data-size={size}>\n {person.imageUrl ? (\n <AvatarImage alt=\"\" src={person.imageUrl} />\n ) : null}\n <AvatarFallback>{resolveInitials(person)}</AvatarFallback>\n </Avatar>\n <span className=\"sr-only\">{person.label}</span>\n </li>\n ))}\n {hidden.length ? (\n <li className=\"flex rounded-full border border-input bg-card\">\n <span\n className={cn(\n 'inline-flex shrink-0 items-center justify-center rounded-full bg-muted font-medium text-muted-foreground tabular-nums',\n overflowClassNames[size],\n )}\n data-slot=\"avatar-stack-overflow\"\n >\n <span aria-hidden=\"true\">+{hidden.length}</span>\n <span className=\"sr-only\">\n {hidden.map((person) => person.label).join(', ')}\n </span>\n </span>\n </li>\n ) : null}\n </ul>\n )\n}\n",
|
|
237
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/avatar-stack.tsx"
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
"path": "patterns/widgets/shared/expandable-list.tsx",
|
|
241
|
+
"type": "registry:file",
|
|
242
|
+
"content": "'use client'\n\nimport { Button } from '@tc96/ui/button'\nimport { ScrollAreaPrimitive, ScrollBar } from '@tc96/ui/scroll-area'\nimport { cn } from '@tc96/utils'\nimport type { ReactElement, ReactNode } from 'react'\nimport { useState } from 'react'\n\nexport interface WidgetExpandProps {\n collapseLabel?: ReactNode\n defaultExpanded?: boolean\n expandLabel?: (hidden: number) => ReactNode\n expanded?: boolean\n maxHeight?: number\n onExpandedChange?: (expanded: boolean) => void\n visibleCount?: number\n}\n\nexport interface ExpandableListProps<TItem> extends WidgetExpandProps {\n children: (items: readonly TItem[]) => ReactNode\n className?: string\n items: readonly TItem[]\n}\n\nexport const defaultVisibleCount = 5\nexport const defaultExpandMaxHeight = 420\n\nfunction defaultExpandLabel(hidden: number): ReactNode {\n return `Ver todas (+${hidden})`\n}\n\nexport function ExpandableList<TItem>({\n children,\n className,\n collapseLabel = 'Ver menos',\n defaultExpanded = false,\n expandLabel = defaultExpandLabel,\n expanded: controlledExpanded,\n items,\n maxHeight = defaultExpandMaxHeight,\n onExpandedChange,\n visibleCount = defaultVisibleCount,\n}: Readonly<ExpandableListProps<TItem>>): ReactElement {\n const [uncontrolledExpanded, setUncontrolledExpanded] =\n useState(defaultExpanded)\n const expanded = controlledExpanded ?? uncontrolledExpanded\n const hidden = Math.max(0, items.length - visibleCount)\n\n function setExpanded(next: boolean) {\n if (controlledExpanded === undefined) setUncontrolledExpanded(next)\n onExpandedChange?.(next)\n }\n\n if (hidden === 0)\n return (\n <div className={className} data-slot=\"expandable-list\">\n {children(items)}\n </div>\n )\n\n if (!expanded)\n return (\n <div\n className={cn('relative', className)}\n data-expanded=\"false\"\n data-slot=\"expandable-list\"\n >\n {children(items.slice(0, visibleCount))}\n <div className=\"pointer-events-none absolute inset-x-0 bottom-0 flex h-24 items-end justify-center bg-linear-to-t from-35% from-card to-transparent\">\n <Button\n className=\"pointer-events-auto\"\n onClick={() => setExpanded(true)}\n size=\"sm\"\n type=\"button\"\n variant=\"outline\"\n >\n {expandLabel(hidden)}\n </Button>\n </div>\n </div>\n )\n\n return (\n <div\n className={cn('grid gap-3', className)}\n data-expanded=\"true\"\n data-slot=\"expandable-list\"\n >\n <ScrollAreaPrimitive.Root\n className=\"relative\"\n data-slot=\"expandable-list-scroll\"\n >\n <ScrollAreaPrimitive.Viewport\n className=\"rounded-md outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n data-slot=\"scroll-area-viewport\"\n style={{ maxHeight }}\n >\n <ScrollAreaPrimitive.Content\n className=\"pe-3\"\n data-slot=\"scroll-area-content\"\n style={{ minWidth: 0 }}\n >\n {children(items)}\n </ScrollAreaPrimitive.Content>\n </ScrollAreaPrimitive.Viewport>\n <ScrollBar orientation=\"vertical\" />\n </ScrollAreaPrimitive.Root>\n {collapseLabel ? (\n <Button\n className=\"justify-self-center\"\n onClick={() => setExpanded(false)}\n size=\"sm\"\n type=\"button\"\n variant=\"ghost\"\n >\n {collapseLabel}\n </Button>\n ) : null}\n </div>\n )\n}\n",
|
|
243
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/expandable-list.tsx"
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
"path": "patterns/widgets/shared/index.ts",
|
|
247
|
+
"type": "registry:file",
|
|
248
|
+
"content": "export type { AmountFormatOptions } from '@tc96/ui/helpers/format'\nexport { formatAmount } from '@tc96/ui/helpers/format'\nexport type {\n IconFrameProps,\n IconFrameShape,\n IconFrameSize,\n IconFrameVariant,\n} from '@tc96/ui/icon-frame'\nexport { IconFrame } from '@tc96/ui/icon-frame'\nexport type { AmountProps } from './amount'\nexport { Amount } from './amount'\nexport type { AvatarStackPerson, AvatarStackProps } from './avatar-stack'\nexport { AvatarStack } from './avatar-stack'\nexport type {\n ExpandableListProps,\n WidgetExpandProps,\n} from './expandable-list'\nexport {\n defaultExpandMaxHeight,\n defaultVisibleCount,\n ExpandableList,\n} from './expandable-list'\nexport type { MetricPillProps, MetricPillTone } from './metric-pill'\nexport { MetricPill } from './metric-pill'\nexport type { ProgressRingProps } from './progress-ring'\nexport { clampRatio, ProgressRing } from './progress-ring'\nexport type { StatListProps, WidgetStat } from './stat-list'\nexport { StatList } from './stat-list'\nexport type {\n TrendIndicatorLabels,\n TrendIndicatorProps,\n} from './trend-indicator'\nexport { TrendIndicator } from './trend-indicator'\nexport type { WidgetPeriodToggleProps } from './widget-period-toggle'\nexport { WidgetPeriodToggle } from './widget-period-toggle'\nexport type { WidgetShellProps } from './widget-shell'\nexport { WidgetShell } from './widget-shell'\n",
|
|
249
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/index.ts"
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
"path": "patterns/widgets/shared/metric-pill.tsx",
|
|
253
|
+
"type": "registry:file",
|
|
254
|
+
"content": "import { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement } from 'react'\n\nexport type MetricPillTone = 'muted' | 'primary' | 'success' | 'warning'\n\nexport interface MetricPillProps extends Omit<ComponentProps<'span'>, 'ref'> {\n as?: 'li' | 'span'\n tone?: MetricPillTone\n}\n\nconst tones: Record<MetricPillTone, string> = {\n muted: 'bg-muted text-muted-foreground',\n primary: 'bg-primary/10 [&>svg]:text-primary',\n success: 'bg-success/15 [&>svg]:text-success-foreground',\n warning: 'bg-warning/15 [&>svg]:text-warning-foreground',\n}\n\nexport function MetricPill({\n as: Tag = 'span',\n className,\n tone = 'muted',\n ...props\n}: Readonly<MetricPillProps>): ReactElement {\n return (\n <Tag\n className={cn(\n 'inline-flex items-center gap-1 whitespace-nowrap rounded-full px-2.5 py-1 font-medium text-sm tabular-nums [&>svg]:size-4 [&>svg]:shrink-0',\n tones[tone],\n className,\n )}\n data-slot=\"metric-pill\"\n data-tone={tone}\n {...props}\n />\n )\n}\n",
|
|
255
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/metric-pill.tsx"
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
"path": "patterns/widgets/shared/progress-ring.tsx",
|
|
259
|
+
"type": "registry:file",
|
|
260
|
+
"content": "import { GaugeRing } from '@tc96/ui/gauge'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\n\nexport interface ProgressRingProps\n extends Omit<ComponentProps<'div'>, 'children'> {\n children?: ReactNode\n empty?: boolean\n ratio: number\n strokeWidth?: number\n}\n\nexport function clampRatio(current: number, target: number): number {\n return target > 0 ? Math.min(Math.max(current / target, 0), 1) : 0\n}\n\nexport function ProgressRing({\n children,\n className,\n empty = false,\n ratio,\n strokeWidth = 10,\n ...props\n}: Readonly<ProgressRingProps>): ReactElement {\n return (\n <GaugeRing\n className={cn('size-10', className)}\n data-slot=\"progress-ring\"\n empty={empty}\n ratio={ratio}\n strokeWidth={strokeWidth}\n {...props}\n >\n {children}\n </GaugeRing>\n )\n}\n",
|
|
261
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/progress-ring.tsx"
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
"path": "patterns/widgets/shared/stat-list.tsx",
|
|
265
|
+
"type": "registry:file",
|
|
266
|
+
"content": "import { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement, ReactNode } from 'react'\n\nexport interface WidgetStat {\n id: string\n label: ReactNode\n value: ReactNode\n}\n\nexport interface StatListProps extends Omit<ComponentProps<'dl'>, 'children'> {\n stats: readonly WidgetStat[]\n}\n\nexport function StatList({\n className,\n stats,\n ...props\n}: Readonly<StatListProps>): ReactElement {\n return (\n <dl\n className={cn('flex flex-wrap gap-x-4 gap-y-3', className)}\n data-slot=\"stat-list\"\n {...props}\n >\n {stats.map((stat) => (\n <div\n className=\"grid gap-1 not-first:border-border/40 not-first:border-s not-first:ps-4\"\n key={stat.id}\n >\n <dt className=\"text-muted-foreground text-sm\">{stat.label}</dt>\n <dd className=\"font-medium text-lg tabular-nums\">{stat.value}</dd>\n </div>\n ))}\n </dl>\n )\n}\n",
|
|
267
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/stat-list.tsx"
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"path": "patterns/widgets/shared/trend-indicator.tsx",
|
|
271
|
+
"type": "registry:file",
|
|
272
|
+
"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",
|
|
273
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/trend-indicator.tsx"
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
"path": "patterns/widgets/shared/widget-header.tsx",
|
|
277
|
+
"type": "registry:file",
|
|
278
|
+
"content": "import { CardAction, CardHeader, CardTitle } from '@tc96/ui/card'\nimport type { ReactElement, ReactNode } from 'react'\n\nexport function WidgetHeader({\n action,\n title,\n titleId,\n}: Readonly<{\n action?: ReactNode\n title: ReactNode\n titleId: string\n}>): ReactElement {\n return (\n <CardHeader className=\"grid-rows-1 items-center p-5\">\n <CardTitle className=\"font-semibold text-base\" id={titleId}>\n {title}\n </CardTitle>\n {action ? (\n <CardAction className=\"row-span-1 self-center\">{action}</CardAction>\n ) : null}\n </CardHeader>\n )\n}\n",
|
|
279
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/widget-header.tsx"
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
"path": "patterns/widgets/shared/widget-period-toggle.tsx",
|
|
283
|
+
"type": "registry:file",
|
|
284
|
+
"content": "'use client'\n\nimport { ToggleGroup, ToggleGroupItem } from '@tc96/ui/toggle-group'\nimport type { ReactElement } from 'react'\nimport type { WidgetPeriodOption } from '../types'\n\nexport interface WidgetPeriodToggleProps<TPeriod extends string = string> {\n 'aria-label'?: string\n className?: string\n onValueChange?: (period: TPeriod) => void\n options: readonly WidgetPeriodOption<TPeriod>[]\n value?: TPeriod\n}\n\nexport function WidgetPeriodToggle<TPeriod extends string = string>({\n 'aria-label': ariaLabel = 'Período',\n className,\n onValueChange,\n options,\n value,\n}: Readonly<WidgetPeriodToggleProps<TPeriod>>): ReactElement {\n return (\n <ToggleGroup\n aria-label={ariaLabel}\n className={className}\n data-slot=\"widget-period-toggle\"\n onValueChange={(next) => {\n const [period] = next as TPeriod[]\n if (period) onValueChange?.(period)\n }}\n size=\"default\"\n value={value === undefined ? [] : [value]}\n variant=\"default\"\n >\n {options.map((option) => (\n <ToggleGroupItem key={option.value} value={option.value}>\n {option.label}\n </ToggleGroupItem>\n ))}\n </ToggleGroup>\n )\n}\n",
|
|
285
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/widget-period-toggle.tsx"
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
"path": "patterns/widgets/shared/widget-shell.tsx",
|
|
289
|
+
"type": "registry:file",
|
|
290
|
+
"content": "import { Card } from '@tc96/ui/card'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactElement } from 'react'\n\nexport interface WidgetShellProps extends ComponentProps<typeof Card> {}\n\nexport function WidgetShell({\n className,\n render = <section />,\n ...props\n}: Readonly<WidgetShellProps>): ReactElement {\n return (\n <Card\n className={cn('min-w-0 border-transparent', className)}\n render={render}\n {...props}\n />\n )\n}\n",
|
|
291
|
+
"target": "~/packages/ui/src/patterns/widgets/shared/widget-shell.tsx"
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
"path": "patterns/widgets/types/index.ts",
|
|
295
|
+
"type": "registry:file",
|
|
296
|
+
"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",
|
|
297
|
+
"target": "~/packages/ui/src/patterns/widgets/types/index.ts"
|
|
298
|
+
}
|
|
299
|
+
],
|
|
300
|
+
"dependencies": [
|
|
301
|
+
"@phosphor-icons/react@2.1.10",
|
|
302
|
+
"react@19.1.1",
|
|
303
|
+
"recharts@3.10.1"
|
|
304
|
+
],
|
|
305
|
+
"registryDependencies": [
|
|
306
|
+
"@ui/avatar",
|
|
307
|
+
"@ui/badge",
|
|
308
|
+
"@ui/button",
|
|
309
|
+
"@ui/calendar",
|
|
310
|
+
"@ui/card",
|
|
311
|
+
"@ui/checkbox",
|
|
312
|
+
"@ui/gauge",
|
|
313
|
+
"@ui/icon-frame",
|
|
314
|
+
"@ui/meter",
|
|
315
|
+
"@ui/scroll-area",
|
|
316
|
+
"@ui/toggle-group"
|
|
317
|
+
],
|
|
318
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json"
|
|
319
|
+
}
|