Skip to content

Commit 44e28ee

Browse files
Fix color-docs (#1090)
* Fix color-docs * Delete old file * Organize imports * Fix formatting
1 parent 24ed492 commit 44e28ee

File tree

8 files changed

+235
-29
lines changed

8 files changed

+235
-29
lines changed

apps/docs/app/routeTree.gen.ts

Lines changed: 84 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ 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'
17+
import { Route as DocsProfilIndexImport } from './routes/_docs/profil/index'
1818
import { Route as DocsKomponenterIndexImport } from './routes/_docs/komponenter/index'
19+
import { Route as DocsProfilIkonerImport } from './routes/_docs/profil/ikoner'
20+
import { Route as DocsProfilFargerImport } from './routes/_docs/profil/farger'
1921
import { Route as DocsKomponenterSlugImport } from './routes/_docs/komponenter/$slug'
2022

2123
// Create/Update Routes
@@ -37,9 +39,9 @@ const StudioSplatRoute = StudioSplatImport.update({
3739
getParentRoute: () => rootRoute,
3840
} as any)
3941

40-
const DocsIkonerRoute = DocsIkonerImport.update({
41-
id: '/ikoner',
42-
path: '/ikoner',
42+
const DocsProfilIndexRoute = DocsProfilIndexImport.update({
43+
id: '/profil/',
44+
path: '/profil/',
4345
getParentRoute: () => DocsRoute,
4446
} as any)
4547

@@ -49,6 +51,18 @@ const DocsKomponenterIndexRoute = DocsKomponenterIndexImport.update({
4951
getParentRoute: () => DocsRoute,
5052
} as any)
5153

54+
const DocsProfilIkonerRoute = DocsProfilIkonerImport.update({
55+
id: '/profil/ikoner',
56+
path: '/profil/ikoner',
57+
getParentRoute: () => DocsRoute,
58+
} as any)
59+
60+
const DocsProfilFargerRoute = DocsProfilFargerImport.update({
61+
id: '/profil/farger',
62+
path: '/profil/farger',
63+
getParentRoute: () => DocsRoute,
64+
} as any)
65+
5266
const DocsKomponenterSlugRoute = DocsKomponenterSlugImport.update({
5367
id: '/komponenter/$slug',
5468
path: '/komponenter/$slug',
@@ -66,13 +80,6 @@ declare module '@tanstack/react-router' {
6680
preLoaderRoute: typeof DocsImport
6781
parentRoute: typeof rootRoute
6882
}
69-
'/_docs/ikoner': {
70-
id: '/_docs/ikoner'
71-
path: '/ikoner'
72-
fullPath: '/ikoner'
73-
preLoaderRoute: typeof DocsIkonerImport
74-
parentRoute: typeof DocsImport
75-
}
7683
'/studio/$': {
7784
id: '/studio/$'
7885
path: '/studio/$'
@@ -94,80 +101,122 @@ declare module '@tanstack/react-router' {
94101
preLoaderRoute: typeof DocsKomponenterSlugImport
95102
parentRoute: typeof DocsImport
96103
}
104+
'/_docs/profil/farger': {
105+
id: '/_docs/profil/farger'
106+
path: '/profil/farger'
107+
fullPath: '/profil/farger'
108+
preLoaderRoute: typeof DocsProfilFargerImport
109+
parentRoute: typeof DocsImport
110+
}
111+
'/_docs/profil/ikoner': {
112+
id: '/_docs/profil/ikoner'
113+
path: '/profil/ikoner'
114+
fullPath: '/profil/ikoner'
115+
preLoaderRoute: typeof DocsProfilIkonerImport
116+
parentRoute: typeof DocsImport
117+
}
97118
'/_docs/komponenter/': {
98119
id: '/_docs/komponenter/'
99120
path: '/komponenter'
100121
fullPath: '/komponenter'
101122
preLoaderRoute: typeof DocsKomponenterIndexImport
102123
parentRoute: typeof DocsImport
103124
}
125+
'/_docs/profil/': {
126+
id: '/_docs/profil/'
127+
path: '/profil'
128+
fullPath: '/profil'
129+
preLoaderRoute: typeof DocsProfilIndexImport
130+
parentRoute: typeof DocsImport
131+
}
104132
}
105133
}
106134

107135
// Create and export the route tree
108136

109137
interface DocsRouteChildren {
110-
DocsIkonerRoute: typeof DocsIkonerRoute
111138
DocsIndexRoute: typeof DocsIndexRoute
112139
DocsKomponenterSlugRoute: typeof DocsKomponenterSlugRoute
140+
DocsProfilFargerRoute: typeof DocsProfilFargerRoute
141+
DocsProfilIkonerRoute: typeof DocsProfilIkonerRoute
113142
DocsKomponenterIndexRoute: typeof DocsKomponenterIndexRoute
143+
DocsProfilIndexRoute: typeof DocsProfilIndexRoute
114144
}
115145

116146
const DocsRouteChildren: DocsRouteChildren = {
117-
DocsIkonerRoute: DocsIkonerRoute,
118147
DocsIndexRoute: DocsIndexRoute,
119148
DocsKomponenterSlugRoute: DocsKomponenterSlugRoute,
149+
DocsProfilFargerRoute: DocsProfilFargerRoute,
150+
DocsProfilIkonerRoute: DocsProfilIkonerRoute,
120151
DocsKomponenterIndexRoute: DocsKomponenterIndexRoute,
152+
DocsProfilIndexRoute: DocsProfilIndexRoute,
121153
}
122154

123155
const DocsRouteWithChildren = DocsRoute._addFileChildren(DocsRouteChildren)
124156

125157
export interface FileRoutesByFullPath {
126158
'': typeof DocsRouteWithChildren
127-
'/ikoner': typeof DocsIkonerRoute
128159
'/studio/$': typeof StudioSplatRoute
129160
'/': typeof DocsIndexRoute
130161
'/komponenter/$slug': typeof DocsKomponenterSlugRoute
162+
'/profil/farger': typeof DocsProfilFargerRoute
163+
'/profil/ikoner': typeof DocsProfilIkonerRoute
131164
'/komponenter': typeof DocsKomponenterIndexRoute
165+
'/profil': typeof DocsProfilIndexRoute
132166
}
133167

134168
export interface FileRoutesByTo {
135-
'/ikoner': typeof DocsIkonerRoute
136169
'/studio/$': typeof StudioSplatRoute
137170
'/': typeof DocsIndexRoute
138171
'/komponenter/$slug': typeof DocsKomponenterSlugRoute
172+
'/profil/farger': typeof DocsProfilFargerRoute
173+
'/profil/ikoner': typeof DocsProfilIkonerRoute
139174
'/komponenter': typeof DocsKomponenterIndexRoute
175+
'/profil': typeof DocsProfilIndexRoute
140176
}
141177

142178
export interface FileRoutesById {
143179
__root__: typeof rootRoute
144180
'/_docs': typeof DocsRouteWithChildren
145-
'/_docs/ikoner': typeof DocsIkonerRoute
146181
'/studio/$': typeof StudioSplatRoute
147182
'/_docs/': typeof DocsIndexRoute
148183
'/_docs/komponenter/$slug': typeof DocsKomponenterSlugRoute
184+
'/_docs/profil/farger': typeof DocsProfilFargerRoute
185+
'/_docs/profil/ikoner': typeof DocsProfilIkonerRoute
149186
'/_docs/komponenter/': typeof DocsKomponenterIndexRoute
187+
'/_docs/profil/': typeof DocsProfilIndexRoute
150188
}
151189

152190
export interface FileRouteTypes {
153191
fileRoutesByFullPath: FileRoutesByFullPath
154192
fullPaths:
155193
| ''
156-
| '/ikoner'
157194
| '/studio/$'
158195
| '/'
159196
| '/komponenter/$slug'
197+
| '/profil/farger'
198+
| '/profil/ikoner'
160199
| '/komponenter'
200+
| '/profil'
161201
fileRoutesByTo: FileRoutesByTo
162-
to: '/ikoner' | '/studio/$' | '/' | '/komponenter/$slug' | '/komponenter'
202+
to:
203+
| '/studio/$'
204+
| '/'
205+
| '/komponenter/$slug'
206+
| '/profil/farger'
207+
| '/profil/ikoner'
208+
| '/komponenter'
209+
| '/profil'
163210
id:
164211
| '__root__'
165212
| '/_docs'
166-
| '/_docs/ikoner'
167213
| '/studio/$'
168214
| '/_docs/'
169215
| '/_docs/komponenter/$slug'
216+
| '/_docs/profil/farger'
217+
| '/_docs/profil/ikoner'
170218
| '/_docs/komponenter/'
219+
| '/_docs/profil/'
171220
fileRoutesById: FileRoutesById
172221
}
173222

@@ -198,16 +247,14 @@ export const routeTree = rootRoute
198247
"/_docs": {
199248
"filePath": "_docs.tsx",
200249
"children": [
201-
"/_docs/ikoner",
202250
"/_docs/",
203251
"/_docs/komponenter/$slug",
204-
"/_docs/komponenter/"
252+
"/_docs/profil/farger",
253+
"/_docs/profil/ikoner",
254+
"/_docs/komponenter/",
255+
"/_docs/profil/"
205256
]
206257
},
207-
"/_docs/ikoner": {
208-
"filePath": "_docs/ikoner.tsx",
209-
"parent": "/_docs"
210-
},
211258
"/studio/$": {
212259
"filePath": "studio/$.tsx"
213260
},
@@ -219,9 +266,21 @@ export const routeTree = rootRoute
219266
"filePath": "_docs/komponenter/$slug.tsx",
220267
"parent": "/_docs"
221268
},
269+
"/_docs/profil/farger": {
270+
"filePath": "_docs/profil/farger.tsx",
271+
"parent": "/_docs"
272+
},
273+
"/_docs/profil/ikoner": {
274+
"filePath": "_docs/profil/ikoner.tsx",
275+
"parent": "/_docs"
276+
},
222277
"/_docs/komponenter/": {
223278
"filePath": "_docs/komponenter/index.tsx",
224279
"parent": "/_docs"
280+
},
281+
"/_docs/profil/": {
282+
"filePath": "_docs/profil/index.tsx",
283+
"parent": "/_docs"
225284
}
226285
}
227286
}

apps/docs/app/routes/_docs/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ function Home() {
1818
</Card>
1919
<Card variant="outlined">
2020
<Heading level={2}>
21-
<CardLink href="/ikoner">Ikoner</CardLink>
21+
<CardLink href="/profil">Profil</CardLink>
2222
</Heading>
23-
Utforsk ikonsettet vårt
23+
Utforsk profilen vår
2424
</Card>
2525
</div>
2626
</>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { useLayoutEffect } from '@react-aria/utils';
2+
import { createFileRoute } from '@tanstack/react-router';
3+
import { useState } from 'react';
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: [
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { sanityFetch } from '@/lib/sanity';
2+
import { Card, CardLink, Heading } from '@obosbbl/grunnmuren-react';
3+
import { createFileRoute } from '@tanstack/react-router';
4+
import { defineQuery } from 'groq';
5+
6+
const COMPONENTS_INDEX_QUERY = defineQuery(
7+
// make sure the slug is always a string so we don't have add fallback value in code just to make TypeScript happy
8+
`*[_type == "component"]{ _id, name, 'slug': coalesce(slug.current, '')} | order(name asc)`,
9+
);
10+
11+
export const Route = createFileRoute('/_docs/profil/')({
12+
component: Page,
13+
head: () => ({
14+
meta: [
15+
{ title: 'Profil - Grunnmuren' },
16+
{ name: 'description', content: 'Grunnmuren sin grafiske profil' },
17+
],
18+
}),
19+
loader: () => sanityFetch({ query: COMPONENTS_INDEX_QUERY }),
20+
});
21+
22+
function Page() {
23+
return (
24+
<>
25+
<h1 className="heading-l mb-12 mt-9">Profil</h1>
26+
<div className="grid grid-cols-2 gap-4">
27+
<Card variant="outlined">
28+
<Heading level={2}>
29+
<CardLink href="/profil/farger">Farger</CardLink>
30+
</Heading>
31+
Se alle fargene våre
32+
</Card>
33+
<Card variant="outlined">
34+
<Heading level={2}>
35+
<CardLink href="/profil/ikoner">Ikoner</CardLink>
36+
</Heading>
37+
Utforsk ikonsettet vårt
38+
</Card>
39+
</div>
40+
</>
41+
);
42+
}

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
],

0 commit comments

Comments
 (0)