Skip to content

Commit 623a1f2

Browse files
Merge branch 'colors-docs'
2 parents 56c1fb9 + 5c7e8eb commit 623a1f2

File tree

6 files changed

+166
-29
lines changed

6 files changed

+166
-29
lines changed

apps/docs/app/routeTree.gen.ts

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import { Route as rootRoute } from './routes/__root'
1414
import { Route as DocsImport } from './routes/_docs'
1515
import { Route as DocsIndexImport } from './routes/_docs/index'
1616
import { Route as StudioSplatImport } from './routes/studio/$'
17-
import { Route as DocsIkonerImport } from './routes/_docs/ikoner'
1817
import { Route as DocsKomponenterIndexImport } from './routes/_docs/komponenter/index'
18+
import { Route as DocsProfilIkonerImport } from './routes/_docs/profil/ikoner'
19+
import { Route as DocsProfilFargerImport } from './routes/_docs/profil/farger'
1920
import { Route as DocsKomponenterSlugImport } from './routes/_docs/komponenter/$slug'
2021

2122
// Create/Update Routes
@@ -37,18 +38,24 @@ const StudioSplatRoute = StudioSplatImport.update({
3738
getParentRoute: () => rootRoute,
3839
} as any)
3940

40-
const DocsIkonerRoute = DocsIkonerImport.update({
41-
id: '/ikoner',
42-
path: '/ikoner',
43-
getParentRoute: () => DocsRoute,
44-
} as any)
45-
4641
const DocsKomponenterIndexRoute = DocsKomponenterIndexImport.update({
4742
id: '/komponenter/',
4843
path: '/komponenter/',
4944
getParentRoute: () => DocsRoute,
5045
} as any)
5146

