next-yak 0.0.20 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,34 +1,22 @@
1
1
  # next-yak
2
2
 
3
- yet another CSS-in-JS library
4
-
5
- a CSS-in-JS with the power of "dynamic at the speed and reliability of static" 🙃
6
-
7
- the initial version of next-yak will only work for next.js
8
-
9
3
  ![Yak At Work as Frontend Dev](https://github.com/jantimon/next-yak/assets/4113649/2dcaf443-7205-4ef3-ba44-fbbe3ef2807d)
10
4
 
5
+ [![npm version](https://badge.fury.io/js/next-yak.svg)](https://www.npmjs.com/package/next-yak)
6
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jantimon/next-yak/blob/main/LICENSE)
11
7
 
12
- ## Example
8
+ **next-yak** is a CSS-in-JS solution tailored for [Next.js](https://nextjs.org/) that seamlessly combines the expressive power of styled-components syntax with efficient build-time extraction of CSS using Next.js's built-in CSS configuration.
13
9
 
14
- Try it on [stackblitz](https://stackblitz.com/edit/stackblitz-starters-dfykqy?file=app%2Fpage.tsx)
15
10
 
16
- ```tsx
17
- import { styled, css } from "next-yak";
11
+ ## Features
18
12
 
19
- const Title = styled.h1<{ x: number; children: React.ReactNode }>`
20
- display: block;
21
- ${({ $x }) => $x % 2 === 0 && css`color: red`}
22
- position: relative;
23
- top: ${({ $x }) => `${$x * 100}px`};
24
- `;
13
+ - **NextJs Compatibility**: Works smoothly with both React Server and Client Components
14
+ - **Build-time CSS**: Reduces load time by handling CSS during the build phase, using Next.js built-in CSS Modules features
15
+ - **Lightweight Runtime**: Operates with minimal impact, simply changing CSS classes without modifying the CSSOM
16
+ - **Standard CSS Syntax**: Write styles in familiar, easy-to-use CSS
17
+ - **Integrates with Atomic CSS**: Easily combines with atomic CSS frameworks like Tailwind CSS for more design options
25
18
 
26
- const App = () => (
27
- <Title $x={3}>
28
- Hello World
29
- </Title>
30
- );
31
- ```
19
+ [Preview (Video)](https://github.com/jantimon/next-yak/assets/4113649/5383f60c-3bab-4aba-906c-d66070b6116c)
32
20
 
33
21
  ## Installation
34
22
 
@@ -36,9 +24,25 @@ const App = () => (
36
24
  npm install next-yak
37
25
  ```
38
26
 
27
+ or
28
+
29
+ ```bash
30
+ yarn add next-yak
31
+ ```
32
+
33
+ ## Getting Started
34
+
35
+ Try it on [stackblitz](https://stackblitz.com/edit/stackblitz-starters-dfykqy?file=app%2Fpage.tsx)
36
+
37
+ ### Locally
38
+
39
+ 1. Install **next-yak** in your Next.js project.
40
+
41
+ 2. Add next-yak to your `next.config.js`:
42
+
39
43
  ```js
40
44
  // next.config.js
41
- const { withYak } = require("next-yak");
45
+ const { withYak } = require("next-yak/withYak");
42
46
 
43
47
  const nextConfig = {
44
48
  // your next.js config
@@ -47,10 +51,114 @@ const nextConfig = {
47
51
  module.exports = withYak(nextConfig);
48
52
  ```
49
53
 
54
+ 3. Ready to go:
55
+
56
+ ```jsx
57
+ // pages/index.js
58
+ import { styled } from 'next-yak';
59
+
60
+ const StyledDiv = styled.div`
61
+ color: #333;
62
+ padding: 16px;
63
+ background-color: #f0f0f0;
64
+ `;
65
+
66
+ function HomePage() {
67
+ return <StyledDiv>Hello, next-yak!</StyledDiv>;
68
+ }
69
+
70
+ export default HomePage;
71
+ ```
72
+
73
+ ## More Examples
74
+
75
+ ### Dynamic Styles
76
+
77
+ Dynamic Styles will only toggle the css class during runtime:
78
+
79
+ ```jsx
80
+ import { styled, css } from 'next-yak';
81
+
82
+ const ToggleButton = styled.button`
83
+ ${props => props.$active
84
+ ? css`background-color: green`
85
+ : css`background-color: lime`
86
+ };
87
+ color: white;
88
+ padding: 10px 20px;
89
+ `;
90
+ ```
91
+
92
+ [Dynamic Styles (Video)](https://github.com/jantimon/next-yak/assets/4113649/c5f52846-33e4-4058-9c78-efd98197d75f)
93
+
94
+ ### Dynamic Properties
95
+
96
+ Dynamic Properties use custom properties ([aka css variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties)) under the hood to extract the CSS at built time but modify properties at runtime:
97
+
98
+ ```jsx
99
+ import { styled } from 'next-yak';
100
+
101
+ const ProgressBar = styled.div`
102
+ width: ${props => `${props.$percent}%`};
103
+ height: 20px;
104
+ background-color: #3498db;
105
+ transition: width 0.3s ease-in-out;
106
+ `;
107
+
108
+ const ProgressBarContainer = styled.div`
109
+ border: 1px solid #ccc;
110
+ `;
111
+
112
+ const ExampleComponent = () => {
113
+ const progress = 75; // You can dynamically set this value
114
+
115
+ return (
116
+ <ProgressBarContainer>
117
+ <ProgressBar $percent={progress} />
118
+ </ProgressBarContainer>
119
+ );
120
+ };
121
+ ```
122
+
123
+ [Dynamic Props (video)](https://github.com/jantimon/next-yak/assets/4113649/2fa78f82-382c-465f-b294-2504739ea168)
124
+
125
+
126
+ ### Targeting Components
127
+
128
+ In next-yak, you can target other components directly using CSS selectors as long as they are **in the same file**:
129
+
130
+ ```jsx
131
+ import { styled, keyframes } from 'next-yak';
132
+
133
+ const flip = keyframes`
134
+ from { transform: rotateY(0deg); }
135
+ to { transform: rotateY(360deg); }
136
+ `;
137
+
138
+ const Glow = styled.div`
139
+ /* Add your Glow component styles here */
140
+ `;
141
+
142
+ const Text = styled.span`
143
+ display: inline-block;
144
+ ${Glow}:hover & {
145
+ animation: 1.5s ${flip} ease-out;
146
+ }
147
+ `;
148
+
149
+ const ExampleComponent = () => {
150
+ return (
151
+ <Glow>
152
+ <Text>This text will flip on hover.</Text>
153
+ </Glow>
154
+ );
155
+ };
156
+ ```
157
+
50
158
  ## Nesting
51
159
 
52
160
  `next-yak` supports nesting out of the box.
53
- Next.js 13 supports nesting only with the `postcss-nested` plugin.
161
+ [For now](https://github.com/css-modules/postcss-modules-local-by-default/pull/64) Next.js 13 supports nesting only with the `postcss-nested` plugin.
54
162
  Therefore you have to create a `postcss.config.js` file in your project root:
55
163
 
56
164
  ```js
@@ -62,6 +170,8 @@ module.exports = {
62
170
  };
63
171
  ```
64
172
 
173
+ [Nesting Example (video)](https://github.com/jantimon/next-yak/assets/4113649/33eeeb13-b0cf-499f-a1d3-ba6f51cf4308)
174
+
65
175
  ## Motivation
66
176
 
67
177
  Most of the existing CSS-in-JS libraries are either slow or have a complex api. This project tries to find a middle ground between speed and api complexity.
@@ -127,7 +237,7 @@ const Button = styled.button`
127
237
 
128
238
  ## Todos:
129
239
 
130
- This is a proof of concept. There are a lot of things that need to be done before this can be used in production:
240
+ next-yak is currently in the development phase, with several todos that must be completed before it is ready for production:
131
241
 
132
242
  - [ ] improve js parsing - right now it not reusing babel..
133
243
  - [ ] better sourcemaps
@@ -150,6 +260,20 @@ This is a proof of concept. There are a lot of things that need to be done befor
150
260
 
151
261
  </details>
152
262
 
153
- ## Prior art
263
+ ## Acknowledgments
264
+
265
+ Special thanks to the contributors and the inspiring projects that influenced next-yak:
266
+
267
+ - Styled-Components 💅: For pioneering the styled syntax and redefining styling in the React ecosystem.
268
+ - Linaria: For its innovative approach to zero-runtime CSS in JS and efficient styling solutions.
269
+ - Emotion: For pushing the boundaries of CSS-in-JS and providing a high-performance styling experience.
270
+ - Vanilla Extract: For its focus on type-safe, zero-runtime CSS and contributing to the evolution of styling techniques.
271
+ - Tailwind CSS: For its exceptional atomic CSS approach, enabling efficient and customizable styling solutions.
272
+
273
+ ## License
274
+
275
+ **next-yak** is licensed under the [MIT License](link/to/LICENSE).
276
+
277
+ ---
154
278
 
155
- This POC is heavily inspried by [styled-components](https://styled-components.com/), [emotion](https://emotion.sh/docs/introduction) and [linaria](https://github.com/callstack/linaria).
279
+ Feel free to reach out with any questions, issues, or suggestions!