blacksmithgu / datacore

Work-in-progress successor to Dataview with a focus on UX and speed.
MIT License
1.4k stars 14 forks source link

separate interface for pagination #28

Closed GamerGirlandCo closed 2 months ago

GamerGirlandCo commented 11 months ago

all the views currently implemented (List and Table) have pagination props:

https://github.com/blacksmithgu/datacore/blob/b6d7ed7c0480ee2879162499388ea18da793b583/src/ui/table.tsx#L31-L40

i was thinking, maybe we could move these to a separate interface, and have TableProps and ListState extend said interface, to avoid repitition.

what do you think?

GamerGirlandCo commented 11 months ago

something like

export interface Pagination {
     /** 
      * If a boolean, enables/disables paging with the default configuration. If a number, paging will be 
      * enabled with the given number of entries per page. 
      */ 
     paging?: number | boolean; 

     /** The initial page of the table. */ 
     initialPage?: number; 
     /** Controlled prop for setting the page of the table. */ 
     page?: number;
}

which could then be extended like this

export interface TableProps<T> extends Pagination {
// ...
}
blacksmithgu commented 9 months ago

It saves some typing, but the main benefit of extracting is if we can actually write generic code that just needs Pagination; is there anywhere where we would benefit doing this?

GamerGirlandCo commented 9 months ago

It saves some typing, but the main benefit of extracting is if we can actually write generic code that just needs Pagination; is there anywhere where we would benefit doing this?

i'm experimenting with creating a generic usePagination hook. as of right now, the only place where it doesn't work is the table component

blacksmithgu commented 2 months ago

I've added a usePaging hook for these purposes... can review if having a paging interface is useful in the future.