matthewp / corset

Declarative data bindings, bring your own backend.

Home Page:https://corset.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Media queries

matthewp opened this issue · comments

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

@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'))};
      }
    }
  `;
});