Skip to content

Commit cff0113

Browse files
author
Zaydek Michels-Gualtieri
committed
Added emojiClassName so that we don’t need to do <span>{children}</span>
1 parent 17c80ae commit cff0113

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

src/Editor/Elements/Elements.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import attrs from "./attrs"
22
import dedupeSpaces from "lib/dedupeSpaces"
3+
import emojiClassName from "./emojiClassName"
34
import escape from "lodash/escape"
45
import IfWrapper from "lib/IfWrapper"
56
import Markdown from "./Markdown"
@@ -14,7 +15,6 @@ import { Strikethrough } from "./InlineElements"
1415
// React components.
1516
function toReact(children) {
1617
if (children === null || typeof children === "string") {
17-
// return !children ? null : <span>{children}</span>
1818
return children
1919
}
2020
const components = []
@@ -52,7 +52,7 @@ export const Header = React.memo(({ tag: Tag, id, syntax, hash, children }) => (
5252
))
5353

5454
export const Paragraph = React.memo(({ id, children }) => (
55-
<p id={id}>
55+
<p id={id} className={emojiClassName(children)}>
5656
{toReact(children) || (
5757
<br />
5858
)}
@@ -223,13 +223,13 @@ export const Image = React.memo(({ id, syntax, src, alt, href, children }) => {
223223
<img className="mx-auto" style={{ minHeight: "1.5em", maxHeight: "24em" }} src={src} alt={alt} />
224224
{/* </IfWrapper> */}
225225
{/* {(!readOnly || (readOnly && children)) && ( */}
226-
<figcaption className="px-6 py-2 text-center text-sm text-gray-600">
227-
<Markdown syntax={syntax} {...attrs.disableAutoCorrect}>
228-
{toReact(children) || (
229-
<br />
230-
)}
231-
</Markdown>
232-
</figcaption>
226+
<figcaption className="px-6 py-2 text-center text-sm text-gray-600">
227+
<Markdown syntax={syntax} {...attrs.disableAutoCorrect}>
228+
{toReact(children) || (
229+
<br />
230+
)}
231+
</Markdown>
232+
</figcaption>
233233
{/* )} */}
234234
</figure>
235235
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import typeEnum from "./typeEnum"
2+
3+
// Returns an `emojis--${count}` class name.
4+
function emojiClassName(children) {
5+
const count = (
6+
children &&
7+
children.every &&
8+
children.every(each => (
9+
each &&
10+
each.type &&
11+
each.type === typeEnum.Emoji
12+
)) &&
13+
children.length
14+
)
15+
return !count ? undefined : `emojis--${count}`
16+
}
17+
18+
export default emojiClassName

src/Editor/stylesheets/core.css

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@
1717
line-height: 1;
1818
}
1919

20-
/* https://stackoverflow.com/a/12198561 */
21-
.codex-editor p [aria-label][role="img"]:first-child:nth-last-child(1),
22-
.codex-editor p [aria-label][role="img"]:first-child:nth-last-child(2),
23-
.codex-editor p [aria-label][role="img"]:first-child:nth-last-child(2) ~ [aria-label][role="img"],
24-
.codex-editor p [aria-label][role="img"]:first-child:nth-last-child(3),
25-
.codex-editor p [aria-label][role="img"]:first-child:nth-last-child(3) ~ [aria-label][role="img"] {
20+
.codex-editor p.emojis--1 [aria-label][role="img"],
21+
.codex-editor p.emojis--2 [aria-label][role="img"],
22+
.codex-editor p.emojis--3 [aria-label][role="img"] {
2623
font-size: 2em;
2724
}
2825

0 commit comments

Comments
 (0)