Skip to content

Commit 9dad233

Browse files
committed
chore: refactor
1 parent b375259 commit 9dad233

File tree

5 files changed

+64
-25
lines changed

5 files changed

+64
-25
lines changed

apps/docs/src/app/components/anchors/anchors.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ export class DocsAnchorsComponent implements OnDestroy, OnInit {
157157
.pipe(debounceTime(this.debounceTime), takeUntilDestroyed(this.destroyRef))
158158
.subscribe(this.onScroll);
159159
}
160-
161-
this.ref.detectChanges();
162160
}
163161

164162
/* TODO Техдолг: при изменении ширины экрана должен переопределяться параметр top

apps/docs/src/app/components/design-tokens-viewers/design-tokens-viewer.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ import { DocsLocale } from 'src/app/constants/locale';
77
import { DocsStructureTokensTab } from '../../structure';
88
import { DocsComponentViewerComponent } from '../component-viewer/component-viewer.component';
99
import { DocsRegisterHeaderDirective } from '../register-header/register-header.directive';
10-
import { docsData as borderRadius } from './data/border-radius';
11-
import { docsData as colors } from './data/colors';
12-
import { docsData as palette } from './data/palette';
13-
import { docsData as shadows } from './data/shadows';
14-
import { docsData as sizes } from './data/sizes';
1510

1611
@Component({
1712
standalone: true,
@@ -60,46 +55,41 @@ export class DocsDesignTokensViewer extends DocsComponentViewerComponent {
6055
super();
6156
}
6257

63-
readonly links: Array<{ title: Record<DocsLocale, string>; value: string; data: any }> = [
58+
readonly links: Array<{ title: Record<DocsLocale, string>; value: string }> = [
6459
{
6560
title: {
6661
ru: 'Цвета',
6762
en: 'Colors'
6863
},
69-
value: DocsStructureTokensTab.Colors,
70-
data: colors
64+
value: DocsStructureTokensTab.Colors
7165
},
7266
{
7367
title: {
7468
ru: 'Тени',
7569
en: 'Shadows'
7670
},
77-
value: DocsStructureTokensTab.Shadows,
78-
data: shadows
71+
value: DocsStructureTokensTab.Shadows
7972
},
8073
{
8174
title: {
8275
ru: 'Скругления',
8376
en: 'Border radius'
8477
},
85-
value: DocsStructureTokensTab.BorderRadius,
86-
data: borderRadius
78+
value: DocsStructureTokensTab.BorderRadius
8779
},
8880
{
8981
title: {
9082
ru: 'Размеры',
9183
en: 'Sizes'
9284
},
93-
value: DocsStructureTokensTab.Sizes,
94-
data: sizes
85+
value: DocsStructureTokensTab.Sizes
9586
},
9687
{
9788
title: {
9889
ru: 'Инженерная палитра',
9990
en: 'Engineer palette'
10091
},
101-
value: DocsStructureTokensTab.Palette,
102-
data: palette
92+
value: DocsStructureTokensTab.Palette
10393
}
10494
];
10595
}

apps/docs/src/app/components/design-tokens-viewers/tokens-overview.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ export interface DocsTokensInfo {
2929
tokens?: { token: string; value: string }[];
3030
}
3131

32+
export interface DocsTokensSectionInfoRaw {
33+
type: string;
34+
tokens: string[];
35+
}
36+
37+
export interface DocsTokensInfoRaw {
38+
type: string;
39+
sections?: DocsTokensSectionInfoRaw[];
40+
tokens?: string[];
41+
}
42+
3243
@Component({
3344
standalone: true,
3445
selector: 'docs-tokens-table',
@@ -179,7 +190,7 @@ export class DocsTokensOverview extends DocsLocaleState implements AfterViewInit
179190
protected readonly platformId = inject(PLATFORM_ID);
180191
protected readonly activatedRoute = inject(ActivatedRoute);
181192

182-
protected tokensInfo = signal<DocsTokensInfo[]>([]);
193+
protected readonly tokensInfo = signal<DocsTokensInfo[]>([]);
183194
protected readonly activatedTab = toSignal(
184195
this.activatedRoute.url.pipe(
185196
map(([{ path: id }]: UrlSegment[]) => <DocsStructureTokensTab>id),
@@ -203,7 +214,7 @@ export class DocsTokensOverview extends DocsLocaleState implements AfterViewInit
203214
}
204215
};
205216

206-
protected tokenDataMap: Record<DocsStructureTokensTab, unknown> = {
217+
protected tokenDataMap: Record<DocsStructureTokensTab, DocsTokensInfoRaw[]> = {
207218
[DocsStructureTokensTab.Colors]: colors,
208219
[DocsStructureTokensTab.Shadows]: shadows,
209220
[DocsStructureTokensTab.BorderRadius]: borderRadius,
@@ -229,10 +240,7 @@ export class DocsTokensOverview extends DocsLocaleState implements AfterViewInit
229240

230241
const getTokenValue = (token: string) => styles.getPropertyValue(token);
231242

232-
const resolvedData = this.tokenDataMap[this.activatedTab()] as any;
233-
234-
// ts-ignore
235-
return resolvedData.map((section) => {
243+
return this.tokenDataMap[this.activatedTab()].map((section) => {
236244
if (section.tokens && section.tokens.length > 0) {
237245
return {
238246
type: section.type,

tools/tokens/docs/formats.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,38 @@
1-
const { simpleMapColors } = require('./templates');
1+
const { simpleMapColors, outputTypographyTable, mapTypography } = require('./templates');
22
const { updateObject, sortSections } = require('./utils');
33
const { NO_HEADER } = require('./config');
44

55
module.exports = (StyleDictionary) => {
6+
StyleDictionary.registerFormat({
7+
name: 'docs/typography',
8+
formatter: function ({ dictionary }) {
9+
const filtered = [];
10+
11+
for (const token of dictionary.allTokens) {
12+
const isTypographyTypeMissing =
13+
filtered.findIndex(({ attributes }) => attributes.type === token.attributes.type) === -1;
14+
15+
if (isTypographyTypeMissing && token.attributes.item === 'font-size') {
16+
filtered.push(token);
17+
}
18+
}
19+
20+
// Sort by font-size
21+
filtered.sort((a, b) => {
22+
const aFontSize = parseInt(a.value);
23+
const bFontSize = parseInt(b.value);
24+
25+
if (aFontSize < bFontSize) return 1;
26+
if (aFontSize > bFontSize) return -1;
27+
28+
return 0;
29+
});
30+
const mappedTokens = filtered.map(mapTypography);
31+
32+
return outputTypographyTable(mappedTokens);
33+
}
34+
});
35+
636
StyleDictionary.registerFormat({
737
name: 'docs/colors-ts',
838
formatter: function ({ dictionary }) {

tools/tokens/docs/templates.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
const { LINE_SEP, TYPOGRAPHY_TABLE_ID } = require('./config');
22
const { capitalize } = require('./utils');
33

4+
const varTypographyTemplate = (token) => `<code docsCodeSnippet>kbq-${token.attributes.type}</code>`;
5+
6+
const simpleExampleTypographyTemplate = (typographyType) => {
7+
const typographyTypeOutput = capitalize(typographyType, { separator: '-' });
8+
9+
return `<div class="kbq-${typographyType}">${typographyTypeOutput}</div>`;
10+
};
11+
412
const simpleMapToken = ({ name }) => `--${name}`;
513

614
const simpleMapColors = ([type, tokens]) => {
@@ -23,6 +31,11 @@ module.exports = {
2331
simpleMapToken,
2432
simpleMapColors,
2533

34+
mapTypography: (token) => ({
35+
varSnippet: varTypographyTemplate(token),
36+
example: simpleExampleTypographyTemplate(token.attributes.type)
37+
}),
38+
2639
outputTypographyTable: (tokens) => {
2740
return `<table id="${TYPOGRAPHY_TABLE_ID}">
2841
<thead>

0 commit comments

Comments
 (0)