All Projects โ†’ PandaSekh โ†’ lepre

PandaSekh / lepre

Licence: MIT License
๐Ÿฐ Lightweight Emoji Picker for React Enthusiast

Programming Languages

typescript
32286 projects
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to lepre

Vue Twemoji Picker
Vue Twemoji Picker - A fast plug-n-play Twemoji Picker (+textarea for Twemoji rendering) for Vue. Support Unicode Emoji 13.0.
Stars: โœญ 154 (+926.67%)
Mutual labels:  emoji, emoji-picker
discord-emoji
[Library/Deno] A near exact emoji tables of Discord for string-based insertion of emotes without having to escape Unicode.
Stars: โœญ 37 (+146.67%)
Mutual labels:  emoji, emoji-picker
Emoji Keyboard
Type emoji easily! Virtual keyboard-like emoji palette for Linux with lots of features.
Stars: โœญ 231 (+1440%)
Mutual labels:  emoji, emoji-picker
Awesome Emoji Picker
Add-on/WebExtension that provides a modern emoji picker that you can use to find and copy/insert emoji into the active web page.
Stars: โœญ 54 (+260%)
Mutual labels:  emoji, emoji-picker
winmoji
Emoji lookup for Windows ๐Ÿ˜‰ https://www.winmoji.com https://twitter.com/winmoji
Stars: โœญ 79 (+426.67%)
Mutual labels:  emoji, emoji-picker
Jquery Emoji
๐Ÿ˜„ Let textarea or editable div has ability to insert emoji. ่ฎฉๆ–‡ๆœฌๆก†ๆˆ–divๅ…ทๅค‡ๆ’ๅ…ฅ่กจๆƒ…ๅŠŸ่ƒฝใ€‚
Stars: โœญ 125 (+733.33%)
Mutual labels:  emoji, emoji-picker
rn-emoji-keyboard
Super performant, lightweight, fully customizable emoji picker ๐Ÿš€
Stars: โœญ 228 (+1420%)
Mutual labels:  emoji, emoji-picker
Emoji Picker Element
A lightweight emoji picker for the modern web
Stars: โœญ 587 (+3813.33%)
Mutual labels:  emoji, emoji-picker
mr-emoji
Lightweight emoji picker like SLACK
Stars: โœญ 23 (+53.33%)
Mutual labels:  emoji, emoji-picker
EmojiRunner
Search for emojis in Krunner and copy/paste them
Stars: โœญ 33 (+120%)
Mutual labels:  emoji, emoji-picker
Vanilla Emoji Picker
Modern emoji picker. Super light 2kb gzipped, simple and no frameworks ๐Ÿ˜ป
Stars: โœญ 20 (+33.33%)
Mutual labels:  emoji, emoji-picker
ngx-emoj
A simple, theme-able emoji mart/picker for angular 4+
Stars: โœญ 18 (+20%)
Mutual labels:  emoji, emoji-picker
Emoji Button
Vanilla JavaScript emoji picker component
Stars: โœญ 646 (+4206.67%)
Mutual labels:  emoji, emoji-picker
Emojipanel
๐Ÿ˜€ A customisable Javascript emoji picker
Stars: โœญ 129 (+760%)
Mutual labels:  emoji, emoji-picker
Uni
Query the Unicode database from the commandline, with good support for emojis
Stars: โœญ 633 (+4120%)
Mutual labels:  emoji, emoji-picker
AllGithubEmojis
A list of all supported github emojis updated weekly. https://jzeferino.github.io/AllGithubEmojis/
Stars: โœญ 82 (+446.67%)
Mutual labels:  emoji, emoji-picker
Emoji Mart
One component to pick them all ๐Ÿ‘Š๐Ÿผ
Stars: โœญ 4,687 (+31146.67%)
Mutual labels:  emoji, emoji-picker
Interweave
๐ŸŒ€ React library to safely render HTML, filter attributes, autowrap text with matchers, render emoji characters, and much more.
Stars: โœญ 467 (+3013.33%)
Mutual labels:  emoji, emoji-picker
ermoji
๐Ÿคทโ€โ™‚๏ธ RStudio Addin to Search and Copy Emoji
Stars: โœญ 26 (+73.33%)
Mutual labels:  emoji, emoji-picker
vuemoji-picker
Vue 2 and 3 lightweight emoji picker.
Stars: โœญ 53 (+253.33%)
Mutual labels:  emoji, emoji-picker

Rabbit Emoji

L.E.P.R.E

Travis CI npm Size Code Coverage Dependencies

๐Ÿฐ Lightweight Emoji Picker for React Enthusiasts.

Lepre is a lightweight (<1Kb) emoji picker library for React. It's fully customizable and was inspired by Github's reactions.

Lepre Example


Install

npm:

npm install --save lepre

Yarn:

yarn add lepre

CDN:

<sript src="https://unpkg.com/lepre@latest/dist/index.js"></script>

