Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] $vuetify.application values as customProperties #9532

Closed
spencercap opened this issue Oct 31, 2019 · 2 comments
Closed

[Feature Request] $vuetify.application values as customProperties #9532

spencercap opened this issue Oct 31, 2019 · 2 comments

Comments

@spencercap
Copy link

spencercap commented Oct 31, 2019

Problem to solve

The Vuetify v-app-bar and v-navigation-drawer components play nicely when setting their height and width as attributes vs inline styles (for example, v-content and v-navigation-drawer set their padding based on these) but I've found that I occasionally need to access the v-app-bar height or v-navigation-drawer width elsewhere in my webapp so having their values available globally would be super helpful.

Proposed solution

In a similar way that Vuetify stores theme colors in the $vuetify object AND as custom CSS properties, it'd be nice to access other global style constants (such as header height) via custom properties.

This way, you could set the height attribute via something like:
set in vuetify.ts:

export default new Vuetify({
    theme: {
        constants: {
            headerHeight: '90px'
        },
        options: {
            customProperties: true
        },
        themes: { ... }
    }
});

in vue markup:

<v-app-bar
    :height="$vuetify.theme.constants.headerHeight"
    ...

in CSS like:

#banner {
    margin-top: var(--v-constants-headerHeight);
}

Maybe this solution would come in handy in neat other ways too 🙃

@ghost ghost added the S: triage label Oct 31, 2019
@spencercap
Copy link
Author

I did come up with a solution for this (that is, syncing Vue data with CSS custom properties).

main.ts / main.js :

Vue.prototype.$constants = {
    navWidth: 300,
    headerHeight: '200px'
};

App.vue (style binding to the outermost element) :

<v-app
    id="app"
    data-app
    :style="
        Object.entries($constants)
            .map(c => {
                return `--${c[0]}: ${c[1]};`;
            })
            .join(' ')
    "
>
...

css :

.something { 
    width: calc(var(--navWidth) * 1px); /* if you want to keep constants unitless */
    height: var(--headerHeight);
}

@Leespiker Leespiker added T: feature A new feature and removed S: triage labels Apr 5, 2020
@KaelWD KaelWD changed the title [Feature Request] Numbers + Strings in customProperties [Feature Request] $vuetify.application values as customProperties Oct 7, 2020
@KaelWD KaelWD added this to the v3.0.0 milestone Oct 7, 2020
@johnleider johnleider added this to To do in Vuetify 3 - Titan via automation Nov 30, 2020
@johnleider johnleider added S: needs docs update The change requires an update to the documentation T: documentation and removed S: needs docs update The change requires an update to the documentation labels Mar 9, 2021
@KaelWD
Copy link
Member

KaelWD commented Mar 9, 2021

We'll expose those values to JS and you can use Vue's <style vars> to create css variables where needed: vuejs/rfcs#226

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

6 participants