@liorian/sdk 0.28.0-alpha.56010ca
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 +483 -0
- package/package.json +94 -0
- package/schemas/module.schema.json +818 -0
- package/src/application/index.ts +3 -0
- package/src/application/module-instance.ts +36 -0
- package/src/application/service/auth-api-service.ts +291 -0
- package/src/application/service/auth-user.service.ts +108 -0
- package/src/application/service/index.ts +12 -0
- package/src/application/service/module-activation-api.service.ts +105 -0
- package/src/application/service/notifications-api-service.ts +38 -0
- package/src/application/service/notifications-push.service.ts +299 -0
- package/src/application/service/notifications-socket-service.ts +76 -0
- package/src/application/service/organizations-api-service.ts +104 -0
- package/src/application/service/otp-api-service.ts +11 -0
- package/src/application/service/storage-api-service.ts +77 -0
- package/src/application/service/storefront-api.service.ts +72 -0
- package/src/application/service/user-preferences-api.service.ts +57 -0
- package/src/domain/config/app.config.ts +35 -0
- package/src/domain/config/auth.config.ts +30 -0
- package/src/domain/config/index.ts +4 -0
- package/src/domain/config/logo.config.ts +17 -0
- package/src/domain/entities/activities.interface.ts +18 -0
- package/src/domain/entities/catalog.interface.ts +96 -0
- package/src/domain/entities/index.ts +13 -0
- package/src/domain/entities/media.ts +22 -0
- package/src/domain/entities/module-activation.interface.ts +173 -0
- package/src/domain/entities/module.interface.ts +101 -0
- package/src/domain/entities/notification.interface.ts +23 -0
- package/src/domain/entities/objectable.type.ts +3 -0
- package/src/domain/entities/organization.interface.ts +81 -0
- package/src/domain/entities/user-auth.interface.ts +17 -0
- package/src/domain/entities/user-phone.interface.ts +11 -0
- package/src/domain/entities/user-profile.interface.ts +23 -0
- package/src/domain/entities/user.interface.ts +79 -0
- package/src/domain/enums/coloring.enum.ts +6 -0
- package/src/domain/enums/domains.enum.ts +282 -0
- package/src/domain/enums/index.ts +8 -0
- package/src/domain/enums/module-category.enum.ts +57 -0
- package/src/domain/enums/module.enum.ts +97 -0
- package/src/domain/enums/routine.enum.ts +12 -0
- package/src/domain/enums/user-profile.enum.ts +25 -0
- package/src/domain/enums/user-status.enum.ts +7 -0
- package/src/domain/index.ts +6 -0
- package/src/domain/typing/auth-caches.ts +12 -0
- package/src/domain/typing/auth-oauth.types.ts +172 -0
- package/src/domain/typing/devise.ts +2 -0
- package/src/domain/typing/index.ts +10 -0
- package/src/domain/typing/response.ts +30 -0
- package/src/domain/typing/routine.types.ts +113 -0
- package/src/domain/typing/session.interface.ts +28 -0
- package/src/domain/typing/statisticals.ts +11 -0
- package/src/domain/typing/user-media-upload.ts +9 -0
- package/src/domain/typing/values.ts +6 -0
- package/src/index.tsx +168 -0
- package/src/infrastructure/capabilities/cache-storage/capability.ts +129 -0
- package/src/infrastructure/capabilities/cache-storage/enum.ts +5 -0
- package/src/infrastructure/capabilities/cache-storage/index.ts +4 -0
- package/src/infrastructure/capabilities/cache-storage/types.ts +13 -0
- package/src/infrastructure/capabilities/index.ts +3 -0
- package/src/infrastructure/capabilities/stackable/capability.ts +55 -0
- package/src/infrastructure/capabilities/stackable/index.ts +3 -0
- package/src/infrastructure/capabilities/stackable/types.ts +24 -0
- package/src/infrastructure/common-classname.constant.ts +4 -0
- package/src/infrastructure/data/countries.ts +208 -0
- package/src/infrastructure/data/gender.ts +5 -0
- package/src/infrastructure/data/index.ts +3 -0
- package/src/infrastructure/dataset/index.ts +3 -0
- package/src/infrastructure/dataset/sign-in.dataset.ts +21 -0
- package/src/infrastructure/dataset/sign-up.dataset.ts +64 -0
- package/src/infrastructure/hooks/index.ts +10 -0
- package/src/infrastructure/hooks/use-activity-lock-draft.ts +69 -0
- package/src/infrastructure/hooks/use-auth.ts +24 -0
- package/src/infrastructure/hooks/use-elastic-interaction.ts +180 -0
- package/src/infrastructure/hooks/use-is-desktop.ts +25 -0
- package/src/infrastructure/hooks/use-is-tauri.ts +17 -0
- package/src/infrastructure/hooks/use-mobile.ts +19 -0
- package/src/infrastructure/hooks/use-notifications.ts +128 -0
- package/src/infrastructure/hooks/use-recent-colors.ts +113 -0
- package/src/infrastructure/hooks/use-recent-modules.ts +76 -0
- package/src/infrastructure/index.tsx +11 -0
- package/src/infrastructure/library/design-system.ts +95 -0
- package/src/infrastructure/library/index.tsx +5 -0
- package/src/infrastructure/library/motion-utils.ts +77 -0
- package/src/infrastructure/library/motion.tsx +31 -0
- package/src/infrastructure/library/scroll-progress.tsx +93 -0
- package/src/infrastructure/providers/auth-guard.provider.tsx +47 -0
- package/src/infrastructure/providers/auth.provider.tsx +168 -0
- package/src/infrastructure/providers/index.tsx +8 -0
- package/src/infrastructure/providers/module-usage.provider.tsx +95 -0
- package/src/infrastructure/providers/modules-guard.provider.tsx +64 -0
- package/src/infrastructure/providers/modules-routines.provider.tsx +33 -0
- package/src/infrastructure/providers/modules-switcher.provider.tsx +25 -0
- package/src/infrastructure/providers/query.provider.tsx +27 -0
- package/src/infrastructure/routines/__tests__/routine.test.ts +368 -0
- package/src/infrastructure/routines/index.tsx +3 -0
- package/src/infrastructure/routines/routine.hook.ts +121 -0
- package/src/infrastructure/routines/routine.ts +283 -0
- package/src/infrastructure/routines/routine.tsx +283 -0
- package/src/infrastructure/stores/activity-lock.store.ts +22 -0
- package/src/infrastructure/stores/auth-user-connected.store.ts +24 -0
- package/src/infrastructure/stores/dataset.store.ts +106 -0
- package/src/infrastructure/stores/index.ts +6 -0
- package/src/infrastructure/stores/module.store.ts +266 -0
- package/src/infrastructure/stores/upload.store.ts +198 -0
- package/src/infrastructure/utilities/access-label.util.ts +158 -0
- package/src/infrastructure/utilities/activities.util.tsx +54 -0
- package/src/infrastructure/utilities/activity-lock.service.ts +263 -0
- package/src/infrastructure/utilities/activity-tracker.service.ts +205 -0
- package/src/infrastructure/utilities/api-service.ts +237 -0
- package/src/infrastructure/utilities/auth-logout.util.ts +23 -0
- package/src/infrastructure/utilities/classname.util.ts +7 -0
- package/src/infrastructure/utilities/encryption.service.ts +125 -0
- package/src/infrastructure/utilities/form-snapshot.service.ts +304 -0
- package/src/infrastructure/utilities/format.util.ts +40 -0
- package/src/infrastructure/utilities/index.tsx +23 -0
- package/src/infrastructure/utilities/media-label.service.ts +47 -0
- package/src/infrastructure/utilities/modules.ts +11 -0
- package/src/infrastructure/utilities/permission.util.ts +22 -0
- package/src/infrastructure/utilities/push-permission.util.ts +43 -0
- package/src/infrastructure/utilities/route-access.ts +38 -0
- package/src/infrastructure/utilities/socket-service.ts +123 -0
- package/src/infrastructure/utilities/sso-auth.util.ts +188 -0
- package/src/infrastructure/utilities/stringable.util.ts +16 -0
- package/src/infrastructure/utilities/strings.util.ts +18 -0
- package/src/infrastructure/utilities/tauri.util.ts +15 -0
- package/src/infrastructure/utilities/utils.ts +6 -0
- package/src/infrastructure/utilities/values.ts +5 -0
- package/src/presentation/8starlabs-ui/button.tsx +94 -0
- package/src/presentation/8starlabs-ui/flip-clock.tsx +368 -0
- package/src/presentation/8starlabs-ui/heatmap.tsx +430 -0
- package/src/presentation/8starlabs-ui/hooks/index.tsx +2 -0
- package/src/presentation/8starlabs-ui/hooks/use-mobile.ts +21 -0
- package/src/presentation/8starlabs-ui/index.tsx +20 -0
- package/src/presentation/8starlabs-ui/json-viewer.tsx +972 -0
- package/src/presentation/8starlabs-ui/marquee.tsx +134 -0
- package/src/presentation/8starlabs-ui/partition-bar.tsx +198 -0
- package/src/presentation/8starlabs-ui/scroll-fade.tsx +158 -0
- package/src/presentation/8starlabs-ui/status-indicator.tsx +86 -0
- package/src/presentation/8starlabs-ui/system-banner.tsx +50 -0
- package/src/presentation/8starlabs-ui/timeline.tsx +576 -0
- package/src/presentation/8starlabs-ui/transport-badge.tsx +249 -0
- package/src/presentation/8starlabs-ui/ui/copy-button.tsx +60 -0
- package/src/presentation/8starlabs-ui/ui/index.tsx +2 -0
- package/src/presentation/analytics-section.tsx +85 -0
- package/src/presentation/app-sidebar.tsx +234 -0
- package/src/presentation/charts/area-widget.chart-skeleton.tsx +61 -0
- package/src/presentation/charts/area-widget.chart.tsx +128 -0
- package/src/presentation/charts/chart-widgets.types.ts +81 -0
- package/src/presentation/charts/index.tsx +16 -0
- package/src/presentation/charts/line-widget.chart-skeleton.tsx +64 -0
- package/src/presentation/charts/line-widget.chart.tsx +105 -0
- package/src/presentation/charts/pie-widget.chart-skeleton.tsx +56 -0
- package/src/presentation/charts/pie-widget.chart.tsx +168 -0
- package/src/presentation/charts/radar-widget.chart-skeleton.tsx +67 -0
- package/src/presentation/charts/radar-widget.chart.tsx +80 -0
- package/src/presentation/charts/radial-stacked-widget.chart-skeleton.tsx +66 -0
- package/src/presentation/charts/radial-stacked-widget.chart.tsx +120 -0
- package/src/presentation/charts/radial-widget.chart-skeleton.tsx +61 -0
- package/src/presentation/charts/radial-widget.chart.tsx +87 -0
- package/src/presentation/charts/tooltip-widget.chart-skeleton.tsx +64 -0
- package/src/presentation/charts/tooltip-widget.chart.tsx +89 -0
- package/src/presentation/components/activity-actions.tsx +20 -0
- package/src/presentation/components/activity-container.tsx +55 -0
- package/src/presentation/components/activity-content.tsx +20 -0
- package/src/presentation/components/activity-descriptor-parser.tsx +37 -0
- package/src/presentation/components/activity-header.tsx +20 -0
- package/src/presentation/components/activity-loader.tsx +19 -0
- package/src/presentation/components/activity-title.tsx +32 -0
- package/src/presentation/components/activity.tsx +22 -0
- package/src/presentation/components/auth/index.tsx +4 -0
- package/src/presentation/components/auth/sso-callback.view.tsx +44 -0
- package/src/presentation/components/auth/sso-disconnect.view.tsx +41 -0
- package/src/presentation/components/auth/sso-sign-in.view.tsx +29 -0
- package/src/presentation/components/auth-lock-screen.tsx +309 -0
- package/src/presentation/components/auth-session.view.tsx +17 -0
- package/src/presentation/components/data-table.tsx +814 -0
- package/src/presentation/components/dynamic-icon.tsx +16 -0
- package/src/presentation/components/floating-upload.tsx +291 -0
- package/src/presentation/components/index.tsx +40 -0
- package/src/presentation/components/local-time.tsx +170 -0
- package/src/presentation/components/markdown-parser.tsx +201 -0
- package/src/presentation/components/message-scroller.tsx +131 -0
- package/src/presentation/components/module-first-access-config.view.tsx +181 -0
- package/src/presentation/components/module-first-access-pending.view.tsx +38 -0
- package/src/presentation/components/module-guard.tsx +34 -0
- package/src/presentation/components/modules-first-access.guard.tsx +88 -0
- package/src/presentation/components/modules-guard-forbidden.tsx +46 -0
- package/src/presentation/components/notification-details.modal.tsx +145 -0
- package/src/presentation/components/notification-item.tsx +127 -0
- package/src/presentation/components/notifications-popover.tsx +128 -0
- package/src/presentation/components/push-notifications.provider.tsx +65 -0
- package/src/presentation/components/upload-progress-dialog.tsx +140 -0
- package/src/presentation/components/waiting-bar.tsx +22 -0
- package/src/presentation/components/waiting-section.tsx +15 -0
- package/src/presentation/components/waiting.tsx +14 -0
- package/src/presentation/data-grid/data-grid-empty.tsx +24 -0
- package/src/presentation/data-grid/data-grid-search-engine.tsx +32 -0
- package/src/presentation/data-grid/data-grid.tsx +892 -0
- package/src/presentation/data-grid/index.tsx +4 -0
- package/src/presentation/form-screen.tsx +95 -0
- package/src/presentation/icons/custom.tsx +20 -0
- package/src/presentation/icons/glyphIcons.tsx +53 -0
- package/src/presentation/icons/icons.enum.ts +4 -0
- package/src/presentation/icons/icons.util.ts +6 -0
- package/src/presentation/icons/index.tsx +8 -0
- package/src/presentation/icons/lucide.tsx +17 -0
- package/src/presentation/icons/remix.tsx +33 -0
- package/src/presentation/icons/types.ts +27 -0
- package/src/presentation/index.tsx +45 -0
- package/src/presentation/modals/components/ModalBox.tsx +74 -0
- package/src/presentation/modals/components/ModalPortal.tsx +31 -0
- package/src/presentation/modals/components/ModalStepper.tsx +319 -0
- package/src/presentation/modals/components/ModalWrapper.tsx +65 -0
- package/src/presentation/modals/components/index.tsx +5 -0
- package/src/presentation/modals/hooks/index.ts +2 -0
- package/src/presentation/modals/hooks/useModal.ts +38 -0
- package/src/presentation/modals/index.tsx +5 -0
- package/src/presentation/modals/stores/index.ts +2 -0
- package/src/presentation/modals/stores/useModalStore.ts +90 -0
- package/src/presentation/modals/types/index.ts +2 -0
- package/src/presentation/modals/types/modal.type.ts +33 -0
- package/src/presentation/module-menubar.tsx +300 -0
- package/src/presentation/module-widget.tsx +233 -0
- package/src/presentation/nav-documents.tsx +89 -0
- package/src/presentation/nav-main.tsx +62 -0
- package/src/presentation/nav-secondary.tsx +41 -0
- package/src/presentation/nav-user.tsx +109 -0
- package/src/presentation/permission-action-badge.tsx +35 -0
- package/src/presentation/reui/index.tsx +3 -0
- package/src/presentation/reui/stepper.tsx +508 -0
- package/src/presentation/reui/timeline.tsx +226 -0
- package/src/presentation/sheets/index.tsx +2 -0
- package/src/presentation/sheets/legacy-sheet-header.tsx +0 -0
- package/src/presentation/sheets/legacy-sheet.tsx +37 -0
- package/src/presentation/size.enum.ts +19 -0
- package/src/presentation/system/index.tsx +3 -0
- package/src/presentation/system/logo.theme.tsx +21 -0
- package/src/presentation/system/types.ts +10 -0
- package/src/presentation/theme/index.tsx +6 -0
- package/src/presentation/theme/prefer-color-scheme.tsx +50 -0
- package/src/presentation/theme/switch-color-scheme.tsx +16 -0
- package/src/presentation/theme/theme-switcher-button.tsx +20 -0
- package/src/presentation/theme/theme.enum.ts +4 -0
- package/src/presentation/theme/theme.store.ts +87 -0
- package/src/presentation/themes/index.tsx +2 -0
- package/src/presentation/themes/katon/dashboard-layout.tsx +1080 -0
- package/src/presentation/themes/katon/edge-section.tsx +19 -0
- package/src/presentation/themes/katon/header-menubar.tsx +270 -0
- package/src/presentation/themes/katon/header-modules-available.tsx +44 -0
- package/src/presentation/themes/katon/header-modules-recents.tsx +52 -0
- package/src/presentation/themes/katon/header-modules-store.tsx +25 -0
- package/src/presentation/themes/katon/header-options.tsx +13 -0
- package/src/presentation/themes/katon/header-organization-select.tsx +146 -0
- package/src/presentation/themes/katon/header-routines.tsx +74 -0
- package/src/presentation/themes/katon/header-tasks-connected-user.tsx +150 -0
- package/src/presentation/themes/katon/index.tsx +16 -0
- package/src/presentation/themes/katon/main-wrapper.tsx +34 -0
- package/src/presentation/themes/katon/module-item-link.tsx +32 -0
- package/src/presentation/themes/katon/view-frame.tsx +25 -0
- package/src/presentation/themes/katon/view-helmet.tsx +53 -0
- package/src/presentation/themes/katon/view-status.tsx +32 -0
- package/src/presentation/themes/katon/view-wrapper.tsx +15 -0
- package/src/presentation/themes/katon/view.tsx +42 -0
- package/src/presentation/ui/accordion-multiselect.tsx +206 -0
- package/src/presentation/ui/accordion.tsx +81 -0
- package/src/presentation/ui/alert-dialog.tsx +199 -0
- package/src/presentation/ui/alert.tsx +76 -0
- package/src/presentation/ui/aspect-ratio.tsx +11 -0
- package/src/presentation/ui/attachment.tsx +204 -0
- package/src/presentation/ui/avatar.tsx +112 -0
- package/src/presentation/ui/badge.tsx +49 -0
- package/src/presentation/ui/breadcrumb.tsx +122 -0
- package/src/presentation/ui/bubble.tsx +125 -0
- package/src/presentation/ui/button-group.tsx +83 -0
- package/src/presentation/ui/button.tsx +87 -0
- package/src/presentation/ui/calendar.tsx +222 -0
- package/src/presentation/ui/card.tsx +106 -0
- package/src/presentation/ui/carousel.tsx +242 -0
- package/src/presentation/ui/chart.tsx +373 -0
- package/src/presentation/ui/checkbox.tsx +33 -0
- package/src/presentation/ui/clickable.tsx +58 -0
- package/src/presentation/ui/collapsible.tsx +33 -0
- package/src/presentation/ui/color-swatch-selector.tsx +81 -0
- package/src/presentation/ui/combobox.tsx +299 -0
- package/src/presentation/ui/command.tsx +195 -0
- package/src/presentation/ui/context-menu.tsx +263 -0
- package/src/presentation/ui/dialog.tsx +168 -0
- package/src/presentation/ui/direction.tsx +22 -0
- package/src/presentation/ui/drawer.tsx +134 -0
- package/src/presentation/ui/dropdown-menu.tsx +269 -0
- package/src/presentation/ui/empty.tsx +104 -0
- package/src/presentation/ui/field.tsx +238 -0
- package/src/presentation/ui/granularity-selector.tsx +58 -0
- package/src/presentation/ui/hover-card.tsx +44 -0
- package/src/presentation/ui/index.tsx +74 -0
- package/src/presentation/ui/input-group.tsx +156 -0
- package/src/presentation/ui/input-otp.tsx +87 -0
- package/src/presentation/ui/input.tsx +19 -0
- package/src/presentation/ui/item.tsx +196 -0
- package/src/presentation/ui/kpi-card.tsx +203 -0
- package/src/presentation/ui/label-selector.tsx +100 -0
- package/src/presentation/ui/label.tsx +24 -0
- package/src/presentation/ui/legacy-birth-date-input.tsx +43 -0
- package/src/presentation/ui/legacy-color-picker/index.tsx +42 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.content.tsx +37 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.context.tsx +42 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.hex-input.tsx +97 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.picker.tsx +266 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.presets.ts +22 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.quick-list.tsx +49 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.recent.tsx +43 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.swatches.tsx +111 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.trigger.tsx +128 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.tsx +110 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.types.ts +1 -0
- package/src/presentation/ui/legacy-color-picker/legacy-color-picker.utils.ts +114 -0
- package/src/presentation/ui/legacy-country-input.tsx +171 -0
- package/src/presentation/ui/legacy-gender-input.tsx +22 -0
- package/src/presentation/ui/legacy-input.tsx +106 -0
- package/src/presentation/ui/legacy-phone-input.tsx +213 -0
- package/src/presentation/ui/legacy-select-input.tsx +114 -0
- package/src/presentation/ui/legacy-text-area.tsx +111 -0
- package/src/presentation/ui/list-items.tsx +59 -0
- package/src/presentation/ui/marker.tsx +69 -0
- package/src/presentation/ui/media-player/index.tsx +12 -0
- package/src/presentation/ui/media-player/media-player.context.tsx +36 -0
- package/src/presentation/ui/media-player/media-player.tsx +167 -0
- package/src/presentation/ui/media-player/player-controls.tsx +207 -0
- package/src/presentation/ui/media-player/players/audio-player.tsx +78 -0
- package/src/presentation/ui/media-player/players/index.tsx +4 -0
- package/src/presentation/ui/media-player/players/video-player.tsx +193 -0
- package/src/presentation/ui/media-player/players/voice-note-player.tsx +108 -0
- package/src/presentation/ui/media-player/use-media-player.hook.ts +263 -0
- package/src/presentation/ui/menubar.tsx +281 -0
- package/src/presentation/ui/message.tsx +92 -0
- package/src/presentation/ui/navigation-menu.tsx +172 -0
- package/src/presentation/ui/pagination.tsx +129 -0
- package/src/presentation/ui/popover.tsx +89 -0
- package/src/presentation/ui/progress.tsx +31 -0
- package/src/presentation/ui/resizable.tsx +50 -0
- package/src/presentation/ui/select.tsx +192 -0
- package/src/presentation/ui/separator.tsx +28 -0
- package/src/presentation/ui/sheet.tsx +147 -0
- package/src/presentation/ui/sidebar.tsx +702 -0
- package/src/presentation/ui/skeleton.tsx +13 -0
- package/src/presentation/ui/slide-to-confirm.tsx +129 -0
- package/src/presentation/ui/slider.tsx +59 -0
- package/src/presentation/ui/sonner.tsx +58 -0
- package/src/presentation/ui/switch.tsx +33 -0
- package/src/presentation/ui/table.tsx +116 -0
- package/src/presentation/ui/tabs.tsx +90 -0
- package/src/presentation/ui/text-gradient.tsx +84 -0
- package/src/presentation/ui/textarea.tsx +18 -0
- package/src/presentation/ui/timeline-steps.tsx +235 -0
- package/src/presentation/ui/toggle-group.tsx +89 -0
- package/src/presentation/ui/toggle.tsx +47 -0
- package/src/presentation/ui/tooltip.tsx +57 -0
- package/src/presentation/uploading/index.tsx +3 -0
- package/src/presentation/uploading/media-upload-field.tsx +152 -0
- package/src/presentation/uploading/storage-media.tsx +210 -0
- package/src/styles.css +403 -0
- package/src/themes.css +1038 -0
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Children,
|
|
5
|
+
createContext,
|
|
6
|
+
HTMLAttributes,
|
|
7
|
+
isValidElement,
|
|
8
|
+
ReactElement,
|
|
9
|
+
useCallback,
|
|
10
|
+
useContext,
|
|
11
|
+
useEffect,
|
|
12
|
+
useMemo,
|
|
13
|
+
useRef,
|
|
14
|
+
useState,
|
|
15
|
+
} from "react"
|
|
16
|
+
|
|
17
|
+
import { cn } from "../../infrastructure/utilities/utils"
|
|
18
|
+
import { Motion } from "../../infrastructure/library/motion"
|
|
19
|
+
import { elasticEnter, elasticSlideInLeft, elasticSlideInRight } from "../../infrastructure/library/motion-utils"
|
|
20
|
+
|
|
21
|
+
// Types
|
|
22
|
+
type StepperOrientation = "horizontal" | "vertical"
|
|
23
|
+
type StepState = "active" | "completed" | "inactive" | "loading"
|
|
24
|
+
type StepperDirection = "forward" | "backward" | "none"
|
|
25
|
+
type StepIndicators = {
|
|
26
|
+
active?: React.ReactNode
|
|
27
|
+
completed?: React.ReactNode
|
|
28
|
+
inactive?: React.ReactNode
|
|
29
|
+
loading?: React.ReactNode
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface StepperContextValue {
|
|
33
|
+
activeStep: number
|
|
34
|
+
setActiveStep: (step: number) => void
|
|
35
|
+
stepsCount: number
|
|
36
|
+
orientation: StepperOrientation
|
|
37
|
+
direction: StepperDirection
|
|
38
|
+
registerTrigger: (node: HTMLButtonElement | null) => void
|
|
39
|
+
triggerNodes: HTMLButtonElement[]
|
|
40
|
+
focusNext: (currentIdx: number) => void
|
|
41
|
+
focusPrev: (currentIdx: number) => void
|
|
42
|
+
focusFirst: () => void
|
|
43
|
+
focusLast: () => void
|
|
44
|
+
indicators: StepIndicators
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface StepItemContextValue {
|
|
48
|
+
step: number
|
|
49
|
+
state: StepState
|
|
50
|
+
isDisabled: boolean
|
|
51
|
+
isLoading: boolean
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const StepperContext = createContext<StepperContextValue | undefined>(undefined)
|
|
55
|
+
const StepItemContext = createContext<StepItemContextValue | undefined>(
|
|
56
|
+
undefined
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
function useStepper() {
|
|
60
|
+
const ctx = useContext(StepperContext)
|
|
61
|
+
if (!ctx) throw new Error("useStepper must be used within a Stepper")
|
|
62
|
+
return ctx
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function useStepItem() {
|
|
66
|
+
const ctx = useContext(StepItemContext)
|
|
67
|
+
if (!ctx) throw new Error("useStepItem must be used within a StepperItem")
|
|
68
|
+
return ctx
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface StepperProps extends HTMLAttributes<HTMLDivElement> {
|
|
72
|
+
defaultValue?: number
|
|
73
|
+
value?: number
|
|
74
|
+
onValueChange?: (value: number) => void
|
|
75
|
+
orientation?: StepperOrientation
|
|
76
|
+
indicators?: StepIndicators
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function Stepper({
|
|
80
|
+
defaultValue = 1,
|
|
81
|
+
value,
|
|
82
|
+
onValueChange,
|
|
83
|
+
orientation = "horizontal",
|
|
84
|
+
className,
|
|
85
|
+
children,
|
|
86
|
+
indicators = {},
|
|
87
|
+
...props
|
|
88
|
+
}: StepperProps) {
|
|
89
|
+
const [activeStep, setActiveStep] = useState(defaultValue)
|
|
90
|
+
const [triggerNodes, setTriggerNodes] = useState<HTMLButtonElement[]>([])
|
|
91
|
+
const [direction, setDirection] = useState<StepperDirection>("none")
|
|
92
|
+
|
|
93
|
+
// Register/unregister triggers
|
|
94
|
+
const registerTrigger = useCallback((node: HTMLButtonElement | null) => {
|
|
95
|
+
setTriggerNodes((prev) => {
|
|
96
|
+
if (node && !prev.includes(node)) {
|
|
97
|
+
return [...prev, node]
|
|
98
|
+
} else if (!node && prev.includes(node!)) {
|
|
99
|
+
return prev.filter((n) => n !== node)
|
|
100
|
+
} else {
|
|
101
|
+
return prev
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
}, [])
|
|
105
|
+
|
|
106
|
+
const handleSetActiveStep = useCallback(
|
|
107
|
+
(step: number) => {
|
|
108
|
+
const prevStep = value ?? activeStep
|
|
109
|
+
setDirection(
|
|
110
|
+
step > prevStep ? "forward" : step < prevStep ? "backward" : "none"
|
|
111
|
+
)
|
|
112
|
+
if (value === undefined) {
|
|
113
|
+
setActiveStep(step)
|
|
114
|
+
}
|
|
115
|
+
onValueChange?.(step)
|
|
116
|
+
},
|
|
117
|
+
[value, activeStep, onValueChange]
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
const currentStep = value ?? activeStep
|
|
121
|
+
|
|
122
|
+
// Keyboard navigation logic
|
|
123
|
+
const focusTrigger = (idx: number) => {
|
|
124
|
+
if (triggerNodes[idx]) triggerNodes[idx].focus()
|
|
125
|
+
}
|
|
126
|
+
const focusNext = (currentIdx: number) =>
|
|
127
|
+
focusTrigger((currentIdx + 1) % triggerNodes.length)
|
|
128
|
+
const focusPrev = (currentIdx: number) =>
|
|
129
|
+
focusTrigger((currentIdx - 1 + triggerNodes.length) % triggerNodes.length)
|
|
130
|
+
const focusFirst = () => focusTrigger(0)
|
|
131
|
+
const focusLast = () => focusTrigger(triggerNodes.length - 1)
|
|
132
|
+
|
|
133
|
+
// Context value
|
|
134
|
+
const contextValue = useMemo<StepperContextValue>(
|
|
135
|
+
() => ({
|
|
136
|
+
activeStep: currentStep,
|
|
137
|
+
setActiveStep: handleSetActiveStep,
|
|
138
|
+
stepsCount: Children.toArray(children).filter(
|
|
139
|
+
(child): child is ReactElement =>
|
|
140
|
+
isValidElement(child) &&
|
|
141
|
+
(child.type as { displayName?: string }).displayName === "StepperItem"
|
|
142
|
+
).length,
|
|
143
|
+
orientation,
|
|
144
|
+
direction,
|
|
145
|
+
registerTrigger,
|
|
146
|
+
focusNext,
|
|
147
|
+
focusPrev,
|
|
148
|
+
focusFirst,
|
|
149
|
+
focusLast,
|
|
150
|
+
triggerNodes,
|
|
151
|
+
indicators,
|
|
152
|
+
}),
|
|
153
|
+
[
|
|
154
|
+
currentStep,
|
|
155
|
+
handleSetActiveStep,
|
|
156
|
+
children,
|
|
157
|
+
orientation,
|
|
158
|
+
direction,
|
|
159
|
+
registerTrigger,
|
|
160
|
+
triggerNodes,
|
|
161
|
+
]
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
return (
|
|
165
|
+
<StepperContext.Provider value={contextValue}>
|
|
166
|
+
<div
|
|
167
|
+
role="tablist"
|
|
168
|
+
aria-orientation={orientation}
|
|
169
|
+
data-slot="stepper"
|
|
170
|
+
className={cn("w-full", className)}
|
|
171
|
+
data-orientation={orientation}
|
|
172
|
+
{...props}
|
|
173
|
+
>
|
|
174
|
+
{children}
|
|
175
|
+
</div>
|
|
176
|
+
</StepperContext.Provider>
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
interface StepperItemProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
181
|
+
step: number
|
|
182
|
+
completed?: boolean
|
|
183
|
+
disabled?: boolean
|
|
184
|
+
loading?: boolean
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function StepperItem({
|
|
188
|
+
step,
|
|
189
|
+
completed = false,
|
|
190
|
+
disabled = false,
|
|
191
|
+
loading = false,
|
|
192
|
+
className,
|
|
193
|
+
children,
|
|
194
|
+
...props
|
|
195
|
+
}: StepperItemProps) {
|
|
196
|
+
const { activeStep } = useStepper()
|
|
197
|
+
|
|
198
|
+
const state: StepState =
|
|
199
|
+
completed || step < activeStep
|
|
200
|
+
? "completed"
|
|
201
|
+
: activeStep === step
|
|
202
|
+
? "active"
|
|
203
|
+
: "inactive"
|
|
204
|
+
|
|
205
|
+
const isLoading = loading && step === activeStep
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<StepItemContext.Provider
|
|
209
|
+
value={{ step, state, isDisabled: disabled, isLoading }}
|
|
210
|
+
>
|
|
211
|
+
<div
|
|
212
|
+
data-slot="stepper-item"
|
|
213
|
+
className={cn(
|
|
214
|
+
"group/step flex items-center justify-center not-last:flex-1 group-data-[orientation=horizontal]/stepper-nav:flex-row group-data-[orientation=vertical]/stepper-nav:flex-col",
|
|
215
|
+
className
|
|
216
|
+
)}
|
|
217
|
+
data-state={state}
|
|
218
|
+
{...(isLoading ? { "data-loading": true } : {})}
|
|
219
|
+
{...props}
|
|
220
|
+
>
|
|
221
|
+
{children}
|
|
222
|
+
</div>
|
|
223
|
+
</StepItemContext.Provider>
|
|
224
|
+
)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
interface StepperTriggerProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
228
|
+
asChild?: boolean
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function StepperTrigger({
|
|
232
|
+
asChild = false,
|
|
233
|
+
className,
|
|
234
|
+
children,
|
|
235
|
+
tabIndex,
|
|
236
|
+
...props
|
|
237
|
+
}: StepperTriggerProps) {
|
|
238
|
+
const { state, isLoading } = useStepItem()
|
|
239
|
+
const stepperCtx = useStepper()
|
|
240
|
+
const {
|
|
241
|
+
setActiveStep,
|
|
242
|
+
activeStep,
|
|
243
|
+
registerTrigger,
|
|
244
|
+
triggerNodes,
|
|
245
|
+
focusNext,
|
|
246
|
+
focusPrev,
|
|
247
|
+
focusFirst,
|
|
248
|
+
focusLast,
|
|
249
|
+
} = stepperCtx
|
|
250
|
+
const { step, isDisabled } = useStepItem()
|
|
251
|
+
const isSelected = activeStep === step
|
|
252
|
+
const id = `stepper-tab-${step}`
|
|
253
|
+
const panelId = `stepper-panel-${step}`
|
|
254
|
+
|
|
255
|
+
// Register this trigger for keyboard navigation
|
|
256
|
+
const btnRef = useRef<HTMLButtonElement>(null)
|
|
257
|
+
useEffect(() => {
|
|
258
|
+
if (btnRef.current) {
|
|
259
|
+
registerTrigger(btnRef.current)
|
|
260
|
+
}
|
|
261
|
+
}, [btnRef.current])
|
|
262
|
+
|
|
263
|
+
// Find our index among triggers for navigation
|
|
264
|
+
const myIdx = useMemo(
|
|
265
|
+
() =>
|
|
266
|
+
triggerNodes.findIndex((n: HTMLButtonElement) => n === btnRef.current),
|
|
267
|
+
[triggerNodes, btnRef.current]
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
const handleKeyDown = (e: React.KeyboardEvent<HTMLButtonElement>) => {
|
|
271
|
+
switch (e.key) {
|
|
272
|
+
case "ArrowRight":
|
|
273
|
+
case "ArrowDown":
|
|
274
|
+
e.preventDefault()
|
|
275
|
+
if (myIdx !== -1 && focusNext) focusNext(myIdx)
|
|
276
|
+
break
|
|
277
|
+
case "ArrowLeft":
|
|
278
|
+
case "ArrowUp":
|
|
279
|
+
e.preventDefault()
|
|
280
|
+
if (myIdx !== -1 && focusPrev) focusPrev(myIdx)
|
|
281
|
+
break
|
|
282
|
+
case "Home":
|
|
283
|
+
e.preventDefault()
|
|
284
|
+
if (focusFirst) focusFirst()
|
|
285
|
+
break
|
|
286
|
+
case "End":
|
|
287
|
+
e.preventDefault()
|
|
288
|
+
if (focusLast) focusLast()
|
|
289
|
+
break
|
|
290
|
+
case "Enter":
|
|
291
|
+
case " ":
|
|
292
|
+
e.preventDefault()
|
|
293
|
+
setActiveStep(step)
|
|
294
|
+
break
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (asChild) {
|
|
299
|
+
return (
|
|
300
|
+
<span
|
|
301
|
+
data-slot="stepper-trigger"
|
|
302
|
+
data-state={state}
|
|
303
|
+
className={className}
|
|
304
|
+
>
|
|
305
|
+
{children}
|
|
306
|
+
</span>
|
|
307
|
+
)
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return (
|
|
311
|
+
<button
|
|
312
|
+
ref={btnRef}
|
|
313
|
+
role="tab"
|
|
314
|
+
id={id}
|
|
315
|
+
aria-selected={isSelected}
|
|
316
|
+
aria-controls={panelId}
|
|
317
|
+
tabIndex={typeof tabIndex === "number" ? tabIndex : isSelected ? 0 : -1}
|
|
318
|
+
data-slot="stepper-trigger"
|
|
319
|
+
data-state={state}
|
|
320
|
+
data-loading={isLoading}
|
|
321
|
+
className={cn(
|
|
322
|
+
"focus-visible:border-ring focus-visible:ring-ring/50 inline-flex cursor-pointer items-center outline-none focus-visible:z-10 focus-visible:ring-3 disabled:pointer-events-none disabled:opacity-60",
|
|
323
|
+
"gap-2.5 rounded-full",
|
|
324
|
+
className
|
|
325
|
+
)}
|
|
326
|
+
onClick={() => setActiveStep(step)}
|
|
327
|
+
onKeyDown={handleKeyDown}
|
|
328
|
+
disabled={isDisabled}
|
|
329
|
+
{...props}
|
|
330
|
+
>
|
|
331
|
+
{children}
|
|
332
|
+
</button>
|
|
333
|
+
)
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function StepperIndicator({
|
|
337
|
+
children,
|
|
338
|
+
className,
|
|
339
|
+
}: React.ComponentProps<"div">) {
|
|
340
|
+
const { state, isLoading } = useStepItem()
|
|
341
|
+
const { indicators } = useStepper()
|
|
342
|
+
|
|
343
|
+
return (
|
|
344
|
+
<div
|
|
345
|
+
data-slot="stepper-indicator"
|
|
346
|
+
data-state={state}
|
|
347
|
+
className={cn(
|
|
348
|
+
"border-background bg-accent text-accent-foreground data-[state=completed]:bg-primary data-[state=completed]:text-primary-foreground data-[state=active]:bg-primary data-[state=active]:text-primary-foreground relative flex size-6 shrink-0 items-center justify-center overflow-hidden",
|
|
349
|
+
"rounded-full text-xs",
|
|
350
|
+
className
|
|
351
|
+
)}
|
|
352
|
+
>
|
|
353
|
+
<div className="absolute">
|
|
354
|
+
{indicators &&
|
|
355
|
+
((isLoading && indicators.loading) ||
|
|
356
|
+
(state === "completed" && indicators.completed) ||
|
|
357
|
+
(state === "active" && indicators.active) ||
|
|
358
|
+
(state === "inactive" && indicators.inactive))
|
|
359
|
+
? (isLoading && indicators.loading) ||
|
|
360
|
+
(state === "completed" && indicators.completed) ||
|
|
361
|
+
(state === "active" && indicators.active) ||
|
|
362
|
+
(state === "inactive" && indicators.inactive)
|
|
363
|
+
: children}
|
|
364
|
+
</div>
|
|
365
|
+
</div>
|
|
366
|
+
)
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function StepperSeparator({ className }: React.ComponentProps<"div">) {
|
|
370
|
+
const { state } = useStepItem()
|
|
371
|
+
|
|
372
|
+
return (
|
|
373
|
+
<div
|
|
374
|
+
data-slot="stepper-separator"
|
|
375
|
+
data-state={state}
|
|
376
|
+
className={cn(
|
|
377
|
+
"bg-muted rounded-sm group-data-[orientation=horizontal]/stepper-nav:h-0.5 group-data-[orientation=vertical]/stepper-nav:h-12 group-data-[orientation=vertical]/stepper-nav:w-0.5 m-0.5 group-data-[orientation=horizontal]/stepper-nav:flex-1",
|
|
378
|
+
className
|
|
379
|
+
)}
|
|
380
|
+
/>
|
|
381
|
+
)
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function StepperTitle({ children, className }: React.ComponentProps<"h3">) {
|
|
385
|
+
const { state } = useStepItem()
|
|
386
|
+
|
|
387
|
+
return (
|
|
388
|
+
<h3
|
|
389
|
+
data-slot="stepper-title"
|
|
390
|
+
data-state={state}
|
|
391
|
+
className={cn(
|
|
392
|
+
"text-sm leading-none font-medium",
|
|
393
|
+
className
|
|
394
|
+
)}
|
|
395
|
+
>
|
|
396
|
+
{children}
|
|
397
|
+
</h3>
|
|
398
|
+
)
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function StepperDescription({
|
|
402
|
+
children,
|
|
403
|
+
className,
|
|
404
|
+
}: React.ComponentProps<"div">) {
|
|
405
|
+
const { state } = useStepItem()
|
|
406
|
+
|
|
407
|
+
return (
|
|
408
|
+
<div
|
|
409
|
+
data-slot="stepper-description"
|
|
410
|
+
data-state={state}
|
|
411
|
+
className={cn(
|
|
412
|
+
"text-muted-foreground text-sm",
|
|
413
|
+
className
|
|
414
|
+
)}
|
|
415
|
+
>
|
|
416
|
+
{children}
|
|
417
|
+
</div>
|
|
418
|
+
)
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function StepperNav({ children, className }: React.ComponentProps<"nav">) {
|
|
422
|
+
const { activeStep, orientation } = useStepper()
|
|
423
|
+
|
|
424
|
+
return (
|
|
425
|
+
<nav
|
|
426
|
+
data-slot="stepper-nav"
|
|
427
|
+
data-state={activeStep}
|
|
428
|
+
data-orientation={orientation}
|
|
429
|
+
className={cn(
|
|
430
|
+
"group/stepper-nav inline-flex data-[orientation=horizontal]:w-full data-[orientation=horizontal]:flex-row data-[orientation=vertical]:flex-col",
|
|
431
|
+
className
|
|
432
|
+
)}
|
|
433
|
+
>
|
|
434
|
+
{children}
|
|
435
|
+
</nav>
|
|
436
|
+
)
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function StepperPanel({ children, className }: React.ComponentProps<"div">) {
|
|
440
|
+
const { activeStep } = useStepper()
|
|
441
|
+
|
|
442
|
+
return (
|
|
443
|
+
<div
|
|
444
|
+
data-slot="stepper-panel"
|
|
445
|
+
data-state={activeStep}
|
|
446
|
+
className={cn("w-full", className)}
|
|
447
|
+
>
|
|
448
|
+
{children}
|
|
449
|
+
</div>
|
|
450
|
+
)
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
interface StepperContentProps extends React.ComponentProps<"div"> {
|
|
454
|
+
value: number
|
|
455
|
+
forceMount?: boolean
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function StepperContent({
|
|
459
|
+
value,
|
|
460
|
+
forceMount,
|
|
461
|
+
children,
|
|
462
|
+
className,
|
|
463
|
+
}: StepperContentProps) {
|
|
464
|
+
const { activeStep, direction } = useStepper()
|
|
465
|
+
const isActive = value === activeStep
|
|
466
|
+
|
|
467
|
+
if (!forceMount && !isActive) {
|
|
468
|
+
return null
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
const animation =
|
|
472
|
+
direction === "backward"
|
|
473
|
+
? elasticSlideInLeft()
|
|
474
|
+
: direction === "forward"
|
|
475
|
+
? elasticSlideInRight()
|
|
476
|
+
: elasticEnter()
|
|
477
|
+
|
|
478
|
+
return (
|
|
479
|
+
<Motion
|
|
480
|
+
animation={animation}
|
|
481
|
+
data-slot="stepper-content"
|
|
482
|
+
data-state={activeStep}
|
|
483
|
+
className={cn("w-full", className, !isActive && forceMount && "hidden")}
|
|
484
|
+
hidden={!isActive && forceMount}
|
|
485
|
+
>
|
|
486
|
+
{children}
|
|
487
|
+
</Motion>
|
|
488
|
+
)
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
export {
|
|
492
|
+
useStepper,
|
|
493
|
+
useStepItem,
|
|
494
|
+
Stepper,
|
|
495
|
+
StepperItem,
|
|
496
|
+
StepperTrigger,
|
|
497
|
+
StepperIndicator,
|
|
498
|
+
StepperSeparator,
|
|
499
|
+
StepperTitle,
|
|
500
|
+
StepperDescription,
|
|
501
|
+
StepperPanel,
|
|
502
|
+
StepperContent,
|
|
503
|
+
StepperNav,
|
|
504
|
+
type StepperProps,
|
|
505
|
+
type StepperItemProps,
|
|
506
|
+
type StepperTriggerProps,
|
|
507
|
+
type StepperContentProps,
|
|
508
|
+
}
|