@tc96/cli 0.0.0-stage → 0.27.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 +1395 -0
- package/package.json +35 -4
- package/registry/agent-builder.json +503 -0
- package/registry/aggregate.json +4 -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/app-shell-5.json +106 -0
- package/registry/bulk-import-1.json +151 -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 +307 -0
- package/registry/collection-layouts.json +836 -0
- package/registry/collection-views.json +836 -0
- package/registry/collection.json +831 -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/detail-sheet.json +54 -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/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/icon-row.json +52 -0
- package/registry/impact-map.json +75 -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/lookup-create-1.json +157 -0
- package/registry/magic-link-6.json +79 -0
- package/registry/navbar-1.json +66 -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/next-steps-1.json +147 -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/properties.json +523 -0
- package/registry/record-dialog.json +88 -0
- package/registry/record-group.json +190 -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/rich-text-editor.json +93 -0
- package/registry/run-monitor.json +198 -0
- package/registry/settings-1.json +119 -0
- package/registry/settings-10.json +218 -0
- package/registry/settings-11.json +129 -0
- package/registry/settings-12.json +130 -0
- package/registry/settings-13.json +130 -0
- package/registry/settings-14.json +173 -0
- package/registry/settings-15.json +149 -0
- package/registry/settings-16.json +129 -0
- package/registry/settings-17.json +117 -0
- package/registry/settings-18.json +117 -0
- package/registry/settings-19.json +125 -0
- package/registry/settings-2.json +123 -0
- package/registry/settings-20.json +112 -0
- package/registry/settings-21.json +116 -0
- package/registry/settings-22.json +118 -0
- package/registry/settings-23.json +118 -0
- package/registry/settings-3.json +123 -0
- package/registry/settings-4.json +116 -0
- package/registry/settings-5.json +119 -0
- package/registry/settings-6.json +125 -0
- package/registry/settings-7.json +128 -0
- package/registry/settings-8.json +116 -0
- package/registry/settings-9.json +118 -0
- package/registry/settings-shell.json +60 -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/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/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 +831 -0
- package/registry/widgets.json +319 -0
- package/registry/wizard.json +89 -0
- package/registry/workflow-editor.json +460 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "checklist",
|
|
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/date.ts",
|
|
13
|
+
"type": "registry:file",
|
|
14
|
+
"content": "import type { CalendarDate } from './calendar-date'\nimport { toZonedDateTime } from './zoned-date-time'\n\nconst DATE_ONLY_PATTERN = /^\\d{4}-\\d{2}-\\d{2}$/\nconst MILLISECONDS_IN_DAY = 86_400_000\n\nconst DATE_FORMAT_OPTIONS = {\n dateTime: { dateStyle: 'long', timeStyle: 'short' },\n long: { dateStyle: 'long' },\n medium: { dateStyle: 'medium' },\n numeric: { day: '2-digit', month: '2-digit', year: 'numeric' },\n short: { day: 'numeric', month: 'short' },\n weekdayAndDay: { day: 'numeric', weekday: 'long' },\n} satisfies Record<string, Intl.DateTimeFormatOptions>\n\nconst dateFormatters = new Map<string, Intl.DateTimeFormat>()\nconst relativeDayFormatters = new Map<string, Intl.RelativeTimeFormat>()\n\n/**\n * Type guard for a `Date` whose time is not `NaN`.\n *\n * @param value - Any value, typically the result of parsing user input.\n */\nexport function isValidDate(value: unknown): value is Date {\n return value instanceof Date && !Number.isNaN(value.getTime())\n}\n\n/**\n * Parses an ISO 8601 string, such as the value stored by a date property.\n *\n * @param value - The serialized date; empty values are treated as absent.\n * @returns The parsed date, or `null` when the value is absent or invalid.\n */\nexport function parseIsoDate(value: string | null | undefined): Date | null {\n if (!value) return null\n const date = new Date(value)\n return isValidDate(date) ? date : null\n}\n\n/**\n * Coerces a cell value into a `Date`. A date-only string (`2026-08-04`) is\n * read as local midnight, because `new Date('2026-08-04')` is UTC midnight and\n * would display as the previous day in any negative time zone.\n *\n * @param value - A `Date`, a date string or anything `String()` can serialize.\n * @returns A date that may be invalid; check it with {@link isValidDate}.\n */\nexport function parseDateValue(value: unknown): Date {\n if (value instanceof Date) return value\n const raw = String(value)\n return DATE_ONLY_PATTERN.test(raw)\n ? new Date(`${raw}T00:00:00`)\n : new Date(raw)\n}\n\n/**\n * Serializes the local calendar day of a date as noon UTC, so the day survives\n * a round trip through any time zone.\n *\n * @param date - A date whose local year, month and day are kept.\n * @returns An ISO string such as `2026-06-19T12:00:00.000Z`.\n */\nexport function serializeIsoDay(date: Date): string {\n return new Date(\n Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), 12),\n ).toISOString()\n}\n\n/**\n * Formats a date as day and abbreviated month, without the year.\n *\n * @param date - A valid date.\n * @param locale - A BCP 47 locale tag such as `pt-BR`.\n * @param timeZone - An IANA time zone; when omitted the date is read in the\n * runtime's local zone, which suits local day markers.\n * @returns The formatted date, such as `Jun 19` or `19 de jun.`.\n */\nexport function formatShortDate(\n date: Date,\n locale: string,\n timeZone?: string,\n): string {\n return getDateFormatter('short', locale, timeZone).format(date)\n}\n\n/**\n * Formats a date as two-digit day and month with the full year, so a column\n * of dates aligns.\n *\n * @param date - A valid date.\n * @param locale - A BCP 47 locale tag such as `pt-BR`.\n * @param timeZone - An IANA time zone; when omitted the date is read in the\n * runtime's local zone.\n * @returns The formatted date, such as `11/09/2026` or `09/11/2026`.\n */\nexport function formatNumericDate(\n date: Date,\n locale: string,\n timeZone?: string,\n): string {\n return getDateFormatter('numeric', locale, timeZone).format(date)\n}\n\n/**\n * Formats a date with day, abbreviated month and year, as a date picker\n * trigger shows it.\n *\n * @param date - A valid date.\n * @param locale - A BCP 47 locale tag such as `pt-BR`.\n * @param timeZone - An IANA time zone; when omitted the date is read in the\n * runtime's local zone.\n * @returns The formatted date, such as `Oct 20, 2026` or `20 de out. de 2026`.\n */\nexport function formatMediumDate(\n date: Date,\n locale: string,\n timeZone?: string,\n): string {\n return getDateFormatter('medium', locale, timeZone).format(date)\n}\n\n/**\n * Formats a date with day, full month name and year.\n *\n * @param date - A valid date.\n * @param locale - A BCP 47 locale tag such as `pt-BR`.\n * @param timeZone - An IANA time zone; when omitted the date is read in the\n * runtime's local zone.\n * @returns The formatted date, such as `October 20, 2026` or\n * `20 de outubro de 2026`.\n */\nexport function formatLongDate(\n date: Date,\n locale: string,\n timeZone?: string,\n): string {\n return getDateFormatter('long', locale, timeZone).format(date)\n}\n\n/**\n * Formats a date with day, full month name, year and time of day, as a\n * tooltip over a short or relative date shows it.\n *\n * @param date - A valid date.\n * @param locale - A BCP 47 locale tag such as `pt-BR`.\n * @param timeZone - An IANA time zone; when omitted the date is read in the\n * runtime's local zone.\n * @returns The formatted date and time, such as `October 20, 2026 at 2:30 PM`\n * or `20 de outubro de 2026 às 14:30`.\n */\nexport function formatDateTime(\n date: Date,\n locale: string,\n timeZone?: string,\n): string {\n return getDateFormatter('dateTime', locale, timeZone).format(date)\n}\n\n/**\n * Formats the weekday name with the day of the month, as a day heading over a\n * list of time slots.\n *\n * @param date - A valid date.\n * @param locale - A BCP 47 locale tag such as `pt-BR`.\n * @param timeZone - An IANA time zone; when omitted the date is read in the\n * runtime's local zone.\n * @returns The formatted day, such as `Tuesday 20` or `terça-feira, 20`.\n */\nexport function formatWeekdayAndDay(\n date: Date,\n locale: string,\n timeZone?: string,\n): string {\n return getDateFormatter('weekdayAndDay', locale, timeZone).format(date)\n}\n\n/**\n * Counts the civil days between two instants as seen on the wall clock of a\n * time zone, so an instant just after midnight in that zone counts as the\n * next day even when it is still the previous day in UTC.\n *\n * @param from - The reference instant, usually now.\n * @param to - The instant being measured, such as a due date.\n * @param timeZone - An IANA time zone.\n * @returns Negative when `to` falls on an earlier day than `from`.\n */\nexport function dayOffsetInTimeZone(\n from: Date,\n to: Date,\n timeZone: string,\n): number {\n return (\n dayNumber(toZonedDateTime(to, timeZone).date) -\n dayNumber(toZonedDateTime(from, timeZone).date)\n )\n}\n\n/**\n * Names a day relative to today (`Yesterday`, `Today`, `Tomorrow`, `In 3\n * days`) with the first letter upper-cased for the locale.\n *\n * @param dayOffset - Civil days from today; see {@link dayOffsetInTimeZone}.\n * @param locale - A BCP 47 locale tag such as `pt-BR`.\n */\nexport function formatRelativeDay(dayOffset: number, locale: string): string {\n const label = getRelativeDayFormatter(locale).format(dayOffset, 'day')\n return label.charAt(0).toLocaleUpperCase(locale) + label.slice(1)\n}\n\n/**\n * Moves a date by a number of local calendar days, keeping its time of day.\n *\n * @param date - The starting date; it is not mutated.\n * @param days - Days to add; negative values move backwards.\n */\nexport function addDays(date: Date, days: number): Date {\n const next = new Date(date)\n next.setDate(next.getDate() + days)\n return next\n}\n\n/**\n * Moves a date by a number of months. When the target month is shorter, the\n * day is clamped to its last day, so January 31 plus one month is the end of\n * February instead of early March.\n *\n * @param date - The starting date; it is not mutated.\n * @param months - Months to add; negative values move backwards.\n */\nexport function addMonths(date: Date, months: number): Date {\n const next = new Date(date)\n next.setDate(1)\n next.setMonth(next.getMonth() + months)\n const lastDay = new Date(next.getFullYear(), next.getMonth() + 1, 0).getDate()\n next.setDate(Math.min(date.getDate(), lastDay))\n return next\n}\n\n/**\n * Moves a date by a number of years. February 29 becomes February 28 in a\n * common year.\n *\n * @param date - The starting date; it is not mutated.\n * @param years - Years to add; negative values move backwards.\n */\nexport function addYears(date: Date, years: number): Date {\n return addMonths(date, years * 12)\n}\n\n/** Building an `Intl` formatter costs ~50 formats, so one is kept per key. */\nfunction getDateFormatter(\n style: keyof typeof DATE_FORMAT_OPTIONS,\n locale: string,\n timeZone?: string,\n): Intl.DateTimeFormat {\n const key = `${style}|${locale}|${timeZone ?? ''}`\n const cached = dateFormatters.get(key)\n if (cached) return cached\n\n const formatter = new Intl.DateTimeFormat(locale, {\n ...DATE_FORMAT_OPTIONS[style],\n ...(timeZone ? { timeZone } : {}),\n })\n dateFormatters.set(key, formatter)\n\n return formatter\n}\n\nfunction getRelativeDayFormatter(locale: string): Intl.RelativeTimeFormat {\n const cached = relativeDayFormatters.get(locale)\n if (cached) return cached\n\n const formatter = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' })\n relativeDayFormatters.set(locale, formatter)\n\n return formatter\n}\n\n/** Days since the Unix epoch for a calendar date, ignoring time zones. */\nfunction dayNumber(date: CalendarDate): number {\n return Date.UTC(date.year, date.month - 1, date.day) / MILLISECONDS_IN_DAY\n}\n",
|
|
15
|
+
"target": "~/packages/ui/src/helpers/date.ts"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "helpers/initials.ts",
|
|
19
|
+
"type": "registry:file",
|
|
20
|
+
"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",
|
|
21
|
+
"target": "~/packages/ui/src/helpers/initials.ts"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "helpers/zoned-date-time.ts",
|
|
25
|
+
"type": "registry:file",
|
|
26
|
+
"content": "import type { CalendarDate } from './calendar-date'\n\n/**\n * A wall-clock reading in some time zone: the calendar day and the minutes\n * elapsed since local midnight.\n */\nexport interface ZonedDateTime {\n date: CalendarDate\n minutes: number\n}\n\nconst formatterCache = new Map<string, Intl.DateTimeFormat>()\n\n/**\n * Returns the formatter for a time zone. `Intl.DateTimeFormat` is expensive\n * to construct, so one instance per zone is kept for the life of the module.\n */\nfunction getFormatter(timeZone: string): Intl.DateTimeFormat {\n const cached = formatterCache.get(timeZone)\n if (cached) return cached\n\n const formatter = new Intl.DateTimeFormat('en-US', {\n day: '2-digit',\n hour: '2-digit',\n hourCycle: 'h23',\n minute: '2-digit',\n month: '2-digit',\n second: '2-digit',\n timeZone,\n year: 'numeric',\n })\n formatterCache.set(timeZone, formatter)\n\n return formatter\n}\n\n/** Numeric date and time fields of an instant, read in a time zone. */\ninterface WallClockParts {\n day: number\n hour: number\n minute: number\n month: number\n second: number\n year: number\n}\n\n/**\n * Reads the wall-clock fields of an instant in a time zone.\n *\n * @param instant - The UTC instant to project.\n * @param timeZone - An IANA time zone.\n */\nfunction wallClockPartsOf(instant: Date, timeZone: string): WallClockParts {\n const parts: Partial<WallClockParts> = {}\n\n for (const part of getFormatter(timeZone).formatToParts(instant)) {\n if (part.type === 'literal') continue\n if (part.type in partKeys)\n parts[partKeys[part.type as keyof typeof partKeys]] = Number(part.value)\n }\n\n return parts as WallClockParts\n}\n\nconst partKeys = {\n day: 'day',\n hour: 'hour',\n minute: 'minute',\n month: 'month',\n second: 'second',\n year: 'year',\n} as const\n\n/**\n * Projects a UTC instant onto the wall clock of a time zone.\n *\n * @param instant - The UTC instant to project.\n * @param timeZone - An IANA time zone.\n * @returns The calendar day and the minutes since local midnight.\n */\nexport function toZonedDateTime(\n instant: Date,\n timeZone: string,\n): ZonedDateTime {\n const parts = wallClockPartsOf(instant, timeZone)\n\n return {\n date: { day: parts.day, month: parts.month, year: parts.year },\n minutes: parts.hour * 60 + parts.minute,\n }\n}\n\n/**\n * Offset of a time zone from UTC at a given instant. The formatter stops at\n * seconds, so the instant is truncated to the second before comparing;\n * otherwise milliseconds would leak into the offset.\n *\n * @param instant - The UTC instant to measure at.\n * @param timeZone - An IANA time zone.\n * @returns The offset in milliseconds; positive east of UTC.\n */\nexport function getTimeZoneOffsetMs(instant: Date, timeZone: string): number {\n const parts = wallClockPartsOf(instant, timeZone)\n const wallAsUtc = Date.UTC(\n parts.year,\n parts.month - 1,\n parts.day,\n parts.hour,\n parts.minute,\n parts.second,\n )\n const truncated =\n instant.getTime() - (((instant.getTime() % 1000) + 1000) % 1000)\n\n return wallAsUtc - truncated\n}\n\n/**\n * Converts a wall-clock reading in a time zone back to a UTC instant without a\n * date library: the wall time is first treated as UTC and then corrected by the\n * zone offset. A second pass handles transition edges, since offsets only\n * change there: an ambiguous time (fall back) keeps the first offset found,\n * and a nonexistent time (spring forward) resolves to the instant after the\n * transition.\n *\n * @param zoned - The calendar day and minutes since local midnight.\n * @param timeZone - An IANA time zone.\n * @returns The UTC instant that shows that wall time in the zone.\n */\nexport function fromZonedDateTime(\n zoned: ZonedDateTime,\n timeZone: string,\n): Date {\n const { date, minutes } = zoned\n const guess = Date.UTC(date.year, date.month - 1, date.day, 0, minutes)\n const firstOffset = getTimeZoneOffsetMs(new Date(guess), timeZone)\n const candidate = guess - firstOffset\n const secondOffset = getTimeZoneOffsetMs(new Date(candidate), timeZone)\n\n if (firstOffset === secondOffset) return new Date(candidate)\n\n const corrected = guess - secondOffset\n const projected = toZonedDateTime(new Date(corrected), timeZone)\n const matchesWall =\n projected.minutes === ((minutes % 1440) + 1440) % 1440 &&\n projected.date.day === date.day &&\n projected.date.month === date.month &&\n projected.date.year === date.year\n\n return matchesWall ? new Date(corrected) : new Date(candidate)\n}\n",
|
|
27
|
+
"target": "~/packages/ui/src/helpers/zoned-date-time.ts"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "patterns/checklist/components/checklist-body.tsx",
|
|
31
|
+
"type": "registry:file",
|
|
32
|
+
"content": "'use client'\n\nimport { DragDropProvider } from '@dnd-kit/react'\nimport type { ReactElement, Ref } from 'react'\nimport { handleDragEnd } from '../lib/sortable'\nimport type { ChecklistDensity, ChecklistFrame } from '../lib/variants'\nimport type { ChecklistItem, ChecklistProps } from '../types/index'\nimport { ChecklistDraftRow } from './checklist-draft-row'\nimport { ChecklistList } from './checklist-list'\nimport { ChecklistReadOnlyRow } from './checklist-read-only-row'\nimport { ChecklistRow } from './checklist-row'\n\nexport interface ChecklistBodyProps {\n authorOptions: NonNullable<ChecklistProps['authorOptions']>\n creating: boolean\n density: ChecklistDensity\n draftInputRef?: Ref<HTMLInputElement>\n frame: ChecklistFrame\n items: readonly ChecklistItem[]\n locale: string\n newItemTitle: string\n onCreate: ChecklistProps['onCreate']\n onDraftEscape?: () => void\n onDraftLeave?: () => void\n onItemAuthorChange?: ChecklistProps['onItemAuthorChange']\n onItemClick?: ChecklistProps['onItemClick']\n onItemCompletionChange: ChecklistProps['onItemCompletionChange']\n onItemDelete?: ChecklistProps['onItemDelete']\n onItemDueDateChange?: ChecklistProps['onItemDueDateChange']\n onItemMove: ChecklistProps['onItemMove']\n onItemRename: ChecklistProps['onItemRename']\n onNewItemTitleChange: ChecklistProps['onNewItemTitleChange']\n readOnly: boolean\n timeZone: string\n}\n\nexport function ChecklistBody({\n authorOptions,\n creating,\n density,\n draftInputRef,\n frame,\n items,\n locale,\n newItemTitle,\n onCreate,\n onDraftEscape,\n onDraftLeave,\n onItemAuthorChange,\n onItemClick,\n onItemCompletionChange,\n onItemDelete,\n onItemDueDateChange,\n onItemMove,\n onItemRename,\n onNewItemTitleChange,\n readOnly,\n timeZone,\n}: Readonly<ChecklistBodyProps>): ReactElement {\n if (readOnly) {\n return (\n <ChecklistList variant={frame}>\n {items.map((item) => (\n <ChecklistReadOnlyRow\n density={density}\n variant={frame}\n item={item}\n key={item.id}\n authorOptions={authorOptions}\n locale={locale}\n onItemClick={onItemClick}\n timeZone={timeZone}\n />\n ))}\n </ChecklistList>\n )\n }\n\n return (\n <DragDropProvider\n onDragEnd={(event) => handleDragEnd(event, items, onItemMove)}\n >\n <ChecklistList variant={frame}>\n {items.map((item, index) => (\n <ChecklistRow\n density={density}\n variant={frame}\n item={item}\n itemCount={items.length}\n itemIndex={index}\n key={item.id}\n authorOptions={authorOptions}\n locale={locale}\n onItemClick={onItemClick}\n onItemAuthorChange={onItemAuthorChange}\n onCompletionChange={(completed) =>\n onItemCompletionChange(item.id, completed)\n }\n onDelete={onItemDelete ? () => onItemDelete(item.id) : undefined}\n onItemDueDateChange={onItemDueDateChange}\n onMove={(targetIndex) => onItemMove(item.id, targetIndex)}\n onRename={(title) => onItemRename(item.id, title)}\n timeZone={timeZone}\n />\n ))}\n <ChecklistDraftRow\n callToAction={items.length === 0}\n creating={creating}\n density={density}\n inputRef={draftInputRef}\n variant={frame}\n onCreate={onCreate}\n onEscape={onDraftEscape}\n onLeave={onDraftLeave}\n onTitleChange={onNewItemTitleChange}\n title={newItemTitle}\n />\n </ChecklistList>\n </DragDropProvider>\n )\n}\n",
|
|
33
|
+
"target": "~/packages/ui/src/patterns/checklist/components/checklist-body.tsx"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"path": "patterns/checklist/components/checklist-count.tsx",
|
|
37
|
+
"type": "registry:file",
|
|
38
|
+
"content": "import type { ReactElement } from 'react'\nimport { checklistProgressLabel } from '../lib/progress-label'\nimport { CHECKLIST_COUNT_CLASSNAME } from '../lib/variants'\n\nconst ringRadius = 5\nconst ringCircumference = 2 * Math.PI * ringRadius\n\nexport function ChecklistCount({\n completed,\n meter = false,\n total,\n}: Readonly<{\n completed: number\n meter?: boolean\n total: number\n}>): ReactElement {\n const label = checklistProgressLabel(completed, total)\n\n return (\n <span\n aria-label={meter ? label : undefined}\n aria-valuemax={meter ? total : undefined}\n aria-valuemin={meter ? 0 : undefined}\n aria-valuenow={meter ? completed : undefined}\n className={CHECKLIST_COUNT_CLASSNAME}\n data-slot=\"checklist-count\"\n role={meter ? 'progressbar' : undefined}\n >\n <svg\n aria-hidden=\"true\"\n className=\"-rotate-90 size-3.5 shrink-0\"\n data-slot=\"checklist-count-ring\"\n viewBox=\"0 0 14 14\"\n >\n <circle\n className=\"stroke-muted-foreground/30\"\n cx=\"7\"\n cy=\"7\"\n fill=\"none\"\n r={ringRadius}\n strokeWidth=\"2\"\n />\n <circle\n className=\"stroke-primary\"\n cx=\"7\"\n cy=\"7\"\n fill=\"none\"\n r={ringRadius}\n strokeDasharray={ringCircumference}\n strokeDashoffset={ringCircumference * (1 - completed / total)}\n strokeLinecap=\"round\"\n strokeWidth=\"2\"\n />\n </svg>\n <span aria-hidden=\"true\">{`${completed}/${total}`}</span>\n {meter ? null : <span className=\"sr-only\">{label}</span>}\n </span>\n )\n}\n",
|
|
39
|
+
"target": "~/packages/ui/src/patterns/checklist/components/checklist-count.tsx"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "patterns/checklist/components/checklist-draft-row.tsx",
|
|
43
|
+
"type": "registry:file",
|
|
44
|
+
"content": "'use client'\n\nimport { PlusIcon } from '@phosphor-icons/react'\nimport { Checkbox } from '@tc96/ui/checkbox'\nimport { InputPrimitive } from '@tc96/ui/input'\nimport type { ReactElement, Ref } from 'react'\nimport {\n type ChecklistDensity,\n type ChecklistFrame,\n checklistCheckboxVariants,\n checklistDraftInputVariants,\n checklistItemVariants,\n} from '../lib/variants'\nimport type { ChecklistProps } from '../types/index'\nimport { ChecklistItemCard } from './checklist-item-card'\n\nexport function ChecklistDraftRow({\n callToAction,\n creating,\n density,\n inputRef,\n variant,\n onCreate,\n onEscape,\n onLeave,\n onTitleChange,\n title,\n}: Readonly<{\n callToAction: boolean\n creating: boolean\n density: ChecklistDensity\n inputRef?: Ref<HTMLInputElement>\n variant: ChecklistFrame\n onCreate: ChecklistProps['onCreate']\n onEscape?: () => void\n onLeave?: () => void\n onTitleChange: ChecklistProps['onNewItemTitleChange']\n title: string\n}>): ReactElement {\n const normalizedTitle = title.trim()\n const actionable = normalizedTitle.length > 0 && !creating\n const create = (completed: boolean) => {\n if (actionable) onCreate(normalizedTitle, completed)\n }\n\n return (\n <li\n className={checklistItemVariants({ variant })}\n data-slot=\"checklist-draft-item\"\n >\n <form\n onSubmit={(event) => {\n event.preventDefault()\n create(false)\n }}\n >\n <ChecklistItemCard\n action={null}\n density={density}\n variant={variant}\n checkbox={\n callToAction ? (\n <PlusIcon\n aria-hidden=\"true\"\n className=\"size-4 text-muted-foreground\"\n />\n ) : (\n <Checkbox\n aria-label=\"Concluir novo item\"\n checked={false}\n className={checklistCheckboxVariants({ density })}\n disabled={!actionable}\n onCheckedChange={(checked) => {\n if (checked === true) create(true)\n }}\n />\n )\n }\n title={\n <InputPrimitive\n aria-label=\"Novo item\"\n className={checklistDraftInputVariants({ density })}\n disabled={creating}\n onBlur={(event) => {\n if (!onLeave || normalizedTitle.length > 0) return\n const root = event.currentTarget.closest(\n '[data-slot=\"checklist\"]',\n )\n const next = event.relatedTarget\n if (next instanceof Node && root?.contains(next)) return\n onLeave()\n }}\n onChange={(event) => onTitleChange(event.target.value)}\n onKeyDown={(event) => {\n if (event.key === 'Escape' && normalizedTitle.length === 0) {\n onEscape?.()\n }\n }}\n placeholder=\"Adicionar uma nova etapa\"\n ref={inputRef}\n type=\"text\"\n value={title}\n />\n }\n />\n </form>\n </li>\n )\n}\n",
|
|
45
|
+
"target": "~/packages/ui/src/patterns/checklist/components/checklist-draft-row.tsx"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"path": "patterns/checklist/components/checklist-group.tsx",
|
|
49
|
+
"type": "registry:file",
|
|
50
|
+
"content": "'use client'\n\nimport { PlusIcon } from '@phosphor-icons/react'\nimport {\n type ReactElement,\n type ReactNode,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from 'react'\nimport { RecordGroup } from '../../records/group/composition/record-group/record-group'\nimport { RecordGroupAction } from '../../records/group/composition/record-group-action/record-group-action'\nimport { RecordGroupFilter } from '../../records/group/composition/record-group-filter/record-group-filter'\nimport type { RecordGroupFilterProps } from '../../records/group/core'\nimport { ChecklistBody, type ChecklistBodyProps } from './checklist-body'\nimport { ChecklistCount } from './checklist-count'\n\nexport function ChecklistGroup({\n actions,\n addLabel,\n autoFocusDraft = false,\n filter,\n title,\n ...body\n}: Readonly<\n Omit<ChecklistBodyProps, 'draftInputRef' | 'frame'> & {\n actions?: ReactNode\n addLabel: string\n autoFocusDraft?: boolean\n filter?: RecordGroupFilterProps\n title: ReactNode\n }\n>): ReactElement {\n const [open, setOpen] = useState(true)\n const [focusRequest, setFocusRequest] = useState(0)\n const pendingFocus = useRef(autoFocusDraft)\n const draftInput = useRef<HTMLInputElement | null>(null)\n const draftInputRef = useCallback((node: HTMLInputElement | null) => {\n draftInput.current = node\n if (node && pendingFocus.current) {\n pendingFocus.current = false\n node.focus()\n }\n }, [])\n const total = body.items.length\n const completed = body.items.filter((item) => item.completed).length\n\n useEffect(() => {\n if (focusRequest === 0 || !draftInput.current) return\n pendingFocus.current = false\n draftInput.current.focus()\n }, [focusRequest])\n\n return (\n <RecordGroup\n actions={\n <>\n {actions}\n {filter ? <RecordGroupFilter {...filter} /> : null}\n <RecordGroupAction\n disabled={body.readOnly}\n icon={PlusIcon}\n label={addLabel}\n onClick={() => {\n pendingFocus.current = true\n setOpen(true)\n setFocusRequest((current) => current + 1)\n }}\n />\n </>\n }\n onOpenChange={setOpen}\n open={open}\n title={\n <span className=\"inline-flex items-center gap-2\">\n {title}\n {total > 0 ? (\n <ChecklistCount completed={completed} total={total} />\n ) : null}\n </span>\n }\n variant=\"plain\"\n >\n <ChecklistBody {...body} draftInputRef={draftInputRef} frame=\"plain\" />\n </RecordGroup>\n )\n}\n",
|
|
51
|
+
"target": "~/packages/ui/src/patterns/checklist/components/checklist-group.tsx"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"path": "patterns/checklist/components/checklist-header.tsx",
|
|
55
|
+
"type": "registry:file",
|
|
56
|
+
"content": "'use client'\n\nimport { Text } from '@tc96/ui/text'\nimport type { ReactElement, ReactNode } from 'react'\nimport { ChecklistCount } from './checklist-count'\n\nexport function ChecklistHeader({\n completed,\n title,\n total,\n}: Readonly<{\n completed: number\n title: ReactNode\n total: number\n}>): ReactElement | null {\n if (title == null) return null\n\n return (\n <div className=\"flex items-center gap-2\" data-slot=\"checklist-header\">\n <Text size=\"sm\" weight=\"medium\">\n {title}\n </Text>\n {total > 0 ? (\n <ChecklistCount completed={completed} meter total={total} />\n ) : null}\n </div>\n )\n}\n",
|
|
57
|
+
"target": "~/packages/ui/src/patterns/checklist/components/checklist-header.tsx"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"path": "patterns/checklist/components/checklist-item-card.tsx",
|
|
61
|
+
"type": "registry:file",
|
|
62
|
+
"content": "'use client'\n\nimport { Text } from '@tc96/ui/text'\nimport type { ReactElement, ReactNode } from 'react'\nimport { EditableText } from '../../properties/display/editable-text/editable-text'\nimport {\n CHECKLIST_TITLE_BUTTON_CLASSNAME,\n CHECKLIST_TITLE_CLASSNAME,\n CHECKLIST_TITLE_SIZE,\n CHECKLIST_TITLE_TEXT_CLASSNAME,\n type ChecklistDensity,\n type ChecklistFrame,\n checklistRowVariants,\n} from '../lib/variants'\nimport type { ChecklistItem, ChecklistProps } from '../types/index'\n\nexport function ChecklistItemCard({\n action,\n checkbox,\n density,\n title,\n variant,\n}: Readonly<{\n action: ReactNode\n checkbox: ReactNode\n density: ChecklistDensity\n title: ReactNode\n variant: ChecklistFrame\n}>): ReactElement {\n return (\n <div\n className={checklistRowVariants({ density, variant })}\n data-slot=\"checklist-row\"\n >\n <span className=\"flex shrink-0 items-center justify-center\">\n {checkbox}\n </span>\n {title}\n {action}\n </div>\n )\n}\n\nexport function ChecklistTitle({\n density,\n item,\n onItemClick,\n onRename,\n}: Readonly<{\n density: ChecklistDensity\n item: ChecklistItem\n onItemClick?: ChecklistProps['onItemClick']\n onRename?: (title: string) => void\n}>): ReactElement {\n const size = CHECKLIST_TITLE_SIZE[density]\n\n if (onItemClick) {\n return (\n <Text\n aria-label={`Abrir ${item.title}`}\n className={CHECKLIST_TITLE_BUTTON_CLASSNAME}\n data-slot=\"checklist-title\"\n onClick={() => onItemClick(item)}\n render={<button type=\"button\" />}\n size={size}\n >\n {item.title}\n </Text>\n )\n }\n\n if (onRename) {\n return (\n <span className=\"min-w-0 flex-1\" data-slot=\"checklist-title\">\n <EditableText\n ariaLabel={`Título: ${item.title}`}\n className={CHECKLIST_TITLE_CLASSNAME}\n onCommit={(next) => next && onRename(next)}\n revertWhenEmpty\n size={size}\n value={item.title}\n />\n </span>\n )\n }\n\n return (\n <Text\n className={CHECKLIST_TITLE_TEXT_CLASSNAME}\n data-slot=\"checklist-title\"\n size={size}\n >\n {item.title}\n </Text>\n )\n}\n",
|
|
63
|
+
"target": "~/packages/ui/src/patterns/checklist/components/checklist-item-card.tsx"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"path": "patterns/checklist/components/checklist-list.tsx",
|
|
67
|
+
"type": "registry:file",
|
|
68
|
+
"content": "import { Card } from '@tc96/ui/card'\nimport type { ReactElement, ReactNode } from 'react'\nimport { type ChecklistFrame, checklistListVariants } from '../lib/variants'\n\nexport function ChecklistList({\n children,\n variant,\n}: Readonly<{\n children: ReactNode\n variant: ChecklistFrame\n}>): ReactElement {\n const list = (\n <ol\n className={checklistListVariants({ variant }) || undefined}\n data-slot=\"checklist-items\"\n >\n {children}\n </ol>\n )\n\n return variant === 'card' ? <Card>{list}</Card> : list\n}\n",
|
|
69
|
+
"target": "~/packages/ui/src/patterns/checklist/components/checklist-list.tsx"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"path": "patterns/checklist/components/checklist-metadata.tsx",
|
|
73
|
+
"type": "registry:file",
|
|
74
|
+
"content": "'use client'\n\nimport type { ReactElement } from 'react'\nimport { DateProperty } from '../../properties/display/date/date-property'\nimport {\n PersonProperty,\n type PersonPropertyOption,\n} from '../../properties/display/person/person-property'\nimport {\n calendarDayOffset,\n dueStatus,\n formatChecklistDueDate,\n} from '../lib/due-date'\nimport { checklistDueDateVariants } from '../lib/variants'\nimport type { ChecklistItem, ChecklistProps } from '../types/index'\n\nexport function ChecklistMetadata({\n authorOptions,\n item,\n locale,\n onItemAuthorChange,\n onItemDueDateChange,\n readOnly = false,\n timeZone,\n}: Readonly<{\n authorOptions: readonly PersonPropertyOption[]\n item: ChecklistItem\n locale: string\n onItemAuthorChange?: ChecklistProps['onItemAuthorChange']\n onItemDueDateChange?: ChecklistProps['onItemDueDateChange']\n readOnly?: boolean\n timeZone: string\n}>): ReactElement | null {\n if (item.authorId === undefined && item.dueDate === undefined) return null\n const dueDayOffset = calendarDayOffset(item.dueDate, new Date(), timeZone)\n const status = dueStatus(dueDayOffset)\n\n return (\n <span\n className=\"flex shrink-0 items-center gap-3 text-muted-foreground\"\n data-due={item.dueDate !== undefined ? status : undefined}\n data-slot=\"checklist-actions\"\n >\n {item.authorId !== undefined ? (\n <PersonProperty\n ariaLabel=\"Author\"\n options={authorOptions}\n readOnly={readOnly || !onItemAuthorChange}\n value={item.authorId}\n variant=\"plain\"\n onValueChange={(authorId) => onItemAuthorChange?.(item.id, authorId)}\n />\n ) : null}\n {item.dueDate !== undefined ? (\n <DateProperty\n ariaLabel=\"Due date\"\n className={checklistDueDateVariants({ status })}\n displayLabel={formatChecklistDueDate(\n item.dueDate,\n locale,\n timeZone,\n dueDayOffset,\n )}\n fallback=\"No due date\"\n isOverdue={status === 'overdue'}\n locale={locale}\n readOnly={readOnly || !onItemDueDateChange}\n timeZone={timeZone}\n value={item.dueDate}\n variant=\"plain\"\n onValueChange={(dueDate) => onItemDueDateChange?.(item.id, dueDate)}\n />\n ) : null}\n </span>\n )\n}\n",
|
|
75
|
+
"target": "~/packages/ui/src/patterns/checklist/components/checklist-metadata.tsx"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"path": "patterns/checklist/components/checklist-read-only-row.tsx",
|
|
79
|
+
"type": "registry:file",
|
|
80
|
+
"content": "'use client'\n\nimport { Checkbox } from '@tc96/ui/checkbox'\nimport type { ReactElement } from 'react'\nimport type { PersonPropertyOption } from '../../properties/display/person/person-property'\nimport {\n type ChecklistDensity,\n type ChecklistFrame,\n checklistCheckboxVariants,\n checklistItemVariants,\n} from '../lib/variants'\nimport type { ChecklistItem, ChecklistProps } from '../types/index'\nimport { ChecklistItemCard, ChecklistTitle } from './checklist-item-card'\nimport { ChecklistMetadata } from './checklist-metadata'\n\nexport function ChecklistReadOnlyRow({\n authorOptions,\n density,\n variant,\n item,\n locale,\n onItemClick,\n timeZone,\n}: Readonly<{\n authorOptions: readonly PersonPropertyOption[]\n density: ChecklistDensity\n variant: ChecklistFrame\n item: ChecklistItem\n locale: string\n onItemClick?: ChecklistProps['onItemClick']\n timeZone: string\n}>): ReactElement {\n return (\n <li\n className={checklistItemVariants({ variant })}\n data-completed={item.completed || undefined}\n data-slot=\"checklist-item\"\n >\n <ChecklistItemCard\n action={\n <ChecklistMetadata\n authorOptions={authorOptions}\n item={item}\n locale={locale}\n readOnly\n timeZone={timeZone}\n />\n }\n checkbox={\n <Checkbox\n aria-label={item.title}\n checked={item.completed}\n className={checklistCheckboxVariants({ density })}\n disabled\n />\n }\n density={density}\n variant={variant}\n title={\n <ChecklistTitle\n density={density}\n item={item}\n onItemClick={onItemClick}\n />\n }\n />\n </li>\n )\n}\n",
|
|
81
|
+
"target": "~/packages/ui/src/patterns/checklist/components/checklist-read-only-row.tsx"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"path": "patterns/checklist/components/checklist-row.tsx",
|
|
85
|
+
"type": "registry:file",
|
|
86
|
+
"content": "'use client'\n\nimport { useSortable } from '@dnd-kit/react/sortable'\nimport { DotsSixVerticalIcon, TrashIcon } from '@phosphor-icons/react'\nimport { Button } from '@tc96/ui/button'\nimport { Checkbox } from '@tc96/ui/checkbox'\nimport { Tooltip, TooltipPopup, TooltipTrigger } from '@tc96/ui/tooltip'\nimport type { ReactElement } from 'react'\nimport type { PersonPropertyOption } from '../../properties/display/person/person-property'\nimport {\n CHECKLIST_ITEM_TYPE,\n CHECKLIST_SENSORS,\n handleMoveShortcut,\n} from '../lib/sortable'\nimport {\n CHECKLIST_DELETE_BUTTON_CLASSNAME,\n type ChecklistDensity,\n type ChecklistFrame,\n checklistCheckboxVariants,\n checklistDragHandleVariants,\n checklistItemVariants,\n} from '../lib/variants'\nimport type { ChecklistItem, ChecklistProps } from '../types/index'\nimport { ChecklistItemCard, ChecklistTitle } from './checklist-item-card'\nimport { ChecklistMetadata } from './checklist-metadata'\n\nexport function ChecklistRow({\n authorOptions,\n density,\n variant,\n item,\n itemCount,\n itemIndex,\n locale,\n onItemClick,\n onItemAuthorChange,\n onCompletionChange,\n onDelete,\n onItemDueDateChange,\n onMove,\n onRename,\n timeZone,\n}: Readonly<{\n authorOptions: readonly PersonPropertyOption[]\n density: ChecklistDensity\n variant: ChecklistFrame\n item: ChecklistItem\n itemCount: number\n itemIndex: number\n locale: string\n onItemClick?: ChecklistProps['onItemClick']\n onItemAuthorChange?: ChecklistProps['onItemAuthorChange']\n onCompletionChange: (completed: boolean) => void\n onDelete?: () => void\n onItemDueDateChange?: ChecklistProps['onItemDueDateChange']\n onMove: (targetIndex: number) => void\n onRename: (title: string) => void\n timeZone: string\n}>): ReactElement {\n const { handleRef, isDragSource, ref } = useSortable({\n accept: CHECKLIST_ITEM_TYPE,\n data: { type: CHECKLIST_ITEM_TYPE },\n disabled: itemCount < 2,\n group: 'checklist',\n id: item.id,\n index: itemIndex,\n sensors: CHECKLIST_SENSORS,\n transition: null,\n type: CHECKLIST_ITEM_TYPE,\n })\n\n const dragHandle = (\n <Tooltip>\n <TooltipTrigger\n render={\n <Button\n aria-keyshortcuts=\"Alt+ArrowUp Alt+ArrowDown\"\n aria-label={`Reordenar ${item.title}`}\n className={checklistDragHandleVariants({ variant })}\n data-slot=\"checklist-drag-handle\"\n disabled={itemCount < 2}\n onKeyDown={(event) =>\n handleMoveShortcut(event, itemIndex, itemCount, onMove)\n }\n ref={handleRef}\n size=\"icon-sm\"\n type=\"button\"\n variant=\"ghost\"\n />\n }\n >\n <DotsSixVerticalIcon aria-hidden=\"true\" />\n </TooltipTrigger>\n <TooltipPopup>Arraste para ordenar acima ou abaixo</TooltipPopup>\n </Tooltip>\n )\n\n return (\n <li\n className={checklistItemVariants({ variant })}\n data-completed={item.completed || undefined}\n data-dragging={isDragSource || undefined}\n data-slot=\"checklist-item\"\n ref={ref}\n >\n {dragHandle}\n <ChecklistItemCard\n action={\n <>\n <ChecklistMetadata\n authorOptions={authorOptions}\n item={item}\n locale={locale}\n onItemAuthorChange={onItemAuthorChange}\n onItemDueDateChange={onItemDueDateChange}\n timeZone={timeZone}\n />\n {onDelete ? (\n <ChecklistDeleteButton\n itemTitle={item.title}\n onDelete={onDelete}\n />\n ) : null}\n </>\n }\n checkbox={\n <Checkbox\n aria-label={item.title}\n checked={item.completed}\n className={checklistCheckboxVariants({ density })}\n onCheckedChange={(checked) => onCompletionChange(checked === true)}\n />\n }\n density={density}\n variant={variant}\n title={\n <ChecklistTitle\n density={density}\n item={item}\n onItemClick={onItemClick}\n onRename={onRename}\n />\n }\n />\n </li>\n )\n}\n\nfunction ChecklistDeleteButton({\n itemTitle,\n onDelete,\n}: Readonly<{ itemTitle: string; onDelete: () => void }>): ReactElement {\n return (\n <Button\n aria-label={`Excluir ${itemTitle}`}\n className={CHECKLIST_DELETE_BUTTON_CLASSNAME}\n data-slot=\"checklist-delete\"\n onClick={onDelete}\n size=\"icon-sm\"\n type=\"button\"\n variant=\"ghost\"\n >\n <TrashIcon aria-hidden=\"true\" />\n </Button>\n )\n}\n",
|
|
87
|
+
"target": "~/packages/ui/src/patterns/checklist/components/checklist-row.tsx"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"path": "patterns/checklist/components/checklist-trigger.tsx",
|
|
91
|
+
"type": "registry:file",
|
|
92
|
+
"content": "'use client'\n\nimport { PlusIcon } from '@phosphor-icons/react'\nimport { Button } from '@tc96/ui/button'\nimport type { ReactElement, Ref } from 'react'\n\nexport function ChecklistTrigger({\n addLabel,\n disabled,\n onClick,\n triggerRef,\n}: Readonly<{\n addLabel: string\n disabled: boolean\n onClick: () => void\n triggerRef?: Ref<HTMLButtonElement>\n}>): ReactElement {\n return (\n <Button\n data-slot=\"checklist-trigger\"\n disabled={disabled}\n onClick={onClick}\n ref={triggerRef}\n size=\"sm\"\n type=\"button\"\n variant=\"ghost\"\n >\n <PlusIcon aria-hidden=\"true\" />\n {addLabel}\n </Button>\n )\n}\n",
|
|
93
|
+
"target": "~/packages/ui/src/patterns/checklist/components/checklist-trigger.tsx"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"path": "patterns/checklist/composition/checklist/checklist.tsx",
|
|
97
|
+
"type": "registry:file",
|
|
98
|
+
"content": "'use client'\n\nimport { cn } from '@tc96/utils'\nimport { type ReactElement, useEffect, useRef, useState } from 'react'\nimport { ChecklistBody } from '../../components/checklist-body'\nimport { ChecklistGroup } from '../../components/checklist-group'\nimport { ChecklistHeader } from '../../components/checklist-header'\nimport { ChecklistTrigger } from '../../components/checklist-trigger'\nimport { checklistFilterNarrows } from '../../lib/filter'\nimport { checklistVariants } from '../../lib/variants'\nimport type { ChecklistProps } from '../../types/index'\n\nexport function Checklist({\n actions,\n addLabel = 'Adicionar etapas',\n ariaLabel,\n authorOptions = [],\n className,\n creating = false,\n density = 'md',\n feedback,\n filter,\n items,\n locale = 'en-US',\n newItemTitle,\n onCreate,\n onItemClick,\n onItemAuthorChange,\n onItemCompletionChange,\n onItemDelete,\n onItemDueDateChange,\n onItemMove,\n onItemRename,\n onNewItemTitleChange,\n readOnly = false,\n title,\n timeZone = 'UTC',\n variant = 'card',\n ...props\n}: Readonly<ChecklistProps>): ReactElement {\n const [composing, setComposing] = useState(false)\n const triggerRef = useRef<HTMLButtonElement>(null)\n const restoreTriggerFocus = useRef(false)\n\n useEffect(() => {\n if (!composing && restoreTriggerFocus.current) {\n restoreTriggerFocus.current = false\n triggerRef.current?.focus()\n }\n }, [composing])\n\n if (composing && items.length > 0) setComposing(false)\n\n const body = {\n authorOptions,\n creating,\n density,\n items,\n locale,\n newItemTitle,\n onCreate,\n onItemAuthorChange,\n onItemClick,\n onItemCompletionChange,\n onItemDelete,\n onItemDueDateChange,\n onItemMove,\n onItemRename,\n onNewItemTitleChange,\n readOnly,\n timeZone,\n }\n\n if (variant === 'card' || variant === 'plain') {\n return (\n <section\n aria-label={ariaLabel}\n className={cn(checklistVariants({ variant }), className)}\n data-density={density}\n data-readonly={readOnly || undefined}\n data-slot=\"checklist\"\n data-variant={variant}\n {...props}\n >\n <ChecklistHeader\n completed={items.filter((item) => item.completed).length}\n title={title}\n total={items.length}\n />\n\n <ChecklistBody {...body} frame={variant} />\n\n {feedback}\n </section>\n )\n }\n\n const grouped =\n variant === 'complete' ||\n items.length > 0 ||\n composing ||\n checklistFilterNarrows(filter)\n\n return (\n <div\n className={cn(checklistVariants({ variant }), className)}\n data-density={density}\n data-readonly={readOnly || undefined}\n data-slot=\"checklist\"\n data-variant={variant}\n {...props}\n >\n {grouped ? (\n <ChecklistGroup\n {...body}\n actions={actions}\n addLabel={addLabel}\n autoFocusDraft={composing}\n filter={filter}\n onDraftEscape={\n composing\n ? () => {\n restoreTriggerFocus.current = true\n setComposing(false)\n }\n : undefined\n }\n onDraftLeave={composing ? () => setComposing(false) : undefined}\n title={title ?? ariaLabel}\n />\n ) : (\n <ChecklistTrigger\n addLabel={addLabel}\n disabled={readOnly}\n onClick={() => setComposing(true)}\n triggerRef={triggerRef}\n />\n )}\n\n {feedback}\n </div>\n )\n}\n",
|
|
99
|
+
"target": "~/packages/ui/src/patterns/checklist/composition/checklist/checklist.tsx"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"path": "patterns/checklist/composition/checklist/index.ts",
|
|
103
|
+
"type": "registry:file",
|
|
104
|
+
"content": "export { Checklist } from './checklist'\n",
|
|
105
|
+
"target": "~/packages/ui/src/patterns/checklist/composition/checklist/index.ts"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"path": "patterns/checklist/composition/index.ts",
|
|
109
|
+
"type": "registry:file",
|
|
110
|
+
"content": "export * from './checklist/index'\n",
|
|
111
|
+
"target": "~/packages/ui/src/patterns/checklist/composition/index.ts"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"path": "patterns/checklist/index.ts",
|
|
115
|
+
"type": "registry:file",
|
|
116
|
+
"content": "export * from './composition/index'\nexport * from './types/index'\n",
|
|
117
|
+
"target": "~/packages/ui/src/patterns/checklist/index.ts"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"path": "patterns/checklist/lib/due-date.ts",
|
|
121
|
+
"type": "registry:file",
|
|
122
|
+
"content": "import {\n dayOffsetInTimeZone,\n formatRelativeDay,\n formatShortDate,\n parseIsoDate,\n} from '@tc96/ui/helpers/date'\nimport type { ChecklistDueStatus } from './variants'\n\nexport function calendarDayOffset(\n value: string | null | undefined,\n now: Date,\n timeZone: string,\n): number | null {\n const due = parseIsoDate(value)\n return due ? dayOffsetInTimeZone(now, due, timeZone) : null\n}\n\nexport function dueStatus(dayOffset: number | null): ChecklistDueStatus {\n if (dayOffset === null || dayOffset > 0) return 'upcoming'\n return dayOffset < 0 ? 'overdue' : 'today'\n}\n\nexport function formatChecklistDueDate(\n value: string | null,\n locale: string,\n timeZone: string,\n dayOffset: number | null,\n): string {\n if (dayOffset !== null && Math.abs(dayOffset) <= 1)\n return formatRelativeDay(dayOffset, locale)\n const due = parseIsoDate(value)\n return due ? formatShortDate(due, locale, timeZone) : 'No due date'\n}\n",
|
|
123
|
+
"target": "~/packages/ui/src/patterns/checklist/lib/due-date.ts"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"path": "patterns/checklist/lib/filter.ts",
|
|
127
|
+
"type": "registry:file",
|
|
128
|
+
"content": "import type { RecordGroupFilterProps } from '../../records/group/core'\n\nexport function checklistFilterNarrows(\n filter: RecordGroupFilterProps | undefined,\n): boolean {\n if (!filter) return false\n const narrowsOptions =\n filter.filterOptions !== undefined &&\n filter.filterValue !== undefined &&\n filter.filterValue.length < filter.filterOptions.length\n return (\n narrowsOptions ||\n (filter.sections ?? []).some(\n (section) => section.value.length < section.options.length,\n )\n )\n}\n",
|
|
129
|
+
"target": "~/packages/ui/src/patterns/checklist/lib/filter.ts"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
"path": "patterns/checklist/lib/progress-label.ts",
|
|
133
|
+
"type": "registry:file",
|
|
134
|
+
"content": "export function checklistProgressLabel(\n completed: number,\n total: number,\n): string {\n return `${completed} de ${total} ${total === 1 ? 'concluído' : 'concluídos'}`\n}\n",
|
|
135
|
+
"target": "~/packages/ui/src/patterns/checklist/lib/progress-label.ts"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"path": "patterns/checklist/lib/sortable.ts",
|
|
139
|
+
"type": "registry:file",
|
|
140
|
+
"content": "import { KeyboardSensor, PointerSensor } from '@dnd-kit/dom'\nimport type { DragEndEvent } from '@dnd-kit/react'\nimport { isSortableOperation } from '@dnd-kit/react/sortable'\nimport type { KeyboardEvent } from 'react'\nimport type { ChecklistItem, ChecklistProps } from '../types/index'\n\nexport const CHECKLIST_ITEM_TYPE = 'checklist-item'\n\nexport const CHECKLIST_SENSORS = [\n PointerSensor,\n KeyboardSensor.configure({\n keyboardCodes: {\n cancel: ['Escape'],\n down: ['ArrowDown'],\n end: ['Space', 'Tab'],\n left: ['ArrowLeft'],\n right: ['ArrowRight'],\n start: ['Space'],\n up: ['ArrowUp'],\n },\n }),\n]\n\nexport function handleMoveShortcut(\n event: KeyboardEvent<HTMLButtonElement>,\n itemIndex: number,\n itemCount: number,\n onMove: (targetIndex: number) => void,\n) {\n if (!event.altKey || (event.key !== 'ArrowUp' && event.key !== 'ArrowDown'))\n return\n\n const targetIndex = event.key === 'ArrowUp' ? itemIndex - 1 : itemIndex + 1\n if (targetIndex < 0 || targetIndex >= itemCount) return\n event.preventDefault()\n onMove(targetIndex)\n}\n\nexport function handleDragEnd(\n event: DragEndEvent,\n items: readonly ChecklistItem[],\n onItemMove: ChecklistProps['onItemMove'],\n) {\n if (event.canceled || !isSortableOperation(event.operation)) return\n\n const { source, target } = event.operation\n if (!source || !target) return\n\n const itemId = String(source.id)\n const sourceIndex = items.findIndex((item) => item.id === itemId)\n const targetIndex = target.index\n if (sourceIndex < 0 || sourceIndex === targetIndex) return\n onItemMove(itemId, targetIndex)\n}\n",
|
|
141
|
+
"target": "~/packages/ui/src/patterns/checklist/lib/sortable.ts"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"path": "patterns/checklist/lib/variants.ts",
|
|
145
|
+
"type": "registry:file",
|
|
146
|
+
"content": "import { cva, type VariantProps } from 'class-variance-authority'\nimport type { EditableTextSize } from '../../properties/display/editable-text/editable-text'\n\nexport const checklistRowVariants = cva('flex min-w-0 items-center gap-2', {\n compoundVariants: [\n { class: 'h-10 px-3', density: 'md', variant: 'card' },\n {\n class: 'h-[var(--record-group-row-height,calc(var(--spacing)*9))] px-2',\n density: 'md',\n variant: 'plain',\n },\n ],\n defaultVariants: {\n density: 'md',\n variant: 'card',\n },\n variants: {\n density: {\n md: null,\n sm: 'h-8 px-2',\n },\n variant: {\n card: null,\n plain: null,\n },\n },\n})\n\nexport type ChecklistDensity = NonNullable<\n VariantProps<typeof checklistRowVariants>['density']\n>\n\nexport const checklistCheckboxVariants = cva(\n \"after:absolute after:content-['']\",\n {\n defaultVariants: {\n density: 'md',\n },\n variants: {\n density: {\n md: 'after:size-11',\n sm: 'after:size-8',\n },\n },\n },\n)\n\nexport const checklistDraftInputVariants = cva(\n 'min-w-0 flex-1 rounded-sm bg-transparent outline-none placeholder:text-foreground/40 focus-visible:outline-2 focus-visible:outline-ring',\n {\n defaultVariants: {\n density: 'md',\n },\n variants: {\n density: {\n md: 'text-base',\n sm: 'text-sm',\n },\n },\n },\n)\n\nexport const checklistDueDateVariants = cva('', {\n defaultVariants: {\n status: 'upcoming',\n },\n variants: {\n status: {\n overdue: 'text-destructive-foreground',\n today: 'text-warning-foreground',\n upcoming: 'text-muted-foreground',\n },\n },\n})\n\nexport type ChecklistDueStatus = NonNullable<\n VariantProps<typeof checklistDueDateVariants>['status']\n>\n\nexport const CHECKLIST_TITLE_SIZE = {\n md: 'base',\n sm: 'sm',\n} as const satisfies Record<ChecklistDensity, EditableTextSize>\n\nexport const checklistVariants = cva('min-w-0 space-y-2', {\n defaultVariants: {\n variant: 'card',\n },\n variants: {\n variant: {\n card: 'pt-2 pb-4',\n complete: null,\n plain: null,\n trigger: null,\n },\n },\n})\n\nexport type ChecklistVariant = NonNullable<\n VariantProps<typeof checklistVariants>['variant']\n>\n\nexport const checklistListVariants = cva('', {\n defaultVariants: {\n variant: 'card',\n },\n variants: {\n variant: {\n card: null,\n plain: 'flex flex-col gap-0.5',\n },\n },\n})\n\nexport type ChecklistFrame = NonNullable<\n VariantProps<typeof checklistListVariants>['variant']\n>\n\nexport const checklistItemVariants = cva(\n 'group relative min-w-0 transition-colors hover:bg-muted/60 data-dragging:opacity-40',\n {\n defaultVariants: {\n variant: 'card',\n },\n variants: {\n variant: {\n card: \"before:-left-9 before:absolute before:inset-y-0 before:w-9 before:content-[''] first:rounded-t-[calc(var(--card-surface-radius,var(--radius-2xl))-1px)] last:rounded-b-[calc(var(--card-surface-radius,var(--radius-2xl))-1px)]\",\n plain:\n \"before:-left-9 before:absolute before:inset-y-0 before:w-9 before:content-[''] rounded-md -mx-[var(--record-group-hover-offset,0px)]\",\n },\n },\n },\n)\n\nexport const checklistDragHandleVariants = cva(\n 'cursor-grab touch-none opacity-0 transition-opacity focus-visible:opacity-100 active:cursor-grabbing group-hover:opacity-100',\n {\n defaultVariants: {\n variant: 'card',\n },\n variants: {\n variant: {\n card: '-left-9 -translate-y-1/2 invisible absolute top-1/2 z-10 focus-visible:visible group-hover:visible',\n plain: '-left-9 -translate-y-1/2 absolute top-1/2 z-10',\n },\n },\n },\n)\n\nexport const CHECKLIST_DELETE_BUTTON_CLASSNAME =\n 'opacity-0 transition-opacity focus-visible:opacity-100 group-hover:opacity-100'\n\nexport const CHECKLIST_TITLE_CLASSNAME =\n 'min-w-0 flex-1 group-data-completed:text-muted-foreground group-data-completed:line-through'\n\nexport const CHECKLIST_TITLE_TEXT_CLASSNAME = `${CHECKLIST_TITLE_CLASSNAME} truncate`\n\nexport const CHECKLIST_TITLE_BUTTON_CLASSNAME = `${CHECKLIST_TITLE_TEXT_CLASSNAME} h-full cursor-pointer text-left focus-visible:outline-2 focus-visible:outline-ring`\n\nexport const CHECKLIST_COUNT_CLASSNAME =\n 'inline-flex items-center gap-1 rounded-full bg-muted px-1.5 py-0.5 font-normal text-muted-foreground text-xs tabular-nums'\n",
|
|
147
|
+
"target": "~/packages/ui/src/patterns/checklist/lib/variants.ts"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"path": "patterns/checklist/types/index.ts",
|
|
151
|
+
"type": "registry:file",
|
|
152
|
+
"content": "import type { ComponentPropsWithoutRef, ReactNode } from 'react'\nimport type { PersonPropertyOption } from '../../properties/display/person/person-property'\nimport type { RecordGroupFilterProps } from '../../records/group/core'\nimport type { ChecklistDensity, ChecklistVariant } from '../lib/variants'\n\nexport type { ChecklistDensity, ChecklistVariant } from '../lib/variants'\n\nexport interface ChecklistItem {\n authorId?: string | null\n completed: boolean\n dueDate?: string | null\n id: string\n title: string\n}\n\nexport interface ChecklistProps\n extends Omit<ComponentPropsWithoutRef<'section'>, 'title'> {\n actions?: ReactNode\n addLabel?: string\n ariaLabel: string\n authorOptions?: readonly PersonPropertyOption[]\n creating?: boolean\n density?: ChecklistDensity\n feedback?: ReactNode\n filter?: RecordGroupFilterProps\n items: readonly ChecklistItem[]\n locale?: string\n newItemTitle: string\n onCreate: (title: string, completed: boolean) => void\n onItemClick?: (item: ChecklistItem) => void\n onItemAuthorChange?: (id: string, authorId: string) => void\n onItemCompletionChange: (id: string, completed: boolean) => void\n onItemDelete?: (id: string) => void\n onItemDueDateChange?: (id: string, dueDate: string | null) => void\n onItemMove: (id: string, targetIndex: number) => void\n onItemRename: (id: string, title: string) => void\n onNewItemTitleChange: (title: string) => void\n readOnly?: boolean\n title?: ReactNode\n timeZone?: string\n variant?: ChecklistVariant\n}\n",
|
|
153
|
+
"target": "~/packages/ui/src/patterns/checklist/types/index.ts"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"path": "patterns/editable/composition/editable/editable.tsx",
|
|
157
|
+
"type": "registry:file",
|
|
158
|
+
"content": "'use client'\n\nimport { mergeProps } from '@base-ui/react/merge-props'\nimport { useRender } from '@base-ui/react/use-render'\nimport { cn } from '@tc96/utils'\nimport * as React from 'react'\nimport {\n EditableContext,\n type EditableContextValue,\n useEditableContext,\n} from '../../store/editable-store'\n\ntype Direction = 'ltr' | 'rtl'\ntype TriggerMode = 'click' | 'dblclick' | 'focus'\n\nfunction assignRef<T>(ref: React.Ref<T> | undefined, value: T | null) {\n if (typeof ref === 'function') {\n ref(value)\n return\n }\n if (ref) {\n ref.current = value\n }\n}\n\nfunction dataAttributes(\n attributes: Record<`data-${string}`, string | undefined>,\n): Record<string, string | undefined> {\n return attributes\n}\n\nfunction useComposedRefs<T>(\n firstRef: React.Ref<T> | undefined,\n secondRef: React.Ref<T> | undefined,\n) {\n return React.useCallback(\n (value: T | null) => {\n assignRef(firstRef, value)\n assignRef(secondRef, value)\n },\n [firstRef, secondRef],\n )\n}\n\nexport interface EditableProps\n extends Omit<\n React.ComponentProps<'div'> & useRender.ComponentProps<'div'>,\n 'defaultValue' | 'onSubmit'\n > {\n defaultValue?: string\n value?: string\n onValueChange?: (value: string) => void\n defaultEditing?: boolean\n editing?: boolean\n onEditingChange?: (editing: boolean) => void\n onCancel?: () => void\n onEdit?: () => void\n onSubmit?: (value: string) => void\n onEscapeKeyDown?: (event: KeyboardEvent) => void\n onEnterKeyDown?: (event: KeyboardEvent) => void\n dir?: Direction\n maxLength?: number\n name?: string\n placeholder?: string\n triggerMode?: TriggerMode\n autosize?: boolean\n disabled?: boolean\n readOnly?: boolean\n required?: boolean\n invalid?: boolean\n}\n\nexport function Editable(props: EditableProps) {\n const {\n value: controlledValue,\n defaultValue = '',\n defaultEditing = false,\n editing: controlledEditing,\n onValueChange,\n onEditingChange,\n onCancel,\n onEdit,\n onSubmit,\n onEscapeKeyDown,\n onEnterKeyDown,\n dir,\n maxLength,\n name,\n placeholder,\n triggerMode = 'click',\n autosize = false,\n disabled = false,\n required = false,\n readOnly = false,\n invalid = false,\n className,\n id,\n render,\n ref,\n ...rootProps\n } = props\n\n const generatedRootId = React.useId()\n const rootId = id ?? generatedRootId\n const inputId = React.useId()\n const labelId = React.useId()\n const [uncontrolledValue, setUncontrolledValue] = React.useState(defaultValue)\n const [uncontrolledEditing, setUncontrolledEditing] =\n React.useState(defaultEditing)\n const rootRef = React.useRef<HTMLDivElement>(null)\n const composedRef = useComposedRefs(ref, rootRef)\n\n const value = controlledValue ?? uncontrolledValue\n const editing = controlledEditing ?? uncontrolledEditing\n\n const previousValueRef = React.useRef(value)\n const restoreValueRef = React.useRef(value)\n const valueRef = React.useRef(value)\n const editingRef = React.useRef(editing)\n\n React.useEffect(() => {\n valueRef.current = value\n editingRef.current = editing\n }, [editing, value])\n\n const setValue = React.useCallback(\n (nextValue: string) => {\n valueRef.current = nextValue\n if (controlledValue === undefined) {\n setUncontrolledValue(nextValue)\n }\n onValueChange?.(nextValue)\n },\n [controlledValue, onValueChange],\n )\n\n const setEditing = React.useCallback(\n (nextEditing: boolean) => {\n editingRef.current = nextEditing\n if (controlledEditing === undefined) {\n setUncontrolledEditing(nextEditing)\n }\n onEditingChange?.(nextEditing)\n },\n [controlledEditing, onEditingChange],\n )\n\n const beginEditing = React.useCallback(\n (initialDraft?: string) => {\n if (disabled || readOnly) return\n const draft = initialDraft ?? value\n restoreValueRef.current = value\n previousValueRef.current = draft\n valueRef.current = value\n if (draft !== value) setValue(draft)\n setEditing(true)\n onEdit?.()\n },\n [disabled, onEdit, readOnly, setEditing, setValue, value],\n )\n\n const cancelEditing = React.useCallback(() => {\n if (disabled || readOnly) return\n setValue(restoreValueRef.current)\n setEditing(false)\n onCancel?.()\n }, [disabled, onCancel, readOnly, setEditing, setValue])\n\n const submitValue = React.useCallback(() => {\n if (disabled || readOnly) return\n setEditing(false)\n onSubmit?.(value)\n }, [disabled, onSubmit, readOnly, setEditing, value])\n\n const isDirty = React.useCallback(\n () => editingRef.current && valueRef.current !== previousValueRef.current,\n [],\n )\n\n const finishEditing = React.useCallback(() => {\n if (disabled || readOnly || !editingRef.current) return\n if (isDirty()) {\n submitValue()\n return\n }\n if (valueRef.current !== restoreValueRef.current) {\n setValue(restoreValueRef.current)\n }\n setEditing(false)\n }, [disabled, isDirty, readOnly, setEditing, setValue, submitValue])\n\n const context = React.useMemo<EditableContextValue>(\n () => ({\n rootId,\n inputId,\n labelId,\n value,\n editing,\n dir,\n maxLength,\n placeholder,\n triggerMode,\n autosize,\n disabled,\n readOnly,\n required,\n invalid,\n beginEditing,\n cancelEditing,\n finishEditing,\n isDirty,\n submitValue,\n setValue,\n onEnterKeyDown,\n onEscapeKeyDown,\n }),\n [\n rootId,\n inputId,\n labelId,\n value,\n editing,\n dir,\n maxLength,\n placeholder,\n triggerMode,\n autosize,\n disabled,\n readOnly,\n required,\n invalid,\n beginEditing,\n cancelEditing,\n finishEditing,\n isDirty,\n submitValue,\n setValue,\n onEnterKeyDown,\n onEscapeKeyDown,\n ],\n )\n\n const element = useRender({\n defaultTagName: 'div',\n props: mergeProps<'div'>(\n {\n id: rootId,\n ref: composedRef,\n ...dataAttributes({\n 'data-disabled': disabled ? '' : undefined,\n 'data-editing': editing ? '' : undefined,\n 'data-invalid': invalid ? '' : undefined,\n 'data-slot': 'editable',\n }),\n className: cn('flex min-w-0 flex-col gap-2', className),\n },\n rootProps,\n ),\n render,\n state: {\n slot: 'editable',\n ...(editing && { editing: '' }),\n ...(disabled && { disabled: '' }),\n ...(invalid && { invalid: '' }),\n },\n })\n\n return (\n <EditableContext.Provider value={context}>\n {element}\n {name && (\n <input\n disabled={disabled}\n name={name}\n readOnly={readOnly}\n type=\"hidden\"\n value={value}\n />\n )}\n </EditableContext.Provider>\n )\n}\n\nexport interface EditableLabelProps\n extends React.ComponentProps<'label'>,\n useRender.ComponentProps<'label'> {}\n\nexport function EditableLabel(props: EditableLabelProps) {\n const { className, render, ref, ...labelProps } = props\n const context = useEditableContext('EditableLabel')\n\n return useRender({\n defaultTagName: 'label',\n props: mergeProps<'label'>(\n {\n ref,\n id: context.labelId,\n htmlFor: context.inputId,\n ...dataAttributes({\n 'data-disabled': context.disabled ? '' : undefined,\n 'data-invalid': context.invalid ? '' : undefined,\n 'data-required': context.required ? '' : undefined,\n 'data-slot': 'editable-label',\n }),\n className: cn(\n \"font-medium text-sm leading-none data-required:after:ml-0.5 data-required:after:text-destructive-foreground data-required:after:content-['*'] data-disabled:cursor-not-allowed data-disabled:opacity-50\",\n className,\n ),\n },\n labelProps,\n ),\n render,\n state: {\n slot: 'editable-label',\n ...(context.disabled && { disabled: '' }),\n ...(context.invalid && { invalid: '' }),\n ...(context.required && { required: '' }),\n },\n })\n}\n\nexport interface EditableAreaProps\n extends React.ComponentProps<'div'>,\n useRender.ComponentProps<'div'> {}\n\nexport function EditableArea(props: EditableAreaProps) {\n const { className, render, ref, ...areaProps } = props\n const context = useEditableContext('EditableArea')\n\n return useRender({\n defaultTagName: 'div',\n props: mergeProps<'div'>(\n {\n role: 'group',\n dir: context.dir,\n ref,\n ...dataAttributes({\n 'data-disabled': context.disabled ? '' : undefined,\n 'data-editing': context.editing ? '' : undefined,\n 'data-slot': 'editable-area',\n }),\n className: cn(\n 'relative inline-flex min-w-0 items-center gap-2 data-disabled:cursor-not-allowed data-disabled:opacity-50',\n className,\n ),\n },\n areaProps,\n ),\n render,\n state: {\n slot: 'editable-area',\n ...(context.disabled && { disabled: '' }),\n ...(context.editing && { editing: '' }),\n },\n })\n}\n\nexport interface EditablePreviewProps\n extends React.ComponentProps<'div'>,\n useRender.ComponentProps<'div'> {}\n\nexport function EditablePreview(props: EditablePreviewProps) {\n const {\n onClick,\n onDoubleClick,\n onFocus,\n onKeyDown,\n className,\n render,\n ref,\n ...previewProps\n } = props\n const context = useEditableContext('EditablePreview')\n\n const trigger = React.useCallback(() => {\n context.beginEditing()\n }, [context.beginEditing])\n\n const handleKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event)\n if (event.defaultPrevented || event.key !== 'Enter') return\n\n const nativeEvent = event.nativeEvent\n context.onEnterKeyDown?.(nativeEvent)\n if (!nativeEvent.defaultPrevented) {\n trigger()\n }\n },\n [context.onEnterKeyDown, onKeyDown, trigger],\n )\n\n const element = useRender({\n defaultTagName: 'div',\n props: mergeProps<'div'>(\n {\n role: 'button',\n tabIndex: context.disabled ? undefined : 0,\n 'aria-disabled': context.disabled || undefined,\n ref,\n ...dataAttributes({\n 'data-disabled': context.disabled ? '' : undefined,\n 'data-empty': !context.value ? '' : undefined,\n 'data-slot': 'editable-preview',\n }),\n onClick: (event: React.MouseEvent<HTMLDivElement>) => {\n onClick?.(event)\n if (!event.defaultPrevented && context.triggerMode === 'click')\n trigger()\n },\n onDoubleClick: (event: React.MouseEvent<HTMLDivElement>) => {\n onDoubleClick?.(event)\n if (!event.defaultPrevented && context.triggerMode === 'dblclick')\n trigger()\n },\n onFocus: (event: React.FocusEvent<HTMLDivElement>) => {\n onFocus?.(event)\n if (!event.defaultPrevented && context.triggerMode === 'focus')\n trigger()\n },\n onKeyDown: handleKeyDown,\n className: cn(\n 'min-w-0 cursor-text truncate rounded-md border border-transparent px-2 py-1.5 text-sm outline-none hover:bg-accent/50 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 data-disabled:cursor-not-allowed data-disabled:opacity-50 data-empty:text-muted-foreground',\n className,\n ),\n children: context.value || context.placeholder,\n },\n previewProps,\n ),\n render,\n state: {\n slot: 'editable-preview',\n ...(context.disabled && { disabled: '' }),\n ...(!context.value && { empty: '' }),\n },\n })\n\n if (context.editing || context.readOnly) return null\n\n return element\n}\n\nexport interface EditableInputProps\n extends React.ComponentProps<'input'>,\n useRender.ComponentProps<'input'> {}\n\nexport function EditableInput(props: EditableInputProps) {\n const {\n onBlur,\n onChange,\n onKeyDown,\n className,\n disabled,\n readOnly,\n required,\n maxLength,\n render,\n ref,\n ...inputProps\n } = props\n const context = useEditableContext('EditableInput')\n const inputRef = React.useRef<HTMLInputElement>(null)\n const composedRef = useComposedRefs(ref, inputRef)\n const isDisabled = disabled || context.disabled\n const isReadOnly = readOnly || context.readOnly\n const isRequired = required || context.required\n\n const autosize = React.useCallback(\n (target: HTMLInputElement) => {\n if (!context.autosize) return\n target.style.width = '0'\n target.style.width = `${target.scrollWidth + 4}px`\n },\n [context.autosize],\n )\n\n React.useEffect(() => {\n if (!context.editing || isDisabled || isReadOnly || !inputRef.current)\n return\n\n const frame = requestAnimationFrame(() => {\n inputRef.current?.focus()\n inputRef.current?.select()\n if (inputRef.current) autosize(inputRef.current)\n })\n return () => cancelAnimationFrame(frame)\n }, [autosize, context.editing, isDisabled, isReadOnly])\n\n const element = useRender({\n defaultTagName: 'input',\n props: mergeProps<'input'>(\n {\n id: context.inputId,\n 'aria-labelledby': context.labelId,\n 'aria-required': isRequired || undefined,\n 'aria-invalid': context.invalid || undefined,\n dir: context.dir,\n disabled: isDisabled,\n readOnly: isReadOnly,\n required: isRequired,\n ref: composedRef,\n ...dataAttributes({ 'data-slot': 'editable-input' }),\n maxLength: maxLength ?? context.maxLength,\n placeholder: context.placeholder,\n value: context.value,\n onBlur: (event: React.FocusEvent<HTMLInputElement>) => {\n onBlur?.(event)\n if (event.defaultPrevented || isDisabled || isReadOnly) return\n\n const relatedTarget = event.relatedTarget\n const isEditableAction =\n relatedTarget instanceof HTMLElement &&\n Boolean(\n relatedTarget.closest(\n '[data-slot=\"editable-trigger\"], [data-slot=\"editable-cancel\"], [data-slot=\"editable-submit\"]',\n ),\n )\n if (!isEditableAction) {\n context.submitValue()\n }\n },\n onChange: (event: React.ChangeEvent<HTMLInputElement>) => {\n onChange?.(event)\n if (event.defaultPrevented || isDisabled || isReadOnly) return\n context.setValue(event.target.value)\n autosize(event.target)\n },\n onKeyDown: (event: React.KeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(event)\n if (event.defaultPrevented || isDisabled || isReadOnly) return\n\n if (event.key === 'Escape') {\n const nativeEvent = event.nativeEvent\n context.onEscapeKeyDown?.(nativeEvent)\n if (!nativeEvent.defaultPrevented) {\n context.cancelEditing()\n }\n } else if (event.key === 'Enter') {\n const nativeEvent = event.nativeEvent\n context.onEnterKeyDown?.(nativeEvent)\n if (!nativeEvent.defaultPrevented) {\n context.submitValue()\n }\n }\n },\n className: cn(\n 'flex h-9 rounded-md border border-input bg-transparent px-2 py-1 text-sm shadow-xs outline-none transition-colors placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 disabled:cursor-not-allowed disabled:opacity-50',\n context.autosize ? 'w-auto min-w-8' : 'w-full',\n className,\n ),\n },\n inputProps,\n ),\n render,\n state: {\n slot: 'editable-input',\n },\n })\n\n if (!context.editing && !isReadOnly) return null\n\n return element\n}\n\ntype EditableFieldElement = HTMLInputElement | HTMLTextAreaElement\n\nexport interface EditableFieldProps\n extends Omit<\n React.ComponentProps<'input'>,\n | 'defaultValue'\n | 'onBlur'\n | 'onChange'\n | 'onFocus'\n | 'onKeyDown'\n | 'ref'\n | 'value'\n > {\n emptyValue?: string\n multiline?: boolean\n ref?: React.Ref<EditableFieldElement>\n render?: useRender.ComponentProps<'input'>['render']\n onBlur?: React.FocusEventHandler<EditableFieldElement>\n onChange?: React.ChangeEventHandler<EditableFieldElement>\n onFocus?: React.FocusEventHandler<EditableFieldElement>\n onKeyDown?: React.KeyboardEventHandler<EditableFieldElement>\n}\n\nexport function EditableField(props: EditableFieldProps) {\n const {\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n emptyValue,\n multiline = false,\n onBlur,\n onChange,\n onFocus,\n onKeyDown,\n className,\n disabled,\n readOnly,\n required,\n maxLength,\n type,\n render,\n ref,\n ...fieldProps\n } = props\n const context = useEditableContext('EditableField')\n const isDisabled = disabled || context.disabled\n const isReadOnly = readOnly || context.readOnly\n const isRequired = required || context.required\n\n const begin = () => {\n if (context.editing) return\n context.beginEditing(\n emptyValue !== undefined && context.value === emptyValue ? '' : undefined,\n )\n }\n\n const element = useRender({\n defaultTagName: multiline ? 'textarea' : 'input',\n ref,\n props: mergeProps<'input'>(\n {\n id: context.inputId,\n 'aria-label': ariaLabel,\n 'aria-labelledby':\n ariaLabelledBy ?? (ariaLabel ? undefined : context.labelId),\n 'aria-required': isRequired || undefined,\n 'aria-invalid': context.invalid || undefined,\n dir: context.dir,\n disabled: isDisabled,\n required: isRequired,\n ...dataAttributes({\n 'data-disabled': isDisabled ? '' : undefined,\n 'data-editing': context.editing ? '' : undefined,\n 'data-empty': !context.value ? '' : undefined,\n 'data-slot': 'editable-field',\n }),\n maxLength: maxLength ?? context.maxLength,\n placeholder: context.placeholder,\n value: context.value,\n ...(multiline ? { rows: 1 } : { type }),\n onFocus: (event: React.FocusEvent<EditableFieldElement>) => {\n onFocus?.(event)\n if (event.defaultPrevented || isDisabled) return\n begin()\n },\n onBlur: (event: React.FocusEvent<EditableFieldElement>) => {\n onBlur?.(event)\n if (event.defaultPrevented || isDisabled) return\n context.finishEditing()\n },\n onChange: (event: React.ChangeEvent<EditableFieldElement>) => {\n onChange?.(event)\n if (event.defaultPrevented || isDisabled) return\n begin()\n context.setValue(event.target.value)\n },\n onKeyDown: (event: React.KeyboardEvent<EditableFieldElement>) => {\n onKeyDown?.(event)\n if (event.defaultPrevented || isDisabled) return\n\n const nativeEvent = event.nativeEvent\n if (event.key === 'Escape') {\n if (!context.isDirty()) return\n context.onEscapeKeyDown?.(nativeEvent)\n if (nativeEvent.defaultPrevented) return\n event.stopPropagation()\n context.cancelEditing()\n event.currentTarget.blur()\n } else if (event.key === 'Enter' && !multiline) {\n context.onEnterKeyDown?.(nativeEvent)\n if (nativeEvent.defaultPrevented) return\n event.preventDefault()\n event.currentTarget.blur()\n }\n },\n className: cn(\n 'w-full bg-transparent outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50',\n multiline && 'field-sizing-content resize-none',\n className,\n ),\n },\n fieldProps,\n ),\n render,\n state: {\n slot: 'editable-field',\n ...(context.editing && { editing: '' }),\n ...(isDisabled && { disabled: '' }),\n ...(!context.value && { empty: '' }),\n },\n })\n\n if (isReadOnly) {\n const dataProps = Object.fromEntries(\n Object.entries(fieldProps).filter(([key]) => key.startsWith('data-')),\n )\n return (\n <span\n className={className}\n data-empty={!context.value ? '' : undefined}\n data-readonly=\"\"\n data-slot=\"editable-field\"\n dir={context.dir}\n {...dataProps}\n >\n {context.value || context.placeholder}\n </span>\n )\n }\n\n return element\n}\n\nexport interface EditableTriggerProps\n extends React.ComponentProps<'button'>,\n useRender.ComponentProps<'button'> {\n forceMount?: boolean\n}\n\nexport function EditableTrigger(props: EditableTriggerProps) {\n const { forceMount = false, className, render, ref, ...triggerProps } = props\n const context = useEditableContext('EditableTrigger')\n\n const element = useRender({\n defaultTagName: 'button',\n props: mergeProps<'button'>(\n {\n type: 'button',\n 'aria-controls': context.rootId,\n 'aria-disabled': context.disabled || context.readOnly || undefined,\n ref,\n ...dataAttributes({\n 'data-disabled': context.disabled ? '' : undefined,\n 'data-readonly': context.readOnly ? '' : undefined,\n 'data-slot': 'editable-trigger',\n }),\n onClick:\n context.triggerMode === 'click'\n ? () => context.beginEditing()\n : undefined,\n onDoubleClick:\n context.triggerMode === 'dblclick'\n ? () => context.beginEditing()\n : undefined,\n className: cn(\n 'inline-flex h-8 w-fit items-center justify-center rounded-md border border-input bg-background px-3 font-medium text-sm shadow-xs outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring/30 disabled:pointer-events-none disabled:opacity-50',\n className,\n ),\n },\n triggerProps,\n ),\n render,\n state: {\n slot: 'editable-trigger',\n ...(context.disabled && { disabled: '' }),\n ...(context.readOnly && { readonly: '' }),\n },\n })\n\n if (!forceMount && (context.editing || context.readOnly)) return null\n\n return element\n}\n\nexport interface EditableToolbarProps\n extends React.ComponentProps<'div'>,\n useRender.ComponentProps<'div'> {\n orientation?: 'horizontal' | 'vertical'\n}\n\nexport function EditableToolbar(props: EditableToolbarProps) {\n const {\n className,\n orientation = 'horizontal',\n render,\n ref,\n ...toolbarProps\n } = props\n const context = useEditableContext('EditableToolbar')\n\n const element = useRender({\n defaultTagName: 'div',\n props: mergeProps<'div'>(\n {\n role: 'toolbar',\n 'aria-orientation': orientation,\n ref,\n ...dataAttributes({\n 'data-orientation': orientation,\n 'data-slot': 'editable-toolbar',\n }),\n className: cn(\n 'flex gap-2',\n orientation === 'vertical'\n ? 'flex-col items-stretch'\n : 'flex-row items-center',\n className,\n ),\n },\n toolbarProps,\n ),\n render,\n state: {\n slot: 'editable-toolbar',\n orientation,\n },\n })\n\n if (!context.editing) return null\n\n return element\n}\n\nexport interface EditableCancelProps\n extends React.ComponentProps<'button'>,\n useRender.ComponentProps<'button'> {}\n\nexport function EditableCancel(props: EditableCancelProps) {\n const { className, render, ref, ...cancelProps } = props\n const context = useEditableContext('EditableCancel')\n\n const element = useRender({\n defaultTagName: 'button',\n props: mergeProps<'button'>(\n {\n type: 'button',\n 'aria-controls': context.rootId,\n ref,\n ...dataAttributes({ 'data-slot': 'editable-cancel' }),\n onClick: context.cancelEditing,\n className: cn(\n 'inline-flex h-8 items-center justify-center rounded-md border border-input bg-background px-3 font-medium text-sm shadow-xs outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring/30',\n className,\n ),\n },\n cancelProps,\n ),\n render,\n state: {\n slot: 'editable-cancel',\n },\n })\n\n if (!context.editing) return null\n\n return element\n}\n\nexport interface EditableSubmitProps\n extends React.ComponentProps<'button'>,\n useRender.ComponentProps<'button'> {}\n\nexport function EditableSubmit(props: EditableSubmitProps) {\n const { className, render, ref, ...submitProps } = props\n const context = useEditableContext('EditableSubmit')\n\n const element = useRender({\n defaultTagName: 'button',\n props: mergeProps<'button'>(\n {\n type: 'button',\n 'aria-controls': context.rootId,\n ref,\n ...dataAttributes({ 'data-slot': 'editable-submit' }),\n onClick: context.submitValue,\n className: cn(\n 'inline-flex h-8 items-center justify-center rounded-md border border-primary bg-primary px-3 font-medium text-primary-foreground text-sm shadow-xs outline-none hover:bg-primary/90 focus-visible:ring-2 focus-visible:ring-ring/30',\n className,\n ),\n },\n submitProps,\n ),\n render,\n state: {\n slot: 'editable-submit',\n },\n })\n\n if (!context.editing) return null\n\n return element\n}\n",
|
|
159
|
+
"target": "~/packages/ui/src/patterns/editable/composition/editable/editable.tsx"
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"path": "patterns/editable/composition/editable/index.ts",
|
|
163
|
+
"type": "registry:file",
|
|
164
|
+
"content": "export {\n Editable,\n EditableArea,\n type EditableAreaProps,\n EditableCancel,\n type EditableCancelProps,\n EditableField,\n type EditableFieldProps,\n EditableInput,\n type EditableInputProps,\n EditableLabel,\n type EditableLabelProps,\n EditablePreview,\n type EditablePreviewProps,\n type EditableProps,\n EditableSubmit,\n type EditableSubmitProps,\n EditableToolbar,\n type EditableToolbarProps,\n EditableTrigger,\n type EditableTriggerProps,\n} from './editable'\n",
|
|
165
|
+
"target": "~/packages/ui/src/patterns/editable/composition/editable/index.ts"
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"path": "patterns/editable/index.ts",
|
|
169
|
+
"type": "registry:file",
|
|
170
|
+
"content": "export * from './composition/editable/index'\n",
|
|
171
|
+
"target": "~/packages/ui/src/patterns/editable/index.ts"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"path": "patterns/editable/store/editable-store.ts",
|
|
175
|
+
"type": "registry:file",
|
|
176
|
+
"content": "import { createContext, useContext } from 'react'\n\ntype Direction = 'ltr' | 'rtl'\ntype TriggerMode = 'click' | 'dblclick' | 'focus'\n\nexport interface EditableContextValue {\n rootId: string\n inputId: string\n labelId: string\n value: string\n editing: boolean\n dir?: Direction\n maxLength?: number\n placeholder?: string\n triggerMode: TriggerMode\n autosize: boolean\n disabled: boolean\n readOnly: boolean\n required: boolean\n invalid: boolean\n beginEditing: (initialDraft?: string) => void\n cancelEditing: () => void\n finishEditing: () => void\n isDirty: () => boolean\n submitValue: () => void\n setValue: (value: string) => void\n onEnterKeyDown?: (event: KeyboardEvent) => void\n onEscapeKeyDown?: (event: KeyboardEvent) => void\n}\n\nexport const EditableContext = createContext<EditableContextValue | null>(null)\n\nexport function useEditableContext(consumerName: string): EditableContextValue {\n const context = useContext(EditableContext)\n if (!context) {\n throw new Error(`\\`${consumerName}\\` must be used within \\`Editable\\``)\n }\n return context\n}\n",
|
|
177
|
+
"target": "~/packages/ui/src/patterns/editable/store/editable-store.ts"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"path": "patterns/properties/display/date/date-property.tsx",
|
|
181
|
+
"type": "registry:file",
|
|
182
|
+
"content": "'use client'\n\nimport type { DayPickerLocale } from '@daypicker/react'\nimport { CalendarDotsIcon } from '@phosphor-icons/react'\nimport { Calendar } from '@tc96/ui/calendar'\nimport { formatDateTime } from '@tc96/ui/helpers/date'\nimport { cn } from '@tc96/utils'\nimport { useState } from 'react'\nimport { emitChange, isEditable } from '../../shared/lib/property-change'\nimport {\n PropertyCalendarPopover,\n type PropertyCalendarProps,\n type PropertyPopoverDropdownPlacement,\n} from '../../shared/property-calendar-popover'\nimport {\n PropertySurface,\n type PropertyVariant,\n} from '../../shared/property-surface'\nimport { PropertyTooltip } from '../../shared/property-tooltip'\nimport {\n formatDateProperty,\n parseDatePropertyValue,\n serializeDatePropertyValue,\n} from './date-value'\n\nexport type DatePropertyDropdownPlacement = PropertyPopoverDropdownPlacement\n\nexport interface DatePropertyActionContext {\n date: Date | null\n previousValue: string | null\n}\n\nexport interface DatePropertyProps {\n value: string | null\n action?: (value: string | null, context: DatePropertyActionContext) => void\n allowClear?: boolean\n ariaLabel?: string\n calendarLocale?: DayPickerLocale\n calendarProps?: PropertyCalendarProps\n className?: string\n clearLabel?: string\n fallback?: string\n disabled?: boolean\n displayLabel?: string\n dropdownPlacement?: DatePropertyDropdownPlacement\n isOverdue?: boolean\n locale?: string\n readOnly?: boolean\n serializeDate?: (date: Date) => string\n timeZone?: string\n tooltip?: boolean\n variant?: PropertyVariant\n onValueChange?: (value: string | null) => void\n}\n\nfunction formatFullDate(\n value: string | null,\n locale: string,\n timeZone: string,\n): string | null {\n const date = parseDatePropertyValue(value)\n return date ? formatDateTime(date, locale, timeZone) : null\n}\n\nexport function DateProperty({\n action,\n allowClear = true,\n ariaLabel,\n calendarLocale,\n calendarProps,\n className,\n clearLabel = 'Limpar data',\n disabled = false,\n displayLabel,\n dropdownPlacement,\n fallback = 'Sem data',\n isOverdue = false,\n locale = 'en-US',\n onValueChange,\n readOnly = false,\n serializeDate = serializeDatePropertyValue,\n timeZone = 'UTC',\n tooltip = false,\n value,\n variant = 'badge',\n}: Readonly<DatePropertyProps>) {\n const [open, setOpen] = useState(false)\n const selectedDate = parseDatePropertyValue(value)\n const accessibleLabel = ariaLabel ?? 'Date'\n\n const handleChange = (nextValue: string | null, date: Date | null) => {\n if (nextValue !== value) {\n emitChange({ action, onValueChange }, nextValue, {\n date,\n previousValue: value,\n })\n }\n setOpen(false)\n }\n\n if (!isEditable({ action, onValueChange, readOnly })) {\n return (\n <DatePropertyBadge\n className={className}\n displayLabel={displayLabel}\n fallback={fallback}\n isOverdue={isOverdue}\n locale={locale}\n timeZone={timeZone}\n tooltip={tooltip}\n value={value}\n variant={variant}\n />\n )\n }\n\n const label =\n displayLabel ?? formatDateProperty(value, fallback, locale, timeZone)\n\n return (\n <PropertyCalendarPopover\n ariaLabel={accessibleLabel}\n className={cn(isOverdue && 'font-medium', className)}\n muted={!value}\n clear={\n allowClear\n ? { label: clearLabel, onClear: () => handleChange(null, null) }\n : undefined\n }\n disabled={disabled}\n dropdownPlacement={dropdownPlacement}\n icon={CalendarDotsIcon}\n label={label}\n onOpenChange={setOpen}\n open={open}\n overdue={isOverdue}\n tooltip={tooltip ? formatFullDate(value, locale, timeZone) : null}\n variant={variant}\n >\n <Calendar\n defaultMonth={selectedDate ?? undefined}\n locale={calendarLocale}\n mode=\"single\"\n selected={selectedDate ?? undefined}\n onSelect={(date) => {\n if (!date) return\n handleChange(serializeDate(date), date)\n }}\n {...calendarProps}\n />\n </PropertyCalendarPopover>\n )\n}\n\nexport function DatePropertyBadge({\n className,\n displayLabel,\n fallback = 'Sem data',\n isOverdue = false,\n locale = 'en-US',\n timeZone = 'UTC',\n tooltip = false,\n value,\n variant = 'badge',\n}: Readonly<\n Pick<\n DatePropertyProps,\n | 'className'\n | 'displayLabel'\n | 'fallback'\n | 'isOverdue'\n | 'locale'\n | 'timeZone'\n | 'tooltip'\n | 'value'\n | 'variant'\n >\n>) {\n const label =\n displayLabel ?? formatDateProperty(value, fallback, locale, timeZone)\n const fullDate = tooltip ? formatFullDate(value, locale, timeZone) : null\n\n const surface = (\n <PropertySurface\n className={cn('max-w-full', isOverdue && 'font-medium', className)}\n data-overdue={isOverdue || undefined}\n data-slot=\"property-surface\"\n muted={!value}\n tabIndex={fullDate ? 0 : undefined}\n variant={variant}\n >\n <CalendarDotsIcon\n aria-hidden\n className=\"size-4\"\n data-slot=\"property-icon\"\n />\n <span className=\"truncate\">{label}</span>\n </PropertySurface>\n )\n\n if (!fullDate) return surface\n\n return <PropertyTooltip content={fullDate} trigger={surface} />\n}\n",
|
|
183
|
+
"target": "~/packages/ui/src/patterns/properties/display/date/date-property.tsx"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
"path": "patterns/properties/display/date/date-value.ts",
|
|
187
|
+
"type": "registry:file",
|
|
188
|
+
"content": "import {\n formatShortDate,\n parseIsoDate,\n serializeIsoDay,\n} from '@tc96/ui/helpers/date'\n\nexport function formatDateProperty(\n value: string | null,\n fallback: string,\n locale: string,\n timeZone: string,\n): string {\n const date = parseIsoDate(value)\n return date ? formatShortDate(date, locale, timeZone) : fallback\n}\n\nexport function parseDatePropertyValue(value: string | null): Date | null {\n return parseIsoDate(value)\n}\n\nexport function serializeDatePropertyValue(date: Date): string {\n return serializeIsoDay(date)\n}\n",
|
|
189
|
+
"target": "~/packages/ui/src/patterns/properties/display/date/date-value.ts"
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"path": "patterns/properties/display/editable-text/editable-text.tsx",
|
|
193
|
+
"type": "registry:file",
|
|
194
|
+
"content": "'use client'\n\nimport { cn } from '@tc96/utils'\nimport { useState } from 'react'\nimport { Editable, EditableField } from '../../../editable/index'\n\nexport type EditableTextSize = 'sm' | 'base' | 'lg' | 'xl'\n\nexport interface EditableTextProps {\n ariaLabel: string\n autoFocus?: boolean\n className?: string\n emptyValue?: string\n multiline?: boolean\n placeholder?: string\n readOnly?: boolean\n revertWhenEmpty?: boolean\n size?: EditableTextSize\n type?: 'email' | 'text'\n value: string | null\n onCommit: (value: string | null) => void\n}\n\nconst sizeClassName: Record<EditableTextSize, string> = {\n base: 'text-base',\n lg: 'text-2xl',\n sm: 'text-sm',\n xl: 'text-[2rem]',\n}\n\nexport function EditableText({\n ariaLabel,\n autoFocus = false,\n className,\n emptyValue,\n multiline = false,\n placeholder,\n readOnly = false,\n revertWhenEmpty = false,\n size = 'base',\n type = 'text',\n value,\n onCommit,\n}: Readonly<EditableTextProps>) {\n const confirmed = value ?? ''\n const [draft, setDraft] = useState(confirmed)\n const [editing, setEditing] = useState(false)\n const [syncedValue, setSyncedValue] = useState(confirmed)\n\n if (!editing && confirmed !== syncedValue) {\n setSyncedValue(confirmed)\n setDraft(confirmed)\n }\n\n const showsEmptyValue = !draft || draft === emptyValue\n\n const submit = (next: string) => {\n const trimmed = next.trim()\n if (!trimmed && revertWhenEmpty) return setDraft(confirmed)\n if (trimmed !== confirmed) onCommit(trimmed || null)\n }\n\n return (\n <Editable\n className=\"contents\"\n editing={editing}\n onEditingChange={setEditing}\n onSubmit={submit}\n onValueChange={setDraft}\n placeholder={placeholder}\n readOnly={readOnly}\n render={<span />}\n value={draft}\n >\n <EditableField\n aria-label={ariaLabel}\n autoFocus={autoFocus}\n className={cn(\n sizeClassName[size],\n showsEmptyValue && 'text-muted-foreground',\n className,\n )}\n data-slot=\"editable-text\"\n emptyValue={emptyValue}\n multiline={multiline}\n type={type}\n />\n </Editable>\n )\n}\n",
|
|
195
|
+
"target": "~/packages/ui/src/patterns/properties/display/editable-text/editable-text.tsx"
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
"path": "patterns/properties/display/person/person-option-content.tsx",
|
|
199
|
+
"type": "registry:file",
|
|
200
|
+
"content": "'use client'\n\nimport { UserIcon } from '@phosphor-icons/react'\nimport { Avatar, AvatarFallback, AvatarImage } from '@tc96/ui/avatar'\nimport { resolveInitials } from '@tc96/ui/helpers/initials'\n\nexport type PersonAvatarSize = 'xs' | 'sm' | 'default' | 'lg' | 'xl'\n\nconst personAvatarSizeClassNames: Record<PersonAvatarSize, string | undefined> =\n {\n xs: '[--avatar-size:--spacing(4)] text-[0.625rem]',\n sm: '[--avatar-size:--spacing(6)] text-[0.625rem]',\n default: undefined,\n lg: '[--avatar-size:--spacing(10)]',\n xl: '[--avatar-size:--spacing(12)]',\n }\n\nexport interface PersonPropertyOption<TValue extends string = string> {\n value: TValue\n label: string\n fallback?: string\n imageUrl?: string\n supportingLabel?: string\n}\n\nexport function PersonAvatar({\n option,\n size = 'sm',\n}: Readonly<{\n option: PersonPropertyOption | null\n size?: PersonAvatarSize\n}>) {\n const resolved = option ? resolveInitials(option) : null\n const fallback =\n size === 'xs' && resolved !== null\n ? (Array.from(resolved)[0] ?? '')\n : resolved\n return (\n <Avatar className={personAvatarSizeClassNames[size]} data-size={size}>\n {option?.imageUrl ? <AvatarImage alt=\"\" src={option.imageUrl} /> : null}\n <AvatarFallback className=\"border border-input\">\n {fallback ?? <UserIcon aria-hidden className=\"size-4\" />}\n </AvatarFallback>\n </Avatar>\n )\n}\n\nexport function PersonOptionContent({\n option,\n size,\n}: Readonly<{\n option: PersonPropertyOption\n size?: PersonAvatarSize\n}>) {\n return (\n <span className=\"flex min-w-0 items-center gap-1.5\">\n <PersonAvatar option={option} size={size} />\n <span className=\"min-w-0 truncate\">{option.label}</span>\n {option.supportingLabel ? (\n <span className=\"hidden text-muted-foreground text-xs in-data-[slot=combobox-chip]:text-foreground/72 sm:inline\">\n {option.supportingLabel}\n </span>\n ) : null}\n </span>\n )\n}\n",
|
|
201
|
+
"target": "~/packages/ui/src/patterns/properties/display/person/person-option-content.tsx"
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"path": "patterns/properties/display/person/person-property.tsx",
|
|
205
|
+
"type": "registry:file",
|
|
206
|
+
"content": "'use client'\n\nimport { UserPlusIcon } from '@phosphor-icons/react'\nimport { SelectItem } from '@tc96/ui/select'\nimport { cn } from '@tc96/utils'\nimport { emitChange, isEditable } from '../../shared/lib/property-change'\nimport { resolveOption } from '../../shared/lib/property-options'\nimport {\n type PropertySelectDropdownPlacement,\n PropertySelectShell,\n propertySelectItemClassName,\n} from '../../shared/property-select-shell'\nimport {\n PropertySurface,\n type PropertyVariant,\n} from '../../shared/property-surface'\nimport {\n PersonAvatar,\n type PersonAvatarSize,\n PersonOptionContent,\n type PersonPropertyOption,\n} from './person-option-content'\n\nexport type { PersonPropertyOption }\n\nexport type PersonPropertyDropdownPlacement = PropertySelectDropdownPlacement\n\nexport interface PersonPropertyActionContext<TValue extends string = string> {\n option: PersonPropertyOption<TValue>\n previousValue: TValue | null\n}\n\nexport interface PersonPropertyProps<TValue extends string = string> {\n value: TValue | null\n options: readonly PersonPropertyOption<TValue>[]\n action?: (value: TValue, context: PersonPropertyActionContext<TValue>) => void\n ariaLabel?: string\n avatarSize?: PersonAvatarSize\n className?: string\n disabled?: boolean\n display?: 'avatar' | 'full'\n dropdownPlacement?: PersonPropertyDropdownPlacement\n placeholder?: string\n readOnly?: boolean\n variant?: PropertyVariant\n onValueChange?: (value: TValue) => void\n}\n\nexport function PersonProperty<TValue extends string = string>({\n action,\n ariaLabel,\n avatarSize = 'xs',\n className,\n disabled = false,\n display = 'full',\n dropdownPlacement,\n onValueChange,\n options,\n placeholder = 'Sem responsável',\n readOnly = false,\n value,\n variant = 'badge',\n}: Readonly<PersonPropertyProps<TValue>>) {\n const selectedOption = value ? resolveOption(options, value) : null\n const accessibleLabel = ariaLabel ?? 'Person'\n\n return (\n <PropertySelectShell\n ariaLabel={`${accessibleLabel}: ${selectedOption?.label ?? placeholder}`}\n className={className}\n disabled={disabled}\n dropdownPlacement={dropdownPlacement}\n items={options}\n itemToStringLabel={(option) => option.label}\n itemToStringValue={(option) => option.value}\n onValueChange={(option) => {\n if (option && option.value !== value) {\n emitChange({ action, onValueChange }, option.value, {\n option,\n previousValue: value,\n })\n }\n }}\n muted={!selectedOption}\n readOnly={!isEditable({ action, onValueChange, readOnly })}\n renderValue={(option) => (\n <PersonPropertyContent\n avatarSize={avatarSize}\n display={display}\n option={option}\n placeholder={placeholder}\n />\n )}\n variant={variant}\n value={selectedOption}\n >\n {options.map((option) => (\n <SelectItem\n aria-label={option.label}\n key={option.value}\n className={propertySelectItemClassName}\n value={option}\n >\n <PersonPropertyContent option={option} placeholder={placeholder} />\n </SelectItem>\n ))}\n </PropertySelectShell>\n )\n}\n\nexport function PersonPropertyBadge<TValue extends string = string>({\n ariaLabel,\n className,\n display = 'full',\n option,\n placeholder = 'Sem responsável',\n variant = 'badge',\n}: Readonly<{\n ariaLabel?: string\n className?: string\n display?: 'avatar' | 'full'\n option: PersonPropertyOption<TValue> | null\n placeholder?: string\n variant?: PropertyVariant\n}>) {\n return (\n <PropertySurface\n aria-label={ariaLabel}\n className={cn('max-w-full', className)}\n muted={!option}\n variant={variant}\n >\n <PersonPropertyContent\n avatarSize=\"xs\"\n display={display}\n option={option}\n placeholder={placeholder}\n />\n </PropertySurface>\n )\n}\n\nfunction PersonPropertyContent<TValue extends string = string>({\n avatarSize,\n display,\n option,\n placeholder,\n}: Readonly<{\n avatarSize?: PersonAvatarSize\n display?: 'avatar' | 'full'\n option: PersonPropertyOption<TValue> | null\n placeholder: string\n}>) {\n if (display === 'avatar') {\n return <PersonAvatar option={option} size={avatarSize} />\n }\n\n if (!option) {\n return (\n <span className=\"flex min-w-0 items-center gap-1.5 text-muted-foreground\">\n <UserPlusIcon aria-hidden className=\"size-4\" />\n <span className=\"truncate\">{placeholder}</span>\n </span>\n )\n }\n\n return <PersonOptionContent option={option} size={avatarSize} />\n}\n",
|
|
207
|
+
"target": "~/packages/ui/src/patterns/properties/display/person/person-property.tsx"
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
"path": "patterns/properties/shared/lib/property-change.ts",
|
|
211
|
+
"type": "registry:file",
|
|
212
|
+
"content": "export interface PropertyChangeHandlers<TValue, TContext> {\n action?: (value: TValue, context: TContext) => void\n onValueChange?: (value: TValue) => void\n}\n\nexport function isEditable({\n action,\n onValueChange,\n readOnly = false,\n}: Readonly<{\n action?: unknown\n onValueChange?: unknown\n readOnly?: boolean\n}>): boolean {\n return !readOnly && Boolean(action ?? onValueChange)\n}\n\nexport function emitChange<TValue, TContext>(\n { action, onValueChange }: Readonly<PropertyChangeHandlers<TValue, TContext>>,\n value: TValue,\n context: TContext,\n): void {\n if (action) {\n action(value, context)\n return\n }\n onValueChange?.(value)\n}\n",
|
|
213
|
+
"target": "~/packages/ui/src/patterns/properties/shared/lib/property-change.ts"
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"path": "patterns/properties/shared/lib/property-options.ts",
|
|
217
|
+
"type": "registry:file",
|
|
218
|
+
"content": "export interface OptionLike {\n label: string\n value: string\n}\n\nexport type ResolvedOption<TOption extends OptionLike> =\n | TOption\n | { label: TOption['value']; value: TOption['value'] }\n\nexport function resolveOption<TOption extends OptionLike>(\n options: readonly TOption[],\n value: TOption['value'],\n): ResolvedOption<TOption> {\n return (\n options.find((option) => option.value === value) ?? {\n label: value,\n value,\n }\n )\n}\n\nexport function resolveOptions<TOption extends OptionLike>(\n options: readonly TOption[],\n values: readonly TOption['value'][],\n): ResolvedOption<TOption>[] {\n return values.map((value) => resolveOption(options, value))\n}\n\nexport function diffValues<TValue>(\n previous: readonly TValue[],\n next: readonly TValue[],\n): { added: TValue | null; removed: TValue | null } {\n const previousValues = new Set(previous)\n const nextValues = new Set(next)\n\n return {\n added: next.find((value) => !previousValues.has(value)) ?? null,\n removed: previous.find((value) => !nextValues.has(value)) ?? null,\n }\n}\n\nexport function diffOptions<TOption extends OptionLike>(\n options: readonly TOption[],\n previous: readonly TOption['value'][],\n next: readonly TOption['value'][],\n): {\n added: ResolvedOption<TOption> | null\n removed: ResolvedOption<TOption> | null\n} {\n const { added, removed } = diffValues(previous, next)\n\n return {\n added: added === null ? null : resolveOption(options, added),\n removed: removed === null ? null : resolveOption(options, removed),\n }\n}\n",
|
|
219
|
+
"target": "~/packages/ui/src/patterns/properties/shared/lib/property-options.ts"
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"path": "patterns/properties/shared/property-calendar-popover.tsx",
|
|
223
|
+
"type": "registry:file",
|
|
224
|
+
"content": "'use client'\n\nimport { Button } from '@tc96/ui/button'\nimport type { Calendar } from '@tc96/ui/calendar'\nimport { Popover, PopoverPopup, PopoverTrigger } from '@tc96/ui/popover'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactNode } from 'react'\nimport type { PropertyIcon } from './property-catalog'\nimport { PropertySurface, type PropertyVariant } from './property-surface'\nimport { PropertyTooltip } from './property-tooltip'\n\nexport type PropertyPopoverDropdownPlacement = Pick<\n ComponentProps<typeof PopoverPopup>,\n 'align' | 'alignOffset' | 'side' | 'sideOffset'\n>\n\nexport type PropertyCalendarProps = Omit<\n ComponentProps<typeof Calendar>,\n 'defaultMonth' | 'mode' | 'onSelect' | 'selected'\n>\n\nexport interface PropertyCalendarPopoverProps {\n ariaLabel: string\n children: ReactNode\n icon: PropertyIcon\n label: string\n onOpenChange: (open: boolean) => void\n open: boolean\n align?: PropertyPopoverDropdownPlacement['align']\n className?: string\n clear?: { label: string; onClear: () => void }\n disabled?: boolean\n dropdownPlacement?: PropertyPopoverDropdownPlacement\n muted?: boolean\n overdue?: boolean\n tooltip?: ReactNode\n variant?: PropertyVariant\n}\n\nexport function PropertyCalendarPopover({\n align = 'start',\n ariaLabel,\n children,\n className,\n clear,\n disabled,\n dropdownPlacement,\n icon: Icon,\n label,\n muted = false,\n onOpenChange,\n open,\n overdue = false,\n tooltip,\n variant,\n}: Readonly<PropertyCalendarPopoverProps>) {\n const trigger = (\n <PopoverTrigger\n aria-label={`${ariaLabel}: ${label}`}\n disabled={disabled}\n render={\n <PropertySurface\n className={cn('max-w-full', className)}\n data-overdue={overdue || undefined}\n muted={muted}\n render={<button type=\"button\" />}\n variant={variant}\n />\n }\n >\n <Icon aria-hidden className=\"size-4\" data-slot=\"property-icon\" />\n <span className=\"truncate\">{label}</span>\n </PopoverTrigger>\n )\n\n return (\n <Popover onOpenChange={onOpenChange} open={open}>\n {tooltip ? (\n <PropertyTooltip content={tooltip} trigger={trigger} />\n ) : (\n trigger\n )}\n <PopoverPopup\n align={align}\n aria-label={ariaLabel}\n className=\"w-auto\"\n side=\"bottom\"\n {...dropdownPlacement}\n >\n {children}\n {clear ? (\n <div className=\"border-t p-2\">\n <Button\n className=\"w-full justify-start\"\n onClick={clear.onClear}\n size=\"sm\"\n type=\"button\"\n variant=\"ghost\"\n >\n {clear.label}\n </Button>\n </div>\n ) : null}\n </PopoverPopup>\n </Popover>\n )\n}\n",
|
|
225
|
+
"target": "~/packages/ui/src/patterns/properties/shared/property-calendar-popover.tsx"
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
"path": "patterns/properties/shared/property-catalog.ts",
|
|
229
|
+
"type": "registry:file",
|
|
230
|
+
"content": "import type React from 'react'\n\nexport type PropertyIcon = React.ComponentType<React.SVGProps<SVGSVGElement>>\n\nexport type PropertyTone = 'danger' | 'info' | 'neutral' | 'success' | 'warning'\n\nexport interface PropertyPreset<TValue extends string> {\n icon: PropertyIcon\n label: string\n tone: PropertyTone\n value: TValue\n}\n\nexport const propertyToneClassName: Record<PropertyTone, string> = {\n danger: 'text-destructive-foreground',\n info: 'text-info-foreground',\n neutral: 'text-muted-foreground',\n success: 'text-success-foreground',\n warning: 'text-warning-foreground',\n}\n",
|
|
231
|
+
"target": "~/packages/ui/src/patterns/properties/shared/property-catalog.ts"
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"path": "patterns/properties/shared/property-select-shell.tsx",
|
|
235
|
+
"type": "registry:file",
|
|
236
|
+
"content": "'use client'\n\nimport { Select, SelectPopup, SelectPrimitive } from '@tc96/ui/select'\nimport { cn } from '@tc96/utils'\nimport type { ComponentProps, ReactNode } from 'react'\nimport { PropertySurface, type PropertyVariant } from './property-surface'\n\nexport type PropertySelectDropdownPlacement = Pick<\n ComponentProps<typeof SelectPopup>,\n 'align' | 'alignItemWithTrigger' | 'alignOffset' | 'side' | 'sideOffset'\n>\n\nexport interface PropertySelectShellProps<\n TOption extends { label: ReactNode; value: string },\n> {\n ariaLabel: string\n children: ReactNode\n className?: string\n disabled?: boolean\n dropdownPlacement?: PropertySelectDropdownPlacement\n items: readonly TOption[]\n itemToStringLabel: (option: TOption) => string\n itemToStringValue: (option: TOption) => string\n muted?: boolean\n onValueChange: (option: TOption | null) => void\n readOnly?: boolean\n renderValue: (option: TOption | null) => ReactNode\n value: TOption | null\n variant?: PropertyVariant\n}\n\nexport function PropertySelectShell<\n TOption extends { label: ReactNode; value: string },\n>({\n ariaLabel,\n children,\n className,\n disabled = false,\n dropdownPlacement,\n items,\n itemToStringLabel,\n itemToStringValue,\n muted = false,\n onValueChange,\n readOnly = false,\n renderValue,\n value,\n variant = 'badge',\n}: Readonly<PropertySelectShellProps<TOption>>) {\n if (readOnly) {\n return (\n <PropertySurface\n aria-label={ariaLabel}\n className={cn('max-w-full', className)}\n muted={muted}\n role=\"img\"\n variant={variant}\n >\n {renderValue(value)}\n </PropertySurface>\n )\n }\n\n return (\n <Select<TOption>\n itemToStringLabel={itemToStringLabel}\n itemToStringValue={itemToStringValue}\n items={[...items]}\n onValueChange={onValueChange}\n value={value}\n >\n <SelectPrimitive.Trigger\n aria-label={ariaLabel}\n disabled={disabled}\n render={\n <PropertySurface\n className={cn('max-w-full', className)}\n muted={muted}\n render={<button type=\"button\" />}\n variant={variant}\n />\n }\n >\n {renderValue(value)}\n </SelectPrimitive.Trigger>\n <SelectPopup {...dropdownPlacement}>{children}</SelectPopup>\n </Select>\n )\n}\n\nexport const propertySelectItemClassName =\n 'grid-cols-[minmax(0,1fr)_.75rem] gap-4 pe-2.5 *:row-start-1 [&>div]:col-start-1 [&>span]:col-start-2 [&>span]:-me-0.5'\n",
|
|
237
|
+
"target": "~/packages/ui/src/patterns/properties/shared/property-select-shell.tsx"
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
"path": "patterns/properties/shared/property-surface.tsx",
|
|
241
|
+
"type": "registry:file",
|
|
242
|
+
"content": "'use client'\n\nimport { mergeProps } from '@base-ui/react/merge-props'\nimport { useRender } from '@base-ui/react/use-render'\nimport { Badge } from '@tc96/ui/badge'\nimport { cn } from '@tc96/utils'\nimport type React from 'react'\n\nexport type PropertyVariant = 'badge' | 'plain'\n\nexport const propertyBadgeClassName =\n 'h-6 min-w-6 px-[calc(--spacing(2.5)-1px)] text-sm sm:h-6 sm:min-w-6 sm:text-sm'\n\nexport interface PropertySurfaceProps extends useRender.ComponentProps<'span'> {\n variant?: PropertyVariant\n muted?: boolean\n}\n\nexport function PropertySurface({\n className,\n muted = false,\n render,\n variant = 'badge',\n ...props\n}: PropertySurfaceProps): React.ReactElement {\n const state = {\n 'data-slot': 'property-surface',\n 'data-variant': variant,\n ...(muted ? { 'data-empty': 'true' } : {}),\n ...(props['aria-label'] && !props.role && !render ? { role: 'img' } : {}),\n }\n const plain = useRender({\n defaultTagName: 'span',\n enabled: variant !== 'badge',\n props: mergeProps<'span'>(\n {\n className: cn(\n muted ? 'text-muted-foreground' : 'text-primary',\n 'inline-flex min-w-0 max-w-full items-center gap-1 whitespace-nowrap text-sm outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-64 [button&,a&]:cursor-pointer',\n '[button&,a&]:-ms-1.5 [button&,a&]:-my-0.5 [button&,a&]:h-6 [button&,a&]:rounded-sm [button&,a&]:px-1.5',\n '[button&,a&]:hover:bg-secondary [button&,a&]:hover:text-secondary-foreground',\n '[button&,a&]:focus-visible:bg-secondary [button&,a&]:focus-visible:text-secondary-foreground',\n '[button&,a&]:data-popup-open:bg-secondary [button&,a&]:data-popup-open:text-secondary-foreground',\n className,\n ),\n ...state,\n },\n props,\n ),\n render,\n })\n\n if (plain) return plain\n\n return (\n <Badge\n className={cn(\n propertyBadgeClassName,\n !muted && 'text-primary',\n className,\n )}\n variant={muted ? 'outline' : 'secondary'}\n {...(render ? { render } : {})}\n {...state}\n {...props}\n />\n )\n}\n",
|
|
243
|
+
"target": "~/packages/ui/src/patterns/properties/shared/property-surface.tsx"
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
"path": "patterns/properties/shared/property-tooltip.tsx",
|
|
247
|
+
"type": "registry:file",
|
|
248
|
+
"content": "'use client'\n\nimport { Tooltip, TooltipPopup, TooltipTrigger } from '@tc96/ui/tooltip'\nimport { type ReactElement, type ReactNode, useId } from 'react'\n\nexport interface PropertyTooltipProps {\n content: ReactNode\n trigger: ReactElement\n}\n\nexport function PropertyTooltip({\n content,\n trigger,\n}: Readonly<PropertyTooltipProps>) {\n const descriptionId = useId()\n\n return (\n <Tooltip>\n <TooltipTrigger aria-describedby={descriptionId} render={trigger} />\n <span hidden id={descriptionId}>\n {content}\n </span>\n <TooltipPopup>{content}</TooltipPopup>\n </Tooltip>\n )\n}\n",
|
|
249
|
+
"target": "~/packages/ui/src/patterns/properties/shared/property-tooltip.tsx"
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
"path": "patterns/records/group/composition/record-group-action/record-group-action.tsx",
|
|
253
|
+
"type": "registry:file",
|
|
254
|
+
"content": "'use client'\n\nimport { Button } from '@tc96/ui/button'\nimport type * as React from 'react'\nimport type { RecordGroupActionProps } from '../../core'\n\nexport function RecordGroupAction({\n disabled,\n icon: Icon,\n label,\n onClick,\n}: Readonly<RecordGroupActionProps>): React.ReactElement {\n return (\n <Button\n aria-label={label}\n disabled={disabled}\n onClick={onClick}\n size=\"icon-sm\"\n variant=\"ghost\"\n >\n <Icon aria-hidden=\"true\" />\n </Button>\n )\n}\n",
|
|
255
|
+
"target": "~/packages/ui/src/patterns/records/group/composition/record-group-action/record-group-action.tsx"
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
"path": "patterns/records/group/composition/record-group-filter/record-group-filter.tsx",
|
|
259
|
+
"type": "registry:file",
|
|
260
|
+
"content": "'use client'\n\nimport { FunnelSimpleIcon } from '@phosphor-icons/react'\nimport { Button } from '@tc96/ui/button'\nimport {\n Menu,\n MenuCheckboxItem,\n MenuGroup,\n MenuGroupLabel,\n MenuPopup,\n MenuRadioGroup,\n MenuRadioItem,\n MenuSeparator,\n MenuTrigger,\n} from '@tc96/ui/menu'\nimport { Fragment, type ReactElement } from 'react'\nimport type {\n RecordGroupFilterProps,\n RecordGroupFilterSection,\n} from '../../core'\n\nfunction FilterSection({\n label,\n onChange,\n options,\n value,\n}: Readonly<RecordGroupFilterSection>): ReactElement {\n return (\n <MenuGroup data-slot=\"record-group-filter-options\">\n <MenuGroupLabel>{label}</MenuGroupLabel>\n {options.map((option) => (\n <MenuCheckboxItem\n checked={value.includes(option.value)}\n key={option.value}\n onCheckedChange={(checked) =>\n onChange(\n options\n .map((item) => item.value)\n .filter((item) =>\n item === option.value ? checked : value.includes(item),\n ),\n )\n }\n >\n {option.label}\n </MenuCheckboxItem>\n ))}\n </MenuGroup>\n )\n}\n\nexport function RecordGroupFilter({\n filterLabel,\n filterOptions,\n filterValue = [],\n label,\n onFilterChange,\n onSortChange,\n sections = [],\n sortLabel,\n sortOptions,\n sortValue,\n}: Readonly<RecordGroupFilterProps>): ReactElement {\n const filterSections: readonly RecordGroupFilterSection[] = filterOptions\n ? [\n {\n label: filterLabel,\n onChange: (value) => onFilterChange?.(value),\n options: filterOptions,\n value: filterValue,\n },\n ...sections,\n ]\n : sections\n\n return (\n <Menu>\n <MenuTrigger\n aria-label={label}\n render={<Button size=\"icon-sm\" variant=\"ghost\" />}\n >\n <FunnelSimpleIcon aria-hidden=\"true\" />\n </MenuTrigger>\n <MenuPopup\n align=\"end\"\n aria-label={label}\n className=\"w-56\"\n data-slot=\"record-group-filter\"\n >\n {filterSections.map((section, index) => (\n <Fragment key={section.options.map((option) => option.value).join()}>\n {index > 0 ? <MenuSeparator /> : null}\n <FilterSection {...section} />\n </Fragment>\n ))}\n {sortOptions ? (\n <>\n {filterSections.length > 0 ? <MenuSeparator /> : null}\n <MenuGroup data-slot=\"record-group-filter-sort\">\n <MenuGroupLabel>{sortLabel}</MenuGroupLabel>\n <MenuRadioGroup\n onValueChange={(value) => onSortChange?.(String(value))}\n value={sortValue}\n >\n {sortOptions.map((option) => (\n <MenuRadioItem key={option.value} value={option.value}>\n {option.label}\n </MenuRadioItem>\n ))}\n </MenuRadioGroup>\n </MenuGroup>\n </>\n ) : null}\n </MenuPopup>\n </Menu>\n )\n}\n",
|
|
261
|
+
"target": "~/packages/ui/src/patterns/records/group/composition/record-group-filter/record-group-filter.tsx"
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
"path": "patterns/records/group/composition/record-group/record-group.tsx",
|
|
265
|
+
"type": "registry:file",
|
|
266
|
+
"content": "'use client'\n\nimport { CaretDownIcon } from '@phosphor-icons/react'\nimport { Card } from '@tc96/ui/card'\nimport {\n Collapsible,\n CollapsiblePanel,\n CollapsibleTrigger,\n} from '@tc96/ui/collapsible'\nimport { cn } from '@tc96/utils'\nimport { type ReactElement, type ReactNode, useId, useState } from 'react'\nimport type { RecordGroupProps } from '../../core'\nimport {\n recordGroupClassName,\n recordGroupContentVariants,\n recordGroupHeaderClassName,\n recordGroupPanelClassName,\n recordGroupShellClassName,\n recordGroupTitleVariants,\n recordGroupTriggerVariants,\n} from '../../lib/variants'\n\nconst chevronIcon = (\n <CaretDownIcon\n aria-hidden=\"true\"\n className=\"size-4 shrink-0 -rotate-90 transition-transform group-data-panel-open/trigger:rotate-0\"\n />\n)\n\nexport function RecordGroup({\n actions,\n actionsAlign = 'between',\n chevron = 'start',\n children,\n className,\n collapsible = true,\n defaultOpen = true,\n empty = false,\n footer,\n onOpenChange,\n open,\n title,\n variant = 'plain',\n}: Readonly<RecordGroupProps>): ReactElement {\n const controlled = open !== undefined\n const titleId = `record-group-title-${useId()}`\n const [internalOpen, setInternalOpen] = useState(defaultOpen && !empty)\n const [wasEmpty, setWasEmpty] = useState(empty)\n if (wasEmpty !== empty) {\n setWasEmpty(empty)\n if (wasEmpty && !controlled) setInternalOpen(true)\n }\n\n const isOpen = controlled ? open : internalOpen\n\n const content = (\n <div\n className={recordGroupContentVariants({ empty, variant })}\n data-slot=\"record-group-content\"\n >\n {children}\n </div>\n )\n\n const titleText = (\n <span className=\"min-w-0 break-words text-start\">{title}</span>\n )\n\n const hasTitle = title !== undefined && title !== null && title !== ''\n const labelledBy = hasTitle ? titleId : undefined\n\n const header =\n hasTitle || actions ? (\n <div\n className={recordGroupHeaderClassName(variant, actionsAlign)}\n data-actions-align={actionsAlign}\n data-slot=\"record-group-header\"\n >\n {hasTitle ? (\n <h2\n className={\n collapsible\n ? 'min-w-0 font-medium text-sm'\n : cn(\n 'font-medium text-sm',\n recordGroupTitleVariants({ variant }),\n )\n }\n id={titleId}\n >\n {collapsible ? (\n <CollapsibleTrigger\n className={recordGroupTriggerVariants({ variant })}\n >\n {chevron === 'start' ? chevronIcon : null}\n {titleText}\n {chevron === 'end' ? chevronIcon : null}\n </CollapsibleTrigger>\n ) : (\n titleText\n )}\n </h2>\n ) : null}\n {actions ? (\n <div\n className=\"flex shrink-0 items-center gap-1\"\n data-slot=\"record-group-actions\"\n >\n {actions}\n </div>\n ) : null}\n </div>\n ) : null\n\n const body = (\n <>\n {variant === 'inset' ? (\n <Card className={recordGroupShellClassName}>{content}</Card>\n ) : (\n content\n )}\n {footer ? (\n <div className=\"py-2\" data-slot=\"record-group-footer\">\n {footer}\n </div>\n ) : null}\n </>\n )\n\n const shell = (parts: ReactNode) =>\n variant === 'card' ? (\n <Card className={recordGroupShellClassName}>{parts}</Card>\n ) : (\n parts\n )\n\n if (!collapsible)\n return (\n <section\n aria-labelledby={labelledBy}\n className={recordGroupClassName(variant, className)}\n data-empty={empty ? 'true' : undefined}\n data-slot=\"record-group\"\n data-variant={variant}\n >\n {shell(\n <>\n {header}\n <div className={recordGroupPanelClassName(variant)}>{body}</div>\n </>,\n )}\n </section>\n )\n\n return (\n <Collapsible\n aria-labelledby={labelledBy}\n className={recordGroupClassName(variant, className)}\n data-empty={empty ? 'true' : undefined}\n data-slot=\"record-group\"\n data-variant={variant}\n onOpenChange={(next) => {\n if (!controlled) setInternalOpen(next)\n onOpenChange?.(next)\n }}\n open={isOpen}\n render={<section />}\n >\n {shell(\n <>\n {header}\n <CollapsiblePanel\n className={recordGroupPanelClassName(variant)}\n inert={!isOpen}\n >\n {body}\n </CollapsiblePanel>\n </>,\n )}\n </Collapsible>\n )\n}\n",
|
|
267
|
+
"target": "~/packages/ui/src/patterns/records/group/composition/record-group/record-group.tsx"
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"path": "patterns/records/group/core.ts",
|
|
271
|
+
"type": "registry:file",
|
|
272
|
+
"content": "import type { useRender } from '@base-ui/react/use-render'\nimport type { ReactNode } from 'react'\nimport type { PropertyIcon } from '../../properties/shared/property-catalog'\n\nexport type RecordGroupVariant = 'card' | 'inset' | 'plain'\n\nexport type RecordGroupRowAlign = 'between' | 'start'\n\nexport type RecordGroupActionsAlign = 'between' | 'start'\n\nexport interface RecordGroupProps {\n actions?: ReactNode\n actionsAlign?: RecordGroupActionsAlign\n chevron?: 'start' | 'end'\n children?: ReactNode\n className?: string\n collapsible?: boolean\n defaultOpen?: boolean\n empty?: boolean\n footer?: ReactNode\n onOpenChange?: (open: boolean) => void\n open?: boolean\n title?: ReactNode\n variant?: RecordGroupVariant\n}\n\nexport interface RecordGroupRowProps {\n align?: RecordGroupRowAlign\n children?: ReactNode\n className?: string\n label: ReactNode\n leading?: ReactNode\n}\n\nexport interface RecordGroupActionProps {\n disabled?: boolean\n icon: PropertyIcon\n label: string\n onClick?: () => void\n}\n\nexport interface RecordGroupDividerProps {\n className?: string\n}\n\nexport interface RecordGroupFilterOption {\n label: ReactNode\n value: string\n}\n\nexport interface RecordGroupFilterSection {\n label: ReactNode\n onChange: (value: string[]) => void\n options: readonly RecordGroupFilterOption[]\n value: readonly string[]\n}\n\nexport interface RecordGroupFilterProps {\n filterLabel?: ReactNode\n filterOptions?: readonly RecordGroupFilterOption[]\n filterValue?: readonly string[]\n label: string\n onFilterChange?: (value: string[]) => void\n onSortChange?: (value: string) => void\n sections?: readonly RecordGroupFilterSection[]\n sortLabel?: ReactNode\n sortOptions?: readonly RecordGroupFilterOption[]\n sortValue?: string\n}\n\nexport interface RecordGroupItemProps {\n children?: ReactNode\n className?: string\n interactive?: boolean\n leading?: ReactNode\n title: ReactNode\n}\n\nexport interface RecordGroupLinkProps extends useRender.ComponentProps<'a'> {\n leading?: ReactNode\n meta?: ReactNode\n}\n\nexport interface RecordStatusBadgeProps {\n children: ReactNode\n className?: string\n color?: string\n}\n\nexport interface RecordGroupSubgroupProps {\n chevron?: 'start' | 'end'\n children?: ReactNode\n className?: string\n collapsible?: boolean\n count?: ReactNode\n defaultOpen?: boolean\n meta?: ReactNode\n onOpenChange?: (open: boolean) => void\n open?: boolean\n title: ReactNode\n}\n\nexport type RecordGroupMetricsColumns = 1 | 2\n\nexport interface RecordGroupMetricsProps {\n children?: ReactNode\n className?: string\n columns?: RecordGroupMetricsColumns\n}\n\nexport interface RecordGroupMetricProps {\n className?: string\n icon?: ReactNode\n label: ReactNode\n progress?: number\n target?: ReactNode\n value: ReactNode\n}\n",
|
|
273
|
+
"target": "~/packages/ui/src/patterns/records/group/core.ts"
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
"path": "patterns/records/group/lib/variants.ts",
|
|
277
|
+
"type": "registry:file",
|
|
278
|
+
"content": "import { cn } from '@tc96/utils'\nimport { cva } from 'class-variance-authority'\nimport type { RecordGroupActionsAlign, RecordGroupVariant } from '../core'\n\nexport const recordGroupClassName = (\n variant: RecordGroupVariant,\n className?: string,\n) => cn('flex flex-col', variant === 'inset' && 'gap-1', className)\n\nexport const recordGroupShellClassName =\n 'bg-muted/72 p-3 shadow-none before:hidden'\n\nconst recordGroupHeaderVariants = cva('flex min-h-6 items-center gap-2', {\n defaultVariants: { actionsAlign: 'between' },\n variants: {\n actionsAlign: { between: 'justify-between', start: 'justify-start' },\n },\n})\n\nexport const recordGroupHeaderClassName = (\n variant: RecordGroupVariant,\n actionsAlign: RecordGroupActionsAlign,\n) =>\n cn(recordGroupHeaderVariants({ actionsAlign }), variant === 'inset' && 'px-1')\n\nconst recordGroupTitleVariantConfig = {\n defaultVariants: { variant: 'plain' },\n variants: { variant: { card: 'px-1', inset: 'px-1', plain: '' } },\n} as const\n\nexport const recordGroupTitleVariants = cva(\n 'flex min-w-0 items-center gap-1 py-1',\n recordGroupTitleVariantConfig,\n)\n\nexport const recordGroupTriggerVariants = cva(\n 'group/trigger flex min-w-0 items-center gap-1 rounded-md py-1 outline-none focus-visible:ring-2 focus-visible:ring-ring',\n recordGroupTitleVariantConfig,\n)\n\nexport const recordGroupRowHeightClassName =\n 'min-h-[var(--record-group-row-height,calc(var(--spacing)*8))]'\n\nexport const recordGroupRowPaddingClassName =\n 'px-[var(--record-group-row-padding,0px)]'\n\nexport const recordGroupRowGapClassName =\n 'gap-[var(--record-group-row-gap,0px)]'\n\nexport const recordGroupLinkOffsetClassName =\n '-mx-[var(--record-group-hover-offset,0px)] px-[calc(var(--record-group-row-padding,0px)+var(--record-group-hover-offset,0px))]'\n\nconst recordGroupRoomyRows =\n 'px-1 [--record-group-row-height:calc(var(--spacing)*8)]'\n\nconst recordGroupHoverOffset =\n '[--record-group-hover-offset:calc(var(--spacing)*2)]'\n\nconst recordGroupCardRows = cn(recordGroupRoomyRows, recordGroupHoverOffset)\n\nconst recordGroupPlainRows = cn(\n '[--record-group-row-height:calc(var(--spacing)*8)]',\n recordGroupHoverOffset,\n)\n\nexport const recordGroupSubgroupPanelClassName =\n '-mx-[var(--record-group-hover-offset,0px)] px-[var(--record-group-hover-offset,0px)]'\n\nexport const recordGroupPanelClassName = (variant: RecordGroupVariant) =>\n cn('overflow-x-visible overflow-y-clip', variant !== 'inset' && '-mx-2 px-2')\n\nexport const recordGroupContentVariants = cva(\n `flex flex-col [--record-group-row-gap:calc(var(--spacing)*1)] ${recordGroupRowGapClassName} has-[[data-slot=record-group-metrics]]:p-0`,\n {\n defaultVariants: { empty: false, variant: 'plain' },\n variants: {\n empty: {\n false: 'py-1',\n true: '',\n },\n variant: {\n card: recordGroupCardRows,\n inset: recordGroupCardRows,\n plain: recordGroupPlainRows,\n },\n },\n },\n)\n\nexport const recordGroupRowVariants = cva(\n `${recordGroupRowHeightClassName} ${recordGroupRowPaddingClassName} items-center gap-2`,\n {\n defaultVariants: { align: 'start' },\n variants: {\n align: {\n between: 'grid grid-cols-[minmax(4rem,1fr)_minmax(0,max-content)]',\n start: 'flex',\n },\n },\n },\n)\n\nexport const recordGroupRowLabelVariants = cva(\n 'flex items-center gap-2 text-muted-foreground text-sm',\n {\n defaultVariants: { align: 'start' },\n variants: {\n align: {\n between: 'min-w-0 max-w-36',\n start: 'w-28 shrink-0',\n },\n },\n },\n)\n\nexport const recordGroupRowValueVariants = cva(\n 'flex min-w-0 items-center text-sm',\n {\n defaultVariants: { align: 'start', leading: false },\n variants: {\n align: {\n between: 'justify-end text-end',\n start: 'flex-1',\n },\n leading: {\n false: '',\n true: '[&_[data-slot=property-icon]]:hidden',\n },\n },\n },\n)\n\nexport const recordGroupMetricsVariants = cva('grid gap-2', {\n defaultVariants: { columns: 2 },\n variants: { columns: { 1: 'grid-cols-1', 2: 'grid-cols-2' } },\n})\n\nexport const recordGroupMetricShellClassName =\n 'h-full gap-2 border-0 p-3 shadow-none before:hidden'\n",
|
|
279
|
+
"target": "~/packages/ui/src/patterns/records/group/lib/variants.ts"
|
|
280
|
+
}
|
|
281
|
+
],
|
|
282
|
+
"dependencies": [
|
|
283
|
+
"@base-ui/react@1.8.0",
|
|
284
|
+
"@daypicker/react@10.0.2",
|
|
285
|
+
"@dnd-kit/dom@0.5.0",
|
|
286
|
+
"@dnd-kit/react@0.5.0",
|
|
287
|
+
"@phosphor-icons/react@2.1.10",
|
|
288
|
+
"class-variance-authority@0.7.1",
|
|
289
|
+
"react@19.1.1"
|
|
290
|
+
],
|
|
291
|
+
"registryDependencies": [
|
|
292
|
+
"@ui/avatar",
|
|
293
|
+
"@ui/badge",
|
|
294
|
+
"@ui/button",
|
|
295
|
+
"@ui/calendar",
|
|
296
|
+
"@ui/card",
|
|
297
|
+
"@ui/checkbox",
|
|
298
|
+
"@ui/collapsible",
|
|
299
|
+
"@ui/input",
|
|
300
|
+
"@ui/menu",
|
|
301
|
+
"@ui/popover",
|
|
302
|
+
"@ui/select",
|
|
303
|
+
"@ui/text",
|
|
304
|
+
"@ui/tooltip"
|
|
305
|
+
],
|
|
306
|
+
"$schema": "https://ui.shadcn.com/schema/registry-item.json"
|
|
307
|
+
}
|