Skip to content

Commit 4066b4e

Browse files
authored
Merge pull request #821 from GetStream/emoji-fonts
CRS-455 Emoji flag fonts
2 parents 666c98a + 53db36e commit 4066b4e

File tree

10 files changed

+90
-2
lines changed

10 files changed

+90
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
"eslint-plugin-react-hooks": "^4.2.0",
120120
"eslint-plugin-sort-destructure-keys": "1.3.5",
121121
"eslint-plugin-typescript-sort-keys": "1.5.0",
122+
"file-loader": "^6.2.0",
122123
"htmlparser2": "^5.0.1",
123124
"husky": "^4.3.0",
124125
"jest": "^26.6.3",

src/assets/EmojiOneColor.woff2

3.19 MB
Binary file not shown.
752 KB
Binary file not shown.

src/components/Channel/Channel.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,15 @@ const ChannelInner = <
244244
onMentionsHover,
245245
} = props;
246246

247-
const { client, mutes, theme } = useChatContext<At, Ch, Co, Ev, Me, Re, Us>();
247+
const { client, mutes, theme, useImageFlagEmojisOnWindows } = useChatContext<
248+
At,
249+
Ch,
250+
Co,
251+
Ev,
252+
Me,
253+
Re,
254+
Us
255+
>();
248256
const { t } = useTranslationContext();
249257

250258
const [notifications, setNotifications] = useState<ChannelNotifications>([]);
@@ -804,7 +812,13 @@ const ChannelInner = <
804812
}
805813

806814
return (
807-
<div className={`str-chat str-chat-channel ${theme}`}>
815+
<div
816+
className={`str-chat str-chat-channel ${theme}${
817+
useImageFlagEmojisOnWindows && navigator.platform.match(/Win/)
818+
? ' str-chat--windows-flags'
819+
: ''
820+
}`}
821+
>
808822
<ChannelProvider<At, Ch, Co, Ev, Me, Re, Us> value={channelContextValue}>
809823
<div className='str-chat__container'>{children}</div>
810824
</ChannelProvider>

src/components/ChannelList/ChannelList.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ const UnMemoizedChannelList = <
291291
navOpen = false,
292292
setActiveChannel,
293293
theme,
294+
useImageFlagEmojisOnWindows,
294295
} = useChatContext<At, Ch, Co, Ev, Me, Re, Us>();
295296

296297
const channelListRef = useRef<HTMLDivElement>(null);
@@ -441,6 +442,10 @@ const UnMemoizedChannelList = <
441442
<div
442443
className={`str-chat str-chat-channel-list ${theme} ${
443444
navOpen ? 'str-chat-channel-list--open' : ''
445+
} ${
446+
useImageFlagEmojisOnWindows && navigator.platform.match(/Win/)
447+
? 'str-chat--windows-flags'
448+
: ''
444449
}`}
445450
ref={channelListRef}
446451
>

src/components/Chat/Chat.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ export type ChatProps<
8383
* - `livestream dark`
8484
*/
8585
theme?: Theme;
86+
/**
87+
* Windows 10 does not support country flag emojis out of the box.
88+
* It chooses to render these emojis as characters instead.
89+
* Stream chat can override this by loading a custom web font that will
90+
* render images (PNGs or SVGs depending on the platform) instead.
91+
* Set this prop to true if you want to use these custom emojis for Windows users.
92+
*/
93+
useImageFlagEmojisOnWindows?: boolean;
8694
};
8795

8896
/**
@@ -121,6 +129,7 @@ export const Chat = <
121129
i18nInstance,
122130
initialNavOpen = true,
123131
theme = 'messaging light',
132+
useImageFlagEmojisOnWindows = false,
124133
} = props;
125134

126135
const {
@@ -146,6 +155,7 @@ export const Chat = <
146155
openMobileNav,
147156
setActiveChannel,
148157
theme,
158+
useImageFlagEmojisOnWindows,
149159
}}
150160
>
151161
<TranslationProvider value={translators}>{children}</TranslationProvider>

src/context/ChatContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export type ChatContextValue<
3636
watchers?: { limit?: number; offset?: number },
3737
event?: React.SyntheticEvent,
3838
) => void;
39+
useImageFlagEmojisOnWindows?: boolean;
3940
};
4041

4142
export const ChatContext = React.createContext({} as ChatContextValue);

src/styles/_base.scss

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,47 @@
6767
}
6868
}
6969

70+
/* declare a font faces for our Emoji Replacement font, based on the default font used by Stream Chat React */
71+
72+
$emoji-flag-unicode-range: U+1F1E6-1F1FF;
73+
74+
/* png based woff for most browsers */
75+
@font-face {
76+
font-family: ReplaceFlagEmojiPNG;
77+
src: url("../assets/NotoColorEmoji-flags.woff2") format("woff2");
78+
/* using the unicode-range attribute to limit the reach of the Flag Emoji web font to only flags */
79+
unicode-range: $emoji-flag-unicode-range;
80+
}
81+
82+
/* svg based for firefox */
83+
@font-face {
84+
font-family: ReplaceFlagEmojiSVG;
85+
src: url("../assets/EmojiOneColor.woff2") format("woff2");
86+
unicode-range: $emoji-flag-unicode-range;
87+
}
88+
89+
.str-chat--windows-flags {
90+
.str-chat__textarea__textarea,
91+
.str-chat__message-text-inner *,
92+
.str-chat__emoji-item--entity,
93+
.emoji-mart-emoji-native * {
94+
font-family: ReplaceFlagEmojiPNG, $second-font, sans-serif;
95+
font-display: swap;
96+
}
97+
}
98+
99+
@-moz-document url-prefix() {
100+
.str-chat--windows-flags {
101+
.str-chat__textarea__textarea,
102+
.str-chat__message-text-inner *,
103+
.str-chat__emoji-item--entity,
104+
.emoji-mart-emoji-native * {
105+
font-family: ReplaceFlagEmojiSVG, $second-font, sans-serif;
106+
font-display: swap;
107+
}
108+
}
109+
}
110+
70111
.str-chat-channel-list {
71112
float: left;
72113
}

styleguidist/webpack.config.styleguidist.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ const config = {
4444
test: /\.css$/,
4545
use: ['style-loader', 'css-loader', 'postcss-loader'],
4646
},
47+
{
48+
test: /\.(woff2)$/,
49+
use: [
50+
{
51+
loader: 'file-loader',
52+
}
53+
]
54+
}
4755
],
4856
},
4957
resolve: {

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5254,6 +5254,14 @@ file-entry-cache@^6.0.1:
52545254
dependencies:
52555255
flat-cache "^3.0.4"
52565256

5257+
file-loader@^6.2.0:
5258+
version "6.2.0"
5259+
resolved "https://registry.yarnpkg.com/file-loader/-/file-loader-6.2.0.tgz#baef7cf8e1840df325e4390b4484879480eebe4d"
5260+
integrity sha512-qo3glqyTa61Ytg4u73GultjHGjdRyig3tG6lPtyX/jOEJvHif9uB0/OCI2Kif6ctF3caQTW2G5gym21oAsI4pw==
5261+
dependencies:
5262+
loader-utils "^2.0.0"
5263+
schema-utils "^3.0.0"
5264+
52575265
file-selector@^0.1.12:
52585266
version "0.1.19"
52595267
resolved "https://registry.yarnpkg.com/file-selector/-/file-selector-0.1.19.tgz#8ecc9d069a6f544f2e4a096b64a8052e70ec8abf"

0 commit comments

Comments
 (0)