@salty-css/core 0.0.1-alpha.98 → 0.0.1

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.
Files changed (136) hide show
  1. package/.saltyrc.schema.json +11 -3
  2. package/README.md +415 -47
  3. package/bin/index.cjs +3 -1
  4. package/bin/index.js +2 -2
  5. package/bin/main.cjs +448 -11
  6. package/bin/main.js +411 -209
  7. package/cache/resolve-dynamic-config-cache.cjs +24 -0
  8. package/cache/resolve-dynamic-config-cache.d.ts +1 -0
  9. package/cache/resolve-dynamic-config-cache.js +24 -0
  10. package/class-name-generator-B2Pb2obX.cjs +74 -0
  11. package/class-name-generator-YeSQe_Ik.js +75 -0
  12. package/compiler/as-class.cjs +753 -0
  13. package/compiler/as-class.d.ts +52 -0
  14. package/compiler/as-class.js +735 -0
  15. package/compiler/get-files.cjs +25 -0
  16. package/compiler/get-files.js +25 -0
  17. package/compiler/get-function-range.cjs +22 -0
  18. package/compiler/get-function-range.d.ts +1 -0
  19. package/compiler/get-function-range.js +22 -0
  20. package/compiler/helpers.cjs +25 -0
  21. package/compiler/helpers.d.ts +5 -0
  22. package/compiler/helpers.js +24 -0
  23. package/config/define-config.d.ts +1 -1
  24. package/config/index.cjs +16 -1
  25. package/config/index.d.ts +2 -1
  26. package/config/index.js +14 -2
  27. package/css/index.cjs +12 -1
  28. package/css/index.d.ts +4 -1
  29. package/css/index.js +10 -2
  30. package/css/keyframes.cjs +49 -0
  31. package/css/keyframes.d.ts +22 -0
  32. package/css/keyframes.js +49 -0
  33. package/css/media.cjs +93 -0
  34. package/css/media.d.ts +87 -0
  35. package/css/media.js +93 -0
  36. package/css/merge.cjs +15 -0
  37. package/css/merge.d.ts +7 -0
  38. package/css/merge.js +15 -0
  39. package/css/token.cjs +4 -0
  40. package/css/token.d.ts +1 -0
  41. package/css/token.js +4 -0
  42. package/dash-case-DIwKaYgE.cjs +9 -0
  43. package/dash-case-DblXvymC.js +10 -0
  44. package/define-templates-CVhhgPnd.js +60 -0
  45. package/define-templates-Deq1aCbN.cjs +59 -0
  46. package/factories/define-global-styles.d.ts +7 -0
  47. package/factories/define-media-query.d.ts +8 -0
  48. package/factories/define-templates.d.ts +27 -0
  49. package/factories/define-variables.d.ts +12 -0
  50. package/factories/index.cjs +37 -0
  51. package/factories/index.d.ts +4 -0
  52. package/factories/index.js +37 -0
  53. package/generators/class-name-generator.d.ts +7 -0
  54. package/generators/index.cjs +57 -0
  55. package/generators/index.d.ts +2 -0
  56. package/generators/index.js +58 -0
  57. package/generators/styled-generator.d.ts +20 -0
  58. package/generators/styles-generator.d.ts +22 -0
  59. package/helpers/color.d.ts +18 -0
  60. package/helpers/index.cjs +53 -0
  61. package/helpers/index.d.ts +2 -0
  62. package/helpers/index.js +53 -0
  63. package/helpers/viewport-clamp.d.ts +9 -0
  64. package/index-ByR0nfaf.cjs +4 -0
  65. package/index-DKz1QXqs.js +4 -0
  66. package/instances/classname-instance.cjs +31 -0
  67. package/instances/classname-instance.d.ts +10 -0
  68. package/instances/classname-instance.js +31 -0
  69. package/package.json +71 -8
  70. package/parse-styles-BTIoYnBr.js +232 -0
  71. package/parse-styles-CA3TP5n1.cjs +231 -0
  72. package/parsers/index.cjs +58 -0
  73. package/parsers/index.d.ts +5 -0
  74. package/parsers/index.js +59 -0
  75. package/parsers/parse-modifiers.d.ts +3 -0
  76. package/parsers/parse-styles.d.ts +13 -0
  77. package/parsers/parse-templates.d.ts +4 -0
  78. package/parsers/parse-tokens.d.ts +3 -0
  79. package/parsers/parser-types.d.ts +8 -0
  80. package/parsers/property-name-check.d.ts +1 -0
  81. package/parsers/unit-check.d.ts +7 -0
  82. package/pascal-case-By_l58S-.cjs +7 -0
  83. package/pascal-case-F3Usi5Wf.js +8 -0
  84. package/{react-styled-file-CGVf5n1B.js → react-styled-file-B99mwk0w.js} +2 -2
  85. package/react-styled-file-U02jek-B.cjs +11 -0
  86. package/react-vanilla-file-Bj6XC8GS.cjs +18 -0
  87. package/{react-vanilla-file-CCXbsjIb.js → react-vanilla-file-D9px70iK.js} +2 -2
  88. package/runtime/index.cjs +11 -0
  89. package/runtime/index.d.ts +7 -0
  90. package/runtime/index.js +11 -0
  91. package/salty.config-DjosWdPw.js +4 -0
  92. package/salty.config-cqavVm2t.cjs +4 -0
  93. package/server/index.cjs +4 -0
  94. package/server/index.d.ts +1 -0
  95. package/server/index.js +4 -0
  96. package/server/should-restart.d.ts +1 -0
  97. package/should-restart-CQsyHls3.cjs +17 -0
  98. package/should-restart-CXIO0jxY.js +18 -0
  99. package/templates/salty-reset.d.ts +2 -0
  100. package/to-hash-C05Y906F.cjs +24 -0
  101. package/to-hash-DAN2LcHK.js +25 -0
  102. package/types/cli-types.d.ts +10 -0
  103. package/types/config-types.d.ts +85 -0
  104. package/types/index.d.ts +44 -23
  105. package/util/dot-case.d.ts +1 -0
  106. package/util/index.cjs +14 -1
  107. package/util/index.js +11 -8
  108. package/viewport-clamp-CEmzmcSj.cjs +10 -0
  109. package/viewport-clamp-K553uXu3.js +11 -0
  110. package/compiler/index.cjs +0 -1
  111. package/compiler/index.d.ts +0 -16
  112. package/compiler/index.js +0 -18
  113. package/config/config-types.d.ts +0 -65
  114. package/dash-case-DKzpenwY.cjs +0 -1
  115. package/dash-case-DMQMcCO6.js +0 -19
  116. package/generator/index.cjs +0 -1
  117. package/generator/index.d.ts +0 -1
  118. package/generator/index.js +0 -65
  119. package/generator/parse-modifiers.d.ts +0 -3
  120. package/generator/parse-styles.d.ts +0 -2
  121. package/generator/parse-templates.d.ts +0 -2
  122. package/generator/parse-tokens.d.ts +0 -2
  123. package/generator/parser-types.d.ts +0 -4
  124. package/generator/style-generator.d.ts +0 -33
  125. package/index-84Wroia-.cjs +0 -1
  126. package/index-BGaLvshf.js +0 -232
  127. package/index-BKoD9apd.cjs +0 -11
  128. package/index-D_732b92.js +0 -4
  129. package/parse-templates-DUUSaubj.js +0 -96
  130. package/parse-templates-DVK3iZIl.cjs +0 -8
  131. package/pascal-case-BQpR5PdN.js +0 -6
  132. package/pascal-case-iWoaJWwT.cjs +0 -1
  133. package/react-styled-file-Dkubsz-U.cjs +0 -8
  134. package/react-vanilla-file-CG_WJLam.cjs +0 -15
  135. package/salty.config-BhBY_oOk.js +0 -10
  136. package/salty.config-Dk6ZcCxI.cjs +0 -7
