-
Notifications
You must be signed in to change notification settings - Fork 0
Matchers
Add conditional properties matching a given prop name and optional value. If the second param is not given, the prop is treated like a boolean.
const Test = styled.div`
${is('enabled')`
color: green;
`}
${is('size', 'big')`
font-size: 20px;
`}
`;
const Example = () => <Test enabled size="big">test</Test>;
Add conditional properties not matching a given prop name and optional value. If the second param is not given, the prop is treated like a boolean.
const Test = styled.div`
${isnt('enabled')`color: green`};
${isnt('size', 'big')`
font-size: 16px;
`}
`;
const Example = () => <Test size="small">test</Test>;
Add conditional properties when a prop matches a value in a given array.
const Test = styled.div`
${isAny('size', ['small', 'medium'])`color: green`};
`;
const Example = () => <Test size="small">test</Test>;
Add conditional properties when a prop is not within a given array.
const Test = styled.div`
${isntAny('size', ['small', 'medium'])`color: green`};
`;
const Example = () => <Test size="large">test</Test>;
Apply the value of a given prop name to a property.
const Test = styled.div`
width: ${value('size')};
`;
const Example = () => <Test size="4rem">test</Test>;
A quick way to apply values for both the true and false condition of a boolean prop.
const Test = styled.div`
color: ${swap('enabled', 'green', 'red')};
`;
const Example = () => <Test enabled>test</Test>;
Map the potential values of a given prop to CSS properties.
const sizes = {
small: '10px',
medium: '20px',
large: '30px',
};
const Test = styled.div`
width: ${choose('size', sizes)};
`;
const Example = () => <Test size="medium">test</Test>;
Conditionally render properties when prop is greater than then given value.
const Test = styled.div`
${over('amount', 10)`color: green`};
`;
const Example = () => <Test amount={11}>test</Test>;
Conditionally render properties when prop is less than then given value.
const Test = styled.div`
${under('amount', 10)`color: green`};
`;
const Example = () => <Test amount={9}>test</Test>;
Conditionally render properties when prop is between two values.
const Test = styled.div`
${between('amount', 5, 10)`color: green`};
`;
const Example = () => <Test amount={7}>test</Test>;