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

MWPW-161130 - [Table] Handle dynamic pricing in addon labels #3100

Merged
merged 5 commits into from
Nov 6, 2024
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
4 changes: 1 addition & 3 deletions libs/blocks/table/table.css
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@

.table.has-addon .row-heading .col.col-heading:not(.col-1) .buttons-wrapper {
align-items: flex-end;
height: 100%;
}

.table.has-addon p.body {
Expand All @@ -485,7 +484,6 @@
text-align: start;
font-style: normal;
font-weight: 400;
gap: var(--spacing-xxs);
overmyheadandbody marked this conversation as resolved.
Show resolved Hide resolved
color: black;
padding: 5px 10px;
box-sizing: border-box;
Expand All @@ -495,7 +493,7 @@
background-color: var(--color-gray-300);
}

.table.has-addon .addon-label :first-child {
.table.has-addon .addon-label .icon {
display: flex;
align-self: center;
}
Expand Down
13 changes: 9 additions & 4 deletions libs/blocks/table/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,19 @@ function handleAddOnContent(table) {
const [position, order, style] = addOn.innerText.split('-')
.filter((key) => key.toUpperCase() !== addOnKey).map((key) => key.toLowerCase());
if (!position || !order) return;
const indexAttr = 'data-col-index';
const dataIndex = 'data-col-index';
[...table.querySelector('.row-heading').children].forEach((headCol) => {
headCol.querySelector('.heading-content')?.classList.add('content');
const colIndex = headCol.getAttribute(indexAttr);
const colIndex = headCol.getAttribute(dataIndex);
if (colIndex <= 1) return; // skip the key column
const tagName = `${position}-${order}`;
const content = [...addOnRow.children]
.find((col) => col.getAttribute(indexAttr) === colIndex).childNodes;
const column = [...addOnRow.children].find((el) => el.getAttribute(dataIndex) === colIndex);
let content = column.childNodes;
const icon = column.querySelector('.icon');
if (style === 'label' && icon) {
const text = [...content].filter((node) => !node.classList?.contains('icon'));
content = [createTag('span', null, text), icon];
}
const tag = createTag('div', { class: tagName }, [...content].map((node) => node));
if (style) tag.classList.add(`addon-${style}`);
const el = headCol.querySelector(`.${position}`);
Expand Down
7 changes: 7 additions & 0 deletions test/blocks/table/mocks/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,13 @@
<div data-valign="middle">test</div>
<div data-valign="middle">test</div>
</div>
<div>
<div data-valign="middle">ADDON-CONTENT-AFTER-LABEL</div>
<div data-valign="middle">test <em><span class="icon icon-tooltip"></span>| test</em></div>
<div data-valign="middle">test <em><span class="icon icon-tooltip"></span>| test</em></div>
<div data-valign="middle">test <em><span class="icon icon-tooltip"></span>| test</em></div>
<div data-valign="middle">test <em><span class="icon icon-tooltip"></span>| test</em></div>
</div>
<div>
<div data-align="center">
<hr>
Expand Down
Loading