Index

Examples

Default Reaction Block

import React from 'react';

import Reactions from 'lepre';

export default function Example() {
  const MY_EMOJIS = [
    { emoji: '๐Ÿผ', label: 'panda' },
    { emoji: '๐Ÿ“ž', label: 'cell' },
  ];

  return <Reactions emojis={MY_EMOJIS} selected={SELECTED_EMOJIS}
 />;
}

Custom Component

import React from 'react';
import { EmojiCounter, EmojiPicker, useEmojis } from 'lepre';

const MY_EMOJIS = [
  { emoji: '๐Ÿผ', label: 'panda' },
  { emoji: '๐Ÿ“ž', label: 'cell' },
];
export default function CustomReactions() {
  const [emojis, increment] = useEmojis();

  const selected = emojis
    .sort((a, b) => (a.emoji < b.emoji ? 1 : -1)) // No sorting is applied by default
    .map((emoji) => (
      <EmojiCounter
        key={emoji.label}
        emoji={emoji}
        initialValue={emoji.counter}
        onClick={increment}
      />
));


  return (
    <div className='comment'>
      <div className='custom-picker'>
        <EmojiPicker
            availableEmojis={MY_EMOJIS}
            onClick={increment}
            selectedEmojis={emojis}
          />
      </div>
      <p>You can customize the reaction block however you want!</p>
      <div className='custom-selection'>{selected}</div>
    </div>
  );
}

Usage

lepre can be used in two ways, either by importing a single block which handles everything for you, or by importing each component and then do the connections yourself. While the first method is plug and play and easy to get started, the latter will give you more flexibility on the layout.

Default Reaction Block

API Documentation.
To use the Reaction Block, import the default Component from lepre.

import React from 'react';
import Reactions from 'lepre';

This Component only requires an emojis prop to work. emojis is an array of emoji objects which will be available to be selected. Optionally, it also accepts a selected prop, which is an array of emojis already selected, and onUpdate, a callback fired whenever the state is updated.

  const MY_EMOJIS = [
    { emoji: '๐Ÿผ', label: 'panda' },
    { emoji: '๐Ÿ“ž', label: 'cell' },
  ];

  const onStateUpdate = newState => console.log(newState)

  return <Reactions emojis={MY_EMOJIS} 
                    selected={SELECTED_EMOJIS} 
                    onUpdate={onStateUpdate}
          />;

Custom Block

To create a Custom Block you have to individually import the three building blocks of this library:

import React from 'react';
import { EmojiCounter, EmojiPicker, useEmojis } from 'lepre';

Then use the useEmojis hook to create a state for the emojis.

const emojisFromDatabase = fetch(...);

const [emojis, increment, decrement] = useEmojis(emojisFromDatabase);

Map the emojis with the EmojiCounter Component.

const mappedEmojis = emojis
  .sort((a, b) => (a.emoji < b.emoji ? 1 : -1)) // This is optional, but recommended
  .map((emoji) => (
    <EmojiCounter
      key={emoji.label}
      emoji={emoji}
      initialValue={emoji.counter}
      onClick={increment}
    />
  ));

Or create your own Component with the Emoji Component.

import React from 'react';
import EmojiComponent from './EmojiComponent.js';

export default function MyCustomEmojiComponent({ emoji, initialValue = 0, increment, decrement }){
  return (
    <span>
      <span onClick={() => increment(emoji)}>Incr</span>
      <span onClick={() => decrement(emoji)}>Decr</span>
      <EmojiComponent emoji={emoji} />
      <div>
        <span>{initialValue}</span>
      </div>
    </span>
  );
}

Finally, render the components however you want.

return (
<div>
  <div>
    <EmojiPicker
      availableEmojis={AVAILABLE_EMOJIS}
      onClick={increment}
      selectedEmojis={emojis}
    />
  </div>
  <p>{YOUR_CONTENT}</p>
  <div>{mappedEmojis}</div>
</div>
);

API


Emoji (Object)

const Emoji = {
  emoji: "๐Ÿฐ", 
  label: "rabbit", 
  counter: 0
}

Object containing infos about an emoji.

  • emoji: string The emoji itself.
  • label?: string Label of the emoji, used for accessibility reasons (Optional).
  • counter?: number Number of times the emoji was selected (Optional).

Emoji (Event)

addEventListener("emoji", e => console.log(e.emoji));

Event dispatched whenever an emoji gets clicked.

  • emoji: Emoji emoji from which the event was dispatched.

useEmojis

const [emojis, increment, decrement] = useEmojis(initialValue);
  • emojis: Array<Emoji> State.
  • increment(Emoji): function Increment the counter of the given Emoji.
  • decrement(Emoji): function Decrement the counter of the given Emoji.
  • initialValue: Array<Emoji> An initial value for the state.

Reactions

import Reactions from 'lepre';

