(buttons: Element[], ...classes: string[])
| 5 | |
| 6 | // Wrap a list of elements with BtnGroup + ensure each has BtnGroup-item |
| 7 | export function groupButtons(buttons: Element[], ...classes: string[]): HTMLElement { |
| 8 | // Ensure every button has this class |
| 9 | for (let button of buttons) { |
| 10 | if (!button.matches('button, .btn')) { |
| 11 | button.classList.add('BtnGroup-parent'); |
| 12 | button = $('.btn', button); |
| 13 | } |
| 14 | |
| 15 | button.classList.add('BtnGroup-item'); |
| 16 | } |
| 17 | |
| 18 | // They may already be part of a group |
| 19 | let group = closestElementOptional('.BtnGroup', buttons[0]); |
| 20 | |
| 21 | // If it doesn't exist, wrap them in a new group |
| 22 | if (!group) { |
| 23 | group = <div className="BtnGroup" />; |
| 24 | wrapAll(group, ...buttons); |
| 25 | } |
| 26 | |
| 27 | group.classList.add(...classes); |
| 28 | |
| 29 | return group; |
| 30 | } |
| 31 | |
| 32 | // Find immediate `.btn` siblings of `button` and wrap them with groupButtons |
| 33 | export function groupSiblings(button: Element): Element { |
no test coverage detected