Skip to content

Instantly share code, notes, and snippets.

@rafaelrinaldi
Created January 23, 2018 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelrinaldi/b2c868850b13deaf04946b77fbe710a4 to your computer and use it in GitHub Desktop.
Save rafaelrinaldi/b2c868850b13deaf04946b77fbe710a4 to your computer and use it in GitHub Desktop.
const calc = (minWidth, maxWidth, minFontSize, maxFontSize) =>
`calc(${minFontSize}px + (${maxFontSize} - ${minFontSize}) * ((100vw - ${minWidth}px) / (${maxWidth} - ${minWidth})))`;
const fluidType = (minWidth, maxWidth, minFontSize, maxFontSize) => ({
fontSize: minFontSize,
[`@media screen and (min-width: ${minWidth}px)`]: {
fontSize: calc(minWidth, maxWidth, minFontSize, maxFontSize),
},
[`@media screen and (min-width: ${maxWidth}px)`]: {
fontSize: maxFontSize,
},
});
export default class FluidHeading extends PureComponent {
template(css) {
const { children, ...props } = this.props;
return (
<Text color={ Colors.BLUE } className={ css('root') } tag="h1" { ...props } caps>
{ children }
</Text>
);
}
styles() {
// Everything here is pixel based
const minWidth = 320;
const maxWidth = 1440;
const minFontSize = 28;
const maxFontSize = 80;
return {
root: {
fontFamily: [fontSansSerif],
...fluidType(minWidth, maxWidth, minFontSize, maxFontSize),
},
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment