[Feature Request] Any way to get current theme (dark/light) in a (customed) component?
See original GitHub issueFirst, thanks for this awesome Vue plugin.
I drew some glyph icons (.ttf; surely for those which cannot found in FontAwesome or MaterialDesign) for my project. So I’m trying to write a Vue component to wrap my icon, which can aware currently activated theme (dark
/light
) and change color for it.
Basically, for consistence, I wish it can works just like
v-icon
, with same API, maybe…
However, after hours of research, I didn’t find any reliable way/API/mechanism to get the activated theme of a specific level of a HTML/Component hierarchy, for coloring the glyph icons I made.
I guess the possible way can be (may be silly, I’m not familiar the internal implementation of Vuetify):
- event from parent (e.g.
v-app
?) to notify all children (oops,this.$broadcast
seems only available in Vue1.x; not available in Vue2.x) - Accessible in
this.$vuetify
? - A CSS class which Vuetify will automatically change its color ?
- A HTML attribute directive which Vuetify will automatically add CSS classes such as
.theme--dark
to the HTML element, then user can decide the color in CSS (e.g..my-glyphicon.theme--dark { color: #fff; }
)?
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Implementing Dark Mode In React Apps Using styled ...
To implement dark mode, we need to create four different components. Theme This contains the color properties of our light and dark themes....
Read more >A Dark Mode Toggle with React and ThemeProvider
This media feature is used to detect if the user has requested the page to use a light or dark color theme based...
Read more >Dark theme - Android Developers
Your themes and styles should avoid hard-coded colors or icons intended for use under a light theme. You should use theme attributes (preferred)...
Read more >Automatic Dark Mode Detection in Angular Material - Philipp Kief
This article showed how to detect the Dark Mode in an Angular application and how the color scheme of all components can be...
Read more >Is there an API to detect which theme the OS is using - dark or ...
In order to manage the dark theme, you must first use the latest version of the Material Components library: "com.google.android.material: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I was just trying to understand how to programmatically manipulate the theme, and themeable components, first as an exercise to make a theme switcher for the user…
Old habits die hard, and so first crack at it was this ah, rather jquery-esque (walk the dom, manipulate/toggle classes) and not so vue-esque (or reactive) approach:
Aaaand right about when I got that working, I found this theme-switching codepen, maybe shed a tear, and went to bed. 😂
👍 Point stands tho, that I had trouble finding documentation or examples of how to work with the active and available themes programmatically… at runtime.
VIcon uses this: https://github.com/vuetifyjs/vuetify/blob/dev/src/mixins/themeable.ts#L70
If you just want to consume the current theme, simply use
inject: ['theme']
andthis.theme.isDark
. We could probably expose a renderless component to make this easier though.