Skip to content

Instantly share code, notes, and snippets.

@davesnx
Created July 25, 2024 11:00
Show Gist options
  • Save davesnx/31e22eeb6d890208470cbdd3f96a481b to your computer and use it in GitHub Desktop.
Save davesnx/31e22eeb6d890208470cbdd3f96a481b to your computer and use it in GitHub Desktop.
Random design for "Adaptative" component
/* This type defines a value that 'depends' on the screen size, and changes based on `window.matchMedia` */
type dependant('value) = {
default: 'value,
mobile: option('value), /* 800px */
desktop: option('value), /* 1200px */
huge: option('value) /* 1900px */
};
type t('value) =
| Fixed('value)
| ByScreenSize(dependant('value));
module OnMobileOnly = {
let className = [%cx
{|
display: none;
@media screen and (min-width: 300px) {
display: block;
}
|}
];
[@react.component]
let make = (~children) => {
<span className> children </span>;
};
};
/* <OnMobileOnly>
<div />
</OnMobileOnly>
<MediaQuery
onMobile={_ => <div />}
onDesktop={_ => <div />}
/>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment