@cboxdk/cbox-ui 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode, ComponentProps, ComponentType } from 'react';
3
3
  import { LucideIcon } from 'lucide-react';
4
4
  import { ClassValue } from 'clsx';
5
+ export { T as TimePoint, n as niceTicks, t as timeTicks } from './scale-BaaY5qJs.js';
5
6
 
6
7
  /**
7
8
  * Identity contract every Cbox-family app must populate.
@@ -22,7 +23,8 @@ import { ClassValue } from 'clsx';
22
23
  */
23
24
  type CboxAppKey = string;
24
25
  type CboxUser = {
25
- id: number;
26
+ /** Cbox ID's user id: numeric in id itself, a prefixed string (`usr_…`) in the apps that mirror it. */
27
+ id: number | string;
26
28
  name: string;
27
29
  email: string;
28
30
  avatar_url?: string | null;
@@ -32,7 +34,8 @@ type CboxUser = {
32
34
  timezone?: string | null;
33
35
  };
34
36
  type CboxOrganization = {
35
- id: number;
37
+ /** Cbox ID's organization id: numeric in id itself, a prefixed string (`org_…`) in the apps that mirror it. */
38
+ id: number | string;
36
39
  slug: string;
37
40
  name: string;
38
41
  /**
@@ -59,8 +62,10 @@ type CboxAppLink = {
59
62
  * Defaults to the first letter of `name`.
60
63
  */
61
64
  monogram?: string;
62
- /** Optional inline SVG path or URL for the launcher tile icon. */
63
- iconUrl?: string;
65
+ /** Cbox ID's catalog `icon_url`: the app's icon for light surfaces (`https:` only). */
66
+ iconUrl?: string | null;
67
+ /** Cbox ID's catalog `icon_dark_url`: the app's icon for dark surfaces. */
68
+ iconDarkUrl?: string | null;
64
69
  /**
65
70
  * Accent colour for the monogram tile (and current-app highlight).
66
71
  * Hex string or any CSS colour the browser accepts. Falls back to
@@ -255,6 +260,8 @@ type LinkComponent = ComponentType<{
255
260
  className?: string;
256
261
  title?: string;
257
262
  'aria-label'?: string;
263
+ /** Set on the link of the page the person is on. */
264
+ 'aria-current'?: 'page';
258
265
  }>;
259
266
  type CboxAppSidebarProps = {
260
267
  /** App key for the brand submark (and aria labels). */
@@ -389,7 +396,9 @@ type CboxBrandProps = {
389
396
  * `light` on dark / coloured surfaces. */
390
397
  tone?: 'dark' | 'light';
391
398
  /** Collapsed mode renders only the square icon — used in the
392
- * collapsed-sidebar state. */
399
+ * collapsed-sidebar state. The icon is the app's own icon from
400
+ * Cbox ID's catalog (light and dark) once this browser has seen
401
+ * the catalog, and the Cbox icon until then. */
393
402
  collapsed?: boolean;
394
403
  className?: string;
395
404
  };
@@ -494,6 +503,119 @@ type AppLauncherProps = {
494
503
  */
495
504
  declare function AppLauncher({ className, onLockedAppClick }: AppLauncherProps): react_jsx_runtime.JSX.Element | null;
496
505
 
506
+ /** One app as the host's catalog endpoint lists it. */
507
+ type CboxCatalogApp = {
508
+ key: string;
509
+ name: string;
510
+ launch_url: string;
511
+ /** Cbox ID's uploaded icon for light surfaces. */
512
+ icon_url?: string | null;
513
+ /** Cbox ID's uploaded icon for dark surfaces. */
514
+ icon_dark_url?: string | null;
515
+ description?: string | null;
516
+ };
517
+ type CboxAppCatalogState = {
518
+ status: 'idle' | 'loading';
519
+ } | {
520
+ status: 'ready';
521
+ apps: CboxCatalogApp[];
522
+ refreshAfter: number;
523
+ } | {
524
+ status: 'authorization_required';
525
+ authorizeUrl: string | null;
526
+ } | {
527
+ status: 'unavailable';
528
+ };
529
+ type CboxAppCatalogProps = {
530
+ /**
531
+ * Same-origin URL the host serves the person's app catalog from (a proxy of Cbox ID's
532
+ * catalog, authorized for the signed-in person). `null` renders the control disabled, so the
533
+ * chrome keeps its shape on pages without an organization.
534
+ */
535
+ endpoint: string | null;
536
+ /** The app key of this app; its tile is marked current and does not navigate. */
537
+ currentAppKey: string;
538
+ className?: string;
539
+ };
540
+ /**
541
+ * Interpret the catalog endpoint's answer. The contract every Cbox app serves:
542
+ *
543
+ * - `200 { apps: [{ key, name, launch_url, icon_url?, icon_dark_url?, description? }], refresh_after?: seconds }`
544
+ * - `401`/`403 { authorize_url?: string }` or `{ state: 'authorization_required' }`: the
545
+ * person has to (re)connect their catalog grant; `authorize_url` is where.
546
+ * - anything else: unavailable right now.
547
+ *
548
+ * Only `http(s)` launch URLs are kept: the tiles are links the person will click.
549
+ */
550
+ declare function parseAppCatalog(ok: boolean, body: unknown): CboxAppCatalogState;
551
+ /** The authorize link with `return_to` set to where the person is, when it is on this origin. */
552
+ declare function authorizeHref(authorizeUrl: string | null, location: {
553
+ origin: string;
554
+ pathname: string;
555
+ search: string;
556
+ }): string | null;
557
+ /**
558
+ * The Switch-app control: a grid of the Cbox apps this person can open, read live from the
559
+ * host's catalog endpoint. The host owns the endpoint and the grant; this renders the answer,
560
+ * refreshes it when it expires while the panel is open, and offers the way back to Cbox ID
561
+ * when the grant is missing. Each tile shows the app's icon from the catalog (light and dark),
562
+ * and the answer is kept so `CboxServiceMark` paints the app's own mark from it.
563
+ */
564
+ declare function CboxAppCatalog({ endpoint, currentAppKey, className }: CboxAppCatalogProps): react_jsx_runtime.JSX.Element;
565
+
566
+ /**
567
+ * Every Cbox app's icon comes from Cbox ID's catalog: one light and one dark upload per app
568
+ * (`icon_url`, `icon_dark_url`). There is no local copy of the marks in this package or in an
569
+ * app. The last catalog the browser saw is kept here so an app's own mark and the switcher
570
+ * paint at once on the next page; the live answer replaces it when it arrives.
571
+ */
572
+ type CboxKnownApp = {
573
+ key: string;
574
+ name: string;
575
+ icon_url: string | null;
576
+ icon_dark_url: string | null;
577
+ };
578
+ /** Keep the catalog the person just loaded, so every mark on this origin repaints from it. */
579
+ declare function rememberAppCatalog(apps: ReadonlyArray<{
580
+ key: string;
581
+ name: string;
582
+ icon_url?: string | null;
583
+ icon_dark_url?: string | null;
584
+ }>): void;
585
+ /** The last catalog this browser kept; empty on the server and before the first answer. */
586
+ declare function useKnownAppCatalog(): CboxKnownApp[];
587
+ /** Only `https:` icon URLs are rendered: the icons are hosted by Cbox ID. */
588
+ declare function secureIconUrl(url: unknown): string | null;
589
+ type CboxAppIconProps = {
590
+ /** The app's name; its first two letters stand in when it has no icon. */
591
+ name: string;
592
+ /** Catalog `icon_url`: the icon for light surfaces (or the only one). */
593
+ iconUrl?: string | null;
594
+ /** Catalog `icon_dark_url`: the icon for dark surfaces. */
595
+ iconDarkUrl?: string | null;
596
+ /** Size and shape of the icon box, e.g. `h-6 w-6`. */
597
+ className?: string;
598
+ /** Rendered instead of initials when the app has no usable icon. */
599
+ fallback?: ReactNode;
600
+ };
601
+ /**
602
+ * One app's icon from the catalog. With both uploads it renders two images and the token
603
+ * stylesheet shows the one for the current theme (`.dark` or `[data-theme="dark"]` on the
604
+ * root, the same switch the tokens use). Without an icon, or when it fails to load, it shows
605
+ * the app's initials.
606
+ */
607
+ declare function CboxAppIcon({ name, iconUrl, iconDarkUrl, className, fallback }: CboxAppIconProps): react_jsx_runtime.JSX.Element;
608
+ type CboxServiceMarkProps = {
609
+ /** The app key in Cbox ID's catalog (`signals`, `infra`, …). */
610
+ appKey: string;
611
+ /** Size of the mark. Default `h-6 w-6`. */
612
+ className?: string;
613
+ /** Shown while the catalog has not told this browser the app's icon yet. Default nothing. */
614
+ fallback?: ReactNode;
615
+ };
616
+ /** An app's own mark (its rail or brand icon), read from the catalog this browser last kept. */
617
+ declare function CboxServiceMark({ appKey, className, fallback }: CboxServiceMarkProps): react_jsx_runtime.JSX.Element;
618
+
497
619
  type AppSwitcherProps = {
498
620
  className?: string;
499
621
  /**
@@ -595,7 +717,14 @@ type Props$3 = {
595
717
  * is consistency across apps.
596
718
  */
597
719
  extras?: ReactNode;
720
+ placement?: 'bottom-end' | 'top-start';
598
721
  className?: string;
722
+ /**
723
+ * The router's link for the account and organization rows, when they are pages of this
724
+ * app (an Inertia `Link` keeps the visit client-side). Default: a plain anchor, which is
725
+ * right when the rows deep-link into Cbox ID on another origin.
726
+ */
727
+ LinkComponent?: LinkComponent;
599
728
  };
600
729
  /**
601
730
  * User-menu dropdown. Always exposes:
@@ -605,7 +734,7 @@ type Props$3 = {
605
734
  *
606
735
  * The arrows signal cross-app navigation — id is canonical.
607
736
  */
608
- declare function UserMenu({ extras, className }: Props$3): react_jsx_runtime.JSX.Element;
737
+ declare function UserMenu({ extras, className, placement, LinkComponent: Link }: Props$3): react_jsx_runtime.JSX.Element;
609
738
 
610
739
  /**
611
740
  * Combobox — the canonical select replacement for the Cbox suite.
@@ -1380,4 +1509,75 @@ declare function parseUrlSearch<S extends UrlSchema>(search: string, schema: S):
1380
1509
  */
1381
1510
  declare function buildUrlSearch<S extends UrlSchema>(state: InferUrlState<S>, schema: S): string;
1382
1511
 
1383
- export { AppContent, AppLauncher, AppShell, AppSwitcher, type CboxAppKey, type CboxAppLink, CboxAppShell, type CboxAppShellProps, CboxAppSidebar, type CboxAppSidebarProps, CboxBrand, type CboxBrandProps, type CboxIdContextValue, CboxIdProvider, CboxMobileNavDrawer, type CboxMobileNavDrawerProps, type CboxNavItem, type CboxNavSection, type CboxNotificationPreviewItem, type CboxNotificationsState, CboxOrgContextBar, type CboxOrgContextBarProps, type CboxOrganization, CboxSurfaces, type CboxSurfacesProps, type CboxUser, Combobox, type ComboboxAvatar, type ComboboxGroup, type ComboboxOption, type ComboboxProps, type ContextAvatar, ContextAvatarChip, ContextBar, type ContextCrumb, type ContextItem, DataPanel, EmptyState, Heading, type InboxState, type InferUrlState, KeyValue, KeyValueList, type LinkComponent, NotificationsBell, OrgSwitcher, PageHeader, PageShell, type PageTabSpec, PageTabs, type PageTabsProps, type PageWidth, PanelBody, type RealtimeState, type RealtimeStatus, RowLink, type RowLinkProps, SearchTrigger, SectionHeader, StatTile, StatusPill, type SurfaceArgs, type SurfaceConfig, type SurfaceController, type SurfaceId, TopBar, type Transport, type UrlField, type UrlSchema, UserMenu, buildUrlSearch, cn, defineUrlSchema, parseUrlSearch, urlBoolean, urlEnum, urlNumber, urlString, urlStringArray, useCboxId, useCboxIdOptional, useCboxSurfaces, useCboxSurfacesOptional };
1512
+ type CboxTranslationValues = Record<string, string | number>;
1513
+ type CboxTranslator = (message: string, values?: CboxTranslationValues) => string;
1514
+ declare function interpolate(message: string, values?: CboxTranslationValues): string;
1515
+ /** Optional and additive: without a provider existing consumers retain English. */
1516
+ declare function CboxLocalizationProvider({ locale, translate, formatDate, children }: {
1517
+ locale: string;
1518
+ translate: CboxTranslator;
1519
+ formatDate?: (value: string) => string;
1520
+ children: ReactNode;
1521
+ }): react_jsx_runtime.JSX.Element;
1522
+ declare function useCboxLocalization(): {
1523
+ locale: string;
1524
+ t: CboxTranslator;
1525
+ formatDate: (value: string) => string;
1526
+ };
1527
+
1528
+ type CboxNavArea = CboxNavItem & {
1529
+ items?: CboxNavItem[];
1530
+ };
1531
+ type CboxWorkspaceShellProps = {
1532
+ appKey: string;
1533
+ brandSubmark: string;
1534
+ areas: CboxNavArea[];
1535
+ currentPath: string;
1536
+ LinkComponent: LinkComponent;
1537
+ context: ReactNode;
1538
+ tools: ReactNode;
1539
+ account: ReactNode;
1540
+ children: ReactNode;
1541
+ /** Where the brand row links. Default `/`. */
1542
+ brandHref?: string;
1543
+ /** `id` of the `<main>` landmark, so a host's skip link can target it. Default `main-content`. */
1544
+ mainId?: string;
1545
+ /**
1546
+ * Rail pinned open. Pass `pinned` + `onPinnedChange` to control it (the host persists the
1547
+ * preference, in a cookie or Cbox ID), or `defaultPinned` to seed the shell's own state.
1548
+ */
1549
+ pinned?: boolean;
1550
+ defaultPinned?: boolean;
1551
+ onPinnedChange?: (pinned: boolean) => void;
1552
+ /** Contextual subnav collapsed to its strip. Controlled and uncontrolled as `pinned`. */
1553
+ collapsed?: boolean;
1554
+ defaultCollapsed?: boolean;
1555
+ onCollapsedChange?: (collapsed: boolean) => void;
1556
+ };
1557
+ /**
1558
+ * How well `href` matches `path`: the href's length when the path is the href or beneath it,
1559
+ * -1 otherwise. `/` matches only itself, so a home item never claims every page.
1560
+ */
1561
+ declare function navMatchLength(path: string, href: string): number;
1562
+ /** The item whose href is the most specific match for `path`, or undefined. */
1563
+ declare function activeNavItem<T extends CboxNavItem>(path: string, items: readonly T[]): T | undefined;
1564
+ /**
1565
+ * The area `path` is in: the one holding the most specific match among its own href and its
1566
+ * items' hrefs. A first-match would put every page beneath an area at `/` (an overview, a
1567
+ * dashboard) under that area and never show another area's subnav.
1568
+ */
1569
+ declare function activeNavArea<T extends CboxNavArea>(path: string, areas: readonly T[]): T | undefined;
1570
+ /** Two-tier workspace navigation. Route ownership and preference persistence stay with the host. */
1571
+ declare function CboxWorkspaceShell({ appKey, brandSubmark, areas, currentPath, LinkComponent: Link, context, tools, account, children, brandHref, mainId, pinned: pinnedProp, defaultPinned, onPinnedChange, collapsed: collapsedProp, defaultCollapsed, onCollapsedChange }: CboxWorkspaceShellProps): react_jsx_runtime.JSX.Element;
1572
+
1573
+ /** The chart tokens in order, for series that set their own colour. */
1574
+ declare const CHART_PALETTE: string[];
1575
+ /** A row's shape over the window, small: a line with a faint area, zero at the bottom. Decorative. */
1576
+ declare function Sparkline({ values, color, width, height }: {
1577
+ values: number[];
1578
+ color?: string;
1579
+ width?: number;
1580
+ height?: number;
1581
+ }): react_jsx_runtime.JSX.Element | null;
1582
+
1583
+ export { AppContent, AppLauncher, AppShell, AppSwitcher, CHART_PALETTE, CboxAppCatalog, type CboxAppCatalogProps, type CboxAppCatalogState, CboxAppIcon, type CboxAppIconProps, type CboxAppKey, type CboxAppLink, CboxAppShell, type CboxAppShellProps, CboxAppSidebar, type CboxAppSidebarProps, CboxBrand, type CboxBrandProps, type CboxCatalogApp, type CboxIdContextValue, CboxIdProvider, type CboxKnownApp, CboxLocalizationProvider, CboxMobileNavDrawer, type CboxMobileNavDrawerProps, type CboxNavArea, type CboxNavItem, type CboxNavSection, type CboxNotificationPreviewItem, type CboxNotificationsState, CboxOrgContextBar, type CboxOrgContextBarProps, type CboxOrganization, CboxServiceMark, type CboxServiceMarkProps, CboxSurfaces, type CboxSurfacesProps, type CboxTranslationValues, type CboxTranslator, type CboxUser, CboxWorkspaceShell, type CboxWorkspaceShellProps, Combobox, type ComboboxAvatar, type ComboboxGroup, type ComboboxOption, type ComboboxProps, type ContextAvatar, ContextAvatarChip, ContextBar, type ContextCrumb, type ContextItem, DataPanel, EmptyState, Heading, type InboxState, type InferUrlState, KeyValue, KeyValueList, type LinkComponent, NotificationsBell, OrgSwitcher, PageHeader, PageShell, type PageTabSpec, PageTabs, type PageTabsProps, type PageWidth, PanelBody, type RealtimeState, type RealtimeStatus, RowLink, type RowLinkProps, SearchTrigger, SectionHeader, Sparkline, StatTile, StatusPill, type SurfaceArgs, type SurfaceConfig, type SurfaceController, type SurfaceId, TopBar, type Transport, type UrlField, type UrlSchema, UserMenu, activeNavArea, activeNavItem, authorizeHref, buildUrlSearch, cn, defineUrlSchema, interpolate, navMatchLength, parseAppCatalog, parseUrlSearch, rememberAppCatalog, secureIconUrl, urlBoolean, urlEnum, urlNumber, urlString, urlStringArray, useCboxId, useCboxIdOptional, useCboxLocalization, useCboxSurfaces, useCboxSurfacesOptional, useKnownAppCatalog };