Last active
March 25, 2022 13:10
-
-
Save glenpadua/ff6092950ee477d45083cbc0c5768ebc to your computer and use it in GitHub Desktop.
Fluid typography helper mixin for use with styled components
This file contains 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
/** | |
* @desc Styled components mixin for fluid typography - https://www.youtube.com/watch?v=Wb5xDcUNq48 | |
* @param string minScreen - min screen width | |
* @param string maxScreen - max screen width | |
* @param string minFont - min font size | |
* @param string maxFont - max font size | |
* @return string - Template literal containing CSS | |
*/ | |
export function fluidType (minScreen, maxScreen, minFont, maxFont) { | |
return ` | |
font-size: calc(${minFont} + (${parseInt(maxFont) - parseInt(minFont)}) * (100vw - ${minScreen})/(${parseInt(maxScreen) - parseInt(minScreen)})); | |
` | |
} |
This file contains 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
import styled from 'styled-components' | |
import { fluidType } from './fluid-typography' | |
const Text = styled.p` | |
${props => | |
fluidType( | |
props.theme.screen.mobile, | |
props.theme.screen.desktop, | |
'20px', | |
'30px' | |
) | |
}; | |
color: #4d4d4d; | |
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment