@skbkontur/colors 0.5.0 → 1.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/README.md +171 -76
  2. package/dist/cjs/constants/abney-correction.d.ts +2 -0
  3. package/dist/cjs/constants/abney-correction.js +1105 -0
  4. package/dist/cjs/constants/chroma-settings.d.ts +2 -0
  5. package/dist/cjs/constants/chroma-settings.js +105 -0
  6. package/dist/cjs/constants/default-swatch.d.ts +109 -0
  7. package/dist/cjs/constants/default-swatch.js +112 -0
  8. package/dist/cjs/constants/interaction-settings.d.ts +8 -0
  9. package/dist/cjs/constants/interaction-settings.js +19 -0
  10. package/dist/cjs/constants/logo-lightness.d.ts +1 -0
  11. package/dist/cjs/constants/logo-lightness.js +4 -0
  12. package/dist/cjs/constants/promo-hue-shift.d.ts +3 -0
  13. package/dist/cjs/constants/promo-hue-shift.js +14 -0
  14. package/dist/cjs/constants/warning-hue-patch.d.ts +3 -0
  15. package/dist/cjs/constants/warning-hue-patch.js +25 -0
  16. package/dist/cjs/get-base-tokens.d.ts +19 -0
  17. package/dist/cjs/get-base-tokens.js +199 -0
  18. package/dist/cjs/get-colors.d.ts +19 -0
  19. package/dist/cjs/get-colors.js +25 -0
  20. package/dist/cjs/get-default-tokens.d.ts +645 -0
  21. package/dist/cjs/get-default-tokens.js +996 -0
  22. package/dist/cjs/helpers/get-interactions.d.ts +7 -0
  23. package/dist/cjs/helpers/get-interactions.js +61 -0
  24. package/dist/cjs/helpers/get-logo.d.ts +6 -0
  25. package/dist/cjs/helpers/get-logo.js +32 -0
  26. package/dist/cjs/helpers/get-palette.d.ts +76 -0
  27. package/dist/cjs/helpers/get-palette.js +287 -0
  28. package/dist/cjs/helpers/get-promo.d.ts +12 -0
  29. package/dist/cjs/helpers/get-promo.js +56 -0
  30. package/dist/cjs/types/base-tokens.d.ts +125 -0
  31. package/dist/cjs/types/base-tokens.js +2 -0
  32. package/dist/cjs/types/generator-tokens.d.ts +43 -0
  33. package/dist/cjs/types/generator-tokens.js +2 -0
  34. package/dist/cjs/utils/format-variable.d.ts +2 -0
  35. package/dist/cjs/utils/format-variable.js +15 -0
  36. package/dist/colors.default-dark.js +325 -0
  37. package/dist/colors.default-light.js +326 -0
  38. package/dist/colors.js +319 -0
  39. package/dist/colors.less +319 -0
  40. package/dist/colors.scss +319 -0
  41. package/dist/esm/constants/abney-correction.d.ts +2 -0
  42. package/dist/esm/constants/abney-correction.js +1102 -0
  43. package/dist/esm/constants/chroma-settings.d.ts +2 -0
  44. package/dist/esm/constants/chroma-settings.js +102 -0
  45. package/dist/esm/constants/default-swatch.d.ts +109 -0
  46. package/dist/esm/constants/default-swatch.js +109 -0
  47. package/dist/esm/constants/interaction-settings.d.ts +8 -0
  48. package/dist/esm/constants/interaction-settings.js +8 -0
  49. package/dist/esm/constants/logo-lightness.d.ts +1 -0
  50. package/dist/esm/constants/logo-lightness.js +1 -0
  51. package/dist/esm/constants/promo-hue-shift.d.ts +3 -0
  52. package/dist/esm/constants/promo-hue-shift.js +11 -0
  53. package/dist/esm/constants/warning-hue-patch.d.ts +3 -0
  54. package/dist/esm/constants/warning-hue-patch.js +22 -0
  55. package/dist/esm/get-base-tokens.d.ts +19 -0
  56. package/dist/esm/get-base-tokens.js +147 -0
  57. package/dist/esm/get-colors.d.ts +19 -0
  58. package/dist/esm/get-colors.js +21 -0
  59. package/dist/esm/get-default-tokens.d.ts +645 -0
  60. package/dist/esm/get-default-tokens.js +992 -0
  61. package/dist/esm/helpers/get-interactions.d.ts +7 -0
  62. package/dist/esm/helpers/get-interactions.js +49 -0
  63. package/dist/esm/helpers/get-logo.d.ts +6 -0
  64. package/dist/esm/helpers/get-logo.js +28 -0
  65. package/dist/esm/helpers/get-palette.d.ts +76 -0
  66. package/dist/esm/helpers/get-palette.js +232 -0
  67. package/dist/esm/helpers/get-promo.d.ts +12 -0
  68. package/dist/esm/helpers/get-promo.js +51 -0
  69. package/dist/esm/types/base-tokens.d.ts +125 -0
  70. package/dist/esm/types/base-tokens.js +1 -0
  71. package/dist/esm/types/generator-tokens.d.ts +43 -0
  72. package/dist/esm/types/generator-tokens.js +1 -0
  73. package/dist/esm/utils/format-variable.d.ts +2 -0
  74. package/dist/esm/utils/format-variable.js +10 -0
  75. package/dist/tokens/brand-blue-deep_accent-brand.css +643 -0
  76. package/dist/tokens/brand-blue-deep_accent-gray.css +643 -0
  77. package/dist/tokens/brand-blue_accent-brand.css +643 -0
  78. package/dist/tokens/brand-blue_accent-gray.css +643 -0
  79. package/dist/tokens/brand-green_accent-brand.css +643 -0
  80. package/dist/tokens/brand-green_accent-gray.css +643 -0
  81. package/dist/tokens/brand-mint_accent-brand.css +643 -0
  82. package/dist/tokens/brand-mint_accent-gray.css +643 -0
  83. package/dist/tokens/brand-orange_accent-gray.css +643 -0
  84. package/dist/tokens/brand-purple_accent-brand.css +643 -0
  85. package/dist/tokens/brand-purple_accent-gray.css +643 -0
  86. package/dist/tokens/brand-red_accent-gray.css +643 -0
  87. package/dist/tokens/brand-violet_accent-brand.css +643 -0
  88. package/dist/tokens/brand-violet_accent-gray.css +643 -0
  89. package/dist/tokens-js/brand-blue-deep_accent-brand.js +644 -0
  90. package/dist/tokens-js/brand-blue-deep_accent-gray.js +644 -0
  91. package/dist/tokens-js/brand-blue_accent-brand.js +644 -0
  92. package/dist/tokens-js/brand-blue_accent-gray.js +644 -0
  93. package/dist/tokens-js/brand-green_accent-brand.js +644 -0
  94. package/dist/tokens-js/brand-green_accent-gray.js +644 -0
  95. package/dist/tokens-js/brand-mint_accent-brand.js +644 -0
  96. package/dist/tokens-js/brand-mint_accent-gray.js +644 -0
  97. package/dist/tokens-js/brand-orange_accent-gray.js +644 -0
  98. package/dist/tokens-js/brand-purple_accent-brand.js +644 -0
  99. package/dist/tokens-js/brand-purple_accent-gray.js +644 -0
  100. package/dist/tokens-js/brand-red_accent-gray.js +644 -0
  101. package/dist/tokens-js/brand-violet_accent-brand.js +644 -0
  102. package/dist/tokens-js/brand-violet_accent-gray.js +644 -0
  103. package/dist/tokens-mobile/brand-blue-deep_accent-brand.json +718 -0
  104. package/dist/tokens-mobile/brand-blue-deep_accent-gray.json +718 -0
  105. package/dist/tokens-mobile/brand-blue_accent-brand.json +718 -0
  106. package/dist/tokens-mobile/brand-blue_accent-gray.json +718 -0
  107. package/dist/tokens-mobile/brand-green_accent-brand.json +718 -0
  108. package/dist/tokens-mobile/brand-green_accent-gray.json +718 -0
  109. package/dist/tokens-mobile/brand-mint_accent-brand.json +718 -0
  110. package/dist/tokens-mobile/brand-mint_accent-gray.json +718 -0
  111. package/dist/tokens-mobile/brand-orange_accent-gray.json +718 -0
  112. package/dist/tokens-mobile/brand-purple_accent-brand.json +718 -0
  113. package/dist/tokens-mobile/brand-purple_accent-gray.json +718 -0
  114. package/dist/tokens-mobile/brand-red_accent-gray.json +718 -0
  115. package/dist/tokens-mobile/brand-violet_accent-brand.json +718 -0
  116. package/dist/tokens-mobile/brand-violet_accent-gray.json +718 -0
  117. package/package.json +15 -7
  118. package/CHANGELOG.md +0 -100
  119. package/colors.css +0 -160
  120. package/colors.less +0 -158
  121. package/dist/cjs/colors.d.ts +0 -161
  122. package/dist/cjs/colors.js +0 -163
  123. package/dist/esm/colors.d.ts +0 -161
  124. package/dist/esm/colors.js +0 -160
package/README.md CHANGED
@@ -1,115 +1,210 @@
1
1
  # Библиотека цветов
2
2
 
3
- В этой библиотеке собраны основные цвета, используемые в интерфейсах Контура. Вся палитра собрана [тут](https://www.figma.com/file/XuiIin3JAOEcHHPihtthOJ/%E2%9A%A1%EF%B8%8F-Kontur-Colors?node-id=0%3A1&t=pL38Ju5ZOo3VC6vt-0).
3
+ NPM-пакет для доступа к цветам из общей Figma-библиотеки [Kontur.Colors](https://www.figma.com/file/XuiIin3JAOEcHHPihtthOJ/%E2%9A%A1%EF%B8%8F-Kontur-Colors?node-id=0%3A1&t=pL38Ju5ZOo3VC6vt-0)
4
4
 
5
- Установить библиотеку можно командой:
5
+ ## Установка
6
6
 
7
7
  ```bash
8
8
  npm i @skbkontur/colors
9
9
  ```
10
10
 
11
- Сейчас в библиотеке представлены расширения .less, .css, .ts (по запросу могут быть новые расширения)
11
+ ## Использование
12
12
 
13
- Названия цветов - это camelCase варианция названия из фигмы.
14
- Например, `Blue Dark / 30` из фигмы в библиотеке можно найти как:
15
- - `@blueDark30` для colors.less
16
- - `--blueDark30` для colors.css
17
- - `KonturColors.blueDark30` для colors.ts
13
+ - JS/TS токены содержатся в объекте `KonturColors.color.name`
14
+ - В CSS в виде глобальных переменных`--kontur-color-name` в `:root { ... }`
15
+ - В препроцессорах Less `@color-name` и SCSS `$color-name`
18
16
 
19
- Пример использования colors.less
17
+ #### JS/TS
20
18
 
21
- ```less
22
- // styles.less
19
+ ```js static
20
+ import { KonturColors } from '@skbkontur/colors';
23
21
 
24
- @import '@skbkontur/colors/colors.less';
22
+ const text = `<div style="color: ${KonturColors.blueDark90}">Цвет blueDark90</div>`;
23
+ ```
25
24
 
26
- .class {
27
- color: @blue10;
28
- }
25
+ #### React
26
+
27
+ ```jsx static
28
+ import { KonturColors } from '@skbkontur/colors';
29
+
30
+ const Component = () => {
31
+ return <div style={{ color: KonturColors.blueDark90 }}>Цвет blueDark90</div>;
32
+ };
29
33
  ```
30
34
 
31
- Пример использования colors.css
35
+ #### CSS
32
36
 
33
37
  ```css
34
- // styles.css
35
-
36
38
  @import '@skbkontur/colors/colors.css';
37
39
 
38
40
  .class {
39
- color: var(--blue10);
41
+ color: var(--blue-dark-90);
40
42
  }
41
43
  ```
42
44
 
43
- Пример использования colors.ts
44
-
45
- ```ts
46
- // styles.ts
45
+ #### SCSS
47
46
 
48
- import { KonturColors } from '@skbkontur/colors';
47
+ ```scss
48
+ @import '@skbkontur/colors/colors.scss';
49
49
 
50
- someRenderMethod = () => {
51
- return (
52
- <div style={{color: KonturColors.blue10}}>some content</div>
53
- )
50
+ .class {
51
+ color: $blue-dark-90;
54
52
  }
55
53
  ```
56
54
 
55
+ #### Less
57
56
 
58
- ## Как работает
59
- Все цвета описаны в файле `src/colors.ts`.
60
- В файле `generate.ts` живёт сам код генерации файлов, а запускается генерация командой `npm run build`
57
+ ```less
58
+ @import '@skbkontur/colors/colors.less';
59
+
60
+ .class {
61
+ color: @blue-dark-90;
62
+ }
63
+ ```
61
64
 
62
65
  ## Палитра
63
66
 
64
- ```
67
+ ```jsx harmony
65
68
  import { KonturColors } from '@skbkontur/colors';
69
+ import {
70
+ Toast,
71
+ DropdownMenu,
72
+ MenuHeader,
73
+ MenuItem,
74
+ ThemeContext,
75
+ ThemeFactory,
76
+ THEME_2022_UPDATE_2024,
77
+ } from '@skbkontur/react-ui';
78
+
79
+ import { css } from '@skbkontur/react-ui/lib/theming/Emotion';
66
80
 
67
81
  const styles = {
68
- storyWrapper: {
69
- display: 'flex',
70
- flexWrap: 'wrap',
71
- justifyContent: 'space-between',
72
- fontSize: '12px',
73
- },
74
- colorBlock: {
75
- width: '22%',
76
- alignItems: 'center',
77
- margin: '10px',
78
- },
79
- colorTile: {
80
- width: '100%',
81
- height: '30px',
82
- marginRight: '10px',
83
- border: '1px #000 solid',
84
- },
85
- wordBreak: {
86
- wordBreak: 'break-word',
87
- },
88
- title: {
89
- display: 'flex',
90
- justifyContent: 'space-between',
91
- },
82
+ colors: css`
83
+ display: grid;
84
+ grid-template-columns: repeat(3, minmax(0, 1fr));
85
+ gap: 24px;
86
+ `,
87
+ colorGroup: css`
88
+ break-inside: avoid;
89
+ margin-bottom: 64px;
90
+ `,
91
+ colorBlock: css`
92
+ display: flex;
93
+ align-items: center;
94
+ gap: 10px;
95
+ width: 100%;
96
+ border: none;
97
+ text-align: left;
98
+ background: none;
99
+ cursor: pointer;
100
+ padding: 8px;
101
+ border-radius: 8px;
102
+ transition: 0.1s ease;
103
+
104
+ &:hover {
105
+ background: rgba(0, 0, 0, 0.06);
106
+ }
107
+
108
+ &:active {
109
+ background: rgba(0, 0, 0, 0.1);
110
+ }
111
+ `,
112
+ colorTile: css`
113
+ display: block;
114
+ height: 32px;
115
+ width: 32px;
116
+ border: 1px solid rgba(0, 0, 0, 0.08);
117
+ border-radius: 8px;
118
+ flex-shrink: 0;
119
+ `,
120
+ groupTitle: css`
121
+ display: block;
122
+ font-size: 20px;
123
+ font-weight: 600;
124
+ margin: 0 8px 12px;
125
+ `,
126
+ title: css`
127
+ display: block;
128
+ padding: 1px 0 0 8px;
129
+ `,
130
+ colorName: css`
131
+ display: block;
132
+ font-size: 14px;
133
+ line-height: 1.2;
134
+ `,
135
+ colorValue: css`
136
+ display: block;
137
+ fontSize: 12px;
138
+ color: #8b8b8b;
139
+ }`,
92
140
  };
93
141
 
94
- <div style={styles.storyWrapper}>
95
- {Object.keys(KonturColors).map((colorName) => {
96
- const colorValue = KonturColors[colorName];
97
- return (
98
- <>
99
- <div style={styles.colorBlock}>
100
- <div
101
- style={{
102
- ...styles.colorTile,
103
- backgroundColor: colorValue,
104
- }}
105
- />
106
- <div style={styles.title}>
107
- <div style={styles.wordBreak}>{colorName}</div>
108
- <div style={styles.wordBreak}>{colorValue}</div>
109
- </div>
142
+ const colorGroups = Object.entries(KonturColors).reduce((acc, [colorKey, colorValue]) => {
143
+ const firstWord = ['greenMint', 'blueDark'].find((color) => colorKey.match(color)) || colorKey.match(/^[a-z]+/)[0];
144
+
145
+ acc[firstWord] = { ...acc[firstWord], [colorKey]: colorValue };
146
+
147
+ return acc;
148
+ }, {});
149
+
150
+ const getColors = (color) => {
151
+ const colorDashCase = color
152
+ .replace(/[A-Z]/g, (m) => '-' + m.toLowerCase())
153
+ .replace(/\d/, (m) => `-${m}`)
154
+ .replace('f-f-f', 'fff');
155
+
156
+ return {
157
+ 'JavaScript / TypeScript': `KonturColors.${color}`,
158
+ CSS: `var(--kontur-${colorDashCase})`,
159
+ SCSS: `$${colorDashCase}`,
160
+ Less: `@${colorDashCase}`,
161
+ };
162
+ };
163
+
164
+ const copyColor = (color) => {
165
+ navigator.clipboard.writeText(color);
166
+ Toast.push('Цвет скопирован', null, 1000);
167
+ };
168
+
169
+ <div className={styles.colors}>
170
+ <ThemeContext.Provider value={THEME_2022_UPDATE_2024}>
171
+ {Object.entries(colorGroups).map(([group, colors]) => {
172
+ return (
173
+ <div className={styles.colorGroup}>
174
+ <div className={styles.groupTitle}>{group}</div>
175
+ {Object.keys(colors).map((colorName) => {
176
+ const colorValue = KonturColors[colorName];
177
+ const colorTile = (
178
+ <div className={styles.colorBlock}>
179
+ <span className={styles.colorTile} style={{ backgroundColor: colorValue }} />
180
+ <span>
181
+ <span className={styles.colorName}>{colorName}</span>
182
+ <span className={styles.colorValue}>{colorValue}</span>
183
+ </span>
184
+ </div>
185
+ );
186
+ return (
187
+ <div>
188
+ <DropdownMenu caption={colorTile} width="300">
189
+ <MenuHeader>Скопировать переменную</MenuHeader>
190
+ {Object.entries(getColors(colorName)).map(([lang, color]) => (
191
+ <MenuItem onClick={() => copyColor(color)} comment={lang}>
192
+ <div style={{ minWidth: 270 }}>{color}</div>
193
+ </MenuItem>
194
+ ))}
195
+ </DropdownMenu>
196
+ </div>
197
+ );
198
+ })}
110
199
  </div>
111
- </>
112
- );
113
- })}
114
- </div>
200
+ );
201
+ })}
202
+ </ThemeContext.Provider>
203
+ </div>;
115
204
  ```
205
+
206
+ ## Разработка
207
+
208
+ - Токены выгружаются в формате `camelCase`
209
+ - `src/colors.ts` — файл с токенами
210
+ - `npm run build` — сборка пакета в `/dist`
@@ -0,0 +1,2 @@
1
+ import type { GeneratorColorAbneyCorrection } from '../types/generator-tokens';
2
+ export declare const ABNEY_CORRECTION: GeneratorColorAbneyCorrection;