Commit f358b68 1 parent c868da0 commit f358b68 Copy full SHA for f358b68
File tree 3 files changed +26
-13
lines changed
3 files changed +26
-13
lines changed Original file line number Diff line number Diff line change @@ -77,15 +77,22 @@ function useKanbanContext(name: keyof typeof KANBAN_ERROR) {
77
77
return context ;
78
78
}
79
79
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 > > ) ;
89
96
90
97
function Kanban < T > ( props : KanbanProps < T > ) {
91
98
const {
Original file line number Diff line number Diff line change @@ -94,16 +94,22 @@ function useSortableContext(name: keyof typeof SORTABLE_ERROR) {
94
94
return context ;
95
95
}
96
96
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
+
97
105
type SortableProps < T > = DndContextProps & {
98
106
value : T [ ] ;
99
107
onValueChange ?: ( items : T [ ] ) => void ;
100
108
onMove ?: ( event : DragEndEvent ) => void ;
101
109
strategy ?: SortableContextProps [ "strategy" ] ;
102
110
orientation ?: "vertical" | "horizontal" | "mixed" ;
103
111
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 > > ) ;
107
113
108
114
function Sortable < T > ( props : SortableProps < T > ) {
109
115
const {
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ export interface RootProps<TData> extends DndContextProps {
27
27
onValueChange ?: ( items : TData [ ] ) => void ;
28
28
29
29
/**
30
- * A function that returns a unique identifier for each sortable item.
30
+ * Callback that returns a unique identifier for each sortable item.
31
31
*
32
32
* Required when using an array of objects.
33
33
*
You can’t perform that action at this time.
0 commit comments