Skip to content

Commit

Permalink
fix: Don't use dark mode for print media (#1204)
Browse files Browse the repository at this point in the history
  • Loading branch information
gethinwebster authored Jun 15, 2023
1 parent 88e7a4b commit ec44714
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/internal/hooks/use-visual-mode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { useMutationObserver } from '../use-mutation-observer';
import { isDevelopment } from '../../is-development';
import { warnOnce } from '../../logging';

// Note that this hook doesn't take into consideration @media print (unlike the dark mode CSS),
// due to challenges with cross-browser implementations of media/print state change listeners.
// This means that components using this hook will render in dark mode even when printing.
export function useCurrentMode(elementRef: React.RefObject<HTMLElement>) {
const [value, setValue] = useState<'light' | 'dark'>('light');
useMutationObserver(elementRef, node => {
Expand Down
10 changes: 6 additions & 4 deletions src/internal/styles/utils/theming.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
SPDX-License-Identifier: Apache-2.0
*/
@mixin dark-mode-only($selector: '') {
/* stylelint-disable selector-combinator-disallowed-list, selector-class-pattern */
:global(#{$selector}.awsui-polaris-dark-mode) &,
:global(#{$selector}.awsui-dark-mode) & {
@content;
@media not print {
/* stylelint-disable selector-combinator-disallowed-list, selector-class-pattern */
:global(#{$selector}.awsui-polaris-dark-mode) &,
:global(#{$selector}.awsui-dark-mode) & {
@content;
}
}
}
2 changes: 1 addition & 1 deletion style-dictionary/utils/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const createColorMode = (darkSelector: string) => ({
id: 'color',
states: {
light: { default: true },
dark: { selector: darkSelector },
dark: { selector: darkSelector, media: 'not print' },
},
});

Expand Down

0 comments on commit ec44714

Please sign in to comment.