-
Notifications
You must be signed in to change notification settings - Fork 8
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
Remove remaining deprecated apis #12
Changes from 5 commits
e46ce50
85ccaff
39439de
9438bfe
01740a5
0d6853e
61a4b3e
47caa83
44c8c6a
8975658
38c1d9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
categoryOrder: 3 | ||
--- | ||
|
||
# Demos and examples | ||
|
||
While each plugin has its own demo for how to use the plugin (and in combination with other plugins), | ||
there are common behaviors and patterns that can be acheived with the plugin system (with the existing plugins) | ||
that fit more in to a "kitchen-sink" style collection of demos. | ||
|
||
If you have an idea for a demo, please [open an issue](https://github.com/CrowdStrike/ember-headless-table/issues) | ||
requesting the demo, or even better, submit a pull request adding your demo. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
This demonstrates how to use the RowSelection plugin to enable multiple row selection. | ||
NullVoxPopuli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
If single-row selection is desired, that can be handled in userspace, by managing the selection data differently (see other demos). | ||
|
||
To select a row, click it. To deselect a row, click it again. | ||
|
||
```hbs template | ||
<div class="h-full overflow-auto" {{this.table.modifiers.container}}> | ||
<table> | ||
<thead> | ||
<tr> | ||
<td></td> | ||
{{#each this.table.columns as |column|}} | ||
<th {{this.table.modifiers.columnHeader column}} class="relative group"> | ||
{{column.name}} | ||
</th> | ||
{{else}} | ||
<th> | ||
No columns are visible | ||
</th> | ||
{{/each}} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{{#each this.table.rows as |row|}} | ||
<tr {{this.table.modifiers.row row}} class="{{if (this.isSelected row) 'bg-surface-inner'}}"> | ||
<td> | ||
<button {{on 'click' (fn this.toggle row)}}>Toggle</button> | ||
</td> | ||
{{#each this.table.columns as |column|}} | ||
<td> | ||
{{column.getValueForRow row}} | ||
</td> | ||
{{/each}} | ||
</tr> | ||
{{/each}} | ||
</tbody> | ||
</table> | ||
</div> | ||
``` | ||
```js component | ||
import Component from '@glimmer/component'; | ||
|
||
import { headlessTable } from 'ember-headless-table'; | ||
import { meta } from 'ember-headless-table/plugins'; | ||
import { TrackedSet } from 'tracked-built-ins'; | ||
import { RowSelection, toggle, isSelected } from 'ember-headless-table/plugins/row-selection'; | ||
|
||
import { DATA } from 'docs-app/sample-data'; | ||
|
||
export default class extends Component { | ||
selection = new TrackedSet(); | ||
|
||
table = headlessTable(this, { | ||
columns: () => [ | ||
{ name: 'column A', key: 'A' }, | ||
{ name: 'column B', key: 'B' }, | ||
{ name: 'column C', key: 'C' }, | ||
{ name: 'column D', key: 'D' }, | ||
], | ||
data: () => DATA, | ||
plugins: [ | ||
RowSelection.with(() => { | ||
return { | ||
selection: this.selection, | ||
onSelect: (data) => this.selection.add(data), | ||
onDeselect: (data) => this.selection.delete(data), | ||
}; | ||
}), | ||
], | ||
}); | ||
|
||
/** | ||
* Plugin Integration - all of this can be removed in strict mode, gjs/gts | ||
* | ||
* This syntax looks weird, but it's read as: | ||
* [property on this component] = [variable in scope] | ||
*/ | ||
toggle = toggle; | ||
isSelected = isSelected; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Row selection | ||
|
||
API Documentation available [here][api-docs] | ||
|
||
[api-docs]: /api/modules/plugins_row_selection | ||
|
||
## Usage | ||
|
||
State for what is selected is managed by you, the consumer. | ||
This plugin provides helpful utilities and automatically wires up event listeners for each row. | ||
|
||
### ColumnOptions | ||
|
||
None | ||
|
||
|
||
### TableOptions | ||
|
||
Required: | ||
- `selection` - a collection of what is already selected | ||
- `onSelect` - event handler for when a row is selected | ||
- `onDeselect` - event handler for when a row is deselected | ||
|
||
Optional: | ||
- `key` - a function which will be passed to `onSelect` and `onDeselect` for helping manage "what" is selected. This should be the same data type as the individual elements within the `selection` | ||
|
||
|
||
See the API Documentation [here][api-docs] for the full list of options and descriptions. | ||
|
||
### Preferences | ||
|
||
None | ||
|
||
### Accessibility | ||
|
||
Without a focusable element to trigger a row selection, | ||
keyboard and screen reader users will not be able to select a row. | ||
When using this plugin, ensure that each row has a focusable element that interacts with the selection APIs for that row. | ||
|
||
### Helpers + StrictMode | ||
|
||
There are convenience helpers for aiding in more ergonomic template usage when using this plugin. | ||
|
||
```gjs | ||
import { on } from '@ember/modifier'; | ||
import { fn } from '@ember/helper'; | ||
import { toggle, isSelected } from 'ember-headless-table/plugins/row-selection'; | ||
|
||
export const Rows = | ||
<template> | ||
<tbody> | ||
{{#each @table.rows as |row|}} | ||
<tr {{@table.modifiers.row row}} class="{{if (isSelected row) 'bg-surface-inner'}}"> | ||
<td> | ||
<button {{on 'click' (fn toggle row)}}>Toggle</button> | ||
</td> | ||
{{#each @table.columns as |column|}} | ||
<td> | ||
{{column.getValueForRow row}} | ||
</td> | ||
{{/each}} | ||
</tr> | ||
{{/each}} | ||
</tbody> | ||
</template> | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
"./plugins/column-resizing": "./dist/plugins/column-resizing/index.js", | ||
"./plugins/column-visibility": "./dist/plugins/column-visibility/index.js", | ||
"./plugins/sticky-columns": "./dist/plugins/sticky-columns/index.js", | ||
"./plugins/row-selection": "./dist/plugins/row-selection/index.js", | ||
"./test-support": "./dist/test-support/index.js", | ||
"./addon-main.js": "./addon-main.js" | ||
}, | ||
|
@@ -46,6 +47,9 @@ | |
"plugins/sticky-columns": [ | ||
"./dist/plugins/sticky-columns/index.d.ts" | ||
], | ||
"plugins/row-selection": [ | ||
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. Is this something we manually have to add for each new plugin? Maybe this should be a note in CONTRIBUTING 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. it's something that needs to be added in any package for any public entry point -- it's more "normal npm stuff", if that makes sense. |
||
"./dist/plugins/row-selection/index.d.ts" | ||
], | ||
"test-support": [ | ||
"./dist/test-support/index.d.ts" | ||
], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { meta } from '../-private/base'; | ||
import { RowSelection } from './plugin'; | ||
|
||
import type { Row } from '../../-private/row'; | ||
|
||
export const isSelected = (row: Row<any>) => meta.forRow(row, RowSelection).isSelected; | ||
export const select = (row: Row<any>) => meta.forRow(row, RowSelection).select(); | ||
export const deselect = (row: Row<any>) => meta.forRow(row, RowSelection).deselect(); | ||
export const toggle = (row: Row<any>) => meta.forRow(row, RowSelection).toggle(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Public API | ||
export * from './helpers'; | ||
export { RowSelection as Plugin } from './plugin'; | ||
export { RowSelection } from './plugin'; | ||
|
||
// Public types | ||
export type { Signature } from './plugin'; |
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.
we can now sort folders!