@sakoa/ui 0.1.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/README.md +171 -0
- package/dist/App.d.ts +2 -0
- package/dist/cli/index.js +9243 -0
- package/dist/components/DemoSection.d.ts +30 -0
- package/dist/components/SApiKeyboard.d.ts +22 -0
- package/dist/components/SApiSection.d.ts +21 -0
- package/dist/components/SApiTable.d.ts +46 -0
- package/dist/components/STableOfContents.d.ts +2 -0
- package/dist/components/ui/SAlert.d.ts +76 -0
- package/dist/components/ui/SBadge.d.ts +56 -0
- package/dist/components/ui/SButton.d.ts +67 -0
- package/dist/components/ui/SCheckbox.d.ts +64 -0
- package/dist/components/ui/SChip.d.ts +43 -0
- package/dist/components/ui/SDatePicker.d.ts +77 -0
- package/dist/components/ui/SGlassButton.d.ts +70 -0
- package/dist/components/ui/SIcon.d.ts +29 -0
- package/dist/components/ui/SInput.d.ts +129 -0
- package/dist/components/ui/SKbd.d.ts +24 -0
- package/dist/components/ui/SKbdShortcut.d.ts +14 -0
- package/dist/components/ui/SSelect.d.ts +148 -0
- package/dist/components/ui/SSkeleton.d.ts +37 -0
- package/dist/components/ui/SSwitch.d.ts +61 -0
- package/dist/components/ui/STooltip.d.ts +82 -0
- package/dist/components/ui/accordion/SAccordionContent.d.ts +23 -0
- package/dist/components/ui/accordion/SAccordionItem.d.ts +70 -0
- package/dist/components/ui/accordion/SAccordionTrigger.d.ts +37 -0
- package/dist/components/ui/accordion/index.d.ts +4 -0
- package/dist/components/ui/avatar/SAvatar.d.ts +36 -0
- package/dist/components/ui/avatar/SAvatarFallback.d.ts +26 -0
- package/dist/components/ui/avatar/SAvatarGroup.d.ts +30 -0
- package/dist/components/ui/avatar/SAvatarImage.d.ts +23 -0
- package/dist/components/ui/avatar/index.d.ts +4 -0
- package/dist/components/ui/breadcrumb/SBreadcrumb.d.ts +22 -0
- package/dist/components/ui/breadcrumb/SBreadcrumbEllipsis.d.ts +17 -0
- package/dist/components/ui/breadcrumb/SBreadcrumbItem.d.ts +17 -0
- package/dist/components/ui/breadcrumb/SBreadcrumbLink.d.ts +26 -0
- package/dist/components/ui/breadcrumb/SBreadcrumbList.d.ts +17 -0
- package/dist/components/ui/breadcrumb/SBreadcrumbPage.d.ts +17 -0
- package/dist/components/ui/breadcrumb/SBreadcrumbSeparator.d.ts +17 -0
- package/dist/components/ui/breadcrumb/index.d.ts +7 -0
- package/dist/components/ui/card/SCard.d.ts +103 -0
- package/dist/components/ui/card/SCardActions.d.ts +44 -0
- package/dist/components/ui/card/SCardContent.d.ts +35 -0
- package/dist/components/ui/card/SCardFooter.d.ts +38 -0
- package/dist/components/ui/card/SCardHeader.d.ts +53 -0
- package/dist/components/ui/card/SCardMedia.d.ts +83 -0
- package/dist/components/ui/card/SGlassCard.d.ts +103 -0
- package/dist/components/ui/card/SMorphingCardContent.d.ts +18 -0
- package/dist/components/ui/card/index.d.ts +24 -0
- package/dist/components/ui/carousel/SCarousel.d.ts +166 -0
- package/dist/components/ui/carousel/index.d.ts +2 -0
- package/dist/components/ui/color-picker/SColorPickerAlphaSlider.d.ts +4 -0
- package/dist/components/ui/color-picker/SColorPickerCopy.d.ts +19 -0
- package/dist/components/ui/color-picker/SColorPickerEyeDropper.d.ts +17 -0
- package/dist/components/ui/color-picker/SColorPickerHueSlider.d.ts +4 -0
- package/dist/components/ui/color-picker/SColorPickerInputs.d.ts +2 -0
- package/dist/components/ui/color-picker/SColorPickerPresets.d.ts +9 -0
- package/dist/components/ui/color-picker/SColorPickerPreview.d.ts +2 -0
- package/dist/components/ui/color-picker/SColorPickerRecent.d.ts +7 -0
- package/dist/components/ui/color-picker/SColorPickerSpectrum.d.ts +4 -0
- package/dist/components/ui/color-picker/index.d.ts +11 -0
- package/dist/components/ui/drawer/index.d.ts +11 -0
- package/dist/components/ui/dropdown/SDropdownDivider.d.ts +8 -0
- package/dist/components/ui/dropdown/SDropdownGroup.d.ts +25 -0
- package/dist/components/ui/dropdown/SDropdownItem.d.ts +56 -0
- package/dist/components/ui/dropdown/index.d.ts +4 -0
- package/dist/components/ui/form/SForm.d.ts +38 -0
- package/dist/components/ui/form/SFormField.d.ts +31 -0
- package/dist/components/ui/form/index.d.ts +5 -0
- package/dist/components/ui/modal/index.d.ts +19 -0
- package/dist/components/ui/option/SOption.d.ts +32 -0
- package/dist/components/ui/option/SOptionGroup.d.ts +28 -0
- package/dist/components/ui/option/index.d.ts +2 -0
- package/dist/components/ui/otp/SOTP.d.ts +122 -0
- package/dist/components/ui/otp/SOTPGroup.d.ts +23 -0
- package/dist/components/ui/otp/SOTPSeparator.d.ts +17 -0
- package/dist/components/ui/otp/SOTPSlot.d.ts +49 -0
- package/dist/components/ui/otp/index.d.ts +7 -0
- package/dist/components/ui/otp/types.d.ts +26 -0
- package/dist/components/ui/otp/useOTPContext.d.ts +42 -0
- package/dist/components/ui/pagination/SPagination.d.ts +151 -0
- package/dist/components/ui/pagination/index.d.ts +2 -0
- package/dist/components/ui/progress/SProgress.d.ts +62 -0
- package/dist/components/ui/progress/SProgressRange.d.ts +91 -0
- package/dist/components/ui/progress/index.d.ts +4 -0
- package/dist/components/ui/radio/SRadio.d.ts +58 -0
- package/dist/components/ui/radio/SRadioGroup.d.ts +52 -0
- package/dist/components/ui/radio/index.d.ts +2 -0
- package/dist/components/ui/stepper/SStepper.d.ts +83 -0
- package/dist/components/ui/stepper/SStepperContent.d.ts +24 -0
- package/dist/components/ui/stepper/SStepperDescription.d.ts +20 -0
- package/dist/components/ui/stepper/SStepperIndicator.d.ts +37 -0
- package/dist/components/ui/stepper/SStepperItem.d.ts +37 -0
- package/dist/components/ui/stepper/SStepperSeparator.d.ts +5 -0
- package/dist/components/ui/stepper/SStepperTitle.d.ts +20 -0
- package/dist/components/ui/stepper/SStepperTrigger.d.ts +22 -0
- package/dist/components/ui/stepper/index.d.ts +11 -0
- package/dist/components/ui/table/STableBody.d.ts +27 -0
- package/dist/components/ui/table/STableCell.d.ts +55 -0
- package/dist/components/ui/table/STableColumn.d.ts +87 -0
- package/dist/components/ui/table/STableEmpty.d.ts +54 -0
- package/dist/components/ui/table/STableHeader.d.ts +25 -0
- package/dist/components/ui/table/STableRow.d.ts +38 -0
- package/dist/components/ui/table/STableSkeleton.d.ts +29 -0
- package/dist/components/ui/table/index.d.ts +98 -0
- package/dist/components/ui/table/useDataTable.d.ts +80 -0
- package/dist/components/ui/tabs/STabPane.d.ts +31 -0
- package/dist/components/ui/tabs/STabsContent.d.ts +21 -0
- package/dist/components/ui/tabs/STabsIndicator.d.ts +9 -0
- package/dist/components/ui/tabs/STabsTrigger.d.ts +28 -0
- package/dist/components/ui/tabs/index.d.ts +6 -0
- package/dist/components/ui/toast/SToast.d.ts +49 -0
- package/dist/components/ui/toast/SToastContainer.d.ts +21 -0
- package/dist/components/ui/toast/index.d.ts +2 -0
- package/dist/composables/useAsync.d.ts +134 -0
- package/dist/composables/useClickOutside.d.ts +69 -0
- package/dist/composables/useClipboard.d.ts +46 -0
- package/dist/composables/useDebounce.d.ts +150 -0
- package/dist/composables/useDialog.d.ts +118 -0
- package/dist/composables/useForm.d.ts +204 -0
- package/dist/composables/useHotkey.d.ts +128 -0
- package/dist/composables/useIntersectionObserver.d.ts +156 -0
- package/dist/composables/useLocalStorage.d.ts +120 -0
- package/dist/composables/useMediaQuery.d.ts +115 -0
- package/dist/composables/useTheme.d.ts +8 -0
- package/dist/composables/useToast.d.ts +1619 -0
- package/dist/index.d.ts +71 -0
- package/dist/layouts/UILayout.d.ts +2 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/main.d.ts +0 -0
- package/dist/router.d.ts +2 -0
- package/dist/saka-ui.css +1 -0
- package/dist/saka-ui.js +18513 -0
- package/dist/saka-ui.umd.cjs +38 -0
- package/dist/views/docs/CustomizationView.d.ts +2 -0
- package/dist/views/docs/FormValidationView.d.ts +2 -0
- package/dist/views/docs/StylingGuideView.d.ts +2 -0
- package/dist/views/docs/UseAsyncView.d.ts +2 -0
- package/dist/views/docs/UseClickOutsideView.d.ts +124 -0
- package/dist/views/docs/UseClipboardView.d.ts +4 -0
- package/dist/views/docs/UseDebounceView.d.ts +2 -0
- package/dist/views/docs/UseHotkeyView.d.ts +205 -0
- package/dist/views/docs/UseIntersectionObserverView.d.ts +5 -0
- package/dist/views/docs/UseLocalStorageView.d.ts +2 -0
- package/dist/views/docs/UseMediaQueryView.d.ts +2 -0
- package/dist/views/docs/UseThemeView.d.ts +2 -0
- package/dist/views/examples/AuthFormView.d.ts +2 -0
- package/dist/views/examples/CreditCardFormView.d.ts +6 -0
- package/dist/views/examples/FormFieldExampleView.d.ts +2 -0
- package/dist/views/examples/ProjectFormView.d.ts +2 -0
- package/dist/views/ui/AccordionView.d.ts +2 -0
- package/dist/views/ui/AlertView.d.ts +2 -0
- package/dist/views/ui/AvatarView.d.ts +2 -0
- package/dist/views/ui/BadgeView.d.ts +2 -0
- package/dist/views/ui/BreadcrumbView.d.ts +2 -0
- package/dist/views/ui/ButtonView.d.ts +2 -0
- package/dist/views/ui/CardView.d.ts +2 -0
- package/dist/views/ui/CarouselView.d.ts +274 -0
- package/dist/views/ui/CheckboxView.d.ts +2 -0
- package/dist/views/ui/ChipView.d.ts +2 -0
- package/dist/views/ui/ColorPickerView.d.ts +2 -0
- package/dist/views/ui/DatePickerView.d.ts +2 -0
- package/dist/views/ui/DialogView.d.ts +2 -0
- package/dist/views/ui/DrawerView.d.ts +2 -0
- package/dist/views/ui/DropdownView.d.ts +2 -0
- package/dist/views/ui/GlassButtonView.d.ts +2 -0
- package/dist/views/ui/GlassCardView.d.ts +2 -0
- package/dist/views/ui/HomeView.d.ts +2 -0
- package/dist/views/ui/IconsView.d.ts +2 -0
- package/dist/views/ui/InputView.d.ts +2 -0
- package/dist/views/ui/KbdView.d.ts +2 -0
- package/dist/views/ui/ModalView.d.ts +2 -0
- package/dist/views/ui/MorphingCardView.d.ts +2 -0
- package/dist/views/ui/MorphingModalView.d.ts +2 -0
- package/dist/views/ui/OTPView.d.ts +206 -0
- package/dist/views/ui/PaginationView.d.ts +2 -0
- package/dist/views/ui/ProgressView.d.ts +2 -0
- package/dist/views/ui/RadioView.d.ts +2 -0
- package/dist/views/ui/SelectView.d.ts +2 -0
- package/dist/views/ui/SkeletonView.d.ts +2 -0
- package/dist/views/ui/StepperView.d.ts +2 -0
- package/dist/views/ui/SwitchView.d.ts +2 -0
- package/dist/views/ui/TableView.d.ts +2 -0
- package/dist/views/ui/TabsView.d.ts +2 -0
- package/dist/views/ui/ToastView.d.ts +2 -0
- package/dist/views/ui/TooltipView.d.ts +2 -0
- package/dist/vite.svg +1 -0
- package/package.json +64 -0
- package/registry/components/accordion.json +19 -0
- package/registry/components/alert.json +17 -0
- package/registry/components/avatar.json +18 -0
- package/registry/components/badge.json +14 -0
- package/registry/components/breadcrumb.json +24 -0
- package/registry/components/button.json +17 -0
- package/registry/components/card.json +23 -0
- package/registry/components/carousel.json +19 -0
- package/registry/components/checkbox.json +17 -0
- package/registry/components/chip.json +17 -0
- package/registry/components/color-picker.json +24 -0
- package/registry/components/date-picker.json +17 -0
- package/registry/components/drawer.json +26 -0
- package/registry/components/dropdown.json +21 -0
- package/registry/components/form.json +16 -0
- package/registry/components/glass-button.json +17 -0
- package/registry/components/icon.json +17 -0
- package/registry/components/input.json +17 -0
- package/registry/components/kbd.json +16 -0
- package/registry/components/modal.json +32 -0
- package/registry/components/option.json +16 -0
- package/registry/components/otp.json +23 -0
- package/registry/components/pagination.json +18 -0
- package/registry/components/progress.json +16 -0
- package/registry/components/radio.json +19 -0
- package/registry/components/select.json +17 -0
- package/registry/components/skeleton.json +14 -0
- package/registry/components/switch.json +17 -0
- package/registry/components/table.json +26 -0
- package/registry/components/tabs.json +19 -0
- package/registry/components/toast.json +19 -0
- package/registry/components/tooltip.json +14 -0
- package/registry/index.json +4 -0
- package/registry/source/components/ui/SAlert.vue +388 -0
- package/registry/source/components/ui/SBadge.vue +243 -0
- package/registry/source/components/ui/SButton.vue +387 -0
- package/registry/source/components/ui/SCheckbox.vue +310 -0
- package/registry/source/components/ui/SChip.vue +130 -0
- package/registry/source/components/ui/SDatePicker.vue +1290 -0
- package/registry/source/components/ui/SGlassButton.vue +547 -0
- package/registry/source/components/ui/SIcon.vue +78 -0
- package/registry/source/components/ui/SInput.vue +1054 -0
- package/registry/source/components/ui/SKbd.vue +96 -0
- package/registry/source/components/ui/SKbdShortcut.vue +36 -0
- package/registry/source/components/ui/SSelect.vue +1290 -0
- package/registry/source/components/ui/SSkeleton.vue +185 -0
- package/registry/source/components/ui/SSwitch.vue +275 -0
- package/registry/source/components/ui/STooltip.vue +491 -0
- package/registry/source/components/ui/accordion/SAccordion.vue +248 -0
- package/registry/source/components/ui/accordion/SAccordionItem.vue +353 -0
- package/registry/source/components/ui/accordion/index.ts +5 -0
- package/registry/source/components/ui/avatar/SAvatar.vue +169 -0
- package/registry/source/components/ui/avatar/SAvatarFallback.vue +66 -0
- package/registry/source/components/ui/avatar/SAvatarGroup.vue +69 -0
- package/registry/source/components/ui/avatar/SAvatarImage.vue +92 -0
- package/registry/source/components/ui/avatar/index.ts +5 -0
- package/registry/source/components/ui/breadcrumb/SBreadcrumb.vue +23 -0
- package/registry/source/components/ui/breadcrumb/SBreadcrumbEllipsis.vue +17 -0
- package/registry/source/components/ui/breadcrumb/SBreadcrumbItem.vue +14 -0
- package/registry/source/components/ui/breadcrumb/SBreadcrumbLink.vue +46 -0
- package/registry/source/components/ui/breadcrumb/SBreadcrumbList.vue +17 -0
- package/registry/source/components/ui/breadcrumb/SBreadcrumbPage.vue +15 -0
- package/registry/source/components/ui/breadcrumb/SBreadcrumbSeparator.vue +18 -0
- package/registry/source/components/ui/breadcrumb/index.ts +7 -0
- package/registry/source/components/ui/card/SCard.vue +517 -0
- package/registry/source/components/ui/card/SCardActions.vue +129 -0
- package/registry/source/components/ui/card/SCardContent.vue +117 -0
- package/registry/source/components/ui/card/SCardFooter.vue +103 -0
- package/registry/source/components/ui/card/SCardHeader.vue +163 -0
- package/registry/source/components/ui/card/SCardMedia.vue +312 -0
- package/registry/source/components/ui/card/index.ts +34 -0
- package/registry/source/components/ui/carousel/SCarousel.vue +1069 -0
- package/registry/source/components/ui/carousel/SCarouselSlide.vue +107 -0
- package/registry/source/components/ui/carousel/index.ts +3 -0
- package/registry/source/components/ui/color-picker/SColorPicker.vue +772 -0
- package/registry/source/components/ui/color-picker/SColorPickerAlphaSlider.vue +158 -0
- package/registry/source/components/ui/color-picker/SColorPickerCopy.vue +76 -0
- package/registry/source/components/ui/color-picker/SColorPickerEyeDropper.vue +68 -0
- package/registry/source/components/ui/color-picker/SColorPickerHueSlider.vue +138 -0
- package/registry/source/components/ui/color-picker/SColorPickerInputs.vue +227 -0
- package/registry/source/components/ui/color-picker/SColorPickerPresets.vue +87 -0
- package/registry/source/components/ui/color-picker/SColorPickerPreview.vue +46 -0
- package/registry/source/components/ui/color-picker/SColorPickerRecent.vue +74 -0
- package/registry/source/components/ui/color-picker/SColorPickerSpectrum.vue +149 -0
- package/registry/source/components/ui/color-picker/index.ts +11 -0
- package/registry/source/components/ui/drawer/SDrawer.vue +797 -0
- package/registry/source/components/ui/drawer/SDrawerClose.vue +64 -0
- package/registry/source/components/ui/drawer/SDrawerContent.vue +81 -0
- package/registry/source/components/ui/drawer/SDrawerDescription.vue +40 -0
- package/registry/source/components/ui/drawer/SDrawerFooter.vue +97 -0
- package/registry/source/components/ui/drawer/SDrawerHandle.vue +79 -0
- package/registry/source/components/ui/drawer/SDrawerHeader.vue +117 -0
- package/registry/source/components/ui/drawer/SDrawerTitle.vue +40 -0
- package/registry/source/components/ui/drawer/SDrawerTrigger.vue +51 -0
- package/registry/source/components/ui/drawer/index.ts +20 -0
- package/registry/source/components/ui/dropdown/SDropdown.vue +843 -0
- package/registry/source/components/ui/dropdown/SDropdownDivider.vue +23 -0
- package/registry/source/components/ui/dropdown/SDropdownGroup.vue +53 -0
- package/registry/source/components/ui/dropdown/SDropdownItem.vue +179 -0
- package/registry/source/components/ui/dropdown/index.ts +5 -0
- package/registry/source/components/ui/form/SForm.vue +84 -0
- package/registry/source/components/ui/form/SFormField.vue +78 -0
- package/registry/source/components/ui/form/index.ts +8 -0
- package/registry/source/components/ui/modal/SModal.vue +648 -0
- package/registry/source/components/ui/modal/SModalClose.vue +49 -0
- package/registry/source/components/ui/modal/SModalContent.vue +74 -0
- package/registry/source/components/ui/modal/SModalDescription.vue +39 -0
- package/registry/source/components/ui/modal/SModalFooter.vue +84 -0
- package/registry/source/components/ui/modal/SModalHeader.vue +107 -0
- package/registry/source/components/ui/modal/SModalTitle.vue +39 -0
- package/registry/source/components/ui/modal/SModalTrigger.vue +61 -0
- package/registry/source/components/ui/modal/SMorphingModal.vue +429 -0
- package/registry/source/components/ui/modal/SMorphingModalClose.vue +42 -0
- package/registry/source/components/ui/modal/SMorphingModalDescription.vue +49 -0
- package/registry/source/components/ui/modal/SMorphingModalImage.vue +44 -0
- package/registry/source/components/ui/modal/SMorphingModalSubtitle.vue +29 -0
- package/registry/source/components/ui/modal/SMorphingModalTitle.vue +34 -0
- package/registry/source/components/ui/modal/SMorphingModalTrigger.vue +95 -0
- package/registry/source/components/ui/modal/index.ts +32 -0
- package/registry/source/components/ui/option/SOption.vue +180 -0
- package/registry/source/components/ui/option/SOptionGroup.vue +77 -0
- package/registry/source/components/ui/option/index.ts +3 -0
- package/registry/source/components/ui/otp/SOTP.vue +843 -0
- package/registry/source/components/ui/otp/SOTPGroup.vue +29 -0
- package/registry/source/components/ui/otp/SOTPSeparator.vue +15 -0
- package/registry/source/components/ui/otp/SOTPSlot.vue +462 -0
- package/registry/source/components/ui/otp/index.ts +7 -0
- package/registry/source/components/ui/otp/types.ts +27 -0
- package/registry/source/components/ui/otp/useOTPContext.ts +62 -0
- package/registry/source/components/ui/pagination/SPagination.vue +923 -0
- package/registry/source/components/ui/pagination/index.ts +8 -0
- package/registry/source/components/ui/progress/SProgress.vue +635 -0
- package/registry/source/components/ui/progress/SProgressRange.vue +715 -0
- package/registry/source/components/ui/progress/index.ts +4 -0
- package/registry/source/components/ui/radio/SRadio.vue +407 -0
- package/registry/source/components/ui/radio/SRadioGroup.vue +200 -0
- package/registry/source/components/ui/radio/index.ts +3 -0
- package/registry/source/components/ui/table/SDataTable.vue +828 -0
- package/registry/source/components/ui/table/STableBody.vue +70 -0
- package/registry/source/components/ui/table/STableCell.vue +147 -0
- package/registry/source/components/ui/table/STableColumn.vue +120 -0
- package/registry/source/components/ui/table/STableEmpty.vue +159 -0
- package/registry/source/components/ui/table/STableHeader.vue +132 -0
- package/registry/source/components/ui/table/STableRow.vue +106 -0
- package/registry/source/components/ui/table/STableSkeleton.vue +208 -0
- package/registry/source/components/ui/table/index.ts +126 -0
- package/registry/source/components/ui/table/useDataTable.ts +519 -0
- package/registry/source/components/ui/tabs/STabPane.vue +130 -0
- package/registry/source/components/ui/tabs/STabs.vue +467 -0
- package/registry/source/components/ui/tabs/index.ts +7 -0
- package/registry/source/components/ui/toast/SToast.vue +261 -0
- package/registry/source/components/ui/toast/SToastContainer.vue +209 -0
- package/registry/source/components/ui/toast/index.ts +2 -0
- package/registry/source/composables/useForm.ts +960 -0
- package/registry/source/composables/useTheme.ts +86 -0
- package/registry/source/composables/useToast.ts +440 -0
- package/registry/source/lib/utils.ts +6 -0
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
import { ref, computed, watch, shallowRef, type Ref, type ComputedRef } from 'vue'
|
|
2
|
+
import type { TableColumn, SortState, SortDirection, PaginationState } from './index'
|
|
3
|
+
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// Types
|
|
6
|
+
// ============================================================================
|
|
7
|
+
|
|
8
|
+
export interface UseDataTableOptions<T> {
|
|
9
|
+
/** Initial data */
|
|
10
|
+
data?: T[] | Ref<T[]>
|
|
11
|
+
/** Column definitions */
|
|
12
|
+
columns?: TableColumn<T>[] | Ref<TableColumn<T>[]>
|
|
13
|
+
/** Function to get unique key from row */
|
|
14
|
+
rowKey?: keyof T | ((row: T, index: number) => string | number)
|
|
15
|
+
/** Initial sort state */
|
|
16
|
+
initialSort?: SortState
|
|
17
|
+
/** Enable pagination */
|
|
18
|
+
pagination?: boolean | Partial<PaginationState>
|
|
19
|
+
/** Enable selection */
|
|
20
|
+
selection?: boolean
|
|
21
|
+
/** Enable multi-select */
|
|
22
|
+
multiSelect?: boolean
|
|
23
|
+
/** Enable row expansion */
|
|
24
|
+
expandable?: boolean
|
|
25
|
+
/** Async data loader */
|
|
26
|
+
loader?: (params: DataLoaderParams) => Promise<DataLoaderResult<T>>
|
|
27
|
+
/** Debounce delay for async operations */
|
|
28
|
+
debounce?: number
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface DataLoaderParams {
|
|
32
|
+
page: number
|
|
33
|
+
pageSize: number
|
|
34
|
+
sort: SortState
|
|
35
|
+
filters?: Record<string, unknown>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface DataLoaderResult<T> {
|
|
39
|
+
data: T[]
|
|
40
|
+
total: number
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface UseDataTableReturn<T> {
|
|
44
|
+
// Data
|
|
45
|
+
data: Ref<T[]>
|
|
46
|
+
processedData: ComputedRef<T[]>
|
|
47
|
+
paginatedData: ComputedRef<T[]>
|
|
48
|
+
|
|
49
|
+
// Columns
|
|
50
|
+
columns: Ref<TableColumn<T>[]>
|
|
51
|
+
visibleColumns: ComputedRef<TableColumn<T>[]>
|
|
52
|
+
|
|
53
|
+
// Sort
|
|
54
|
+
sortState: Ref<SortState>
|
|
55
|
+
toggleSort: (columnKey: string) => void
|
|
56
|
+
setSort: (columnKey: string, direction: SortDirection) => void
|
|
57
|
+
clearSort: () => void
|
|
58
|
+
|
|
59
|
+
// Selection
|
|
60
|
+
selectedKeys: Ref<Set<string | number>>
|
|
61
|
+
selectedRows: ComputedRef<T[]>
|
|
62
|
+
toggleRowSelection: (key: string | number) => void
|
|
63
|
+
selectRow: (key: string | number) => void
|
|
64
|
+
deselectRow: (key: string | number) => void
|
|
65
|
+
selectAll: () => void
|
|
66
|
+
deselectAll: () => void
|
|
67
|
+
toggleAllSelection: () => void
|
|
68
|
+
isRowSelected: (key: string | number) => boolean
|
|
69
|
+
isAllSelected: ComputedRef<boolean>
|
|
70
|
+
isSomeSelected: ComputedRef<boolean>
|
|
71
|
+
|
|
72
|
+
// Expansion
|
|
73
|
+
expandedKeys: Ref<Set<string | number>>
|
|
74
|
+
toggleRowExpansion: (key: string | number) => void
|
|
75
|
+
expandRow: (key: string | number) => void
|
|
76
|
+
collapseRow: (key: string | number) => void
|
|
77
|
+
expandAll: () => void
|
|
78
|
+
collapseAll: () => void
|
|
79
|
+
isRowExpanded: (key: string | number) => boolean
|
|
80
|
+
|
|
81
|
+
// Pagination
|
|
82
|
+
pagination: Ref<PaginationState>
|
|
83
|
+
totalPages: ComputedRef<number>
|
|
84
|
+
goToPage: (page: number) => void
|
|
85
|
+
nextPage: () => void
|
|
86
|
+
prevPage: () => void
|
|
87
|
+
setPageSize: (size: number) => void
|
|
88
|
+
|
|
89
|
+
// Column visibility
|
|
90
|
+
showColumn: (key: string) => void
|
|
91
|
+
hideColumn: (key: string) => void
|
|
92
|
+
toggleColumn: (key: string) => void
|
|
93
|
+
setColumnVisibility: (key: string, visible: boolean) => void
|
|
94
|
+
|
|
95
|
+
// Loading
|
|
96
|
+
loading: Ref<boolean>
|
|
97
|
+
error: Ref<Error | null>
|
|
98
|
+
|
|
99
|
+
// Utilities
|
|
100
|
+
getRowKey: (row: T, index: number) => string | number
|
|
101
|
+
refresh: () => Promise<void>
|
|
102
|
+
setData: (newData: T[]) => void
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ============================================================================
|
|
106
|
+
// Composable
|
|
107
|
+
// ============================================================================
|
|
108
|
+
|
|
109
|
+
export function useDataTable<T extends Record<string, unknown>>(
|
|
110
|
+
options: UseDataTableOptions<T> = {}
|
|
111
|
+
): UseDataTableReturn<T> {
|
|
112
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
113
|
+
// Initialize refs
|
|
114
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
115
|
+
|
|
116
|
+
const rawData = shallowRef<T[]>(
|
|
117
|
+
Array.isArray(options.data) ? options.data : (options.data?.value ?? [])
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
const columns = ref<TableColumn<T>[]>(
|
|
121
|
+
Array.isArray(options.columns) ? options.columns : (options.columns?.value ?? [])
|
|
122
|
+
) as Ref<TableColumn<T>[]>
|
|
123
|
+
|
|
124
|
+
const loading = ref(false)
|
|
125
|
+
const error = ref<Error | null>(null)
|
|
126
|
+
|
|
127
|
+
// Sort state
|
|
128
|
+
const sortState = ref<SortState>(
|
|
129
|
+
options.initialSort ?? { column: null, direction: null }
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
// Selection state
|
|
133
|
+
const selectedKeys = ref<Set<string | number>>(new Set())
|
|
134
|
+
|
|
135
|
+
// Expansion state
|
|
136
|
+
const expandedKeys = ref<Set<string | number>>(new Set())
|
|
137
|
+
|
|
138
|
+
// Pagination state
|
|
139
|
+
const pagination = ref<PaginationState>({
|
|
140
|
+
page: 1,
|
|
141
|
+
pageSize: typeof options.pagination === 'object' ? (options.pagination.pageSize ?? 10) : 10,
|
|
142
|
+
total: 0
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
146
|
+
// Row key extraction
|
|
147
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
148
|
+
|
|
149
|
+
const getRowKey = (row: T, index: number): string | number => {
|
|
150
|
+
if (!options.rowKey) {
|
|
151
|
+
// Try common key fields
|
|
152
|
+
if ('id' in row) return row.id as string | number
|
|
153
|
+
if ('key' in row) return row.key as string | number
|
|
154
|
+
if ('_id' in row) return row._id as string | number
|
|
155
|
+
return index
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (typeof options.rowKey === 'function') {
|
|
159
|
+
return options.rowKey(row, index)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return row[options.rowKey] as string | number
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
166
|
+
// Visible columns
|
|
167
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
168
|
+
|
|
169
|
+
const visibleColumns = computed(() => {
|
|
170
|
+
return columns.value.filter(col => col.visible !== false)
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
174
|
+
// Sorting
|
|
175
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
176
|
+
|
|
177
|
+
const toggleSort = (columnKey: string) => {
|
|
178
|
+
const column = columns.value.find(c => c.key === columnKey)
|
|
179
|
+
if (!column?.sortable) return
|
|
180
|
+
|
|
181
|
+
if (sortState.value.column !== columnKey) {
|
|
182
|
+
sortState.value = { column: columnKey, direction: 'asc' }
|
|
183
|
+
} else if (sortState.value.direction === 'asc') {
|
|
184
|
+
sortState.value = { column: columnKey, direction: 'desc' }
|
|
185
|
+
} else {
|
|
186
|
+
sortState.value = { column: null, direction: null }
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const setSort = (columnKey: string, direction: SortDirection) => {
|
|
191
|
+
sortState.value = { column: columnKey, direction }
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const clearSort = () => {
|
|
195
|
+
sortState.value = { column: null, direction: null }
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
199
|
+
// Processed data (sorted)
|
|
200
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
201
|
+
|
|
202
|
+
const processedData = computed(() => {
|
|
203
|
+
let result = [...rawData.value]
|
|
204
|
+
|
|
205
|
+
// Apply sorting
|
|
206
|
+
if (sortState.value.column && sortState.value.direction) {
|
|
207
|
+
const column = columns.value.find(c => c.key === sortState.value.column)
|
|
208
|
+
if (column) {
|
|
209
|
+
result = [...result].sort((a, b) => {
|
|
210
|
+
if (column.sortFn) {
|
|
211
|
+
return column.sortFn(a, b, sortState.value.direction)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Default sort
|
|
215
|
+
const aVal = getCellValue(a, column)
|
|
216
|
+
const bVal = getCellValue(b, column)
|
|
217
|
+
|
|
218
|
+
let comparison = 0
|
|
219
|
+
if (aVal === bVal) {
|
|
220
|
+
comparison = 0
|
|
221
|
+
} else if (aVal === null || aVal === undefined) {
|
|
222
|
+
comparison = 1
|
|
223
|
+
} else if (bVal === null || bVal === undefined) {
|
|
224
|
+
comparison = -1
|
|
225
|
+
} else if (typeof aVal === 'string' && typeof bVal === 'string') {
|
|
226
|
+
comparison = aVal.localeCompare(bVal)
|
|
227
|
+
} else {
|
|
228
|
+
comparison = aVal < bVal ? -1 : 1
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return sortState.value.direction === 'desc' ? -comparison : comparison
|
|
232
|
+
})
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return result
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
240
|
+
// Pagination
|
|
241
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
242
|
+
|
|
243
|
+
const totalPages = computed(() => {
|
|
244
|
+
const total = pagination.value.total || processedData.value.length
|
|
245
|
+
return Math.ceil(total / pagination.value.pageSize) || 1
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
const paginatedData = computed(() => {
|
|
249
|
+
if (!options.pagination) return processedData.value
|
|
250
|
+
|
|
251
|
+
const start = (pagination.value.page - 1) * pagination.value.pageSize
|
|
252
|
+
const end = start + pagination.value.pageSize
|
|
253
|
+
return processedData.value.slice(start, end)
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
const goToPage = (page: number) => {
|
|
257
|
+
pagination.value.page = Math.max(1, Math.min(page, totalPages.value))
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const nextPage = () => goToPage(pagination.value.page + 1)
|
|
261
|
+
const prevPage = () => goToPage(pagination.value.page - 1)
|
|
262
|
+
|
|
263
|
+
const setPageSize = (size: number) => {
|
|
264
|
+
pagination.value.pageSize = size
|
|
265
|
+
pagination.value.page = 1
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
269
|
+
// Selection
|
|
270
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
271
|
+
|
|
272
|
+
const toggleRowSelection = (key: string | number) => {
|
|
273
|
+
const newSet = new Set(selectedKeys.value)
|
|
274
|
+
if (newSet.has(key)) {
|
|
275
|
+
newSet.delete(key)
|
|
276
|
+
} else {
|
|
277
|
+
if (!options.multiSelect) {
|
|
278
|
+
newSet.clear()
|
|
279
|
+
}
|
|
280
|
+
newSet.add(key)
|
|
281
|
+
}
|
|
282
|
+
selectedKeys.value = newSet
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const selectRow = (key: string | number) => {
|
|
286
|
+
const newSet = new Set(selectedKeys.value)
|
|
287
|
+
if (!options.multiSelect) {
|
|
288
|
+
newSet.clear()
|
|
289
|
+
}
|
|
290
|
+
newSet.add(key)
|
|
291
|
+
selectedKeys.value = newSet
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const deselectRow = (key: string | number) => {
|
|
295
|
+
const newSet = new Set(selectedKeys.value)
|
|
296
|
+
newSet.delete(key)
|
|
297
|
+
selectedKeys.value = newSet
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const selectAll = () => {
|
|
301
|
+
if (!options.multiSelect) return
|
|
302
|
+
const keys = processedData.value.map((row, i) => getRowKey(row, i))
|
|
303
|
+
selectedKeys.value = new Set(keys)
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const deselectAll = () => {
|
|
307
|
+
selectedKeys.value = new Set()
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const toggleAllSelection = () => {
|
|
311
|
+
if (isAllSelected.value) {
|
|
312
|
+
deselectAll()
|
|
313
|
+
} else {
|
|
314
|
+
selectAll()
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const isRowSelected = (key: string | number) => selectedKeys.value.has(key)
|
|
319
|
+
|
|
320
|
+
const isAllSelected = computed(() => {
|
|
321
|
+
if (processedData.value.length === 0) return false
|
|
322
|
+
return processedData.value.every((row, i) =>
|
|
323
|
+
selectedKeys.value.has(getRowKey(row, i))
|
|
324
|
+
)
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
const isSomeSelected = computed(() => {
|
|
328
|
+
return selectedKeys.value.size > 0 && !isAllSelected.value
|
|
329
|
+
})
|
|
330
|
+
|
|
331
|
+
const selectedRows = computed(() => {
|
|
332
|
+
return processedData.value.filter((row, i) =>
|
|
333
|
+
selectedKeys.value.has(getRowKey(row, i))
|
|
334
|
+
)
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
338
|
+
// Expansion
|
|
339
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
340
|
+
|
|
341
|
+
const toggleRowExpansion = (key: string | number) => {
|
|
342
|
+
const newSet = new Set(expandedKeys.value)
|
|
343
|
+
if (newSet.has(key)) {
|
|
344
|
+
newSet.delete(key)
|
|
345
|
+
} else {
|
|
346
|
+
newSet.add(key)
|
|
347
|
+
}
|
|
348
|
+
expandedKeys.value = newSet
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const expandRow = (key: string | number) => {
|
|
352
|
+
const newSet = new Set(expandedKeys.value)
|
|
353
|
+
newSet.add(key)
|
|
354
|
+
expandedKeys.value = newSet
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const collapseRow = (key: string | number) => {
|
|
358
|
+
const newSet = new Set(expandedKeys.value)
|
|
359
|
+
newSet.delete(key)
|
|
360
|
+
expandedKeys.value = newSet
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const expandAll = () => {
|
|
364
|
+
const keys = processedData.value.map((row, i) => getRowKey(row, i))
|
|
365
|
+
expandedKeys.value = new Set(keys)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const collapseAll = () => {
|
|
369
|
+
expandedKeys.value = new Set()
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const isRowExpanded = (key: string | number) => expandedKeys.value.has(key)
|
|
373
|
+
|
|
374
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
375
|
+
// Column visibility
|
|
376
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
377
|
+
|
|
378
|
+
const setColumnVisibility = (key: string, visible: boolean) => {
|
|
379
|
+
const idx = columns.value.findIndex(c => c.key === key)
|
|
380
|
+
if (idx !== -1) {
|
|
381
|
+
columns.value[idx] = { ...columns.value[idx], visible }
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const showColumn = (key: string) => setColumnVisibility(key, true)
|
|
386
|
+
const hideColumn = (key: string) => setColumnVisibility(key, false)
|
|
387
|
+
const toggleColumn = (key: string) => {
|
|
388
|
+
const col = columns.value.find(c => c.key === key)
|
|
389
|
+
if (col) setColumnVisibility(key, col.visible === false)
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
393
|
+
// Async loading
|
|
394
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
395
|
+
|
|
396
|
+
const refresh = async () => {
|
|
397
|
+
if (!options.loader) return
|
|
398
|
+
|
|
399
|
+
loading.value = true
|
|
400
|
+
error.value = null
|
|
401
|
+
|
|
402
|
+
try {
|
|
403
|
+
const result = await options.loader({
|
|
404
|
+
page: pagination.value.page,
|
|
405
|
+
pageSize: pagination.value.pageSize,
|
|
406
|
+
sort: sortState.value
|
|
407
|
+
})
|
|
408
|
+
|
|
409
|
+
rawData.value = result.data
|
|
410
|
+
pagination.value.total = result.total
|
|
411
|
+
} catch (e) {
|
|
412
|
+
error.value = e instanceof Error ? e : new Error(String(e))
|
|
413
|
+
} finally {
|
|
414
|
+
loading.value = false
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const setData = (newData: T[]) => {
|
|
419
|
+
rawData.value = newData
|
|
420
|
+
pagination.value.total = newData.length
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// Watch for external data changes
|
|
424
|
+
if (options.data && !Array.isArray(options.data)) {
|
|
425
|
+
watch(options.data, (newData) => {
|
|
426
|
+
rawData.value = newData
|
|
427
|
+
pagination.value.total = newData.length
|
|
428
|
+
}, { deep: true })
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// Watch for column changes
|
|
432
|
+
if (options.columns && !Array.isArray(options.columns)) {
|
|
433
|
+
watch(options.columns, (newCols) => {
|
|
434
|
+
columns.value = newCols
|
|
435
|
+
}, { deep: true })
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
439
|
+
// Utilities
|
|
440
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
441
|
+
|
|
442
|
+
function getCellValue<T>(row: T, column: TableColumn<T>): unknown {
|
|
443
|
+
if (typeof column.accessor === 'function') {
|
|
444
|
+
return column.accessor(row, 0)
|
|
445
|
+
}
|
|
446
|
+
if (column.accessor) {
|
|
447
|
+
return (row as Record<string, unknown>)[column.accessor as string]
|
|
448
|
+
}
|
|
449
|
+
return (row as Record<string, unknown>)[column.key]
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
453
|
+
// Return
|
|
454
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
455
|
+
|
|
456
|
+
return {
|
|
457
|
+
// Data
|
|
458
|
+
data: rawData as Ref<T[]>,
|
|
459
|
+
processedData,
|
|
460
|
+
paginatedData,
|
|
461
|
+
|
|
462
|
+
// Columns
|
|
463
|
+
columns,
|
|
464
|
+
visibleColumns,
|
|
465
|
+
|
|
466
|
+
// Sort
|
|
467
|
+
sortState,
|
|
468
|
+
toggleSort,
|
|
469
|
+
setSort,
|
|
470
|
+
clearSort,
|
|
471
|
+
|
|
472
|
+
// Selection
|
|
473
|
+
selectedKeys,
|
|
474
|
+
selectedRows,
|
|
475
|
+
toggleRowSelection,
|
|
476
|
+
selectRow,
|
|
477
|
+
deselectRow,
|
|
478
|
+
selectAll,
|
|
479
|
+
deselectAll,
|
|
480
|
+
toggleAllSelection,
|
|
481
|
+
isRowSelected,
|
|
482
|
+
isAllSelected,
|
|
483
|
+
isSomeSelected,
|
|
484
|
+
|
|
485
|
+
// Expansion
|
|
486
|
+
expandedKeys,
|
|
487
|
+
toggleRowExpansion,
|
|
488
|
+
expandRow,
|
|
489
|
+
collapseRow,
|
|
490
|
+
expandAll,
|
|
491
|
+
collapseAll,
|
|
492
|
+
isRowExpanded,
|
|
493
|
+
|
|
494
|
+
// Pagination
|
|
495
|
+
pagination,
|
|
496
|
+
totalPages,
|
|
497
|
+
goToPage,
|
|
498
|
+
nextPage,
|
|
499
|
+
prevPage,
|
|
500
|
+
setPageSize,
|
|
501
|
+
|
|
502
|
+
// Column visibility
|
|
503
|
+
showColumn,
|
|
504
|
+
hideColumn,
|
|
505
|
+
toggleColumn,
|
|
506
|
+
setColumnVisibility,
|
|
507
|
+
|
|
508
|
+
// Loading
|
|
509
|
+
loading,
|
|
510
|
+
error,
|
|
511
|
+
|
|
512
|
+
// Utilities
|
|
513
|
+
getRowKey,
|
|
514
|
+
refresh,
|
|
515
|
+
setData
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
export default useDataTable
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* STabPane - Tab Panel Component
|
|
4
|
+
* Used as a child of STabs to define tab content
|
|
5
|
+
*/
|
|
6
|
+
defineOptions({ inheritAttrs: false })
|
|
7
|
+
|
|
8
|
+
import { inject, onMounted, onUnmounted, computed, watch } from 'vue'
|
|
9
|
+
import { cn } from '../../../lib/utils'
|
|
10
|
+
import { STabsContextKey, type TabPaneInfo } from './STabs.vue'
|
|
11
|
+
|
|
12
|
+
// Props
|
|
13
|
+
interface Props {
|
|
14
|
+
/** Unique tab identifier (required) */
|
|
15
|
+
name: string | number
|
|
16
|
+
/** Tab label text (required) */
|
|
17
|
+
tab: string
|
|
18
|
+
/** Optional MDI icon name (without mdi- prefix) */
|
|
19
|
+
icon?: string
|
|
20
|
+
/** Disable this tab */
|
|
21
|
+
disabled?: boolean
|
|
22
|
+
/** Override parent closable setting */
|
|
23
|
+
closable?: boolean
|
|
24
|
+
/** Additional classes for this tab button */
|
|
25
|
+
tabClass?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const props = defineProps<Props>()
|
|
29
|
+
|
|
30
|
+
// Inject parent context
|
|
31
|
+
const context = inject(STabsContextKey)
|
|
32
|
+
|
|
33
|
+
if (!context) {
|
|
34
|
+
console.warn('[STabPane] Must be used inside an STabs component')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Computed visibility
|
|
38
|
+
const isActive = computed(() => context?.activeTab.value === props.name)
|
|
39
|
+
|
|
40
|
+
// Register this pane with parent
|
|
41
|
+
const paneInfo = computed<TabPaneInfo>(() => ({
|
|
42
|
+
name: props.name,
|
|
43
|
+
tab: props.tab,
|
|
44
|
+
icon: props.icon,
|
|
45
|
+
disabled: props.disabled,
|
|
46
|
+
closable: props.closable,
|
|
47
|
+
tabClass: props.tabClass
|
|
48
|
+
}))
|
|
49
|
+
|
|
50
|
+
onMounted(() => {
|
|
51
|
+
context?.registerPane(paneInfo.value)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
// Watch for prop changes to update registration
|
|
55
|
+
watch(paneInfo, (newInfo) => {
|
|
56
|
+
context?.unregisterPane(props.name)
|
|
57
|
+
context?.registerPane(newInfo)
|
|
58
|
+
}, { deep: true })
|
|
59
|
+
|
|
60
|
+
onUnmounted(() => {
|
|
61
|
+
context?.unregisterPane(props.name)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
// Animation state - always use smooth base, morph adds blur
|
|
65
|
+
const shouldMorph = computed(() => context?.animated ?? false)
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<template>
|
|
69
|
+
<Transition
|
|
70
|
+
:name="shouldMorph ? 's-tab-morph' : 's-tab-fade'"
|
|
71
|
+
mode="out-in"
|
|
72
|
+
>
|
|
73
|
+
<div v-if="isActive" :key="name" v-bind="$attrs" :class="cn('s-tab-pane', $attrs.class ?? '')">
|
|
74
|
+
<slot />
|
|
75
|
+
</div>
|
|
76
|
+
</Transition>
|
|
77
|
+
</template>
|
|
78
|
+
|
|
79
|
+
<style scoped>
|
|
80
|
+
.s-tab-pane {
|
|
81
|
+
width: 100%;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* Base smooth fade transition (default) */
|
|
85
|
+
.s-tab-fade-enter-active {
|
|
86
|
+
transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.s-tab-fade-leave-active {
|
|
90
|
+
transition: opacity 0.12s cubic-bezier(0.4, 0, 0.2, 1);
|
|
91
|
+
position: absolute;
|
|
92
|
+
left: 0;
|
|
93
|
+
right: 0;
|
|
94
|
+
top: 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.s-tab-fade-enter-from,
|
|
98
|
+
.s-tab-fade-leave-to {
|
|
99
|
+
opacity: 0;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* Enhanced morphing transition with blur + scale */
|
|
103
|
+
.s-tab-morph-enter-active {
|
|
104
|
+
transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1),
|
|
105
|
+
transform 0.35s cubic-bezier(0.16, 1, 0.3, 1),
|
|
106
|
+
filter 0.35s cubic-bezier(0.16, 1, 0.3, 1);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.s-tab-morph-leave-active {
|
|
110
|
+
transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1),
|
|
111
|
+
transform 0.2s cubic-bezier(0.16, 1, 0.3, 1),
|
|
112
|
+
filter 0.2s cubic-bezier(0.16, 1, 0.3, 1);
|
|
113
|
+
position: absolute;
|
|
114
|
+
left: 0;
|
|
115
|
+
right: 0;
|
|
116
|
+
top: 0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.s-tab-morph-enter-from {
|
|
120
|
+
opacity: 0;
|
|
121
|
+
transform: translateY(10px) scale(0.98);
|
|
122
|
+
filter: blur(6px);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.s-tab-morph-leave-to {
|
|
126
|
+
opacity: 0;
|
|
127
|
+
transform: translateY(-6px) scale(0.98);
|
|
128
|
+
filter: blur(6px);
|
|
129
|
+
}
|
|
130
|
+
</style>
|