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

feat(media queries): add Media Query Service #1154

Open
Brocco opened this issue Oct 24, 2016 · 0 comments
Open

feat(media queries): add Media Query Service #1154

Brocco opened this issue Oct 24, 2016 · 0 comments

Comments

@Brocco
Copy link

Brocco commented Oct 24, 2016

Background

One of the core concepts in bootstrap are the media queries (sm, md, lg, xl) where you can conditionally show/hide elements based upon the browser size.

Proposal

Expose a service where users can get the media query as an observable

// media query types
export enum MediaQueryOption { xs, sm, md, lg }

// service to provide access
export class MediaQueryService {
  getMediaQuery(): Observable<MediaQueryOption> { ... }
}

// sample usage
@Component({ ... })
export class SampleComponent implements OnInit{
  isXs: Observable<boolean>
  constructor(private media: MediaQueryService) {}
  ngOnInit() {
    this.isXs = this.media.getMediaQuery()
      .map(m => m === MediaQueryOption.xs);
  }
}

Future Considerations

Create corresponding directives that could internally use this above service for example...
IfXs - to only show in xs view
IfHideXs - to hide only in xs view

Allow configuration values to override the default media query breakpoints

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

No branches or pull requests

4 participants