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

expose a global variable of the current breakpoint xs,sm,md,lg to all component #974

Closed
dohomi opened this issue Jul 13, 2017 · 6 comments
Closed
Labels
T: enhancement Functionality that enhances existing features T: feature A new feature
Milestone

Comments

@dohomi
Copy link
Contributor

dohomi commented Jul 13, 2017

As discussed earlier: it would be nice to have the current visible breakpoint variable as a global variable accessible in all components. The idea would be a client side watcher on window resize and dispatch the current breakpoint name.

@dohomi dohomi added T: enhancement Functionality that enhances existing features T: feature A new feature labels Jul 13, 2017
@cyrrill
Copy link

cyrrill commented Jul 29, 2017

@dohomi @johnleider

I was looking into an easy way of achieving this, and it seems like it wouldn't be too hard. Evan has sketched out the basics here:

vuejs/vue#1915

Seems like we would just need to setup some window listeners and have a function that reads the value of the viewport width, and with a computed property expose the current value of: xs, sm, md, lg, xl

Where:

xs - extra small viewport devices (< 576px)
sm - small viewport devices (< 768px)
md - medium viewport devices (< 992px)
lg - large viewport devices (< 1200px)
xl - extra large viewport devices (> 1200px)

Viewport width can be attained crossbrowser compatible as:
https://stackoverflow.com/questions/1248081/get-the-browser-viewport-dimensions-with-javascript

@stbaer
Copy link
Contributor

stbaer commented Jul 29, 2017

Another option would be to use media queries, e.g.:

@media (max-width: $grid-breakpoints.xs) 
        &:before
            content: "breakpoint-xs";
@media (min-width: $grid-breakpoints.xs+1 ) and (max-width: $grid-breakpoints.sm)
        &:before
            content: "breakpoint-sm";
...

to get the breakpoint in js:

const getBreakpoint = () => {
    if (typeof window === 'undefined') return;

    const appContainer = document.querySelector('[data-app]')
    return window
        .getComputedStyle(appContainer, ':before')
        .getPropertyValue('content').replace(/"/g, '');
}

@cyrrill
Copy link

cyrrill commented Aug 2, 2017

Here is a mixin put together by @cb109

https://gist.github.com/cb109/b074a65f7595cffc21cea59ce8d15f9b

@johnleider johnleider modified the milestone: v0.15.0 Aug 19, 2017
@johnleider
Copy link
Member

Can I get a few peoples examples of how they would expect this to work?

@jacekkarczmarczyk
Copy link
Member

For example:

<v-dialog :full-screen="$breakpoint.xs"></v-dialog>
<v-dialog :full-screen="$breakpoint.xsOnly"></v-dialog>
<v-dialog :full-screen="$breakpoint.smAndDown"></v-dialog>

@lock
Copy link

lock bot commented Apr 16, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please direct any non-bug questions to our Discord

@lock lock bot locked as resolved and limited conversation to collaborators Apr 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T: enhancement Functionality that enhances existing features T: feature A new feature
Projects
None yet
Development

No branches or pull requests

5 participants