Skip to content
This repository was archived by the owner on Feb 3, 2024. It is now read-only.

Commit 38a28e0

Browse files
committed
better docs
1 parent 6c2d2d1 commit 38a28e0

6 files changed

Lines changed: 47 additions & 29 deletions

File tree

packages/docs/index.css

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@
7676
}
7777

7878
body {
79-
padding-top: 1rem;
80-
padding-left: 0.5rem;
81-
padding-right: 0.5rem;
79+
padding: 0.5rem;
8280
margin: 0 auto;
8381
}
8482

@@ -113,12 +111,7 @@ button {
113111

114112
a.badge {
115113
text-decoration: none;
116-
}
117-
118-
a.badge svg {
119-
height: 20px;
120114
display: inline-block;
121-
margin: 0;
122115
}
123116

124117
a.badge svg .background {
@@ -129,14 +122,21 @@ a.badge svg .text {
129122
fill: var(--background);
130123
}
131124

132-
.npm {
133-
margin-right: 4px;
134-
}
135-
136125
.prose pre {
137126
background: var(--color);
138127
}
139128

140129
.prose pre code {
141130
color: var(--background);
142131
}
132+
133+
.header {
134+
display: flex;
135+
flex-direction: row;
136+
justify-content: space-between;
137+
margin-bottom: 1rem;
138+
}
139+
140+
.header h1 {
141+
margin: 0;
142+
}

packages/docs/index.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,27 @@ const changeFavicon = (src) => {
1313
const { mode } = window.__perfect_dark_mode__
1414

1515
// Get some elements we will use.
16-
const toggleElement = document.getElementById('toggle')
16+
const toggleElements = document.querySelectorAll('.toggle')
1717

1818
// Listen to the color mode and update the UI.
1919
mode.subscribe((v) => {
20-
toggleElement.textContent = v === 'dark' ? '🌚 Dark' : '🌝 Light'
20+
toggleElements.forEach(
21+
(el) => (el.textContent = v === 'dark' ? '🌚 Dark' : '🌝 Light'),
22+
)
2123
changeFavicon(v === 'dark' ? 'moon.png' : 'sun.png')
2224
})
2325

2426
// At this point our callback will have been called,
2527
// so the checkbox state and text will be correct and we can show them.
26-
toggleElement.style.visibility = 'unset'
28+
toggleElements.forEach((el) => (el.style.visibility = 'unset'))
29+
30+
// When the checkbox is clicked we update the mode.
31+
// Our listener above will do the rest.
32+
toggleElements.forEach((el) => {
33+
el.addEventListener('click', (e) =>
34+
mode.update((v) => (v === 'light' ? 'dark' : 'light')),
35+
)
36+
})
2737

2838
// We want to make sure that if the OS mode is 'light'
2939
// and the saved mode is 'dark' that we do not transition
@@ -37,12 +47,6 @@ requestAnimationFrame(() =>
3747
),
3848
)
3949

40-
// When the checkbox is clicked we update the mode.
41-
// Our listener above will do the rest.
42-
toggleElement.addEventListener('click', (e) =>
43-
mode.update((v) => (v === 'light' ? 'dark' : 'light')),
44-
)
45-
4650
const button = document.getElementById('button')
4751

4852
button.addEventListener('click', () => mode.set(undefined))

packages/docs/index.pug

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include ./badge
2+
include ./simpleBadge
23
doctype html
34
html
45
head
@@ -11,12 +12,17 @@ html
1112
style
1213
include ./index.css
1314
body.prose
14-
h1 🌚🌝 Perfect Dark Mode - <a href="https://github.com/DylanVann/perfect-dark-mode">GitHub</a>
15+
div.header
16+
h1 🌚🌝 Perfect Dark Mode
17+
button.toggle(style="visibility: hidden;") 🌝 color mode
1518

16-
a.badge.npm(href='https://www.npmjs.com/package/perfect-dark-mode')
17-
+badge("npm", version)
18-
a.badge.size(href='https://bundlephobia.com/result?p=perfect-dark-mode')
19-
+badge("size", size)
19+
div.flex.space-x-4
20+
a.badge(href='https://www.npmjs.com/package/perfect-dark-mode')
21+
+badge("npm", version)
22+
a.badge(href='https://bundlephobia.com/result?p=perfect-dark-mode')
23+
+badge("size", size)
24+
a.badge(href="https://github.com/DylanVann/perfect-dark-mode")
25+
+simpleBadge("GitHub")
2026

2127
include:markdown-it features.md
2228

@@ -34,7 +40,7 @@ html
3440
// For users with JS disabled there will not be a color mode toggle, they can change
3541
// their system color mode.
3642
p You can set the color mode, this will be saved.
37-
button(id="toggle" style="visibility: hidden;") 🌝 color mode
43+
button.toggle(style="visibility: hidden;") 🌝 color mode
3844
p You can reset the color mode and fallback to system color mode.
3945
button(id="button") Reset
4046
p For debugging and understanding here is the saved color mode and the OS color mode.

packages/docs/postcss.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = {
1616
tailwindcss('./tailwind.config.js'),
1717
production &&
1818
purgecss({
19-
content: ['dist/index.html', 'index.js'],
19+
content: ['index.pug', 'index.js'],
2020
defaultExtractor: (content) => content.match(/[A-Za-z0-9-_:/]+/g) || [],
2121
}),
2222
production && cssnano({ preset: 'default' }),

packages/docs/simpleBadge.pug

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
mixin simpleBadge(text)
2+
svg(xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='80' height='20' role='img' aria-label='#{name}: #{text}')
3+
title #{text}
4+
g(clip-path='url(#r)')
5+
rect(width='80' height='20' fill='black' class="background")
6+
g(fill='#fff' text-anchor='middle' font-family='Verdana,Geneva,DejaVu Sans,sans-serif' text-rendering='geometricPrecision' font-size='110')
7+
text(aria-hidden='true' x='400' y='150' fill='#010101' fill-opacity='.3' transform='scale(.1)' textlength='350') #{text}
8+
text(x='400' y='140' transform='scale(.1)' fill='#fff' textlength='350' class="text") #{text}

packages/docs/tailwind.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ const typographyTheme = {
11111111
const theme = merge({}, typographyTheme, defaultTheme)
11121112

11131113
module.exports = {
1114-
purge: ['dist/index.html', 'index.js'],
1114+
purge: ['index.pug', 'index.js'],
11151115
future: {
11161116
defaultLineHeights: true,
11171117
purgeLayersByDefault: true,

0 commit comments

Comments
 (0)