Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
Adding controls to html classes in storybook

I am working on a tailwind + storybook component library where the theme colors change based on the class that is given to the html element.

Since components will have different colors in different themes, it would be great to have a theme toggle control in each story.

To achieve that, I was wondering if there is a way to add and remove a class to the html of each story preview with a control?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In order to get conditional classes on React you can use build the string for the className prop of your component like this:

render() {
  let className = 'menu';
  if (this.props.isActive) {
    className += ' menu-active';
  }
  return <span className={className}>Menu</span>
}

Although it is recommended using the classNames utility in order to simplify this process like this:

render () {
    var btnClass = classNames({
      btn: true,
      'btn-pressed': this.state.isPressed,
      'btn-over': !this.state.isPressed && this.state.isHovered
    });
    return <button className={btnClass}>{this.props.label}</button>;
  }

You can read more about this in the React docs or in the classNames docs.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!