import { css, styled } from '@compiled/react'; import React, { type JSX } from 'react'; import { primaryTaggedTemplateExpression, secondaryTaggedTemplateExpression } from './mixins'; export default { title: 'conditional rules/styled', }; interface TextProps { isPrimary?: boolean; isBolded?: boolean; isMaybe?: boolean; children: React.ReactNode; } const TextWithTemplateLiteral = styled.span` color: red; ${(props) => (props.isPrimary || props.isBolded) && { color: 'blue' }}; ${(props) => props.isPrimary && { fontSize: '20px' }}; `; const TextWithTernaryOperatorTemplateLiteral = styled.span` color: ${(props) => (props.isPrimary ? 'blue' : 'red')}; font-weight: ${(props) => props.isPrimary && props.isMaybe ? (props.isBolded && 'bold') || 'normal' : 'light'}; `; const TextWithNestedTernaryOperatorTemplateLiteralCssVariable = styled.span` color: ${(props) => (props.isPrimary ? (props.isMaybe ? 'orange' : 'blue') : 'red')}; `; const TextWithNestedTernaryOperatorTemplateLiteral = styled.span` ${(props) => props.isPrimary ? (props.isMaybe ? 'color: orange' : 'color: blue') : 'color: red'}; `; const TextWithObjectStyles = styled.span( { color: 'red' }, (props) => props.isPrimary && { color: 'blue' }, (props) => props.isBolded && { fontWeight: 'bold' }, css` text-transform: uppercase; ` ); const TextWithTernaryAndBooleanObjectStyle = styled.span({ fontSize: '20px' }, (props) => props.isPrimary && props.isBolded ? { color: 'blue', fontWeight: 'bold' } : { color: 'red' } ); const TextWithNestedTernaryAndBooleanObjectStyle = styled.span( { fontSize: '20px' }, (props) => props.isPrimary ? props.isBolded ? { color: 'blue', fontWeight: 'bold' } : { color: 'blue' } : { color: 'red' } ); const TextWithMixins = styled.span` ${(props) => props.isPrimary ? primaryTaggedTemplateExpression : secondaryTaggedTemplateExpression}; padding: 10px; `; const InlineMixin = styled.div` ${(props) => props.isPrimary ? css` color: green; ` : css({ color: 'red', })} `; const ComplexMixin = styled.div` ${(props) => props.isPrimary ? css` color: green; font-weight: ${({ isBolded }) => (isBolded ? 'bold' : undefined)}; ` : 'color: red'}; `; const KeyValueString = styled.div` ${(props) => (props.isPrimary ? 'color: green' : `color: red`)}; `; const NoValuePath = styled.div` ${(props) => (props.isPrimary ? undefined : 'color: red')} `; const DestructurededPropsValues = styled.div` color: ${({ isPrimary }) => (isPrimary ? 'green' : 'red')}; `; const DestructuredPropsKeyValueString = styled.div` ${({ isPrimary: primary }) => (primary ? 'color: green' : 'color: red')}; `; export const PrimaryTextWithTemplateLiteral = (): JSX.Element => { return Hello primary; }; export const NotPrimaryTextWithTemplateLiteral = (): JSX.Element => { return Hello secondary; }; export const PrimaryTextWithTernaryOperatorTemplateLiteral = (): JSX.Element => { return ( Hello primary ); }; export const BoldedPrimaryTextWithTernaryOperatorTemplateLiteral = (): JSX.Element => { return ( Hello bolded primary ); }; export const NotPrimaryTextWithTernaryOperatorTemplateLiteral = (): JSX.Element => { return ( Hello secondary ); }; export const PrimaryTextWithNestedTernaryOperatorTemplateLiteralCssVariable = (): JSX.Element => { return ( Hello primary (blue) ); }; export const PrimaryMaybeTextWithNestedTernaryOperatorTemplateLiteralCssVariable = (): JSX.Element => { return ( Hello primary maybe (orange) ); }; export const NotPrimaryTextWithNestedTernaryOperatorTemplateLiteralCssVariable = (): JSX.Element => { return ( Hello secondary (red) ); }; export const NotPrimaryMaybeTextWithNestedTernaryOperatorTemplateLiteralCssVariable = (): JSX.Element => { return ( Hello secondary (red) ); }; export const PrimaryTextWithNestedTernaryOperatorTemplateLiteral = (): JSX.Element => { return ( Hello primary (blue) ); }; export const PrimaryMaybeTextWithNestedTernaryOperatorTemplateLiteral = (): JSX.Element => { return ( Hello primary maybe (orange) ); }; export const NotPrimaryTextWithNestedTernaryOperatorTemplateLiteral = (): JSX.Element => { return ( Hello secondary (red) ); }; export const NotPrimaryMaybeTextWithNestedTernaryOperatorTemplateLiteral = (): JSX.Element => { return ( Hello secondary (red) ); }; export const PrimaryTextWithObjectStyles = (): JSX.Element => { return Hello primary; }; export const BoldedPrimaryTextWithObjectStyles = (): JSX.Element => { return ( Hello bolded primary ); }; export const NotPrimaryTextWithObjectStyles = (): JSX.Element => { return Hello secondary; }; export const PrimaryTextWithTernaryAndBooleanObjectStyle = (): JSX.Element => { return ( {' '} Hello primary but not bolded. This should be red ); }; export const BoldedPrimaryTextWithTernaryAndBooleanObjectStyle = (): JSX.Element => { return ( {' '} Hello bolded primary ); }; export const NotPrimaryTextWithTernaryAndBooleanObjectStyle = (): JSX.Element => { return ( Hello secondary ); }; export const PrimaryTextWithNestedTernaryAndBooleanObjectStyle = (): JSX.Element => { return ( {' '} Hello primary but not bolded. This should be blue. ); }; export const BoldedPrimaryNestedTextWithTernaryAndBooleanObjectStyle = (): JSX.Element => { return ( {' '} Hello bolded primary. This should be blue. ); }; export const NotPrimaryTextWithNestedTernaryAndBooleanObjectStyle = (): JSX.Element => { return ( // should not render bold since it is not also primary {' '} Hello secondary ); }; export const NotPrimaryNotBoldedTextWithNestedTernaryAndBooleanObjectStyle = (): JSX.Element => { return ( {' '} Hello secondary ); }; export const PrimaryTextWithMixins = (): JSX.Element => { return Hello primary; }; export const SecondaryTextWithMixins = (): JSX.Element => { return Hello secondary; }; export const TextWithInlineMixin = (): JSX.Element => (
Using css`` Using css()
); export const TextWithComplexMixin = (): JSX.Element => (
Primary text using mixin with bold condition Primary text using mixin without bold condition Secondary text
); export const TextWithKeyValueString = (): JSX.Element => (
color: green color: red
); export const ConditionWithNoValuePath = (): JSX.Element => { return (
Primary path with no given CSS Secondary path with CSS
); }; export const ConditionWithDestructedValues = (): JSX.Element => (
color: green color: red
); export const ConditionWithDestructuredPropsKeyValueString = (): JSX.Element => (
color: green color: red
);