@uh-design-system/component-library 0.0.1-alpha.9 → 0.1.0
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/dist/cjs/app-globals-3a1e7e63.js +7 -0
- package/dist/cjs/app-globals-3a1e7e63.js.map +1 -0
- package/dist/cjs/ds-icon.cjs.entry.js +522 -0
- package/dist/cjs/ds-icon.cjs.entry.js.map +1 -0
- package/dist/cjs/index-eaf5876c.js +1162 -0
- package/dist/cjs/index-eaf5876c.js.map +1 -0
- package/dist/cjs/index.cjs.js +7 -0
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/cjs/loader.cjs.js +4 -3
- package/dist/cjs/loader.cjs.js.map +1 -1
- package/dist/cjs/{component-library.cjs.js → uh-component-library.cjs.js} +7 -6
- package/dist/cjs/uh-component-library.cjs.js.map +1 -0
- package/dist/collection/collection-manifest.json +3 -1
- package/dist/collection/components/00-foundations/borders/borders.stories.js +20 -0
- package/dist/collection/components/00-foundations/borders/borders.stories.js.map +1 -0
- package/dist/collection/components/00-foundations/colours/colours.stories.js +21 -0
- package/dist/collection/components/00-foundations/colours/colours.stories.js.map +1 -0
- package/dist/collection/components/00-foundations/icons/iconList.js +296 -0
- package/dist/collection/components/00-foundations/icons/iconList.js.map +1 -0
- package/dist/collection/components/00-foundations/icons/icons.stories.js +43 -0
- package/dist/collection/components/00-foundations/icons/icons.stories.js.map +1 -0
- package/dist/collection/components/00-foundations/spacing/spacing.stories.js +21 -0
- package/dist/collection/components/00-foundations/spacing/spacing.stories.js.map +1 -0
- package/dist/collection/components/00-foundations/typography/headings.stories.js +23 -0
- package/dist/collection/components/00-foundations/typography/headings.stories.js.map +1 -0
- package/dist/collection/components/00-foundations/typography/text.stories.js +17 -0
- package/dist/collection/components/00-foundations/typography/text.stories.js.map +1 -0
- package/dist/collection/components/00-foundations/typography/typography.stories.js +21 -0
- package/dist/collection/components/00-foundations/typography/typography.stories.js.map +1 -0
- package/dist/collection/components/01-base-components/ds-icon/ds-icon.css +3 -0
- package/dist/collection/components/01-base-components/ds-icon/ds-icon.js +184 -0
- package/dist/collection/components/01-base-components/ds-icon/ds-icon.js.map +1 -0
- package/dist/collection/components/01-base-components/ds-icon/ds-icon.stories.js +56 -0
- package/dist/collection/components/01-base-components/ds-icon/ds-icon.stories.js.map +1 -0
- package/dist/collection/index.js +11 -0
- package/dist/collection/utils/borders/borderUtils.js +43 -0
- package/dist/collection/utils/borders/borderUtils.js.map +1 -0
- package/dist/collection/utils/colours/colourUtils.js +75 -0
- package/dist/collection/utils/colours/colourUtils.js.map +1 -0
- package/dist/collection/utils/spacing/spacingUtils.js +67 -0
- package/dist/collection/utils/spacing/spacingUtils.js.map +1 -0
- package/dist/collection/utils/tests/testUtils.js +20 -0
- package/dist/collection/utils/tests/testUtils.js.map +1 -0
- package/dist/collection/utils/typography/typographyUtils.js +88 -0
- package/dist/collection/utils/typography/typographyUtils.js.map +1 -0
- package/dist/components/ds-icon.d.ts +11 -0
- package/dist/components/ds-icon.js +545 -0
- package/dist/components/ds-icon.js.map +1 -0
- package/dist/components/index.js +4 -79
- package/dist/components/index.js.map +1 -1
- package/dist/components/p-dcfb6eb2.js +996 -0
- package/dist/components/p-dcfb6eb2.js.map +1 -0
- package/dist/esm/app-globals-0f993ce5.js +5 -0
- package/dist/esm/app-globals-0f993ce5.js.map +1 -0
- package/dist/esm/ds-icon.entry.js +518 -0
- package/dist/esm/ds-icon.entry.js.map +1 -0
- package/dist/esm/index-1586ada2.js +1135 -0
- package/dist/esm/index-1586ada2.js.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/loader.js +4 -3
- package/dist/esm/loader.js.map +1 -1
- package/dist/esm/uh-component-library.js +22 -0
- package/dist/esm/uh-component-library.js.map +1 -0
- package/dist/types/components/00-foundations/borders/borders.stories.d.ts +6 -0
- package/dist/types/components/00-foundations/colours/colours.stories.d.ts +6 -0
- package/dist/types/components/00-foundations/icons/iconList.d.ts +5 -0
- package/dist/types/components/00-foundations/icons/icons.stories.d.ts +13 -0
- package/dist/types/components/00-foundations/spacing/spacing.stories.d.ts +6 -0
- package/dist/types/components/00-foundations/typography/headings.stories.d.ts +17 -0
- package/dist/types/components/00-foundations/typography/text.stories.d.ts +11 -0
- package/dist/types/components/00-foundations/typography/typography.stories.d.ts +6 -0
- package/dist/types/components/01-base-components/ds-icon/ds-icon.d.ts +14 -0
- package/dist/types/components/01-base-components/ds-icon/ds-icon.stories.d.ts +7 -0
- package/dist/types/components.d.ts +25 -0
- package/dist/types/utils/borders/borderUtils.d.ts +3 -0
- package/dist/types/utils/colours/colourUtils.d.ts +18 -0
- package/dist/types/utils/spacing/spacingUtils.d.ts +12 -0
- package/dist/types/utils/tests/testUtils.d.ts +104 -0
- package/dist/types/utils/typography/typographyUtils.d.ts +16 -0
- package/dist/uh-component-library/index.esm.js +2 -0
- package/dist/uh-component-library/index.esm.js.map +1 -0
- package/dist/uh-component-library/p-74d73de3.js +3 -0
- package/dist/uh-component-library/p-74d73de3.js.map +1 -0
- package/dist/uh-component-library/p-c7cd80a5.entry.js +2 -0
- package/dist/uh-component-library/p-c7cd80a5.entry.js.map +1 -0
- package/dist/uh-component-library/p-e1255160.js +2 -0
- package/dist/uh-component-library/p-e1255160.js.map +1 -0
- package/dist/uh-component-library/uh-component-library.esm.js +2 -0
- package/dist/uh-component-library/uh-component-library.esm.js.map +1 -0
- package/docs/DEPLOYMENT.md +1 -2
- package/docs/PUBLISHING.md +15 -0
- package/docs/USAGE.md +30 -0
- package/loader/package.json +1 -1
- package/package.json +2 -2
- package/react-wrapper/components.ts +24 -0
- package/dist/cjs/app-globals-67d97547.js +0 -506
- package/dist/cjs/app-globals-67d97547.js.map +0 -1
- package/dist/cjs/component-library.cjs.js.map +0 -1
- package/dist/component-library/component-library.esm.js +0 -2
- package/dist/component-library/component-library.esm.js.map +0 -1
- package/dist/component-library/index.esm.js +0 -2
- package/dist/component-library/index.esm.js.map +0 -1
- package/dist/component-library/p-a49d7588.js +0 -3
- package/dist/component-library/p-a49d7588.js.map +0 -1
- package/dist/esm/app-globals-cde8e66f.js +0 -481
- package/dist/esm/app-globals-cde8e66f.js.map +0 -1
- package/dist/esm/component-library.js +0 -21
- package/dist/esm/component-library.js.map +0 -1
- /package/dist/{index.js.map → collection/index.js.map} +0 -0
- /package/dist/{utils → collection/utils}/utils.js +0 -0
- /package/dist/{utils → collection/utils}/utils.js.map +0 -0
- /package/dist/types/{Users/teemuparssinen/hy/uh-design-system/uh-component-library/.stencil/index.d.ts → index.d.ts} +0 -0
- /package/dist/types/{Users/teemuparssinen/hy/uh-design-system/uh-component-library/.stencil/utils → utils}/utils.d.ts +0 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { Fragment, h } from "@stencil/core";
|
|
2
|
+
import { icons } from "../../../components/00-foundations/icons/iconList";
|
|
3
|
+
export class DsIcon {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.name = undefined;
|
|
6
|
+
this.colour = undefined;
|
|
7
|
+
this.size = undefined;
|
|
8
|
+
this.title = 'Icon';
|
|
9
|
+
this.role = 'img';
|
|
10
|
+
this.hidden = true;
|
|
11
|
+
this.message = '';
|
|
12
|
+
}
|
|
13
|
+
// get the icon from the icon list
|
|
14
|
+
getIcon() {
|
|
15
|
+
const selectedIcon = icons.find(icon => icon.name === this.name);
|
|
16
|
+
if (!selectedIcon) {
|
|
17
|
+
console.warn(`Icon with name "${this.name}" not found.`);
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
const svgElement = this.parseSvg(selectedIcon.component);
|
|
21
|
+
if (svgElement) {
|
|
22
|
+
this.setIconAttributes(svgElement);
|
|
23
|
+
}
|
|
24
|
+
return svgElement ? svgElement.outerHTML : '';
|
|
25
|
+
}
|
|
26
|
+
// parse the svg string to an svg element
|
|
27
|
+
parseSvg(svgString) {
|
|
28
|
+
const parser = new DOMParser();
|
|
29
|
+
const svgDoc = parser.parseFromString(svgString, 'image/svg+xml');
|
|
30
|
+
return svgDoc.querySelector('svg');
|
|
31
|
+
}
|
|
32
|
+
// get the colour of the icon
|
|
33
|
+
getIconColour() {
|
|
34
|
+
const cssVariable = `--colour-${this.colour}`;
|
|
35
|
+
return getComputedStyle(document.documentElement).getPropertyValue(cssVariable) || this.colour;
|
|
36
|
+
}
|
|
37
|
+
// set the attributes of the icon
|
|
38
|
+
setIconAttributes(svgElement) {
|
|
39
|
+
const size = this.size || '1.5rem';
|
|
40
|
+
const colour = this.getIconColour() || 'currentColor';
|
|
41
|
+
const role = this.role || 'img';
|
|
42
|
+
const title = this.title || '';
|
|
43
|
+
svgElement.setAttribute('style', `fill: ${colour}; width: ${size}; height: ${size};`);
|
|
44
|
+
svgElement.setAttribute('role', role);
|
|
45
|
+
// if title is available, insert it into the svg element
|
|
46
|
+
const titleText = title || 'Icon';
|
|
47
|
+
const titleElement = document.createElementNS('http://www.w3.org/2000/svg', 'title');
|
|
48
|
+
titleElement.textContent = titleText;
|
|
49
|
+
svgElement.insertBefore(titleElement, svgElement.firstChild);
|
|
50
|
+
if (!title) {
|
|
51
|
+
svgElement.setAttribute('aria-label', 'Icon');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
render() {
|
|
55
|
+
return (h(Fragment, { key: '8a2414880389617aa1f009bc7972201ee877ab65' }, h("span", { key: 'e7441e46ef7473d1e7d1a40b70eacc843ee742ea', class: "icon-container", innerHTML: this.getIcon(), "aria-hidden": this.hidden ? 'true' : 'false' })));
|
|
56
|
+
}
|
|
57
|
+
static get is() { return "ds-icon"; }
|
|
58
|
+
static get encapsulation() { return "shadow"; }
|
|
59
|
+
static get originalStyleUrls() {
|
|
60
|
+
return {
|
|
61
|
+
"$": ["ds-icon.css"]
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
static get styleUrls() {
|
|
65
|
+
return {
|
|
66
|
+
"$": ["ds-icon.css"]
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
static get properties() {
|
|
70
|
+
return {
|
|
71
|
+
"name": {
|
|
72
|
+
"type": "string",
|
|
73
|
+
"mutable": false,
|
|
74
|
+
"complexType": {
|
|
75
|
+
"original": "string",
|
|
76
|
+
"resolved": "string",
|
|
77
|
+
"references": {}
|
|
78
|
+
},
|
|
79
|
+
"required": false,
|
|
80
|
+
"optional": false,
|
|
81
|
+
"docs": {
|
|
82
|
+
"tags": [],
|
|
83
|
+
"text": ""
|
|
84
|
+
},
|
|
85
|
+
"attribute": "name",
|
|
86
|
+
"reflect": false
|
|
87
|
+
},
|
|
88
|
+
"colour": {
|
|
89
|
+
"type": "string",
|
|
90
|
+
"mutable": false,
|
|
91
|
+
"complexType": {
|
|
92
|
+
"original": "string",
|
|
93
|
+
"resolved": "string",
|
|
94
|
+
"references": {}
|
|
95
|
+
},
|
|
96
|
+
"required": false,
|
|
97
|
+
"optional": false,
|
|
98
|
+
"docs": {
|
|
99
|
+
"tags": [],
|
|
100
|
+
"text": ""
|
|
101
|
+
},
|
|
102
|
+
"attribute": "colour",
|
|
103
|
+
"reflect": false
|
|
104
|
+
},
|
|
105
|
+
"size": {
|
|
106
|
+
"type": "string",
|
|
107
|
+
"mutable": false,
|
|
108
|
+
"complexType": {
|
|
109
|
+
"original": "string",
|
|
110
|
+
"resolved": "string",
|
|
111
|
+
"references": {}
|
|
112
|
+
},
|
|
113
|
+
"required": false,
|
|
114
|
+
"optional": false,
|
|
115
|
+
"docs": {
|
|
116
|
+
"tags": [],
|
|
117
|
+
"text": ""
|
|
118
|
+
},
|
|
119
|
+
"attribute": "size",
|
|
120
|
+
"reflect": false
|
|
121
|
+
},
|
|
122
|
+
"title": {
|
|
123
|
+
"type": "string",
|
|
124
|
+
"mutable": false,
|
|
125
|
+
"complexType": {
|
|
126
|
+
"original": "string",
|
|
127
|
+
"resolved": "string",
|
|
128
|
+
"references": {}
|
|
129
|
+
},
|
|
130
|
+
"required": false,
|
|
131
|
+
"optional": false,
|
|
132
|
+
"docs": {
|
|
133
|
+
"tags": [],
|
|
134
|
+
"text": ""
|
|
135
|
+
},
|
|
136
|
+
"attribute": "title",
|
|
137
|
+
"reflect": false,
|
|
138
|
+
"defaultValue": "'Icon'"
|
|
139
|
+
},
|
|
140
|
+
"role": {
|
|
141
|
+
"type": "string",
|
|
142
|
+
"mutable": false,
|
|
143
|
+
"complexType": {
|
|
144
|
+
"original": "string",
|
|
145
|
+
"resolved": "string",
|
|
146
|
+
"references": {}
|
|
147
|
+
},
|
|
148
|
+
"required": false,
|
|
149
|
+
"optional": false,
|
|
150
|
+
"docs": {
|
|
151
|
+
"tags": [],
|
|
152
|
+
"text": ""
|
|
153
|
+
},
|
|
154
|
+
"attribute": "role",
|
|
155
|
+
"reflect": false,
|
|
156
|
+
"defaultValue": "'img'"
|
|
157
|
+
},
|
|
158
|
+
"hidden": {
|
|
159
|
+
"type": "boolean",
|
|
160
|
+
"mutable": false,
|
|
161
|
+
"complexType": {
|
|
162
|
+
"original": "boolean",
|
|
163
|
+
"resolved": "boolean",
|
|
164
|
+
"references": {}
|
|
165
|
+
},
|
|
166
|
+
"required": false,
|
|
167
|
+
"optional": false,
|
|
168
|
+
"docs": {
|
|
169
|
+
"tags": [],
|
|
170
|
+
"text": ""
|
|
171
|
+
},
|
|
172
|
+
"attribute": "hidden",
|
|
173
|
+
"reflect": false,
|
|
174
|
+
"defaultValue": "true"
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
static get states() {
|
|
179
|
+
return {
|
|
180
|
+
"message": {}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=ds-icon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ds-icon.js","sourceRoot":"","sources":["../../../../src/components/01-base-components/ds-icon/ds-icon.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,eAAe,CA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IAAI,QAAQ,CAAC;QACnC,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,IAAI,cAAc,CAAC;QACtD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,KAAK,CAAC;QAChC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QAE/B,UAAU,CAAC,YAAY,CAAC,OAAO,EAAE,SAAS,MAAM,YAAY,IAAI,aAAa,IAAI,GAAG,CAAC,CAAC;QACtF,UAAU,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACtC,wDAAwD;QACxD,MAAM,SAAS,GAAG,KAAK,IAAI,MAAM,CAAC;QAClC,MAAM,YAAY,GAAG,QAAQ,CAAC,eAAe,CAAC,4BAA4B,EAAE,OAAO,CAAC,CAAC;QACrF,YAAY,CAAC,WAAW,GAAG,SAAS,CAAC;QACrC,UAAU,CAAC,YAAY,CAAC,YAAY,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;QAE7D,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,UAAU,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED,MAAM;QACJ,OAAO,CACL,EAAC,QAAQ;YACP,6DACE,KAAK,EAAG,gBAAgB,EACxB,SAAS,EAAK,IAAI,CAAC,OAAO,EAAE,iBACZ,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,GAC9C,CACO,CACZ,CAAC;IACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Fragment, Prop, State, h } from '@stencil/core';\nimport { icons } from '../../../components/00-foundations/icons/iconList';\n\n@Component({\n tag: 'ds-icon',\n styleUrl: 'ds-icon.css',\n shadow: true,\n})\nexport class DsIcon {\n @Prop() name: string;\n @Prop() colour: string;\n @Prop() size: string;\n @Prop() title: string = 'Icon';\n @Prop() role: string = 'img';\n @Prop() hidden: boolean = true;\n\n @State() message: string = '';\n\n // get the icon from the icon list\n private getIcon(): string {\n const selectedIcon = icons.find(icon => icon.name === this.name);\n if (!selectedIcon) {\n console.warn(`Icon with name \"${this.name}\" not found.`);\n return '';\n }\n\n const svgElement = this.parseSvg(selectedIcon.component);\n if (svgElement) {\n this.setIconAttributes(svgElement);\n }\n return svgElement ? svgElement.outerHTML : '';\n }\n\n // parse the svg string to an svg element\n private parseSvg(svgString: string): SVGElement | null {\n const parser = new DOMParser();\n const svgDoc = parser.parseFromString(svgString, 'image/svg+xml');\n return svgDoc.querySelector('svg');\n }\n\n // get the colour of the icon\n private getIconColour(): string {\n const cssVariable = `--colour-${this.colour}`;\n return getComputedStyle(document.documentElement).getPropertyValue(cssVariable) || this.colour;\n }\n\n // set the attributes of the icon\n private setIconAttributes(svgElement: SVGElement): void {\n const size = this.size || '1.5rem';\n const colour = this.getIconColour() || 'currentColor';\n const role = this.role || 'img';\n const title = this.title || '';\n\n svgElement.setAttribute('style', `fill: ${colour}; width: ${size}; height: ${size};`);\n svgElement.setAttribute('role', role);\n // if title is available, insert it into the svg element\n const titleText = title || 'Icon';\n const titleElement = document.createElementNS('http://www.w3.org/2000/svg', 'title');\n titleElement.textContent = titleText;\n svgElement.insertBefore(titleElement, svgElement.firstChild);\n\n if (!title) {\n svgElement.setAttribute('aria-label', 'Icon');\n }\n }\n\n render() {\n return (\n <Fragment>\n <span\n class = \"icon-container\"\n innerHTML = { this.getIcon() }\n aria-hidden = { this.hidden ? 'true' : 'false' }\n />\n </Fragment>\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { icons } from "../../../components/00-foundations/icons/iconList";
|
|
2
|
+
import { getColourVariables } from "../../../utils/colours/colourUtils";
|
|
3
|
+
const meta = {
|
|
4
|
+
title: 'Base Components/Icon',
|
|
5
|
+
component: 'ds-icon',
|
|
6
|
+
argTypes: {
|
|
7
|
+
name: {
|
|
8
|
+
options: icons.map(icon => icon.name),
|
|
9
|
+
control: {
|
|
10
|
+
type: 'select',
|
|
11
|
+
},
|
|
12
|
+
name: 'Icon',
|
|
13
|
+
},
|
|
14
|
+
colour: {
|
|
15
|
+
options: getColourVariables().map(colour => colour.name),
|
|
16
|
+
control: {
|
|
17
|
+
type: 'select',
|
|
18
|
+
},
|
|
19
|
+
name: 'Colour',
|
|
20
|
+
},
|
|
21
|
+
size: {
|
|
22
|
+
options: [1, 1.5, 2, 3, 4].map(size => `${size}rem`),
|
|
23
|
+
control: {
|
|
24
|
+
type: 'select',
|
|
25
|
+
},
|
|
26
|
+
name: 'Size',
|
|
27
|
+
},
|
|
28
|
+
title: {
|
|
29
|
+
control: {
|
|
30
|
+
type: 'text',
|
|
31
|
+
},
|
|
32
|
+
name: 'Title',
|
|
33
|
+
},
|
|
34
|
+
hidden: {
|
|
35
|
+
control: {
|
|
36
|
+
type: 'boolean',
|
|
37
|
+
},
|
|
38
|
+
name: 'Hidden (aria-hidden)',
|
|
39
|
+
},
|
|
40
|
+
role: {
|
|
41
|
+
control: {
|
|
42
|
+
type: 'text',
|
|
43
|
+
},
|
|
44
|
+
name: 'Role',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
export default meta;
|
|
49
|
+
export const Default = {};
|
|
50
|
+
Default.args = {
|
|
51
|
+
name: 'archive',
|
|
52
|
+
role: 'img',
|
|
53
|
+
title: 'Icon',
|
|
54
|
+
hidden: true,
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=ds-icon.stories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ds-icon.stories.js","sourceRoot":"","sources":["../../../../src/components/01-base-components/ds-icon/ds-icon.stories.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,m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AAK,EAAE,MAAM;IACb,MAAM,EAAE,IAAI;CACb,CAAC","sourcesContent":["/** src/components/01-base-components/ds-icon/ds-icon.stories.ts */\nimport { Meta, StoryObj } from '@storybook/web-components'\nimport { DsIcon } from './ds-icon';\nimport { icons } from '../../../components/00-foundations/icons/iconList';\nimport { getColourVariables } from '../../../utils/colours/colourUtils';\n\nconst meta: Meta<typeof DsIcon.prototype> = {\n title: 'Base Components/Icon',\n component: 'ds-icon',\n argTypes: {\n name: {\n options: icons.map(icon => icon.name),\n control: {\n type: 'select',\n },\n name: 'Icon',\n },\n colour: {\n options: getColourVariables().map(colour => colour.name),\n control: {\n type: 'select',\n },\n name: 'Colour',\n },\n size: {\n options: [1, 1.5, 2, 3, 4].map(size => `${size}rem`),\n control: {\n type: 'select',\n },\n name: 'Size',\n },\n title: {\n control: {\n type: 'text',\n },\n name: 'Title',\n },\n hidden: {\n control: {\n type: 'boolean',\n },\n name: 'Hidden (aria-hidden)',\n },\n role: {\n control: {\n type: 'text',\n },\n name: 'Role',\n },\n },\n};\n\nexport default meta;\ntype Story = StoryObj;\n\nexport const Default: Story = {};\n\nDefault.args = {\n name: 'archive',\n role: 'img',\n title: 'Icon',\n hidden: true,\n};\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview entry point for your component library
|
|
3
|
+
*
|
|
4
|
+
* This is the entry point for your component library. Use this file to export utilities,
|
|
5
|
+
* constants or data structure that accompany your components.
|
|
6
|
+
*
|
|
7
|
+
* DO NOT use this file to export your components. Instead, use the recommended approaches
|
|
8
|
+
* to consume components of this package as outlined in the `README.md`.
|
|
9
|
+
*/
|
|
10
|
+
export { format } from './utils/utils';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/utils/borders/borderUtils.ts
|
|
2
|
+
import "./borderBox.scss";
|
|
3
|
+
export const getBorderVariables = () => {
|
|
4
|
+
const borderVariables = [];
|
|
5
|
+
const rule = Array.from(document.styleSheets)
|
|
6
|
+
.flatMap((sheet) => Array.from(sheet.cssRules))
|
|
7
|
+
.find((rule) => rule.selectorText === ':root' && rule.cssText.includes('--border'));
|
|
8
|
+
if (!rule) {
|
|
9
|
+
console.warn('Could not read stylesheet:');
|
|
10
|
+
return borderVariables;
|
|
11
|
+
}
|
|
12
|
+
const cssText = rule.cssText;
|
|
13
|
+
const matches = cssText.match(/--(borderWidth)--[\w-]+:\s*[^;]+/g);
|
|
14
|
+
if (matches) {
|
|
15
|
+
matches.forEach(match => {
|
|
16
|
+
const [variable, value] = match.split(/:\s*/);
|
|
17
|
+
const name = variable.replace(/^--/, '').trim();
|
|
18
|
+
borderVariables.push({ name, variable: variable.trim(), value: value.trim() });
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
console.log('No matches found');
|
|
23
|
+
}
|
|
24
|
+
return borderVariables;
|
|
25
|
+
};
|
|
26
|
+
export const createBorderItem = (name, value) => {
|
|
27
|
+
const borderBox = document.createElement('div');
|
|
28
|
+
borderBox.className = 'border-box';
|
|
29
|
+
const borderName = document.createElement('div');
|
|
30
|
+
borderName.className = `border-name ${name}`;
|
|
31
|
+
borderName.innerHTML = `${name}`;
|
|
32
|
+
const borderInfo = document.createElement('div');
|
|
33
|
+
borderInfo.className = 'border-value';
|
|
34
|
+
borderInfo.innerHTML = `${value}`;
|
|
35
|
+
const borderCell = document.createElement('div');
|
|
36
|
+
borderCell.className = 'border-cell';
|
|
37
|
+
borderCell.style.borderWidth = `${value}`;
|
|
38
|
+
borderBox.appendChild(borderName);
|
|
39
|
+
borderBox.appendChild(borderInfo);
|
|
40
|
+
borderBox.appendChild(borderCell);
|
|
41
|
+
return borderBox;
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=borderUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"borderUtils.js","sourceRoot":"","sources":["../../../src/utils/borders/borderUtils.ts"],"names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ACD,OAAO,eAAe,CAAC;AACzB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAE,KAAa,EAAE,EAAE;IAC9D,MAAM,SAAS,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAChD,SAAS,CAAC,SAAS,GAAG,YAAY,CAAC;IAEnC,MAAM,UAAU,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACjD,UAAU,CAAC,SAAS,GAAG,eAAe,IAAI,EAAE,CAAC;IAC7C,UAAU,CAAC,SAAS,GAAG,GAAG,IAAI,EAAE,CAAC;IAEjC,MAAM,UAAU,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACjD,UAAU,CAAC,SAAS,GAAG,cAAc,CAAC;IACtC,UAAU,CAAC,SAAS,GAAG,GAAG,KAAK,EAAE,CAAC;IAElC,MAAM,UAAU,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACjD,UAAU,CAAC,SAAS,GAAG,aAAa,CAAC;IACrC,UAAU,CAAC,KAAK,CAAC,WAAW,GAAG,GAAG,KAAK,EAAE,CAAC;IAE1C,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAClC,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAClC,SAAS,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAElC,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["// src/utils/borders/borderUtils.ts\n\nimport './borderBox.scss';\n\nexport const getBorderVariables = () => {\n const borderVariables = [];\n\n const rule = Array.from(document.styleSheets)\n .flatMap((sheet) => Array.from(sheet.cssRules))\n .find((rule) => (rule as CSSStyleRule).selectorText === ':root' && rule.cssText.includes('--border'));\n\n if (!rule) {\n console.warn('Could not read stylesheet:');\n return borderVariables;\n }\n\n const cssText = rule.cssText;\n const matches = cssText.match(/--(borderWidth)--[\\w-]+:\\s*[^;]+/g);\n if (matches) {\n matches.forEach(match => {\n const [variable, value] = match.split(/:\\s*/);\n const name = variable.replace(/^--/, '').trim();\n borderVariables.push({ name, variable: variable.trim(), value: value.trim() });\n });\n } else {\n console.log('No matches found');\n }\n return borderVariables;\n};\n\nexport const createBorderItem = (name: string, value: string) => {\n const borderBox = document.createElement('div');\n borderBox.className = 'border-box';\n\n const borderName = document.createElement('div');\n borderName.className = `border-name ${name}`;\n borderName.innerHTML = `${name}`;\n\n const borderInfo = document.createElement('div');\n borderInfo.className = 'border-value';\n borderInfo.innerHTML = `${value}`;\n\n const borderCell = document.createElement('div');\n borderCell.className = 'border-cell';\n borderCell.style.borderWidth = `${value}`;\n\n borderBox.appendChild(borderName);\n borderBox.appendChild(borderInfo);\n borderBox.appendChild(borderCell);\n\n return borderBox;\n};\n"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// src/utils/colours/colourUtils.ts
|
|
2
|
+
import "./colourBox.scss";
|
|
3
|
+
export const categories = {
|
|
4
|
+
'--colour-grayscale': 'Grayscale',
|
|
5
|
+
'--colour-main': 'Main colours',
|
|
6
|
+
'--colour-semantic-neutral': 'Semantic|neutral',
|
|
7
|
+
'--colour-semantic-alert': 'Semantic|alert',
|
|
8
|
+
'--colour-semantic-error': 'Semantic|error',
|
|
9
|
+
'--colour-semantic-success': 'Semantic|success',
|
|
10
|
+
'--colour-opaque-black': 'Opaque|black',
|
|
11
|
+
'--colour-opaque-white': 'Opaque|white',
|
|
12
|
+
};
|
|
13
|
+
export const getColourVariables = () => {
|
|
14
|
+
const colourVariables = [];
|
|
15
|
+
const rule = Array.from(document.styleSheets)
|
|
16
|
+
.flatMap((sheet) => Array.from(sheet.cssRules))
|
|
17
|
+
.find((rule) => rule.selectorText === ':root');
|
|
18
|
+
if (!rule) {
|
|
19
|
+
console.warn('Could not read stylesheet:');
|
|
20
|
+
return colourVariables;
|
|
21
|
+
}
|
|
22
|
+
const cssText = rule.cssText;
|
|
23
|
+
const matches = cssText.match(/--colour-[\w-]+:\s*(#[0-9a-fA-F]+|rgba?\([\d\s,.%]+\))/g);
|
|
24
|
+
if (matches) {
|
|
25
|
+
matches.forEach(match => {
|
|
26
|
+
const [variable, value] = match.split(/:\s*/);
|
|
27
|
+
const name = variable.replace('--colour-', '').trim();
|
|
28
|
+
const categoryKey = Object.keys(categories).find(key => variable.includes(key));
|
|
29
|
+
const category = categoryKey ? categories[categoryKey] : 'Other';
|
|
30
|
+
colourVariables.push({ name, variable: variable.trim(), value: value.trim(), category });
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return colourVariables;
|
|
34
|
+
};
|
|
35
|
+
export const createColourBox = (name, hex) => {
|
|
36
|
+
const colourBox = document.createElement('div');
|
|
37
|
+
colourBox.className = 'colour-box';
|
|
38
|
+
const colourSwatch = document.createElement('div');
|
|
39
|
+
colourSwatch.className = 'colour-swatch';
|
|
40
|
+
colourSwatch.style.backgroundColor = hex;
|
|
41
|
+
const colourInfo = document.createElement('div');
|
|
42
|
+
colourInfo.className = 'colour-info';
|
|
43
|
+
colourInfo.innerHTML = `${name} <br /> <code>${hex}</code>`;
|
|
44
|
+
colourBox.appendChild(colourSwatch);
|
|
45
|
+
colourBox.appendChild(colourInfo);
|
|
46
|
+
return colourBox;
|
|
47
|
+
};
|
|
48
|
+
export const createCategorySection = (category, colours, renderedCategories) => {
|
|
49
|
+
const section = document.createElement('div');
|
|
50
|
+
const [mainCategory, subCategory] = category.split('|');
|
|
51
|
+
if (!renderedCategories.has(mainCategory)) {
|
|
52
|
+
const title = document.createElement('h2');
|
|
53
|
+
title.textContent = mainCategory;
|
|
54
|
+
section.appendChild(title);
|
|
55
|
+
renderedCategories.add(mainCategory);
|
|
56
|
+
}
|
|
57
|
+
if (subCategory) {
|
|
58
|
+
const subCategoryTitle = document.createElement('h3');
|
|
59
|
+
subCategoryTitle.textContent = subCategory;
|
|
60
|
+
section.appendChild(subCategoryTitle);
|
|
61
|
+
}
|
|
62
|
+
const gridContainer = document.createElement('div');
|
|
63
|
+
const classes = ['grid-container'];
|
|
64
|
+
if (mainCategory) {
|
|
65
|
+
const category = subCategory ? `${mainCategory.toLowerCase().split(' ')[0]}-${subCategory.toLowerCase().split(' ')[0]}` : mainCategory.toLowerCase().split(' ')[0];
|
|
66
|
+
classes.push(category);
|
|
67
|
+
}
|
|
68
|
+
gridContainer.classList.add(...classes);
|
|
69
|
+
colours.forEach(colour => {
|
|
70
|
+
gridContainer.appendChild(createColourBox(colour.name, colour.value));
|
|
71
|
+
});
|
|
72
|
+
section.appendChild(gridContainer);
|
|
73
|
+
return section;
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=colourUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colourUtils.js","sourceRoot":"","sources":["../../../src/utils/colours/colourUtils.ts"],"names":[],"mappings":"AAAA,mCAAmC;AAEnC,OAAO,kBAAkB,CAAC;AAE1B,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,oBAAoB,EAAE,WAAW;IACjC,eAAe,EAAE,cAAc;IAC/B,2BAA2B,EAAE,kBAAkB;IAC/C,yBAAyB,EAAE,gBAAgB;IAC3C,yBAAyB,EAAE,gBAAgB;IAC3C,2BAA2B,EAAE,kBAAkB;IAC/C,uBAAuB,EAAE,cAAc;IACvC,uBAAuB,EAAE,cAAc;CACxC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,EAAE;IACrC,MAAM,eAAe,GAAG,EAAE,CAAC;IAE3B,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;SAC1C,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;SAC9C,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAE,IAAqB,CAAC,YAAY,KAAK,OAAO,CAAC,CAAC;IAEnE,IAAI,CAAC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AAC;IACpD,MAAM,OAAO,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACnC,IAAI,YAAY,EAAE,CAAC;QACjB,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACnK,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC;IACD,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;IAExC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QACvB,aAAa,CAAC,WAAW,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IAEnC,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["// src/utils/colours/colourUtils.ts\n\nimport './colourBox.scss';\n\nexport const categories = {\n '--colour-grayscale': 'Grayscale',\n '--colour-main': 'Main colours',\n '--colour-semantic-neutral': 'Semantic|neutral',\n '--colour-semantic-alert': 'Semantic|alert',\n '--colour-semantic-error': 'Semantic|error',\n '--colour-semantic-success': 'Semantic|success',\n '--colour-opaque-black': 'Opaque|black',\n '--colour-opaque-white': 'Opaque|white',\n};\n\nexport const getColourVariables = () => {\n const colourVariables = [];\n\n const rule = Array.from(document.styleSheets)\n .flatMap((sheet) => Array.from(sheet.cssRules))\n .find((rule) => (rule as CSSStyleRule).selectorText === ':root');\n\n if (!rule) {\n console.warn('Could not read stylesheet:');\n return colourVariables;\n }\n\n const cssText = rule.cssText;\n const matches = cssText.match(/--colour-[\\w-]+:\\s*(#[0-9a-fA-F]+|rgba?\\([\\d\\s,.%]+\\))/g);\n if (matches) {\n matches.forEach(match => {\n const [variable, value] = match.split(/:\\s*/);\n const name = variable.replace('--colour-', '').trim();\n const categoryKey = Object.keys(categories).find(key => variable.includes(key));\n const category = categoryKey ? categories[categoryKey] : 'Other';\n colourVariables.push({ name, variable: variable.trim(), value: value.trim(), category });\n });\n }\n return colourVariables;\n};\n\nexport const createColourBox = (name: string, hex: string) => {\n const colourBox = document.createElement('div');\n colourBox.className = 'colour-box';\n\n const colourSwatch = document.createElement('div');\n colourSwatch.className = 'colour-swatch';\n colourSwatch.style.backgroundColor = hex;\n\n const colourInfo = document.createElement('div');\n colourInfo.className = 'colour-info';\n colourInfo.innerHTML = `${name} <br /> <code>${hex}</code>`;\n\n colourBox.appendChild(colourSwatch);\n colourBox.appendChild(colourInfo);\n\n return colourBox;\n};\n\nexport const createCategorySection = (category: string, colours: { name: string, variable: string, value: string }[], renderedCategories: Set<string>) => {\n const section = document.createElement('div');\n const [mainCategory, subCategory] = category.split('|');\n\n if (!renderedCategories.has(mainCategory)) {\n const title = document.createElement('h2');\n title.textContent = mainCategory;\n section.appendChild(title);\n renderedCategories.add(mainCategory);\n }\n\n if (subCategory) {\n const subCategoryTitle = document.createElement('h3');\n subCategoryTitle.textContent = subCategory;\n section.appendChild(subCategoryTitle);\n }\n\n const gridContainer = document.createElement('div');\n const classes = ['grid-container'];\n if (mainCategory) {\n const category = subCategory ? `${mainCategory.toLowerCase().split(' ')[0]}-${subCategory.toLowerCase().split(' ')[0]}` : mainCategory.toLowerCase().split(' ')[0];\n classes.push(category);\n }\n gridContainer.classList.add(...classes);\n\n colours.forEach(colour => {\n gridContainer.appendChild(createColourBox(colour.name, colour.value));\n });\n\n section.appendChild(gridContainer);\n\n return section;\n};\n"]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// src/utils/spacing/spacingUtils.ts
|
|
2
|
+
import "./spacingBox.scss";
|
|
3
|
+
export const categories = {
|
|
4
|
+
'--spacing--': 'Spacing',
|
|
5
|
+
'--spacingLayout--': 'Layout',
|
|
6
|
+
};
|
|
7
|
+
export const getSpacingVariables = () => {
|
|
8
|
+
const spacingVariables = [];
|
|
9
|
+
const rule = Array.from(document.styleSheets)
|
|
10
|
+
.flatMap((sheet) => Array.from(sheet.cssRules))
|
|
11
|
+
.find((rule) => rule.selectorText === ':root' && rule.cssText.includes('--spacing'));
|
|
12
|
+
if (!rule) {
|
|
13
|
+
console.warn('Could not read stylesheet:');
|
|
14
|
+
return spacingVariables;
|
|
15
|
+
}
|
|
16
|
+
const cssText = rule.cssText;
|
|
17
|
+
const matches = cssText.match(/--(spacing|spacingLayout)--[\w-]+:\s*[\d.]+rem/g);
|
|
18
|
+
if (matches) {
|
|
19
|
+
matches.forEach(match => {
|
|
20
|
+
console.log(match);
|
|
21
|
+
const [variable, value] = match.split(/:\s*/);
|
|
22
|
+
const name = variable.replace(/^--/, '').trim();
|
|
23
|
+
const categoryKey = Object.keys(categories).find(key => variable.includes(key));
|
|
24
|
+
const category = categoryKey ? categories[categoryKey] : 'Other';
|
|
25
|
+
spacingVariables.push({ name, variable: variable.trim(), value: value.trim(), category });
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
console.log('No matches found');
|
|
30
|
+
}
|
|
31
|
+
return spacingVariables;
|
|
32
|
+
};
|
|
33
|
+
export const createSpacingBox = (name, value, width) => {
|
|
34
|
+
const spacingBox = document.createElement('div');
|
|
35
|
+
spacingBox.className = 'spacing-box';
|
|
36
|
+
const spacingName = document.createElement('div');
|
|
37
|
+
spacingName.className = 'spacing-name';
|
|
38
|
+
spacingName.innerHTML = `${name}`;
|
|
39
|
+
const spacingInfo = document.createElement('div');
|
|
40
|
+
spacingInfo.className = 'spacing-value';
|
|
41
|
+
spacingInfo.innerHTML = `${value}`;
|
|
42
|
+
const spacingBar = document.createElement('div');
|
|
43
|
+
spacingBar.className = 'spacing-bar';
|
|
44
|
+
spacingBar.style.width = width;
|
|
45
|
+
spacingBox.appendChild(spacingName);
|
|
46
|
+
spacingBox.appendChild(spacingInfo);
|
|
47
|
+
spacingBox.appendChild(spacingBar);
|
|
48
|
+
return spacingBox;
|
|
49
|
+
};
|
|
50
|
+
export const createCategorySection = (category, spacings, renderedCategories) => {
|
|
51
|
+
const section = document.createElement('div');
|
|
52
|
+
if (!renderedCategories.has(category)) {
|
|
53
|
+
const title = document.createElement('h2');
|
|
54
|
+
title.textContent = category;
|
|
55
|
+
section.appendChild(title);
|
|
56
|
+
renderedCategories.add(category);
|
|
57
|
+
}
|
|
58
|
+
const gridContainer = document.createElement('div');
|
|
59
|
+
spacings.forEach(spacing => {
|
|
60
|
+
const remValue = parseFloat(spacing.value);
|
|
61
|
+
const pixelValue = remValue * 16; // Assuming 1rem = 16px
|
|
62
|
+
gridContainer.appendChild(createSpacingBox(spacing.name, `${spacing.value} / ${pixelValue}px`, spacing.value));
|
|
63
|
+
});
|
|
64
|
+
section.appendChild(gridContainer);
|
|
65
|
+
return section;
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=spacingUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spacingUtils.js","sourceRoot":"","sources":["../../../src/utils/spacing/spacingUtils.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,mBAAmB,CAAC;AAE3B,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,aAAa,EAAE,SAAS;IACxB,mBAAmB,EAAE,QAAQ;CAC9B,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,EAAE;IACtC,MAAM,gBAAgB,GAAG,EAAE,CAAC;IAE5B,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;SAC1C,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CA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AQ,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC3C,KAAK,CAAC,WAAW,GAAG,QAAQ,CAAC;QAC7B,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC3B,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED,MAAM,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAEpD,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QACzB,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC3C,MAAM,UAAU,GAAG,QAAQ,GAAG,EAAE,CAAC,CAAC,uBAAuB;QACzD,aAAa,CAAC,WAAW,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,KAAK,MAAM,UAAU,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IACjH,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IAEnC,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["// src/utils/spacing/spacingUtils.ts\n\nimport './spacingBox.scss';\n\nexport const categories = {\n '--spacing--': 'Spacing',\n '--spacingLayout--': 'Layout',\n};\n\nexport const getSpacingVariables = () => {\n const spacingVariables = [];\n\n const rule = Array.from(document.styleSheets)\n .flatMap((sheet) => Array.from(sheet.cssRules))\n .find((rule) => (rule as CSSStyleRule).selectorText === ':root' && rule.cssText.includes('--spacing'));\n\n if (!rule) {\n console.warn('Could not read stylesheet:');\n return spacingVariables;\n }\n\n const cssText = rule.cssText;\n const matches = cssText.match(/--(spacing|spacingLayout)--[\\w-]+:\\s*[\\d.]+rem/g);\n if (matches) {\n matches.forEach(match => {\n console.log(match);\n const [variable, value] = match.split(/:\\s*/);\n const name = variable.replace(/^--/, '').trim();\n const categoryKey = Object.keys(categories).find(key => variable.includes(key));\n const category = categoryKey ? categories[categoryKey] : 'Other';\n spacingVariables.push({ name, variable: variable.trim(), value: value.trim(), category });\n });\n } else {\n console.log('No matches found');\n }\n return spacingVariables;\n};\n\nexport const createSpacingBox = (name: string, value: string, width: string) => {\n const spacingBox = document.createElement('div');\n spacingBox.className = 'spacing-box';\n\n const spacingName = document.createElement('div');\n spacingName.className = 'spacing-name';\n spacingName.innerHTML = `${name}`;\n\n const spacingInfo = document.createElement('div');\n spacingInfo.className = 'spacing-value';\n spacingInfo.innerHTML = `${value}`;\n\n const spacingBar = document.createElement('div');\n spacingBar.className = 'spacing-bar';\n spacingBar.style.width = width;\n\n spacingBox.appendChild(spacingName);\n spacingBox.appendChild(spacingInfo);\n spacingBox.appendChild(spacingBar);\n\n return spacingBox;\n};\n\nexport const createCategorySection = (category: string, spacings: { name: string, variable: string, value: string }[], renderedCategories: Set<string>) => {\n const section = document.createElement('div');\n\n if (!renderedCategories.has(category)) {\n const title = document.createElement('h2');\n title.textContent = category;\n section.appendChild(title);\n renderedCategories.add(category);\n }\n\n const gridContainer = document.createElement('div');\n\n spacings.forEach(spacing => {\n const remValue = parseFloat(spacing.value);\n const pixelValue = remValue * 16; // Assuming 1rem = 16px\n gridContainer.appendChild(createSpacingBox(spacing.name, `${spacing.value} / ${pixelValue}px`, spacing.value));\n });\n\n section.appendChild(gridContainer);\n\n return section;\n};\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { fn, expect, waitFor, within } from "@storybook/test";
|
|
2
|
+
/**
|
|
3
|
+
* Utility function for running storybook interaction tests in Shadow DOM containers.
|
|
4
|
+
* Logic taken from https://github.com/storybookjs/testing-library/issues/24#issuecomment-1593709872
|
|
5
|
+
*/
|
|
6
|
+
export const withinShadowRoot = async (customElem, selector) => {
|
|
7
|
+
const webc = customElem.querySelector(selector);
|
|
8
|
+
await waitFor(() => {
|
|
9
|
+
const shadowRootFirstEl = webc.shadowRoot.firstElementChild;
|
|
10
|
+
return expect(shadowRootFirstEl).toContainElement(shadowRootFirstEl);
|
|
11
|
+
}, { timeout: 5000 });
|
|
12
|
+
return within(webc.shadowRoot);
|
|
13
|
+
};
|
|
14
|
+
export const addMockEventListener = (container, selector, eventName) => {
|
|
15
|
+
const elem = container.querySelector(selector);
|
|
16
|
+
const mockFunction = fn();
|
|
17
|
+
elem.addEventListener(eventName, mockFunction);
|
|
18
|
+
return mockFunction;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=testUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testUtils.js","sourceRoot":"","sources":["../../../src/utils/tests/testUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE9D;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAE,UAAuB,EAAE,QAAgB,EAAE,EAAE;IAClF,MAAM,IAAI,GAAG,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,OAAO,CACX,GAAG,EAAE;QACH,MAAM,iBAAiB,GAAG,IAAI,CAAC,UAAU,CAAC,iBAAgC,CAAC;QAC3E,OAAO,MAAM,CAAC,iBAAiB,CAAC,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;IACvE,CAAC,EACD,EAAE,OAAO,EAAE,IAAI,EAAE,CAClB,CAAA;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,UAAgC,CAAC,CAAC;AACvD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,SAAsB,EAAE,QAAgB,EAAE,SAAiB,EAAE,EAAE;IAClG,MAAM,IAAI,GAAG,SAAS,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC/C,MAAM,YAAY,GAAG,EAAE,EAAE,CAAC;IAC1B,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IAC/C,OAAO,YAAY,CAAC;AACtB,CAAC,CAAA","sourcesContent":["import { fn, expect, waitFor, within } from '@storybook/test';\n\n/**\n * Utility function for running storybook interaction tests in Shadow DOM containers.\n * Logic taken from https://github.com/storybookjs/testing-library/issues/24#issuecomment-1593709872\n */\nexport const withinShadowRoot = async (customElem: HTMLElement, selector: string) => {\n const webc = customElem.querySelector(selector);\n await waitFor(\n () => {\n const shadowRootFirstEl = webc.shadowRoot.firstElementChild as HTMLElement;\n return expect(shadowRootFirstEl).toContainElement(shadowRootFirstEl);\n },\n { timeout: 5000 }\n )\n return within(webc.shadowRoot as any as HTMLElement);\n}\n\nexport const addMockEventListener = (container: HTMLElement, selector: string, eventName: string) => {\n const elem = container.querySelector(selector);\n const mockFunction = fn();\n elem.addEventListener(eventName, mockFunction);\n return mockFunction;\n}\n"]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// src/utils/typography/typographyUtils.ts
|
|
2
|
+
import "./typographyBox.scss";
|
|
3
|
+
export const categories = {
|
|
4
|
+
'--ds-fontFamily': 'Font family',
|
|
5
|
+
'--ds-fontSize': 'Font size',
|
|
6
|
+
'--ds-fontWeight': 'Font weight',
|
|
7
|
+
'--ds-letterSpacing': 'Letter spacing',
|
|
8
|
+
'--ds-lineHeight': 'Line height',
|
|
9
|
+
'--ds-fontWidth': 'Font width'
|
|
10
|
+
};
|
|
11
|
+
export const getTypographyVariables = () => {
|
|
12
|
+
const typographyVariables = [];
|
|
13
|
+
// There can be multiple rules so find and combine.
|
|
14
|
+
const findRootRule = () => {
|
|
15
|
+
const rootRules = [];
|
|
16
|
+
for (const sheet of document.styleSheets) {
|
|
17
|
+
try {
|
|
18
|
+
const rules = [...sheet.cssRules].filter((r) => r instanceof CSSStyleRule && r.selectorText === ':root');
|
|
19
|
+
rootRules.push(...rules.map(rule => rule.cssText));
|
|
20
|
+
}
|
|
21
|
+
catch (_a) {
|
|
22
|
+
console.warn('Issue occurred when extracting stylesheets.');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return rootRules.join(';');
|
|
26
|
+
};
|
|
27
|
+
const rules = findRootRule();
|
|
28
|
+
if (!rules) {
|
|
29
|
+
console.warn('Could not read stylesheet:');
|
|
30
|
+
return typographyVariables;
|
|
31
|
+
}
|
|
32
|
+
const matches = new Set(rules.match(/--(ds)-[\w-]+:\s*[^;]+/g));
|
|
33
|
+
if (matches) {
|
|
34
|
+
matches.forEach(match => {
|
|
35
|
+
const [variable, value] = match.split(/:\s*/);
|
|
36
|
+
const categoryKey = Object.keys(categories).find(key => variable.includes(key));
|
|
37
|
+
const category = categoryKey ? categories[categoryKey] : 'Other';
|
|
38
|
+
typographyVariables.push({ name: variable, variable: variable.trim(), value: value.trim(), category });
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return typographyVariables;
|
|
42
|
+
};
|
|
43
|
+
export const createFontBox = (name, value, category) => {
|
|
44
|
+
const fontBox = document.createElement('div');
|
|
45
|
+
fontBox.className = 'font-box';
|
|
46
|
+
const fontInfo = document.createElement('div');
|
|
47
|
+
fontInfo.className = 'font-info';
|
|
48
|
+
fontInfo.innerHTML = `${name}`;
|
|
49
|
+
const fontValue = document.createElement('div');
|
|
50
|
+
fontValue.className = 'font-value';
|
|
51
|
+
fontValue.innerHTML = `${value}`;
|
|
52
|
+
const fontExtra = document.createElement('div');
|
|
53
|
+
const remValue = (1 / 16) * parseInt(value);
|
|
54
|
+
fontExtra.className = 'font-extra';
|
|
55
|
+
fontExtra.innerHTML = category === 'Font size' ? `${remValue}rem` : '';
|
|
56
|
+
fontBox.appendChild(fontInfo);
|
|
57
|
+
fontBox.appendChild(fontValue);
|
|
58
|
+
fontBox.appendChild(fontExtra);
|
|
59
|
+
return fontBox;
|
|
60
|
+
};
|
|
61
|
+
export const createCategorySection = (category, fonts, renderedCategories) => {
|
|
62
|
+
const section = document.createElement('div');
|
|
63
|
+
const [mainCategory, subCategory] = category.split('|');
|
|
64
|
+
if (!renderedCategories.has(mainCategory)) {
|
|
65
|
+
const title = document.createElement('h2');
|
|
66
|
+
title.textContent = mainCategory;
|
|
67
|
+
section.appendChild(title);
|
|
68
|
+
renderedCategories.add(mainCategory);
|
|
69
|
+
}
|
|
70
|
+
if (subCategory) {
|
|
71
|
+
const subCategoryTitle = document.createElement('h3');
|
|
72
|
+
subCategoryTitle.textContent = subCategory;
|
|
73
|
+
section.appendChild(subCategoryTitle);
|
|
74
|
+
}
|
|
75
|
+
const gridContainer = document.createElement('div');
|
|
76
|
+
const classes = ['font-grid-container'];
|
|
77
|
+
if (mainCategory) {
|
|
78
|
+
const category = subCategory ? `${mainCategory.toLowerCase().split(' ')[0]}-${subCategory.toLowerCase().split(' ')[0]}` : mainCategory.toLowerCase().split(' ')[0];
|
|
79
|
+
classes.push(category);
|
|
80
|
+
}
|
|
81
|
+
gridContainer.classList.add(...classes);
|
|
82
|
+
fonts.forEach(font => {
|
|
83
|
+
gridContainer.appendChild(createFontBox(font.name, font.value, category));
|
|
84
|
+
});
|
|
85
|
+
section.appendChild(gridContainer);
|
|
86
|
+
return section;
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=typographyUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typographyUtils.js","sourceRoot":"","sources":["../../../src/utils/typography/typographyUtils.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAE1C,OAAO,sBAAsB,CAAC;AAE9B,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,iBAAiB,EAAE,aAAa;IAChC,eAAe,EAAE,WAAW;IAC5B,iBAAiB,EAAE,aAAa;IAChC,oBAAoB,EAAE,gBAAgB;IACtC,iBAAiB,EAAE,aAAa;IAChC,gBAAgB,EAAE,YAAY;CAC/B,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,MAAM,mBAAmB,GAAG,EAAE,CAAC;IAE/B,mDAAmD;IACnD,MAAM,YAAY,GAAG,GAAW,EAAE;QAChC,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AC,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACnK,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzB,CAAC;IACD,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;IAExC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACnB,aAAa,CAAC,WAAW,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IACnC,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["// src/utils/typography/typographyUtils.ts\n\nimport './typographyBox.scss';\n\nexport const categories = {\n '--ds-fontFamily': 'Font family',\n '--ds-fontSize': 'Font size',\n '--ds-fontWeight': 'Font weight',\n '--ds-letterSpacing': 'Letter spacing',\n '--ds-lineHeight': 'Line height',\n '--ds-fontWidth': 'Font width'\n};\n\nexport const getTypographyVariables = () => {\n const typographyVariables = [];\n\n // There can be multiple rules so find and combine.\n const findRootRule = (): string => {\n const rootRules: string[] = [];\n for (const sheet of (document.styleSheets as StyleSheetList)) {\n try {\n const rules = [...sheet.cssRules].filter(\n (r): r is CSSStyleRule => r instanceof CSSStyleRule && r.selectorText === ':root'\n );\n rootRules.push(...rules.map(rule => rule.cssText));\n } catch {\n console.warn('Issue occurred when extracting stylesheets.');\n }\n }\n return rootRules.join(';');\n };\n\n const rules = findRootRule();\n if (!rules) {\n console.warn('Could not read stylesheet:');\n return typographyVariables;\n }\n\n const matches = new Set(rules.match(/--(ds)-[\\w-]+:\\s*[^;]+/g));\n\n if (matches) {\n matches.forEach(match => {\n const [variable, value] = match.split(/:\\s*/);\n const categoryKey = Object.keys(categories).find(key => variable.includes(key));\n const category = categoryKey ? categories[categoryKey] : 'Other';\n typographyVariables.push({ name: variable, variable: variable.trim(), value: value.trim(), category });\n });\n }\n return typographyVariables;\n};\n\nexport const createFontBox = (name: string, value: string, category: string) => {\n const fontBox = document.createElement('div');\n fontBox.className = 'font-box';\n\n const fontInfo = document.createElement('div');\n fontInfo.className = 'font-info';\n fontInfo.innerHTML = `${name}`;\n\n const fontValue = document.createElement('div');\n fontValue.className = 'font-value';\n fontValue.innerHTML = `${value}`;\n\n const fontExtra = document.createElement('div');\n const remValue = (1 / 16) * parseInt(value);\n fontExtra.className = 'font-extra';\n fontExtra.innerHTML = category === 'Font size' ? `${remValue}rem` : '';\n\n fontBox.appendChild(fontInfo);\n fontBox.appendChild(fontValue);\n fontBox.appendChild(fontExtra);\n\n return fontBox;\n};\n\nexport const createCategorySection = (category: string, fonts: { name: string, variable: string, value: string }[], renderedCategories: Set<string>) => {\n const section = document.createElement('div');\n const [mainCategory, subCategory] = category.split('|');\n\n if (!renderedCategories.has(mainCategory)) {\n const title = document.createElement('h2');\n title.textContent = mainCategory;\n section.appendChild(title);\n renderedCategories.add(mainCategory);\n }\n\n if (subCategory) {\n const subCategoryTitle = document.createElement('h3');\n subCategoryTitle.textContent = subCategory;\n section.appendChild(subCategoryTitle);\n }\n\n const gridContainer = document.createElement('div');\n const classes = ['font-grid-container'];\n if (mainCategory) {\n const category = subCategory ? `${mainCategory.toLowerCase().split(' ')[0]}-${subCategory.toLowerCase().split(' ')[0]}` : mainCategory.toLowerCase().split(' ')[0];\n classes.push(category);\n }\n gridContainer.classList.add(...classes);\n\n fonts.forEach(font => {\n gridContainer.appendChild(createFontBox(font.name, font.value, category));\n });\n\n section.appendChild(gridContainer);\n return section;\n};\n"]}
|