react-emotion-face 1.0.1 → 1.2.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/README.md +151 -28
- package/dist/index.d.ts +13 -2
- package/dist/react-emotion-face.es.js +1655 -1540
- package/dist/react-emotion-face.umd.cjs +2 -2
- package/package.json +21 -4
package/README.md
CHANGED
|
@@ -1,48 +1,171 @@
|
|
|
1
1
|
# react-emotion-face
|
|
2
2
|
|
|
3
|
-
Animated cartoon emotion
|
|
4
|
-
|
|
3
|
+
Animated cartoon emotion faces for React — 21 emotions, 3 character types, speech bubbles, and idle animations powered by Framer Motion.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/react-emotion-face)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
|
|
8
|
+
**[Live Demo →](https://sandeepsj.github.io/react-emotion-face/)**
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- **21 emotions** — happy, sad, angry, mad, surprised, calm, sleepy, excited, tired, confused, embarrassed, nervous, proud, disgusted, bored, love, silly, determined, shy, anxious, laughing
|
|
15
|
+
- **3 character types** — 2D face (rounded rectangle), dog (floppy ears + snout), cat (pointy ears + whiskers)
|
|
16
|
+
- **Speech bubbles** — comic-book style with spring enter/exit animation
|
|
17
|
+
- **Idle animations** — bounce, breathe, pulse, tremble, wiggle, droop, headBob, and more
|
|
18
|
+
- **Framer Motion** path morphing for smooth expression transitions
|
|
19
|
+
- **TypeScript-first** — fully typed props and enums
|
|
20
|
+
- **Zero stylesheet dependency** — CSS is bundled, import once
|
|
21
|
+
|
|
22
|
+
---
|
|
5
23
|
|
|
6
24
|
## Installation
|
|
7
25
|
|
|
8
26
|
```bash
|
|
9
|
-
npm
|
|
27
|
+
npm install react-emotion-face
|
|
10
28
|
```
|
|
11
29
|
|
|
12
|
-
|
|
30
|
+
Peer dependencies: `react >= 17`, `react-dom >= 17`
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Quick start
|
|
13
35
|
|
|
14
36
|
```tsx
|
|
15
|
-
import React, { useState } from 'react';
|
|
16
37
|
import { EmotionFace } from 'react-emotion-face';
|
|
38
|
+
import 'react-emotion-face/styles';
|
|
17
39
|
|
|
18
|
-
function App() {
|
|
19
|
-
const [emotion, setEmotion] = useState('Happy');
|
|
20
|
-
|
|
40
|
+
export default function App() {
|
|
21
41
|
return (
|
|
22
|
-
<
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<button onClick={() => setEmotion('Sad')}>Make Sad</button>
|
|
31
|
-
<button onClick={() => setEmotion('Excited')}>Make Excited</button>
|
|
32
|
-
<button onClick={() => setEmotion('Angry')}>Make Angry</button>
|
|
33
|
-
</div>
|
|
42
|
+
<EmotionFace
|
|
43
|
+
emotion="happy"
|
|
44
|
+
character="dog"
|
|
45
|
+
message="Woof! 🐾"
|
|
46
|
+
size={200}
|
|
47
|
+
animated={true}
|
|
48
|
+
/>
|
|
34
49
|
);
|
|
35
50
|
}
|
|
36
51
|
```
|
|
37
52
|
|
|
53
|
+
---
|
|
54
|
+
|
|
38
55
|
## Props
|
|
39
56
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
| Prop | Type | Default | Description |
|
|
58
|
+
|---|---|---|---|
|
|
59
|
+
| `emotion` | `Emotion` | — | **Required.** One of the 21 emotion values |
|
|
60
|
+
| `character` | `'face' \| 'dog' \| 'cat'` | `'face'` | Character shape |
|
|
61
|
+
| `message` | `string` | — | Speech bubble text (animates in/out) |
|
|
62
|
+
| `size` | `number` | `200` | Width and height in pixels |
|
|
63
|
+
| `animated` | `boolean` | `true` | Enable idle animations |
|
|
64
|
+
| `color` | `string` | emotion default | Override the skin/fur colour |
|
|
65
|
+
| `onEmotionChange` | `(e: Emotion) => void` | — | Called when `emotion` prop changes |
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Characters
|
|
70
|
+
|
|
71
|
+
### `face` — 2D Cartoon Face
|
|
72
|
+
Rounded-rectangle head with classic cartoon features. Default character.
|
|
73
|
+
|
|
74
|
+
### `dog`
|
|
75
|
+
Round head with floppy ears, a snout with a shiny nose, and the mouth positioned on the snout.
|
|
76
|
+
|
|
77
|
+
### `cat`
|
|
78
|
+
Round head with pointy triangular ears (pink inner ear highlight), a small triangular nose, and three whiskers on each side.
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
<EmotionFace emotion="love" character="face" size={150} />
|
|
82
|
+
<EmotionFace emotion="love" character="dog" size={150} />
|
|
83
|
+
<EmotionFace emotion="love" character="cat" size={150} />
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Emotions
|
|
89
|
+
|
|
90
|
+
| Emotion | Eyes | Accessories | Animation |
|
|
91
|
+
|---|---|---|---|
|
|
92
|
+
| `happy` | Normal | — | Breathe |
|
|
93
|
+
| `sad` | Sad | Tears | Slow breathe |
|
|
94
|
+
| `angry` | Squint | Anger lines | Breathe |
|
|
95
|
+
| `mad` | Squint | Anger lines | Tremble |
|
|
96
|
+
| `surprised` | Wide | — | Head bob |
|
|
97
|
+
| `calm` | Closed | — | Breathe |
|
|
98
|
+
| `sleepy` | Sleepy | Floating Zs | Droop |
|
|
99
|
+
| `excited` | Wide | Sparkles | Bounce |
|
|
100
|
+
| `tired` | Sleepy | — | Slow breathe |
|
|
101
|
+
| `confused` | Normal | Question mark | Head bob |
|
|
102
|
+
| `embarrassed` | Closed | Blush | Breathe |
|
|
103
|
+
| `nervous` | Normal | Sweat drop | Tremble |
|
|
104
|
+
| `proud` | Normal | Sparkles | Breathe |
|
|
105
|
+
| `disgusted` | Squint | — | Breathe |
|
|
106
|
+
| `bored` | Sleepy | — | Slow breathe |
|
|
107
|
+
| `love` | Hearts | Floating hearts + blush | Pulse |
|
|
108
|
+
| `silly` | Normal | Tongue | Wiggle |
|
|
109
|
+
| `determined` | Squint | — | Breathe |
|
|
110
|
+
| `shy` | Closed | Blush | Breathe |
|
|
111
|
+
| `anxious` | Wide | Sweat drop | Tremble |
|
|
112
|
+
| `laughing` | Closed | Blush | Bounce |
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Utility functions
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { getEmotions, getCharacters, EMOTIONS, CHARACTERS } from 'react-emotion-face';
|
|
120
|
+
|
|
121
|
+
getEmotions(); // → ['happy', 'sad', 'angry', ...] (all 21)
|
|
122
|
+
getCharacters(); // → ['face', 'dog', 'cat']
|
|
123
|
+
|
|
124
|
+
EMOTIONS; // same as getEmotions() but a static array
|
|
125
|
+
CHARACTERS; // same as getCharacters() but a static array
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Speech bubble
|
|
131
|
+
|
|
132
|
+
Pass any string as `message` to show a comic-book speech bubble. Clears by passing `undefined` or an empty string.
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
const [msg, setMsg] = useState('');
|
|
136
|
+
|
|
137
|
+
<EmotionFace emotion="calm" character="cat" message={msg || undefined} size={200} />
|
|
138
|
+
<input value={msg} onChange={e => setMsg(e.target.value)} placeholder="Say something..." />
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Custom colour
|
|
144
|
+
|
|
145
|
+
Each emotion ships with a default skin/fur colour. Override it with `color`:
|
|
146
|
+
|
|
147
|
+
```tsx
|
|
148
|
+
<EmotionFace emotion="happy" color="#FF6EB4" size={200} /> // pink
|
|
149
|
+
<EmotionFace emotion="angry" color="#6B4FFF" size={200} /> // purple
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Development
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
git clone https://github.com/sandeepsj/react-emotion-face.git
|
|
158
|
+
cd react-emotion-face
|
|
159
|
+
npm install
|
|
160
|
+
|
|
161
|
+
npm run dev # demo dev server → http://localhost:5173/react-emotion-face/
|
|
162
|
+
npm run build:lib # build library → dist/
|
|
163
|
+
npm run build:demo # build demo → docs/
|
|
164
|
+
npm run build # build both
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## License
|
|
46
170
|
|
|
47
|
-
|
|
48
|
-
This library includes over 20 pre-configured emotions: Happy, Sad, Angry, Mad, Surprised, Calm, Sleepy, Excited, Tired, Confused, Embarrassed, Nervous, Proud, Disgusted, Bored, Love, Silly, Sick, Scared, Furious, Shocked. Provide any corresponding key to switch the face seamlessly!
|
|
171
|
+
MIT © sandeepsj
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
2
2
|
|
|
3
|
-
export declare
|
|
3
|
+
export declare const CHARACTERS: CharacterType[];
|
|
4
4
|
|
|
5
|
-
export declare
|
|
5
|
+
export declare type CharacterType = 'face' | 'dog' | 'cat';
|
|
6
|
+
|
|
7
|
+
export declare type Emotion = 'happy' | 'sad' | 'angry' | 'mad' | 'surprised' | 'calm' | 'sleepy' | 'excited' | 'tired' | 'confused' | 'embarrassed' | 'nervous' | 'proud' | 'disgusted' | 'bored' | 'love' | 'silly' | 'determined' | 'shy' | 'anxious' | 'laughing';
|
|
8
|
+
|
|
9
|
+
export declare function EmotionFace({ emotion, message, size, animated, color, character, onEmotionChange, }: EmotionFaceProps): JSX_2.Element;
|
|
6
10
|
|
|
7
11
|
export declare interface EmotionFaceProps {
|
|
8
12
|
emotion: Emotion;
|
|
@@ -10,9 +14,16 @@ export declare interface EmotionFaceProps {
|
|
|
10
14
|
size?: number;
|
|
11
15
|
animated?: boolean;
|
|
12
16
|
color?: string;
|
|
17
|
+
character?: CharacterType;
|
|
13
18
|
onEmotionChange?: (emotion: Emotion) => void;
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
export declare const EMOTIONS: Emotion[];
|
|
17
22
|
|
|
23
|
+
/** Returns all available character types. */
|
|
24
|
+
export declare function getCharacters(): CharacterType[];
|
|
25
|
+
|
|
26
|
+
/** Returns all available emotion strings. */
|
|
27
|
+
export declare function getEmotions(): Emotion[];
|
|
28
|
+
|
|
18
29
|
export { }
|