use-light-switch/README.md
2020-01-06 23:27:22 +01:00

53 lines
1.1 KiB
Markdown
Executable File

# use-light-switch
![Version](https://badgen.net/npm/v/use-light-switch)
![Dependencies](https://badgen.net/david/dep/cupcakearmy/use-light-switch)
![Size Badge](https://badgen.net/bundlephobia/minzip/use-light-switch)
**React hook for dark mode.**
## 🌈 Features
- Typescript compatible
- **0** Dependencies
- Tiny **~0.4kB**
- React Hooks
###### Installation
```
npm i use-light-switch
```
## 🤔 Motivation
There was no library that included typings 🤕
## 🚀 Quickstart
```typescript
import React from 'react'
import ReactDOM from 'react-dom'
import { useModeSelector } from 'use-light-switch'
const App: React.FC = () => {
const selected = useModeSelector({
light: { color: 'green', name: 'Light' },
dark: { color: 'red', name: 'Dark' },
unset: { color: 'blue', name: 'Unset' },
})
return <div>
<p>Try switching your dark mode in macOS or Windows</p>
<div style={{
padding: '1em 2em',
backgroundColor: selected.color
}}>
{selected.name}
</div>
</div>
}
ReactDOM.render(<App />, window.document.getElementById('root'))
```