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

Update docs #254

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Update docs #254

wants to merge 20 commits into from

Conversation

Mad-Kat
Copy link
Collaborator

@Mad-Kat Mad-Kat commented Jan 2, 2025

Updated docs

  • Gave the landing page a make over
  • Styled almost all with next-yak
  • Overhauled the migration guide
  • Streamlined the rest

Preview: https://next-yak-docs-9njrd6pud-jan-nicklas-projects.vercel.app/

Copy link

changeset-bot bot commented Jan 2, 2025

🦋 Changeset detected

Latest commit: d4bc2fd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
next-yak Patch
yak-swc Patch

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

@Mad-Kat Mad-Kat changed the base branch from fix-css-prop-in-exported-component to main January 2, 2025 19:40
@Mad-Kat Mad-Kat marked this pull request as ready for review January 2, 2025 19:41
@Mad-Kat Mad-Kat changed the base branch from main to fix-css-prop-in-exported-component January 2, 2025 19:49
@DigitecGalaxus DigitecGalaxus deleted a comment from codspeed-hq bot Jan 2, 2025
@Mad-Kat Mad-Kat requested a review from jantimon January 2, 2025 19:49
@@ -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.
Copy link
Collaborator

@jantimon jantimon Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Collaborator

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

Otherwise it will be treated as a part of the styles and our parser has no way to differentiate between the two.
</Callout>

### Attrs
Copy link
Collaborator

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### 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.
Copy link
Collaborator

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
Copy link
Collaborator

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

Comment on lines +399 to +402
const Button = (props) => props.$primary
? <button className="next-yak-1">Click me</button>
: <button className="next-yak-2">Click me</button>
```
Copy link
Collaborator

@jantimon jantimon Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;"}
Copy link
Collaborator

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 ++]
Copy link
Collaborator

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``"?

Copy link
Collaborator

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

@Mad-Kat Mad-Kat force-pushed the fix-css-prop-in-exported-component branch from 7b7ead0 to 1e840a7 Compare January 7, 2025 18:47
}; // [!code --]
```

```tsx title="util.yak.ts"
Copy link
Collaborator

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

Base automatically changed from fix-css-prop-in-exported-component to main January 8, 2025 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants