Skip to content

Set theme for external component with prefix #13264

Answered by Vijaykv5
pplonski asked this question in Help
Discussion options

You must be logged in to vote

Hi @pplonski
To set the theme both in the component, which requires a prefix like tw-, and the website without a prefix, you can do a conditional approach.

For you components, you can do like this:

  • you can define a prop in your component to receive the theme.
  • Use a ternary operator to append the prefix.
  • Apply the theme class to your component's elements.
function YourComponent({ theme }) {
  const prefixedTheme = theme.startsWith("tw-") ? theme : `tw-${theme}`;
  
  return (
    <div className={`${prefixedTheme}`}>
    
    </div>
  );
}

For you website, you can do like this:

  • Just use the theme name directly without any prefix.
  • Render the component and pass the theme as a prop.
f…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@pplonski
Comment options

Answer selected by pplonski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants