From dc0df83f10146c219deca1bbfc502c7a8a460c66 Mon Sep 17 00:00:00 2001 From: Nicco Date: Mon, 6 Jan 2020 23:19:43 +0100 Subject: [PATCH 1/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1240aec..8990490 100755 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ - Typescript compatible - **0** Dependencies -- Tiny **~0.7kB** +- Tiny **~0.4kB** - React Hooks ###### Installation From 7f38f5f97762b8288fbe5b5369867b48d5f4d1c9 Mon Sep 17 00:00:00 2001 From: Nicco Date: Mon, 6 Jan 2020 23:27:22 +0100 Subject: [PATCH 2/5] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8990490..74ed45f 100755 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ npm i use-light-switch ## 🤔 Motivation -There was no library with typings 🤕 +There was no library that included typings 🤕 ## 🚀 Quickstart @@ -38,7 +38,7 @@ const App: React.FC = () => { }) return
-

Selector

+

Try switching your dark mode in macOS or Windows

Date: Mon, 6 Jan 2020 23:37:23 +0100 Subject: [PATCH 3/5] Update README.md --- README.md | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/README.md b/README.md index 74ed45f..c903c3b 100755 --- a/README.md +++ b/README.md @@ -50,3 +50,88 @@ const App: React.FC = () => { ReactDOM.render(, window.document.getElementById('root')) ``` + +## 📒 Reference + +### `useLightSwitch()` + +This is the most basic react hook. It returns one of 3 [Modes](#mode) + +###### Example + +```typescript +import { Mode, useLightSwitch } from 'use-light-switch' + + +const Simple: React.FC = () => { + const mode = useLightSwitch() + + if (mode === Mode.Dark) ... + + return ... +} +``` + + +### Mode + +A simple enum. Possible values are: + +- `Mode.Light` +- `Mode.Dark` +- `Mode.Unset` + +`Unset` is returned when the user has no explicit preference. This is often the case with older or if it's simply unsupported. + +### `useModeSelector(options)` + +This is a handy hook that reduces boilerplate. You pass values for the different modes and the hook will choose accordingly to what is currently selected. uses [`modeSelector`](#modeSelector) under the hood. + +###### Example + +```typescript +import { useModeSelector } from 'use-light-switch' + +const WithSelector: React.FC = () => { + + const selected = useModeSelector({ + light: { color: 'green', name: 'Light' }, + dark: { color: 'red', name: 'Dark' }, + unset: { color: 'blue', name: 'Unset' }, + }) + + return
+

Selector

+
+ {selected.name} +
+
+} +``` + +All parameters are optional and typesafe. + +### `modeSelector(mode, options)` + +This is a simple functions that returns the matched option to the mode. + +###### Example + +```typescript +import { Mode, modeSelector } from 'use-light-switch' + +const selected = modeSelector( + Mode.Dark, + { + light: { color: 'green', name: 'Light' }, + dark: { color: 'red', name: 'Dark' }, + unset: { color: 'blue', name: 'Unset' }, + } +) + +selected.color // red +selected.name // Dark +``` From 972aaec90a6c8498cd2a2464f4b8193b33e8673b Mon Sep 17 00:00:00 2001 From: Nicco Date: Mon, 6 Jan 2020 23:37:52 +0100 Subject: [PATCH 4/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c903c3b..7add4c5 100755 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ A simple enum. Possible values are: ### `useModeSelector(options)` -This is a handy hook that reduces boilerplate. You pass values for the different modes and the hook will choose accordingly to what is currently selected. uses [`modeSelector`](#modeSelector) under the hood. +This is a handy hook that reduces boilerplate. You pass values for the different modes and the hook will choose accordingly to what is currently selected. uses [`modeSelector`](#modeselectormode-options) under the hood. ###### Example From 9bf896e3ba80fcbfda53c7aa09afa64ad0d13cb7 Mon Sep 17 00:00:00 2001 From: Nicco Date: Mon, 6 Jan 2020 23:38:40 +0100 Subject: [PATCH 5/5] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7add4c5..d40459e 100755 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ npm i use-light-switch ``` +## 💻 [Live Example](https://codesandbox.io/s/simple-wbpgp) + ## 🤔 Motivation There was no library that included typings 🤕