GithubHelp home page GithubHelp logo

Comments (1)

dddlr avatar dddlr commented on June 14, 2024

Hmm that's a good question - we recommend using JS to detect the hover on Button and store this in a variable, and then pass the variable value as a prop to the Icon.

To give some reasons for why we suggest this: this is a performance compromise 😅, since even though using JS (as opposed to a pure CSS solution) does incur an extra cost...

  • Having complex selectors unnecessarily increases the css stylesheet size (works against our "atomic CSS" approach)
  • Nested selectors (e.g. .Button:hover .Icon) are not as efficient as simple selectors
  • For most components, JS will be already running something else anyway (e.g. logging)
  • Using JS allows for more flexible use cases (even when two elements are not nested in the DOM)

I made a quick React example below - I'm not the best with React so the onMouseEnter/onMouseLeave could probably be optimised a bit:

const Button = styled.div({ fontSize: '25px' });
const Icon = styled.div({
    color: (prop) => prop.isHover ? 'red' : 'black',
});

const Component = () => {
  const [isHover, setIsHover] = React.useState(false);
  return <>
    <Button onMouseEnter={() => setIsHover(true)} onMouseLeave={() => setIsHover(false)}>
      <Icon isHover={isHover}>hello world</Icon>
    </Button>
  </>;
}

If you're doing something inside JFE, we recommend asking DST to see if there's any atlaskit primitives or packages suitable for the kind of button that you're creating (or migrating)

from compiled.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.