Skip to content

Commit

Permalink
feat(pix-table): allow pass onClickon row
Browse files Browse the repository at this point in the history
  • Loading branch information
xav-car committed Feb 27, 2025
1 parent 39fcc5c commit c28d031
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
5 changes: 4 additions & 1 deletion addon/components/pix-table.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
</thead>
<tbody>
{{#each @data as |row|}}
<tr>
<tr
class={{if this.hasClickOnRow "pix-table__clickable-row" ""}}
{{on "click" (fn this.onClick row)}}
>
{{yield row "cell" to="columns"}}
</tr>
{{/each}}
Expand Down
13 changes: 13 additions & 0 deletions addon/components/pix-table.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { warn } from '@ember/debug';
import { action } from '@ember/object';
import Component from '@glimmer/component';

export default class PixTable extends Component {
Expand Down Expand Up @@ -39,4 +40,16 @@ export default class PixTable extends Component {
get headerClass() {
return `pix-table-header--${this.variant}`;
}

get hasClickOnRow() {
return typeof this.args.onClick === 'function';
}

@action
onClick(row, event) {
event.stopPropagation();
if (this.hasClickOnRow) {
this.args.onClick(row);
}
}
}
14 changes: 13 additions & 1 deletion addon/styles/_pix-table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,24 @@

@extend %pix-body-s;

.pix-table__condensed {
&__condensed {
th, td {
padding: var(--pix-spacing-2x) var(--pix-spacing-4x);
}
}

&__clickable-row {
cursor: pointer;

&:hover,
&:focus,
&:active {
color: var(--pix-neutral-900);
background-color: var(--pix-neutral-20);
transition: 0.25s ease;
}
}

table {
min-width: 100%;
border-collapse: collapse;
Expand Down
6 changes: 6 additions & 0 deletions app/stories/pix-table.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export default {
'Définition du rendu des différentes colonnes de la table en utilisant `<PixTableColumn>`. Expose les paramètres `row` et `context` (correspondant aux données de la ligne actuelle)',
type: { name: 'block content', required: true },
},
onClick: {
name: 'onClick',
description:
"Permet d'ajouter un onClick sur le tr de chaque ligne, la function en paramètre récupérera l'objet au complet.",
type: { name: 'function', required: false },
},
variant: {
name: 'variant',
description: "Afficher le bon variant pour l'application",
Expand Down

0 comments on commit c28d031

Please sign in to comment.