-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat(table): S2 tableview custom column menu #7617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2f2da02
S2 TableView custom column menus
snowystinger 4fc2b6e
Fix lint
snowystinger e6c04fe
Merge branch 'main' into s2-tableview-custom-column-menu
ktabors 1682ec4
Update TableView.tsx
snowystinger d027c92
fix styles and empty section
snowystinger f975d06
fix lint
snowystinger f256395
Merge branch 'main' into s2-tableview-custom-column-menu
snowystinger 2764778
chnage prop name, description, internal component name
snowystinger 2ea2c08
Add better string
snowystinger d246fcc
add unstable prefix
snowystinger 1b8dfff
Merge branch 'main' into s2-tableview-custom-column-menu
snowystinger 76c3578
fix storybook
snowystinger 5e4ba24
Merge branch 'main' into s2-tableview-custom-column-menu
snowystinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -11,8 +11,9 @@ | |
*/ | ||
|
||
import {action} from '@storybook/addon-actions'; | ||
import {ActionButton, Cell, Column, Content, Heading, IllustratedMessage, Link, Row, TableBody, TableHeader, TableView} from '../src'; | ||
import {ActionButton, Cell, Column, Content, Heading, IllustratedMessage, Link, MenuItem, MenuSection, Row, TableBody, TableHeader, TableView, Text} from '../src'; | ||
import {categorizeArgTypes} from './utils'; | ||
import Filter from '../s2wf-icons/S2_Icon_Filter_20_N.svg'; | ||
import FolderOpen from '../spectrum-illustrations/linear/FolderOpen'; | ||
import type {Meta} from '@storybook/react'; | ||
import {SortDescriptor} from 'react-aria-components'; | ||
|
@@ -151,6 +152,94 @@ const DynamicTable = (args: any) => ( | |
</TableView> | ||
); | ||
|
||
|
||
const DynamicTableWithCustomMenus = (args: any) => ( | ||
<TableView aria-label="Dynamic table" {...args} styles={style({width: 320, height: 208})}> | ||
<TableHeader columns={columns}> | ||
{(column) => ( | ||
<Column | ||
width={150} | ||
minWidth={150} | ||
isRowHeader={column.isRowHeader} | ||
menu={ | ||
<> | ||
<MenuSection> | ||
<MenuItem onAction={action('filter')}><Filter /><Text slot="label">Filter</Text></MenuItem> | ||
</MenuSection> | ||
snowystinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<MenuSection> | ||
<MenuItem onAction={action('hide column')}><Text slot="label">Hide column</Text></MenuItem> | ||
<MenuItem onAction={action('manage columns')}><Text slot="label">Manage columns</Text></MenuItem> | ||
</MenuSection> | ||
</> | ||
}>{column.name}</Column> | ||
)} | ||
</TableHeader> | ||
<TableBody items={items}> | ||
{item => ( | ||
<Row id={item.id} columns={columns}> | ||
{(column) => { | ||
return <Cell>{item[column.id]}</Cell>; | ||
}} | ||
</Row> | ||
)} | ||
</TableBody> | ||
</TableView> | ||
); | ||
|
||
let sortItems = items; | ||
const DynamicSortableTableWithCustomMenus = (args: any) => { | ||
let [items, setItems] = useState(sortItems); | ||
let [sortDescriptor, setSortDescriptor] = useState({}); | ||
let onSortChange = (sortDescriptor: SortDescriptor) => { | ||
let {direction = 'ascending', column = 'name'} = sortDescriptor; | ||
|
||
let sorted = items.slice().sort((a, b) => { | ||
let cmp = a[column] < b[column] ? -1 : 1; | ||
if (direction === 'descending') { | ||
cmp *= -1; | ||
} | ||
return cmp; | ||
}); | ||
|
||
setItems(sorted); | ||
setSortDescriptor(sortDescriptor); | ||
}; | ||
|
||
return ( | ||
<TableView aria-label="Dynamic table" {...args} sortDescriptor={sortDescriptor} onSortChange={onSortChange} styles={style({width: 320, height: 208})}> | ||
<TableHeader columns={columns}> | ||
{(column) => ( | ||
<Column | ||
allowsSorting | ||
width={150} | ||
minWidth={150} | ||
isRowHeader={column.isRowHeader} | ||
menu={ | ||
<> | ||
<MenuSection> | ||
<MenuItem onAction={action('filter')}><Filter /><Text slot="label">Filter</Text></MenuItem> | ||
</MenuSection> | ||
<MenuSection> | ||
<MenuItem onAction={action('hide column')}><Text slot="label">Hide column</Text></MenuItem> | ||
<MenuItem onAction={action('manage columns')}><Text slot="label">Manage columns</Text></MenuItem> | ||
</MenuSection> | ||
</> | ||
}>{column.name}</Column> | ||
)} | ||
</TableHeader> | ||
<TableBody items={items}> | ||
{item => ( | ||
<Row id={item.id} columns={columns}> | ||
{(column) => { | ||
return <Cell>{item[column.id]}</Cell>; | ||
}} | ||
</Row> | ||
)} | ||
</TableBody> | ||
</TableView> | ||
); | ||
}; | ||
|
||
export const Dynamic = { | ||
render: DynamicTable, | ||
args: { | ||
|
@@ -159,6 +248,22 @@ export const Dynamic = { | |
} | ||
}; | ||
|
||
export const DynamicCustomMenus = { | ||
render: DynamicTableWithCustomMenus, | ||
args: { | ||
...Example.args, | ||
disabledKeys: ['Foo 5'] | ||
} | ||
}; | ||
|
||
export const DynamicSortableCustomMenus = { | ||
render: DynamicSortableTableWithCustomMenus, | ||
args: { | ||
...Example.args, | ||
disabledKeys: ['Foo 5'] | ||
} | ||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should look at potentially combining some of the stories since these are also our docs |
||
function renderEmptyState() { | ||
return ( | ||
<IllustratedMessage> | ||
|
@@ -471,7 +576,11 @@ const SortableResizableTable = (args: any) => { | |
<TableView aria-label="sortable table" {...args} sortDescriptor={isSortable ? sortDescriptor : null} onSortChange={isSortable ? onSortChange : null} styles={style({width: 384, height: 320})}> | ||
<TableHeader columns={args.columns}> | ||
{(column: any) => ( | ||
<Column isRowHeader={column.isRowHeader} allowsSorting={column.isSortable} allowsResizing={column.allowsResizing} align={column.align}>{column.name}</Column> | ||
<Column | ||
isRowHeader={column.isRowHeader} | ||
allowsSorting={column.isSortable} | ||
allowsResizing={column.allowsResizing} | ||
align={column.align}>{column.name}</Column> | ||
)} | ||
</TableHeader> | ||
<TableBody items={items}> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bit strange that this doesn't actually accept a
<Menu>
. We should discuss options for the API here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that's another option to handle it
was trying to answer #7617 (comment) as well
if it accepted a Menu, I guess we could do a custom renderer to inject our three menu items, still not a good way to ensure groups that make sense though
maybe people have to provide a menu with specific ids on certain children if they want resize/sort?
open to other ideas, not sold on what I currently have
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marked current api as UNSTABLE, also changed to menuItems
Other API considerations have been
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Design is fine (for now) if our default items are in their own section at the top. We've decided that without needing to interleave/change order of menuitems, it's better to not give an API which allows people to omit our default options as this could be a problem for accessibility.