|
|
@ -1,4 +1,6 @@ |
|
|
|
import React from 'react'; |
|
|
|
import React, { useRef, useState, useEffect } from 'react'; |
|
|
|
|
|
|
|
import { EmojiButton } from '@joeattardi/emoji-button'; |
|
|
|
|
|
|
|
import DocLayout from '../../components/DocLayout'; |
|
|
|
import Example from '../../components/Example'; |
|
|
@ -7,8 +9,38 @@ import SourceFile from '../../components/SourceFile'; |
|
|
|
import lightExample from '!!raw-loader!../../examples/themes/light.js'; |
|
|
|
import darkExample from '!!raw-loader!../../examples/themes/dark.js'; |
|
|
|
import autoExample from '!!raw-loader!../../examples/themes/auto.js'; |
|
|
|
import switchExample from '!!raw-loader!../../examples/themes/switch-theme.js'; |
|
|
|
|
|
|
|
import styles from './plugins.module.css'; |
|
|
|
|
|
|
|
export default function ThemesExample() { |
|
|
|
|
|
|
|
const buttonRef = useRef(); |
|
|
|
const [picker, setPicker] = useState(null); |
|
|
|
const [emoji, setEmoji] = useState("😎"); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
const pickerObj = new EmojiButton({}); |
|
|
|
pickerObj.on('emoji', selection => setEmoji(selection.emoji)); |
|
|
|
setPicker(pickerObj); |
|
|
|
}, []); |
|
|
|
|
|
|
|
function togglePicker() { |
|
|
|
picker.togglePicker(buttonRef.current); |
|
|
|
} |
|
|
|
|
|
|
|
function setDark() { |
|
|
|
picker.setTheme("dark"); |
|
|
|
} |
|
|
|
|
|
|
|
function setLight() { |
|
|
|
picker.setTheme("light"); |
|
|
|
} |
|
|
|
|
|
|
|
function setAuto() { |
|
|
|
picker.setTheme("auto"); |
|
|
|
} |
|
|
|
|
|
|
|
return ( |
|
|
|
<DocLayout> |
|
|
|
<h1>Themes</h1> |
|
|
@ -42,6 +74,46 @@ export default function ThemesExample() { |
|
|
|
</p> |
|
|
|
<Example options={{ theme: 'auto' }} /> |
|
|
|
<SourceFile src={autoExample} /> |
|
|
|
|
|
|
|
<h1>Switching the theme</h1> |
|
|
|
<p> |
|
|
|
To switch the theme after construction, call <code>setTheme</code>{' '} |
|
|
|
on the <code>EmojiButton</code> instance, passing it a value |
|
|
|
of <code>light</code>,<code>dark</code>, or <code>auto</code>. |
|
|
|
</p> |
|
|
|
|
|
|
|
<div> |
|
|
|
<button |
|
|
|
className={styles.emojiButton} |
|
|
|
ref={buttonRef} |
|
|
|
onClick={togglePicker} |
|
|
|
> |
|
|
|
{emoji} |
|
|
|
</button> |
|
|
|
|
|
|
|
<button |
|
|
|
id="set-theme-dark" |
|
|
|
onClick={setDark} |
|
|
|
> |
|
|
|
dark |
|
|
|
</button> |
|
|
|
|
|
|
|
<button |
|
|
|
id="set-theme-light" |
|
|
|
onClick={setLight} |
|
|
|
> |
|
|
|
light |
|
|
|
</button> |
|
|
|
|
|
|
|
<button |
|
|
|
id="set-theme-auto" |
|
|
|
onClick={setAuto} |
|
|
|
> |
|
|
|
auto |
|
|
|
</button> |
|
|
|
</div> |
|
|
|
|
|
|
|
<SourceFile src={switchExample} /> |
|
|
|
</DocLayout> |
|
|
|
); |
|
|
|
} |
|
|
|