@crispy-seed/data-table 0.4.0 → 0.6.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
@@ -1,4 +1,5 @@
1
1
  import * as react from 'react';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
3
 
3
4
  declare interface DataTableVariant {
4
5
  /**
@@ -66,6 +67,50 @@ interface ToolbarFilter {
66
67
  */
67
68
  type DataTableCalcOp = "count" | "countFilled" | "sum" | "average" | "min" | "max";
68
69
 
70
+ /** Everything a saved view actually captures -- deliberately the same five controlled
71
+ * props `useDataTableColumns` + the toolbar sort/filter hooks already expose, so
72
+ * "restore this view" is just handing each field back to its own `on*Change` setter,
73
+ * not a bespoke apply-state routine this file would have to keep in sync with them by
74
+ * hand. Every field is optional: a consumer capturing only PART of the table's state
75
+ * (e.g. column layout but not filters) still produces a valid view. */
76
+ interface DataTableViewState {
77
+ columnOrder?: string[];
78
+ hiddenColumnKeys?: string[];
79
+ columnWidths?: Record<string, number>;
80
+ pinnedColumnKeys?: string[];
81
+ toolbarSorts?: ToolbarSort[];
82
+ toolbarFilters?: ToolbarFilter[];
83
+ }
84
+ /** One named, saved view. */
85
+ interface DataTableView {
86
+ id: string;
87
+ name: string;
88
+ state: DataTableViewState;
89
+ }
90
+
91
+ interface UseDataTableViewsProps {
92
+ /** 제어할 저장된 view 목록입니다. */
93
+ views?: DataTableView[];
94
+ /** 비제어 방식으로 사용할 때의 초기 view 목록입니다. */
95
+ defaultViews?: DataTableView[];
96
+ /** view 목록이 바뀔 때(생성/이름변경/삭제) 호출됩니다. */
97
+ onViewsChange?: (views: DataTableView[]) => void;
98
+ /** 제어할, 현재 활성화된 view의 id입니다 (`null`은 "저장된 view 없음"). */
99
+ activeViewId?: string | null;
100
+ /** 비제어 방식으로 사용할 때의 초기 활성 view id입니다. */
101
+ defaultActiveViewId?: string | null;
102
+ /** 활성 view가 바뀔 때 호출됩니다. */
103
+ onActiveViewIdChange?: (id: string | null) => void;
104
+ /**
105
+ * 기본 localStorage 저장소의 key입니다. 이 hook이 `views`를 실제로 소유할 때만
106
+ * (즉 `views`가 제어되지 않을 때만) 마운트 시 한 번 읽고, 바뀔 때마다 다시
107
+ *씁니다 -- `views`를 직접 제어하는 소비자(예: 나중에 서버에 저장하는 tether)는
108
+ * 자기 자신의 저장소를 이미 갖고 있으므로 이 hook이 localStorage에 그림자
109
+ * 복사본을 만들 이유가 없습니다. 생략하면 영속화 없이 메모리에만 남습니다.
110
+ */
111
+ storageKey?: string;
112
+ }
113
+
69
114
  type DataTableCellType = "text" | "entity" | "url" | "email" | "tags" | "status" | "number" | "currency" | "date" | "datetime" | "rating" | "checkbox";
70
115
 
71
116
  /** A `select`/`reference`/`actor` editor's own choice list -- `value`/`label` are
@@ -211,6 +256,16 @@ interface DataTableColumn<TRow> {
211
256
  * 옵션의 문자열 그 자체입니다). 생략하면 `value`(또는 `row[key]`)를 그대로 씁니다.
212
257
  */
213
258
  editValue?: (row: TRow) => string | number | boolean;
259
+ /**
260
+ * `type: "entity"` 열에서만 쓰입니다 (your-moon/crisp#601 이식). 행에 마우스를
261
+ * 올리거나 키보드 포커스를 받으면 셀 오른쪽 끝에 "미리보기 열기" 아이콘이
262
+ * 나타납니다 -- crisp가 측정한 것과 동일한 20px 고스트 버튼(`radius.sm`,
263
+ * 평상시 muted, hover에서 진해짐). 생략하면 아이콘이 렌더링되지 않습니다
264
+ * (기본값). `type`이 다르면 무시됩니다.
265
+ */
266
+ onOpenPreview?: (row: TRow) => void;
267
+ /** `onOpenPreview` 아이콘의 aria-label입니다. @default "Open preview" */
268
+ openPreviewLabel?: string;
214
269
  }
