Skip to content

Commit fcf5224

Browse files
authored
docs: fix weird default state showing dark and light elements. (#1179)
1 parent 7a338c6 commit fcf5224

File tree

11 files changed

+512
-483
lines changed

11 files changed

+512
-483
lines changed

site/docs/playground.mdx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ sidebar_position: 3
66

77
[@wirekang](https://github.com/wirekang) has created a [playground for Kysely](https://kyse.link). You can use it to quickly test stuff out and for creating code examples for your issues, PRs and Discord messages.
88

9-
import { Playground, exampleFilterById } from '../src/components/Playground'
9+
import { Playground } from '../src/components/Playground'
1010

11-
<Playground code={exampleFilterById} />
11+
<Playground
12+
code={`const person = await db
13+
.selectFrom('person')
14+
.select(['id', 'first_name'])
15+
.where('id', '=', '1')
16+
.executeTakeFirst()
17+
`}
18+
/>
1219

1320
## Codesandbox
1421

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.playground {
2+
border: 1px solid var(--gray3);
3+
border-radius: 7px;
4+
min-height: 600px;
5+
width: 100%;
6+
}

site/src/components/Playground.tsx

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,56 @@
11
import { useColorMode } from '@docusaurus/theme-common'
2+
import { useEffect, useState } from 'react'
3+
import styles from './Playground.module.css'
24

3-
export function Playground({
4-
code,
5-
setupCode = exampleSetup,
6-
kyselyVersion,
7-
dialect = 'postgres',
8-
disableIframeMode = false,
9-
}: PlaygroundProps) {
10-
const { isDarkTheme } = useColorMode()
5+
export function Playground(props: PlaygroundProps) {
6+
const src = useSrc(props)
7+
8+
return (
9+
<iframe
10+
allow="clipboard-write"
11+
autoFocus
12+
className={styles.playground}
13+
src={src}
14+
/>
15+
)
16+
}
17+
18+
function useSrc(props: PlaygroundProps) {
19+
const { colorMode } = useColorMode()
20+
const [src, setSrc] = useState('')
21+
22+
useEffect(() => {
23+
const params = new URLSearchParams()
24+
25+
params.set('theme', colorMode)
26+
params.set('notheme', '1')
27+
28+
if (!props.disableIframeMode) {
29+
params.set('open', '1')
30+
params.set('nomore', '1')
31+
params.set('nohotkey', '1')
32+
}
33+
34+
setSrc(`https://kyse.link/?${params}${getPlaygroundStateHash(props)}`)
35+
}, [colorMode])
36+
37+
return src
38+
}
39+
40+
function getPlaygroundStateHash(props: PlaygroundProps) {
41+
const { kyselyVersion } = props
1142

1243
const state: PlaygroundState = {
13-
dialect,
14-
editors: { query: code, type: setupCode },
44+
dialect: props.dialect || 'postgres',
45+
editors: { query: props.code, type: props.setupCode || exampleSetup },
1546
hideType: true,
1647
}
48+
1749
if (kyselyVersion) {
1850
state.kysely = { type: 'tag', name: kyselyVersion }
1951
}
20-
const params = new URLSearchParams()
21-
params.set('theme', isDarkTheme ? 'dark' : 'light')
22-
if (!disableIframeMode) {
23-
params.set('open', '1')
24-
params.set('nomore', '1')
25-
params.set('notheme', '1')
26-
params.set('nohotkey', '1')
27-
}
28-
const hash = '#r' + encodeURIComponent(JSON.stringify(state))
2952

30-
return (
31-
<iframe
32-
style={{
33-
width: '100%',
34-
minHeight: '600px',
35-
borderRadius: 7,
36-
border: isDarkTheme ? undefined : '1px solid var(--gray3)',
37-
}}
38-
allow="clipboard-write"
39-
src={`https://kyse.link/?${params}${hash}`}
40-
/>
41-
)
53+
return '#r' + encodeURIComponent(JSON.stringify(state))
4254
}
4355

4456
interface PlaygroundProps {
@@ -85,10 +97,3 @@ interface PetTable {
8597
is_favorite: boolean
8698
}
8799
`
88-
89-
export const exampleFilterById = `const person = await db
90-
.selectFrom('person')
91-
.select(['id', 'first_name'])
92-
.where('id', '=', '1')
93-
.executeTakeFirst()
94-
`

site/src/components/SectionFeatures/index.tsx

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { useColorMode } from '@docusaurus/theme-common'
2-
import { gray } from '@radix-ui/colors'
31
import type { SVGProps } from 'react'
42
import clsx from 'clsx'
53
import styles from './styles.module.css'
@@ -52,7 +50,6 @@ const FeatureList: FeatureItem[] = [
5250
</>
5351
),
5452
},
55-
5653
{
5754
title: 'Runs on every environment',
5855

@@ -93,39 +90,16 @@ function TickIcon(props: SVGProps<SVGSVGElement>) {
9390
}
9491

9592
function Feature({ title, description }: FeatureItem) {
96-
const { isDarkTheme } = useColorMode()
97-
9893
return (
9994
<div className={clsx('col col--6')} style={{ padding: 10 }}>
10095
<div className="padding-horiz--md">
101-
<h3
102-
style={{
103-
color: isDarkTheme ? gray.gray4 : gray.gray12,
104-
display: 'inline-flex',
105-
alignItems: 'center',
106-
gap: 8,
107-
}}
108-
>
109-
<span
110-
style={{
111-
display: 'grid',
112-
placeItems: 'center',
113-
color: 'red',
114-
width: 20,
115-
height: 20,
116-
fontSize: 12,
117-
background: 'var(--sky7)',
118-
borderRadius: 100,
119-
border: `1px solid var(--sky10)`,
120-
}}
121-
>
122-
<TickIcon style={{ width: 12, height: 12, fill: 'var(--sky12)' }} />
96+
<h3 className={styles.featureTitle}>
97+
<span className={styles.tickContainer}>
98+
<TickIcon className={styles.tickIcon} />
12399
</span>
124100
{title}
125101
</h3>
126-
<p style={{ color: isDarkTheme ? gray.gray8 : gray.gray11 }}>
127-
{description}
128-
</p>
102+
<p className={styles.featureDescription}>{description}</p>
129103
</div>
130104
</div>
131105
)

site/src/components/SectionFeatures/styles.module.css

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,47 @@
22
display: flex;
33
align-items: center;
44
width: 100%;
5-
background: transparent;
65
position: relative;
76
min-height: 80vh;
87
padding: 64px 0;
98
}
9+
10+
[data-theme='dark'] .features {
11+
background-color: var(--gray12);
12+
}
13+
14+
.featureTitle {
15+
align-items: center;
16+
color: var(--gray12);
17+
display: inline-flex;
18+
gap: 8px;
19+
}
20+
21+
[data-theme='dark'] .featureTitle {
22+
color: var(--gray4);
23+
}
24+
25+
.tickContainer {
26+
background-color: var(--sky7);
27+
border: 1px solid var(--sky10);
28+
border-radius: 100%;
29+
display: grid;
30+
font-size: 12px;
31+
height: 20px;
32+
place-items: center;
33+
width: 20px;
34+
}
35+
36+
.tickIcon {
37+
height: 12px;
38+
fill: var(--sky12);
39+
width: 12px;
40+
}
41+
42+
.featureDescription {
43+
color: var(--gray11);
44+
}
45+
46+
[data-theme='dark'] .featureDescription {
47+
color: var(--gray8);
48+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import clsx from 'clsx'
2+
import type { ReactElement } from 'react'
3+
4+
import styles from './styles.module.css'
5+
6+
export interface QuoteProps {
7+
avatar: string
8+
authorName: string
9+
authorTitle: string
10+
link: string
11+
text: string
12+
}
13+
14+
const domainNameToIcon: Record<string, ReactElement> = {
15+
twitter: <TwitterIcon />,
16+
discord: <DiscordIcon />,
17+
github: <GithubIcon />,
18+
}
19+
20+
export function Quote(props: QuoteProps) {
21+
const { authorName, authorTitle, avatar, link, text } = props
22+
23+
const [, domainName] = link.toLowerCase().match(/https?:\/\/(?:www\.)?(.+)\./)
24+
25+
return (
26+
<a className={styles.quoteContainer} href={link} target="_blank">
27+
{domainNameToIcon[domainName] || null}
28+
<div className={styles.quoteInnerContainer}>
29+
<img
30+
alt={`${authorName}'s avatar picture`}
31+
className="avatar__photo"
32+
src={avatar}
33+
/>
34+
<div className={styles.quoteHeader}>
35+
<span className={styles.quoteTitle}>{authorName}</span>
36+
<small className={styles.quoteSubtitle}>{authorTitle}</small>
37+
</div>
38+
</div>
39+
40+
<small className={styles.quoteText}>{text}</small>
41+
</a>
42+
)
43+
}
44+
45+
function TwitterIcon() {
46+
return (
47+
<svg
48+
aria-hidden="true"
49+
className={clsx(styles.icon, styles.twitterIcon)}
50+
viewBox="0 0 24 24"
51+
>
52+
<g>
53+
<path d="M23.643 4.937c-.835.37-1.732.62-2.675.733.962-.576 1.7-1.49 2.048-2.578-.9.534-1.897.922-2.958 1.13-.85-.904-2.06-1.47-3.4-1.47-2.572 0-4.658 2.086-4.658 4.66 0 .364.042.718.12 1.06-3.873-.195-7.304-2.05-9.602-4.868-.4.69-.63 1.49-.63 2.342 0 1.616.823 3.043 2.072 3.878-.764-.025-1.482-.234-2.11-.583v.06c0 2.257 1.605 4.14 3.737 4.568-.392.106-.803.162-1.227.162-.3 0-.593-.028-.877-.082.593 1.85 2.313 3.198 4.352 3.234-1.595 1.25-3.604 1.995-5.786 1.995-.376 0-.747-.022-1.112-.065 2.062 1.323 4.51 2.093 7.14 2.093 8.57 0 13.255-7.098 13.255-13.254 0-.2-.005-.402-.014-.602.91-.658 1.7-1.477 2.323-2.41z" />
54+
</g>
55+
</svg>
56+
)
57+
}
58+
59+
function DiscordIcon() {
60+
return (
61+
<svg
62+
aria-hidden="true"
63+
className={styles.icon}
64+
preserveAspectRatio="xMidYMid"
65+
version="1.1"
66+
viewBox="0 -28.5 256 256"
67+
xmlns="http://www.w3.org/2000/svg"
68+
>
69+
<g>
70+
<path
71+
d="M216.856339,16.5966031 C200.285002,8.84328665 182.566144,3.2084988 164.041564,0 C161.766523,4.11318106 159.108624,9.64549908 157.276099,14.0464379 C137.583995,11.0849896 118.072967,11.0849896 98.7430163,14.0464379 C96.9108417,9.64549908 94.1925838,4.11318106 91.8971895,0 C73.3526068,3.2084988 55.6133949,8.86399117 39.0420583,16.6376612 C5.61752293,67.146514 -3.4433191,116.400813 1.08711069,164.955721 C23.2560196,181.510915 44.7403634,191.567697 65.8621325,198.148576 C71.0772151,190.971126 75.7283628,183.341335 79.7352139,175.300261 C72.104019,172.400575 64.7949724,168.822202 57.8887866,164.667963 C59.7209612,163.310589 61.5131304,161.891452 63.2445898,160.431257 C105.36741,180.133187 151.134928,180.133187 192.754523,160.431257 C194.506336,161.891452 196.298154,163.310589 198.110326,164.667963 C191.183787,168.842556 183.854737,172.420929 176.223542,175.320965 C180.230393,183.341335 184.861538,190.991831 190.096624,198.16893 C211.238746,191.588051 232.743023,181.531619 254.911949,164.955721 C260.227747,108.668201 245.831087,59.8662432 216.856339,16.5966031 Z M85.4738752,135.09489 C72.8290281,135.09489 62.4592217,123.290155 62.4592217,108.914901 C62.4592217,94.5396472 72.607595,82.7145587 85.4738752,82.7145587 C98.3405064,82.7145587 108.709962,94.5189427 108.488529,108.914901 C108.508531,123.290155 98.3405064,135.09489 85.4738752,135.09489 Z M170.525237,135.09489 C157.88039,135.09489 147.510584,123.290155 147.510584,108.914901 C147.510584,94.5396472 157.658606,82.7145587 170.525237,82.7145587 C183.391518,82.7145587 193.761324,94.5189427 193.539891,108.914901 C193.539891,123.290155 183.391518,135.09489 170.525237,135.09489 Z"
72+
fill="#5865F2"
73+
fill-rule="nonzero"
74+
/>
75+
</g>
76+
</svg>
77+
)
78+
}
79+
80+
function GithubIcon() {
81+
return (
82+
<svg
83+
aria-hidden="true"
84+
className={styles.icon}
85+
viewBox="0 0 98 96"
86+
xmlns="http://www.w3.org/2000/svg"
87+
>
88+
<path
89+
fill-rule="evenodd"
90+
clip-rule="evenodd"
91+
d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z"
92+
fill="#fff"
93+
/>
94+
</svg>
95+
)
96+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import clsx from 'clsx'
2+
3+
import { Quote } from './Quote'
4+
import { quotes } from './quotes'
5+
import styles from './styles.module.css'
6+
7+
export function SectionQuotes() {
8+
return (
9+
<section className={styles.quotesSection}>
10+
<div className={clsx('container', styles.quotesContainer)}>
11+
<h1>What the internet is saying</h1>
12+
<p>Developers are loving Kysely for its simplicity and power.</p>
13+
<div className={styles.quotesInnerContainer}>
14+
{quotes.map((quote, index) => (
15+
<Quote key={index} {...quote} />
16+
))}
17+
</div>
18+
</div>
19+
</section>
20+
)
21+
}

0 commit comments

Comments
 (0)