@synerise/ds-emoji-picker 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Synerise
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ ---
2
+ id: emoji-picker
3
+ title: EmojiPicker
4
+ ---
5
+
6
+ EmojiPicker UI Component
7
+
8
+ ## Installation
9
+ ```
10
+ npm i @synerise/ds-emoji-picker
11
+ or
12
+ yarn add @synerise/ds-emoji-picker
13
+ ```
14
+
15
+ ## Usage
16
+ ```
17
+ import EmojiPicker from '@synerise/ds-emoji-picker'
18
+
19
+ <EmojiPicker />
20
+
21
+ ```
22
+
23
+ ## Demo
24
+
25
+ <iframe src="/storybook-static/iframe.html?id=components-emoji-picker--default"></iframe>
26
+
27
+ ## API
28
+
29
+ | Property | Description | Type | Default |
30
+ |---------------|------------------------------------------------------------------------------------------|---------------------------|---------|
31
+ | children | the element that triggers showing the picker | ReactElement | - |
32
+ | onSelect | triggered when an emoji has been selected | (emoji: Emoji) => void | - |
33
+ | closeOnSelect | determines whether dropdown should hide when an emoji has been selected. true by default | boolean | true |
34
+ | dropdownProps | Dropdown customisation props see ds-dropdown | Partial<DropdownProps> | - |
35
+ | texts | customise texts / labels | Partial<EmojiPickerTexts> | - |
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import { EmojiListProps } from './EmojiList.types';
3
+ export declare const EmojiList: ({ texts: customTexts, onSelect, searchQuery }: EmojiListProps) => React.JSX.Element;
@@ -0,0 +1,55 @@
1
+ import React, { useMemo } from 'react';
2
+ import Divider from '@synerise/ds-divider';
3
+ import Scrollbar from '@synerise/ds-scrollbar';
4
+ import { getEmojisByGroup } from 'unicode-emoji-utils';
5
+ import * as S from './EmojiList.styles';
6
+ import { useEmojiTranslations } from '../hooks/useEmojiTranslations';
7
+ export var EmojiList = function EmojiList(_ref) {
8
+ var customTexts = _ref.texts,
9
+ onSelect = _ref.onSelect,
10
+ searchQuery = _ref.searchQuery;
11
+ var texts = useEmojiTranslations(customTexts);
12
+ var grouped = useMemo(function () {
13
+ return getEmojisByGroup('group');
14
+ }, []);
15
+ var filteredList = useMemo(function () {
16
+ var items = [];
17
+ grouped.forEach(function (emojis, category) {
18
+ var matching = searchQuery ? emojis.filter(function (emoji) {
19
+ var _emoji$keywords;
20
+ return (_emoji$keywords = emoji.keywords) == null ? void 0 : _emoji$keywords.find(function (keyword) {
21
+ return keyword.match(searchQuery);
22
+ });
23
+ }) : emojis;
24
+ if (matching.length) {
25
+ items.push({
26
+ title: texts[category] || category,
27
+ emojis: matching
28
+ });
29
+ }
30
+ });
31
+ return items;
32
+ }, [searchQuery, grouped, texts]);
33
+ var handleClick = function handleClick(emoji) {
34
+ // eslint-disable-next-line no-unused-expressions
35
+ onSelect == null || onSelect(emoji);
36
+ };
37
+ return /*#__PURE__*/React.createElement(Scrollbar, {
38
+ maxHeight: 330
39
+ }, filteredList.map(function (_ref2, index) {
40
+ var title = _ref2.title,
41
+ emojis = _ref2.emojis;
42
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Divider, {
43
+ labelBelow: title,
44
+ hiddenLine: index === 0
45
+ }), /*#__PURE__*/React.createElement(S.EmojiCategoryWrapper, null, emojis.map(function (emoji) {
46
+ return /*#__PURE__*/React.createElement(S.EmojiItem, {
47
+ key: emoji.emoji,
48
+ "data-testid": "ds-emoji-item",
49
+ onClick: function onClick() {
50
+ return handleClick(emoji);
51
+ }
52
+ }, emoji.emoji);
53
+ })));
54
+ }));
55
+ };
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ export declare const EmojiItem: import("styled-components").StyledComponent<(props: any) => React.JSX.Element, any, {}, never>;
3
+ export declare const EmojiCategoryWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -0,0 +1,17 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+ import React from 'react';
3
+ import styled from 'styled-components';
4
+ import Button from '@synerise/ds-button';
5
+ export var EmojiItem = styled(function (props) {
6
+ return /*#__PURE__*/React.createElement(Button, _extends({}, props, {
7
+ type: "ghost",
8
+ mode: "single-icon"
9
+ }));
10
+ }).withConfig({
11
+ displayName: "EmojiListstyles__EmojiItem",
12
+ componentId: "sc-1yme2ir-0"
13
+ })(["font-size:18px;display:flex;align-items:center;cursor:pointer;"]);
14
+ export var EmojiCategoryWrapper = styled.div.withConfig({
15
+ displayName: "EmojiListstyles__EmojiCategoryWrapper",
16
+ componentId: "sc-1yme2ir-1"
17
+ })(["display:flex;gap:4px;flex-wrap:wrap;"]);
@@ -0,0 +1,22 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { Emoji } from 'unicode-emoji-utils';
3
+ export type EmojiListTexts = {
4
+ 'smileys-emotion': ReactNode;
5
+ 'people-body': ReactNode;
6
+ 'animals-nature': ReactNode;
7
+ 'food-drink': ReactNode;
8
+ 'travel-places': ReactNode;
9
+ activities: ReactNode;
10
+ objects: ReactNode;
11
+ symbols: ReactNode;
12
+ flags: ReactNode;
13
+ };
14
+ export type EmojiListProps = {
15
+ texts?: Partial<EmojiListTexts>;
16
+ onSelect?: (emoji: Emoji) => void;
17
+ searchQuery?: string;
18
+ };
19
+ export type EmojiCategory = {
20
+ title: ReactNode;
21
+ emojis: Emoji[];
22
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import { EmojiOverlayType } from './EmojiOverlay.types';
3
+ export declare const EmojiOverlay: ({ texts: customTexts, onSelect, focus }: EmojiOverlayType) => React.JSX.Element;
@@ -0,0 +1,36 @@
1
+ import React, { useState } from 'react';
2
+ import Icon, { SearchM } from '@synerise/ds-icon';
3
+ import { theme } from '@synerise/ds-core';
4
+ import Dropdown from '@synerise/ds-dropdown';
5
+ import { EmojiList } from '../EmojiList/EmojiList';
6
+ import { useEmojiTranslations } from '../hooks/useEmojiTranslations';
7
+ export var EmojiOverlay = function EmojiOverlay(_ref) {
8
+ var customTexts = _ref.texts,
9
+ onSelect = _ref.onSelect,
10
+ focus = _ref.focus;
11
+ var texts = useEmojiTranslations(customTexts);
12
+ var _useState = useState(''),
13
+ searchQuery = _useState[0],
14
+ setSearchQuery = _useState[1];
15
+ var handleClearInput = function handleClearInput() {
16
+ setSearchQuery('');
17
+ };
18
+ var handleSearchChange = function handleSearchChange(query) {
19
+ setSearchQuery(query);
20
+ };
21
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Dropdown.SearchInput, {
22
+ onSearchChange: handleSearchChange,
23
+ onClearInput: handleClearInput,
24
+ placeholder: texts.placeholder,
25
+ value: searchQuery,
26
+ autofocus: focus,
27
+ iconLeft: /*#__PURE__*/React.createElement(Icon, {
28
+ component: /*#__PURE__*/React.createElement(SearchM, null),
29
+ color: theme.palette['grey-600']
30
+ })
31
+ }), /*#__PURE__*/React.createElement(EmojiList, {
32
+ onSelect: onSelect,
33
+ searchQuery: searchQuery,
34
+ texts: texts
35
+ }));
36
+ };
@@ -0,0 +1,4 @@
1
+ import type { EmojiPickerProps } from '../EmojiPicker.types';
2
+ export type EmojiOverlayType = Pick<EmojiPickerProps, 'onSelect' | 'texts'> & {
3
+ focus?: boolean;
4
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import type { EmojiPickerProps } from './EmojiPicker.types';
3
+ export declare const EmojiPicker: ({ children, closeOnSelect, onSelect, texts, dropdownProps }: EmojiPickerProps) => React.JSX.Element;
@@ -0,0 +1,45 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+ import React, { useRef, useState } from 'react';
3
+ import Dropdown from '@synerise/ds-dropdown';
4
+ import { useOnClickOutside } from '@synerise/ds-utils';
5
+ import * as S from './EmojiPicker.styles';
6
+ import { EmojiOverlay } from './EmojiOverlay/EmojiOverlay';
7
+ export var EmojiPicker = function EmojiPicker(_ref) {
8
+ var children = _ref.children,
9
+ _ref$closeOnSelect = _ref.closeOnSelect,
10
+ closeOnSelect = _ref$closeOnSelect === void 0 ? true : _ref$closeOnSelect,
11
+ _onSelect = _ref.onSelect,
12
+ texts = _ref.texts,
13
+ dropdownProps = _ref.dropdownProps;
14
+ var _useState = useState(false),
15
+ isOpen = _useState[0],
16
+ setOpen = _useState[1];
17
+ var _useState2 = useState(false),
18
+ focus = _useState2[0],
19
+ setFocus = _useState2[1];
20
+ var ref = useRef(null);
21
+ useOnClickOutside(ref, function () {
22
+ setOpen(false);
23
+ });
24
+ var toggleOpen = function toggleOpen(newState) {
25
+ setOpen(newState);
26
+ setFocus(newState);
27
+ };
28
+ return /*#__PURE__*/React.createElement(Dropdown, _extends({
29
+ visible: isOpen,
30
+ onVisibleChange: toggleOpen,
31
+ placement: "bottomRight"
32
+ }, dropdownProps, {
33
+ overlay: /*#__PURE__*/React.createElement(S.Overlay, {
34
+ ref: ref
35
+ }, /*#__PURE__*/React.createElement(EmojiOverlay, {
36
+ onSelect: function onSelect(val) {
37
+ closeOnSelect && toggleOpen(false);
38
+ // eslint-disable-next-line no-unused-expressions
39
+ _onSelect == null || _onSelect(val);
40
+ },
41
+ texts: texts,
42
+ focus: focus
43
+ }))
44
+ }), children);
45
+ };
@@ -0,0 +1 @@
1
+ export declare const Overlay: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -0,0 +1,5 @@
1
+ import styled from 'styled-components';
2
+ export var Overlay = styled.div.withConfig({
3
+ displayName: "EmojiPickerstyles__Overlay",
4
+ componentId: "sc-562kws-0"
5
+ })(["width:260px;"]);
@@ -0,0 +1,14 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { DropdownProps } from '@synerise/ds-dropdown';
3
+ import type { Emoji } from 'unicode-emoji-utils';
4
+ import type { EmojiListTexts } from './EmojiList/EmojiList.types';
5
+ export type EmojiPickerTexts = EmojiListTexts & {
6
+ placeholder: string;
7
+ };
8
+ export type EmojiPickerProps = {
9
+ children?: ReactElement;
10
+ onSelect?: (emoji: Emoji) => void;
11
+ dropdownProps?: Partial<DropdownProps>;
12
+ texts?: Partial<EmojiPickerTexts>;
13
+ closeOnSelect?: boolean;
14
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { EmojiPickerTexts } from '../EmojiPicker.types';
2
+ export declare const useEmojiTranslations: (texts?: Partial<EmojiPickerTexts>) => EmojiPickerTexts;
@@ -0,0 +1,52 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+ import React, { useMemo } from 'react';
3
+ import { FormattedMessage, useIntl } from 'react-intl';
4
+ export var useEmojiTranslations = function useEmojiTranslations(texts) {
5
+ var _useIntl = useIntl(),
6
+ formatMessage = _useIntl.formatMessage;
7
+ var allTexts = useMemo(function () {
8
+ return _extends({
9
+ 'smileys-emotion': /*#__PURE__*/React.createElement(FormattedMessage, {
10
+ id: "DS.ICON-PICKER.SMILEYS",
11
+ defaultMessage: "Smileys"
12
+ }),
13
+ 'people-body': /*#__PURE__*/React.createElement(FormattedMessage, {
14
+ id: "DS.ICON-PICKER.SMILEYS",
15
+ defaultMessage: "People & body"
16
+ }),
17
+ 'animals-nature': /*#__PURE__*/React.createElement(FormattedMessage, {
18
+ id: "DS.ICON-PICKER.SMILEYS",
19
+ defaultMessage: "Animals & nature"
20
+ }),
21
+ 'food-drink': /*#__PURE__*/React.createElement(FormattedMessage, {
22
+ id: "DS.ICON-PICKER.SMILEYS",
23
+ defaultMessage: "Food & drink"
24
+ }),
25
+ 'travel-places': /*#__PURE__*/React.createElement(FormattedMessage, {
26
+ id: "DS.ICON-PICKER.SMILEYS",
27
+ defaultMessage: "Travel & places"
28
+ }),
29
+ activities: /*#__PURE__*/React.createElement(FormattedMessage, {
30
+ id: "DS.ICON-PICKER.SMILEYS",
31
+ defaultMessage: "Activities"
32
+ }),
33
+ objects: /*#__PURE__*/React.createElement(FormattedMessage, {
34
+ id: "DS.ICON-PICKER.SMILEYS",
35
+ defaultMessage: "Objects"
36
+ }),
37
+ symbols: /*#__PURE__*/React.createElement(FormattedMessage, {
38
+ id: "DS.ICON-PICKER.SMILEYS",
39
+ defaultMessage: "Symbols"
40
+ }),
41
+ flags: /*#__PURE__*/React.createElement(FormattedMessage, {
42
+ id: "DS.ICON-PICKER.SMILEYS",
43
+ defaultMessage: "Flags"
44
+ }),
45
+ placeholder: formatMessage({
46
+ id: 'DS.ICON-PICKER.PLACEHOLDER',
47
+ defaultMessage: 'Search'
48
+ })
49
+ }, texts || {});
50
+ }, [texts, formatMessage]);
51
+ return allTexts;
52
+ };
@@ -0,0 +1,2 @@
1
+ export { EmojiPicker, EmojiPicker as default } from './EmojiPicker';
2
+ export type { EmojiPickerProps, EmojiPickerTexts } from './EmojiPicker.types';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { EmojiPicker, EmojiPicker as default } from './EmojiPicker';
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@synerise/ds-emoji-picker",
3
+ "version": "1.0.0",
4
+ "description": "EmojiPicker UI Component for the Synerise Design System",
5
+ "license": "ISC",
6
+ "repository": "Synerise/synerise-design",
7
+ "main": "dist/index.js",
8
+ "files": [
9
+ "/dist",
10
+ "CHANGELOG.md",
11
+ "README.md",
12
+ "package.json",
13
+ "LICENSE.md"
14
+ ],
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "scripts": {
19
+ "build": "npm run build:js && npm run build:css && npm run defs",
20
+ "build:css": "node ../../../scripts/style/less.js",
21
+ "build:js": "babel --delete-dir-on-start --root-mode upward src --out-dir dist --extensions '.js,.ts,.tsx'",
22
+ "build:watch": "npm run build:js -- --watch",
23
+ "defs": "tsc --declaration --outDir dist/ --emitDeclarationOnly",
24
+ "prepublish": "npm run build",
25
+ "types": "tsc --noEmit",
26
+ "pack:ci": "npm pack --pack-destination ../../storybook/storybook-static/static",
27
+ "test": "jest",
28
+ "test:watch": "npm run test -- --watchAll",
29
+ "upgrade:ds": "ncu -f \"@synerise/ds-*\" -u"
30
+ },
31
+ "sideEffects": [
32
+ "dist/style/*",
33
+ "*.less"
34
+ ],
35
+ "types": "dist/index.d.ts",
36
+ "dependencies": {
37
+ "@synerise/ds-button": "^1.1.0",
38
+ "@synerise/ds-divider": "^1.0.1",
39
+ "@synerise/ds-dropdown": "^1.0.1",
40
+ "@synerise/ds-icon": "^1.0.1",
41
+ "@synerise/ds-scrollbar": "^1.0.1",
42
+ "@synerise/ds-utils": "^1.0.1",
43
+ "unicode-emoji-utils": "^1.2.0"
44
+ },
45
+ "peerDependencies": {
46
+ "@synerise/ds-core": "*",
47
+ "react": ">=16.9.0 <= 18.3.1",
48
+ "react-intl": ">=3.12.0 <= 6.8",
49
+ "styled-components": "^5.3.3"
50
+ },
51
+ "gitHead": "bf168e5bafcb99015f36731a8aa158cecca12434"
52
+ }