215
270
  interface DataTableProps<TRow extends {
216
271
  id: string;
@@ -330,6 +385,14 @@ interface DataTableProps<TRow extends {
330
385
  defaultColumnLabels?: Record<string, string>;
331
386
  /** 열 이름이 바뀔 때 호출됩니다. */
332
387
  onColumnLabelsChange?: (labels: Record<string, string>) => void;
388
+ /** 제어할, 왼쪽에 고정(pin)된 열의 key 목록입니다 (Attio의 컬럼 메뉴 "Pin column").
389
+ * 선택 열과 `actions: true` 열은 이미 자기만의 고정 메커니즘(`stickyFirst`/
390
+ * 자동 `stickyLast`)을 갖고 있으므로 이 목록에 넣지 않아도 됩니다. */
391
+ pinnedColumnKeys?: string[];
392
+ /** 비제어 방식으로 사용할 때의 초기 고정 열 목록입니다. */
393
+ defaultPinnedColumnKeys?: string[];
394
+ /** 고정 열 목록이 바뀔 때(핀/언핀) 호출됩니다. */
395
+ onPinnedColumnKeysChange?: (pinned: string[]) => void;
333
396
  /** 순서/숨김/이름 중 무엇이든 바뀌어 "실제로 보여줄 열 목록"이 달라질 때마다,
334
397
  * 그 결과(순서·숨김·이름이 반영된 `columns`)를 통째로 받는 편의 콜백입니다 --
335
398
  * 위 세 쌍의 콜백을 각각 다루는 대신 한 곳에서 "지금 보이는 열 구성"을 저장하고
@@ -411,5 +474,256 @@ declare const DataTable: <TRow extends {
411
474
  ref?: react.ForwardedRef<HTMLDivElement>;
412
475
  }) => react.ReactElement;
413
476
 
414
- export { DataTable };
415
- export type { DataTableColumn, DataTableColumnKind, DataTableProps, ToolbarFilter, ToolbarFilterOp, ToolbarSort, ToolbarSortDirection };
477
+ interface DataTableViewsControlProps extends UseDataTableViewsProps {
478
+ /** The trigger's label when no view is active. @default "Views" */
479
+ label?: string;
480
+ /** Renders an extra leading row in the popover that clears the active view (back to
481
+ * `label`'s own unfiltered state) -- omit (the default) when a consumer has no
482
+ * meaningful "no view" state to switch back to. */
483
+ showClearRow?: boolean;
484
+ /** The clear row's own label, when `showClearRow` is on. @default "label" */
485
+ clearLabel?: react.ReactNode;
486
+ /**
487
+ * Reads the table's CURRENT column order/visibility/widths/pins + toolbar sort/
488
+ * filter conditions -- called when the user picks "Save as new view" or "Update
489
+ * view". Build this from the same controlled state you pass to `<DataTable
490
+ * columnOrder=... toolbarSorts=... />` (or, uncontrolled, from `onColumnsChange`/
491
+ * `onToolbarSortsChange`/... mirrored into your own state).
492
+ */
493
+ captureState: () => DataTableViewState;
494
+ /** Applies a selected view's saved state back onto the table -- typically each of
495
+ * your own `setColumnOrder`/`setHiddenColumnKeys`/`setColumnWidths`/
496
+ * `setPinnedColumnKeys`/`setToolbarSorts`/`setToolbarFilters` setters, one per
497
+ * field present on `state` (every field is optional -- a view that only captured
498
+ * column layout should leave sort/filter alone). */
499
+ applyState: (state: DataTableViewState) => void;
500
+ newViewLabel?: string;
501
+ updateViewLabel?: string;
502
+ renameLabel?: string;
503
+ deleteLabel?: string;
504
+ /** aria-label for the rename text input, given the view's own name. */
505
+ renameInputLabel?: (name: string) => string;
506
+ }
507
+ /**
508
+ * A compact saved-views switcher -- current view name (or `label`) as the trigger,
509
+ * a popover listing every saved view (click to switch, inline Rename/Delete), a
510
+ * trailing "Save as new view", and (once a view is active) "Update view" to overwrite
511
+ * the loaded view with the table's current state.
512
+ */
513
+ declare function DataTableViewsControl({ label, showClearRow, clearLabel, captureState, applyState, newViewLabel, updateViewLabel, renameLabel, deleteLabel, renameInputLabel, ...viewsProps }: DataTableViewsControlProps): react_jsx_runtime.JSX.Element;
514
+ declare namespace DataTableViewsControl {
515
+ var displayName: string;
516
+ }
517
+
518
+ type ResizablePanelSide = "left" | "right";
519
+
520
+ type ResizablePanelHandleVariant = "panel" | "column";
521
+ type ResizablePanelProps = Omit<react.ComponentPropsWithoutRef<"div">, "children" | "onResize"> & {
522
+ /** Which edge of its container the panel is anchored to. @default "left" */
523
+ side?: ResizablePanelSide;
524
+ /** Controlled width, in px. */
525
+ width?: number;
526
+ /** Initial width, in px, when uncontrolled. @default 280 */
527
+ defaultSize?: number;
528
+ /** Fires with the next width on every drag move, and once more with the
529
+ * final, CSS-clamped width once a drag ends. */
530
+ onWidthChange?: (width: number) => void;
531
+ /** `min-width` in px. @default 200 */
532
+ min?: number;
533
+ /**
534
+ * `max-width` -- a px number, or a raw CSS expression for callers that
535
+ * need a real clamp, e.g. `max="min(60%, 100% - 350px)"`. Constraints are
536
+ * never re-applied in JS: the handler writes the unclamped drag width, and
537
+ * the browser's own `min-width`/`max-width` resolve the rendered size.
538
+ */
539
+ max?: number | string;
540
+ /**
541
+ * Layout model: "docked" (default) reserves flow width and sits in-line
542
+ * with a hairline border; "floating" takes the panel out of flow
543
+ * (`position: fixed`, an 8px gutter, r10, the measured floating shadow).
544
+ */
545
+ floating?: boolean;
546
+ /** Resize-handle geometry -- "panel" (default) or "column" (table edges). */
547
+ handleVariant?: ResizablePanelHandleVariant;
548
+ /**
549
+ * Renders the drag handle. `false` gives a fixed-width, non-interactive
550
+ * panel (e.g. `RecordPanel`'s own `resizable={false}` default) -- not part
551
+ * of crisp's own API, added here so a consumer built ON this primitive
552
+ * (like `RecordPanel`) can opt out of dragging entirely without crisp's
553
+ * duplicate resize-handle implementation. @default true
554
+ */
555
+ resizable?: boolean;
556
+ /**
557
+ * Persist width as a percentage of the container under this key (a `%`,
558
+ * not px, so the panel keeps its proportion on resize). Only applies when
559
+ * `width` is uncontrolled.
560
+ */
561
+ storageKey?: string;
562
+ className?: string;
563
+ children?: react.ReactNode;
564
+ };
565
+ /**
566
+ * An adjustable-panel primitive: a spacer that reserves layout width plus a
567
+ * panel that overlays it, so the panel can move between docked (in-flow) and
568
+ * floating (`position: fixed`, an overlay) without a reflow glitch. Drag the
569
+ * edge handle to resize; constraints are CSS `min-width`/`max-width`, never
570
+ * re-clamped in JS. Ported from your-moon/crisp's `ResizablePanel`
571
+ * (`components/resizablepanel/`); state/drag behavior lives in
572
+ * `useResizablePanel` (`@seed-design/react-resizable-panel`), this component
573
+ * owns the DOM + recipe classes on top of it.
574
+ */
575
+ declare const ResizablePanel: react.ForwardRefExoticComponent<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">, "children" | "onResize"> & {
576
+ /** Which edge of its container the panel is anchored to. @default "left" */
577
+ side?: ResizablePanelSide;
578
+ /** Controlled width, in px. */
579
+ width?: number;
580
+ /** Initial width, in px, when uncontrolled. @default 280 */
581
+ defaultSize?: number;
582
+ /** Fires with the next width on every drag move, and once more with the
583
+ * final, CSS-clamped width once a drag ends. */
584
+ onWidthChange?: (width: number) => void;
585
+ /** `min-width` in px. @default 200 */
586
+ min?: number;
587
+ /**
588
+ * `max-width` -- a px number, or a raw CSS expression for callers that
589
+ * need a real clamp, e.g. `max="min(60%, 100% - 350px)"`. Constraints are
590
+ * never re-applied in JS: the handler writes the unclamped drag width, and
591
+ * the browser's own `min-width`/`max-width` resolve the rendered size.
592
+ */
593
+ max?: number | string;
594
+ /**
595
+ * Layout model: "docked" (default) reserves flow width and sits in-line
596
+ * with a hairline border; "floating" takes the panel out of flow
597
+ * (`position: fixed`, an 8px gutter, r10, the measured floating shadow).
598
+ */
599
+ floating?: boolean;
600
+ /** Resize-handle geometry -- "panel" (default) or "column" (table edges). */
601
+ handleVariant?: ResizablePanelHandleVariant;
602
+ /**
603
+ * Renders the drag handle. `false` gives a fixed-width, non-interactive
604
+ * panel (e.g. `RecordPanel`'s own `resizable={false}` default) -- not part
605
+ * of crisp's own API, added here so a consumer built ON this primitive
606
+ * (like `RecordPanel`) can opt out of dragging entirely without crisp's
607
+ * duplicate resize-handle implementation. @default true
608
+ */
609
+ resizable?: boolean;
610
+ /**
611
+ * Persist width as a percentage of the container under this key (a `%`,
612
+ * not px, so the panel keeps its proportion on resize). Only applies when
613
+ * `width` is uncontrolled.
614
+ */
615
+ storageKey?: string;
616
+ className?: string;
617
+ children?: react.ReactNode;
618
+ } & react.RefAttributes<HTMLDivElement>>;
619
+
620
+ /** One Highlights card -- label, value and an optional icon, laid out the way
621
+ * Attio's own peek panel lays its own out (your-moon/crisp#448, measured
622
+ * live): a 2-column grid, no card chrome, a muted label row with a
623
+ * trailing icon, a filled-colour value below it. */
624
+ type RecordPanelHighlight = {
625
+ key: string;
626
+ label: string;
627
+ value: react.ReactNode;
628
+ icon?: react.ComponentType<{
629
+ size?: number;
630
+ }>;
631
+ };
632
+ /** One collapsed section below Activity (your-moon/crisp#413) -- Attio's own
633
+ * peek shows Emails/Notes/Tasks this way, each a label + a count, expanding
634
+ * into the consumer's own content when clicked. Omitting `content` renders
635
+ * the row but not as a button, matching the live DOM measured on an empty
636
+ * section: no chevron, no click handler, nothing to expand into yet. */
637
+ type RecordPanelSection = {
638
+ key: string;
639
+ label: string;
640
+ count: number;
641
+ content?: react.ReactNode;
642
+ };
643
+ /** The record this panel previews. Only `name` is read directly here --
644
+ * everything else the panel shows comes from `highlights`/`activity`/
645
+ * `sections`, the consumer's own data. Unlike crisp's own `RecordPanel`
646
+ * (which reads `Row` from `product/recordpage/column`), this port has no
647
+ * such type to depend on -- crispy-seed has no RecordPage -- so this stays
648
+ * a minimal, consumer-extendable shape. */
649
+ type RecordPanelRecord = {
650
+ name?: string;
651
+ [key: string]: unknown;
652
+ };
653
+ type RecordPanelProps = Omit<react.ComponentPropsWithoutRef<"div">, "children" | "title" | "onResize"> & {
654
+ /** Whether the panel is mounted/visible. */
655
+ open: boolean;
656
+ onClose: () => void;
657
+ /** Label for the close control. */
658
+ closeLabel?: string;
659
+ /**
660
+ * A toolbar row above the panel's own identity header (your-moon/crisp#601,
661
+ * measured live on app.attio.com's peek): Close, then Previous/Next on the
662
+ * left, an "Open record" icon on the right. Close always renders
663
+ * (`onClose` is required); Previous/Next/Open record each render only when
664
+ * given a handler.
665
+ */
666
+ onOpenRecord?: () => void;
667
+ openRecordLabel?: string;
668
+ onPrevious?: () => void;
669
+ previousRecordLabel?: string;
670
+ onNext?: () => void;
671
+ nextRecordLabel?: string;
672
+ /** "2 of 37 in All Companies" (your-moon/crisp#413) -- a single
673
+ * pre-formatted string; omit for no counter at all. */
674
+ counterLabel?: react.ReactNode;
675
+ /**
676
+ * Lets a person drag the panel wider or narrower from its own left edge --
677
+ * this port reuses `ResizablePanel`'s own handle (`side="right"`, whose
678
+ * handle sits at the panel's inline-start/left edge, the same physical
679
+ * position crisp's own hand-rolled resize strip measured). Uncontrolled by
680
+ * default; pass `width`/`onWidthChange` together to own it instead.
681
+ * @default false
682
+ */
683
+ resizable?: boolean;
684
+ width?: number;
685
+ defaultWidth?: number;
686
+ onWidthChange?: (width: number) => void;
687
+ minWidth?: number;
688
+ maxWidth?: number;
689
+ /** The panel's heading, and so its accessible name. Defaults to `record.name`. */
690
+ title?: react.ReactNode;
691
+ /** Avatar image URL beside the title. Omit for an initials tile built from
692
+ * `record.name`'s first character. */
693
+ avatar?: string;
694
+ /** The record to show; renders nothing when `open` is false or `record`
695
+ * is null. */
696
+ record: RecordPanelRecord | null;
697
+ /** Heading above the highlight cards (default "Highlights"). Omit the
698
+ * whole section by omitting `highlights`. */
699
+ highlightsLabel?: react.ReactNode;
700
+ highlights?: RecordPanelHighlight[];
701
+ /** Heading above the activity feed (default "Activity"). */
702
+ activityLabel?: react.ReactNode;
703
+ viewAllActivityLabel?: react.ReactNode;
704
+ onViewAllActivity?: () => void;
705
+ activity?: react.ReactNode;
706
+ /** Collapsed sections below Activity (your-moon/crisp#413). Omit for no
707
+ * sections at all. */
708
+ sections?: RecordPanelSection[];
709
+ /** Rendered below the panel's content, e.g. an Edit button. */
710
+ footer?: react.ReactNode;
711
+ className?: string;
712
+ };
713
+ /**
714
+ * Right-side record peek panel -- Attio's own peek shows a Highlights card
715
+ * area and an Activity feed (measured live). Ported from your-moon/crisp's
716
+ * `RecordPanel` (`product/recordpanel/`), built ON `ResizablePanel`
717
+ * (`side="right" floating`) rather than crisp's own duplicate absolute-
718
+ * positioning/slide-in/resize-handle implementation -- the outer shell (the
719
+ * `@starting-style` slide-in, the floating elevation, the drag handle
720
+ * itself) all come from that primitive; this component only renders the
721
+ * CONTENT inside it.
722
+ */
723
+ declare function RecordPanel({ open, record, onClose, className, closeLabel, onOpenRecord, openRecordLabel, onPrevious, previousRecordLabel, onNext, nextRecordLabel, title, avatar, highlightsLabel, highlights, counterLabel, resizable, width, defaultWidth, onWidthChange, minWidth, maxWidth, activityLabel, viewAllActivityLabel, onViewAllActivity, activity, sections, footer, ...rest }: RecordPanelProps): react_jsx_runtime.JSX.Element | null;
724
+ declare namespace RecordPanel {
725
+ var displayName: string;
726
+ }
727
+
728
+ export { DataTable, DataTableViewsControl, RecordPanel, ResizablePanel };
729
+ export type { DataTableColumn, DataTableColumnKind, DataTableProps, DataTableView, DataTableViewState, DataTableViewsControlProps, RecordPanelHighlight, RecordPanelProps, RecordPanelRecord, RecordPanelSection, ResizablePanelHandleVariant, ResizablePanelProps, ResizablePanelSide, ToolbarFilter, ToolbarFilterOp, ToolbarSort, ToolbarSortDirection };