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

feat(icon): Webtools icons - FRONT-4688 #3736

Open
wants to merge 18 commits into
base: v4-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
table
  • Loading branch information
emeryro committed Jan 6, 2025
commit a78547b9fa2f2c38437c8d3a1f75a2032ee5666d
1 change: 1 addition & 0 deletions src/implementations/twig/components/table/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ npm install --save @ecl/twig-component-table
- "rowspan" (string) (default: ''),
- "data-ecl-table-header-group" (string) (default: ''),
- "headers" (string) (default: ''): headers attribute to reference the relevant table headers ids (for multi headers table)
- **"icon_wt_markup"** (boolean) (default: false): should the icon use the Webtools markup?
- **"rows"** (array) (default: []): [
{ - "extra_attributes": (string) (default: ''), - "extra_classes": (string) (default: '') Extra classes for the table row (space separated) - "data: [
{
Expand Down
8 changes: 8 additions & 0 deletions src/implementations/twig/components/table/table.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- "caption" (string) (default: ''): optional caption for the table
- "label_sort" (string) (default: ''): label used for sorting buttons (screen reader only)
- "zebra" (boolean) (default: false))
- "icon_wt_markup" (boolean) (default: false): should the icon use the Webtools markup?
- "headers" (array) (default: []): format: [
{
"label" (string or array of string)
Expand Down Expand Up @@ -63,6 +64,7 @@
{% set _label_sort = label_sort|default('') %}
{% set _rows = rows|default([]) %}
{% set _zebra = zebra|default(false) %}
{% set _icon_wt_markup = icon_wt_markup|default(false) %}

{# Internal logic - Process properties #}

Expand All @@ -78,6 +80,12 @@
]) %}
{% endif %}

{% if _icon_wt_markup %}
{% set extra_attributes = extra_attributes|default([])|merge([
{ name: 'data-ecl-icon-wt-markup' },
]) %}
{% endif %}

{% if _simple %}
{% set _css_class = _css_class ~ ' ' ~ _simple_css_class %}
{% endif %}
Expand Down
46 changes: 30 additions & 16 deletions src/implementations/vanilla/components/table/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,31 @@ export class Table {
/**
* @returns {HTMLElement}
*/
static createSortIcon(customClass) {
const tempElement = document.createElement('span');
tempElement.innerHTML = iconSvgAllArrow; // avoiding the use of not-so-stable createElementNs
const svg = tempElement.children[0];
svg.removeAttribute('height');
svg.removeAttribute('width');
svg.setAttribute('focusable', false);
svg.setAttribute('aria-hidden', true);
// The following element is <path> which does not support classList API as others.
svg.setAttribute(
'class',
`ecl-table__icon ecl-icon ecl-icon--${iconSvgAllArrowSize} ${customClass}`,
);
return svg;
static createSortIcon(customClass, wtMarkup) {
let icon = '';
if (wtMarkup) {
icon = document.createElement('span');
icon.setAttribute(
'class',
`ecl-table__icon wt-icon--solid-arrow ecl-icon--${iconSvgAllArrowSize} ${customClass}`,
);
} else {
const tempElement = document.createElement('span');
tempElement.innerHTML = iconSvgAllArrow; // avoiding the use of not-so-stable createElementNs
// eslint-disable-next-line prefer-destructuring
icon = tempElement.children[0];
icon.removeAttribute('height');
icon.removeAttribute('width');
icon.setAttribute('focusable', false);
icon.setAttribute('aria-hidden', true);
// The following element is <path> which does not support classList API as others.
icon.setAttribute(
'class',
`ecl-table__icon ecl-icon ecl-icon--${iconSvgAllArrowSize} ${customClass}`,
);
}

return icon;
}

/**
Expand All @@ -96,8 +107,11 @@ export class Table {
this.element.getAttribute(this.sortLabelSelector),
);
}
sort.appendChild(Table.createSortIcon('ecl-table__icon-up'));
sort.appendChild(Table.createSortIcon('ecl-table__icon-down'));
const wtMarkup = this.element.hasAttribute('data-ecl-icon-wt-markup');
sort.appendChild(Table.createSortIcon('ecl-table__icon-up', wtMarkup));
sort.appendChild(
Table.createSortIcon('ecl-table__icon-down', wtMarkup),
);
tr.appendChild(sort);
tr.addEventListener('click', (e) => this.handleClickOnSort(tr)(e));
});
Expand Down
10 changes: 5 additions & 5 deletions src/playground/ec/.storybook/preview-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
src="https://cdnjs.cloudflare.com/ajax/libs/pikaday/1.8.2/pikaday.js"
crossorigin="anonymous"
></script>
<script
defer
src="https://webtools.europa.eu/load.js"
type="text/javascript"
></script>
<script>
function inIframe() {
try {
Expand Down Expand Up @@ -70,6 +65,11 @@
}
</script>
<script type="text/javascript" src="./scripts/ecl-ec.js"></script>
<script
defer
src="https://webtools.europa.eu/load.js"
type="text/javascript"
></script>
<script>
// https://github.com/storybookjs/storybook/issues/6113#issuecomment-473965255
function runOnPageChange() {
Expand Down
1 change: 1 addition & 0 deletions src/specs/components/table/demo/data--sort-table.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
id: 'table-id',
sortable: true,
icon_wt_markup: true,
caption: 'Table caption',
label_sort: 'Sort table',
headers: [
Expand Down
Loading