const reactionBlock = <Reactions emojis={EMOJI_OPTIONS} selected={SELECTED_EMOJIS} />

Default block, already configured and ready to be used anywhere.

  • emojis: Array<Emoji> All available emojis.
  • selected?: Array<Emoji> Emojis already selected (taken from a database, from example).
  • onUpdate?: function(state) Fired whenever the state gets update, has the state as parameter.

Emoji

import {Emoji} from 'lepre';

const myEmoji= (
  <Emoji emoji={{emoji: "๐Ÿฐ", label: "rabbit"}} onClick={myCallback} />
);

Component used to render Emojis.

  • emoji: Emoji The Emoji to render.
  • onClick?: function Optional callback.

EmojiCounter

import {EmojiCounter} from 'lepre';

const counter = (
  <EmojiCounter emoji={{emoji: "๐Ÿฐ", label: "rabbit"}} onClick={myCallback} initialValue={5}/>
);

Component used to render Emojis with a counter near them.

  • emoji: Emoji Emoji to render
  • initialValue: number Initial value of the counter
  • onClick?: function Optional callback

EmojiPicker

import {EmojiPicker} from 'lepre';

const emojisToBeUsed = [
  {emoji: "๐Ÿฐ", label: "rabbit"},
  {emoji: "๐Ÿป", label: "bear"}
]

const emojisAlreadySelectedIGotFromTheDatabase = [
  {emoji: "๐Ÿฐ", label: "rabbit", counter: 10},
]

const picker = (
  <EmojiPicker  selectedEmojis={emojisAlreadySelectedIGotFromTheDatabase} 
                availableEmojis={emojisToBeUsed} 
                pickerIcon="<--"
                onClick={myCallback} />
);

Component used to render the Emoji Picker itself.

  • selectedEmojis: Array<Emoji> Array of Emojis already selected
  • availableEmojis: Array<Emoji> Array of all emojis available
  • onClick?: function Optional callback
  • pickerIcon = "๐Ÿ‘": string || svg Optional custom icon for the picker. Accepts a string (including emojis) or an svg object.

Demo

A basic demo with some example of Custom Blocks is available here.
I also use lepre on a personal project, check it out here: Real-Time React Commenting System.

Limitations

lepre aims to be fast and thin and because of that it has some limitations:

  • Emojis have to be configured first, there are no defaults
  • CSS is not included (but there's a starter CSS in this README!)

Contribute

Contributions are welcome! Please submit a pull request for new features or an issue if you find any bug or problem.
Please bear in mind that this library is meant to be lightweight first.

Contributors

To-Do

  • Typescript support (Thanks to @lodmfjord)
  • Get 100% Test Coverage (Thanks to @lodmfjord)

CSS

lepre comes with no CSS by default because rarely the stock design will remain unchanged. I thought that no CSS was better than unused CSS. Every component comes with classes already defined that you can use for styling.

  • emoji Span container of EmojiComponent
  • emoji-adder Span container of the EmojiComponent which renders the "+" sign
  • emoji-container Span container of EmojiCounter
  • emoji-counter Span container of the counter in EmojiCounter
  • emoji-menu-open Class applied to the emoji selection menu when it's opened
  • emoji-menu-closed Class applied to the emoji selection menu when it's closed
  • reaction-block Div container of the whole library (Default Reactions Block only)

Starter CSS

To help with the design, here's the CSS used in the Demo project for the Default Component. In the example/src folder of this repo you can find the styles for the other blocks.

.emoji {
  font-size: 25px;
  display: flex;
  align-items: center;
  cursor: pointer;
  vertical-align: middle;
  transform: translateZ(0);
  box-shadow: 0 0 1px rgba(0, 0, 0, 0);
  backface-visibility: hidden;
  -moz-osx-font-smoothing: grayscale;
  transition-duration: 0.1s;
  transition-property: transform;
}

.reaction-div {
  display: inline-flex;
  flex-flow: wrap;
  margin: 10px 0px 10px 10px;
}

.emoji-container {
  position: relative;
  user-select: none;
  display: flex;
}

.emoji-counter {
  font-weight: bold;
  padding: 2px 5px;
  border-radius: 30%;
  background-color: #f55742;
  color: #fefefe;
}
.emoji:hover,
.emoji:focus,
.emoji:active {
  transform: scale(1.1);
}

.reaction-block {
  display: inline-flex;
  flex-flow: wrap;
}

.emoji-adder {
  user-select: none;
  position: relative;
  display: inline-block;
}

.emoji-menu-open {
  position: absolute;
  display: flex;
  top: 0px;
  left: 35px;
  border-radius: 10px;
  box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
  background-color: #fefefe;
  z-index: 10;
  width: auto;
}

.emoji-menu-open .emoji {
  margin: 5px;
}

.emoji-menu-closed {
  display: none;
}

Changelog

See CHANGELOG.md.

License

MIT ยฉ PandaSekh

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].