@algenium/blocks 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.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  'use strict';
2
3
 
3
4
  var React2 = require('react');
@@ -3665,6 +3666,158 @@ function ThemeSwitcher({
3665
3666
  }
3666
3667
  );
3667
3668
  }
3669
+ var defaultLabels2 = {
3670
+ heading: "Organizations",
3671
+ create: "Create organization",
3672
+ empty: "No organization selected"
3673
+ };
3674
+ function TenantAvatar({
3675
+ name,
3676
+ logo,
3677
+ size = "md"
3678
+ }) {
3679
+ const sizeClass = size === "sm" ? "size-6 rounded-md" : "size-8 rounded-lg";
3680
+ const textClass = size === "sm" ? "text-xs" : "text-sm";
3681
+ return /* @__PURE__ */ jsxRuntime.jsx(
3682
+ "div",
3683
+ {
3684
+ className: cn(
3685
+ "flex shrink-0 items-center justify-center overflow-hidden bg-muted font-medium text-muted-foreground",
3686
+ sizeClass
3687
+ ),
3688
+ children: logo ? /* @__PURE__ */ jsxRuntime.jsx("img", { src: logo, alt: "", className: "size-full object-cover" }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: textClass, children: name.charAt(0).toUpperCase() })
3689
+ }
3690
+ );
3691
+ }
3692
+ function SwitcherSkeleton({ className }) {
3693
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3694
+ "div",
3695
+ {
3696
+ "data-testid": "org-switcher-skeleton",
3697
+ className: cn(
3698
+ "pointer-events-none flex h-12 min-h-12 w-full items-center gap-2 rounded-md px-2",
3699
+ className
3700
+ ),
3701
+ children: [
3702
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-8 shrink-0 animate-pulse rounded-lg bg-muted" }),
3703
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [
3704
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-4 w-24 animate-pulse rounded bg-muted" }),
3705
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "h-3 w-16 animate-pulse rounded bg-muted" })
3706
+ ] }),
3707
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ml-auto size-4 shrink-0 animate-pulse rounded-sm bg-muted" })
3708
+ ]
3709
+ }
3710
+ );
3711
+ }
3712
+ var triggerClassName = "flex h-12 min-h-12 w-full items-center gap-2 rounded-md px-2 text-left text-sm outline-none transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:ring-2 focus-visible:ring-ring data-[state=open]:bg-accent data-[state=open]:text-accent-foreground";
3713
+ function OrgSwitcher({
3714
+ activeTenant,
3715
+ tenants,
3716
+ onSelectTenant,
3717
+ createUrl,
3718
+ isLoading = false,
3719
+ collapsed = false,
3720
+ isMobile = false,
3721
+ activeSubtitle,
3722
+ labels: userLabels,
3723
+ className,
3724
+ triggerClassName: triggerClassNameProp
3725
+ }) {
3726
+ const labels = { ...defaultLabels2, ...userLabels };
3727
+ if (isLoading) {
3728
+ return /* @__PURE__ */ jsxRuntime.jsx(SwitcherSkeleton, { className });
3729
+ }
3730
+ if (!activeTenant) {
3731
+ if (createUrl) {
3732
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3733
+ "a",
3734
+ {
3735
+ href: createUrl,
3736
+ "data-testid": "org-switcher-empty",
3737
+ className: cn(triggerClassName, className, triggerClassNameProp),
3738
+ children: [
3739
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-8 items-center justify-center rounded-lg bg-muted", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Building2, { className: "size-4 text-muted-foreground" }) }),
3740
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid min-w-0 flex-1 text-left leading-tight", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate font-medium", children: labels.empty }) })
3741
+ ]
3742
+ }
3743
+ );
3744
+ }
3745
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3746
+ "div",
3747
+ {
3748
+ "data-testid": "org-switcher-empty",
3749
+ className: cn(triggerClassName, "pointer-events-none", className),
3750
+ children: [
3751
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-8 items-center justify-center rounded-lg bg-muted", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Building2, { className: "size-4 text-muted-foreground" }) }),
3752
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid min-w-0 flex-1 text-left leading-tight", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate font-medium text-muted-foreground", children: labels.empty }) })
3753
+ ]
3754
+ }
3755
+ );
3756
+ }
3757
+ return /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenu, { children: [
3758
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
3759
+ Button,
3760
+ {
3761
+ type: "button",
3762
+ variant: "ghost",
3763
+ "data-testid": "org-switcher",
3764
+ className: cn(
3765
+ triggerClassName,
3766
+ "h-auto justify-start font-normal",
3767
+ className,
3768
+ triggerClassNameProp
3769
+ ),
3770
+ children: [
3771
+ /* @__PURE__ */ jsxRuntime.jsx(TenantAvatar, { name: activeTenant.name, logo: activeTenant.logo }),
3772
+ !collapsed ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3773
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid min-w-0 flex-1 text-left leading-tight", children: [
3774
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate font-semibold", children: activeTenant.name }),
3775
+ activeSubtitle ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate text-xs text-muted-foreground", children: activeSubtitle }) : null
3776
+ ] }),
3777
+ activeTenant.statusBadge,
3778
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronsUpDown, { className: "ml-auto size-4 shrink-0 opacity-50" })
3779
+ ] }) : null
3780
+ ]
3781
+ }
3782
+ ) }),
3783
+ /* @__PURE__ */ jsxRuntime.jsxs(
3784
+ DropdownMenuContent,
3785
+ {
3786
+ className: "min-w-64 rounded-lg",
3787
+ align: "start",
3788
+ side: isMobile ? "bottom" : "right",
3789
+ sideOffset: 4,
3790
+ children: [
3791
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuLabel, { className: "text-xs text-muted-foreground", children: labels.heading }),
3792
+ tenants.map((tenant, index) => {
3793
+ const isActive = tenant.id === activeTenant.id;
3794
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3795
+ DropdownMenuItem,
3796
+ {
3797
+ onClick: () => onSelectTenant(tenant.id),
3798
+ className: "gap-2 p-2",
3799
+ children: [
3800
+ /* @__PURE__ */ jsxRuntime.jsx(TenantAvatar, { name: tenant.name, logo: tenant.logo, size: "sm" }),
3801
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1 whitespace-normal break-words", children: tenant.name }),
3802
+ tenant.statusBadge,
3803
+ isActive ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "size-4 shrink-0 opacity-70" }) : /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuShortcut, { children: String.fromCharCode(65 + index) })
3804
+ ]
3805
+ },
3806
+ tenant.id
3807
+ );
3808
+ }),
3809
+ createUrl ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3810
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {}),
3811
+ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuItem, { className: "gap-2 p-2", asChild: true, children: /* @__PURE__ */ jsxRuntime.jsxs("a", { href: createUrl, children: [
3812
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-6 items-center justify-center rounded-md border bg-background", children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Plus, { className: "size-4" }) }),
3813
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "font-medium text-muted-foreground", children: labels.create })
3814
+ ] }) })
3815
+ ] }) : null
3816
+ ]
3817
+ }
3818
+ )
3819
+ ] });
3820
+ }
3668
3821
  var defaultLanguages = [
3669
3822
  { key: "en", label: "EN", nativeName: "English" },
3670
3823
  { key: "es", label: "ES", nativeName: "Espa\xF1ol" }
@@ -3721,7 +3874,7 @@ function LanguageSwitcher({
3721
3874
  const onLanguageChange = propOnLanguageChange ?? context?.setLanguage;
3722
3875
  const sizes = sizeClasses2[size];
3723
3876
  const shapeClass = shapeClasses2[shape];
3724
- const defaultLabels4 = {
3877
+ const defaultLabels5 = {
3725
3878
  language: labels.language ?? "Language"
3726
3879
  };
3727
3880
  if (variant === "mini") {
@@ -3731,7 +3884,7 @@ function LanguageSwitcher({
3731
3884
  {
3732
3885
  variant: "ghost",
3733
3886
  size: "icon",
3734
- "aria-label": defaultLabels4.language,
3887
+ "aria-label": defaultLabels5.language,
3735
3888
  className: cn(sizes.buttonMini, shapeClass, className),
3736
3889
  children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Languages, { className: sizes.iconMini })
3737
3890
  }
@@ -3816,7 +3969,7 @@ function LanguageSwitcher({
3816
3969
  }
3817
3970
  );
3818
3971
  }
3819
- var defaultLabels2 = {
3972
+ var defaultLabels3 = {
3820
3973
  environment: "Data environment",
3821
3974
  live: "Live",
3822
3975
  staging: "Staging",
@@ -3889,7 +4042,7 @@ function EnvironmentMiniBadge({
3889
4042
  abbreviated = true
3890
4043
  }) {
3891
4044
  const ctx = useEnvironmentContext();
3892
- const labels = { ...defaultLabels2, ...userLabels };
4045
+ const labels = { ...defaultLabels3, ...userLabels };
3893
4046
  const environment = propEnvironment ?? ctx?.environment ?? "production";
3894
4047
  const text = abbreviated ? abbreviateEnvironment(environment) : getEnvironmentLabel(environment, labels);
3895
4048
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -3946,7 +4099,7 @@ function EnvironmentSwitcher({
3946
4099
  side = "bottom"
3947
4100
  }) {
3948
4101
  const ctx = useEnvironmentContext();
3949
- const labels = { ...defaultLabels2, ...userLabels };
4102
+ const labels = { ...defaultLabels3, ...userLabels };
3950
4103
  const environments = propEnvironments ?? ctx?.environments ?? [...BLOCKS_DATA_ENVIRONMENTS];
3951
4104
  const environment = propEnvironment ?? ctx?.environment ?? "production";
3952
4105
  const setEnvironment = propOnEnvironmentChange ?? ctx?.setEnvironment ?? (() => {
@@ -4101,7 +4254,7 @@ function EnvironmentSwitcher({
4101
4254
  }
4102
4255
  );
4103
4256
  }
4104
- var defaultLabels3 = {
4257
+ var defaultLabels4 = {
4105
4258
  stagingMessage: "You are viewing staging data \u2014 changes do not affect live customers.",
4106
4259
  developmentMessage: "You are viewing development data \u2014 for testing only.",
4107
4260
  dismiss: "Dismiss"
@@ -4113,7 +4266,7 @@ function EnvironmentBanner({
4113
4266
  enabled = true
4114
4267
  }) {
4115
4268
  const ctx = useEnvironmentContext();
4116
- const labels = { ...defaultLabels3, ...userLabels };
4269
+ const labels = { ...defaultLabels4, ...userLabels };
4117
4270
  const [dismissed, setDismissed] = React2.useState(false);
4118
4271
  const environment = propEnvironment ?? ctx?.environment ?? "production";
4119
4272
  const handleDismiss = React2.useCallback(() => {
@@ -8261,6 +8414,7 @@ exports.LoadingState = LoadingState;
8261
8414
  exports.MiniCalendar = MiniCalendar;
8262
8415
  exports.NotificationsContext = NotificationsContext;
8263
8416
  exports.NotificationsWidget = NotificationsWidget;
8417
+ exports.OrgSwitcher = OrgSwitcher;
8264
8418
  exports.Popover = Popover;
8265
8419
  exports.PopoverAnchor = PopoverAnchor;
8266
8420
  exports.PopoverContent = PopoverContent;