@salty-css/eslint-plugin-core 0.0.1-alpha.220 → 0.0.1-alpha.221

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 (2) hide show
  1. package/README.md +276 -4
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -7,7 +7,7 @@ Is there anything saltier than CSS in frontend web development? Salty CSS is bui
7
7
  ## Features
8
8
 
9
9
  - Build time compilation to achieve awesome runtime performance and minimal size
10
- - Next.js, React Server Components, Vite and Webpack support
10
+ - Next.js, React Server Components, Astro, Vite and Webpack support
11
11
  - Type safety with out of the box TypeScript and ESLint plugin
12
12
  - Advanced CSS variables configuration to allow smooth token usage
13
13
  - Style templates to create reusable styles easily
@@ -26,13 +26,41 @@ Fastest way to get started with any framework is `npx salty-css init [directory]
26
26
  - Build: `npx salty-css build [directory]`
27
27
  - Update Salty CSS packages: `npx salty-css up`
28
28
 
29
- ## Salty CSS styled function
29
+ ## Good to know
30
+
31
+ 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.
32
+ 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.
33
+ 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.
34
+
35
+ ## Functions
36
+
37
+ ### Styling
38
+
39
+ - [styled](#styled-function) (react only) - create React components that can be used anywhere easily
40
+ - [className](#class-name-function) (framework agnostic) - create a CSS class string that can be applied to any element
41
+
42
+ ### Global
43
+
44
+ - [defineGlobalStyles](#global-styles) - set global styles like `html` and `body`
45
+ - [defineVariables](#variables) - create CSS variables (tokens) that can be used in any styling function
46
+ - [defineMediaQuery](#media-queries) - create CSS media queries and use them in any styling function
47
+ - [defineTemplates](#templates) - create reusable templates that can be applied when same styles are used over and over again
48
+ - [keyframes](#keyframes-animations) - create CSS keyframes animation that can be used and imported in any styling function
49
+
50
+ ### Helpers & utility
51
+
52
+ - [defineViewportClamp](#viewport-clamp) - create CSS clamp functions that are based on user's viewport and can calculate relative values easily
53
+ - [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))
54
+
55
+ ## Styled function
56
+
57
+ 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
30
58
 
31
59
  ```ts
32
- // components/wrapper.css.ts
60
+ // components/my-component.css.ts
33
61
  import { styled } from '@salty-css/react/styled';
34
62
 
