@salty-css/react 0.0.1-alpha.3 → 0.0.1-alpha.300
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 +490 -43
- package/class-name-client.cjs +1 -0
- package/class-name-client.d.ts +7 -0
- package/class-name-client.js +15 -0
- package/class-name.cjs +1 -0
- package/class-name.d.ts +10 -0
- package/class-name.js +20 -0
- package/clsx-C11secjj.cjs +1 -0
- package/clsx-OuTLNxxd.js +16 -0
- package/config.cjs +1 -0
- package/config.d.ts +1 -0
- package/config.js +1 -0
- package/dynamic-styles.cjs +2 -0
- package/dynamic-styles.d.ts +23 -0
- package/dynamic-styles.js +29 -0
- package/element-factory-BPI0pGIH.cjs +1 -0
- package/element-factory-D5vMsSwp.js +56 -0
- package/element-factory.d.ts +3 -0
- package/helpers.cjs +1 -0
- package/helpers.d.ts +1 -0
- package/helpers.js +1 -0
- package/index.cjs +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/keyframes.cjs +1 -0
- package/keyframes.d.ts +1 -0
- package/keyframes.js +1 -0
- package/media.cjs +1 -0
- package/media.d.ts +1 -0
- package/media.js +1 -0
- package/package.json +38 -3
- package/styled-client.cjs +1 -0
- package/styled-client.d.ts +3 -0
- package/styled-client.js +5 -0
- package/styled.cjs +1 -0
- package/styled.d.ts +5 -0
- package/styled.js +13 -0
- package/dist/README.md +0 -107
- package/dist/element-factory-CHdv47Y_.js +0 -52
- package/dist/element-factory-DvBlAL2I.cjs +0 -1
- package/dist/element-factory.d.ts +0 -2
- package/dist/keyframes.cjs +0 -1
- package/dist/keyframes.d.ts +0 -22
- package/dist/keyframes.js +0 -30
- package/dist/media.cjs +0 -1
- package/dist/media.d.ts +0 -71
- package/dist/media.js +0 -81
- package/dist/package.json +0 -42
- package/dist/parse-styles-BRv2UFN0.js +0 -87
- package/dist/parse-styles-PkK9Yzyn.cjs +0 -7
- package/dist/styled-client.cjs +0 -1
- package/dist/styled-client.d.ts +0 -2
- package/dist/styled-client.js +0 -7
- package/dist/styled.cjs +0 -1
- package/dist/styled.d.ts +0 -3
- package/dist/styled.js +0 -60
package/README.md
CHANGED
@@ -1,15 +1,458 @@
|
|
1
|
-
|
1
|
+

|
2
2
|
|
3
|
-
|
3
|
+
# Salty CSS - CSS-in-JS library that is kinda sweet
|
4
4
|
|
5
|
-
|
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
6
|
|
7
|
-
|
8
|
-
2. Create `salty-config.ts` to the root of your project
|
9
|
-
3. Import global styles to any regular .css file from `saltygen/index.css` (does not exist during first run, cli command coming later)
|
10
|
-
4. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
|
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)
|
11
8
|
|
12
|
-
|
9
|
+
## Features
|
10
|
+
|
11
|
+
- Build time compilation to achieve awesome runtime performance and minimal size
|
12
|
+
- Next.js, React Server Components, Astro, Vite and Webpack support
|
13
|
+
- Type safety with out of the box TypeScript and ESLint plugin
|
14
|
+
- Advanced CSS variables configuration to allow smooth token usage
|
15
|
+
- Style templates to create reusable styles easily
|
16
|
+
|
17
|
+
## Get started
|
18
|
+
|
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
|
+
|
33
|
+
- Create component: `npx salty-css generate [filePath]`
|
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
|
+
```
|
253
|
+
|
254
|
+
## Media queries
|
255
|
+
|
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.
|
257
|
+
|
258
|
+
```ts
|
259
|
+
// /styles/media.css.ts
|
260
|
+
import { defineMediaQuery } from '@salty-css/react/config';
|
261
|
+
|
262
|
+
export const largePortraitUp = defineMediaQuery((media) => media.minWidth(600));
|
263
|
+
export const largeMobileDown = defineMediaQuery((media) => media.maxWidth(600));
|
264
|
+
```
|
265
|
+
|
266
|
+
Example usage:
|
267
|
+
|
268
|
+
```ts
|
269
|
+
styled('span', { base: { fontSize: '64px', '@largeMobileDown': { fontSize: '32px' } } });
|
270
|
+
```
|
271
|
+
|
272
|
+
## Templates
|
273
|
+
|
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.
|
275
|
+
|
276
|
+
```ts
|
277
|
+
// /styles/templates.css.ts
|
278
|
+
import { defineTemplates } from '@salty-css/core/factories';
|
279
|
+
|
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
|
+
```
|
315
|
+
|
316
|
+
Example usage:
|
317
|
+
|
318
|
+
```ts
|
319
|
+
styled('div', { base: { textStyle: 'headline.large', card: '20px' } });
|
320
|
+
```
|
321
|
+
|
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
|
+
```
|
355
|
+
|
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
|
+

