@gntik-ai/blocks 0.0.0-stage → 0.6.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/dist/index.d.ts +3626 -0
- package/dist/index.js +15417 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -3
- package/src/ai/AssistantCardGrid/AssistantCardGrid.test.tsx +32 -0
- package/src/ai/AssistantCardGrid/AssistantCardGrid.tsx +98 -0
- package/src/ai/AssistantCardGrid/block.meta.ts +10 -0
- package/src/ai/AssistantCardGrid/fixtures.ts +72 -0
- package/src/ai/EvaluationScorecard/EvaluationScorecard.test.tsx +39 -0
- package/src/ai/EvaluationScorecard/EvaluationScorecard.tsx +233 -0
- package/src/ai/EvaluationScorecard/block.meta.ts +10 -0
- package/src/ai/EvaluationScorecard/fixtures.ts +79 -0
- package/src/ai/ModelKeysList/ModelKeysList.test.tsx +44 -0
- package/src/ai/ModelKeysList/ModelKeysList.tsx +203 -0
- package/src/ai/ModelKeysList/block.meta.ts +10 -0
- package/src/ai/ModelKeysList/fixtures.ts +44 -0
- package/src/ai/PromptEditor/PromptEditor.test.tsx +97 -0
- package/src/ai/PromptEditor/PromptEditor.tsx +202 -0
- package/src/ai/PromptEditor/block.meta.ts +10 -0
- package/src/ai/PromptEditor/examples/controlled-variables.tsx +23 -0
- package/src/ai/PromptEditor/fixtures.ts +12 -0
- package/src/ai/TokenCostCard/TokenCostCard.test.tsx +36 -0
- package/src/ai/TokenCostCard/TokenCostCard.tsx +130 -0
- package/src/ai/TokenCostCard/block.meta.ts +9 -0
- package/src/ai/TokenCostCard/fixtures.ts +18 -0
- package/src/ai/TraceWaterfall/TraceWaterfall.test.tsx +119 -0
- package/src/ai/TraceWaterfall/TraceWaterfall.tsx +317 -0
- package/src/ai/TraceWaterfall/block.meta.ts +10 -0
- package/src/ai/TraceWaterfall/examples/no-details.tsx +6 -0
- package/src/ai/TraceWaterfall/examples/running.tsx +16 -0
- package/src/ai/TraceWaterfall/fixtures.ts +133 -0
- package/src/ai/TraceWaterfall/span-details.tsx +51 -0
- package/src/ai/index.ts +13 -0
- package/src/auth/ForgotPasswordForm/ForgotPasswordForm.test.tsx +209 -0
- package/src/auth/ForgotPasswordForm/ForgotPasswordForm.tsx +211 -0
- package/src/auth/ForgotPasswordForm/block.meta.ts +10 -0
- package/src/auth/ForgotPasswordForm/examples/UsernameOrEmail.tsx +24 -0
- package/src/auth/MfaChallenge/MfaChallenge.test.tsx +35 -0
- package/src/auth/MfaChallenge/MfaChallenge.tsx +170 -0
- package/src/auth/MfaChallenge/block.meta.ts +9 -0
- package/src/auth/ResetPasswordForm/ResetPasswordForm.test.tsx +27 -0
- package/src/auth/ResetPasswordForm/ResetPasswordForm.tsx +100 -0
- package/src/auth/ResetPasswordForm/block.meta.ts +10 -0
- package/src/auth/SignInForm/SignInForm.test.tsx +222 -0
- package/src/auth/SignInForm/SignInForm.tsx +226 -0
- package/src/auth/SignInForm/block.meta.ts +22 -0
- package/src/auth/SignInForm/examples/Username.tsx +26 -0
- package/src/auth/SignUpForm/SignUpForm.configured.test.tsx +316 -0
- package/src/auth/SignUpForm/SignUpForm.test.tsx +33 -0
- package/src/auth/SignUpForm/SignUpForm.tsx +298 -0
- package/src/auth/SignUpForm/block.meta.ts +22 -0
- package/src/auth/SignUpForm/examples/CustomFields.tsx +56 -0
- package/src/auth/SignUpForm/examples/Error.tsx +5 -0
- package/src/auth/SignUpForm/examples/Loading.tsx +6 -0
- package/src/auth/SignUpForm/examples/NoTerms.tsx +6 -0
- package/src/auth/SignUpForm/examples/Submitting.tsx +5 -0
- package/src/auth/SignUpForm/examples/Unavailable.tsx +15 -0
- package/src/auth/SsoButtons/SsoButtons.test.tsx +23 -0
- package/src/auth/SsoButtons/SsoButtons.tsx +52 -0
- package/src/auth/SsoButtons/block.meta.ts +9 -0
- package/src/auth/SsoButtons/fixtures.ts +15 -0
- package/src/auth/index.ts +16 -0
- package/src/auth/shared.tsx +147 -0
- package/src/billing/CostBreakdown/CostBreakdown.test.tsx +24 -0
- package/src/billing/CostBreakdown/CostBreakdown.tsx +95 -0
- package/src/billing/CostBreakdown/block.meta.ts +10 -0
- package/src/billing/CostBreakdown/fixtures.ts +9 -0
- package/src/billing/InvoiceTable/InvoiceTable.test.tsx +29 -0
- package/src/billing/InvoiceTable/InvoiceTable.tsx +130 -0
- package/src/billing/InvoiceTable/block.meta.ts +10 -0
- package/src/billing/InvoiceTable/fixtures.ts +38 -0
- package/src/billing/PaymentMethodCard/PaymentMethodCard.test.tsx +28 -0
- package/src/billing/PaymentMethodCard/PaymentMethodCard.tsx +103 -0
- package/src/billing/PaymentMethodCard/block.meta.ts +10 -0
- package/src/billing/PaymentMethodCard/fixtures.ts +12 -0
- package/src/billing/PlanCard/PlanCard.baseline.test.tsx +26 -0
- package/src/billing/PlanCard/PlanCard.summary.test.tsx +227 -0
- package/src/billing/PlanCard/PlanCard.test.tsx +27 -0
- package/src/billing/PlanCard/PlanCard.tsx +140 -0
- package/src/billing/PlanCard/PlanSummary.tsx +101 -0
- package/src/billing/PlanCard/README.md +23 -0
- package/src/billing/PlanCard/__snapshots__/PlanCard.baseline.test.tsx.snap +5 -0
- package/src/billing/PlanCard/block.meta.ts +60 -0
- package/src/billing/PlanCard/examples/SummaryActionsOnly.tsx +12 -0
- package/src/billing/PlanCard/examples/SummaryFeaturesOnly.tsx +14 -0
- package/src/billing/PlanCard/examples/SummaryFull.tsx +28 -0
- package/src/billing/PlanCard/examples/SummaryMinimal.tsx +5 -0
- package/src/billing/PlanCard/examples/SummaryPriceOnly.tsx +15 -0
- package/src/billing/PlanCard/examples/SummaryRenewalOnly.tsx +14 -0
- package/src/billing/PlanCard/examples/SummaryUnassigned.tsx +5 -0
- package/src/billing/PlanCard/examples/SummaryUnassignedNoLabel.tsx +5 -0
- package/src/billing/PlanCard/examples/SummaryZeroPrice.tsx +15 -0
- package/src/billing/PlanCard/fixtures.ts +19 -0
- package/src/billing/PlanDefinitionCard/PlanDefinitionCard.test.tsx +111 -0
- package/src/billing/PlanDefinitionCard/PlanDefinitionCard.tsx +86 -0
- package/src/billing/PlanDefinitionCard/README.md +29 -0
- package/src/billing/PlanDefinitionCard/block.meta.ts +46 -0
- package/src/billing/PlanDefinitionCard/examples/Compact.tsx +23 -0
- package/src/billing/PlanDefinitionCard/examples/Full.tsx +23 -0
- package/src/billing/PlanDefinitionCard/fixtures.ts +12 -0
- package/src/billing/QuotaMeters/QuotaMeters.test.tsx +23 -0
- package/src/billing/QuotaMeters/QuotaMeters.tsx +92 -0
- package/src/billing/QuotaMeters/block.meta.ts +10 -0
- package/src/billing/QuotaMeters/fixtures.ts +9 -0
- package/src/billing/SpendVsBudget/SpendVsBudget.test.tsx +24 -0
- package/src/billing/SpendVsBudget/SpendVsBudget.tsx +105 -0
- package/src/billing/SpendVsBudget/block.meta.ts +10 -0
- package/src/billing/SpendVsBudget/fixtures.ts +18 -0
- package/src/billing/format.ts +42 -0
- package/src/billing/index.ts +21 -0
- package/src/builders/CodePanel/CodePanel.test.tsx +280 -0
- package/src/builders/CodePanel/CodePanel.tsx +239 -0
- package/src/builders/CodePanel/block.meta.ts +10 -0
- package/src/builders/CodePanel/examples/controlled.tsx +15 -0
- package/src/builders/CodePanel/examples/diagnostics.tsx +40 -0
- package/src/builders/CodePanel/fixtures.ts +95 -0
- package/src/builders/CodePanel/marker-store.ts +90 -0
- package/src/builders/CodePanel/markers.ts +62 -0
- package/src/builders/FlowBuilder/FlowBuilder.test.tsx +480 -0
- package/src/builders/FlowBuilder/FlowBuilder.tsx +343 -0
- package/src/builders/FlowBuilder/block.meta.ts +20 -0
- package/src/builders/FlowBuilder/connections.ts +67 -0
- package/src/builders/FlowBuilder/decorated-nodes.ts +80 -0
- package/src/builders/FlowBuilder/examples/extensions.tsx +120 -0
- package/src/builders/FlowBuilder/extensions.ts +37 -0
- package/src/builders/FlowBuilder/fixtures.ts +80 -0
- package/src/builders/FlowBuilder/parts.tsx +196 -0
- package/src/builders/FlowBuilder/problems.tsx +40 -0
- package/src/builders/LogViewer/LogViewer.test.tsx +97 -0
- package/src/builders/LogViewer/LogViewer.tsx +253 -0
- package/src/builders/LogViewer/block.meta.ts +10 -0
- package/src/builders/LogViewer/fixtures.ts +49 -0
- package/src/builders/index.ts +15 -0
- package/src/data-display/ActivityFeed/ActivityFeed.test.tsx +62 -0
- package/src/data-display/ActivityFeed/ActivityFeed.tsx +118 -0
- package/src/data-display/ActivityFeed/block.meta.ts +10 -0
- package/src/data-display/ActivityFeed/fixtures.ts +29 -0
- package/src/data-display/ChartCard/ChartCard.ranges.test.tsx +282 -0
- package/src/data-display/ChartCard/ChartCard.test.tsx +54 -0
- package/src/data-display/ChartCard/ChartCard.tsx +218 -0
- package/src/data-display/ChartCard/block.meta.ts +10 -0
- package/src/data-display/ChartCard/examples/custom-ranges.tsx +37 -0
- package/src/data-display/ChartCard/examples/heatmap.tsx +20 -0
- package/src/data-display/ChartCard/examples/toolbar-owned-range.tsx +34 -0
- package/src/data-display/ChartCard/fixtures.ts +82 -0
- package/src/data-display/CommentThread/CommentThread.test.tsx +29 -0
- package/src/data-display/CommentThread/CommentThread.tsx +120 -0
- package/src/data-display/CommentThread/block.meta.ts +10 -0
- package/src/data-display/CommentThread/fixtures.ts +28 -0
- package/src/data-display/DescriptionListCard/DescriptionListCard.test.tsx +28 -0
- package/src/data-display/DescriptionListCard/DescriptionListCard.tsx +120 -0
- package/src/data-display/DescriptionListCard/block.meta.ts +9 -0
- package/src/data-display/DescriptionListCard/fixtures.ts +12 -0
- package/src/data-display/KpiRow/KpiRow.test.tsx +29 -0
- package/src/data-display/KpiRow/KpiRow.tsx +101 -0
- package/src/data-display/KpiRow/block.meta.ts +10 -0
- package/src/data-display/KpiRow/fixtures.ts +34 -0
- package/src/data-display/ResourceCardGrid/ResourceCardGrid.test.tsx +22 -0
- package/src/data-display/ResourceCardGrid/ResourceCardGrid.tsx +98 -0
- package/src/data-display/ResourceCardGrid/block.meta.ts +10 -0
- package/src/data-display/ResourceCardGrid/fixtures.ts +72 -0
- package/src/data-display/StatCard/StatCard.test.tsx +30 -0
- package/src/data-display/StatCard/StatCard.tsx +138 -0
- package/src/data-display/StatCard/block.meta.ts +10 -0
- package/src/data-display/StatCard/fixtures.ts +26 -0
- package/src/data-display/StatusTimeline/StatusTimeline.test.tsx +153 -0
- package/src/data-display/StatusTimeline/StatusTimeline.tsx +114 -0
- package/src/data-display/StatusTimeline/block.meta.ts +10 -0
- package/src/data-display/StatusTimeline/examples/Empty.tsx +6 -0
- package/src/data-display/StatusTimeline/fixtures.ts +62 -0
- package/src/data-display/index.ts +34 -0
- package/src/data-display/shared/TrendDelta.tsx +60 -0
- package/src/feedback/ConfirmDestructive/ConfirmDestructive.test.tsx +47 -0
- package/src/feedback/ConfirmDestructive/ConfirmDestructive.tsx +145 -0
- package/src/feedback/ConfirmDestructive/block.meta.ts +10 -0
- package/src/feedback/EmptyStates/EmptyStates.test.tsx +48 -0
- package/src/feedback/EmptyStates/EmptyStates.tsx +191 -0
- package/src/feedback/EmptyStates/block.meta.ts +10 -0
- package/src/feedback/EmptyStates/fixtures.ts +6 -0
- package/src/feedback/ErrorPanel/ErrorPanel.test.tsx +37 -0
- package/src/feedback/ErrorPanel/ErrorPanel.tsx +146 -0
- package/src/feedback/ErrorPanel/block.meta.ts +10 -0
- package/src/feedback/InlineCallout/InlineCallout.test.tsx +33 -0
- package/src/feedback/InlineCallout/InlineCallout.tsx +81 -0
- package/src/feedback/InlineCallout/block.meta.ts +9 -0
- package/src/feedback/Skeletons/Skeletons.test.tsx +25 -0
- package/src/feedback/Skeletons/Skeletons.tsx +142 -0
- package/src/feedback/Skeletons/block.meta.ts +10 -0
- package/src/feedback/SystemBanner/SystemBanner.test.tsx +29 -0
- package/src/feedback/SystemBanner/SystemBanner.tsx +105 -0
- package/src/feedback/SystemBanner/block.meta.ts +9 -0
- package/src/feedback/index.ts +14 -0
- package/src/feedback/types.ts +13 -0
- package/src/forms/CreateApiKeyDialog/CreateApiKeyDialog.test.tsx +36 -0
- package/src/forms/CreateApiKeyDialog/CreateApiKeyDialog.tsx +197 -0
- package/src/forms/CreateApiKeyDialog/block.meta.ts +10 -0
- package/src/forms/CreateApiKeyDialog/fixtures.ts +31 -0
- package/src/forms/CredentialDisclosureDialog/CredentialDisclosureDialog.test.tsx +339 -0
- package/src/forms/CredentialDisclosureDialog/CredentialDisclosureDialog.tsx +193 -0
- package/src/forms/CredentialDisclosureDialog/block.meta.ts +10 -0
- package/src/forms/CredentialDisclosureDialog/examples/Fresh.tsx +32 -0
- package/src/forms/CredentialDisclosureDialog/examples/ResponseGating.tsx +69 -0
- package/src/forms/CredentialDisclosureDialog/examples/Stored.tsx +32 -0
- package/src/forms/CredentialDisclosureDialog/fixtures.ts +14 -0
- package/src/forms/DangerZone/ConfirmDestructiveDialog.tsx +101 -0
- package/src/forms/DangerZone/DangerZone.test.tsx +28 -0
- package/src/forms/DangerZone/DangerZone.tsx +86 -0
- package/src/forms/DangerZone/block.meta.ts +10 -0
- package/src/forms/DangerZone/fixtures.ts +36 -0
- package/src/forms/DateRangeFilter/DateRangeFilter.test.tsx +26 -0
- package/src/forms/DateRangeFilter/DateRangeFilter.tsx +83 -0
- package/src/forms/DateRangeFilter/block.meta.ts +9 -0
- package/src/forms/DialogWizard/DialogWizard.test.tsx +95 -0
- package/src/forms/DialogWizard/DialogWizard.tsx +39 -0
- package/src/forms/DialogWizard/block.meta.ts +10 -0
- package/src/forms/DialogWizard/examples/CreateResource.tsx +65 -0
- package/src/forms/DialogWizard/fixtures.ts +20 -0
- package/src/forms/FileUploadPanel/FileUploadPanel.test.tsx +43 -0
- package/src/forms/FileUploadPanel/FileUploadPanel.tsx +244 -0
- package/src/forms/FileUploadPanel/block.meta.ts +10 -0
- package/src/forms/FileUploadPanel/fixtures.ts +66 -0
- package/src/forms/FormSection/FormSection.test.tsx +34 -0
- package/src/forms/FormSection/FormSection.tsx +77 -0
- package/src/forms/FormSection/block.meta.ts +9 -0
- package/src/forms/InviteMembersDialog/InviteMembersDialog.test.tsx +37 -0
- package/src/forms/InviteMembersDialog/InviteMembersDialog.tsx +183 -0
- package/src/forms/InviteMembersDialog/block.meta.ts +10 -0
- package/src/forms/InviteMembersDialog/fixtures.ts +14 -0
- package/src/forms/SettingsRow/SettingsRow.test.tsx +50 -0
- package/src/forms/SettingsRow/SettingsRow.tsx +74 -0
- package/src/forms/SettingsRow/block.meta.ts +9 -0
- package/src/forms/ValidationSummary/ValidationSummary.test.tsx +46 -0
- package/src/forms/ValidationSummary/ValidationSummary.tsx +75 -0
- package/src/forms/ValidationSummary/block.meta.ts +9 -0
- package/src/forms/ValidationSummary/fixtures.ts +13 -0
- package/src/forms/index.ts +27 -0
- package/src/index.ts +14 -0
- package/src/marketing/ComparisonTable/ComparisonTable.test.tsx +69 -0
- package/src/marketing/ComparisonTable/ComparisonTable.tsx +245 -0
- package/src/marketing/ComparisonTable/block.meta.ts +10 -0
- package/src/marketing/ComparisonTable/examples/options.tsx +48 -0
- package/src/marketing/ComparisonTable/fixtures.ts +83 -0
- package/src/marketing/Faq/Faq.test.tsx +25 -0
- package/src/marketing/Faq/Faq.tsx +68 -0
- package/src/marketing/Faq/block.meta.ts +10 -0
- package/src/marketing/Faq/fixtures.ts +32 -0
- package/src/marketing/FeatureGrid/FeatureGrid.test.tsx +19 -0
- package/src/marketing/FeatureGrid/FeatureGrid.tsx +79 -0
- package/src/marketing/FeatureGrid/block.meta.ts +10 -0
- package/src/marketing/FeatureGrid/fixtures.ts +36 -0
- package/src/marketing/Hero/Hero.test.tsx +33 -0
- package/src/marketing/Hero/Hero.tsx +107 -0
- package/src/marketing/Hero/block.meta.ts +10 -0
- package/src/marketing/PricingTable/PricingTable.test.tsx +92 -0
- package/src/marketing/PricingTable/PricingTable.tsx +323 -0
- package/src/marketing/PricingTable/block.meta.ts +10 -0
- package/src/marketing/PricingTable/fixtures.ts +34 -0
- package/src/marketing/actions.tsx +40 -0
- package/src/marketing/index.ts +15 -0
- package/src/meta.ts +25 -0
- package/src/page-chrome/BulkActionBar/BulkActionBar.test.tsx +34 -0
- package/src/page-chrome/BulkActionBar/BulkActionBar.tsx +76 -0
- package/src/page-chrome/BulkActionBar/block.meta.ts +9 -0
- package/src/page-chrome/PageHeader/PageHeader.test.tsx +68 -0
- package/src/page-chrome/PageHeader/PageHeader.tsx +152 -0
- package/src/page-chrome/PageHeader/block.meta.ts +10 -0
- package/src/page-chrome/PageHeader/fixtures.ts +29 -0
- package/src/page-chrome/PageToolbar/PageToolbar.test.tsx +38 -0
- package/src/page-chrome/PageToolbar/PageToolbar.tsx +138 -0
- package/src/page-chrome/PageToolbar/block.meta.ts +10 -0
- package/src/page-chrome/PageToolbar/fixtures.ts +8 -0
- package/src/page-chrome/SectionHeader/SectionHeader.test.tsx +28 -0
- package/src/page-chrome/SectionHeader/SectionHeader.tsx +73 -0
- package/src/page-chrome/SectionHeader/block.meta.ts +9 -0
- package/src/page-chrome/StickyActionBar/StickyActionBar.test.tsx +29 -0
- package/src/page-chrome/StickyActionBar/StickyActionBar.tsx +66 -0
- package/src/page-chrome/StickyActionBar/block.meta.ts +9 -0
- package/src/page-chrome/index.ts +13 -0
- package/src/page-chrome/types.ts +25 -0
- package/src/scheduling/AgendaList/AgendaList.test.tsx +28 -0
- package/src/scheduling/AgendaList/AgendaList.tsx +165 -0
- package/src/scheduling/AgendaList/block.meta.ts +10 -0
- package/src/scheduling/MonthCalendar/MonthCalendar.test.tsx +32 -0
- package/src/scheduling/MonthCalendar/MonthCalendar.tsx +223 -0
- package/src/scheduling/MonthCalendar/block.meta.ts +10 -0
- package/src/scheduling/TimeSlotPicker/TimeSlotPicker.test.tsx +26 -0
- package/src/scheduling/TimeSlotPicker/TimeSlotPicker.tsx +115 -0
- package/src/scheduling/TimeSlotPicker/block.meta.ts +10 -0
- package/src/scheduling/TimeSlotPicker/fixtures.ts +10 -0
- package/src/scheduling/WeekCalendar/WeekCalendar.test.tsx +27 -0
- package/src/scheduling/WeekCalendar/WeekCalendar.tsx +274 -0
- package/src/scheduling/WeekCalendar/block.meta.ts +10 -0
- package/src/scheduling/index.ts +11 -0
- package/src/scheduling/shared/CalendarHeader.tsx +54 -0
- package/src/scheduling/shared/EventTile.tsx +21 -0
- package/src/scheduling/shared/dates.ts +98 -0
- package/src/scheduling/shared/events.ts +90 -0
- package/src/scheduling/shared/fixtures.ts +54 -0
- package/src/shell/AppSidebar/AppSidebar.test.tsx +38 -0
- package/src/shell/AppSidebar/AppSidebar.tsx +226 -0
- package/src/shell/AppSidebar/block.meta.ts +10 -0
- package/src/shell/AppSidebar/fixtures.ts +58 -0
- package/src/shell/AppTopbar/AppTopbar.test.tsx +41 -0
- package/src/shell/AppTopbar/AppTopbar.tsx +82 -0
- package/src/shell/AppTopbar/block.meta.ts +19 -0
- package/src/shell/AppTopbar/fixtures.ts +22 -0
- package/src/shell/EnvironmentBadge/EnvironmentBadge.test.tsx +22 -0
- package/src/shell/EnvironmentBadge/EnvironmentBadge.tsx +55 -0
- package/src/shell/EnvironmentBadge/block.meta.ts +10 -0
- package/src/shell/GlobalSearch/GlobalSearch.test.tsx +28 -0
- package/src/shell/GlobalSearch/GlobalSearch.tsx +80 -0
- package/src/shell/GlobalSearch/block.meta.ts +10 -0
- package/src/shell/GlobalSearch/fixtures.ts +64 -0
- package/src/shell/index.ts +11 -0
- package/src/styles.css +2 -0
- package/src/tables/DataTable/DataTable.edit-views.test.tsx +249 -0
- package/src/tables/DataTable/DataTable.labels.test.tsx +291 -0
- package/src/tables/DataTable/DataTable.layout.test.tsx +188 -0
- package/src/tables/DataTable/DataTable.overflow-labels.test.tsx +59 -0
- package/src/tables/DataTable/DataTable.single-select.test.tsx +501 -0
- package/src/tables/DataTable/DataTable.test.tsx +268 -0
- package/src/tables/DataTable/DataTable.tsx +531 -0
- package/src/tables/DataTable/block.meta.ts +129 -0
- package/src/tables/DataTable/column-menu.tsx +112 -0
- package/src/tables/DataTable/column-sizing.ts +166 -0
- package/src/tables/DataTable/data-table-body.tsx +195 -0
- package/src/tables/DataTable/data-table-props.ts +159 -0
- package/src/tables/DataTable/data-table-row.tsx +231 -0
- package/src/tables/DataTable/data-table-utils.ts +195 -0
- package/src/tables/DataTable/density-toggle.tsx +33 -0
- package/src/tables/DataTable/editable-cell.tsx +287 -0
- package/src/tables/DataTable/examples/editable.tsx +71 -0
- package/src/tables/DataTable/examples/grouped.tsx +18 -0
- package/src/tables/DataTable/examples/resizable-pinned.tsx +20 -0
- package/src/tables/DataTable/examples/saved-views.tsx +61 -0
- package/src/tables/DataTable/examples/single-selection.tsx +55 -0
- package/src/tables/DataTable/examples/virtualized.tsx +20 -0
- package/src/tables/DataTable/fixtures.ts +119 -0
- package/src/tables/DataTable/header-cell.tsx +90 -0
- package/src/tables/DataTable/labels.ts +54 -0
- package/src/tables/DataTable/resize-handle.tsx +91 -0
- package/src/tables/DataTable/single-selection.tsx +149 -0
- package/src/tables/DataTable/use-table-views.ts +79 -0
- package/src/tables/DataTable/use-virtual-rows.ts +83 -0
- package/src/tables/DataTable/views.tsx +193 -0
- package/src/tables/FilterBar/FilterBar.labels.test.tsx +69 -0
- package/src/tables/FilterBar/FilterBar.test.tsx +43 -0
- package/src/tables/FilterBar/FilterBar.tsx +232 -0
- package/src/tables/FilterBar/block.meta.ts +32 -0
- package/src/tables/FilterBar/fixtures.ts +32 -0
- package/src/tables/InlineEditRow/InlineEditRow.test.tsx +41 -0
- package/src/tables/InlineEditRow/InlineEditRow.tsx +215 -0
- package/src/tables/InlineEditRow/block.meta.ts +10 -0
- package/src/tables/InlineEditRow/fixtures.ts +28 -0
- package/src/tables/PaginationFooter/PaginationFooter.labels.test.tsx +57 -0
- package/src/tables/PaginationFooter/PaginationFooter.test.tsx +29 -0
- package/src/tables/PaginationFooter/PaginationFooter.tsx +118 -0
- package/src/tables/PaginationFooter/block.meta.ts +33 -0
- package/src/tables/SubordinateList/SubordinateList.test.tsx +351 -0
- package/src/tables/SubordinateList/SubordinateList.tsx +140 -0
- package/src/tables/SubordinateList/block.meta.ts +10 -0
- package/src/tables/SubordinateList/examples/ResourceForm.tsx +129 -0
- package/src/tables/SubordinateList/examples/empty.tsx +5 -0
- package/src/tables/SubordinateList/examples/error.tsx +5 -0
- package/src/tables/SubordinateList/examples/loading.tsx +5 -0
- package/src/tables/TruncatedCollectionFooter/TruncatedCollectionFooter.test.tsx +159 -0
- package/src/tables/TruncatedCollectionFooter/TruncatedCollectionFooter.tsx +60 -0
- package/src/tables/TruncatedCollectionFooter/block.meta.ts +10 -0
- package/src/tables/TruncatedCollectionFooter/examples/exact.tsx +6 -0
- package/src/tables/TruncatedCollectionFooter/examples/has-more.tsx +12 -0
- package/src/tables/TruncatedCollectionFooter/fixtures.ts +2 -0
- package/src/tables/index.ts +45 -0
- package/src/team/MembersTable/MembersTable.test.tsx +29 -0
- package/src/team/MembersTable/MembersTable.tsx +141 -0
- package/src/team/MembersTable/block.meta.ts +9 -0
- package/src/team/MembersTable/fixtures.ts +19 -0
- package/src/team/NotificationMatrix/NotificationMatrix.test.tsx +36 -0
- package/src/team/NotificationMatrix/NotificationMatrix.tsx +144 -0
- package/src/team/NotificationMatrix/block.meta.ts +9 -0
- package/src/team/NotificationMatrix/fixtures.ts +43 -0
- package/src/team/PendingInvitations/PendingInvitations.test.tsx +30 -0
- package/src/team/PendingInvitations/PendingInvitations.tsx +132 -0
- package/src/team/PendingInvitations/block.meta.ts +9 -0
- package/src/team/PendingInvitations/fixtures.ts +39 -0
- package/src/team/ProfileHeader/ProfileHeader.test.tsx +29 -0
- package/src/team/ProfileHeader/ProfileHeader.tsx +106 -0
- package/src/team/ProfileHeader/block.meta.ts +10 -0
- package/src/team/ProfileHeader/fixtures.ts +28 -0
- package/src/team/SessionsDevices/SessionsDevices.test.tsx +30 -0
- package/src/team/SessionsDevices/SessionsDevices.tsx +126 -0
- package/src/team/SessionsDevices/block.meta.ts +10 -0
- package/src/team/SessionsDevices/fixtures.ts +58 -0
- package/src/team/index.ts +15 -0
- package/src/test/a11y.ts +18 -0
- package/src/test/heading-levels.test.tsx +69 -0
- package/src/test/setup.ts +36 -0
- package/README.md +0 -3
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { Check, Pencil, X } from '@gntik-ai/icons';
|
|
2
|
+
import {
|
|
3
|
+
cn,
|
|
4
|
+
IconButton,
|
|
5
|
+
Input,
|
|
6
|
+
Table,
|
|
7
|
+
TableBody,
|
|
8
|
+
TableCaption,
|
|
9
|
+
TableCell,
|
|
10
|
+
TableHead,
|
|
11
|
+
TableHeader,
|
|
12
|
+
TableRow,
|
|
13
|
+
useI18n,
|
|
14
|
+
} from '@gntik-ai/ui';
|
|
15
|
+
import { useEffect, useRef, useState, type KeyboardEvent } from 'react';
|
|
16
|
+
import { EDITABLE_MEMBER_FIELDS, EDITABLE_MEMBERS, type EditableMember } from './fixtures';
|
|
17
|
+
|
|
18
|
+
type Editable = string | number;
|
|
19
|
+
|
|
20
|
+
export interface InlineEditField<T> {
|
|
21
|
+
key: Extract<keyof T, string>;
|
|
22
|
+
label: string;
|
|
23
|
+
type?: 'text' | 'number' | 'email';
|
|
24
|
+
align?: 'left' | 'right';
|
|
25
|
+
required?: boolean;
|
|
26
|
+
/** Read-mode cell classes. */
|
|
27
|
+
className?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface InlineEditRowProps<T extends object> {
|
|
31
|
+
row: T;
|
|
32
|
+
fields: ReadonlyArray<InlineEditField<T>>;
|
|
33
|
+
/** Called with the edited row on Save (or Enter). */
|
|
34
|
+
onSave?: (next: T) => void;
|
|
35
|
+
onCancel?: () => void;
|
|
36
|
+
/** Row name for the Edit button label ("Edit Ana Lopez"). */
|
|
37
|
+
rowLabel?: string;
|
|
38
|
+
/** Start in edit mode. */
|
|
39
|
+
defaultEditing?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const read = <T extends object>(row: T, key: string): Editable => {
|
|
43
|
+
const v = (row as Record<string, unknown>)[key];
|
|
44
|
+
return typeof v === 'number' ? v : v == null ? '' : String(v);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A table row that switches into edit mode: inputs replace the cells, with Save and Cancel.
|
|
49
|
+
* Enter saves, Escape cancels; focus moves to the first input and back to Edit afterwards.
|
|
50
|
+
*/
|
|
51
|
+
export function InlineEditRow<T extends object>({
|
|
52
|
+
row,
|
|
53
|
+
fields,
|
|
54
|
+
onSave,
|
|
55
|
+
onCancel,
|
|
56
|
+
rowLabel,
|
|
57
|
+
defaultEditing = false,
|
|
58
|
+
}: InlineEditRowProps<T>) {
|
|
59
|
+
const { t } = useI18n();
|
|
60
|
+
const [editing, setEditing] = useState(defaultEditing);
|
|
61
|
+
const [draft, setDraft] = useState<Record<string, string>>({});
|
|
62
|
+
const editRef = useRef<HTMLButtonElement>(null);
|
|
63
|
+
const firstInputRef = useRef<HTMLInputElement>(null);
|
|
64
|
+
const restoreFocus = useRef(false);
|
|
65
|
+
const label = rowLabel ?? String(read(row, fields[0]?.key ?? ''));
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (editing) firstInputRef.current?.focus();
|
|
69
|
+
else if (restoreFocus.current) {
|
|
70
|
+
restoreFocus.current = false;
|
|
71
|
+
editRef.current?.focus();
|
|
72
|
+
}
|
|
73
|
+
}, [editing]);
|
|
74
|
+
|
|
75
|
+
const start = () => {
|
|
76
|
+
setDraft(Object.fromEntries(fields.map((f) => [f.key, String(read(row, f.key))])));
|
|
77
|
+
setEditing(true);
|
|
78
|
+
};
|
|
79
|
+
const finish = () => {
|
|
80
|
+
restoreFocus.current = true;
|
|
81
|
+
setEditing(false);
|
|
82
|
+
};
|
|
83
|
+
const invalid = (f: InlineEditField<T>) => f.required === true && (draft[f.key] ?? '').trim() === '';
|
|
84
|
+
const save = () => {
|
|
85
|
+
if (fields.some(invalid)) return;
|
|
86
|
+
const next = { ...row } as Record<string, unknown>;
|
|
87
|
+
for (const f of fields) {
|
|
88
|
+
const value = draft[f.key] ?? '';
|
|
89
|
+
next[f.key] = f.type === 'number' ? Number(value) : value;
|
|
90
|
+
}
|
|
91
|
+
onSave?.(next as T);
|
|
92
|
+
finish();
|
|
93
|
+
};
|
|
94
|
+
const cancel = () => {
|
|
95
|
+
onCancel?.();
|
|
96
|
+
finish();
|
|
97
|
+
};
|
|
98
|
+
const onKeyDown = (event: KeyboardEvent<HTMLTableRowElement>) => {
|
|
99
|
+
if (!editing) return;
|
|
100
|
+
if (event.key === 'Escape') {
|
|
101
|
+
event.preventDefault();
|
|
102
|
+
cancel();
|
|
103
|
+
} else if (event.key === 'Enter' && event.target instanceof HTMLInputElement) {
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
save();
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<TableRow selected={editing} onKeyDown={onKeyDown} data-editing={editing || undefined}>
|
|
111
|
+
{fields.map((f, i) => (
|
|
112
|
+
<TableCell key={f.key} align={f.align} className={cn(!editing && f.className, editing && 'py-1.5')}>
|
|
113
|
+
{editing ? (
|
|
114
|
+
<Input
|
|
115
|
+
ref={i === 0 ? firstInputRef : undefined}
|
|
116
|
+
aria-label={f.label}
|
|
117
|
+
type={f.type ?? 'text'}
|
|
118
|
+
size="sm"
|
|
119
|
+
required={f.required}
|
|
120
|
+
invalid={invalid(f)}
|
|
121
|
+
value={draft[f.key] ?? ''}
|
|
122
|
+
onValueChange={(v) => setDraft((d) => ({ ...d, [f.key]: String(v) }))}
|
|
123
|
+
inputClassName={f.align === 'right' ? 'text-end' : undefined}
|
|
124
|
+
className="min-w-24"
|
|
125
|
+
/>
|
|
126
|
+
) : (
|
|
127
|
+
read(row, f.key)
|
|
128
|
+
)}
|
|
129
|
+
</TableCell>
|
|
130
|
+
))}
|
|
131
|
+
<TableCell align="right" className="w-24 py-1.5 whitespace-nowrap">
|
|
132
|
+
{editing ? (
|
|
133
|
+
<span className="inline-flex gap-1">
|
|
134
|
+
<IconButton
|
|
135
|
+
icon={Check}
|
|
136
|
+
label={t('common.save')}
|
|
137
|
+
size="sm"
|
|
138
|
+
variant="soft"
|
|
139
|
+
onClick={save}
|
|
140
|
+
disabled={fields.some(invalid)}
|
|
141
|
+
/>
|
|
142
|
+
<IconButton icon={X} label={t('common.cancel')} size="sm" variant="ghost" onClick={cancel} />
|
|
143
|
+
</span>
|
|
144
|
+
) : (
|
|
145
|
+
<IconButton
|
|
146
|
+
ref={editRef}
|
|
147
|
+
icon={Pencil}
|
|
148
|
+
label={t('table.editRow', { label })}
|
|
149
|
+
size="sm"
|
|
150
|
+
variant="ghost"
|
|
151
|
+
onClick={start}
|
|
152
|
+
/>
|
|
153
|
+
)}
|
|
154
|
+
</TableCell>
|
|
155
|
+
</TableRow>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface InlineEditTableProps<T extends object> {
|
|
160
|
+
rows?: readonly T[];
|
|
161
|
+
fields?: ReadonlyArray<InlineEditField<T>>;
|
|
162
|
+
getRowId?: (row: T) => string;
|
|
163
|
+
caption?: string;
|
|
164
|
+
/** Called with the saved row; rows also update locally. */
|
|
165
|
+
onRowSave?: (row: T) => void;
|
|
166
|
+
className?: string;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Standalone demo of InlineEditRow: a small editable table that keeps its rows in state. */
|
|
170
|
+
export function InlineEditTable<T extends object = EditableMember>({
|
|
171
|
+
rows: initialRows = EDITABLE_MEMBERS as unknown as readonly T[],
|
|
172
|
+
fields = EDITABLE_MEMBER_FIELDS as unknown as ReadonlyArray<InlineEditField<T>>,
|
|
173
|
+
getRowId = (row) => String((row as { id?: unknown }).id ?? ''),
|
|
174
|
+
caption = 'Members',
|
|
175
|
+
onRowSave,
|
|
176
|
+
className,
|
|
177
|
+
}: InlineEditTableProps<T>) {
|
|
178
|
+
const { t } = useI18n();
|
|
179
|
+
const [rows, setRows] = useState<readonly T[]>(initialRows);
|
|
180
|
+
return (
|
|
181
|
+
<div className={cn('overflow-hidden rounded-xl border border-border bg-card shadow-sm', className)}>
|
|
182
|
+
<Table>
|
|
183
|
+
<TableCaption srOnly>{caption}</TableCaption>
|
|
184
|
+
<TableHeader>
|
|
185
|
+
<TableRow className="hover:bg-transparent">
|
|
186
|
+
{fields.map((f) => (
|
|
187
|
+
<TableHead key={f.key} align={f.align}>
|
|
188
|
+
{f.label}
|
|
189
|
+
</TableHead>
|
|
190
|
+
))}
|
|
191
|
+
<TableHead align="right">
|
|
192
|
+
<span className="sr-only">{t('table.actions')}</span>
|
|
193
|
+
</TableHead>
|
|
194
|
+
</TableRow>
|
|
195
|
+
</TableHeader>
|
|
196
|
+
<TableBody>
|
|
197
|
+
{rows.map((row) => {
|
|
198
|
+
const id = getRowId(row);
|
|
199
|
+
return (
|
|
200
|
+
<InlineEditRow
|
|
201
|
+
key={id}
|
|
202
|
+
row={row}
|
|
203
|
+
fields={fields}
|
|
204
|
+
onSave={(next) => {
|
|
205
|
+
setRows((prev) => prev.map((r) => (getRowId(r) === id ? next : r)));
|
|
206
|
+
onRowSave?.(next);
|
|
207
|
+
}}
|
|
208
|
+
/>
|
|
209
|
+
);
|
|
210
|
+
})}
|
|
211
|
+
</TableBody>
|
|
212
|
+
</Table>
|
|
213
|
+
</div>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BlockMeta } from '../../meta';
|
|
2
|
+
|
|
3
|
+
export const meta: BlockMeta = {
|
|
4
|
+
name: 'Inline edit row',
|
|
5
|
+
family: 'tables',
|
|
6
|
+
status: 'beta',
|
|
7
|
+
description:
|
|
8
|
+
'A table row that switches into edit mode with inputs, Save and Cancel; Enter saves, Escape cancels and focus returns to Edit. InlineEditTable is a ready-made editable table.',
|
|
9
|
+
uses: ['Table', 'Input', 'IconButton'],
|
|
10
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { InlineEditField } from './InlineEditRow';
|
|
2
|
+
|
|
3
|
+
export interface EditableMember {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
email: string;
|
|
7
|
+
role: string;
|
|
8
|
+
seats: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const EDITABLE_MEMBER_FIELDS: InlineEditField<EditableMember>[] = [
|
|
12
|
+
{ key: 'name', label: 'Name', required: true },
|
|
13
|
+
{
|
|
14
|
+
key: 'email',
|
|
15
|
+
label: 'Email',
|
|
16
|
+
type: 'email',
|
|
17
|
+
required: true,
|
|
18
|
+
className: 'font-mono text-[12px] text-muted-foreground',
|
|
19
|
+
},
|
|
20
|
+
{ key: 'role', label: 'Role' },
|
|
21
|
+
{ key: 'seats', label: 'Seats', type: 'number', align: 'right', className: 'font-mono text-[12.5px]' },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
export const EDITABLE_MEMBERS: EditableMember[] = [
|
|
25
|
+
{ id: 'm1', name: 'Ana Lopez', email: 'ana@example.com', role: 'Owner', seats: 3 },
|
|
26
|
+
{ id: 'm2', name: 'Sam Carter', email: 'sam@example.com', role: 'Admin', seats: 2 },
|
|
27
|
+
{ id: 'm3', name: 'Priya Nair', email: 'priya@example.com', role: 'Member', seats: 1 },
|
|
28
|
+
];
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { I18nProvider } from '@gntik-ai/ui';
|
|
4
|
+
import { PaginationFooter, type PaginationFooterLabels } from './PaginationFooter';
|
|
5
|
+
|
|
6
|
+
it('replaces pagination chrome and renders formatter results verbatim through page and size changes', async () => {
|
|
7
|
+
const user = userEvent.setup();
|
|
8
|
+
const rangeSummary = vi.fn((from: number, to: number, total: number) => `${from}|${to}|${total} registros`);
|
|
9
|
+
const paginationNav = vi.fn((noun: string) => `Paginación: ${noun}`);
|
|
10
|
+
const page = vi.fn((n: number) => `Página ${n}`);
|
|
11
|
+
const labels: PaginationFooterLabels = {
|
|
12
|
+
rowsPerPage: 'Filas por página',
|
|
13
|
+
rowsPerPageLabel: 'Tamaño de página',
|
|
14
|
+
rangeSummary,
|
|
15
|
+
paginationNav,
|
|
16
|
+
previous: 'Anterior',
|
|
17
|
+
next: 'Siguiente',
|
|
18
|
+
page,
|
|
19
|
+
};
|
|
20
|
+
const { container } = render(<PaginationFooter labels={labels} noun="Items" />);
|
|
21
|
+
expect(screen.getByText('Filas por página')).toBeVisible();
|
|
22
|
+
expect(screen.getByRole('navigation', { name: 'Paginación: Items' })).toBeVisible();
|
|
23
|
+
expect(paginationNav).toHaveBeenCalledWith('Items');
|
|
24
|
+
expect(page).toHaveBeenCalledWith(10);
|
|
25
|
+
const summary = container.querySelector('[aria-live]');
|
|
26
|
+
expect(summary?.textContent).toBe('1|10|97 registros');
|
|
27
|
+
expect(rangeSummary).toHaveBeenLastCalledWith(1, 10, 97);
|
|
28
|
+
await user.click(screen.getByRole('button', { name: 'Siguiente' }));
|
|
29
|
+
expect(summary?.textContent).toBe('11|20|97 registros');
|
|
30
|
+
expect(rangeSummary).toHaveBeenLastCalledWith(11, 20, 97);
|
|
31
|
+
await user.click(screen.getByRole('button', { name: 'Anterior' }));
|
|
32
|
+
await user.click(screen.getByRole('button', { name: 'Página 3' }));
|
|
33
|
+
expect(summary?.textContent).toBe('21|30|97 registros');
|
|
34
|
+
await user.click(screen.getByRole('combobox', { name: 'Tamaño de página' }));
|
|
35
|
+
await user.click(await screen.findByRole('option', { name: '25' }));
|
|
36
|
+
expect(summary?.textContent).toBe('1|25|97 registros');
|
|
37
|
+
expect(rangeSummary).toHaveBeenLastCalledWith(1, 25, 97);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('merges individual overrides over provider translations and preserves default summary markup', () => {
|
|
41
|
+
const { container, rerender } = render(
|
|
42
|
+
<I18nProvider locale="es">
|
|
43
|
+
<PaginationFooter />
|
|
44
|
+
</I18nProvider>,
|
|
45
|
+
);
|
|
46
|
+
const original = container.querySelector('[aria-live]')?.outerHTML;
|
|
47
|
+
const nextName = screen.getAllByRole('button').at(-1)?.getAttribute('aria-label');
|
|
48
|
+
rerender(
|
|
49
|
+
<I18nProvider locale="es">
|
|
50
|
+
<PaginationFooter labels={{ rowsPerPage: 'Custom' }} />
|
|
51
|
+
</I18nProvider>,
|
|
52
|
+
);
|
|
53
|
+
expect(screen.getByText('Custom')).toBeVisible();
|
|
54
|
+
expect(container.querySelector('[aria-live]')?.outerHTML).toBe(original);
|
|
55
|
+
expect(screen.getAllByRole('button').at(-1)?.getAttribute('aria-label')).toBe(nextName);
|
|
56
|
+
expect(screen.getByRole('combobox')).not.toHaveAccessibleName('Custom');
|
|
57
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { expectNoAxeViolations } from '../../test/a11y';
|
|
4
|
+
import { PaginationFooter } from './PaginationFooter';
|
|
5
|
+
|
|
6
|
+
describe('PaginationFooter', () => {
|
|
7
|
+
it('renders the summary and pagination', async () => {
|
|
8
|
+
const { container } = render(<PaginationFooter />);
|
|
9
|
+
expect(screen.getByText('1–10')).toBeInTheDocument();
|
|
10
|
+
expect(screen.getByRole('navigation', { name: 'Rows pagination' })).toBeInTheDocument();
|
|
11
|
+
expect(screen.getByRole('button', { name: 'Page 10' })).toBeInTheDocument();
|
|
12
|
+
await expectNoAxeViolations(container);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('pages and changes the page size', async () => {
|
|
16
|
+
const user = userEvent.setup();
|
|
17
|
+
const onPageChange = vi.fn();
|
|
18
|
+
const onPageSizeChange = vi.fn();
|
|
19
|
+
render(<PaginationFooter onPageChange={onPageChange} onPageSizeChange={onPageSizeChange} />);
|
|
20
|
+
await user.click(screen.getByRole('button', { name: 'Next page' }));
|
|
21
|
+
expect(onPageChange).toHaveBeenLastCalledWith(2);
|
|
22
|
+
expect(screen.getByText('11–20')).toBeInTheDocument();
|
|
23
|
+
await user.click(screen.getByRole('combobox', { name: 'Rows per page' }));
|
|
24
|
+
await user.click(await screen.findByRole('option', { name: '25' }));
|
|
25
|
+
expect(onPageSizeChange).toHaveBeenCalledWith(25);
|
|
26
|
+
expect(screen.getByText('1–25')).toBeInTheDocument();
|
|
27
|
+
expect(screen.getByRole('button', { name: 'Page 4' })).toBeInTheDocument();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { cn, Pagination, SimpleSelect, useI18n } from '@gntik-ai/ui';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
|
|
4
|
+
export interface PaginationFooterLabels {
|
|
5
|
+
rowsPerPage: string;
|
|
6
|
+
rowsPerPageLabel: string;
|
|
7
|
+
rangeSummary: (from: number, to: number, total: number) => string;
|
|
8
|
+
paginationNav: (noun: string) => string;
|
|
9
|
+
previous: string;
|
|
10
|
+
next: string;
|
|
11
|
+
page: (page: number) => string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface PaginationFooterProps {
|
|
15
|
+
/** Per-key overrides; omitted keys retain the existing provider translations and defaults. */
|
|
16
|
+
labels?: Partial<PaginationFooterLabels>;
|
|
17
|
+
/** Total number of rows. */
|
|
18
|
+
total?: number;
|
|
19
|
+
/** Current page, 1-based (controlled). */
|
|
20
|
+
page?: number;
|
|
21
|
+
defaultPage?: number;
|
|
22
|
+
onPageChange?: (page: number) => void;
|
|
23
|
+
/** Rows per page (controlled). */
|
|
24
|
+
pageSize?: number;
|
|
25
|
+
defaultPageSize?: number;
|
|
26
|
+
onPageSizeChange?: (pageSize: number) => void;
|
|
27
|
+
pageSizeOptions?: readonly number[];
|
|
28
|
+
/** What the rows are, for the accessible names ("Deployments"). */
|
|
29
|
+
noun?: string;
|
|
30
|
+
locale?: string;
|
|
31
|
+
className?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Table footer: rows-per-page Select, a "1–10 of 97" summary and numbered Pagination. Stacks on small screens. */
|
|
35
|
+
export function PaginationFooter({
|
|
36
|
+
total = 97,
|
|
37
|
+
page: pageProp,
|
|
38
|
+
defaultPage = 1,
|
|
39
|
+
onPageChange,
|
|
40
|
+
pageSize: sizeProp,
|
|
41
|
+
defaultPageSize = 10,
|
|
42
|
+
onPageSizeChange,
|
|
43
|
+
pageSizeOptions = [10, 25, 50, 100],
|
|
44
|
+
noun: nounProp,
|
|
45
|
+
locale: localeProp,
|
|
46
|
+
className,
|
|
47
|
+
labels,
|
|
48
|
+
}: PaginationFooterProps) {
|
|
49
|
+
const { t, locale: providerLocale } = useI18n();
|
|
50
|
+
const locale = localeProp ?? providerLocale;
|
|
51
|
+
const noun = nounProp ?? t('table.rows');
|
|
52
|
+
const [innerPage, setInnerPage] = useState(defaultPage);
|
|
53
|
+
const [innerSize, setInnerSize] = useState(defaultPageSize);
|
|
54
|
+
const pageSize = sizeProp ?? innerSize;
|
|
55
|
+
const pageCount = Math.max(1, Math.ceil(total / Math.max(1, pageSize)));
|
|
56
|
+
const page = Math.min(Math.max(1, pageProp ?? innerPage), pageCount);
|
|
57
|
+
const from = total === 0 ? 0 : (page - 1) * pageSize + 1;
|
|
58
|
+
const to = Math.min(page * pageSize, total);
|
|
59
|
+
const fmt = (n: number) => n.toLocaleString(locale);
|
|
60
|
+
|
|
61
|
+
const goTo = (next: number) => {
|
|
62
|
+
setInnerPage(next);
|
|
63
|
+
onPageChange?.(next);
|
|
64
|
+
};
|
|
65
|
+
const resize = (value: string | null) => {
|
|
66
|
+
const next = Number(value);
|
|
67
|
+
if (!next || next === pageSize) return;
|
|
68
|
+
setInnerSize(next);
|
|
69
|
+
onPageSizeChange?.(next);
|
|
70
|
+
// Keep the first visible row on screen.
|
|
71
|
+
const nextPage = Math.floor((from - 1) / next) + 1;
|
|
72
|
+
if (nextPage !== page) goTo(Math.max(1, nextPage));
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<div className={cn('flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between', className)}>
|
|
77
|
+
<div className="flex items-center gap-2.5">
|
|
78
|
+
<span className="text-[12.5px] text-muted-foreground" aria-hidden>
|
|
79
|
+
{labels?.rowsPerPage ?? t('table.rowsPerPage')}
|
|
80
|
+
</span>
|
|
81
|
+
<SimpleSelect
|
|
82
|
+
aria-label={labels?.rowsPerPageLabel ?? t('table.rowsPerPage')}
|
|
83
|
+
size="sm"
|
|
84
|
+
className="w-[76px] font-mono"
|
|
85
|
+
value={String(pageSize)}
|
|
86
|
+
onValueChange={resize}
|
|
87
|
+
items={pageSizeOptions.map((n) => ({ value: String(n), label: String(n) }))}
|
|
88
|
+
/>
|
|
89
|
+
</div>
|
|
90
|
+
<div className="flex flex-col gap-3 sm:flex-row sm:items-center">
|
|
91
|
+
<p className="text-[12.5px] text-muted-foreground tabular-nums" aria-live="polite">
|
|
92
|
+
{labels?.rangeSummary ? (
|
|
93
|
+
labels.rangeSummary(from, to, total)
|
|
94
|
+
) : (
|
|
95
|
+
<>
|
|
96
|
+
<span className="font-mono text-foreground">
|
|
97
|
+
{fmt(from)}–{fmt(to)}
|
|
98
|
+
</span>{' '}
|
|
99
|
+
{t('pagination.of')} <span className="font-mono text-foreground">{fmt(total)}</span>
|
|
100
|
+
</>
|
|
101
|
+
)}
|
|
102
|
+
</p>
|
|
103
|
+
<Pagination
|
|
104
|
+
page={page}
|
|
105
|
+
pageCount={pageCount}
|
|
106
|
+
onPageChange={goTo}
|
|
107
|
+
size="sm"
|
|
108
|
+
labels={{
|
|
109
|
+
nav: labels?.paginationNav?.(noun) ?? t('table.pagination', { noun }),
|
|
110
|
+
previous: labels?.previous,
|
|
111
|
+
next: labels?.next,
|
|
112
|
+
page: labels?.page,
|
|
113
|
+
}}
|
|
114
|
+
/>
|
|
115
|
+
</div>
|
|
116
|
+
</div>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { BlockMeta } from '../../meta';
|
|
2
|
+
import type { PaginationFooterLabels } from './PaginationFooter';
|
|
3
|
+
|
|
4
|
+
export const meta: BlockMeta = {
|
|
5
|
+
name: 'Pagination footer',
|
|
6
|
+
family: 'tables',
|
|
7
|
+
status: 'beta',
|
|
8
|
+
description:
|
|
9
|
+
'Table footer with a rows-per-page Select, a "1–10 of 97" summary and numbered Pagination; controlled or uncontrolled.',
|
|
10
|
+
labels: [
|
|
11
|
+
{ key: 'rowsPerPage', type: 'string', state: 'Always: visible page-size text' },
|
|
12
|
+
{ key: 'rowsPerPageLabel', type: 'string', state: 'Always: page-size Select accessible name' },
|
|
13
|
+
{
|
|
14
|
+
key: 'rangeSummary',
|
|
15
|
+
type: '(from: number, to: number, total: number) => string',
|
|
16
|
+
state: 'Every page and page-size change: visible summary and polite live region',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
key: 'paginationNav',
|
|
20
|
+
type: '(noun: string) => string',
|
|
21
|
+
state:
|
|
22
|
+
'Always: navigation accessible name; noun is caller content or defaults to the provider translation of rows',
|
|
23
|
+
},
|
|
24
|
+
{ key: 'previous', type: 'string', state: 'Always: previous-page button name' },
|
|
25
|
+
{ key: 'next', type: 'string', state: 'Always: next-page button name' },
|
|
26
|
+
{
|
|
27
|
+
key: 'page',
|
|
28
|
+
type: '(page: number) => string',
|
|
29
|
+
state: 'Always: numbered-page button name; number stays caller content',
|
|
30
|
+
},
|
|
31
|
+
] satisfies Array<{ key: keyof PaginationFooterLabels; type: string; state: string }>,
|
|
32
|
+
uses: ['SimpleSelect', 'Pagination'],
|
|
33
|
+
};
|