Joe Attardi
4 years ago
11 changed files with 193 additions and 1 deletions
@ -1,2 +1,5 @@ |
|||
node_modules |
|||
dist |
|||
test.js |
|||
test.html |
|||
|
|||
|
@ -0,0 +1,26 @@ |
|||
import { EmojiButton } from './dist/index.js'; |
|||
|
|||
const trigger = document.querySelector('#trigger'); |
|||
|
|||
const removePlugin = { |
|||
render(picker) { |
|||
const button = document.createElement('button'); |
|||
button.innerHTML = 'Remove'; |
|||
button.addEventListener('click', () => { |
|||
trigger.innerHTML = ''; |
|||
picker.hidePicker(); |
|||
}); |
|||
|
|||
return button; |
|||
} |
|||
}; |
|||
|
|||
const picker = new EmojiButton({ |
|||
plugins: [removePlugin] |
|||
}); |
|||
|
|||
picker.on('emoji', selection => { |
|||
trigger.innerHTML = selection.emoji; |
|||
}); |
|||
|
|||
trigger.addEventListener('click', () => picker.togglePicker(trigger)); |
@ -0,0 +1,13 @@ |
|||
import React from 'react'; |
|||
|
|||
import DocLayout from '../components/DocLayout'; |
|||
|
|||
export default function NotFoundPage() { |
|||
return ( |
|||
<DocLayout> |
|||
<h1>Not Found</h1> |
|||
<div style={{fontSize: '3rem'}}>😔</div> |
|||
<p>Sorry, the page you requested could not be found.</p> |
|||
</DocLayout> |
|||
); |
|||
} |
@ -0,0 +1,86 @@ |
|||
import React, { useRef, useState, useEffect } from 'react'; |
|||
|
|||
import { EmojiButton } from '@joeattardi/emoji-button'; |
|||
|
|||
import DocLayout from '../../components/DocLayout'; |
|||
import SourceFile from '../../components/SourceFile'; |
|||
|
|||
import pluginExample from '!!raw-loader!../../examples/plugin.js'; |
|||
|
|||
import styles from './plugins.module.css'; |
|||
|
|||
export default function PluginsExample() { |
|||
const buttonRef = useRef(); |
|||
const [picker, setPicker] = useState(null); |
|||
const [emoji, setEmoji] = useState(null); |
|||
|
|||
useEffect(() => { |
|||
const removePlugin = { |
|||
render(picker) { |
|||
const button = document.createElement('button'); |
|||
button.innerHTML = 'Remove'; |
|||
button.addEventListener('click', () => { |
|||
setEmoji(null); |
|||
picker.hidePicker(); |
|||
}); |
|||
|
|||
return button; |
|||
} |
|||
}; |
|||
|
|||
const pickerObj = new EmojiButton({ |
|||
plugins: [removePlugin] |
|||
}); |
|||
pickerObj.on('emoji', selection => setEmoji(selection.emoji)); |
|||
setPicker(pickerObj); |
|||
}, []); |
|||
|
|||
function togglePicker() { |
|||
picker.togglePicker(buttonRef.current); |
|||
} |
|||
|
|||
return ( |
|||
<DocLayout> |
|||
<h1>Plugins</h1> |
|||
<p>You can extend the emoji picker's UI using plugins.</p> |
|||
|
|||
<p> |
|||
A plugin is a JavaScript object with a property called{' '} |
|||
<code>render</code>. The value of that property should be a function |
|||
that takes in the picker instance as its sole parameter. The return |
|||
value of the <code>render</code> function should be an{' '} |
|||
<code>HTMLElement</code> that contain the user interface for the plugin. |
|||
</p> |
|||
|
|||
<p> |
|||
A plugin can also optionally define a <code>destroy</code> function |
|||
which will be called when the picker is destroyed, which can be used to |
|||
perform any necessary cleanup. |
|||
</p> |
|||
|
|||
<p> |
|||
Plugins are passed as an array into the <code>plugins</code> picker |
|||
option. The plugins will be rendered at the top of the picker. |
|||
</p> |
|||
|
|||
<p> |
|||
In the example on this page, we show a blank button until an emoji is |
|||
chosen. We have a plugin that adds a "Remove" button to the picker. If |
|||
that button is clicked, it removes the current emoji selection and |
|||
closes the picker. |
|||
</p> |
|||
|
|||
<div> |
|||
<button |
|||
className={styles.emojiButton} |
|||
ref={buttonRef} |
|||
onClick={togglePicker} |
|||
> |
|||
{emoji} |
|||
</button> |
|||
</div> |
|||
|
|||
<SourceFile src={pluginExample} /> |
|||
</DocLayout> |
|||
); |
|||
} |
@ -0,0 +1,17 @@ |
|||
.emoji-button { |
|||
font-size: 2rem; |
|||
background: #eeeeee; |
|||
border: 1px solid #cccccc; |
|||
border-radius: 5px; |
|||
padding: 0.5rem 1rem; |
|||
cursor: pointer; |
|||
margin: 0.5rem; |
|||
width: 4rem; |
|||
height: 4rem; |
|||
display: flex; |
|||
align-items: center; |
|||
justify-content: center; |
|||
font-family: 'Segoe UI Emoji', 'Segoe UI Symbol', 'Segoe UI', |
|||
'Apple Color Emoji', 'Twemoji Mozilla', 'Noto Color Emoji', 'EmojiOne Color', |
|||
'Android Emoji'; |
|||
} |
Loading…
Reference in new issue