Skip to content

Commit b29e0c9

Browse files
committed
🔨 Fix dev script
1 parent f8fd95c commit b29e0c9

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ const darkmode = new Darkmode(options)
200200

201201
### Basic
202202

203+
[View example file](https://github.com/BetaHuhn/drkmd.js/blob/master/examples/basic/index.html)
204+
203205
Render the darkmode toggle with all the default options.
204206

205207
Import [drkmd.js](https://github.com/BetaHuhn/drkmd.js) like this:
@@ -236,6 +238,8 @@ Then specify the styles for the light and dark theme:
236238

237239
### CSS variables
238240

241+
[View example file](https://github.com/BetaHuhn/drkmd.js/blob/master/examples/css-variables/index.html)
242+
239243
If you want to specify different colors for each theme, you can use [css-variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties):
240244

241245
**CSS**
@@ -263,6 +267,8 @@ body {
263267

264268
### With options
265269

270+
[View example file](https://github.com/BetaHuhn/drkmd.js/blob/master/examples/options/index.html)
271+
266272
Render the darkmode toggle with custom options:
267273

268274
**HTML**
@@ -289,6 +295,8 @@ new Darkmode(options).attach()
289295

290296
### Custom darkmode toggle
291297

298+
[View example file](https://github.com/BetaHuhn/drkmd.js/blob/master/examples/custom-toggle/index.html)
299+
292300
Don't render the darkmode toggle, instead change the theme when a custom HTML element is clicked.
293301

294302
Import [drkmd.js](https://github.com/BetaHuhn/drkmd.js) like this:
@@ -321,6 +329,8 @@ There's also `data-drkmd-to-light` and `data-drkmd-to-dark` which will change th
321329

322330
### Different images depending on the theme
323331

332+
[View example file](https://github.com/BetaHuhn/drkmd.js/blob/master/examples/events/index.html)
333+
324334
You can use the `theme-change` [event](#events) to modify an element with JavaScript. Here we are changing the `src` attribute of an `img` tag when the theme changes:
325335

326336
**HTML**
@@ -347,6 +357,8 @@ window.addEventListener('theme-change', e => {
347357

348358
### Programmatic usage
349359

360+
[View example file](https://github.com/BetaHuhn/drkmd.js/blob/master/examples/programmatic/index.html)
361+
350362
You can also control the theme programmatically.
351363

352364
Import [drkmd.js](https://github.com/BetaHuhn/drkmd.js) like this:
@@ -365,18 +377,29 @@ or
365377
import Darkmode from 'drkmd-js'
366378
```
367379

380+
Add HTML elements:
381+
382+
```html
383+
<button id="myBtn">Click me</button>
384+
<span id="theme">Current theme:</span>
385+
```
386+
368387
Then create a new Darkmode instance and use any of the available methods:
369388

370389
```js
371390
const darkmode = new Darkmode()
372391

392+
const updateValue = () => {
393+
document.getElementById('theme').innerText = `Current theme: ${ darkmode.currentTheme() }`
394+
}
395+
373396
document.getElementById('myBtn').addEventListener('click', () => {
374-
if (darkmode.isDark()) {
375-
// Do something
376-
}
397+
darkmode.toggle()
377398

378-
darkmode.toLight()
399+
updateValue()
379400
})
401+
402+
updateValue()
380403
```
381404

382405
## 🌍 Browser compatibility

examples/programmatic/index.html

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<body>
3030
<h1>Darkmode example</h1>
3131
<button id="myBtn">Click me</button>
32-
<span id="theme"></span>
32+
<span id="theme">Current theme:</span>
3333
</body>
3434

3535
<script src="https://cdn.jsdelivr.net/npm/drkmd-js/dist/drkmd-js.min.js" ></script>
@@ -46,14 +46,10 @@ <h1>Darkmode example</h1>
4646
const darkmode = new Darkmode()
4747

4848
const updateValue = () => {
49-
document.getElementById('theme').value = `Current theme: ${ darkmode.currentTheme() }`
49+
document.getElementById('theme').innerText = `Current theme: ${ darkmode.currentTheme() }`
5050
}
5151

5252
document.getElementById('myBtn').addEventListener('click', () => {
53-
if (darkmode.isDark()) {
54-
// Do something
55-
}
56-
5753
darkmode.toggle()
5854

5955
updateValue()

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "dist/drkmd-js.min.js",
66
"scripts": {
77
"lint": "eslint ./src/",
8-
"dev": "watch 'npm run build' ./src/ ./example/ --interval=1",
8+
"dev": "watch 'npm run build' ./src/ ./examples/ --interval=1",
99
"build": "node build.js",
1010
"semantic-release": "semantic-release"
1111
},

0 commit comments

Comments
 (0)