Skip to content

Commit

Permalink
Chidren aren't always of string type (#1)
Browse files Browse the repository at this point in the history
* chidren arent always of string type
* add tests
  • Loading branch information
gorpacrate authored and barbuza committed Aug 23, 2017
1 parent c05b5af commit b0cddfe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
17 changes: 17 additions & 0 deletions src/react-emoji.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,21 @@ describe("ReactEmoji", () => {
</div>,
);
});

test("multiple different children", () => {
match(
<ReactEmoji>
<div />
:smile:
</ReactEmoji>,
<div>
<div></div>
<img
width="20px"
height="20px"
src="https://twemoji.maxcdn.com/svg/1f604.svg"
/>
</div>,
);
});
});
20 changes: 14 additions & 6 deletions src/react-emoji.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,22 @@ export interface IReactEmojiProps {
attrs?: React.HTMLAttributes<HTMLElement>;
imgAttrs?: React.HTMLAttributes<HTMLImageElement>;
svgAttrs?: React.SVGAttributes<SVGSVGElement>;
children: string;
children: React.ReactNode;
symbolsUrl?: string;
type?: EmojiType;
tag?: string;
}

export const ReactEmoji: React.SFC<IReactEmojiProps> = (props) => React.createElement(
props.tag || "div",
props.attrs,
...emojifyText(props.children, props),
);
export const ReactEmoji: React.SFC<IReactEmojiProps> = (props) => {
const children = React.Children.map(props.children, (child) => {
if (typeof child === "string") {
return emojifyText(child, props);
}
return child;
});
return React.createElement(
props.tag || "div",
props.attrs,
...children,
);
};

0 comments on commit b0cddfe

Please sign in to comment.