emoji-picker-react 4.0.0-rc.10 → 4.0.0-rc.11

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/README.md CHANGED
@@ -6,7 +6,7 @@ An emoji picker component for React applications.
6
6
 
7
7
  ## What to know before using
8
8
 
9
- - This package assumes it runs in the browser. I have taken many steps to prevent it from failing on the server, but still, it is recommended to only render the component on the client.
9
+ - This package assumes it runs in the browser. I have taken many steps to prevent it from failing on the server, but still, it is recommended to only render the component on the client. See troubleshooting section for more information.
10
10
 
11
11
  ## Installation
12
12
 
@@ -14,6 +14,20 @@ An emoji picker component for React applications.
14
14
  npm install emoji-picker-react
15
15
  ```
16
16
 
17
+ ## Usage:
18
+
19
+ ```jsx
20
+ import EmojiPicker from 'emoji-picker-react';
21
+
22
+ function App() {
23
+ return (
24
+ <div>
25
+ <EmojiPicker />
26
+ </div>
27
+ );
28
+ }
29
+ ```
30
+
17
31
  ## Features
18
32
 
19
33
  - Custom click handler
@@ -24,46 +38,47 @@ npm install emoji-picker-react
24
38
  - Different emoji sets (Google, Apple, Facebook, Twitter)
25
39
  - Native Emoji support
26
40
 
27
- ## Config Props
41
+ # Props
42
+
43
+ The following props are accepted by them picker:
28
44
 
29
- - _onEmojiClick_ `(event: MouseEvent, emoji: EmojiClickData) => void` - Callback function when an emoji is clicked. The callback receives the event and the emoji data. The emoji data is comprised of the following properties:
45
+ - `onEmojiClick`: `(event: MouseEvent, emoji: EmojiClickData) => void` - Callback function when an emoji is clicked. The callback receives the event and the emoji data. The emoji data is comprised of the following properties:
30
46
 
31
- ```ts{
32
- activeSkinTone: SkinTones;
33
- unified: string;
34
- unifiedWithoutSkinTone: string;
35
- emoji: string;
36
- names: string[];
37
- getImageUrl: (emojiStyle: EmojiStyle) => string;
47
+ ```ts
48
+ {
49
+ activeSkinTone: SkinTones;
50
+ unified: string;
51
+ unifiedWithoutSkinTone: string;
52
+ emoji: string;
53
+ names: string[];
54
+ getImageUrl: (emojiStyle: EmojiStyle) => string;
38
55
  }
39
56
  ```
40
57
 
41
- - _theme_ `Theme` - The theme of the picker. Can be either `light` or `dark`. Default is `light`.
58
+ - `theme`: `Theme` - The theme of the picker. Can be `light`, `dark` or auto. Default is `light`.
42
59
  The `Theme` enum can be imported from the package.
43
60
 
44
61
  ```ts
45
62
  import { Theme } from 'emoji-picker-react';
46
63
  ```
47
64
 
48
- - _emojiStyle_ `EmojiStyle` - The emoji style to use. Can be either `apple`, `google`, `facebook`, `twitter` or `native`. Default is `apple`.
65
+ - `emojiStyle`: `EmojiStyle` - The emoji style to use. Can be either `apple`, `google`, `facebook`, `twitter` or `native`. Default is `apple`.
49
66
  The `EmojiStyle` enum can be imported from the package.
50
67
 
51
68
  ```ts
52
69
  import { EmojiStyle } from 'emoji-picker-react';
53
70
  ```
54
71
 
55
- * _autoFocusSearch_: `boolean` - Whether to focus the search input on mount. Defaults to `true`.
72
+ * `autoFocusSearch`: `boolean` - Whether to focus the search input on mount. Defaults to `true`.
56
73
 
57
- * _defaultSkinTone_: `SkinTones` - The default skin tone to use when an emoji is clicked. Defaults to `SkinTones.Neutral`. Possible skin tones are:
74
+ * `defaultSkinTone`: `SkinTones` - The default skin tone to use when an emoji is clicked. Defaults to `SkinTones.Neutral`. Possible skin tones are:
58
75
 
59
- ```
60
- ✋ NEUTRAL = 'neutral'
61
- ✋🏻 LIGHT = '1f3fb'
62
- ✋🏼 MEDIUM_LIGHT = '1f3fc'
63
- ✋🏽 MEDIUM = '1f3fd'
64
- ✋🏾 MEDIUM_DARK = '1f3fe'
65
- ✋🏿 DARK = '1f3ff'
66
- ```
76
+ - ✋ 'neutral'
77
+ - ✋🏻 '1f3fb'
78
+ - ✋🏼 '1f3fc'
79
+ - ✋🏽 '1f3fd'
80
+ - ✋🏾 '1f3fe'
81
+ - ✋🏿 '1f3ff'
67
82
 
68
83
  The skin tones typescript enum can be imported directly from the package:
69
84
 
@@ -71,35 +86,63 @@ The skin tones typescript enum can be imported directly from the package:
71
86
  import { SkinTones } from 'emoji-picker-react';
72
87
  ```
73
88
 
74
- - _skinTonesDisabled_: `boolean` - Whether to disable the skin tone selection. Defaults to `false`.
89
+ - `skinTonesDisabled`: `boolean` - Whether to disable the skin tone selection. Defaults to `false`.
75
90
 
76
- - _showPreview_: `boolean` - Whether to show the preview of the selected emoji. Defaults to `true`.
91
+ - `showPreview`: `boolean` - Whether to show the preview of the selected emoji. Defaults to `true`.
77
92
 
78
- - _searchPlaceholder_: `string` - The placeholder text for the search input. Defaults to `Search`.
93
+ - `searchPlaceholder`: `string` - The placeholder text for the search input. Defaults to `Search`.
79
94
 
80
95
  - categories: Allows full config over ordering, naming and display of categories.
81
96
  To only sort/omit categories, you can simply pass an array of category names to display:
82
97
 
83
- ```
84
- RECENTLY_USED = 'recently_used',
85
- SMILEYS_PEOPLE = 'smileys_people',
86
- ANIMALS_NATURE = 'animals_nature',
87
- FOOD_DRINK = 'food_drink',
88
- TRAVEL_PLACES = 'travel_places',
89
- ACTIVITIES = 'activities',
90
- OBJECTS = 'objects',
91
- SYMBOLS = 'symbols',
92
- FLAGS = 'flags'
98
+ - 'recently_used',
99
+ - 'smileys_people',
100
+ - 'animals_nature',
101
+ - 'food_drink',
102
+ - 'travel_places',
103
+ - 'activities',
104
+ - 'objects',
105
+ - 'symbols',
106
+ - 'flags'
107
+
108
+ For a more in-depth configuration, you can pass an array with category config:
109
+
110
+ ```ts
111
+ [
112
+ {
113
+ category: 'recently_used',
114
+ name: 'Recently Used'
115
+ },
116
+ {
117
+ category: 'smileys_people',
118
+ name: 'Faces...'
119
+ }
120
+ ];
121
+ ```
122
+
123
+ # Troubleshooting
124
+
125
+ ## Next.js
126
+
127
+ To avoid errors such as "document is not defined" on the server side, you should make sure the library is only imported on the client side. Here is how to do that:
128
+
129
+ ```javascript
130
+ import dynamic from 'next/dynamic';
131
+
132
+ const Picker = dynamic(
133
+ () => {
134
+ return import('emoji-picker-react');
135
+ },
136
+ { ssr: false }
137
+ );
93
138
  ```
94
139
 
95
- For a more in-depth configuration, you can pass an array with category config:
140
+ ## Vite
96
141
 
97
- ```ts
98
- [{
99
- category: Categories.RECENTLY_USED;
100
- name: "Recently Used";
101
- }, {
102
- category: Categories.SMILEYS_PEOPLE;
103
- name: "Faces...";
104
- }]
142
+ For reference, if you only need to shim global, you can add
143
+
144
+ ```html
145
+ <script>
146
+ window.global = window;
147
+ </script>
105
148
  ```
@@ -0,0 +1 @@
1
+ export declare function isSystemDarkTheme(): boolean;
@@ -1,4 +1,4 @@
1
- import { EmojiClickData, EmojiStyle, SkinTones } from '../types/exposedTypes';
1
+ import { EmojiClickData, EmojiStyle, SkinTones, Theme } from '../types/exposedTypes';
2
2
  import { CategoriesConfig } from './categoryConfig';
3
3
  export declare function useSearchPlaceHolderConfig(): string;
4
4
  export declare function useDefaultSkinToneConfig(): SkinTones;
@@ -8,4 +8,4 @@ export declare function useAutoFocusSearchConfig(): boolean;
8
8
  export declare function useCategoriesConfig(): CategoriesConfig;
9
9
  export declare function useOnEmojiClickConfig(): (event: MouseEvent, emoji: EmojiClickData) => void;
10
10
  export declare function useShowPreviewConfig(): boolean;
11
- export declare function useThemeConfig(): string;
11
+ export declare function useThemeConfig(): Theme;
@@ -223,6 +223,14 @@ function usePickerConfig() {
223
223
  return React.useContext(ConfigContext);
224
224
  }
225
225
 
226
+ function isSystemDarkTheme() {
227
+ if (typeof window === 'undefined') {
228
+ return false;
229
+ }
230
+
231
+ return !!window.matchMedia('(prefers-color-scheme: dark)').matches;
232
+ }
233
+
226
234
  function useSearchPlaceHolderConfig() {
227
235
  var _usePickerConfig = usePickerConfig(),
228
236
  searchPlaceHolder = _usePickerConfig.searchPlaceHolder;
@@ -275,6 +283,10 @@ function useThemeConfig() {
275
283
  var _usePickerConfig9 = usePickerConfig(),
276
284
  theme = _usePickerConfig9.theme;
277
285
 
286
+ if (theme === exports.Theme.AUTO) {
287
+ return isSystemDarkTheme() ? exports.Theme.DARK : exports.Theme.LIGHT;
288
+ }
289
+
278
290
  return theme;
279
291
  }
280
292