Skip to content

Commit 37cd616

Browse files
committed
overhaul: dynamic svg loading from package
added size attribute / option added option to show colourless emojis
1 parent f63f2e4 commit 37cd616

3,464 files changed

Lines changed: 1970 additions & 139477 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
# Openmoji for React
22
unofficial; bodged by drinking-code
3-
**do not use in production**
3+
not optimized for production use
4+
5+
1. [What is Openmoji for React?](#what-is-openmoji-for-react)
6+
2. [Installation](#installation)
7+
3. [Usage](#usage)
8+
1. [Automatically](#automatically)
9+
1. [`reactReplaceEmojis(jsx[, options])`](#reactreplaceemojisjsx-options)
10+
2. [`replaceEmojis(string[, options])`](#replaceemojisstring-options)
11+
2. [Manually](#manually)
12+
1. [Via icon name](#via-icon-name)
13+
2. [Via unicode](#via-unicode)
14+
3. [Attributes](#attributes)
15+
416
#### What is Openmoji for React?
5-
[Openmoji](https://github.com/hfg-gmuend/openmoji) is a collection of open source emojis. This repository lets you use these emojis in a reactjs-app easily.
6-
#### Built from (coloured) Openmoji `v12.2.0`
17+
[Openmoji](https://github.com/hfg-gmuend/openmoji) is a collection of open source emojis. This repository lets you use these emojis in a React app easily.
718

819
> Please comply with the [Openmoji Attribution Requirements](https://github.com/hfg-gmuend/openmoji#attribution-requirements)
920
@@ -14,6 +25,7 @@ npm i react-openmoji
1425

1526
## Usage
1627
### Automatically
28+
#### `reactReplaceEmojis(jsx[, options])`
1729
For easy and dynamic use you can replace emojis completely automatically:
1830
```jsx
1931
import React from 'react';
@@ -26,6 +38,37 @@ const App = () => {
2638
export default App;
2739
```
2840

41+
You can also set options:
42+
`size` — size of the emojis; default `1.7em`
43+
`outline` — set to `true` if you want the colourless emojis; default `false`
44+
45+
```jsx
46+
import React from 'react';
47+
import reactReplaceEmojis from 'react-openmoji';
48+
49+
const App = () => {
50+
return reactReplaceEmojis(
51+
<p>Hello 🙋‍♂️ World! 🌍</p>,
52+
{size: '1.2em', outline: true}
53+
)
54+
};
55+
56+
export default App;
57+
```
58+
59+
#### `replaceEmojis(string[, options])`
60+
Is the sting equivalent to `reactReplaceEmojis`. Use this if you only want to replace emojis within a string.
61+
```jsx
62+
import React from 'react';
63+
import {replaceEmojis} from 'react-openmoji';
64+
65+
const App = () => {
66+
return <p>{replaceEmojis('Hello 🙋‍♂️ World! 🌍')}</p>
67+
};
68+
69+
export default App;
70+
```
71+
2972
### Manually
3073
#### Via icon name
3174
```jsx
@@ -91,3 +134,19 @@ const App = () => {
91134

92135
export default App;
93136
```
137+
138+
#### Attributes
139+
In all manual cases you can use two attributes:
140+
`size` — sets the size of the emojis; default `1.7em`
141+
`outline` — add if you want the colourless emojis
142+
143+
```jsx
144+
import React from 'react';
145+
import { ManRaisingHand } from 'react-openmoji';
146+
147+
const App = () => {
148+
return <p>Hello World! <ManRaisingHand size={'1.2em'} outline/></p>
149+
};
150+
151+
export default App;
152+
```

build/build.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@ String.prototype.capitalize = function () {
99
let string = this.split(' '),
1010
capitalised = [];
1111

12+
try {
1213
string.forEach(word => {
14+
if (!word) return
1315
capitalised.push(word[0].toUpperCase() + word.substr(1))
1416
})
17+
} catch (e) {
18+
console.log(string)
19+
string.forEach(word => console.log(word))
20+
throw new Error(e);
21+
}
1522

1623
string = capitalised.join('').split('-');
1724
capitalised = [];
@@ -84,9 +91,11 @@ if (fs.existsSync(srcPath)) {
8491
});
8592
}
8693

94+
const OPENMOJI_DIR = '../node_modules/openmoji'
95+
8796
// get openmoji.json
88-
console.log('reading ./input/openmoji.json');
89-
const index = JSON.parse(fs.readFileSync(path.join(__dirname, 'input/openmoji.json'), {encoding: 'utf-8'}));
97+
console.log('reading openmoji.json');
98+
const index = JSON.parse(fs.readFileSync(path.join(__dirname, OPENMOJI_DIR, 'data/openmoji.json'), {encoding: 'utf-8'}));
9099

91100
//make icons directory
92101
fs.mkdir(srcPath + '/icons', (err) => {
@@ -97,14 +106,19 @@ let indexJS = '';//'module.exports = {\n';
97106
console.log(`writing icon scripts ${''.toString()/*0/${index.length}*/}`);
98107
index.forEach(icon => {
99108
// get content of <HEXCODE>.svg
100-
let iconSvg;
109+
let iconSvg, outlineSvg;
101110
try {
102-
iconSvg = fs.readFileSync(path.join(__dirname, `input/color/${icon.hexcode}.svg`), {encoding: 'utf-8'})
111+
iconSvg = fs.readFileSync(path.join(__dirname, OPENMOJI_DIR, `color/svg/${icon.hexcode}.svg`), {encoding: 'utf-8'})
112+
outlineSvg = fs.readFileSync(path.join(__dirname, OPENMOJI_DIR, `black/svg/${icon.hexcode}.svg`), {encoding: 'utf-8'})
103113
} catch (err) {
104114
return
105115
}
106116
if (!iconSvg) {
107-
console.error(`input/color/${icon.hexcode}.svg does not exist`);
117+
console.error(`color/svg/${icon.hexcode}.svg does not exist`);
118+
return;
119+
}
120+
if (!outlineSvg) {
121+
console.error(`black/svg/${icon.hexcode}.svg does not exist`);
108122
return;
109123
}
110124

@@ -118,20 +132,29 @@ index.forEach(icon => {
118132
/*
119133
import React
120134
const <ICON-NAME> = (size) => {
121-
if (!size) size = '1.2em';
135+
if (!size) size = '1.7em';
122136
return (icon with size in width and height)
123137
}
124138
export default <ICON-NAME>
125139
*/
126140
const iconScript = `
127141
import React from 'react';
128142
129-
const ${iconName} = (size) => {
130-
return (
131-
${iconSvg
132-
.replace('<svg', '<svg width="1.7em" height="1.7em"')
143+
const ${iconName} = ({size, outline}) => {
144+
if (!size) size = '1.7em';
145+
if (!outline) {
146+
return (
147+
${iconSvg
148+
.replace('<svg', '<svg width={size} height={size}')
149+
.replace(/x[a-z]+:[a-z]+="[^>]+"/g, '')/*rem namespace tags*/}
150+
);
151+
} else {
152+
return (
153+
${outlineSvg
154+
.replace('<svg', '<svg width={size} height={size}')
133155
.replace(/x[a-z]+:[a-z]+="[^>]+"/g, '')/*rem namespace tags*/}
134-
);
156+
);
157+
}
135158
};
136159
137160
export default ${iconName};

build/input/color/0023-FE0F-20E3.svg

Lines changed: 0 additions & 12 deletions
This file was deleted.

build/input/color/002A-FE0F-20E3.svg

Lines changed: 0 additions & 11 deletions
This file was deleted.

build/input/color/0030-FE0F-20E3.svg

Lines changed: 0 additions & 9 deletions
This file was deleted.

build/input/color/0031-FE0F-20E3.svg

Lines changed: 0 additions & 9 deletions
This file was deleted.

build/input/color/0032-FE0F-20E3.svg

Lines changed: 0 additions & 9 deletions
This file was deleted.

build/input/color/0033-FE0F-20E3.svg

Lines changed: 0 additions & 9 deletions
This file was deleted.

build/input/color/0034-FE0F-20E3.svg

Lines changed: 0 additions & 10 deletions
This file was deleted.

build/input/color/0035-FE0F-20E3.svg

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)