Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

css: migrate from styled comps to plan css or css-modules #792

Closed
jorgeorpinel opened this issue Nov 14, 2019 · 14 comments
Closed

css: migrate from styled comps to plan css or css-modules #792

jorgeorpinel opened this issue Nov 14, 2019 · 14 comments
Labels
A: website Area: website type: enhancement Something is not clear, small updates, improvement suggestions

Comments

@jorgeorpinel
Copy link
Contributor

jorgeorpinel commented Nov 14, 2019

Extracted from #776 (comment)

Our styled components tend to be defined after the exported component in each file (pages/, src/) so it could be confusing to find them in the JSX of previously defined components.

However we want to keep them in the bottom of each file given their strange code format. The idea then is to RENAME them so it's more obvious that they are styled components. My proposal is to simply add the name of the HTML tag they use in CamelCase. For example a Container component that styles a div tag would be renamed ContainerDiv and look like this in JSX.

UPDATE: Probably going for extracting and not renaming. See #792 (comment)

@jorgeorpinel jorgeorpinel added type: enhancement Something is not clear, small updates, improvement suggestions good first issue Good for newcomers A: docs Area: user documentation (gatsby-theme-iterative) labels Nov 14, 2019
@shcheklein
Copy link
Member

I would check if there are best practices around this. Also, would love to know @iAdramelk 's take on this.

@jorgeorpinel jorgeorpinel added the type: discussion Requires active participation to reach a conclusion. label Nov 14, 2019
@jorgeorpinel
Copy link
Contributor Author

I don't think styled-components.com are so used that there will be broadly established practices around it but I did look this up just now and found https://medium.com/inturn-eng/naming-styled-components-d7097950a245 where they propose using StyledContainer or S.Container, which is what Alexey suggested in #776 (comment). But I still like ContainerDiv more. Let's just vote on it?

@jorgeorpinel
Copy link
Contributor Author

