Skip to content

How to decide show which component based on dark mode statu? #4238

Closed Answered by falkoschindler
weinibuliu asked this question in Q&A
Discussion options

You must be logged in to vote

Here is how you can show and hide elements based on the current mode:

ui.icon('light_mode').classes('dark:hidden')
ui.icon('dark_mode').classes('hidden dark:!block')

The class "dark:!block" will display the element as a normal "block" only in dark mode. Otherwise the element is hidden. The exclamation mark ! is needed to overrule the "hidden" class.

Alternatively you can create your own classes with some custom CSS, which might be more handy:

ui.add_css('''
@media (prefers-color-scheme: dark) {
    .only-in-light-mode {
        display: none;
    }
}
@media (prefers-color-scheme: light) {
    .only-in-dark-mode {
        display: none;
    }
}
''')

ui.icon('light_mode').classes('only-in-…

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@weinibuliu
Comment options

@falkoschindler
Comment options

Answer selected by weinibuliu
@weinibuliu
Comment options

@falkoschindler
Comment options

@weinibuliu
Comment options

@falkoschindler
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants