-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components): use gridjs for mutation table
- Loading branch information
1 parent
f1171fc
commit 0c9134a
Showing
10 changed files
with
372 additions
and
172 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
24 changes: 24 additions & 0 deletions
24
components/src/components/container/component-table.stories.ts
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,24 @@ | ||
import { html } from 'lit'; | ||
import { Meta, StoryObj } from '@storybook/web-components'; | ||
import './component-table'; | ||
|
||
const meta: Meta = { | ||
title: 'Component/Table', | ||
component: 'gs-component-table', | ||
parameters: { fetchMock: {} }, | ||
}; | ||
|
||
export default meta; | ||
|
||
export const ComponentTableStory: StoryObj = { | ||
render: (args) => { | ||
return html` <gs-component-table .data=${args.data} .columns=${args.columns}></gs-component-table> `; | ||
}, | ||
args: { | ||
data: [ | ||
['John Do', 'john@example.com', '123-456-7890'], | ||
['Jane Doe', 'jane@example.com', '098-765-4321'], | ||
], | ||
columns: [{ name: 'Name' }, { name: 'Email', sort: false }, { name: 'Phone Number' }], | ||
}, | ||
}; |
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,70 @@ | ||
import { html, LitElement, unsafeCSS } from 'lit'; | ||
import { customElement, property, query } from 'lit/decorators.js'; | ||
|
||
import { Grid } from 'gridjs'; | ||
import 'gridjs/dist/theme/mermaid.css'; | ||
|
||
import style from 'gridjs/dist/theme/mermaid.css?inline'; | ||
import { OneDArray, TColumn, TData } from 'gridjs/dist/src/types'; | ||
import { ComponentChild } from 'preact'; | ||
import { PaginationConfig } from 'gridjs/dist/src/view/plugin/pagination'; | ||
|
||
const tableFontSize = '12px'; | ||
|
||
export const tableStyle = { | ||
table: { | ||
'font-size': tableFontSize, | ||
}, | ||
th: { | ||
padding: '4px', | ||
textAlign: 'center', | ||
}, | ||
td: { | ||
textAlign: 'center', | ||
padding: '8px', | ||
}, | ||
footer: { | ||
'font-size': tableFontSize, | ||
}, | ||
}; | ||
|
||
@customElement('gs-component-table') | ||
export class ComponentTable extends LitElement { | ||
@property({ type: Array }) | ||
data: TData = []; | ||
|
||
@property({ type: Array }) | ||
columns: OneDArray<TColumn | string | ComponentChild> = []; | ||
|
||
@property({ type: Object }) | ||
pagination: PaginationConfig | boolean = true; | ||
|
||
private grid: Grid | undefined; | ||
|
||
static override styles = unsafeCSS(style); | ||
|
||
@query('#grid-table') tableContainer!: HTMLElement; | ||
|
||
override firstUpdated() { | ||
this.grid = new Grid({ | ||
columns: this.columns, | ||
data: this.data, | ||
pagination: this.pagination, | ||
style: tableStyle, | ||
}); | ||
|
||
this.grid.render(this.tableContainer); | ||
} | ||
|
||
override updated() { | ||
this.grid?.updateConfig({ | ||
columns: this.columns, | ||
data: this.data, | ||
pagination: this.pagination, | ||
}); | ||
} | ||
|
||
override render() { | ||
return html` <div id="grid-table"></div> `; | ||
} | ||
} |
Oops, something went wrong.