-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bryan Lee
committed
May 27, 2022
1 parent
a9b15bd
commit eab7187
Showing
3 changed files
with
110 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import type { | ||
TableAttributes, | ||
TableBodyAttributes, | ||
TableHeadAttributes, | ||
} from '$lib/createViewModel'; | ||
import type { DeriveFn, NewTablePropSet, TablePlugin } from '$lib/types/TablePlugin'; | ||
import { derived } from 'svelte/store'; | ||
|
||
export const addGridLayout = | ||
<Item>(): TablePlugin< | ||
Item, | ||
Record<string, never>, | ||
Record<string, never>, | ||
NewTablePropSet<never> | ||
> => | ||
({ tableState }) => { | ||
const pluginState = {}; | ||
|
||
const deriveTableAttrs: DeriveFn<TableAttributes<Item>> = (attrs) => { | ||
return derived([attrs, tableState.visibleColumns], ([$attrs, $visibleColumns]) => { | ||
return { | ||
...$attrs, | ||
style: { | ||
display: 'grid', | ||
'grid-template-columns': `repeat(${$visibleColumns.length}, auto)`, | ||
}, | ||
}; | ||
}); | ||
}; | ||
|
||
const deriveTableHeadAttrs: DeriveFn<TableHeadAttributes<Item>> = (attrs) => { | ||
return derived(attrs, ($attrs) => { | ||
return { | ||
...$attrs, | ||
style: { | ||
display: 'contents', | ||
}, | ||
}; | ||
}); | ||
}; | ||
|
||
const deriveTableBodyAttrs: DeriveFn<TableBodyAttributes<Item>> = (attrs) => { | ||
return derived(attrs, ($attrs) => { | ||
return { | ||
...$attrs, | ||
style: { | ||
display: 'contents', | ||
}, | ||
}; | ||
}); | ||
}; | ||
|
||
return { | ||
pluginState, | ||
deriveTableAttrs, | ||
deriveTableHeadAttrs, | ||
deriveTableBodyAttrs, | ||
hooks: { | ||
'thead.tr': () => { | ||
const attrs = derived([], () => { | ||
return { | ||
style: { | ||
display: 'contents', | ||
}, | ||
}; | ||
}); | ||
return { attrs }; | ||
}, | ||
'thead.tr.th': (cell) => { | ||
const attrs = derived([], () => { | ||
return { | ||
style: { | ||
'grid-column': `${cell.colstart + 1} / span ${cell.colspan}`, | ||
}, | ||
}; | ||
}); | ||
return { attrs }; | ||
}, | ||
'tbody.tr': () => { | ||
const attrs = derived([], () => { | ||
return { | ||
style: { | ||
display: 'contents', | ||
}, | ||
}; | ||
}); | ||
return { attrs }; | ||
}, | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters