bernova 0.0.2

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 (125) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +1778 -0
  3. package/dist/bin/bernova.js +2 -0
  4. package/dist/bin/buildstyle.js +2 -0
  5. package/dist/bin/createConfigFile.js +2 -0
  6. package/dist/bin/declareCssType.js +1 -0
  7. package/dist/index.js +1 -0
  8. package/dist/src/app.js +1 -0
  9. package/dist/src/constants/compilerType.js +1 -0
  10. package/dist/src/constants/cssAdvancedSelectors.js +1 -0
  11. package/dist/src/constants/cssProps.js +1 -0
  12. package/dist/src/constants/cssPseudoClasses.js +1 -0
  13. package/dist/src/constants/cssPseudoElements.js +1 -0
  14. package/dist/src/constants/index.js +1 -0
  15. package/dist/src/constants/resetCss.js +1 -0
  16. package/dist/src/index.d.ts +31 -0
  17. package/dist/src/index.js +1 -0
  18. package/dist/src/lib/compileConfig.js +1 -0
  19. package/dist/src/lib/compileThemes.js +1 -0
  20. package/dist/src/lib/copyLocalFonts/copyLocalFonts.utils.js +1 -0
  21. package/dist/src/lib/copyLocalFonts/generateCssFonts.utils.js +1 -0
  22. package/dist/src/lib/extractDocFragment/extractDocFragment.utils.js +1 -0
  23. package/dist/src/lib/fileExists/fileExists.utils.js +1 -0
  24. package/dist/src/lib/generateBaseCss/generateBaseCss.utils.js +1 -0
  25. package/dist/src/lib/generateCss/generateCSS.utils.js +1 -0
  26. package/dist/src/lib/generateCss/helpers/advanceselector/advancedSelectorHandler.utils.js +1 -0
  27. package/dist/src/lib/generateCss/helpers/attribute/attributeHandler.utils.js +1 -0
  28. package/dist/src/lib/generateCss/helpers/classnames/formatClassName.utils.js +1 -0
  29. package/dist/src/lib/generateCss/helpers/classnames/handlerRegister.utils.js +1 -0
  30. package/dist/src/lib/generateCss/helpers/cssVars/generateVars.utils.js +1 -0
  31. package/dist/src/lib/generateCss/helpers/dynamicValues/dynamicValues.utils.js +1 -0
  32. package/dist/src/lib/generateCss/helpers/dynamicValues/processDynamic.utils.js +1 -0
  33. package/dist/src/lib/generateCss/helpers/filterGenerateCss.utils.js +1 -0
  34. package/dist/src/lib/generateCss/helpers/foreign/foreignHandler.utils.js +1 -0
  35. package/dist/src/lib/generateCss/helpers/generateCssStyles.utils.js +1 -0
  36. package/dist/src/lib/generateCss/helpers/index.js +1 -0
  37. package/dist/src/lib/generateCss/helpers/mediaqueries/generateMediaQueries.utils.js +1 -0
  38. package/dist/src/lib/generateCss/helpers/mediaqueries/mediaQueriesHandler.utils.js +1 -0
  39. package/dist/src/lib/generateCss/helpers/other/declareCssType.utils.js +1 -0
  40. package/dist/src/lib/generateCss/helpers/other/generateGlobalStyles.utils.js +1 -0
  41. package/dist/src/lib/generateCss/helpers/pseudo/pseudoHandler.utils.js +1 -0
  42. package/dist/src/lib/generateCss/helpers/rulename/formatRuleName.utils.js +1 -0
  43. package/dist/src/lib/generateCss/helpers/utils/extractValues.utils.js +1 -0
  44. package/dist/src/lib/generateCss/helpers/utils/formattedStatKey.utils.js +1 -0
  45. package/dist/src/lib/generateCss/helpers/utils/index.js +1 -0
  46. package/dist/src/lib/generateCss/helpers/utils/processCss.utils.js +1 -0
  47. package/dist/src/lib/generateCss/helpers/utils/separateStyles.utils.js +1 -0
  48. package/dist/src/lib/generateCss/helpers/utils/validatePreviouslyExists.utils.js +1 -0
  49. package/dist/src/lib/generateCssDoc/generateCssDoc.util.js +1 -0
  50. package/dist/src/lib/generateProvider/generateProvider.utils.js +1 -0
  51. package/dist/src/lib/generateProvider/template/providerTemplate.d.ts +60 -0
  52. package/dist/src/lib/generateProvider/template/providerTemplate.js +1 -0
  53. package/dist/src/lib/generateThemeRegister/generateThemeRegister.utils.js +1 -0
  54. package/dist/src/lib/generateTools/generateTools.utils.js +1 -0
  55. package/dist/src/lib/generateTypesTools/generateTypesTools.utils.js +1 -0
  56. package/dist/src/lib/handlerForeignThemes/handlerForeignThemes.utils.js +1 -0
  57. package/dist/src/lib/index.js +1 -0
  58. package/dist/src/lib/processMediaConfig/processMediaConfig.util.js +1 -0
  59. package/dist/src/lib/readFile/readFile.utils.js +1 -0
  60. package/dist/src/lib/simplifyName/simplifyName.utils.js +1 -0
  61. package/dist/src/lib/typingStyles/index.js +1 -0
  62. package/dist/src/lib/typingStyles/typingStyles.utils.js +1 -0
  63. package/dist/src/lib/writeDoc/writeDoc.utils.js +1 -0
  64. package/package.json +80 -0
  65. package/src/app.js +176 -0
  66. package/src/constants/__tests__/compilerType.test.js +20 -0
  67. package/src/constants/__tests__/cssAdvancedSelectors.test.js +38 -0
  68. package/src/constants/__tests__/cssProps.test.js +331 -0
  69. package/src/constants/__tests__/cssPseudoClasses.test.js +48 -0
  70. package/src/constants/compilerType.js +14 -0
  71. package/src/constants/cssAdvancedSelectors.js +32 -0
  72. package/src/constants/cssProps.js +325 -0
  73. package/src/constants/cssPseudoClasses.js +138 -0
  74. package/src/constants/cssPseudoElements.js +83 -0
  75. package/src/constants/index.js +15 -0
  76. package/src/constants/resetCss.js +171 -0
  77. package/src/index.d.ts +31 -0
  78. package/src/index.js +20 -0
  79. package/src/lib/compileConfig.js +59 -0
  80. package/src/lib/compileThemes.js +118 -0
  81. package/src/lib/copyLocalFonts/copyLocalFonts.utils.js +42 -0
  82. package/src/lib/copyLocalFonts/generateCssFonts.utils.js +56 -0
  83. package/src/lib/extractDocFragment/extractDocFragment.utils.js +25 -0
  84. package/src/lib/fileExists/fileExists.utils.js +31 -0
  85. package/src/lib/generateBaseCss/generateBaseCss.utils.js +51 -0
  86. package/src/lib/generateCss/generateCSS.utils.js +42 -0
  87. package/src/lib/generateCss/helpers/advanceselector/advancedSelectorHandler.utils.js +22 -0
  88. package/src/lib/generateCss/helpers/attribute/attributeHandler.utils.js +47 -0
  89. package/src/lib/generateCss/helpers/classnames/formatClassName.utils.js +28 -0
  90. package/src/lib/generateCss/helpers/classnames/handlerRegister.utils.js +124 -0
  91. package/src/lib/generateCss/helpers/cssVars/generateVars.utils.js +73 -0
  92. package/src/lib/generateCss/helpers/dynamicValues/dynamicValues.utils.js +72 -0
  93. package/src/lib/generateCss/helpers/dynamicValues/processDynamic.utils.js +10 -0
  94. package/src/lib/generateCss/helpers/filterGenerateCss.utils.js +73 -0
  95. package/src/lib/generateCss/helpers/foreign/foreignHandler.utils.js +85 -0
  96. package/src/lib/generateCss/helpers/generateCssStyles.utils.js +249 -0
  97. package/src/lib/generateCss/helpers/index.js +53 -0
  98. package/src/lib/generateCss/helpers/mediaqueries/generateMediaQueries.utils.js +9 -0
  99. package/src/lib/generateCss/helpers/mediaqueries/mediaQueriesHandler.utils.js +181 -0
  100. package/src/lib/generateCss/helpers/other/declareCssType.utils.js +120 -0
  101. package/src/lib/generateCss/helpers/other/generateGlobalStyles.utils.js +30 -0
  102. package/src/lib/generateCss/helpers/pseudo/pseudoHandler.utils.js +56 -0
  103. package/src/lib/generateCss/helpers/rulename/formatRuleName.utils.js +163 -0
  104. package/src/lib/generateCss/helpers/utils/extractValues.utils.js +44 -0
  105. package/src/lib/generateCss/helpers/utils/formattedStatKey.utils.js +43 -0
  106. package/src/lib/generateCss/helpers/utils/index.js +15 -0
  107. package/src/lib/generateCss/helpers/utils/processCss.utils.js +93 -0
  108. package/src/lib/generateCss/helpers/utils/separateStyles.utils.js +43 -0
  109. package/src/lib/generateCss/helpers/utils/validatePreviouslyExists.utils.js +61 -0
  110. package/src/lib/generateCssDoc/generateCssDoc.util.js +47 -0
  111. package/src/lib/generateProvider/generateProvider.utils.js +283 -0
  112. package/src/lib/generateProvider/template/providerTemplate.d.ts +60 -0
  113. package/src/lib/generateProvider/template/providerTemplate.js +160 -0
  114. package/src/lib/generateThemeRegister/generateThemeRegister.utils.js +136 -0
  115. package/src/lib/generateTools/generateTools.utils.js +181 -0
  116. package/src/lib/generateTypesTools/generateTypesTools.utils.js +59 -0
  117. package/src/lib/handlerForeignThemes/handlerForeignThemes.utils.js +96 -0
  118. package/src/lib/index.js +61 -0
  119. package/src/lib/processMediaConfig/processMediaConfig.util.js +32 -0
  120. package/src/lib/readFile/readFile.utils.js +110 -0
  121. package/src/lib/simplifyName/__tests__/simplifyName.utils.test.js +87 -0
  122. package/src/lib/simplifyName/simplifyName.utils.js +28 -0
  123. package/src/lib/typingStyles/index.js +3 -0
  124. package/src/lib/typingStyles/typingStyles.utils.js +144 -0
  125. package/src/lib/writeDoc/writeDoc.utils.js +30 -0