47+
const DocsProfilIkonerRoute = DocsProfilIkonerImport.update({
48+
id: '/profil/ikoner',
49+
path: '/profil/ikoner',
50+
getParentRoute: () => DocsRoute,
51+
} as any)
52+
53+
const DocsProfilFargerRoute = DocsProfilFargerImport.update({
54+
id: '/profil/farger',
55+
path: '/profil/farger',
56+
getParentRoute: () => DocsRoute,
57+
} as any)
58+
5259
const DocsKomponenterSlugRoute = DocsKomponenterSlugImport.update({
5360
id: '/komponenter/$slug',
5461
path: '/komponenter/$slug',
@@ -66,13 +73,6 @@ declare module '@tanstack/react-router' {
6673
preLoaderRoute: typeof DocsImport
6774
parentRoute: typeof rootRoute
6875
}
69-
'/_docs/ikoner': {
70-
id: '/_docs/ikoner'
71-
path: '/ikoner'
72-
fullPath: '/ikoner'
73-
preLoaderRoute: typeof DocsIkonerImport
74-
parentRoute: typeof DocsImport
75-
}
7676
'/studio/$': {
7777
id: '/studio/$'
7878
path: '/studio/$'
@@ -94,6 +94,20 @@ declare module '@tanstack/react-router' {
9494
preLoaderRoute: typeof DocsKomponenterSlugImport
9595
parentRoute: typeof DocsImport
9696
}
97+
'/_docs/profil/farger': {
98+
id: '/_docs/profil/farger'
99+
path: '/profil/farger'
100+
fullPath: '/profil/farger'
101+
preLoaderRoute: typeof DocsProfilFargerImport
102+
parentRoute: typeof DocsImport
103+
}
104+
'/_docs/profil/ikoner': {
105+
id: '/_docs/profil/ikoner'
106+
path: '/profil/ikoner'
107+
fullPath: '/profil/ikoner'
108+
preLoaderRoute: typeof DocsProfilIkonerImport
109+
parentRoute: typeof DocsImport
110+
}
97111
'/_docs/komponenter/': {
98112
id: '/_docs/komponenter/'
99113
path: '/komponenter'
@@ -107,66 +121,79 @@ declare module '@tanstack/react-router' {
107121
// Create and export the route tree
108122

109123
interface DocsRouteChildren {
110-
DocsIkonerRoute: typeof DocsIkonerRoute
111124
DocsIndexRoute: typeof DocsIndexRoute
112125
DocsKomponenterSlugRoute: typeof DocsKomponenterSlugRoute
126+
DocsProfilFargerRoute: typeof DocsProfilFargerRoute
127+
DocsProfilIkonerRoute: typeof DocsProfilIkonerRoute
113128
DocsKomponenterIndexRoute: typeof DocsKomponenterIndexRoute
114129
}
115130

116131
const DocsRouteChildren: DocsRouteChildren = {
117-
DocsIkonerRoute: DocsIkonerRoute,
118132
DocsIndexRoute: DocsIndexRoute,
119133
DocsKomponenterSlugRoute: DocsKomponenterSlugRoute,
134+
DocsProfilFargerRoute: DocsProfilFargerRoute,
135+
DocsProfilIkonerRoute: DocsProfilIkonerRoute,
120136
DocsKomponenterIndexRoute: DocsKomponenterIndexRoute,
121137
}
122138

123139
const DocsRouteWithChildren = DocsRoute._addFileChildren(DocsRouteChildren)
124140

125141
export interface FileRoutesByFullPath {
126142
'': typeof DocsRouteWithChildren
127-
'/ikoner': typeof DocsIkonerRoute
128143
'/studio/$': typeof StudioSplatRoute
129144
'/': typeof DocsIndexRoute
130145
'/komponenter/$slug': typeof DocsKomponenterSlugRoute
146+
'/profil/farger': typeof DocsProfilFargerRoute
147+
'/profil/ikoner': typeof DocsProfilIkonerRoute
131148
'/komponenter': typeof DocsKomponenterIndexRoute
132149
}
133150

134151
export interface FileRoutesByTo {
135-
'/ikoner': typeof DocsIkonerRoute
136152
'/studio/$': typeof StudioSplatRoute
137153
'/': typeof DocsIndexRoute
138154
'/komponenter/$slug': typeof DocsKomponenterSlugRoute
155+
'/profil/farger': typeof DocsProfilFargerRoute
156+
'/profil/ikoner': typeof DocsProfilIkonerRoute
139157
'/komponenter': typeof DocsKomponenterIndexRoute
140158
}
141159

142160
export interface FileRoutesById {
143161
__root__: typeof rootRoute
144162
'/_docs': typeof DocsRouteWithChildren
145-
'/_docs/ikoner': typeof DocsIkonerRoute
146163
'/studio/$': typeof StudioSplatRoute
147164
'/_docs/': typeof DocsIndexRoute
148165
'/_docs/komponenter/$slug': typeof DocsKomponenterSlugRoute
166+
'/_docs/profil/farger': typeof DocsProfilFargerRoute
167+
'/_docs/profil/ikoner': typeof DocsProfilIkonerRoute
149168
'/_docs/komponenter/': typeof DocsKomponenterIndexRoute
150169
}
151170

152171
export interface FileRouteTypes {
153172
fileRoutesByFullPath: FileRoutesByFullPath
154173
fullPaths:
155174
| ''
156-
| '/ikoner'
157175
| '/studio/$'
158176
| '/'
159177
| '/komponenter/$slug'
178+
| '/profil/farger'
179+
| '/profil/ikoner'
160180
| '/komponenter'
161181
fileRoutesByTo: FileRoutesByTo
162-
to: '/ikoner' | '/studio/$' | '/' | '/komponenter/$slug' | '/komponenter'
182+
to:
183+
| '/studio/$'
184+
| '/'
185+
| '/komponenter/$slug'
186+
| '/profil/farger'
187+
| '/profil/ikoner'
188+
| '/komponenter'
163189
id:
164190
| '__root__'
165191
| '/_docs'
166-
| '/_docs/ikoner'
167192
| '/studio/$'
168193
| '/_docs/'
169194
| '/_docs/komponenter/$slug'
195+
| '/_docs/profil/farger'
196+
| '/_docs/profil/ikoner'
170197
| '/_docs/komponenter/'
171198
fileRoutesById: FileRoutesById
172199
}
@@ -198,16 +225,13 @@ export const routeTree = rootRoute
198225
"/_docs": {
199226
"filePath": "_docs.tsx",
200227
"children": [
201-
"/_docs/ikoner",
202228
"/_docs/",
203229
"/_docs/komponenter/$slug",
230+
"/_docs/profil/farger",
231+
"/_docs/profil/ikoner",
204232
"/_docs/komponenter/"
205233
]
206234
},
207-
"/_docs/ikoner": {
208-
"filePath": "_docs/ikoner.tsx",
209-
"parent": "/_docs"
210-
},
211235
"/studio/$": {
212236
"filePath": "studio/$.tsx"
213237
},
@@ -219,6 +243,14 @@ export const routeTree = rootRoute
219243
"filePath": "_docs/komponenter/$slug.tsx",
220244
"parent": "/_docs"
221245
},
246+
"/_docs/profil/farger": {
247+
"filePath": "_docs/profil/farger.tsx",
248+
"parent": "/_docs"
249+
},
250+
"/_docs/profil/ikoner": {
251+
"filePath": "_docs/profil/ikoner.tsx",
252+
"parent": "/_docs"
253+
},
222254
"/_docs/komponenter/": {
223255
"filePath": "_docs/komponenter/index.tsx",
224256
"parent": "/_docs"
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { createFileRoute } from '@tanstack/react-router';
2+
import { useState } from 'react';
3+
import { useLayoutEffect } from '@react-aria/utils';
4+
5+
export const Route = createFileRoute('/_docs/profil/farger')({
6+
component: RouteComponent,
7+
});
8+
9+
/**
10+
* Retrieves all colors from the CSS variables in the document.
11+
* @returns a record of all colors
12+
*/
13+
function getAllColors() {
14+
const cssVariables: Record<string, string> = {};
15+
16+
for (const sheet of document.styleSheets) {
17+
for (const rule of sheet.cssRules ?? []) {
18+
if (rule instanceof CSSStyleRule && rule.selectorText === ':root') {
19+
for (const style of rule.style) {
20+
const prefix = '--gm-color-';
21+
if (style.startsWith('--gm-color-')) {
22+
cssVariables[style.replace(prefix, '')] = rule.style
23+
.getPropertyValue(style)
24+
.trim();
25+
}
26+
}
27+
}
28+
}
29+
}
30+
31+
return cssVariables;
32+
}
33+
34+
function RouteComponent() {
35+
const [colors, setColors] = useState<null | {
36+
[key: string]: string;
37+
}>(null);
38+
39+
// Make sure to read the colors from the custom properties when the component mounts client side
40+
useLayoutEffect(() => {
41+
setColors(getAllColors());
42+
}, []);
43+
44+
if (!colors) {
45+
// Return null if the colors are not loaded yet (usually this will only happen on the server)
46+
return null;
47+
}
48+
49+
return (
50+
<>
51+
<h1 className="heading-l mb-12 mt-9">Farger</h1>
52+
<div className="prose mb-12">
53+
<p>Grunnmuren har {Object.keys(colors).length} forskjellige farger.</p>
54+
</div>
55+
<div className="grid grid-cols-[repeat(auto-fill,_130px)] content-center gap-6">
56+
{Object.entries(colors).map(([name, value]) => (
57+
<Color key={name} name={name} value={value} />
58+
))}
59+
</div>
60+
</>
61+
);
62+
}
63+
64+
const Color = ({ name, value }) => {
65+
const color = `rgb(${value.split(' ').join(', ')})`;
66+
67+
return (
68+
<div
69+
style={{
70+
backgroundColor: color,
71+
// Makes sure the text has enough contrast by calculating the color based on the background color
72+
// This will yield a color that is either black or white
73+
// Refer to: https://til.jakelazaroff.com/css/swap-between-black-and-white-text-based-on-background-color/
74+
color: `lch(from ${color} calc((54 - l) * infinity) 0 0)`,
75+
border:
76+
name === 'white' ? '1px solid rgb(var(--gm-color-blue-dark))' : '',
77+
}}
78+
className="grid h-32 w-32 items-end"
79+
>
80+
<span className="block p-2 text-sm">{name}</span>
81+
</div>
82+
);
83+
};

apps/docs/app/routes/_docs/ikoner.tsx renamed to apps/docs/app/routes/_docs/profil/ikoner.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Box, Download, Figma, Github } from '@obosbbl/grunnmuren-icons-react';
33
import { Button, Card } from '@obosbbl/grunnmuren-react';
44
import { createFileRoute } from '@tanstack/react-router';
55

6-
export const Route = createFileRoute('/_docs/ikoner')({
6+
export const Route = createFileRoute('/_docs/profil/ikoner')({
77
component: Page,
88
head: () => ({
99
meta: [

apps/docs/app/ui/main-nav.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ const mainNavItems = [
5353
title: 'Profil',
5454
subNavItems: [
5555
{
56-
to: '/ikoner',
56+
to: '/profil/farger',
57+
title: 'Farger',
58+
},
59+
{
60+
to: '/profil/ikoner',
5761
title: 'Ikoner',
5862
},
5963
],

apps/docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@obosbbl/grunnmuren-icons-svg": "workspace:*",
2323
"@obosbbl/grunnmuren-react": "workspace:*",
2424
"@portabletext/react": "3.2.0",
25+
"@react-aria/utils": "3.25.1",
2526
"@sanity/client": "6.24.1",
2627
"@sanity/code-input": "5.1.2",
2728
"@sanity/vision": "3.68.3",

pnpm-lock.yaml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)