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

Media queries #24

Open
matthewp opened this issue Nov 16, 2021 · 1 comment
Open

Media queries #24

matthewp opened this issue Nov 16, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@matthewp
Copy link
Owner

Need a concrete use-case but it would be fun.

@matthewp
Copy link
Owner Author

matthewp commented Jan 7, 2022

@media only screen and (max-width: 768px) {
  .sidebar {
    mount: ${MobileSidebar};
  }
}

To dynamically load the mobile sidebar:

// This is a mountpoint which loads another mountpoint dynamically.
const mount = Symbol();
const Loadable = fn => state => {
  if(state[mount]) {
    return state[mount];
  }

  fn().then(mod => {
    // Triggers a reload.
    state[mount] = mod.default;
  });

  return sheet``;
};

mount(document, state => {
  return sheet`
    @media only screen and (max-width: 768px) {
      .sidebar {
        mount: ${Loadable(() => import('./mobile-sidebar.js'))};
      }
    }
  `;
});

@matthewp matthewp added the enhancement New feature or request label Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant