-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: added sticky last column * feat: added full story
- Loading branch information
1 parent
bdbfd56
commit 96e67ed
Showing
11 changed files
with
175 additions
and
116 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import {html} from 'lit'; | ||
import {Meta, Canvas, ArgsTable, Story} from '@storybook/addon-docs'; | ||
import {userEvent} from '@storybook/testing-library'; | ||
import { UPDATE_STORY_ARGS } from "@storybook/core-events"; | ||
|
||
<Meta | ||
title="Components/Table/bl-table" | ||
|
@@ -17,53 +17,79 @@ import {userEvent} from '@storybook/testing-library'; | |
}} | ||
/> | ||
|
||
export const TableTemplate = (args) => html` | ||
<div style="height: 400px;"> | ||
<bl-table | ||
select-value=[0,1] | ||
?selectable=${true} | ||
?multiple=${false} | ||
?sortable=${true} | ||
?sticky-first-column=${true} | ||
?sticky-last-column=${false} | ||
@bl-table-sort=${console.log} | ||
> | ||
<bl-table-header ?sticky=${args.stickyHeader}> | ||
<bl-table-row> | ||
${args.headers.map((header) => | ||
html`<bl-table-header-cell | ||
?sortable=${header.sortable} | ||
sort-key='${header.sortKey}' | ||
style='${header.width?'--bl-table-header-cell-width: '+header.width+';': ''} ${header.minWidth?'--bl-table-header-cell-min-width: '+header.minWidth+';': ''}' | ||
> | ||
${header.text} | ||
</bl-table-header-cell>` | ||
)} | ||
</bl-table-row> | ||
</bl-table-header> | ||
<bl-table-body> | ||
${args.data.map((row) => | ||
html` | ||
<bl-table-row> | ||
${args.headers.map((header, col_idx) => | ||
html` | ||
<bl-table-cell ?disable-selection=${col_idx===0&&row.disabled}> | ||
${row[header.key]} | ||
</bl-table-cell> | ||
` | ||
)} | ||
</bl-table-row> | ||
` | ||
)} | ||
</bl-table-body> | ||
</bl-table> | ||
</div> | ||
`; | ||
export const TableTemplate = (args, {id}) => { | ||
const updateArgs = (_args)=>{ | ||
window.__STORYBOOK_ADDONS_CHANNEL__.emit(UPDATE_STORY_ARGS, { | ||
storyId: id, | ||
updatedArgs: _args, | ||
}); | ||
|
||
} | ||
let {data, headers, selectValue} = args; | ||
const onSort = (event) => { | ||
const [sortKey, sortDirection] = event.detail; | ||
console.log("onSort", event.detail); | ||
updateArgs({ | ||
...args, | ||
data: data.sort((a, b) => { | ||
return a[sortKey].toString().localeCompare(b[sortKey], 'tr', {sensitivity: 'base'}) * (sortDirection === 'asc' ? -1 : 1); | ||
}), | ||
}); | ||
|
||
export const focusSecondOption = async ({}) => { | ||
await userEvent.tab(); | ||
await userEvent.keyboard('{ArrowRight}'); | ||
console.log(data) | ||
} | ||
const onRowSelect = (event) => { | ||
console.log("onRowSelect", event.detail); | ||
updateArgs({ | ||
...args, | ||
selectValue: event.detail, | ||
}); | ||
} | ||
|
||
return html` | ||
<div style="height: 400px;"> | ||
<bl-table | ||
select-value=${JSON.stringify(selectValue)} | ||
?selectable=${true} | ||
?multiple=${true} | ||
?sortable=${true} | ||
?sticky-first-column=${true} | ||
?sticky-last-column=${true} | ||
@bl-table-sort=${onSort} | ||
@bl-table-row-select=${onRowSelect} | ||
> | ||
<bl-table-header ?sticky=${args.stickyHeader}> | ||
<bl-table-row> | ||
${args.headers.map((header) => | ||
html` | ||
<bl-table-header-cell | ||
?sortable=${header.sortable} | ||
sort-key='${header.sortKey}' | ||
style='${header.width ? '--bl-table-header-cell-width: ' + header.width + ';' : ''} ${header.minWidth ? '--bl-table-header-cell-min-width: ' + header.minWidth + ';' : ''}' | ||
> | ||
${header.text} | ||
</bl-table-header-cell>` | ||
)} | ||
</bl-table-row> | ||
</bl-table-header> | ||
<bl-table-body> | ||
${data.map((row) => | ||
html` | ||
<bl-table-row selection-key="row-${row.id}"> | ||
${headers.map((header, col_idx) => | ||
html` | ||
<bl-table-cell ?disable-selection=${col_idx === 0 && row.disabled}> | ||
${row[header.key]} | ||
</bl-table-cell> | ||
` | ||
)} | ||
</bl-table-row> | ||
` | ||
)} | ||
</bl-table-body> | ||
</bl-table> | ||
</div> | ||
`; | ||
} | ||
|
||
# Table Component | ||
|
@@ -81,16 +107,16 @@ If you set a list of `values`, options with those values will be selected. | |
{key: "gender", text: "Gender", width: '85px'}, | ||
{key: "ip_address", text: "IP Address", width: '90px', sticky: 'right'}, | ||
], | ||
data: Array(1) | ||
.fill([ | ||
{ | ||
id: 1, | ||
first_name: "Antonella", | ||
last_name: "Bellefonte", | ||
email: "[email protected]", | ||
gender: "Female", | ||
ip_address: "193.108.174.118" | ||
}, | ||
selectValue: ["row-1","row-4"], | ||
data: [ | ||
{ | ||
id: 1, | ||
first_name: "Antonella", | ||
last_name: "Bellefonte", | ||
email: "[email protected]", | ||
gender: "Female", | ||
ip_address: "193.108.174.118" | ||
}, | ||
{id:2,first_name:"Wash",last_name:"Carnson",email:"[email protected]",gender:"Male",ip_address:"255.169.128.60"}, | ||
{id:3,first_name:"Betteanne",last_name:"Cowgill",email:"[email protected]",gender:"Female",ip_address:"235.237.3.233", disabled: true}, | ||
{id:4,first_name:"Lilith",last_name:"Astbury",email:"[email protected]",gender:"Female",ip_address:"46.41.60.65"}, | ||
|
@@ -110,8 +136,7 @@ If you set a list of `values`, options with those values will be selected. | |
{id:18,first_name:"Germana",last_name:"Downing",email:"[email protected]",gender:"Female",ip_address:"55.83.134.58"}, | ||
{id:19,first_name:"Kizzie",last_name:"Pyzer",email:"[email protected]",gender:"Female",ip_address:"84.92.93.248"}, | ||
{id:20,first_name:"Almire",last_name:"Slinn",email:"[email protected]",gender:"Female",ip_address:"195.56.102.224"}, | ||
]) | ||
.reduce((a, b)=>a.concat(b), []), | ||
], | ||
stickyHeader:true | ||
}}> | ||
{TableTemplate.bind({})} | ||
|
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
Oops, something went wrong.