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
This is a really big task and I would suggest starting small. Try to convert one component, one small component. Transform a SCSS placeholder into a generic component. Something like that.
Hi @catarak . I have worked on the "About Component". While working on the issue I faced a challenge where themify mixin was used. Please suggest to me how to counter the problem.
@catarak I am trying to convert the NavBasic.jsx file to styled component. I am having difficulties converting the following "theme mixin" code: @include themify() { border-bottom: 1px dashed map-get($theme-map, 'nav-border-color'); }
Can you suggest to me how to solve this?
Hey @catarak
I don't like the way this issue is going forward.Please assign this to someone and let it go in one single direction with a clear idea on how to tackle this.
Please do it fast as many are trying to contribute to this which may lead to some work done which is not used in the repo.
Sorry for the delay in responding to this issue and all of the related pull requests! I was on a GitHub hiatus and now I am making my way through issues/PRs. I agree with @satyasaibhushan, that this needs to be approached component by component with small PRs rather than with large PRs. It will be too difficult for me to review huge PRs with a lot of changes, and unfortunately I'm going to have to close those PRs.
Easier to convert existing components which use classNames to combine multiple conditional classes.
Can use classes on the top-level styled element or on deeply nested components. In other words, this works with both 1A and 1B whereas 2A only works with 1A.
Don't need to worry about declaring extra props in propTypes.
Works better alongside the existing prop utility function for accessing theme variables. This utility returns a function of props so it needs special handling to work within a ${(props) => function (ie. ${(props) => props.isSelected ? prop('primaryTextColor')(props) : prop('secondaryTextColor')(props)})
Thanks @lindapaiste for the thorough explanations and examples! I'm not too familiar with styled-components, so my understanding of this might need some clarification!
I'm leaning towards 1B and 2B particularly because of their ease in converting existing components (and I think it's also how it's currently implemented in the mobile components?). However, I also like the readability and cleanliness of 1A, and might be better to implement for the longterm because of the listed advantages. Ultimately though, I think you and @dewanshDT should go with what feels best and makes sense for the both of you! Is there an approach you preferred as well?
@lindapaiste I was adding the styled-component to the About.jsx file. I added the logoColor property in the theme.js but its giving error that prop logoColor not found. I have added logoColor like this under light, dark and contract
@adityagarg06 The prop utility is a higher-order function so it actually returns a function of props. In your styled components you write color: ${prop('logoColor')}; and that's the equivalent of color: ${(props) => props.theme.logoColor};. There are no other styles in those components that depend on props so you don't need to have any ${props => or css` .
If there's a className on a React component that's not a built-in DOM element (looks like AsteriskIcon is the only one on this page) you can still use styled on it.
(BTW, I'm looking at this About component right now and it really irks me that we have a "list" which is not semantically a list because we're not using ul and li. But one thing at a time...)
(For the record, I don't like that we use the &&& in core UI elements like Button and icons because it makes it hard to override when we want to extend it. But that's not an issue with the About components as they're not used anywhere else.)
Activity
rt1301 commentedon Feb 12, 2021
@catarak I would like to work on this issue if it is open. Can you suggest me how to get started on this?
Ajaya1000 commentedon Feb 17, 2021
@catarak as this is a pretty long implementation I would like to work with @rt1301 to speed up the process. Can you please guide us.
catarak commentedon Feb 19, 2021
This is a really big task and I would suggest starting small. Try to convert one component, one small component. Transform a SCSS placeholder into a generic component. Something like that.
satyasaibhushan commentedon Mar 5, 2021
Hey @catarak,
I've converted a small component, please check and give your suggestions and thoughts!
[processing#1760]Added logoColor
[processing#1760] About Component scss to styled component
Ajaya1000 commentedon Mar 15, 2021
Hi @catarak . I have worked on the "About Component". While working on the issue I faced a challenge where themify mixin was used. Please suggest to me how to counter the problem.
[processing#1760] fixed issue with hovering
9 remaining items
rt1301 commentedon Mar 17, 2021
@catarak I am trying to convert the NavBasic.jsx file to styled component. I am having difficulties converting the following "theme mixin" code:
@include themify() { border-bottom: 1px dashed map-get($theme-map, 'nav-border-color'); }
Can you suggest to me how to solve this?
satyasaibhushan commentedon Mar 17, 2021
Hey @catarak
I don't like the way this issue is going forward.Please assign this to someone and let it go in one single direction with a clear idea on how to tackle this.
Please do it fast as many are trying to contribute to this which may lead to some work done which is not used in the repo.
catarak commentedon May 4, 2021
Sorry for the delay in responding to this issue and all of the related pull requests! I was on a GitHub hiatus and now I am making my way through issues/PRs. I agree with @satyasaibhushan, that this needs to be approached component by component with small PRs rather than with large PRs. It will be too difficult for me to review huge PRs with a lot of changes, and unfortunately I'm going to have to close those PRs.
lindapaiste commentedon May 13, 2023
I have questions about the preferred code style for implementing
styled-components
@raclim @dewanshDTThis is very subjective but I'll lay out some pros and cons with examples so you can see what I mean.
Question 1: Should each component use one
styled
element or many?Approach A: Use
styled
separately on each DOM element.Advantages:
PageTitle
).PageTitle
don't depend on its context.Approach B: Use nested CSS to style child elements of on main
styled
componentNote: this can be done by targeting elements like
h1
,p
, etc. or class names like.title
.Advantages:
Question 2: Should conditional styling be applied through props or classes?
Approach A: Styles depend on the
props
of thestyled
componentAdvantages:
styled-components
because it doesn't need any CSS class names.Approach B: Styles depend on class names
Advantages:
classNames
to combine multiple conditional classes.styled
element or on deeply nested components. In other words, this works with both 1A and 1B whereas 2A only works with 1A.propTypes
.prop
utility function for accessing theme variables. This utility returns a function ofprops
so it needs special handling to work within a${(props) =>
function (ie.${(props) => props.isSelected ? prop('primaryTextColor')(props) : prop('secondaryTextColor')(props)}
)or
Example codes on CodeSandbox
dewanshDT commentedon May 13, 2023
hey @lindapaiste I think we should go with 1A and 2B, I agree with the advantages that come with them.
raclim commentedon May 17, 2023
Thanks @lindapaiste for the thorough explanations and examples! I'm not too familiar with
styled-components
, so my understanding of this might need some clarification!I'm leaning towards 1B and 2B particularly because of their ease in converting existing components (and I think it's also how it's currently implemented in the mobile components?). However, I also like the readability and cleanliness of 1A, and might be better to implement for the longterm because of the listed advantages. Ultimately though, I think you and @dewanshDT should go with what feels best and makes sense for the both of you! Is there an approach you preferred as well?
adityagarg06 commentedon Jul 31, 2023
@lindapaiste I was adding the styled-component to the About.jsx file. I added the logoColor property in the theme.js but its giving error that prop logoColor not found. I have added logoColor like this under light, dark and contract
About.jsx
lindapaiste commentedon Jul 31, 2023
@adityagarg06 The
prop
utility is a higher-order function so it actually returns a function ofprops
. In your styled components you writecolor: ${prop('logoColor')};
and that's the equivalent ofcolor: ${(props) => props.theme.logoColor};
. There are no other styles in those components that depend on props so you don't need to have any${props =>
orcss`
.It should look like this:
If there's a
className
on a React component that's not a built-in DOM element (looks likeAsteriskIcon
is the only one on this page) you can still usestyled
on it.(BTW, I'm looking at this
About
component right now and it really irks me that we have a "list" which is not semantically a list because we're not usingul
andli
. But one thing at a time...)adityagarg06 commentedon Aug 1, 2023
@lindapaiste Thanks for helping, I have fixed the props but some styles are getting overridden by _mixin.scss.
lindapaiste commentedon Aug 1, 2023
Ugh yeah I have experienced that and it's really annoying. Feel free to put up a draft PR with what you have now.
One of the tricks that we used is to wrap the style in
&&& { }
to increase the specificity, like we do here.(For the record, I don't like that we use the
&&&
in core UI elements likeButton
and icons because it makes it hard to override when we want to extend it. But that's not an issue with theAbout
components as they're not used anywhere else.)styled-components
inKeyboardShortcutModal
#2356