Skip to content
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

[DOCS] Add interactive row-selection demo #732

Merged
merged 1 commit into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions addon/components/ember-tbody/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,17 @@ export default Component.extend({
selectingChildrenSelectsParent: defaultTo(true),

/**
The currently selected rows. Can either be an array or and individual row.
The currently selected rows. Can either be an array or an individual row.

@argument selection
@type object?
@type array|object|null
*/
selection: null,

/**
An action that triggers when the row selection of the table changes.
An action that is called when the row selection of the table changes.
Will be called with either an array or individual row, depending on the
checkboxSelectionMode.

@argument onSelect
@type Action?
Expand Down
63 changes: 31 additions & 32 deletions tests/dummy/app/pods/docs/guides/body/row-selection/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,44 +75,43 @@ export default class SimpleController extends Controller {

@computed
get rowsWithChildren() {
return [
{
A: 'A',
B: 'B',
C: 'C',
D: 'D',

children: [
{ A: 'A', B: 'B', C: 'C', D: 'D' },
{ A: 'A', B: 'B', C: 'C', D: 'D' },
{ A: 'A', B: 'B', C: 'C', D: 'D' },
],
},
{
A: 'A',
let makeRow = (id, { children } = { children: [] }) => {
return {
A: `A${id}`,
B: 'B',
C: 'C',
D: 'D',

children: [
{ A: 'A', B: 'B', C: 'C', D: 'D' },
{ A: 'A', B: 'B', C: 'C', D: 'D' },
{ A: 'A', B: 'B', C: 'C', D: 'D' },
],
},
{
A: 'A',
B: 'B',
C: 'C',
D: 'D',

children,
};
};
return [
makeRow(1, {
children: [
{ A: 'A', B: 'B', C: 'C', D: 'D' },
{ A: 'A', B: 'B', C: 'C', D: 'D' },
{ A: 'A', B: 'B', C: 'C', D: 'D' },
makeRow(2, {
children: [makeRow(3), makeRow(4), makeRow(5)],
}),
makeRow(6),
makeRow(7),
makeRow(8, {
children: [makeRow(9), makeRow(10), makeRow(11)],
}),
],
},
}),
];
}

@computed('selection')
get currentSelection() {
if (!this.selection || this.selection.length === 0) {
return 'Nothing selected';
} else {
if (Array.isArray(this.selection)) {
return `Array: [${this.selection.map(row => row.A).join(',')}]`;
} else {
let row = this.selection;
return `Single: ${row.A}`;
}
}
}
// END-SNIPPET
}
12 changes: 8 additions & 4 deletions tests/dummy/app/pods/docs/guides/body/row-selection/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ to control the selection using DDAU:
{{demo.snippet label='component.js' name='docs-example-row-selection.js'}}
{{/docs-demo}}

# Selected Rows
## Selected Rows

`selection` can either be a single row, or a group of rows. Selecting a row also
marks all of its children as selected.
Expand Down Expand Up @@ -62,12 +62,12 @@ in the `selection` group. It makes other tasks much easier though, like finding
all of the groups that are selected, and selecting a group manually, external to
the table.

# Selection Modes
## Selection Modes

There are three different properties you can use to control the behavior of
row selection:

1. `checkboxSelectionMode`: This controls the behavior of the checkbox which
1. `checkboxSelectionMode`: This controls the behavior of the checkbox that
appears in the first cell of a row. It can be either `multiple`, `single`, or
`none`. Checkbox selection is always a group selection - it will always pass an
array to `onSelect`. In `multiple` mode it allows more than one checkbox to be
Expand All @@ -88,7 +88,7 @@ itself.
{{#docs-demo as |demo|}}
{{#demo.example name='selection-modes'}}
{{! BEGIN-SNIPPET docs-example-selection-modes.hbs }}
<div class="demo-container small">
<div class="demo-container">
<EmberTable as |t|>
<t.head @columns={{columns}} />

Expand All @@ -104,6 +104,10 @@ itself.
/>
</EmberTable>
</div>
<div class="demo-options-group">
<h4>Current selection</h4>
<div class="demo-current-selection">{{currentSelection}}</div>
</div>
<div class="demo-options-group">
<h4>rowSelectionMode</h4>
<label> <RadioButton @name='row-selection-mode' @value='multiple' @groupValue={{rowSelectionMode}} /> multiple </label>
Expand Down
10 changes: 9 additions & 1 deletion tests/dummy/app/styles/tables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@
}
}

.demo-current-selection {
font-weight: bold;
}

.demo-options-group {
h4 {
font-weight: normal;
font-size: larger;
}

display: flex;

& *:first-child {
text-align: right;
flex-basis: 40%;
}

Expand Down