From 67cf9593080ce08b761ab6074df4044eb9a40d32 Mon Sep 17 00:00:00 2001 From: jeremie Date: Mon, 13 Jan 2025 15:41:21 +0100 Subject: [PATCH] feat: Add property to condense pixTable Co-authored-by: Iris Benoit Co-authored-by: Fael Bassetti Co-authored-by: Laura Bergoens --- addon/components/pix-table.hbs | 2 +- addon/components/pix-table.js | 14 +++ addon/styles/_pix-table.scss | 6 + app/stories/pix-table.stories.js | 16 ++- .../integration/components/pix-table-test.js | 109 ++++++++++++++++++ 5 files changed, 145 insertions(+), 2 deletions(-) diff --git a/addon/components/pix-table.hbs b/addon/components/pix-table.hbs index 938e5dc12..118551896 100644 --- a/addon/components/pix-table.hbs +++ b/addon/components/pix-table.hbs @@ -1,5 +1,5 @@
- +
diff --git a/addon/components/pix-table.js b/addon/components/pix-table.js index 1ba350b89..432ce8ed5 100644 --- a/addon/components/pix-table.js +++ b/addon/components/pix-table.js @@ -22,6 +22,20 @@ export default class PixTable extends Component { return this.args.caption; } + get tableClass() { + warn( + 'PixTable: @condensed must be a boolean, default undefined', + [true, false, undefined].includes(this.args.condensed), + { + id: 'pix-ui.pix-table.condensed.not-boolean', + }, + ); + if (this.args.condensed) { + return 'pix-table__condensed'; + } + return null; + } + get headerClass() { return `pix-table-header--${this.variant}`; } diff --git a/addon/styles/_pix-table.scss b/addon/styles/_pix-table.scss index c279b77d1..e30558bbd 100644 --- a/addon/styles/_pix-table.scss +++ b/addon/styles/_pix-table.scss @@ -11,6 +11,12 @@ @extend %pix-body-s; + .pix-table__condensed { + th, td { + padding: var(--pix-spacing-2x) var(--pix-spacing-4x); + } + } + table { min-width: 100%; border-collapse: collapse; diff --git a/app/stories/pix-table.stories.js b/app/stories/pix-table.stories.js index 91b05668a..f446160b3 100644 --- a/app/stories/pix-table.stories.js +++ b/app/stories/pix-table.stories.js @@ -37,12 +37,25 @@ export default { required: false, }, }, + condensed: { + name: 'condensed', + description: 'Afficher le tableau en mode condensé', + type: { + name: 'boolean', + required: false, + }, + }, }, }; const Template = (args) => { return { - template: hbs` + template: hbs` <:columns as |row context|> <:header> @@ -81,6 +94,7 @@ const Template = (args) => { export const Default = Template.bind({}); Default.args = { caption: 'Description du tableau', + condensed: false, data: [ { name: 'jean', diff --git a/tests/integration/components/pix-table-test.js b/tests/integration/components/pix-table-test.js index e73c3688d..449498b53 100644 --- a/tests/integration/components/pix-table-test.js +++ b/tests/integration/components/pix-table-test.js @@ -124,6 +124,96 @@ module('Integration | Component | table', function (hooks) { }); }); + module('#condensed', function () { + test('it should not be condensed by default', async function (assert) { + // when + await render( + hbs` + <:columns as |row context|> + + <:header> + Nom + + <:cell> + {{row.name}} + + + + <:header> + Description + + <:cell> + {{row.description}} + + + + <:header> + Age + + <:cell> + il a + {{row.age}} + ans + + + +`, + ); + + // then + assert.notOk(this.element.querySelector('table').getAttribute('class')); + }); + + test('it should be condensed', async function (assert) { + // given + this.condensed = true; + + // when + await render( + hbs` + <:columns as |row context|> + + <:header> + Nom + + <:cell> + {{row.name}} + + + + <:header> + Description + + <:cell> + {{row.description}} + + + + <:header> + Age + + <:cell> + il a + {{row.age}} + ans + + + +`, + ); + + // then + assert.strictEqual( + this.element.querySelector('table').getAttribute('class'), + 'pix-table__condensed', + ); + }); + }); + module('#sort', function () { test('it should call @onSort on click', async function (assert) { // given @@ -318,6 +408,25 @@ module('Integration | Component | table', function (hooks) { ); }); + test('it should warn when @condensed is incorrect', async function (assert) { + // when + this.data = []; + await render( + hbs` + <:columns as |row context|> + + +`, + ); + + // then + assert.ok( + warnStub.calledWithExactly( + 'WARNING: PixTable: @condensed must be a boolean, default undefined', + ), + ); + }); + [ { ariaLabelDefaultSort: 'tri',
{{this.caption}}