Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

if statement inside styled component

export enum SizeEnum {
    Small,
    Large
}

export interface ICheckbox {
    Size: SizeEnum;
}

const Box = styled.div`
    height: 20px;
    width: 20px;
`

In the above code I want to be able to conditionally change the height and width value of <Box> based on the prop. How do I do this?

like image 409
blankface Avatar asked Apr 10 '18 05:04

blankface


Video Answer


1 Answers

Another way to do this, if you want to add several css styles.

const Box = styled.div`
    height:100px;
    width:100px;
    ${props => props.Size === 'Small' && css`
         height:20px;
         width:20px;
    `}
`
like image 190
subharb Avatar answered Nov 15 '22 08:11

subharb