You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for the great work on the project.
I was wondering if there is a good way to handle components which look differently depending on a prop. example:
exportinterfaceIProps{type?: 'primary'|'secondary';// optional, defaults to default style}
My approach:
case 1: component has a container element of sorts
The approach is not pretty at all IMO. It shouldn't be solved with @extend, also readability 😭.
case 2: component does not have a container element
// Button.tsxconstButton: React.SFC<IProps>=(props)=>{consttheme=getThemeFromProps(style,props);return(<Child><a>Example use case.</a></Child>);}
No idea how to solve this as .A > .B cannot be used (we do not want to add extra wrapper divs, it could result in unexpected layout changes we'd then have to fix with css, also DOM bloat).
Why I think making type wrappers is bad
In my opinion creating wrapper components for every type is not practical, also it's merely a visual rather than semantic difference.
Imagine we have more than 10 type variants per component and we are working with a big code-base.
The project will be a bloated mess in no time.
The text was updated successfully, but these errors were encountered:
Not sure that I've got your question correctly, but if you have a Button with different types, the easiest way to style it would be something like that. Assume your default type is standard, primary and secondary are optionals.
importPropTypesfrom'prop-types';import{PureComponent}from'react';import{mixThemeWithProps}from'@css-modules-theme/react';importstylesfrom'./Button.css';exportdefaultclassButtonextendsPureComponent{staticpropTypes={// The html style of the buttonstyle: PropTypes.oneOf(['standard','primary','secondary']),};staticdefaultProps={style: 'standard',}render(){// Use mixThemeWithProps to pass all the rest props directly to domconst{style, theme, ...buttonProps}=mixThemeWithProps(styles,this.props);// Don't need to concatenate `.button` classname with classname for style type, // because they already concatenated statically using `compose` in css.buttonProps.className=theme[style];return<button{...buttonProps}>;
}}
Thanks for the great work on the project.
I was wondering if there is a good way to handle components which look differently depending on a prop.
example:
My approach:
case 1: component has a container element of sorts
The approach is not pretty at all IMO. It shouldn't be solved with
@extend
, also readability 😭.case 2: component does not have a container element
No idea how to solve this as
.A > .B
cannot be used (we do not want to add extra wrapper divs, it could result in unexpected layout changes we'd then have to fix with css, also DOM bloat).Why I think making type wrappers is bad
In my opinion creating wrapper components for every type is not practical, also it's merely a visual rather than semantic difference.
Imagine we have more than 10 type variants per component and we are working with a big code-base.
The project will be a bloated mess in no time.
The text was updated successfully, but these errors were encountered: