Last active
November 26, 2021 02:46
-
-
Save gentamura/d73794c5a9ca58c974906a56c9390623 to your computer and use it in GitHub Desktop.
Font Family checks on several OS by Next.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createFontDebugComponent = (Component) => ( | |
Array<number>(9) | |
.fill(0) | |
.map<number>((_, i) => i + 1) | |
.map<number>((size) => { | |
const weight = size * 100; | |
return ( | |
<Component size={size} weight={weight} /> | |
); | |
}) | |
); | |
const Typography = (): JSX.Element => ( | |
<div className="p-4"> | |
<ul style={{ listStyle: 'none', paddingLeft: 0 }}> | |
{/* | |
Hiragino sans W? 指定はchrome、MacOSが対応。iOSはW3、W6、W7だけフォントがあり、太さはregularのみ。 | |
結論からいうと、iOS、PC共通にするには、system fontがHiragino Sansなので、Hiragino sans W?を利用せず、font-weightのみで設定する方がよさそう。 | |
*/} | |
<li><pre>iOS</pre></li> | |
{ | |
createFontDebugComponent(({ size, weight }) => ( | |
<li style={{ fontFamily: `-apple-system, Hiragino sans W${size}, Hiragino sans`, fontWeight: weight }}> | |
あいうえお (SF Pro Text or Display) { weight } | |
あいうえお (Hiragino sans W{ size }) | |
あいうえお (Hiragino sans) { weight } | |
</li> | |
)) | |
} | |
<li><pre>fontFamily: '-apple-system', fontWeight: [100-900]</pre></li> | |
{ | |
createFontDebugComponent(({ size, weight }) => ( | |
<li style={{ fontFamily: '-apple-system', fontWeight: weight }}> | |
あいうえお (SF Pro Text or Display) { weight } | |
</li> | |
)) | |
} | |
<li><pre>fontFamily: 'Hiragino Sans W[1-9]'</pre></li> | |
{ | |
createFontDebugComponent(({ size, weight }) => ( | |
<li style={{ fontFamily: `Hiragino Sans W${size}` }}> | |
あいうえお (Hiragino Sans W{ size }) | |
</li> | |
)) | |
} | |
<li><pre>fontFamily: 'Hiragino Sans', fontWeight: [100-900]</pre></li> | |
{ | |
createFontDebugComponent(({ size, weight }) => ( | |
<li style={{ fontFamily: 'Hiragino Sans', fontWeight: weight }}> | |
あいうえお (Hiragino Sans) { weight } | |
</li> | |
)) | |
} | |
<li><pre>Android</pre></li> | |
<li><pre>fontFamily: 'Noto Sans JP', fontWeight: [100-900]</pre></li> | |
{ | |
createFontDebugComponent(({ size, weight }) => ( | |
<li style={{ fontFamily: 'Noto Sans JP', fontWeight: weight }}> | |
あいうえお (Noto Sans JP) { weight } | |
</li> | |
)) | |
} | |
<li><pre>fontFamily: default(Noto Sans CJK JP), fontWeight: [100-900]</pre></li> | |
{ | |
createFontDebugComponent(({ size, weight }) => ( | |
<li style={{ fontWeight: weight }}> | |
あいうえお (default font family) { weight } | |
</li> | |
)) | |
} | |
<li><pre>fontFamily: 'Roboto', fontWeight: [100-900]</pre></li> | |
{ | |
createFontDebugComponent(({ size, weight }) => ( | |
<li style={{ fontFamily: 'Roboto', fontWeight: weight }}> | |
default font family { weight } | |
</li> | |
)) | |
} | |
<li><pre>fontFamily: default(Noto Serif), fontWeight: [100-900]</pre></li> | |
{ | |
createFontDebugComponent(({ size, weight }) => ( | |
<li style={{ fontWeight: weight }}> | |
default font family { weight } | |
</li> | |
)) | |
} | |
</ul> | |
</div> | |
); | |
export default Typography; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment