@bison-lab/ui 1.9.0 → 1.10.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.mjs CHANGED
@@ -85,6 +85,66 @@ function useIsMobile() {
85
85
  return !!isMobile;
86
86
  }
87
87
  //#endregion
88
+ //#region src/hooks/use-hide-on-scroll.ts
89
+ /**
90
+ * Tracks scroll direction and reports whether a fixed element should hide.
91
+ * `hidden` turns on while scrolling down past `threshold` and off again on
92
+ * the first meaningful scroll up. Reads are rAF-throttled, so a fast scroll
93
+ * costs one state update per frame at most.
94
+ *
95
+ * @example
96
+ * ```tsx
97
+ * const { hidden } = useHideOnScroll();
98
+ * <header className={hidden ? "-translate-y-full" : "translate-y-0"} />
99
+ * ```
100
+ */
101
+ function useHideOnScroll(options = {}) {
102
+ const { threshold = 80, tolerance = 6, disabled = false } = options;
103
+ const [hidden, setHidden] = React.useState(false);
104
+ const [scrolled, setScrolled] = React.useState(false);
105
+ const lastY = React.useRef(0);
106
+ const frame = React.useRef(null);
107
+ React.useEffect(() => {
108
+ const read = () => {
109
+ frame.current = null;
110
+ const y = Math.max(window.scrollY, 0);
111
+ const delta = y - lastY.current;
112
+ setScrolled(y > threshold);
113
+ if (disabled) {
114
+ setHidden(false);
115
+ lastY.current = y;
116
+ return;
117
+ }
118
+ if (y <= threshold) {
119
+ setHidden(false);
120
+ lastY.current = y;
121
+ } else if (Math.abs(delta) >= tolerance) {
122
+ setHidden(delta > 0);
123
+ lastY.current = y;
124
+ }
125
+ };
126
+ const onScroll = () => {
127
+ if (frame.current === null) frame.current = requestAnimationFrame(read);
128
+ };
129
+ lastY.current = Math.max(window.scrollY, 0);
130
+ read();
131
+ window.addEventListener("scroll", onScroll, { passive: true });
132
+ return () => {
133
+ window.removeEventListener("scroll", onScroll);
134
+ if (frame.current !== null) cancelAnimationFrame(frame.current);
135
+ frame.current = null;
136
+ };
137
+ }, [
138
+ threshold,
139
+ tolerance,
140
+ disabled
141
+ ]);
142
+ return {
143
+ hidden,
144
+ scrolled
145
+ };
146
+ }
147
+ //#endregion
88
148
  //#region src/providers/theme-provider.tsx
89
149
  const ThemeProviderContext = React.createContext(void 0);
90
150
  function ThemeProvider({ children, defaultTheme = "system", storageKey = "bison-theme", attribute = "data-theme", ...props }) {
@@ -5423,6 +5483,172 @@ function HeaderBlock({ logo, nav, actions, onMenuToggle, sticky = true, classNam
5423
5483
  });
5424
5484
  }
5425
5485
  //#endregion
