-
Notifications
You must be signed in to change notification settings - Fork 6
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
Update docs #254
base: main
Are you sure you want to change the base?
Update docs #254
Conversation
🦋 Changeset detectedLatest commit: d4bc2fd The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -1,514 +1,582 @@ | |||
--- | |||
title: Migration from styled-components | |||
description: We tried to keep the changes you need to know if you're already familiar with styled-components to a minimum. | |||
description: We tried to keep the changes you need to know if you're already familiar with styled-components to a minimum. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description: We tried to keep the changes you need to know if you're already familiar with styled-components to a minimum. | |
description: `next-yak` provides a RSC compatible API which is very similar to the `styled-components` API. In most cases the only change necessary is the import. However there are some edge cases which have to be migrated manually. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we could also mention that this was one of the core goals of yak so we can switch from styled-components without losing all the know-how and dev tooling
packages/docs/content/docs/migration-from-styled-components.mdx
Outdated
Show resolved
Hide resolved
Otherwise it will be treated as a part of the styles and our parser has no way to differentiate between the two. | ||
</Callout> | ||
|
||
### Attrs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move after keyframes?
|
||
In order to create a selector that includes another component, you can just reference it in the tagged | ||
template literal. | ||
Other usages of styled-components need a bit more work. Yak files are special files that are evaluated during build time and can be used to store static values that are extracted during build time. You can create a `.yak.ts` file everywhere in your project and it will be picked up by next-yak. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other usages of styled-components need a bit more work. Yak files are special files that are evaluated during build time and can be used to store static values that are extracted during build time. You can create a `.yak.ts` file everywhere in your project and it will be picked up by next-yak. | |
Migrating `styled-components` with complex logic might need a bit more work. Yak files are special files that are evaluated during build time and can be used to store static values that are extracted during build time. You can create a `.yak.ts` or `.yak.tsx` file everywhere in your project and it will be picked up by next-yak. | |
<Callout> | |
**Important note on `.yak.tsx` files**: | |
As yak files are evaluated on every code change, they will slow down your dev experience and your production build times. They should only be used as a last resort. | |
</Callout> |
import styled, { css } from 'styled-components'; | ||
Another use case for yak files is to store shared values that are used across your application. | ||
Next-yak tries to optimize each file individually and doesn't share values between files. | ||
So if you have a value that is used in multiple files, you should move it to a yak file so that it can be optimized across all files. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should explain that everything but calculations and string concatenations work WITHOUT yak files and should be preferred to keep the compilation fast
|
||
Change the import from `styled-components` to `next-yak` and change the import of `styled` from a default import | ||
to a named import. | ||
### CSS prop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### CSS prop | |
### CSS prop (optional) |
}; | ||
``` | ||
|
||
You can then use these values in your styled components. | ||
Unfortunately, you can't use dynamic values in the css prop. If you need to use dynamic values, you should create a styled component with the styles from the css prop. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead show an example how dynamic runtime props work here
```tsx | ||
import { styled } from 'next-yak'; | ||
import { colors, breakpoints } from './constants.yak'; | ||
### Dynamic component styles |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should move this up (before yak files) under a Performance section
const Button = (props) => props.$primary | ||
? <button className="next-yak-1">Click me</button> | ||
: <button className="next-yak-2">Click me</button> | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const Button = (props) => props.$primary | |
? <button className="next-yak-1">Click me</button> | |
: <button className="next-yak-2">Click me</button> | |
``` | |
const Button = (props) => | |
<button className={props.$primary ? "next-yak-1" : "next-yak-2"}> | |
Click me | |
</button> |
color: ${props => props.$primary ? "white" : "#BF4F74"}; | ||
|
||
/* Alternative syntax */ | ||
${props => props.$primary ? "color: white;" : "color: #BF4F74;"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here css`...`
is missing - which is also important when migrating - should we also mention this somewhere?
|
||
```tsx title="util.yak.ts" | ||
export const allColors = { // [!code ++] | ||
"red": { // [!code ++] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it ok to use css objects like this or should this also be wrapped with "css``"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it's a constant in this case - so that should be fine
7b7ead0
to
1e840a7
Compare
}; // [!code --] | ||
``` | ||
|
||
```tsx title="util.yak.ts" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this needs to be a .yak
file
Updated docs
next-yak
Preview: https://next-yak-docs-9njrd6pud-jan-nicklas-projects.vercel.app/