|
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
|
403
|
+
|
404
|
+
1. For Next.js support install `npm i @salty-css/next @salty-css/core @salty-css/react`
|
405
|
+
2. Create `salty.config.ts` to your app directory
|
406
|
+
3. Add Salty CSS plugin to next.js config
|
407
|
+
|
408
|
+
- **Next.js 15:** In `next.config.ts` add import for salty plugin `import { withSaltyCss } from '@salty-css/next';` and then add `withSaltyCss` to wrap your nextConfig export like so `export default withSaltyCss(nextConfig);`
|
409
|
+
- **Next.js 14 and older:** In `next.config.js` add import for salty plugin `const { withSaltyCss } = require('@salty-css/next');` and then add `withSaltyCss` to wrap your nextConfig export like so `module.exports = withSaltyCss(nextConfig);`
|
410
|
+
|
411
|
+
4. Make sure that `salty.config.ts` and `next.config.ts` are in the same folder!
|
412
|
+
5. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
|
413
|
+
6. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
|
414
|
+
|
415
|
+
[Check out Next.js demo project](https://github.com/margarita-form/salty-css-website) or [react example code](#code-examples)
|
416
|
+
|
417
|
+
---
|
418
|
+
|
419
|
+
### React + Vite
|
420
|
+
|
421
|
+

|
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:
|
434
|
+
|
435
|
+
[](https://codesandbox.io/p/github/margarita-form/salty-css-react-vite-demo/main?import=true&embed=1)
|
436
|
+
|
437
|
+
### Manual configuration
|
438
|
+
|
439
|
+
1. For Vite support install `npm i @salty-css/vite @salty-css/core`
|
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
|
441
|
+
3. Make sure that `salty.config.ts` and `vite.config.ts` are in the same folder!
|
442
|
+
4. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
|
443
|
+
5. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
|
444
|
+
|
445
|
+
[Check out react example code](#code-examples)
|
446
|
+
|
447
|
+
---
|
448
|
+
|
449
|
+
### Create components
|
450
|
+
|
451
|
+
1. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
|
452
|
+
|
453
|
+
## Code examples
|
454
|
+
|
455
|
+
### Basic usage example with Button
|
13
456
|
|
14
457
|
**Salty config**
|
15
458
|
|
@@ -31,31 +474,16 @@ export const config = defineConfig({
|
|
31
474
|
});
|
32
475
|
```
|
33
476
|
|
34
|
-
**Your React component file**
|
35
|
-
|
36
|
-
```tsx
|
37
|
-
import { Wrapper } from '../components/wrapper/wrapper.css';
|
38
|
-
import { Button } from '../components/button/button.css';
|
39
|
-
|
40
|
-
export const IndexPage = () => {
|
41
|
-
return (
|
42
|
-
<Wrapper>
|
43
|
-
<Button variant="solid" onClick={() => alert('It is a button.')}>
|
44
|
-
Outlined
|
45
|
-
</Button>
|
46
|
-
</Wrapper>
|
47
|
-
);
|
48
|
-
};
|
49
|
-
```
|
50
|
-
|
51
477
|
**Wrapper** (`components/wrapper/wrapper.css.ts`)
|
52
478
|
|
53
479
|
```tsx
|
54
480
|
import { styled } from '@salty-css/react/styled';
|
55
481
|
|
56
482
|
export const Wrapper = styled('div', {
|
57
|
-
|
58
|
-
|
483
|
+
base: {
|
484
|
+
display: 'block',
|
485
|
+
padding: '2vw',
|
486
|
+
},
|
59
487
|
});
|
60
488
|
```
|
61
489
|
|
@@ -65,22 +493,24 @@ export const Wrapper = styled('div', {
|
|
65
493
|
import { styled } from '@salty-css/react/styled';
|
66
494
|
|
67
495
|
export const Button = styled('button', {
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
496
|
+
base: {
|
497
|
+
display: 'block',
|
498
|
+
padding: `0.6em 1.2em`,
|
499
|
+
border: '1px solid currentColor',
|
500
|
+
background: 'transparent',
|
501
|
+
color: 'currentColor',
|
502
|
+
cursor: 'pointer',
|
503
|
+
transition: '200ms',
|
504
|
+
textDecoration: 'none',
|
505
|
+
'&:hover': {
|
506
|
+
background: 'black',
|
507
|
+
borderColor: 'black',
|
508
|
+
color: 'white',
|
509
|
+
},
|
510
|
+
'&:disabled': {
|
511
|
+
opacity: 0.25,
|
512
|
+
pointerEvents: 'none',
|
513
|
+
},
|
84
514
|
},
|
85
515
|
variants: {
|
86
516
|
variant: {
|
@@ -104,4 +534,21 @@ export const Button = styled('button', {
|
|
104
534
|
});
|
105
535
|
```
|
106
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
|
+
|
107
554
|
More examples coming soon
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=t=>{const s=new String(t);return Object.assign(s,{get isClassName(){return!0},variant:(n,r)=>{const a=`${n}-${r}`,c=`${t} ${a}`;return e(c)}}),s};exports.className=e;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
interface ClassNameMethods {
|
2
|
+
isClassName: boolean;
|
3
|
+
variant: (name: string, value: string) => string & ClassNameFunction;
|
4
|
+
}
|
5
|
+
type ClassNameFunction = string & ClassNameMethods;
|
6
|
+
export declare const className: (classNameStr: string) => ClassNameFunction;
|
7
|
+
export {};
|
package/class-name.cjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@salty-css/core/generators"),u=r=>{const s=new i.ClassNameGenerator(r),t=a=>{const e=new String(a);return Object.assign(e,{get isClassName(){return!0},variant:(n,c)=>{const o=`${n}-${c}`,l=`${e} ${o}`;return t(l)},generator:s}),e};return t(s.cssClassName)};exports.className=u;
|
package/class-name.d.ts
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
import { StyledParams } from '@salty-css/core/types';
|
2
|
+
import { ClassNameGenerator } from '@salty-css/core/generators';
|
3
|
+
interface ClassNameMethods<STYLE_PARAMS extends StyledParams> {
|
4
|
+
generator: ClassNameGenerator<STYLE_PARAMS>;
|
5
|
+
isClassName: boolean;
|
6
|
+
variant: (name: string, value: string) => string & ClassNameFunction<STYLE_PARAMS>;
|
7
|
+
}
|
8
|
+
type ClassNameFunction<STYLE_PARAMS extends StyledParams> = string & ClassNameMethods<STYLE_PARAMS>;
|
9
|
+
export declare const className: <const STYLE_PARAMS extends StyledParams>(params: STYLE_PARAMS) => ClassNameFunction<STYLE_PARAMS>;
|
10
|
+
export {};
|
package/class-name.js
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
import { ClassNameGenerator as l } from "@salty-css/core/generators";
|
2
|
+
const C = (r) => {
|
3
|
+
const t = new l(r), e = (a) => {
|
4
|
+
const s = new String(a);
|
5
|
+
return Object.assign(s, {
|
6
|
+
get isClassName() {
|
7
|
+
return !0;
|
8
|
+
},
|
9
|
+
variant: (n, o) => {
|
10
|
+
const c = `${n}-${o}`, i = `${s} ${c}`;
|
11
|
+
return e(i);
|
12
|
+
},
|
13
|
+
generator: t
|
14
|
+
}), s;
|
15
|
+
};
|
16
|
+
return e(t.cssClassName);
|
17
|
+
};
|
18
|
+
export {
|
19
|
+
C as className
|
20
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";function i(r){var f,n,t="";if(typeof r=="string"||typeof r=="number")t+=r;else if(typeof r=="object")if(Array.isArray(r)){var s=r.length;for(f=0;f<s;f++)r[f]&&(n=i(r[f]))&&(t&&(t+=" "),t+=n)}else for(n in r)r[n]&&(t&&(t+=" "),t+=n);return t}function o(){for(var r,f,n=0,t="",s=arguments.length;n<s;n++)(r=arguments[n])&&(f=i(r))&&(t&&(t+=" "),t+=f);return t}exports.clsx=o;
|
package/clsx-OuTLNxxd.js
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
function a(r) {
|
2
|
+
var f, n, t = "";
|
3
|
+
if (typeof r == "string" || typeof r == "number") t += r;
|
4
|
+
else if (typeof r == "object") if (Array.isArray(r)) {
|
5
|
+
var o = r.length;
|
6
|
+
for (f = 0; f < o; f++) r[f] && (n = a(r[f])) && (t && (t += " "), t += n);
|
7
|
+
} else for (n in r) r[n] && (t && (t += " "), t += n);
|
8
|
+
return t;
|
9
|
+
}
|
10
|
+
function i() {
|
11
|
+
for (var r, f, n = 0, t = "", o = arguments.length; n < o; n++) (r = arguments[n]) && (f = a(r)) && (t && (t += " "), t += f);
|
12
|
+
return t;
|
13
|
+
}
|
14
|
+
export {
|
15
|
+
i as c
|
16
|
+
};
|
package/config.cjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@salty-css/core/config");Object.keys(t).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
|
package/config.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from '@salty-css/core/config';
|
package/config.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from "@salty-css/core/config";
|
@@ -0,0 +1,2 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),g=require("@salty-css/core/parsers"),C=require("@salty-css/core/cache/resolve-dynamic-config-cache"),S=require("@salty-css/core/util"),f=require("./clsx-C11secjj.cjs"),j=require("react"),l=e=>S.toHash(e),r=async(e,t)=>{const s=await C.resolveDynamicConfigCache();return(await g.parseStyles(e,t,s)).join(`
|
2
|
+
`)},x=async({as:e,scope:t,styles:s,...c})=>{if(e){const a=o=>typeof e=="string"?j.createElement(e,o):e(o);if(!s)return n.jsx(a,{...c});const i=l(s),u=await r(s,t||`.${i}`),y={...c,className:f.clsx(i,c.className)};return n.jsxs(n.Fragment,{children:[n.jsx("style",{children:u}),n.jsx(a,{...y})]})}if(!s)return null;const m=await r(s,t);return n.jsx("style",{children:m})};exports.DynamicStyles=x;exports.getDynamicStylesClassName=l;exports.getDynamicStylesCss=r;
|