Skip to content

Commit f358b68

Browse files
committed
feat: update sortable
1 parent c868da0 commit f358b68

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

docs/registry/default/ui/kanban.tsx

+16-9
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,22 @@ function useKanbanContext(name: keyof typeof KANBAN_ERROR) {
7777
return context;
7878
}
7979

80-
type KanbanProps<T> = Omit<DndContextProps, "collisionDetection"> & {
81-
value: Record<UniqueIdentifier, T[]>;
82-
onValueChange?: (columns: Record<UniqueIdentifier, T[]>) => void;
83-
onMove?: (event: DragEndEvent) => void;
84-
strategy?: SortableContextProps["strategy"];
85-
flatCursor?: boolean;
86-
} & (T extends object
87-
? { getItemValue: (item: T) => UniqueIdentifier }
88-
: { getItemValue?: (item: T) => UniqueIdentifier });
80+
interface GetItemValue<T> {
81+
/**
82+
* Callback that returns a unique identifier for each kanban item. Required for array of objects.
83+
* @example getItemValue={(item) => item.id}
84+
*/
85+
getItemValue: (item: T) => UniqueIdentifier;
86+
}
87+
88+
type KanbanProps<T> = Omit<DndContextProps, "collisionDetection"> &
89+
GetItemValue<T> & {
90+
value: Record<UniqueIdentifier, T[]>;
91+
onValueChange?: (columns: Record<UniqueIdentifier, T[]>) => void;
92+
onMove?: (event: DragEndEvent) => void;
93+
strategy?: SortableContextProps["strategy"];
94+
flatCursor?: boolean;
95+
} & (T extends object ? GetItemValue<T> : Partial<GetItemValue<T>>);
8996

9097
function Kanban<T>(props: KanbanProps<T>) {
9198
const {

docs/registry/default/ui/sortable.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,22 @@ function useSortableContext(name: keyof typeof SORTABLE_ERROR) {
9494
return context;
9595
}
9696

97+
interface GetItemValue<T> {
98+
/**
99+
* Callback that returns a unique identifier for each sortable item. Required for array of objects.
100+
* @example getItemValue={(item) => item.id}
101+
*/
102+
getItemValue: (item: T) => UniqueIdentifier;
103+
}
104+
97105
type SortableProps<T> = DndContextProps & {
98106
value: T[];
99107
onValueChange?: (items: T[]) => void;
100108
onMove?: (event: DragEndEvent) => void;
101109
strategy?: SortableContextProps["strategy"];
102110
orientation?: "vertical" | "horizontal" | "mixed";
103111
flatCursor?: boolean;
104-
} & (T extends object
105-
? { getItemValue: (item: T) => UniqueIdentifier }
106-
: { getItemValue?: (item: T) => UniqueIdentifier });
112+
} & (T extends object ? GetItemValue<T> : Partial<GetItemValue<T>>);
107113

108114
function Sortable<T>(props: SortableProps<T>) {
109115
const {

docs/types/docs/sortable.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface RootProps<TData> extends DndContextProps {
2727
onValueChange?: (items: TData[]) => void;
2828

2929
/**
30-
* A function that returns a unique identifier for each sortable item.
30+
* Callback that returns a unique identifier for each sortable item.
3131
*
3232
* Required when using an array of objects.
3333
*

0 commit comments

Comments
 (0)