Skip to content

Commit

Permalink
Add support for text changing attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardCoyle authored and tmcconechy committed Jun 22, 2023
1 parent abe8ff8 commit 2836bd5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/components/module-nav/module-nav.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,22 @@ export const SWITCHER_ICON_HTML = `<svg
</svg>`;

/**
* @param {string} [buttonText] provides the template with descriptive button text, if applicable
* @returns {string} IdsButton component HTML template used to define Module Nav Switcher Button
*/
export const buttonTemplate = () => `<div class="module-nav-section module-btn">
export const buttonTemplate = buttonText => `<div class="module-nav-section module-btn">
<button id="module-nav-homepage-btn" class="btn-icon btn-tertiary">
${SWITCHER_ICON_HTML}
<span>${Locale ? Locale.translate('ModuleSwitch') : 'Switch Modules'}</span>
<span>${buttonText || (Locale ? Locale.translate('ModuleSwitch') : 'Switch Modules')}</span>
</button>
</div>`;

/**
* @param {string} [labelText] provides the template with descriptive label text, if applicable
* @returns {string} IdsDropdown component HTML template used to define Module Nav Switcher Dropdown
*/
export const dropdownTemplate = () => `<div class="module-nav-section role-dropdown">
<label for="module-nav-role-switcher" class="label audible">Roles</label>
export const dropdownTemplate = labelText => `<div class="module-nav-section role-dropdown">
<label for="module-nav-role-switcher" class="label audible">${labelText || 'Roles'}</label>
<select id="module-nav-role-switcher" name="module-nav-role-switcher" class="dropdown"></select>
</div>`;

Expand Down
6 changes: 4 additions & 2 deletions src/components/module-nav/module-nav.switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const MODULE_NAV_SWITCHER_DEFAULTS = {
displayMode: MODULE_NAV_DISPLAY_MODES[0],
generate: true,
icon: () => SWITCHER_ICON_HTML,
moduleButtonText: 'Standard Module',
roleDropdownLabel: 'Roles',
roles: []
};

Expand Down Expand Up @@ -154,7 +156,7 @@ ModuleNavSwitcher.prototype = {

renderModuleButton() {
if (this.settings.generate && (!this.moduleButtonContainerEl || !this.moduleButtonEl)) {
this.element[0].insertAdjacentHTML('afterbegin', buttonTemplate());
this.element[0].insertAdjacentHTML('afterbegin', buttonTemplate(this.settings.moduleButtonText));
}
if (this.moduleButtonEl) {
$(this.moduleButtonEl).button({
Expand All @@ -165,7 +167,7 @@ ModuleNavSwitcher.prototype = {

renderRoleDropdown() {
if (this.settings.generate && (!this.roleDropdownContainerEl || !this.roleDropdownEl)) {
this.element[0].insertAdjacentHTML('beforeend', dropdownTemplate());
this.element[0].insertAdjacentHTML('beforeend', dropdownTemplate(this.settings.roleDropdownLabel));
}
if (!$(this.roleDropdownEl).find('option').length) {
this.renderDropdownOptions();
Expand Down

0 comments on commit 2836bd5

Please sign in to comment.