Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Flex components more general-purpose #7

Open
good-idea opened this issue Jun 13, 2019 · 0 comments
Open

Make Flex components more general-purpose #7

good-idea opened this issue Jun 13, 2019 · 0 comments
Assignees
Labels

Comments

@good-idea
Copy link
Collaborator

I think that as the site grows, these Flex components are going to start getting more and more complicated:

export const FlexThree = styled.div`
	flex: 1 1 33%;
	max-width: 33.33%;
	margin: ${(props) => props.margin};
	${(props: WrapperProps) => `
   		${props.theme.mediaQueries.tablet} {
			max-width: ${props.mobileWidth === '2' ? '49.65%' : '33.33%'};
	 	}
	`}
`

We'll probably need to continue adding props (like tabletWidth or something) to suit the needs of all of the places where it is used.

Instead, it would be easier and more maintainable to make them more general purpose, then extending them for use in specific places. We could do this several ways:

  • Export them as simple components that only set up basic flex styles, then extend them later:
// Flex.tsx
export const Flex3 = styled.div`
	flex: 1 1 33%;
	max-width: 33.33%;
`

// checkout/styled.tsx
import { Flex3 } from 'Components/Layout/Flex'

const ProductWrapper = styled(Flex3)`
	// * margins, media queries, etc
`
  • Add some 'mixins' to the theme object:
// theme/mixins.tsx

export const flex3 = `
	flex: 1 1 33%;
	max-width: 33.33%;
`

// could be handy for other commonly-used sets of rules:
export const absFullSize = `
   position: absolute;
   top: 0;
   left: 0;
   width: 100%;
   height: 100%;
`

// checkout/styled.tsx

const ProductWrapper = styled.div`
  ${({ theme }) => css`
     ${theme.mixins.flex3};
     // * margins, media queries, etc
  `}
`
  • Or, just drop them completely in favor of just writing out the flex rules for each component. This isn't too DRY, but it simplifies things overall.
// checkout/styled.tsx
const ProductWrapper = styled.div`
	flex: 1 1 33%;
	max-width: 33.33%;
     // * margins, media queries, etc
`

I removed the usage of the Flex containers on the PDP and PLP pages. I broke some of the styling in the process 🤦🏼‍♂️and probably should have left it alone. So now they are only used in the Checkout component. They're fine as-is, but let's deprecate them and, as you make any changes to Checkout, build out checkout-specific styled components

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants