baseline
This commit is contained in:
26
web/js/components/app-bulk-selection.js
Normal file
26
web/js/components/app-bulk-selection.js
Normal file
@@ -0,0 +1,26 @@
|
||||
export function bindBulkVisibility({
|
||||
containerSelector,
|
||||
buttonSelector,
|
||||
selectedRowSelector = '.gridjs-tr-selected'
|
||||
} = {}) {
|
||||
const container = document.querySelector(containerSelector);
|
||||
const buttons = Array.from(document.querySelectorAll(buttonSelector));
|
||||
if (!container || !buttons.length) return { update: () => {} };
|
||||
|
||||
const update = () => {
|
||||
const selected = container.querySelectorAll(selectedRowSelector).length > 0;
|
||||
buttons.forEach((button) => {
|
||||
button.hidden = !selected;
|
||||
});
|
||||
};
|
||||
|
||||
const observer = new MutationObserver(() => update());
|
||||
observer.observe(container, {
|
||||
subtree: true,
|
||||
attributes: true,
|
||||
attributeFilter: ['class']
|
||||
});
|
||||
|
||||
update();
|
||||
return { update, destroy: () => observer.disconnect() };
|
||||
}
|
||||
Reference in New Issue
Block a user