@@ -20,16 +20,24 @@
20
20
  "properties": {
21
21
  "dir": {
22
22
  "type": "string",
23
- "description": "The directory of the project. This is also used as the project name."
23
+ "description": "The root directory of the project. This is also used as the project name."
24
24
  },
25
25
  "framework": {
26
26
  "type": "string",
27
27
  "description": "The framework used by the project.",
28
- "enum": ["react", "other"]
28
+ "enum": ["react", "astro", "other"]
29
29
  },
30
30
  "components": {
31
31
  "type": "string",
32
- "description": "The directory for the components."
32
+ "description": "The directory for the components, relative to the project root."
33
+ },
34
+ "configDir": {
35
+ "type": "string",
36
+ "description": "Dir3ectorywhere the project configuration file is located, relative to the project root."
37
+ },
38
+ "saltygenDir": {
39
+ "type": "string",
40
+ "description": "Directory where the salty css files will be generated to, relative to the project root."
33
41
  }
34
42
  },
35
43
  "required": ["dir", "framework"]
package/README.md CHANGED
@@ -1,53 +1,405 @@
1
- # Salty CSS - Kinda sweet but yet spicy CSS-in-JS library
1
+ ![Salty CSS Banner](https://salty-css.dev/assets/banners/dvd.svg)
2
2
 
3
- In the world of frontend dev is there anything saltier than CSS? Salty CSS is built to provide better developer experience for developers looking for performant and feature rich CSS-in-JS solutions.
3
+ # Salty CSS - CSS-in-JS library that is kinda sweet
4
+
5
+ Is there anything saltier than CSS in frontend web development? Salty CSS is built to provide better developer experience for developers looking for performant and feature rich CSS-in-JS solutions.
6
+
7
+ [Get started](#get-started) | [API](#api) | [Discord](https://discord.gg/R6kr4KxMhP) | [Website](https://salty-css.dev/) | [GitHub](https://github.com/margarita-form/salty-css) | [NPM](https://www.npmjs.com/package/@salty-css/core)
4
8
 
5
9
  ## Features
6
10
 
7
11
  - Build time compilation to achieve awesome runtime performance and minimal size
8
- - Next.js, React Server Components, Vite and Webpack support
12
+ - Next.js, React Server Components, Astro, Vite and Webpack support
9
13
  - Type safety with out of the box TypeScript and ESLint plugin
10
14
  - Advanced CSS variables configuration to allow smooth token usage
11
15
  - Style templates to create reusable styles easily
12
16
 
13
17
  ## Get started
14
18
 
15
- - Initialize: `npx salty-css init [directory]`
19
+ Fastest way to get started with any framework is
20
+
21
+ ```bash
22
+ npx salty-css init
23
+ ```
24
+
25
+ Other guides:
26
+
27
+ - Next.js → [Next.js guide](#nextjs) + [Next.js example app](https://github.com/margarita-form/salty-css-website)
28
+ - React + Vite → [React + Vite guide](#react--vite) + [React example code](#code-examples)
29
+ - React + Webpack → Guide coming soon
30
+
31
+ ## Useful commands
32
+
16
33
  - Create component: `npx salty-css generate [filePath]`
17
34
  - Build: `npx salty-css build [directory]`
35
+ - Update Salty CSS packages: `npx salty-css up`
36
+
37
+ ## Good to know
38
+
39
+ 1. All Salty CSS functions (`styled`, `classNames`, `keyframes`, etc.) must be created in `*.css.ts` or `*.css.tsx` files. This is to ensure best build performance.
40
+ 2. Salty CSS components created with styled function can extend non Salty CSS components (`export const CustomLink = styled(NextJSLink, { ... });`) but those components must take in `className` prop for styles to apply.
41
+ 3. Among common types like `string` and `number`, CSS-in-JS properties in Salty CSS do support `functions` and `promises` as values (`styled('span', { base: { color: async () => 'red' } });`) but running asynchronous tasks or importing heavy 3rd party libraries into `*.css.ts` or `*.css.tsx` files can cause longer build times.
42
+
43
+ ## Get support
44
+
45
+ To get help with problems, [Join Salty CSS Discord server](https://discord.gg/R6kr4KxMhP).
46
+
47
+ ## API
48
+
49
+ ### Component styling
50
+
51
+ - [styled](#styled-function) (react only) - create React components that can be used anywhere easily
52
+ - [className](#class-name-function) (framework agnostic) - create a CSS class string that can be applied to any element
53
+
54
+ ### Global styling
55
+
56
+ - [defineGlobalStyles](#global-styles) - set global styles like `html` and `body`
57
+ - [defineVariables](#variables) - create CSS variables (tokens) that can be used in any styling function
58
+ - [defineMediaQuery](#media-queries) - create CSS media queries and use them in any styling function
59
+ - [defineTemplates](#templates) - create reusable templates that can be applied when same styles are used over and over again
60
+ - [keyframes](#keyframes-animations) - create CSS keyframes animation that can be used and imported in any styling function
61
+
62
+ ### Styling helpers & utility
63
+
64
+ - [defineViewportClamp](#viewport-clamp) - create CSS clamp functions that are based on user's viewport and can calculate relative values easily
65
+ - [color](#color-function) - transform any valid color code or variable to be darker, lighter etc. easily (uses [color library by Qix-](https://github.com/Qix-/color))
66
+
67
+ ### Salty CSS CLI
68
+
69
+ In your existing repository you can use `npx salty-css [command]` to initialize a project, generate components, update related packages and build required files.
70
+
71
+ - Initialize project → `npx salty-css init [directory]` - Installs required packages, detects framework in use and creates project files to the provided directory. Directory can be left blank if you want files to be created to the current directory.
72
+ - Generate component → `npx salty-css update [version]` - Update @salty-css packages in your repository. Default version is "latest". Additional options like `--dir`, `--tag`, `--name` and `--className` are also supported.
73
+ - Build files → `npx salty-css build [directory/filename]` - Compile Salty CSS related files in your project. This should not be needed if you are using tools like Next.js or Vite
74
+
75
+ ## Styled function
76
+
77
+ Styled function is the main way to use Salty CSS within React. Styled function creates a React component that then can be used anywhere in your app. All styled functions must be created in `.css.ts` or `.css.tsx` files
78
+
79
+ ```ts
80
+ // /components/my-component.css.ts
81
+ import { styled } from '@salty-css/react/styled';
82
+
83
+ // Define a component with a styled function. First argument is the component name or existing component to extend and second argument is the object containing the styles and other options
84
+ export const Component = styled('div', {
85
+ className: 'wrapper', // Define optional custom class name that will be included for this component
86
+ element: 'section', // Override the html element that will be rendered for this component
87
+ base: {
88
+ // 👉 Add your CSS-in-JS base styles here! 👈
89
+ },
90
+ variants: {
91
+ // Define conditional styles that will be applied to the component based on the variant prop values
92
+ },
93
+ compoundVariants: [
94
+ // Define conditional styles that will be applied to the component based on the combination of variant prop values
95
+ ],
96
+ defaultVariants: {
97
+ // Set default variant prop values
98
+ },
99
+ defaultProps: {
100
+ // Add additional default props for the component (eg, id and other html element attributes)
101
+ },
102
+ passProps: true, // Pass variant props to the rendered element / parent component (default: false)
103
+ priority: 1, // Override automatic priotity layer with a custom value (0-8), higher is considered more important
104
+ });
105
+ ```
106
+
107
+ Example usage:
108
+
109
+ ```tsx
110
+ import { Component } from './my-component.css';
111
+
112
+ export const Page = () => {
113
+ return <Component>Hello world</Component>;
114
+ };
115
+ ```
116
+
117
+ ## Class name function
118
+
119
+ Create CSS class names with possibility to add scope and media queries etc. Function `className` is quite similar to `styled` but does not allow extending components or classes.
120
+
121
+ ```ts
122
+ // /components/my-class.css.ts
123
+ import { className } from '@salty-css/react/class-name';
124
+
125
+ // Define a CSS class with className function. First and only argument is the object containing the styles and other options
126
+ export const myClass = className({
127
+ className: 'wrapper', // Define optional custom class name that will be included to the scope
128
+ base: {
129
+ // 👉 Add your CSS-in-JS base styles here! 👈
130
+ },
131
+ });
132
+ ```
133
+
134
+ Example usage:
135
+
136
+ ```tsx
137
+ import { myClass } from './my-class.css';
138
+
139
+ export const Page = () => {
140
+ return <div className={myClass}>Hello world</div>;
141
+ };
142
+ ```
143
+
144
+ ## Global styles
145
+
146
+ ```ts
147
+ // /styles/global.css.ts
148
+ import { defineGlobalStyles } from '@salty-css/core/factories';
149
+
150
+ export default defineGlobalStyles({
151
+ html: {
152
+ fontFamily: 'Arial, sans-serif',
153
+ },
154
+ body: {
155
+ backgroundColor: '#fff',
156
+ margin: 0,
157
+ },
158
+ // Add more global styles as needed
159
+ });
160
+ ```
161
+
162
+ ## Variables
163
+
164
+ ```ts
165
+ // /styles/variables.css.ts
166
+ import { defineVariables } from '@salty-css/core/factories';
167
+
168
+ export default defineVariables({
169
+ /*
170
+ Define static variable token (like colors, font sizes, etc.). and use them in your styles (e.g. color: '{colors.brand.highlight}').
171
+ Variables can be nested (colors.brand.main) and can reference other variables.
172
+ */
173
+ colors: {
174
+ dark: '#111',
175
+ light: '#fefefe',
176
+ brand: {
177
+ main: '#0070f3',
178
+ highlight: '#ff4081',
179
+ },
180
+ },
181
+ fontFamily: {
182
+ heading: 'Arial, sans-serif',
183
+ body: 'Georgia, serif',
184
+ },
185
+
186
+ /*
187
+ Define variables that are responsive to a media query (defined in media.css.ts) asn use them in your styles as normal (e.g. font-size: '{fontSize.heading.regular}').
188
+ These variables will be automatically updated when the media query is matched. Base values are used when no media query is matched.
189
+ */
190
+ responsive: {
191
+ base: {
192
+ fontSize: {
193
+ heading: {
194
+ small: '32px',
195
+ regular: '48px',
196
+ large: '64px',
197
+ },
198
+ body: {
199
+ small: '16px',
200
+ regular: '20px',
201
+ large: '24px',
202
+ },
203
+ },
204
+ },
205
+ '@largeMobileDown': {
206
+ fontSize: {
207
+ heading: {
208
+ small: '20px',
209
+ regular: '32px',
210
+ large: '48px',
211
+ },
212
+ body: {
213
+ small: '14px',
214
+ regular: '16px',
215
+ large: '20px',
216
+ },
217
+ },
218
+ },
219
+ },
220
+
221
+ /*
222
+ Conditional variables are used to define styles that depend on a class name (e.g. <div className="theme-dark">). or data-attribute (e.g. <div data-theme="dark">). Names for these variables will be "{theme.backgroundColor}" and "{theme.textColor}".
223
+ */
224
+ conditional: {
225
+ theme: {
226
+ dark: {
227
+ backgroundColor: '{colors.dark}',
228
+ textColor: '{colors.light}',
229
+ },
230
+ light: {
231
+ backgroundColor: '{colors.light}',
232
+ textColor: '{colors.dark}',
233
+ },
234
+ },
235
+ },
236
+ });
237
+ ```
238
+
239
+ Example usage:
240
+
241
+ ```ts
242
+ styled('span', {
243
+ base: {
244
+ // Use of static font family variable
245
+ fontFamily: '{fontFamily.heading}',
246
+ // Use of responsive font size variable
247
+ fontSize: '{fontSize.heading.regular}',
248
+ // Use of conditional theme text color variable
249
+ color: '{theme.textColor}',
250
+ },
251
+ });
252
+ ```
18
253
 
19
- ### Packages
254
+ ## Media queries
20
255
 
21
- Note: Fastest way to get started with any framework is [npx salty-css init [directory]](#initialize-salty-css-for-a-project) command
256
+ Create global media queries that can be either used directly as a scope (e.g. `'@MEDIA_QUERY_NAME': { color: 'blue' }`) or imported to be used in JS.
22
257
 
23
- - [Next.js](#nextjs) → `npm install @salty-css/next` + [Next.js install guide](#nextjs) + [Next.js example app](https://github.com/margarita-form/salty-css-website)
24
- - [React](#react) → `npm install @salty-css/react` + [React install guide](#react) + [React example code](#code-examples)
25
- - [Vite](#vite) `npm install @salty-css/vite` + [(Vite install guide)](#vite)
26
- - [Webpack](https://www.npmjs.com/package/@salty-css/webpack) → `npm install @salty-css/webpack` + Guide coming soon
27
- - [ESLint](https://www.npmjs.com/package/@salty-css/eslint-plugin-core) → `npm install @salty-css/eslint-plugin-core` + Guide coming soon
28
- - [Core](https://www.npmjs.com/package/@salty-css/react) → `npm install @salty-css/core` (This package contains code for internal use)
258
+ ```ts
259
+ // /styles/media.css.ts
260
+ import { defineMediaQuery } from '@salty-css/react/config';
29
261
 
30
- ### Add Salty CSS to your project with `salty-css` CLI
262
+ export const largePortraitUp = defineMediaQuery((media) => media.minWidth(600));
263
+ export const largeMobileDown = defineMediaQuery((media) => media.maxWidth(600));
264
+ ```
31
265
 
32
- #### Initialize Salty CSS for a project
266
+ Example usage:
33
267
 
34
- In your existing repository run `npx salty-css init [directory]` which installs required salty-css packages to the current directory, detects framework in use (current support for vite and next.js) and creates project files to the provided directory. Directory can be left blank if you want files to be created to the current directory. Init will also create `.saltyrc.json` which contains some metadata for future CLI commands.
268
+ ```ts
269
+ styled('span', { base: { fontSize: '64px', '@largeMobileDown': { fontSize: '32px' } } });
270
+ ```
35
271
 
36
- #### Create components
272
+ ## Templates
37
273
 
38
- Components can be created with `npx salty-css generate [filePath]` which then creates a new Salty CSS component file to the specified path. Additional options like `--dir, --tag, --name and --className` are also supported. Read more about them with `npx salty-css generate --help`
274
+ With templates you can create reusable styles that can be used in any styles function. Templates can be static (all values defined in the template) or functions (parameters can be passed to define values). Templates can be used in styles by using template's name (e.g. textStyle) as property name and for static a key as the value for functions any supported parameter value can be used as the value.
39
275
 
40
- #### Build / Compile Salty CSS
276
+ ```ts
277
+ // /styles/templates.css.ts
278
+ import { defineTemplates } from '@salty-css/core/factories';
41
279
 
42
- If you want to manually build your project that can be done by running `npx salty-css build [directory]`. Directory is not required as CLI can use default directory defined in `.saltyrc.json`. Note that build generates css files but Vite / Webpack plugin is still required for full support.
280
+ export default defineTemplates({
281
+ // Static templates for text styles.
282
+ textStyle: {
283
+ headline: {
284
+ small: {
285
+ fontSize: '{fontSize.heading.small}',
286
+ },
287
+ regular: {
288
+ fontSize: '{fontSize.heading.regular}',
289
+ },
290
+ large: {
291
+ fontSize: '{fontSize.heading.large}',
292
+ },
293
+ },
294
+ body: {
295
+ small: {
296
+ fontSize: '{fontSize.body.small}',
297
+ lineHeight: '1.5em',
298
+ },
299
+ regular: {
300
+ fontSize: '{fontSize.body.regular}',
301
+ lineHeight: '1.33em',
302
+ },
303
+ },
304
+ },
305
+ // Dynamic function templates for card styles.
306
+ card: (value: string) => {
307
+ return {
308
+ padding: value,
309
+ borderRadius: '8px',
310
+ boxShadow: '0 0 10px rgba(0, 0, 0, 0.1)',
311
+ };
312
+ },
313
+ });
314
+ ```
43
315
 
44
- #### Update Salty CSS packages
316
+ Example usage:
45
317
 
46
- To ease the pain of package updates all Salty CSS packages can be updated with `npx salty-css update`
318
+ ```ts
319
+ styled('div', { base: { textStyle: 'headline.large', card: '20px' } });
320
+ ```
47
321
 
48
- ### Manual work
322
+ ## Keyframes animations
323
+
324
+ ```ts
325
+ // /styles/animations.css.ts
326
+ import { keyframes } from '@salty-css/react/keyframes';
327
+
328
+ export const fadeIn = keyframes({
329
+ // Name of the animation in final CSS
330
+ animationName: 'fadeIn',
331
+ // Add `from` or `0%` to the component's css making it the initial state.
332
+ appendInitialStyles: true,
333
+ // CSS animation default params used with the value
334
+ params: {
335
+ delay: '250ms',
336
+ fillMode: 'forwards',
337
+ },
338
+ // Rest is animation timeline
339
+ from: {
340
+ opacity: 0,
341
+ },
342
+ to: {
343
+ opacity: 1,
344
+ },
345
+ });
346
+ ```
347
+
348
+ Example usage:
349
+
350
+ ```ts
351
+ import { fadeIn } from 'path-to-animations.css.ts';
352
+
353
+ export const Wrapper = styled('div', { base: { animation: fadeIn } });
354
+ ```
49
355
 
50
- #### Next.js
356
+ ## Viewport clamp
357
+
358
+ Create a CSS clamp function based on screen sizes. Useful when aiming to create font sizes or spacings that scale with the screen.
359
+
360
+ ```ts
361
+ // /styles/clamp.css.ts
362
+ import { defineViewportClamp } from '@salty-css/react/helpers';
363
+
364
+ export const fhdClamp = defineViewportClamp({ screenSize: 1920 });
365
+ export const mobileClamp = defineViewportClamp({ screenSize: 640 });
366
+ ```
367
+
368
+ Example usage:
369
+
370
+ ```ts
371
+ styled('span', { base: { fontSize: fhdClamp(96), '@largeMobileDown': { fontSize: mobileClamp(48) } } });
372
+ ```
373
+
374
+ ## Color function
375
+
376
+ Modify any color easily, add opacity, darken...
377
+
378
+ Example usage:
379
+
380
+ ```ts
381
+ import { color } from '@salty-css/core/helpers';
382
+
383
+ export const Wrapper = styled('span', { base: { backgroundColor: color('#000').alpha(0.5) } });
384
+ ```
385
+
386
+ ## Usage
387
+
388
+ ### Next.js
389
+
390
+ ![salty-next](https://github.com/user-attachments/assets/2cf6a93f-cdd5-4f5f-ab2e-3bc8bcfb83e8)
391
+
392
+ Salty CSS provides Next.js App & Pages router support with full React Server Components support.
393
+
394
+ ### Add Salty CSS to Next.js
395
+
396
+ 1. In your existing Next.js repository you can run `npx salty-css init` to automatically configure Salty CSS.
397
+ 2. Create your first Salty CSS component with `npx salty-css generate [filePath]` (e.g. src/custom-wrapper)
398
+ 3. Import your component for example to `page.tsx` and see it working!
399
+
400
+ And note: steps 2 & 3 are just to show how get new components up and running, step 1 does all of the important stuff 🤯
401
+
402
+ #### Manual configuration
51
403
 
52
404
  1. For Next.js support install `npm i @salty-css/next @salty-css/core @salty-css/react`
53
405
  2. Create `salty.config.ts` to your app directory
@@ -62,15 +414,27 @@ To ease the pain of package updates all Salty CSS packages can be updated with `
62
414
 
63
415
  [Check out Next.js demo project](https://github.com/margarita-form/salty-css-website) or [react example code](#code-examples)
64
416
 
65
- #### React
417
+ ---
66
418
 
67
- 1. Install related dependencies: `npm i @salty-css/core @salty-css/react`
68
- 2. Create `salty.config.ts` to your app directory
69
- 3. Configure your build tool to support Salty CSS ([Vite](#vite) or Webpack)
419
+ ### React + Vite
70
420
 
71
- [Check out react example code](#code-examples)
421
+ ![salty-vite-react](https://github.com/user-attachments/assets/12ec5b6a-0dcc-48fa-afc1-d337fc8f800c)
422
+
423
+ ### Add Salty CSS to your React + Vite app
424
+
425
+ 1. In your existing Vite repository you can run `npx salty-css init` to automatically configure Salty CSS.
426
+ 2. Create your first Salty CSS component with `npx salty-css generate [filePath]` (e.g. src/custom-wrapper)
427
+ 3. Import your component for example to `main.tsx` and see it working!
428
+
429
+ And note: steps 2 & 3 are just to show how get new components up and running, step 1 does all of the important stuff 🤯
430
+
431
+ ### Test it out
432
+
433
+ Check out React + Vite + Salty CSS demo repository at https://github.com/margarita-form/salty-css-react-vite-demo or view it in CodeSandbox:
72
434
 
73
- #### Vite
435
+ [![Edit margarita-form/salty-css-react-vite-demo/main](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/p/github/margarita-form/salty-css-react-vite-demo/main?import=true&embed=1)
436
+
437
+ ### Manual configuration
74
438
 
75
439
  1. For Vite support install `npm i @salty-css/vite @salty-css/core`
76
440
  2. In `vite.config` add import for salty plugin `import { saltyPlugin } from '@salty-css/vite';` and then add `saltyPlugin(__dirname)` to your vite configuration plugins
@@ -78,6 +442,10 @@ To ease the pain of package updates all Salty CSS packages can be updated with `
78
442
  4. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
79
443
  5. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
80
444
 
445
+ [Check out react example code](#code-examples)
446
+
447
+ ---
448
+
81
449
  ### Create components
82
450
 
83
451
  1. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
@@ -106,23 +474,6 @@ export const config = defineConfig({
106
474
  });
107
475
  ```
108
476
 
109
- **Your React component file**
110
-
111
- ```tsx
112
- import { Wrapper } from '../components/wrapper/wrapper.css';
113
- import { Button } from '../components/button/button.css';
114
-
115
- export const IndexPage = () => {
116
- return (
117
- <Wrapper>
118
- <Button variant="solid" onClick={() => alert('It is a button.')}>
119
- Outlined
120
- </Button>
121
- </Wrapper>
122
- );
123
- };
124
- ```
125
-
126
477
  **Wrapper** (`components/wrapper/wrapper.css.ts`)
127
478
 
128
479
  ```tsx
@@ -147,7 +498,7 @@ export const Button = styled('button', {
147
498
  padding: `0.6em 1.2em`,
148
499
  border: '1px solid currentColor',
149
500
  background: 'transparent',
150
- color: 'currentColor/40',
501
+ color: 'currentColor',
151
502
  cursor: 'pointer',
152
503
  transition: '200ms',
153
504
  textDecoration: 'none',
@@ -183,4 +534,21 @@ export const Button = styled('button', {
183
534
  });
184
535
  ```
185
536
 
537
+ **Your React component file**
538
+
539
+ ```tsx
540
+ import { Wrapper } from '../components/wrapper/wrapper.css';
541
+ import { Button } from '../components/button/button.css';
542
+
543
+ export const IndexPage = () => {
544
+ return (
545
+ <Wrapper>
546
+ <Button variant="solid" onClick={() => alert('It is a button.')}>
547
+ Outlined
548
+ </Button>
549
+ </Wrapper>
550
+ );
551
+ };
552
+ ```
553
+
186
554
  More examples coming soon
package/bin/index.cjs CHANGED
@@ -1,2 +1,4 @@
1
1
  #!/usr/bin/env node
2
- "use strict";const e=require("./main.cjs");e.main().catch(n=>console.error(n));
2
+ "use strict";
3
+ const bin_main = require("./main.cjs");
4
+ bin_main.main().catch((e) => console.error(e));
package/bin/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import { main as r } from "./main.js";
3
- r().catch((o) => console.error(o));
2
+ import { main } from "./main.js";
3
+ main().catch((e) => console.error(e));