package/README.md ADDED
@@ -0,0 +1,1778 @@
1
+ <p align="center">
2
+ <a href="https://kubit-ui.com">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://github.com/kubit-ui/bernova/raw/cms/assets/bernova.png">
5
+ <img src="https://github.com/kubit-ui/bernova/raw/cms/assets/bernova.png" width="70%">
6
+ </picture>
7
+ </a>
8
+ </p>
9
+
10
+ <p align="center">
11
+ <strong>The best way to write CSS with Javascript syntax</strong><br/>
12
+ </p>
13
+
14
+ <p align="center">
15
+ <img src="https://img.shields.io/npm/v/bernova" alt="Version" />
16
+ <img src="https://img.shields.io/badge/license-Apache%202.0-blue" alt="License" />
17
+ </p>
18
+
19
+ ## Related Information
20
+
21
+ - [Instalation](#installation)
22
+ - [Configuration](#configuration)
23
+ - [How to use](#how-to-use)
24
+ - [Design tools](#design-tools)
25
+ - [Foundations](#foundations)
26
+ - [Global Styles](#global-styles)
27
+ - [MediaQueries](#mediaqueries)
28
+ - [Css MediaQueries](#Css-MediaQueries)
29
+ - [Components Tools](#components-tools)
30
+ - [Nested Styles](#Nested-styles)
31
+ - [Variant styles](#Variant-styles)
32
+ - [Css Pseudo Classes](#Css-Pseudo-Classes)
33
+ - [Css Pseudo Elements](#Css-Pseudo-Elements)
34
+ - [HTML Atributes](#HTML-Atributes)
35
+ - [Css Advanced Selectors](#Css-Advanced-Selectors)
36
+ - [Complex Styles](#Complex-Styles)
37
+ - [Foreign Feature](#Foreign-Feature)
38
+ - [Dynamic Values Feature](#Dynamic-Values-Feature)
39
+ - [Fonts](#setting-text-fonts)
40
+ - [Reset CSS](#enable-reset-css)
41
+ - [Typescript helps](#typescript-helps)
42
+ - [Multi themes](#using-multi-themes)
43
+ - [Provider](#library-provider)
44
+ - [Foreign CSS documents](#foreign-css-documents)
45
+
46
+ ## Installation
47
+
48
+ ```bash
49
+ yarn add bernova
50
+ ```
51
+
52
+ ## Configuration
53
+
54
+ The library requires a JSON configuration file located in the root of the project. The name of this file is **bernova.config.json**.
55
+
56
+ There is a script provided by the library to generate a template for the configuration file:
57
+
58
+ ```bash
59
+ npx bv-config
60
+ ```
61
+
62
+ **bernova.config.json** looks like this
63
+
64
+ ```json
65
+ {
66
+ "provider": {
67
+ "name": "BernovaStyledProvider",
68
+ "path": "./src/styles/provider",
69
+ "declarationHelp": true
70
+ },
71
+ "themes": [
72
+ {
73
+ "name": "default",
74
+ "minified": false,
75
+ "theme": {
76
+ "name": "BERNOVA_STYLES",
77
+ "path": "./fixture/theme.ts"
78
+ },
79
+ "foundations": {
80
+ "name": "FOUNDATIONS",
81
+ "path": "./fixture/foundations/foundations.ts"
82
+ },
83
+ "globalStyles": {
84
+ "name": "GLOBAL_STYLES",
85
+ "path": "./fixture/globalStyles.ts"
86
+ },
87
+ "mediaQueries": {
88
+ "name": "MEDIA_QUERIES",
89
+ "path": "./fixture/mediaQueries.ts"
90
+ },
91
+ "resetCss": true,
92
+ "stylesPath": "./src/styles/default",
93
+ "bvTools": {
94
+ "path": "./src/styles/default/tools",
95
+ "declarationHelp": true,
96
+ "cssVariables": true,
97
+ "cssClassNames": true,
98
+ "cssMediaQueries": true,
99
+ "cssGlobalStyles": true,
100
+ "availableComponents": true
101
+ },
102
+ "typesTools": {
103
+ "stylesTypes": { "name": "stylesTypes", "path": "./src/styles/types" },
104
+ "componentsTypes": {
105
+ "name": "componentsTypes",
106
+ "path": "./src/styles/default/tools"
107
+ }
108
+ },
109
+ "fonts": {
110
+ "google": [
111
+ {
112
+ "name": "Roboto",
113
+ "weights": ["300", "400", "600", "700"]
114
+ }
115
+ ]
116
+ }
117
+ }
118
+ ]
119
+ }
120
+ ```
121
+
122
+ ## How to use
123
+
124
+ The library has a script to transpile the js code into css. The command for this is:
125
+
126
+ ```bash
127
+ npx bernova
128
+ ```
129
+
130
+ By adding a flag at the end of the script, you can transpile only part of the project.
131
+
132
+ For FOUNDATIONS, MediaQueries, and GlobalStyles:
133
+
134
+ ```bash
135
+ npx bernova --foundationOnly
136
+ ```
137
+
138
+ For the classes of the HTML elements and available components
139
+
140
+ ```bash
141
+ npx bernova --componentOnly
142
+ ```
143
+
144
+ ## Design Tools
145
+
146
+ ### Foundations
147
+
148
+ The library gives you a lot of freedom when it comes to applying styles, but it also provides tools to follow good CSS practices. If you want to use the CSS variable system, you must add that configuration to the **bernova.config.json** file and create that document in the path provided.
149
+
150
+ ```json
151
+ {
152
+ "themes": [
153
+ {
154
+ //... rest of the config
155
+ "foundations": {
156
+ "name": "FOUNDATIONS",
157
+ "path": "./fixture/foundations/foundations.ts"
158
+ }
159
+ //... rest of the config
160
+ }
161
+ ]
162
+ }
163
+ ```
164
+
165
+ foundation example:
166
+
167
+ ```js
168
+ export const FOUNDATIONS = {
169
+ colors: {
170
+ primary: '#FF0000',
171
+ secondary: '#00FF00',
172
+ tertiary: '#0000FF',
173
+ },
174
+ sizes: {
175
+ small: '4px',
176
+ medium: '8px',
177
+ large: '12px',
178
+ },
179
+ };
180
+ ```
181
+
182
+ The result of this when transpiling is
183
+
184
+ ```css
185
+ :root {
186
+ --colors-primary: #ff0000;
187
+ --colors-secondary: #00ff00;
188
+ --colors-tertiary: #0000ff;
189
+ --sizes-small: 4px;
190
+ --sizes-medium: 8px;
191
+ --sizes-large: 12px;
192
+ }
193
+ ```
194
+
195
+ If you add bvTools to the configuration file, you can have an object to access these variables from your js code.
196
+
197
+ ```json
198
+ {
199
+ "themes": [
200
+ {
201
+ //... rest of the config
202
+ "foundations": {
203
+ "name": "FOUNDATIONS",
204
+ "path": "./fixture/foundations/foundations.ts"
205
+ },
206
+ "bvTools": {
207
+ "path": "./src/styles/default/tools",
208
+ "declarationHelp": true,
209
+ "cssVariables": true
210
+ }
211
+ //... rest of the config
212
+ }
213
+ ]
214
+ }
215
+ ```
216
+
217
+ The resulting tool is
218
+
219
+ ```js
220
+ export const cssVars = {
221
+ colors_primary: 'var(--colors-primary)',
222
+ colors_secondary: 'var(--colors-secondary)',
223
+ colors_tertiary: 'var(--colors-tertiary)',
224
+ sizes_small: 'var(--sizes-small)',
225
+ sizes_medium: 'var(--sizes-medium)',
226
+ sizes_large: 'var(--sizes-large)',
227
+ };
228
+ ```
229
+
230
+ For use with TypeScript, if we set the declarationHelp key to true, it will give us a declaration file.
231
+
232
+ ```ts
233
+ export declare const cssVars: {
234
+ colors_primary: string;
235
+ colors_secondary: string;
236
+ colors_tertiary: string;
237
+ sizes_small: string;
238
+ sizes_medium: string;
239
+ sizes_large: string;
240
+ };
241
+ ```
242
+
243
+ ### Global Styles
244
+
245
+ We can create global styles for the project and create their tools, as long as they are CSS classes.
246
+
247
+ ```json
248
+ {
249
+ "themes": [
250
+ {
251
+ //... rest of the config
252
+ "globalStyles": {
253
+ "name": "GLOBAL_STYLES",
254
+ "path": "./fixture/globalStyles.ts"
255
+ }
256
+ //... rest of the config
257
+ }
258
+ ]
259
+ }
260
+ ```
261
+
262
+ Global styles example:
263
+
264
+ ```js
265
+ export const GLOBAL_STYLES = [
266
+ { targets: 'html, body', styles: { font_size: '16px' } },
267
+ { targets: 'a', styles: { font_weight: '700' } },
268
+ { targets: '*', styles: { box_sizing: 'border-box' } },
269
+ { targets: '.padding-4', styles: { padding: '4px' } },
270
+ { targets: '.padding-8', styles: { padding: '8px' } },
271
+ ];
272
+ ```
273
+
274
+ The result of this when transpiling is:
275
+
276
+ ```css
277
+ html,
278
+ body {
279
+ font-size: 16px;
280
+ }
281
+ a {
282
+ font-weight: 700;
283
+ }
284
+ * {
285
+ box-sizing: border-box;
286
+ }
287
+ .padding-4 {
288
+ padding: 4px;
289
+ }
290
+ .padding-8 {
291
+ padding: 8px;
292
+ }
293
+ ```
294
+
295
+ If you add bvTools to the configuration file, you can have an object to access these variables from your js code.
296
+
297
+ ```json
298
+ {
299
+ "themes": [
300
+ {
301
+ //... rest of the config
302
+ "globalStyles": {
303
+ "name": "GLOBAL_STYLES",
304
+ "path": "./fixture/globalStyles.ts"
305
+ },
306
+ "bvTools": {
307
+ "path": "./src/styles/default/tools",
308
+ "declarationHelp": true,
309
+ "cssGlobalStyles": true
310
+ }
311
+ //... rest of the config
312
+ }
313
+ ]
314
+ }
315
+ ```
316
+
317
+ The resulting tool is (Only CSS classes are considered for the object):
318
+
319
+ ```js
320
+ export const cssGlobalStyles = {
321
+ padding_4: '.padding-4',
322
+ padding_8: '.padding-8',
323
+ };
324
+ ```
325
+
326
+ For use with TypeScript, if we set the declarationHelp key to true, it will give us a declaration file.
327
+
328
+ ```ts
329
+ export declare const cssGlobalStyles: {
330
+ padding_4: string;
331
+ padding_8: string;
332
+ };
333
+ ```
334
+
335
+ ### MediaQueries
336
+
337
+ MediaQueries are an important aspect of CSS, and the library can handle them
338
+
339
+ ```json
340
+ {
341
+ "themes": [
342
+ {
343
+ //... rest of the config
344
+ "mediaQueries": {
345
+ "name": "MEDIA_QUERIES",
346
+ "path": "./fixture/mediaQueries.ts"
347
+ }
348
+ //... rest of the config
349
+ }
350
+ ]
351
+ }
352
+ ```
353
+
354
+ MediaQueries example:
355
+
356
+ ```js
357
+ export const MEDIA_QUERIES = [
358
+ {
359
+ name: 'mobile',
360
+ type: 'screen',
361
+ values: {
362
+ max_width: '767px',
363
+ min_width: '240px',
364
+ },
365
+ },
366
+ {
367
+ name: 'tablet',
368
+ type: 'screen',
369
+ values: {
370
+ max_width: '1024px',
371
+ min_width: '768px',
372
+ },
373
+ },
374
+ {
375
+ name: 'desktop',
376
+ type: 'screen',
377
+ values: {
378
+ max_width: '1440px',
379
+ min_width: '1025px',
380
+ },
381
+ },
382
+ ];
383
+ ```
384
+
385
+ The result of this when transpiling is:
386
+
387
+ ```css
388
+ @media screen and (max-width: 767px) and (min-width: 240px) {
389
+ .test {
390
+ padding: 10px;
391
+ }
392
+ }
393
+ @media screen and (max-width: 1024px) and (min-width: 768px) {
394
+ .test {
395
+ padding: 20px;
396
+ }
397
+ }
398
+ @media screen and (max-width: 1440px) and (min-width: 1025px) {
399
+ .test {
400
+ padding: 30px;
401
+ }
402
+ }
403
+ ```
404
+
405
+ If you add bvTools to the configuration file, you can have an object to access these variables from your js code.
406
+
407
+ ```json
408
+ {
409
+ "themes": [
410
+ {
411
+ //... rest of the config
412
+ "mediaQueries": {
413
+ "name": "MEDIA_QUERIES",
414
+ "path": "./fixture/mediaQueries.ts"
415
+ },
416
+ "bvTools": {
417
+ "path": "./src/styles/default/tools",
418
+ "declarationHelp": true,
419
+ "cssMediaQueries": true
420
+ }
421
+ //... rest of the config
422
+ }
423
+ ]
424
+ }
425
+ ```
426
+
427
+ The resulting tool is:
428
+
429
+ ```js
430
+ export const cssMediaQueries = {
431
+ mobile: 'mobile',
432
+ tablet: 'tablet',
433
+ desktop: 'desktop',
434
+ };
435
+ ```
436
+
437
+ For use with TypeScript, if we set the declarationHelp key to true, it will give us a declaration file.
438
+
439
+ ```ts
440
+ export declare const cssMediaQueries: {
441
+ mobile: 'mobile';
442
+ tablet: 'tablet';
443
+ desktop: 'desktop';
444
+ };
445
+ ```
446
+
447
+ ## Components tools
448
+
449
+ The main feature of the library is the ability to build CSS styles from a JavaScript literal object.
450
+
451
+ Example:
452
+
453
+ ```js
454
+ const CONTAINER = {
455
+ background_color: 'red',
456
+ color: '#fff',
457
+ border_radius: '8px',
458
+ };
459
+ ```
460
+
461
+ The result of this when transpiling is:
462
+
463
+ ```css
464
+ .container {
465
+ background-color: red;
466
+ color: #fff;
467
+ border-radius: 8px;
468
+ }
469
+ ```
470
+
471
+ You can create multiple objects with different components and export them all as a single object. To do this, remember to add the configuration in **bernova.config.json**.
472
+
473
+ ```json
474
+ {
475
+ "themes": [
476
+ {
477
+ //... rest of the config
478
+ "theme": {
479
+ "name": "BERNOVA_STYLES",
480
+ "path": "./fixture/theme.ts"
481
+ }
482
+ //... rest of the config
483
+ }
484
+ ]
485
+ }
486
+ ```
487
+
488
+ theme.ts example:
489
+
490
+ ```js
491
+ import { BUTTON, LINK, CONTAINER } from './components';
492
+
493
+ export const BERNOVA_STYLES = {
494
+ BUTTON,
495
+ LINK,
496
+ CONTAINER,
497
+ };
498
+ ```
499
+
500
+ The result of this when transpiling is:
501
+
502
+ ```css
503
+ .button {
504
+ /* button styles */
505
+ }
506
+ .link {
507
+ /* link styles */
508
+ }
509
+ .container {
510
+ /* container styles */
511
+ }
512
+ ```
513
+
514
+ ### Nested styles
515
+
516
+ In many cases, HTML elements have nested children. It is possible to create styles for these from the main element object.
517
+
518
+ ```js
519
+ export const BUTTON = {
520
+ background: 'red',
521
+ border: 'none',
522
+ _text: {
523
+ color: 'white',
524
+ font_size: '12px',
525
+ },
526
+ _icon: {
527
+ height: '16px',
528
+ width: '16px',
529
+ color: 'white',
530
+ },
531
+ };
532
+ ```
533
+
534
+ Based on the BEM methodology, the result would be as follows:
535
+
536
+ ```css
537
+ .button {
538
+ background: red;
539
+ border: none;
540
+ }
541
+ .button__text {
542
+ color: white;
543
+ font-size: 12px;
544
+ }
545
+ .button__icon {
546
+ height: 16px;
547
+ width: 16px;
548
+ color: white;
549
+ }
550
+ ```
551
+
552
+ ### Variant styles
553
+
554
+ Sometimes we may want to have several similar elements, but with certain variations in their design. The library also allows the use of variants in the javascript object for styles.
555
+
556
+ ```js
557
+ const buttonVariants = {
558
+ PRIMARY: 'PRIMARY',
559
+ ALTERNATIVE: 'ALTERNATIVE',
560
+ };
561
+
562
+ export const BUTTON = {
563
+ border: 'none',
564
+ _text: {
565
+ font_size: '16px',
566
+ },
567
+ _icon: {
568
+ width: '16px',
569
+ height: '16px',
570
+ },
571
+ [buttonVariants.PRIMARY]: {
572
+ background: 'red',
573
+ _text: {
574
+ color: 'white',
575
+ },
576
+ _icon: {
577
+ color: 'white',
578
+ },
579
+ },
580
+ [buttonVariants.ALTERNATIVE]: {
581
+ background: '#fff',
582
+ _text: {
583
+ color: '#000',
584
+ },
585
+ _icon: {
586
+ color: '#000',
587
+ },
588
+ },
589
+ };
590
+ ```
591
+
592
+ Based on the BEM methodology, the result would be as follows:
593
+
594
+ ```css
595
+ .button {
596
+ border: none;
597
+ }
598
+ .button__text {
599
+ font-size: 16px;
600
+ }
601
+ .button__icon {
602
+ width: 16px;
603
+ height: 16px;
604
+ }
605
+ .button--primary {
606
+ background: red;
607
+ }
608
+ .button__text--primary {
609
+ color: white;
610
+ }
611
+ .button__icon--primary {
612
+ color: white;
613
+ }
614
+ .button--alternative {
615
+ background: #fff;
616
+ }
617
+ .button__text--alternative {
618
+ color: #000;
619
+ }
620
+ .button__icon--alternative {
621
+ color: #000;
622
+ }
623
+ ```
624
+
625
+ ### Css Pseudo Classes
626
+
627
+ A very common practice in CSS is the use of pseudo classes. The library allows their implementation from the JavaScript styles object.
628
+
629
+ ```js
630
+ const BUTTON = {
631
+ background_color: '#ff0000',
632
+ color: 'white',
633
+ $pseudoClasses: {
634
+ active: {
635
+ background_color: '#ac0202'
636
+ },
637
+ hover: {
638
+ background_color: '#e94141',
639
+ }
640
+ focus: {
641
+ border_color: '#0000ff',
642
+ }
643
+ }
644
+ }
645
+ ```
646
+
647
+ The result of this when transpiling is:
648
+
649
+ ```css
650
+ .button {
651
+ background-color: #ff0000;
652
+ color: white;
653
+ }
654
+ .button:active {
655
+ background-color: #ac0202;
656
+ }
657
+ .button:hover {
658
+ background-color: #e94141;
659
+ }
660
+ .button:focus {
661
+ background-color: #0000ff;
662
+ }
663
+ ```
664
+
665
+ ### Css Pseudo Elements
666
+
667
+ Pseudo elements are widely used in CSS styles. The library also supports them.
668
+
669
+ ```js
670
+ export const CONTAINER = {
671
+ border_radius: '100%',
672
+ border: '1px solid black',
673
+ height: '80px',
674
+ width: '80px',
675
+ $pseudoElements: {
676
+ before: {
677
+ $content: '',
678
+ position: 'absolute',
679
+ border_radius: '100%',
680
+ background_color: 'blue',
681
+ height: '20px',
682
+ width: '20px',
683
+ left: '70px',
684
+ top: '10px',
685
+ },
686
+ },
687
+ };
688
+ ```
689
+
690
+ The result of this when transpiling is:
691
+
692
+ ```css
693
+ .container {
694
+ border-radius: 100%;
695
+ border: 1px solid black;
696
+ height: 80px;
697
+ width: 80px;
698
+ }
699
+ .container::before {
700
+ content: '';
701
+ position: absolute;
702
+ border-radius: 100%;
703
+ background-color: blue;
704
+ height: 20px;
705
+ width: 20px;
706
+ left: 70px;
707
+ top: 10px;
708
+ }
709
+ ```
710
+
711
+ ### HTML Atributes
712
+
713
+ Sometimes, we need to condition the application of certain styles, depending on whether a certain condition is met.
714
+
715
+ #### Simple example:
716
+
717
+ If you only need to check that an attribute exists (Boolean), you can do so as follows:
718
+
719
+ HTML element example:
720
+
721
+ ```html
722
+ <span class="message" data-valid="true">A simple notify</span>
723
+ ```
724
+
725
+ Javascript style object:
726
+
727
+ ```js
728
+ export const MESSAGE = {
729
+ color: '#000',
730
+ padding: '8px',
731
+ border_radius: '16px',
732
+ $attributes: {
733
+ ['data-valid']: {
734
+ cursor: 'pointer',
735
+ },
736
+ },
737
+ };
738
+ ```
739
+
740
+ The result of this when transpiling is:
741
+
742
+ ```css
743
+ .message {
744
+ color: #000;
745
+ padding: 8px;
746
+ border-radius: 16px;
747
+ }
748
+ .message[data-valid='true'] {
749
+ cursor: pointer;
750
+ }
751
+ ```
752
+
753
+ #### Custom example
754
+
755
+ If you need the attribute value to be customized or have more than one use case, you can do so as follows:
756
+
757
+ HMLT element example:
758
+
759
+ ```html
760
+ <span class="message" data-type="warning">A simple notify</span>
761
+ ```
762
+
763
+ JavaScript style object:
764
+
765
+ ```js
766
+ export const MESSAGE = {
767
+ color: '#000',
768
+ padding: '8px',
769
+ border_radius: '16px',
770
+ $attributes: {
771
+ ['data-type']: {
772
+ success: {
773
+ background_color: 'green',
774
+ },
775
+ warning: {
776
+ background_color: 'yellow',
777
+ },
778
+ error: {
779
+ background_color: 'red',
780
+ },
781
+ },
782
+ },
783
+ };
784
+ ```
785
+
786
+ The result of this when transpiling is:
787
+
788
+ ```css
789
+ .message {
790
+ color: #000;
791
+ padding: 8px;
792
+ border-radius: 16px;
793
+ }
794
+ .message[data-type='success'] {
795
+ background-color: green;
796
+ }
797
+ .message[data-type='warning'] {
798
+ background-color: yellow;
799
+ }
800
+ .message[data-type='error'] {
801
+ background-color: red;
802
+ }
803
+ ```
804
+
805
+ ### Css MediaQueries
806
+
807
+ An important aspect of modern designs is adaptability to different devices. This is usually handled with MediaQueries, so the library also supports this feature.
808
+
809
+ #### From project config
810
+
811
+ If you have created the media queries configuration file [MediaQueries](#MediaQueries), you can access its configuration using the configuration name as the object key.
812
+
813
+ ```js
814
+ import { cssMediaQueries } from './tools/cssMediaQueries';
815
+
816
+ export const BANNER = {
817
+ width: '1220px',
818
+ $mediaQueries: {
819
+ [cssMediaQueries.mobile]: {
820
+ width: '240px',
821
+ },
822
+ },
823
+ };
824
+ ```
825
+
826
+ The result of this when transpiling is:
827
+
828
+ ```css
829
+ .banner {
830
+ width: 1220px;
831
+ }
832
+ @media screen and (max-width: 767px) and (min-width: 240px) {
833
+ .banner {
834
+ width: 240px;
835
+ }
836
+ }
837
+ ```
838
+
839
+ #### Custom config
840
+
841
+ Sometimes, we need a very specific media query that is not found in the configuration structure. Or perhaps we don't want to generate the media query configuration because there will be very few use cases. For these types of situations, we can set up custom media queries.
842
+
843
+ ```js
844
+ export const BANNER = {
845
+ width: '1220px',
846
+ $mediaQueries: {
847
+ mini: {
848
+ $type: 'screen',
849
+ $values: { 'min-width': '100px', 'max-width': '200px' },
850
+ width: '100px',
851
+ },
852
+ },
853
+ };
854
+ ```
855
+
856
+ The result of this when transpiling is:
857
+
858
+ ```css
859
+ .banner {
860
+ width: 1220px;
861
+ }
862
+ @media screen and (max-width: 200px) and (min-width: 100px) {
863
+ .banner {
864
+ width: 100px;
865
+ }
866
+ }
867
+ ```
868
+
869
+ ### Css Advanced Selectors
870
+
871
+ In CSS, advanced selectors can be used to access other elements of the DOM. To do this with the library, we can use the following feature
872
+
873
+ ```js
874
+ export const CONTAINER = {
875
+ height: '100px',
876
+ width: '100px',
877
+ $advancedSelector: [
878
+ {
879
+ descendant: {
880
+ $target: 'span',
881
+ color: 'red',
882
+ },
883
+ },
884
+ {
885
+ child: {
886
+ $target: 'p',
887
+ font_size: '10px';
888
+ color: 'black',
889
+ },
890
+ },
891
+ ]
892
+ }
893
+ ```
894
+
895
+ The result of this when transpiling is:
896
+
897
+ ```css
898
+ .container {
899
+ height: 100px;
900
+ width: 100px;
901
+ }
902
+ .container span {
903
+ color: red;
904
+ }
905
+ .container > p {
906
+ font-size: 10px;
907
+ color: black;
908
+ }
909
+ ```
910
+
911
+ ### Complex Styles
912
+
913
+ Within each special feature (those that begin with the **$** symbol) of style objects in JavaScript, others can be used to create complex styles.
914
+
915
+ ```js
916
+ export const CONTAINER = {
917
+ width: '30px';
918
+ height: '30px';
919
+ $attributes: {
920
+ ['data-hoverable']: {
921
+ $pseudoClasses: {
922
+ hover: {
923
+ $advancedSelectors: [
924
+ {
925
+ descendant: {
926
+ $target: 'p',
927
+ background_color: 'red',
928
+ color: 'white',
929
+ },
930
+ },
931
+ {
932
+ descendant: {
933
+ $target: 'b',
934
+ background_color: 'green',
935
+ color: 'white',
936
+ },
937
+ },
938
+ {
939
+ child: {
940
+ $target: 'span',
941
+ background_color: 'blue',
942
+ color: 'black',
943
+ },
944
+ },
945
+ ]
946
+ }
947
+ }
948
+ }
949
+ }
950
+ }
951
+ ```
952
+
953
+ The result of this when transpiling is:
954
+
955
+ ```css
956
+ .container {
957
+ width: 30px;
958
+ height: 30px;
959
+ }
960
+ .container[data-hoverable='true']:hover p {
961
+ background-color: red;
962
+ color: white;
963
+ }
964
+ .container[data-hoverable='true']:hover b {
965
+ background-color: green;
966
+ color: white;
967
+ }
968
+ .container[data-hoverable='true']:hover > span {
969
+ background-color: blue;
970
+ color: white;
971
+ }
972
+ ```
973
+
974
+ When nesting pseudo-classes and pseudo-elements, you can avoid using the **$** symbol a second time.
975
+
976
+ ```js
977
+ export const INPUT = {
978
+ border_color: 'black',
979
+ border_radius: '4px',
980
+ $pseudoClasses: {
981
+ active: {
982
+ before: {
983
+ $content: '',
984
+ color: '#ccc',
985
+ },
986
+ },
987
+ },
988
+ };
989
+ ```
990
+
991
+ The result of this when transpiling is:
992
+
993
+ ```css
994
+ .input {
995
+ border-color: black;
996
+ border-radius: 4px;
997
+ }
998
+ .input:active::before {
999
+ content: '';
1000
+ color: #ccc;
1001
+ }
1002
+ ```
1003
+
1004
+ ### Foreign Feature
1005
+
1006
+ When we are creating styles for an HTML element, there may be other nested elements whose styles we have already styled in another element and may want to reuse.
1007
+
1008
+ ```js
1009
+ import { LINK, BUTTON } from './components';
1010
+
1011
+ export const HEADER = {
1012
+ width: '100%',
1013
+ height: '80px',
1014
+ background_color: 'green',
1015
+ $foreign: {
1016
+ nav_item: {
1017
+ component: LINK,
1018
+ variant: 'primary',
1019
+ name: 'link',
1020
+ },
1021
+ loging_button: {
1022
+ component: BUTTON,
1023
+ name: 'button',
1024
+ },
1025
+ },
1026
+ };
1027
+ ```
1028
+
1029
+ ### Dynamic Values Feature
1030
+
1031
+ There may be a value within our styles that we need to retrieve dynamically. The library provides a tool to handle these cases.
1032
+
1033
+ IMPORTANT: The names of variables within the array, as well as in its implementation, must starts with the dollar char <**$**>.
1034
+
1035
+ ```js
1036
+ export const CONTAINER = {
1037
+ $dynamicValues: ['$bgColor', '$borderColor'],
1038
+ height: '100px',
1039
+ width: '100px',
1040
+ background_color: '$bgColor',
1041
+ border_color: '$borderColor',
1042
+ };
1043
+ ```
1044
+
1045
+ The _$dynamicValues_ tool will return the result in string format and in object format so that we can use the one that applies in our case.
1046
+
1047
+ ```js
1048
+ import { StylesProvider } from './provider';
1049
+
1050
+ const styles = StylesProvider.getComponentStyles({ component: 'CONTAINER' });
1051
+ const dynamicVars = styles.dynamic_values({
1052
+ $bgColor: 'white',
1053
+ $borderColor: 'red',
1054
+ });
1055
+
1056
+ /**
1057
+ * dinamycVars = {
1058
+ * string: '--bgcolor: white; --bordercolor: red',
1059
+ * object: {
1060
+ * '--bgcolor': 'white',
1061
+ * '--bordercolor': 'red'
1062
+ * }
1063
+ * }
1064
+ */
1065
+ ```
1066
+
1067
+ Example of implementation
1068
+
1069
+ ```jsx
1070
+ import { StylesProvider } from './provider';
1071
+
1072
+ export const Container = ({ bgColor, borderColor, children }) => {
1073
+ const styles = StylesProvider.getComponentStyles({ component: 'CONTAINER' });
1074
+ const dynamicVars = styles.dynamic_values({
1075
+ $bgColor: bgColor,
1076
+ $borderColor: borderColor,
1077
+ }).object;
1078
+
1079
+ <div className={styles.container} style={dynamicVars}>
1080
+ {children}
1081
+ </div>;
1082
+ };
1083
+ ```
1084
+
1085
+ In this case, only the styles for the header will be generated, and in the development tools, for _nav_item_ and _login_button_, the existing classes for BUTTON and LINK will be returned.
1086
+
1087
+ ## Access to classNames
1088
+
1089
+ To use the generated CSS classes, you can use the name directly on the HTML element, as the library will return a valid CSS file.
1090
+
1091
+ ```html
1092
+ <button class="button button--primary">
1093
+ <span class="button__text button__text--primary">Button Text</span>
1094
+ </button>
1095
+ ```
1096
+
1097
+ However, this can be complex to use in collaborative projects or large projects. The library provides an object that records all the CSS classes generated.
1098
+
1099
+ ```json
1100
+ {
1101
+ "themes": [
1102
+ {
1103
+ //... rest of the config
1104
+ "theme": {
1105
+ "name": "BERNOVA_STYLES",
1106
+ "path": "./fixture/theme.ts"
1107
+ },
1108
+ "bvTools": {
1109
+ "path": "./src/styles/default/tools",
1110
+ "declarationHelp": true,
1111
+ "cssClassNames": true
1112
+ }
1113
+ //... rest of the config
1114
+ }
1115
+ ]
1116
+ }
1117
+ ```
1118
+
1119
+ The returned object looks like this:
1120
+
1121
+ ```js
1122
+ export const cssClasses = {
1123
+ button: 'button',
1124
+ button_icon: 'button__icon',
1125
+ button_text: 'button__text',
1126
+ button_primary: 'button button--primary',
1127
+ button_icon_primary: 'button__icon button__icon--primary',
1128
+ button_text_primary: 'button__text button__text--primary',
1129
+ card: 'card',
1130
+ card_header: 'card__header',
1131
+ card_body: 'card__body',
1132
+ card_footer: 'card__footer',
1133
+ };
1134
+ ```
1135
+
1136
+ For use with TypeScript, if we set the declarationHelp key to true, it will give us a declaration file.
1137
+
1138
+ ```ts
1139
+ export declare const cssClasses: {
1140
+ button: string;
1141
+ button_icon: string;
1142
+ button_text: string;
1143
+ button_primary: string;
1144
+ button_icon_primary: string;
1145
+ button_text_primary: string;
1146
+ card: string;
1147
+ card_header: string;
1148
+ card_body: string;
1149
+ card_footer: string;
1150
+ };
1151
+ ```
1152
+
1153
+ Example of use
1154
+
1155
+ ```jsx
1156
+ import { cssClasses } from './tools';
1157
+
1158
+ export const Button = ({ text }) => {
1159
+ return (
1160
+ <button className={cssClasses.button_primary}>
1161
+ <span className={cssClasses.button_text_primary}>{text}</span>
1162
+ </button>
1163
+ );
1164
+ };
1165
+ ```
1166
+
1167
+ ## Access to components
1168
+
1169
+ Sometimes, we may need to know which components have been styled with the library, beyond just the CSS classes.
1170
+
1171
+ ```json
1172
+ {
1173
+ "themes": [
1174
+ {
1175
+ //... rest of the config
1176
+ "theme": {
1177
+ "name": "BERNOVA_STYLES",
1178
+ "path": "./fixture/theme.ts"
1179
+ },
1180
+ "bvTools": {
1181
+ "path": "./src/styles/default/tools",
1182
+ "declarationHelp": true,
1183
+ "availableComponents": true
1184
+ }
1185
+ //... rest of the config
1186
+ }
1187
+ ]
1188
+ }
1189
+ ```
1190
+
1191
+ The returned object looks like this:
1192
+
1193
+ ```js
1194
+ export const cssAvailableComponents = {
1195
+ BUTTON: 'BUTTON',
1196
+ CARD: 'CARD',
1197
+ };
1198
+ ```
1199
+
1200
+ For use with TypeScript, if we set the declarationHelp key to true, it will give us a declaration file.
1201
+
1202
+ ```ts
1203
+ export declare const cssAvailableComponents: {
1204
+ BUTTON: 'BUTTON';
1205
+ CARD: 'CARD';
1206
+ };
1207
+ ```
1208
+
1209
+ ## Using variables in JavaScript objects for styles
1210
+
1211
+ We typically use constants to store values and reuse them when necessary.
1212
+
1213
+ ```js
1214
+ const SIZES = {
1215
+ small: '4px',
1216
+ medium: '8px',
1217
+ large: '12px',
1218
+ };
1219
+ const COLORS = {
1220
+ red: '#ff0000',
1221
+ green: '#00ff00',
1222
+ blue: '#0000ff',
1223
+ white: '#fff',
1224
+ };
1225
+ export const BUTTON = {
1226
+ background_color: COLORS.red,
1227
+ padding: SIZES.medium,
1228
+ border_radius: SIZES.small,
1229
+ color: COLORS.white,
1230
+ };
1231
+ ```
1232
+
1233
+ The result of this when transpiling is:
1234
+
1235
+ ```css
1236
+ .button {
1237
+ background-color: #ff0000;
1238
+ padding: 8px;
1239
+ border-radius: 4px;
1240
+ color: #fff;
1241
+ }
1242
+ ```
1243
+
1244
+ This could work in the library, but if you want to use the CSS variable system, it is advisable to create the tools for the [foundations](#Foundations)
1245
+
1246
+ ```js
1247
+ import { cssVars } from './tools';
1248
+
1249
+ export const BUTTON = {
1250
+ background_color: cssVars.colors_red,
1251
+ padding: cssVars.sizes_medium,
1252
+ border_radius: cssVars.sizes_small,
1253
+ color: cssVars.colors_white,
1254
+ };
1255
+ ```
1256
+
1257
+ The result of this when transpiling is:
1258
+
1259
+ ```css
1260
+ .button {
1261
+ background-color: var(--colors-red);
1262
+ padding: var(--sizes-medium);
1263
+ border-radius: var(--sizes-small);
1264
+ color: var(--colors-white);
1265
+ }
1266
+ ```
1267
+
1268
+ ## Setting text fonts
1269
+
1270
+ ```json
1271
+ {
1272
+ "themes": [
1273
+ {
1274
+ //... rest of the config
1275
+ "fonts": {
1276
+ "google": [
1277
+ {
1278
+ "name": "Roboto",
1279
+ "weights": ["300", "400", "600", "700"]
1280
+ }
1281
+ ]
1282
+ }
1283
+ //... rest of the config
1284
+ }
1285
+ ]
1286
+ }
1287
+ ```
1288
+
1289
+ The result of this when transpiling is:
1290
+
1291
+ ```css
1292
+ @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;600;700&display=swap');
1293
+ ```
1294
+
1295
+ ## Enable Reset CSS
1296
+
1297
+ The library has a feature that can be enabled so that the generated CSS resets certain styles.
1298
+
1299
+ ```json
1300
+ {
1301
+ "themes": [
1302
+ {
1303
+ //... rest of the config
1304
+ "resetCss": true
1305
+ //... rest of the config
1306
+ }
1307
+ ]
1308
+ }
1309
+ ```
1310
+
1311
+ The result of this when transpiling is:
1312
+
1313
+ ```css
1314
+ html {
1315
+ margin: 0;
1316
+ padding: 0;
1317
+ vertical-align: baseline;
1318
+ margin-top: 0;
1319
+ margin-bottom: 0;
1320
+ margin-left: 0;
1321
+ margin-right: 0;
1322
+ box-sizing: border-box;
1323
+ background-color: transparent;
1324
+ border: 0;
1325
+ }
1326
+ body,
1327
+ div,
1328
+ span,
1329
+ applet,
1330
+ object,
1331
+ iframe,
1332
+ h1,
1333
+ h2,
1334
+ h3,
1335
+ h4,
1336
+ h5,
1337
+ h6,
1338
+ p,
1339
+ blockquote,
1340
+ pre,
1341
+ a,
1342
+ abbr,
1343
+ acronym,
1344
+ address,
1345
+ big,
1346
+ cite,
1347
+ code,
1348
+ del,
1349
+ dfn,
1350
+ em,
1351
+ img,
1352
+ ins,
1353
+ kbd,
1354
+ q,
1355
+ s,
1356
+ samp,
1357
+ small,
1358
+ strike,
1359
+ strong,
1360
+ sub,
1361
+ sup,
1362
+ tt,
1363
+ var,
1364
+ b,
1365
+ u,
1366
+ i,
1367
+ center,
1368
+ dl,
1369
+ dt,
1370
+ dd,
1371
+ ol,
1372
+ ul,
1373
+ li,
1374
+ fieldset,
1375
+ form,
1376
+ label,
1377
+ legend,
1378
+ table,
1379
+ caption,
1380
+ tbody,
1381
+ tfoot,
1382
+ thead,
1383
+ tr,
1384
+ th,
1385
+ td,
1386
+ article,
1387
+ aside,
1388
+ canvas,
1389
+ details,
1390
+ embed,
1391
+ figure,
1392
+ figcaption,
1393
+ footer,
1394
+ header,
1395
+ hgroup,
1396
+ menu,
1397
+ nav,
1398
+ output,
1399
+ ruby,
1400
+ section,
1401
+ summary,
1402
+ time,
1403
+ mark,
1404
+ audio,
1405
+ video,
1406
+ dialog,
1407
+ input,
1408
+ button {
1409
+ margin: 0;
1410
+ padding: 0;
1411
+ vertical-align: baseline;
1412
+ margin-top: 0;
1413
+ margin-bottom: 0;
1414
+ margin-left: 0;
1415
+ margin-right: 0;
1416
+ box-sizing: border-box;
1417
+ background-color: transparent;
1418
+ border: 0;
1419
+ }
1420
+ article,
1421
+ aside,
1422
+ details,
1423
+ figcaption,
1424
+ figure,
1425
+ footer,
1426
+ header,
1427
+ hgroup,
1428
+ menu,
1429
+ nav,
1430
+ section {
1431
+ display: block;
1432
+ }
1433
+ body {
1434
+ line-height: 1;
1435
+ }
1436
+ ol,
1437
+ ul {
1438
+ list-style: none;
1439
+ }
1440
+ blockquote,
1441
+ q {
1442
+ quotes: none;
1443
+ }
1444
+ blockquote::before,
1445
+ blockquote::after,
1446
+ q::before,
1447
+ q::after {
1448
+ content: '';
1449
+ content: none;
1450
+ }
1451
+ table {
1452
+ border-collapse: collapse;
1453
+ border-spacing: 0;
1454
+ }
1455
+
1456
+ @supports (font: -apple-system-body) {
1457
+ html {
1458
+ font: -apple-system-body;
1459
+ }
1460
+ }
1461
+ @supports (font: system-ui) {
1462
+ html {
1463
+ font: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell,
1464
+ Noto Sans, sans-serif;
1465
+ }
1466
+ }
1467
+ ```
1468
+
1469
+ ## TypeScript Helps
1470
+
1471
+ The tools generated by the library are in JavaScript format, but they have declaration files for type support in TypeScript. In addition to this, the library can generate _types_ to help in the construction of style objects or for the structure of components styled with the library.
1472
+
1473
+ ```json
1474
+ {
1475
+ "themes": [
1476
+ {
1477
+ //... rest of the config
1478
+ "typesTools": {
1479
+ "stylesTypes": { "name": "stylesTypes", "path": "./src/styles/types" },
1480
+ "componentsTypes": {
1481
+ "name": "componentsTypes",
1482
+ "path": "./src/styles/default/tools"
1483
+ }
1484
+ }
1485
+ //... rest of the config
1486
+ }
1487
+ ]
1488
+ }
1489
+ ```
1490
+
1491
+ ## Using Multi themes
1492
+
1493
+ If you need to work with different themes, the **themes** key of the configuration object is an array and allows you to customize settings for different themes. The result will be a CSS document for each theme, as well as its set of tools.
1494
+
1495
+ ```json
1496
+ {
1497
+ "provider": {
1498
+ "name": "TsAppProvider",
1499
+ "path": "./src/provider"
1500
+ },
1501
+ "themes": [
1502
+ {
1503
+ "name": "default",
1504
+ "theme": {
1505
+ "name": "BERNOVA_STYLES",
1506
+ "path": "./src/design/default/components/theme.ts"
1507
+ },
1508
+ "foundations": {
1509
+ "name": "FOUNDATIONS",
1510
+ "path": "./src/design/default/foundations/foundations.ts"
1511
+ },
1512
+ "mediaQueries": {
1513
+ "name": "MEDIA_QUERIES",
1514
+ "path": "./src/design/default/mediaQueries/mediaQueries.ts"
1515
+ },
1516
+ "resetCss": false,
1517
+ "stylesPath": "./src/styles/default",
1518
+ "fonts": {
1519
+ "google": [
1520
+ {
1521
+ "name": "Roboto",
1522
+ "weights": ["300", "400", "600", "700"]
1523
+ }
1524
+ ]
1525
+ }
1526
+ },
1527
+ {
1528
+ "name": "alternative",
1529
+ "theme": {
1530
+ "name": "BERNOVA_STYLES",
1531
+ "path": "./src/design/alternative/components/theme.ts"
1532
+ },
1533
+ "foundations": {
1534
+ "name": "FOUNDATIONS",
1535
+ "path": "./src/design/alternative/foundations/foundations.ts"
1536
+ },
1537
+ "mediaQueries": {
1538
+ "name": "MEDIA_QUERIES",
1539
+ "path": "./src/design/alternative/mediaQueries/mediaQueries.ts"
1540
+ },
1541
+ "resetCss": true,
1542
+ "stylesPath": "./src/styles/alternative",
1543
+ "fileName": "alternative",
1544
+ "fonts": {
1545
+ "google": [
1546
+ {
1547
+ "name": "Roboto",
1548
+ "weights": ["300", "400", "600", "700"]
1549
+ }
1550
+ ]
1551
+ }
1552
+ }
1553
+ ]
1554
+ }
1555
+ ```
1556
+
1557
+ ## Library Provider
1558
+
1559
+ If the project is very large, it is likely that you will need to manage all the tools generated by the library. This is why the library can create a JavaScript Provider to handle all these aspects. Like the other tools, the declaration files are available to the provider.
1560
+
1561
+ ```json
1562
+ {
1563
+ "provider": {
1564
+ "name": "StylesProvider",
1565
+ "path": "./src/styles/provider",
1566
+ "declarationHelp": true
1567
+ },
1568
+ "themes": [
1569
+ {
1570
+ "name": "theme-1"
1571
+ //... theme configurations
1572
+ },
1573
+ {
1574
+ "name": "theme-2"
1575
+ //... theme configurations
1576
+ }
1577
+ ]
1578
+ }
1579
+ ```
1580
+
1581
+ ### Handler themes
1582
+
1583
+ The provider returned by the library will be built automatically, allowing access to multiple themes, variables, styled components, and CSS classes. All that is required is to create a new instance of the provider.
1584
+
1585
+ ```js
1586
+ import { StylesProvider } from './src/styles/provider'; // <-- The same name and same route of bernova.config.json
1587
+
1588
+ export const ThemeProvider = new StylesProvider();
1589
+ ```
1590
+
1591
+ You can allow the provider to manage the import of CSS into the DOM with minimal configuration.
1592
+
1593
+ ```js
1594
+ import { StylesProvider } from './src/styles/provider'; // <-- The same name and same route of bernova.config.json
1595
+
1596
+ export const ThemeProvider = new StylesProvider({ jsInCss: true });
1597
+ ```
1598
+
1599
+ In order for the strategy of allowing the provider to manage the import of CSS with multiple instances of the provider to work, an ID can be set for each instance.
1600
+
1601
+ ```js
1602
+ import { StylesProvider } from './src/styles/provider'; // <-- The same name and same route of bernova.config.json
1603
+
1604
+ export const LightThemeProvider = new StylesProvider({
1605
+ jsInCss: true,
1606
+ id: 'lighttheme1',
1607
+ });
1608
+ export const DarkThemeProvider = new StylesProvider({
1609
+ jsInCss: true,
1610
+ id: 'darktheme1',
1611
+ });
1612
+ ```
1613
+
1614
+ It is also possible to switch between themes from the same provider.
1615
+
1616
+ ```js
1617
+ import { StylesProvider } from './src/styles/provider';
1618
+
1619
+ export const ThemeProvider = new StylesProvider({ jsInCss: true });
1620
+
1621
+ ThemeProvider.themeSelected = 'dark';
1622
+ ```
1623
+
1624
+ If you do not have access to, or do not know, the names of the topics generated with the library, the provider also has tools to manage this.
1625
+
1626
+ ```js
1627
+ import { StylesProvider } from './src/styles/provider';
1628
+
1629
+ export const ThemeProvider = new StylesProvider({ jsInCss: true });
1630
+
1631
+ const themes = ThemeProvider.allThemeNames; // <-- string[]
1632
+
1633
+ export const themeObject = themes.reduce((acc, theme) => {
1634
+ acc[theme] = theme;
1635
+ return acc;
1636
+ }, {});
1637
+ ```
1638
+
1639
+ You can also access the complete themes with their variables, components, and CSS classes associated with each one.
1640
+
1641
+ ```js
1642
+ import { StylesProvider } from './src/styles/provider';
1643
+
1644
+ export const ThemeProvider = new StylesProvider({ jsInCss: true });
1645
+
1646
+ const completeThemes = ThemeProvider.allThemes;
1647
+ ```
1648
+
1649
+ #### Provider themes tools
1650
+
1651
+ Once you have selected the theme you want to work with (if you don't specify one, it will default to the first one), you can access the variables, CSS classes, and components by parts associated only with the selected theme.
1652
+
1653
+ ```js
1654
+ import { StylesProvider } from './src/styles/provider';
1655
+
1656
+ export const ThemeProvider = new StylesProvider({ jsInCss: true });
1657
+
1658
+ const themes = ThemeProvider.allThemeNames;
1659
+ export const themeObject = themes.reduce((acc, theme) => {
1660
+ acc[theme] = theme;
1661
+ return acc;
1662
+ }, {});
1663
+
1664
+ ThemeProvider.themeSelected = themeObject.dark;
1665
+ export const cssDarkVariables = ThemeProvider.variables;
1666
+ export const cssDarkClasses = ThemeProvider.classsNames;
1667
+ export const cssDarkComponents = ThemeProvider.components;
1668
+ export const cssDarkGlobalStyles = ThemeProvider.globalStyles;
1669
+ export const cssDarkMediaQueries = ThemeProvider.mediaQueries;
1670
+ ```
1671
+
1672
+ To use the specific CSS classes of a component from a selected theme, there is no need to create different interactions between the objects returned by the provider. There is a method to manage this.
1673
+
1674
+ ```js
1675
+ import { StylesProvider } from './src/styles/provider';
1676
+
1677
+ export const ThemeProvider = new StylesProvider({ jsInCss: true });
1678
+
1679
+ const { components, getComponentStyles } = ThemeProvider;
1680
+
1681
+ const buttonStyles = getComponentStyles({
1682
+ variant: 'primary', // <-- optional parameter
1683
+ component: components.button,
1684
+ });
1685
+
1686
+ /*
1687
+ * buttonStyles = {
1688
+ * button: 'button button--primary,
1689
+ * text: 'button__text button__text--primary,
1690
+ * icon: 'button__icon button__icon--primary,
1691
+ * }
1692
+ */
1693
+ ```
1694
+
1695
+ The **getComponentStyle** method has a prop that allows you to extend CSS classes with external classes, as long as the object structure is maintained.
1696
+
1697
+ ```js
1698
+ import { StylesProvider } from './src/styles/provider';
1699
+
1700
+ export const ThemeProvider = new StylesProvider({ jsInCss: true });
1701
+
1702
+ const { components, getComponentStyles } = ThemeProvider;
1703
+
1704
+ const additionalClassNames = {
1705
+ button: 'external-color',
1706
+ text: 'external-size',
1707
+ };
1708
+
1709
+ const buttonStyles = getComponentStyles({
1710
+ variant: 'primary', // <-- optional parameter
1711
+ component: components.button,
1712
+ additionalClassNames,
1713
+ });
1714
+
1715
+ /*
1716
+ * buttonStyles = {
1717
+ * button: 'button button--primary external-color,
1718
+ * text: 'button__text button__text--primary external-size,
1719
+ * icon: 'button__icon button__icon--primary,
1720
+ * }
1721
+ */
1722
+ ```
1723
+
1724
+ ## Foreign CSS documents
1725
+
1726
+ You probably already have CSS documents with highly customized rules and want to integrate these documents into the library provider. There is a key in the individual configuration of each theme to add all these additional documents, which will be associated with the theme in which they are established.
1727
+
1728
+ ```json
1729
+ {
1730
+ "provider": {
1731
+ "name": "StylesProvider",
1732
+ "path": "./src/styles/provider",
1733
+ "declarationHelp": true
1734
+ },
1735
+ "themes": [
1736
+ {
1737
+ "name": "theme-1",
1738
+ "foreignThemes": [
1739
+ {
1740
+ "priority": "low",
1741
+ "name": "teams",
1742
+ "path": "./fixture/teams.css"
1743
+ },
1744
+ {
1745
+ "priority": "high",
1746
+ "name": "reset",
1747
+ "path": "./fixture/reset.css"
1748
+ }
1749
+ ]
1750
+ //... theme configurations
1751
+ }
1752
+ ]
1753
+ }
1754
+ ```
1755
+
1756
+ With this configuration, every time the provider injects the related theme's CSS, it will also inject the established CSS. Similarly, if the external CSS files have CSS classes or variables, these keys can be accessed in their corresponding categories from the provider.
1757
+
1758
+ ### Recover className from extenal css document
1759
+
1760
+ ```js
1761
+ import { ThemeProvider } from './src/styles/provider';
1762
+
1763
+ const { components, getComponentStyles } = ThemeProvider;
1764
+
1765
+ const avatarStyles = getComponentStyles({
1766
+ component: components.teams, // <-- This is from teams.css document
1767
+ });
1768
+ ```
1769
+
1770
+ ### Recover variable from extenal css document
1771
+
1772
+ ```js
1773
+ import { ThemeProvider } from './src/styles/provider';
1774
+
1775
+ export const LOGIN_BUTTON = {
1776
+ background_color: ThemeProvider.variables.color_teams_primary, // <-- This is from ':root' into teams.css document
1777
+ };
1778
+ ```