Skip to content

Commit

Permalink
Merge pull request #12 from bryanmylee/rename-plugins
Browse files Browse the repository at this point in the history
rename: useX -> addX
  • Loading branch information
bryanmylee authored May 16, 2022
2 parents 5337014 + babad90 commit 975c357
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 47 deletions.
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ Svelte Headless Table is designed with extensibility in mind. Its complex featur
### Plugin roadmap

- [x] [useSortBy](https://svelte-headless-table.bryanmylee.com/docs/plugins/use-sort-by)
- [x] [useColumnFilters](https://svelte-headless-table.bryanmylee.com/docs/plugins/use-column-filters)
- [x] [useTableFilter](https://svelte-headless-table.bryanmylee.com/docs/plugins/use-table-filter)
- [x] [useColumnOrder](https://svelte-headless-table.bryanmylee.com/docs/plugins/use-column-order)
- [x] [useHiddenColumns](https://svelte-headless-table.bryanmylee.com/docs/plugins/use-hidden-columns)
- [x] [usePagination](https://svelte-headless-table.bryanmylee.com/docs/plugins/use-pagination)
- [ ] useGroupBy
- [ ] useExpanded
- [ ] useRowSelect
- [ ] useResizeColumns
- [ ] useEditable
- [ ] useRowLabel
- [x] [addSortBy](https://svelte-headless-table.bryanmylee.com/docs/plugins/add-sort-by)
- [x] [addColumnFilters](https://svelte-headless-table.bryanmylee.com/docs/plugins/add-column-filters)
- [x] [addTableFilter](https://svelte-headless-table.bryanmylee.com/docs/plugins/add-table-filter)
- [x] [addColumnOrder](https://svelte-headless-table.bryanmylee.com/docs/plugins/add-column-order)
- [x] [addHiddenColumns](https://svelte-headless-table.bryanmylee.com/docs/plugins/add-hidden-columns)
- [x] [addPagination](https://svelte-headless-table.bryanmylee.com/docs/plugins/add-pagination)
- [x] [addSubRows](https://svelte-headless-table.bryanmylee.com/docs/plugins/add-sub-rows)
- [x] [addExpandedRows](https://svelte-headless-table.bryanmylee.com/docs/plugins/add-expanded-rows)
- [ ] addGroupBy
- [ ] addRowSelect
- [ ] addResizeColumns
- [ ] addEditable
- [ ] addRowLabel
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const getFilteredRows = <Item, Row extends BodyRow<Item>>(
return _filteredRows;
};

export const useColumnFilters =
export const addColumnFilters =
<Item>(): TablePlugin<
Item,
ColumnFiltersState<Item>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface ColumnOrderState {
columnIdOrder: Writable<string[]>;
}

export const useColumnOrder =
export const addColumnOrder =
<Item>({
initialColumnIdOrder = [],
hideUnspecifiedColumns = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const withExpandedRows = <Item, Row extends BodyRow<Item>>(
return [row, ...expandedSubRows];
};

export const useExpandedRows =
export const addExpandedRows =
<Item>({
initialExpandedIds = {},
}: ExpandedRowsConfig<Item>): TablePlugin<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface HiddenColumnsState {
hiddenColumnIds: Writable<string[]>;
}

export const useHiddenColumns =
export const addHiddenColumns =
<Item>({ initialHiddenColumnIds = [] }: HiddenColumnsConfig = {}): TablePlugin<
Item,
HiddenColumnsState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface PaginationState {

const MIN_PAGE_SIZE = 1;

export const usePageStore = ({ items, initialPageSize, initialPageIndex }: PageStoreConfig) => {
export const createPageStore = ({ items, initialPageSize, initialPageIndex }: PageStoreConfig) => {
const pageSize = writable(initialPageSize);
const updatePageSize = (fn: Updater<number>) => {
pageSize.update(($pageSize) => {
Expand Down Expand Up @@ -66,7 +66,7 @@ export interface PageStoreConfig {
initialPageIndex?: number;
}

export const usePagination =
export const addPagination =
<Item>({ initialPageIndex = 0, initialPageSize = 10 }: PaginationConfig = {}): TablePlugin<
Item,
PaginationState,
Expand All @@ -76,7 +76,7 @@ export const usePagination =
() => {
const prePaginatedRows = writable<BodyRow<Item>[]>([]);
const paginatedRows = writable<BodyRow<Item>[]>([]);
const { pageSize, pageCount, pageIndex, hasPreviousPage, hasNextPage } = usePageStore({
const { pageSize, pageCount, pageIndex, hasPreviousPage, hasNextPage } = createPageStore({
items: prePaginatedRows,
initialPageIndex,
initialPageSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const getSortedRows = <Item, Row extends BodyRow<Item>>(
return _sortedRows;
};

export const useSortBy =
export const addSortBy =
<Item>({
initialSortKeys = [],
disableMultiSort = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const withSubRows = <Item, Row extends BodyRow<Item>>(
return row;
};

export const useSubRows =
export const addSubRows =
<Item>({
children,
}: SubRowsConfig<Item>): TablePlugin<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const getFilteredRows = <Item, Row extends BodyRow<Item>>(
return _filteredRows;
};

export const useTableFilter =
export const addTableFilter =
<Item>({
fn = textPrefixFilter,
initialFilterValue = '',
Expand Down
18 changes: 9 additions & 9 deletions src/lib/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export {
useColumnFilters,
addColumnFilters,
matchFilter,
numberRangeFilter,
textPrefixFilter,
type ColumnFilterFn,
type ColumnFilterFnProps,
} from './useColumnFilters';
export { useColumnOrder } from './useColumnOrder';
export { useHiddenColumns } from './useHiddenColumns';
export { usePagination } from './usePagination';
export { useSortBy } from './useSortBy';
export { useTableFilter } from './useTableFilter';
export { useExpandedRows } from './useExpandedRows';
export { useSubRows } from './useSubRows';
} from './addColumnFilters';
export { addColumnOrder } from './addColumnOrder';
export { addHiddenColumns } from './addHiddenColumns';
export { addPagination } from './addPagination';
export { addSortBy } from './addSortBy';
export { addTableFilter } from './addTableFilter';
export { addExpandedRows } from './addExpandedRows';
export { addSubRows } from './addSubRows';
32 changes: 16 additions & 16 deletions src/routes/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
import { derived, readable } from 'svelte/store';
import { Render, Subscribe, createTable, createRender } from '$lib';
import {
useColumnFilters,
useColumnOrder,
useHiddenColumns,
useSortBy,
useTableFilter,
usePagination,
useExpandedRows,
addColumnFilters,
addColumnOrder,
addHiddenColumns,
addSortBy,
addTableFilter,
addPagination,
addExpandedRows,
matchFilter,
numberRangeFilter,
textPrefixFilter,
useSubRows,
addSubRows,
} from '$lib/plugins';
import { getShuffled } from './_getShuffled';
import { createSamples } from './_createSamples';
Expand All @@ -27,20 +27,20 @@
const data = readable(createSamples(10, 5, 5));
const table = createTable(data, {
subRows: useSubRows({
subRows: addSubRows({
children: 'children',
}),
sort: useSortBy(),
filter: useColumnFilters(),
tableFilter: useTableFilter({
sort: addSortBy(),
filter: addColumnFilters(),
tableFilter: addTableFilter({
includeHiddenColumns: true,
}),
expand: useExpandedRows({
expand: addExpandedRows({
initialExpandedIds: { 1: true },
}),
orderColumns: useColumnOrder(),
hideColumns: useHiddenColumns(),
page: usePagination({
orderColumns: addColumnOrder(),
hideColumns: addHiddenColumns(),
page: addPagination({
initialPageSize: 20,
}),
});
Expand Down

0 comments on commit 975c357

Please sign in to comment.