diff --git a/site/assets/scss/_clipboard-js.scss b/site/assets/scss/_clipboard-js.scss index de709d09ba7f..f0ab74947100 100644 --- a/site/assets/scss/_clipboard-js.scss +++ b/site/assets/scss/_clipboard-js.scss @@ -18,7 +18,8 @@ } .btn-clipboard, -.btn-edit { +.btn-edit, +.btn-theme > .dropdown-toggle { display: block; padding: .5em; line-height: 1; diff --git a/site/assets/scss/_component-examples.scss b/site/assets/scss/_component-examples.scss index fde8b7f4164a..dc20d1fe2f1b 100644 --- a/site/assets/scss/_component-examples.scss +++ b/site/assets/scss/_component-examples.scss @@ -21,6 +21,8 @@ position: relative; padding: var(--bd-example-padding); margin: 0 ($bd-gutter-x * -.5) 1rem; + color: var(--bs-body-color); + background-color: var(--bs-body-bg); border: solid var(--bs-border-color); border-width: 1px 0; @include clearfix(); diff --git a/site/layouts/shortcodes/example.html b/site/layouts/shortcodes/example.html index 5b398e6814fc..fb9ba000bfc8 100644 --- a/site/layouts/shortcodes/example.html +++ b/site/layouts/shortcodes/example.html @@ -31,6 +31,34 @@
{{ $lang }}
+ diff --git a/site/static/docs/5.3/assets/js/color-modes.js b/site/static/docs/5.3/assets/js/color-modes.js index 8a0dabf18164..f0a2c5c4dad0 100644 --- a/site/static/docs/5.3/assets/js/color-modes.js +++ b/site/static/docs/5.3/assets/js/color-modes.js @@ -19,29 +19,29 @@ return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light' } - const setTheme = theme => { + const setTheme = (theme, element = document.documentElement) => { if (theme === 'auto') { - document.documentElement.setAttribute('data-bs-theme', (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) + element.setAttribute('data-bs-theme', (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')) } else { - document.documentElement.setAttribute('data-bs-theme', theme) + element.setAttribute('data-bs-theme', theme) } } setTheme(getPreferredTheme()) - const showActiveTheme = (theme, focus = false) => { - const themeSwitcher = document.querySelector('#bd-theme') - + const showActiveTheme = (theme, focus = false, selectedToggler = document.querySelector('#bd-theme')) => { + const themeSwitcher = selectedToggler.closest('.dropdown') if (!themeSwitcher) { return } + const themeSwitcherButton = themeSwitcher.querySelector('.dropdown-toggle') const themeSwitcherText = document.querySelector('#bd-theme-text') - const activeThemeIcon = document.querySelector('.theme-icon-active use') - const btnToActive = document.querySelector(`[data-bs-theme-value="${theme}"]`) + const activeThemeIcon = themeSwitcher.querySelector('.theme-icon-active use') + const btnToActive = themeSwitcher.querySelector(`[data-bs-theme-value="${theme}"]`) const svgOfActiveBtn = btnToActive.querySelector('svg use').getAttribute('href') - document.querySelectorAll('[data-bs-theme-value]').forEach(element => { + themeSwitcher.querySelectorAll('[data-bs-theme-value]').forEach(element => { element.classList.remove('active') element.setAttribute('aria-pressed', 'false') }) @@ -49,11 +49,11 @@ btnToActive.classList.add('active') btnToActive.setAttribute('aria-pressed', 'true') activeThemeIcon.setAttribute('href', svgOfActiveBtn) - const themeSwitcherLabel = `${themeSwitcherText.textContent} (${btnToActive.dataset.bsThemeValue})` - themeSwitcher.setAttribute('aria-label', themeSwitcherLabel) + const themeSwitcherLabel = `${themeSwitcherText.textContent} (${btnToActive.dataset.bsThemeValue})${btnToActive.closest('.highlight-toolbar') ? ' (local)' : ''}` + themeSwitcherButton.setAttribute('aria-label', themeSwitcherLabel) if (focus) { - themeSwitcher.focus() + themeSwitcherButton.focus() } } @@ -71,9 +71,15 @@ .forEach(toggle => { toggle.addEventListener('click', () => { const theme = toggle.getAttribute('data-bs-theme-value') - setStoredTheme(theme) - setTheme(theme) - showActiveTheme(theme, true) + + if (toggle.closest('.bd-code-snippet')) { + setTheme(theme, toggle.closest('.bd-code-snippet').firstElementChild) + showActiveTheme(theme, true, toggle.closest('.dropdown-menu').previousElementSibling) + } else { + setStoredTheme(theme) + setTheme(theme) + showActiveTheme(theme, true) + } }) }) })