@mirror-physics/fractal-ui 0.2.0-next.23 → 0.2.0-next.24

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.cts CHANGED
@@ -164,6 +164,10 @@ interface CheckboxProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElemen
164
164
  declare function Checkbox({ checked, onCheckedChange, className, disabled, onClick, onKeyDown, ...props }: CheckboxProps): React.JSX.Element;
165
165
 
166
166
  type SortDirection = 'asc' | 'desc' | null;
167
+ interface SortableTableDefaultSort {
168
+ key: string;
169
+ direction: Exclude<SortDirection, null>;
170
+ }
167
171
  interface SortableTableColumn<T> {
168
172
  key: string;
169
173
  header: string;
@@ -186,6 +190,9 @@ interface SortableTableProps<T> {
186
190
  /** Removes the table's outer border and radius for use inside another framed surface. */
187
191
  embedded?: boolean;
188
192
  className?: string;
193
+ /** Baseline row ordering that does not appear as an active user sort. */
194
+ defaultSort?: SortableTableDefaultSort;
195
+ /** Initial visible user sort state. */
189
196
  defaultSortKey?: string;
190
197
  defaultSortDirection?: SortDirection;
191
198
  sortKey?: string | null;
@@ -197,7 +204,7 @@ interface SortableTableProps<T> {
197
204
  /** Directional affordance displayed over the right edge of an interactive row. */
198
205
  rowAction?: SortableTableRowAction<T>;
199
206
  }
200
- declare function SortableTable<T>({ columns, data, emptyMessage, header, size, embedded, className, defaultSortKey, defaultSortDirection, sortKey: controlledKey, sortDirection: controlledDirection, onSortChange, highlightRow, onRowClick, rowAction, }: SortableTableProps<T>): React.JSX.Element;
207
+ declare function SortableTable<T>({ columns, data, emptyMessage, header, size, embedded, className, defaultSort, defaultSortKey, defaultSortDirection, sortKey: controlledKey, sortDirection: controlledDirection, onSortChange, highlightRow, onRowClick, rowAction, }: SortableTableProps<T>): React.JSX.Element;
201
208
 
202
209
  interface TabItem {
203
210
  id: string;
@@ -335,4 +342,4 @@ declare function useEscapeDismiss(priority: number, handler: () => void, enabled
335
342
 
336
343
  declare function cn(...inputs: ClassValue[]): string;
337
344
 
338
- export { Alert, AlertDescription, AlertTitle, Button, type ButtonColor, type ButtonProps, type ButtonSize, type ButtonType, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, type CheckboxProps, Chip, type ChipProps, type ChipTone, ContentSwitcher, type ContentSwitcherItem, type ContentSwitcherProps, DataTable, type DataTableColumn, type DataTableProps, Disclosure, type DisclosureProps, Dropdown, type DropdownItem, type DropdownProps, FeatureCard, type FeatureCardProps, FileDropzone, type FileDropzoneProps, FolderCard, type FolderCardProps, Input, type InputProps, Label, type LabelProps, LatticeLoader, type LatticeLoaderProps, Link, type LinkProps, type LinkSize, type LinkTheme, Modal, type ModalProps, Pagination, type PaginationProps, PromptCard, type PromptCardProps, type PromptCardTone, PromptGrid, type PromptGridProps, SidePanel, type SidePanelProps, Sidebar, SidebarBrand, SidebarFooter, SidebarHeader, SidebarNav, SidebarNavItem, type SidebarNavItemProps, type SidebarProps, SidebarSection, type SortDirection, SortableTable, type SortableTableColumn, type SortableTableProps, type SortableTableRowAction, type TabItem, Tabs, type TabsProps, TextButton, type TextButtonIconPosition, type TextButtonProps, type TextButtonSize, type TextButtonTone, Textarea, type TextareaProps, Toggle, type ToggleProps, cn, useEscapeDismiss };
345
+ export { Alert, AlertDescription, AlertTitle, Button, type ButtonColor, type ButtonProps, type ButtonSize, type ButtonType, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, type CheckboxProps, Chip, type ChipProps, type ChipTone, ContentSwitcher, type ContentSwitcherItem, type ContentSwitcherProps, DataTable, type DataTableColumn, type DataTableProps, Disclosure, type DisclosureProps, Dropdown, type DropdownItem, type DropdownProps, FeatureCard, type FeatureCardProps, FileDropzone, type FileDropzoneProps, FolderCard, type FolderCardProps, Input, type InputProps, Label, type LabelProps, LatticeLoader, type LatticeLoaderProps, Link, type LinkProps, type LinkSize, type LinkTheme, Modal, type ModalProps, Pagination, type PaginationProps, PromptCard, type PromptCardProps, type PromptCardTone, PromptGrid, type PromptGridProps, SidePanel, type SidePanelProps, Sidebar, SidebarBrand, SidebarFooter, SidebarHeader, SidebarNav, SidebarNavItem, type SidebarNavItemProps, type SidebarProps, SidebarSection, type SortDirection, SortableTable, type SortableTableColumn, type SortableTableDefaultSort, type SortableTableProps, type SortableTableRowAction, type TabItem, Tabs, type TabsProps, TextButton, type TextButtonIconPosition, type TextButtonProps, type TextButtonSize, type TextButtonTone, Textarea, type TextareaProps, Toggle, type ToggleProps, cn, useEscapeDismiss };
package/dist/index.d.ts CHANGED
@@ -164,6 +164,10 @@ interface CheckboxProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElemen
164
164
  declare function Checkbox({ checked, onCheckedChange, className, disabled, onClick, onKeyDown, ...props }: CheckboxProps): React.JSX.Element;
165
165
 
166
166
  type SortDirection = 'asc' | 'desc' | null;
167
+ interface SortableTableDefaultSort {
168
+ key: string;
169
+ direction: Exclude<SortDirection, null>;
170
+ }
167
171
  interface SortableTableColumn<T> {
168
172
  key: string;
169
173
  header: string;
@@ -186,6 +190,9 @@ interface SortableTableProps<T> {
186
190
  /** Removes the table's outer border and radius for use inside another framed surface. */
187
191
  embedded?: boolean;
188
192
  className?: string;
193
+ /** Baseline row ordering that does not appear as an active user sort. */
194
+ defaultSort?: SortableTableDefaultSort;
195
+ /** Initial visible user sort state. */
189
196
  defaultSortKey?: string;
190
197
  defaultSortDirection?: SortDirection;
191
198
  sortKey?: string | null;
@@ -197,7 +204,7 @@ interface SortableTableProps<T> {
197
204
  /** Directional affordance displayed over the right edge of an interactive row. */
198
205
  rowAction?: SortableTableRowAction<T>;
199
206
  }
200
- declare function SortableTable<T>({ columns, data, emptyMessage, header, size, embedded, className, defaultSortKey, defaultSortDirection, sortKey: controlledKey, sortDirection: controlledDirection, onSortChange, highlightRow, onRowClick, rowAction, }: SortableTableProps<T>): React.JSX.Element;
207
+ declare function SortableTable<T>({ columns, data, emptyMessage, header, size, embedded, className, defaultSort, defaultSortKey, defaultSortDirection, sortKey: controlledKey, sortDirection: controlledDirection, onSortChange, highlightRow, onRowClick, rowAction, }: SortableTableProps<T>): React.JSX.Element;
201
208
 
202
209
  interface TabItem {
203
210
  id: string;
@@ -335,4 +342,4 @@ declare function useEscapeDismiss(priority: number, handler: () => void, enabled
335
342
 
336
343
  declare function cn(...inputs: ClassValue[]): string;
337
344
 
338
- export { Alert, AlertDescription, AlertTitle, Button, type ButtonColor, type ButtonProps, type ButtonSize, type ButtonType, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, type CheckboxProps, Chip, type ChipProps, type ChipTone, ContentSwitcher, type ContentSwitcherItem, type ContentSwitcherProps, DataTable, type DataTableColumn, type DataTableProps, Disclosure, type DisclosureProps, Dropdown, type DropdownItem, type DropdownProps, FeatureCard, type FeatureCardProps, FileDropzone, type FileDropzoneProps, FolderCard, type FolderCardProps, Input, type InputProps, Label, type LabelProps, LatticeLoader, type LatticeLoaderProps, Link, type LinkProps, type LinkSize, type LinkTheme, Modal, type ModalProps, Pagination, type PaginationProps, PromptCard, type PromptCardProps, type PromptCardTone, PromptGrid, type PromptGridProps, SidePanel, type SidePanelProps, Sidebar, SidebarBrand, SidebarFooter, SidebarHeader, SidebarNav, SidebarNavItem, type SidebarNavItemProps, type SidebarProps, SidebarSection, type SortDirection, SortableTable, type SortableTableColumn, type SortableTableProps, type SortableTableRowAction, type TabItem, Tabs, type TabsProps, TextButton, type TextButtonIconPosition, type TextButtonProps, type TextButtonSize, type TextButtonTone, Textarea, type TextareaProps, Toggle, type ToggleProps, cn, useEscapeDismiss };
345
+ export { Alert, AlertDescription, AlertTitle, Button, type ButtonColor, type ButtonProps, type ButtonSize, type ButtonType, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Checkbox, type CheckboxProps, Chip, type ChipProps, type ChipTone, ContentSwitcher, type ContentSwitcherItem, type ContentSwitcherProps, DataTable, type DataTableColumn, type DataTableProps, Disclosure, type DisclosureProps, Dropdown, type DropdownItem, type DropdownProps, FeatureCard, type FeatureCardProps, FileDropzone, type FileDropzoneProps, FolderCard, type FolderCardProps, Input, type InputProps, Label, type LabelProps, LatticeLoader, type LatticeLoaderProps, Link, type LinkProps, type LinkSize, type LinkTheme, Modal, type ModalProps, Pagination, type PaginationProps, PromptCard, type PromptCardProps, type PromptCardTone, PromptGrid, type PromptGridProps, SidePanel, type SidePanelProps, Sidebar, SidebarBrand, SidebarFooter, SidebarHeader, SidebarNav, SidebarNavItem, type SidebarNavItemProps, type SidebarProps, SidebarSection, type SortDirection, SortableTable, type SortableTableColumn, type SortableTableDefaultSort, type SortableTableProps, type SortableTableRowAction, type TabItem, Tabs, type TabsProps, TextButton, type TextButtonIconPosition, type TextButtonProps, type TextButtonSize, type TextButtonTone, Textarea, type TextareaProps, Toggle, type ToggleProps, cn, useEscapeDismiss };
package/dist/index.js CHANGED
@@ -702,6 +702,7 @@ function SortableTable({
702
702
  size = "md",
703
703
  embedded = false,
704
704
  className,
705
+ defaultSort,
705
706
  defaultSortKey = void 0,
706
707
  defaultSortDirection = null,
707
708
  sortKey: controlledKey,
@@ -716,12 +717,16 @@ function SortableTable({
716
717
  const isControlled = controlledKey !== void 0 && controlledDirection !== void 0;
717
718
  const activeKey = isControlled ? controlledKey : internalKey;
718
719
  const activeDirection = isControlled ? controlledDirection : internalDirection;
720
+ const baselineKey = defaultSort?.key ?? null;
721
+ const baselineDirection = defaultSort?.direction ?? null;
722
+ const effectiveKey = activeKey && activeDirection ? activeKey : baselineKey;
723
+ const effectiveDirection = activeKey && activeDirection ? activeDirection : baselineDirection;
719
724
  const sorted = useMemo(() => {
720
- if (!activeKey || !activeDirection) return data;
721
- const col = columns.find((c) => c.key === activeKey);
725
+ if (!effectiveKey || !effectiveDirection) return data;
726
+ const col = columns.find((c) => c.key === effectiveKey);
722
727
  if (!col) return data;
723
728
  const accessor = col.sortAccessor ?? ((row) => {
724
- const value = row[activeKey];
729
+ const value = row[effectiveKey];
725
730
  return typeof value === "string" || typeof value === "number" ? value : null;
726
731
  });
727
732
  const copy = [...data];
@@ -732,19 +737,21 @@ function SortableTable({
732
737
  if (av == null) return 1;
733
738
  if (bv == null) return -1;
734
739
  if (typeof av === "number" && typeof bv === "number") {
735
- return activeDirection === "asc" ? av - bv : bv - av;
740
+ return effectiveDirection === "asc" ? av - bv : bv - av;
736
741
  }
737
742
  const as = String(av).toLowerCase();
738
743
  const bs = String(bv).toLowerCase();
739
- if (as < bs) return activeDirection === "asc" ? -1 : 1;
740
- if (as > bs) return activeDirection === "asc" ? 1 : -1;
744
+ if (as < bs) return effectiveDirection === "asc" ? -1 : 1;
745
+ if (as > bs) return effectiveDirection === "asc" ? 1 : -1;
741
746
  return 0;
742
747
  });
743
748
  return copy;
744
- }, [data, columns, activeKey, activeDirection]);
749
+ }, [data, columns, effectiveKey, effectiveDirection]);
745
750
  const handleSortClick = (key) => {
746
751
  let nextDirection;
747
- if (activeKey !== key) {
752
+ if (!activeKey || !activeDirection) {
753
+ nextDirection = baselineKey === key && baselineDirection ? baselineDirection : "asc";
754
+ } else if (activeKey !== key) {
748
755
  nextDirection = "asc";
749
756
  } else if (activeDirection === "asc") {
750
757
  nextDirection = "desc";