UNPKG

front-end-dojo

Version:

Library full of useful CSS, Sass, Styled-components, JavaScript, React functions, mixins, utilities, etc.

95 lines (76 loc) 2.15 kB
// Grid - flexbox // Import styled-components library - "import" version import styled as sc from styled-components import { css } from styled-components import { remy } from './_helper-functions' // Function for calculating value for width const getWidth = (value) => { if (!value) return let width = value / 12 * 100 return `width: ${width}%;` } // Function for calculating value for flex const getFlex = (value) => { if (!value) return let flex = value / 12 * 100 return `flex: 0 0 ${flex}%;` } // Grid container const GridContainer = sc.div` padding-right: ${remy(15)}; padding-left: ${remy(15)}; margin-right: auto; margin-left: auto; width: 100%; // Breakpoint for tablets @media (min-width: 576px) { max-width: ${remy(540)}; } // Breakpoint for small desktops @media (min-width: 768px) { max-width: ${remy(720)}; } // Breakpoint for medium desktops @media (min-width: 992px) { max-width: ${remy(960)}; } // Breakpoint for large desktops and HD devices @media (min-width: 1200px) { max-width: ${remy(1140)}; } ` // Grid row const GridRow = sc.div` margin-right: ${remy(-15)}; margin-left: ${remy(-15)}; display: flex; flex-wrap: wrap; ` // Grid columns const GridColumn = sc.div` padding-right: ${remy(15)}; padding-left: ${remy(15)}; // Columns for mobile ${({ xs }) => (xs ? getFlex(xs) : 'flex: 0 0 100%')}; ${({ xs }) => (xs ? getWidth(xs) : 'width: 100%')}; // Columns for tablets @media (min-width: 576px) { ${({ sm }) => sm && getFlex(sm)}; ${({ sm }) => sm && getWidth(sm)}; } // Columns for small desktops @media (min-width: 768px) { ${({ md }) => md && getFlex(md)}; ${({ md }) => md && getWidth(md)}; } // Columns for medium desktops @media (min-width: 992px) { ${({ lg }) => lg && getFlex(lg)}; ${({ lg }) => lg && getWidth(lg)}; } // Columns for large desktops and HD devices @media (min-width: 1200px) { ${({ xl }) => xl && getFlex(xl)}; ${({ xl }) => xl && getWidth(xl)}; } `