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

keyframes in css function call in ternary operator not supported #1682

Open
dddlr opened this issue Jun 7, 2024 · 1 comment · May be fixed by #1683
Open

keyframes in css function call in ternary operator not supported #1682

dddlr opened this issue Jun 7, 2024 · 1 comment · May be fixed by #1683

Comments

@dddlr
Copy link
Collaborator

dddlr commented Jun 7, 2024

Example:

import { css, keyframes } from '@compiled/react';
import React, { lazy } from 'react';

const fadeIn = keyframes({
  from: {
      opacity: "0"
  },
  to: {
      opacity: "1"
  }
});
const slideInLeft = keyframes({
  from: {
      transform: "translateX(-100%)",
      opacity: "0"
  },
  to: {
      transform: "translateX(0%)",
      opacity: "1"
  }
});
const slideInRight = keyframes({
  from: {
      transform: "translateX(0%)",
      opacity: "0"
  },
  to: {
      transform: "translateX(100%)",
      opacity: "1"
  }
});
const fadeInCss = css({
  "opacity": "0",
  "animation": `0.4s ease-in ${fadeIn} 200ms forwards`
});
const slideInLeftCss = css({
  "opacity": "0",
  "animation": `0.5s ${slideInLeft} forwards`
});
const slideInRightCss = css({
  "opacity": "0",
  "animation": `0.5s ${slideInRight} forwards`
});

const firstOpen = false;

export const App = () => (
  <>
    <div css={[firstOpen ? fadeInCss : slideInRightCss]}>hello world</div>
  </>
);

Workaround: using logical operator instead of a ternary operator.

<div css={[firstOpen && fadeInCss, !firstOpen && slideInRightCss]}>hello world</div>
@dddlr dddlr linked a pull request Jun 7, 2024 that will close this issue
3 tasks
@kylorhall-atlassian
Copy link
Collaborator

Related to #389 @dddlr ?

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

Successfully merging a pull request may close this issue.

2 participants