5486
+ //#region src/blocks/layout/floating-nav-block.tsx
5487
+ const PANEL_COLUMNS = {
5488
+ 1: "w-[min(92vw,20rem)] grid-cols-1",
5489
+ 2: "w-[min(92vw,36rem)] grid-cols-1 sm:grid-cols-2",
5490
+ 3: "w-[min(92vw,48rem)] grid-cols-1 sm:grid-cols-3"
5491
+ };
5492
+ const FloatingNavBlock = React.forwardRef(({ logo, items = [], actions, renderLink, hideOnScroll = true, scrollThreshold = 80, viewport = false, navLabel = "Main", mobileMenuLabel = "Toggle menu", containerClassName, navClassName, className, ...props }, ref) => {
5493
+ const [openPanel, setOpenPanel] = React.useState("");
5494
+ const [mobileOpen, setMobileOpen] = React.useState(false);
5495
+ const { hidden, scrolled } = useHideOnScroll({
5496
+ threshold: scrollThreshold,
5497
+ disabled: !hideOnScroll || openPanel !== "" || mobileOpen
5498
+ });
5499
+ const closeDrawerOnLink = React.useCallback((event) => {
5500
+ if (event.target.closest("a")) setMobileOpen(false);
5501
+ }, []);
5502
+ const link = React.useCallback((linkProps) => {
5503
+ if (renderLink) return renderLink(linkProps);
5504
+ const { children, ...rest } = linkProps;
5505
+ return /* @__PURE__ */ jsx("a", {
5506
+ ...rest,
5507
+ children
5508
+ });
5509
+ }, [renderLink]);
5510
+ return /* @__PURE__ */ jsx("header", {
5511
+ ref,
5512
+ "data-hidden": hidden,
5513
+ "data-scrolled": scrolled,
5514
+ className: cn("pointer-events-none fixed inset-x-0 top-0 z-[var(--z-sticky)] pt-4 transition-transform duration-slow ease-out", hidden && "-translate-y-full", className),
5515
+ ...props,
5516
+ children: /* @__PURE__ */ jsx("div", {
5517
+ className: cn("mx-auto w-full max-w-6xl px-4 sm:px-6", containerClassName),
5518
+ children: /* @__PURE__ */ jsxs("div", {
5519
+ className: cn("pointer-events-auto flex items-center gap-6 rounded-xl border bg-background/85 px-3 py-3 shadow-lg backdrop-blur-2xl sm:px-5", navClassName),
5520
+ children: [
5521
+ /* @__PURE__ */ jsx("div", {
5522
+ className: "flex flex-1 items-center",
5523
+ children: logo
5524
+ }),
5525
+ items.length > 0 ? /* @__PURE__ */ jsx(NavigationMenu, {
5526
+ "aria-label": navLabel,
5527
+ viewport,
5528
+ value: openPanel,
5529
+ onValueChange: setOpenPanel,
5530
+ className: "hidden md:flex",
5531
+ children: /* @__PURE__ */ jsx(NavigationMenuList, {
5532
+ className: "gap-1",
5533
+ children: items.map((item) => {
5534
+ const panel = item.content ?? (item.items?.length ? /* @__PURE__ */ jsx("div", {
5535
+ className: cn("grid gap-1 p-2", PANEL_COLUMNS[item.columns ?? 2]),
5536
+ children: item.items.map((sub) => /* @__PURE__ */ jsx(NavigationMenuLink, {
5537
+ asChild: true,
5538
+ children: link({
5539
+ href: sub.href,
5540
+ className: "flex select-none items-start gap-3 rounded-md p-3 leading-none no-underline outline-none transition-colors hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground",
5541
+ children: /* @__PURE__ */ jsxs(Fragment, { children: [sub.icon ? /* @__PURE__ */ jsx("span", {
5542
+ className: "mt-0.5 shrink-0 text-muted-foreground",
5543
+ children: sub.icon
5544
+ }) : null, /* @__PURE__ */ jsxs("span", {
5545
+ className: "min-w-0",
5546
+ children: [/* @__PURE__ */ jsx("span", {
5547
+ className: "block text-sm font-medium",
5548
+ children: sub.label
5549
+ }), sub.description ? /* @__PURE__ */ jsx("span", {
5550
+ className: "mt-1.5 block text-sm leading-snug text-muted-foreground",
5551
+ children: sub.description
5552
+ }) : null]
5553
+ })] })
5554
+ })
5555
+ }, sub.href))
5556
+ }) : null);
5557
+ return /* @__PURE__ */ jsx(NavigationMenuItem, {
5558
+ value: item.label,
5559
+ children: panel ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(NavigationMenuTrigger, {
5560
+ "data-active": item.active,
5561
+ children: item.label
5562
+ }), /* @__PURE__ */ jsx(NavigationMenuContent, { children: panel })] }) : /* @__PURE__ */ jsx(NavigationMenuLink, {
5563
+ asChild: true,
5564
+ active: item.active,
5565
+ children: link({
5566
+ href: item.href ?? "#",
5567
+ className: navigationMenuTriggerStyle(),
5568
+ "aria-current": item.active ? "page" : void 0,
5569
+ children: item.label
5570
+ })
5571
+ })
5572
+ }, item.label);
5573
+ })
5574
+ })
5575
+ }) : null,
5576
+ /* @__PURE__ */ jsxs("div", {
5577
+ className: "flex flex-1 items-center justify-end gap-2",
5578
+ children: [actions, items.length > 0 ? /* @__PURE__ */ jsxs(Sheet, {
5579
+ open: mobileOpen,
5580
+ onOpenChange: setMobileOpen,
5581
+ children: [/* @__PURE__ */ jsx(SheetTrigger, {
5582
+ asChild: true,
5583
+ children: /* @__PURE__ */ jsx(Button, {
5584
+ variant: "ghost",
5585
+ size: "icon",
5586
+ className: "md:hidden",
5587
+ "aria-label": mobileMenuLabel,
5588
+ children: /* @__PURE__ */ jsx(Menu, {
5589
+ className: "size-5",
5590
+ "aria-hidden": true
5591
+ })
5592
+ })
5593
+ }), /* @__PURE__ */ jsxs(SheetContent, {
5594
+ side: "right",
5595
+ size: "sm",
5596
+ "aria-describedby": void 0,
5597
+ children: [/* @__PURE__ */ jsx(SheetTitle, {
5598
+ className: "sr-only",
5599
+ children: navLabel
5600
+ }), /* @__PURE__ */ jsxs("div", {
5601
+ onClick: closeDrawerOnLink,
5602
+ children: [logo ? /* @__PURE__ */ jsx("div", {
5603
+ className: "flex items-center pr-12",
5604
+ children: logo
5605
+ }) : null, /* @__PURE__ */ jsx("nav", {
5606
+ className: cn(logo ? "mt-8" : "mt-6"),
5607
+ children: /* @__PURE__ */ jsx(Accordion, {
5608
+ type: "single",
5609
+ collapsible: true,
5610
+ className: "w-full",
5611
+ children: items.map((item) => {
5612
+ const subs = item.items ?? [];
5613
+ if (!subs.length && !item.content) return /* @__PURE__ */ jsx("div", {
5614
+ className: "border-b",
5615
+ children: link({
5616
+ href: item.href ?? "#",
5617
+ className: "flex py-4 text-base font-medium hover:underline",
5618
+ "aria-current": item.active ? "page" : void 0,
5619
+ onClick: () => setMobileOpen(false),
5620
+ children: item.label
5621
+ })
5622
+ }, item.label);
5623
+ return /* @__PURE__ */ jsxs(AccordionItem, {
5624
+ value: item.label,
5625
+ children: [/* @__PURE__ */ jsx(AccordionTrigger, {
5626
+ className: "text-base",
5627
+ children: item.label
5628
+ }), /* @__PURE__ */ jsx(AccordionContent, {
5629
+ className: "flex flex-col gap-1 pl-1",
5630
+ children: item.content ?? subs.map((sub) => /* @__PURE__ */ jsx(React.Fragment, { children: link({
5631
+ href: sub.href,
5632
+ className: "block rounded-md px-2 py-2 text-sm text-muted-foreground hover:bg-accent hover:text-accent-foreground",
5633
+ onClick: () => setMobileOpen(false),
5634
+ children: sub.label
5635
+ }) }, sub.href))
5636
+ })]
5637
+ }, item.label);
5638
+ })
5639
+ })
5640
+ })]
5641
+ })]
5642
+ })]
5643
+ }) : null]
5644
+ })
5645
+ ]
5646
+ })
5647
+ })
5648
+ });
5649
+ });
5650
+ FloatingNavBlock.displayName = "FloatingNavBlock";
5651
+ //#endregion
5426
5652
  //#region src/blocks/layout/sidebar-block.tsx