35
- // Define a component with 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
63
+ // 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
36
64
  export const Component = styled('div', {
37
65
  className: 'wrapper', // Define custom class name that will be included for this component
38
66
  element: 'section', // Define the html element that will be rendered for this component, overrides the first 'div' argument
@@ -55,6 +83,250 @@ export const Component = styled('div', {
55
83
  });
56
84
  ```
57
85
 
86
+ ## Class name function
87
+
88
+ 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.
89
+
90
+ ```ts
91
+ // styles/my-class.css.ts
92
+ import { className } from '@salty-css/react/class-name';
93
+
94
+ // Define a CSS class with className function. First and only argument is the object containing the styles and other options
95
+ export const myClass = className({
96
+ className: 'wrapper', // Define custom class name that will be included to the scope
97
+ base: {
98
+ // 👉 Add your CSS-in-JS base styles here! 👈
99
+ },
100
+ });
101
+ ```
102
+
103
+ ## Global styles
104
+
105
+ ```ts
106
+ // /styles/global.css.ts
107
+ import { defineGlobalStyles } from '@salty-css/core/factories';
108
+
109
+ export default defineGlobalStyles({
110
+ html: {
111
+ fontFamily: 'Arial, sans-serif',
112
+ },
113
+ body: {
114
+ backgroundColor: '#fff',
115
+ margin: 0,
116
+ },
117
+ // Add more global styles as needed
118
+ });
119
+ ```
120
+
121
+ ## Variables
122
+
123
+ ```ts
124
+ // /styles/variables.css.ts
125
+ import { defineVariables } from '@salty-css/core/factories';
126
+
127
+ export default defineVariables({
128
+ /*
129
+ Define static variable token (like colors, font sizes, etc.). and use them in your styles (e.g. color: '{colors.brand.highlight}').
130
+ Variables can be nested (colors.brand.main) and can reference other variables.
131
+ */
132
+ colors: {
133
+ dark: '#111',
134
+ light: '#fefefe',
135
+ brand: {
136
+ main: '#0070f3',
137
+ highlight: '#ff4081',
138
+ },
139
+ },
140
+ fontFamily: {
141
+ heading: 'Arial, sans-serif',
142
+ body: 'Georgia, serif',
143
+ },
144
+
145
+ /*
146
+ 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}').
147
+ These variables will be automatically updated when the media query is matched. Base values are used when no media query is matched.
148
+ */
149
+ responsive: {
150
+ base: {
151
+ fontSize: {
152
+ heading: {
153
+ small: '32px',
154
+ regular: '48px',
155
+ large: '64px',
156
+ },
157
+ body: {
158
+ small: '16px',
159
+ regular: '20px',
160
+ large: '24px',
161
+ },
162
+ },
163
+ },
164
+ '@largeMobileDown': {
165
+ fontSize: {
166
+ heading: {
167
+ small: '20px',
168
+ regular: '32px',
169
+ large: '48px',
170
+ },
171
+ body: {
172
+ small: '14px',
173
+ regular: '16px',
174
+ large: '20px',
175
+ },
176
+ },
177
+ },
178
+ },
179
+
180
+ /*
181
+ 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">).
182
+ */
183
+ conditional: {
184
+ theme: {
185
+ dark: {
186
+ backgroundColor: '{colors.dark}',
187
+ textColor: '{colors.light}',
188
+ },
189
+ light: {
190
+ backgroundColor: '{colors.light}',
191
+ textColor: '{colors.dark}',
192
+ },
193
+ },
194
+ },
195
+ });
196
+ ```
197
+
198
+ ## Media queries
199
+
200
+ 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.
201
+
202
+ ```ts
203
+ // /styles/media.css.ts
204
+ import { defineMediaQuery } from '@salty-css/react/config';
205
+
206
+ export const largePortraitUp = defineMediaQuery((media) => media.minWidth(600));
207
+ export const largeMobileDown = defineMediaQuery((media) => media.maxWidth(600));
208
+ ```
209
+
210
+ Example usage:
211
+
212
+ ```ts
213
+ styled('span', { base: { fontSize: '64px', '@largeMobileDown': { fontSize: '32px' } } });
214
+ ```
215
+
216
+ ## Templates
217
+
218
+ 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.
219
+
220
+ ```ts
221
+ // /styles/templates.css.ts
222
+ import { defineTemplates } from '@salty-css/core/factories';
223
+
224
+ export default defineTemplates({
225
+ // Static templates for text styles.
226
+ textStyle: {
227
+ headline: {
228
+ small: {
229
+ fontSize: '{fontSize.heading.small}',
230
+ },
231
+ regular: {
232
+ fontSize: '{fontSize.heading.regular}',
233
+ },
234
+ large: {
235
+ fontSize: '{fontSize.heading.large}',
236
+ },
237
+ },
238
+ body: {
239
+ small: {
240
+ fontSize: '{fontSize.body.small}',
241
+ lineHeight: '1.5em',
242
+ },
243
+ regular: {
244
+ fontSize: '{fontSize.body.regular}',
245
+ lineHeight: '1.33em',
246
+ },
247
+ },
248
+ },
249
+ // Dynamic function templates for card styles.
250
+ card: (value: string) => {
251
+ return {
252
+ padding: value,
253
+ borderRadius: '8px',
254
+ boxShadow: '0 0 10px rgba(0, 0, 0, 0.1)',
255
+ };
256
+ },
257
+ });
258
+ ```
259
+
260
+ Example usage:
261
+
262
+ ```ts
263
+ styled('div', { base: { textStyle: 'headline.large', card: '20px' } });
264
+ ```
265
+
266
+ ## Keyframes animations
267
+
268
+ ```ts
269
+ // /styles/animations.css.ts
270
+ import { keyframes } from '@salty-css/react/keyframes';
271
+
272
+ export const fadeIn = keyframes({
273
+ // Name of the animation in final CSS
274
+ animationName: 'fadeIn',
275
+ // Add `from` or `0%` to the component's css making it the initial state.
276
+ appendInitialStyles: true,
277
+ // CSS animation default params used with the value
278
+ params: {
279
+ delay: '250ms',
280
+ fillMode: 'forwards',
281
+ },
282
+ // Rest is animation timeline
283
+ from: {
284
+ opacity: 0,
285
+ },
286
+ to: {
287
+ opacity: 1,
288
+ },
289
+ });
290
+ ```
291
+
292
+ Example usage:
293
+
294
+ ```ts
295
+ import { fadeIn } from 'path-to-animations.css.ts';
296
+
297
+ export const Wrapper = styled('div', { base: { animation: fadeIn } });
298
+ ```
299
+
300
+ ## Viewport clamp
301
+
302
+ Create a CSS clamp function based on screen sizes. Useful when aiming to create font sizes or spacings that scale with the screen.
303
+
304
+ ```ts
305
+ // /styles/clamp.css.ts
306
+ import { defineViewportClamp } from '@salty-css/react/helpers';
307
+
308
+ export const fhdClamp = defineViewportClamp({ screenSize: 1920 });
309
+ export const mobileClamp = defineViewportClamp({ screenSize: 640 });
310
+ ```
311
+
312
+ Example usage:
313
+
314
+ ```ts
315
+ styled('span', { base: { fontSize: fhdClamp(96), '@largeMobileDown': { fontSize: mobileClamp(48) } } });
316
+ ```
317
+
318
+ ## Color function
319
+
320
+ Modify any color easily, add opacity, darken...
321
+
322
+ Example usage:
323
+
324
+ ```ts
325
+ import { color } from '@salty-css/core/helpers';
326
+
327
+ export const Wrapper = styled('span', { base: { backgroundColor: color('#000').alpha(0.5) } });
328
+ ```
329
+
58
330
  ## Salty CSS CLI
59
331
 
60
332
  In your existing repository you can use `npx salty-css [command]` to initialize a project, generate components, update related packages and build required files.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/eslint-plugin-core",
3
- "version": "0.0.1-alpha.220",
3
+ "version": "0.0.1-alpha.221",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -34,7 +34,7 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@salty-css/core": "^0.0.1-alpha.220",
37
+ "@salty-css/core": "^0.0.1-alpha.221",
38
38
  "eslint": ">=9.x || >=8.x || >=7.x"
39
39
  }
40
40
  }