Created
July 25, 2024 11:00
-
-
Save davesnx/31e22eeb6d890208470cbdd3f96a481b to your computer and use it in GitHub Desktop.
Random design for "Adaptative" component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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