5427
5653
  function SidebarItemComponent({ item, collapsed }) {
5428
5654
  return /* @__PURE__ */ jsxs(item.href ? "a" : "button", {
@@ -6927,6 +7153,6 @@ function NotificationSettingsBlock({ groups, onSave, loading = false, error, dis
6927
7153
  });
6928
7154
  }
6929
7155
  //#endregion
6930
- export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, AccountSettingsBlock, Alert, AlertDescription, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, AlertTitle, AppSidebarBlock, AspectRatio, Avatar, AvatarFallback, AvatarImage, Badge, BisonProvider, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, Calendar, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, CodeInput, Collapsible, CollapsibleContent, CollapsibleTrigger, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuPortal, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, CurrencyInput, DataTable, DataTableColumnHeader, DatePicker, DateRangePicker, DensityProvider, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, EditableTitle, EmptyStateBlock, FAQColumnsBlock, FieldGroupScope, FieldProvider, FooterBlock, ForgotPasswordBlock, Form, FormError, FormField, HeaderBlock, Input, InputGroup, JsonLd, Label, MaintenanceBlock, MediaCard, NapBlock, NavigationMenu, NavigationMenuContent, NavigationMenuIndicator, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, NavigationMenuViewport, NotFoundBlock, NotificationSettingsBlock, OutlinedField, PageShell, Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, PasswordInput, PhoneInput, Popover, PopoverContent, PopoverTrigger, ProcessStepsBlock, ProfileSettingsBlock, Progress, ProgressBar, RadioGroup, RadioGroupItem, Rating, ResetPasswordBlock, ReviewsBlock, SavedPing, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue, Separator, ServerErrorBlock, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, SheetPortal, SheetTitle, SheetTrigger, ShowcasePanelsBlock, Sidebar, SidebarBlock, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupAction, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInput, SidebarInset, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarMenuSkeleton, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger, SignInBlock, SignUpBlock, Skeleton, Slider, SocialProviders, Spinner, Stepper, StepperDescription, StepperIndicator, StepperItem, StepperLabel, StepperSeparator, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, TextContent, TextEditor, Textarea, ThemeProvider, ThemeScope, TimePicker, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, VerifyBlock, actionNegativeToneClasses, actionNeutralIconChromeClasses, actionNeutralToneClasses, actionPositiveToneClasses, alertVariants, avatarVariants, badgeVariants, buttonVariants, cn, dateRangePresets, editableTitleVariants, formatUsPhone, napRecordToJsonLd, navigationMenuTriggerStyle, outlinedFieldNestResetClasses, parseUsPhoneDigits, progressBarVariants, ratingVariants, spinnerVariants, stepperIndicatorVariants, stepperItemVariants, stepperLabelVariants, switchVariants, toast, useDensity, useField, useFieldControl, useFieldGroup, useFieldIds, useFormContext, useIsMobile, useScrollReveal, useSidebar, useTheme };
7156
+ export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, AccountSettingsBlock, Alert, AlertDescription, AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, AlertTitle, AppSidebarBlock, AspectRatio, Avatar, AvatarFallback, AvatarImage, Badge, BisonProvider, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, Calendar, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, CodeInput, Collapsible, CollapsibleContent, CollapsibleTrigger, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, ContextMenu, ContextMenuCheckboxItem, ContextMenuContent, ContextMenuGroup, ContextMenuItem, ContextMenuLabel, ContextMenuPortal, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubContent, ContextMenuSubTrigger, ContextMenuTrigger, CurrencyInput, DataTable, DataTableColumnHeader, DatePicker, DateRangePicker, DensityProvider, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, EditableTitle, EmptyStateBlock, FAQColumnsBlock, FieldGroupScope, FieldProvider, FloatingNavBlock, FooterBlock, ForgotPasswordBlock, Form, FormError, FormField, HeaderBlock, Input, InputGroup, JsonLd, Label, MaintenanceBlock, MediaCard, NapBlock, NavigationMenu, NavigationMenuContent, NavigationMenuIndicator, NavigationMenuItem, NavigationMenuLink, NavigationMenuList, NavigationMenuTrigger, NavigationMenuViewport, NotFoundBlock, NotificationSettingsBlock, OutlinedField, PageShell, Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, PasswordInput, PhoneInput, Popover, PopoverContent, PopoverTrigger, ProcessStepsBlock, ProfileSettingsBlock, Progress, ProgressBar, RadioGroup, RadioGroupItem, Rating, ResetPasswordBlock, ReviewsBlock, SavedPing, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue, Separator, ServerErrorBlock, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, SheetPortal, SheetTitle, SheetTrigger, ShowcasePanelsBlock, Sidebar, SidebarBlock, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupAction, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInput, SidebarInset, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarMenuSkeleton, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger, SignInBlock, SignUpBlock, Skeleton, Slider, SocialProviders, Spinner, Stepper, StepperDescription, StepperIndicator, StepperItem, StepperLabel, StepperSeparator, Switch, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, TabsContent, TabsList, TabsTrigger, TextContent, TextEditor, Textarea, ThemeProvider, ThemeScope, TimePicker, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, VerifyBlock, actionNegativeToneClasses, actionNeutralIconChromeClasses, actionNeutralToneClasses, actionPositiveToneClasses, alertVariants, avatarVariants, badgeVariants, buttonVariants, cn, dateRangePresets, editableTitleVariants, formatUsPhone, napRecordToJsonLd, navigationMenuTriggerStyle, outlinedFieldNestResetClasses, parseUsPhoneDigits, progressBarVariants, ratingVariants, spinnerVariants, stepperIndicatorVariants, stepperItemVariants, stepperLabelVariants, switchVariants, toast, useDensity, useField, useFieldControl, useFieldGroup, useFieldIds, useFormContext, useHideOnScroll, useIsMobile, useScrollReveal, useSidebar, useTheme };
6931
7157
 
6932
7158
  //# sourceMappingURL=index.mjs.map