jorgeorpinel commented Dec 29, 2019

  • BTW if we do this and rename the Link styles components to something else, we should probably rename NextLink to just Link (it's natural name from next/link).

@jorgeorpinel
Copy link
Contributor Author

jorgeorpinel commented Dec 29, 2019

Oh, and another option to consider for all this is to migrate to https://github.com/zeit/styled-jsx (supported out-of-box in Next.js) but doesn't support nested styles I think.

@jorgeorpinel jorgeorpinel removed the type: discussion Requires active participation to reach a conclusion. label Dec 29, 2019
@jorgeorpinel
Copy link
Contributor Author

Do you have a vote here, @iAdramelk? Thanks

@iAdramelk
Copy link
Contributor

@jorgeorpinel I do think that we should probably move them to the separate files at least. I started experimenting with this approach in #874 (check the files in src/Community) and I think that this way it is a lot more convenient. We can rename them too, but if we move them to the separate files it is not that important, because it is easier to understand that they are a part of the styles. Alternatively, naming convention can be to add prefix to them. Like SCLink instead of Link. This way we will not lock ourselves in using predefined tags there and will be able to change tags without changing component names.

I checked styled-jsx and I am not a big fan of it, it looks janky to me. But I very much want to replace styled-comonents with something that not requires runtime and builds to static css files, like https://github.com/4Catalyzer/astroturf . Right now styled-components is making our bundle size unnecessary large and slows down pages render speed (and also make react profiling tools almost impossible to use). Alternatively, latest version of Next has added css-modules support so we can just switch to normal css instead (old versions of Next didn't work with normal css correctly)

@jorgeorpinel jorgeorpinel changed the title React: rename styled components for readability React: rename/extract styled components for readability Dec 30, 2019
@jorgeorpinel
Copy link
Contributor Author

jorgeorpinel commented Dec 30, 2019

We can rename them too, but if we move them to the separate files it is not that important, because it is easier to understand that they are a part of the styles.
Example: https://github.com/iterative/dvc.org/pull/874/files?file-filters%5B%5D=.js#diff-6f1eb6a2d283c5cf998903a810e9f7a3

Agree. Probably no need to rename them if they're moved. I'd call the source file styled.js BTW (left a comment in your PR).

add prefix to them. Like SCLink instead of Link. This way we will not lock ourselves

I don't really see the need. There's no locking since you can always rename them at import. I don't love any of the prefixes or suffixes we've suggested here anyway.

@jorgeorpinel
Copy link
Contributor Author

jorgeorpinel commented Dec 30, 2019

I checked styled-jsx ... looks janky. But I very much want to replace styled-comonents with something ... builds to static

Well, styled-jsx comes from the same developers as Next.js haha...
UPDATE: More officially recommended options: https://github.com/zeit/next.js#css-in-js

Agree about substituting styled-components eventually, but probably needs a separate issue? Unless you think it's a high priority (cc @shcheklein) because that would basically render this and possibly other issues no-longer-relevant.

Rewriting with https://github.com/css-modules/css-modules sounds like the easiest option to me at this point, BTW. But we can list and discuss the options in a new issue if you guys agree.

@shcheklein shcheklein changed the title React: rename/extract styled components for readability rename/extract styled components for readability Dec 30, 2019
@shcheklein shcheklein added the website: eng-doc DEPRECATED JS engine for /doc label Dec 30, 2019
@jorgeorpinel jorgeorpinel changed the title rename/extract styled components for readability app: rename/extract styled comps for readability Jan 10, 2020
@fabiosantoscode
Copy link
Contributor

fabiosantoscode commented Jan 16, 2020

Hey, https://emotion.sh is a thing.

It has all the features of styled-components, plus it can easily give you class names that you can pass to random libraries on NPM, react or not. It's more likely that you can customise a className than that you're able to control the element generation just to change a style.

Plus it has a css prop thing (granted, it requires a babel plugin) that allows you to define the styles right in the divs and spans and whatever which use them.

Worth a look?

@shcheklein
Copy link
Member

shcheklein commented Jan 16, 2020

@fabiosantoscode @iAdramelk is migrating dvc.org to Gatsby now and probably we'll use the same convention eventually (postcss?) . @iAdramelk could you shed some light here?

@jorgeorpinel jorgeorpinel added A: website Area: website help wanted Contributors especially welcome and removed A: docs Area: user documentation (gatsby-theme-iterative) good first issue Good for newcomers labels Jan 19, 2020
@jorgeorpinel jorgeorpinel changed the title app: rename/extract styled comps for readability js: rename/extract styled comps for readability Jan 19, 2020
@iAdramelk
Copy link
Contributor

@fabiosantoscode thanks for suggestion, but the thing is, we didn't really need css-in-js library. We don't use any of it's advanced capabilities and in our case just importing css without the need for a runtime will be a lot better for the perfomance. The main reason why we use styled-components is because next.js can't work with plain css or css-modules. But we are now migrating to gatsby which didn't have this problem, and even if we didn't migrate, next version of next.js will support css-modules out of the box.

@jorgeorpinel jorgeorpinel removed help wanted Contributors especially welcome website: eng-doc DEPRECATED JS engine for /doc labels Jan 20, 2020
@jorgeorpinel jorgeorpinel changed the title js: rename/extract styled comps for readability css: migrate from styled comps to plan css or css-modules Jan 20, 2020
@jorgeorpinel
Copy link
Contributor Author

@iAdramelk @shcheklein so is this issue still valid? If the Gatsby migration is definitive, let's close it?

@shcheklein
Copy link
Member

let's keep, we'll close all the tickets with the engine label (those that will become obsolete) at once after the migration. Since it's not over, the issue is still relevant.

@shcheklein
Copy link
Member

Fixed by the recent migration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A: website Area: website type: enhancement Something is not clear, small updates, improvement suggestions
Projects
None yet
Development

No branches or pull requests

4 participants