Font support (#149)

* Add font family/font size support

* Load fonts with css

* Change settings item order
main
Jake Dexheimer 7 years ago committed by Michael Fix
parent ac28311429
commit 38cc0f91af

@ -69,6 +69,7 @@ Carbon is a project by <a href="http://dawnlabs.io/"><img width=8% src="https://
Thanks goes out to all these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): Thanks goes out to all these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
| [<img src="https://avatars0.githubusercontent.com/u/10078572?v=4" width="100px;"/><br /><sub><b>briandennis</b></sub>](https://github.com/briandennis)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=briandennis "Code") [πŸ“–](https://github.com/dawnlabs/carbon/commits?author=briandennis "Documentation") [πŸš‡](#infra-briandennis "Infrastructure (Hosting, Build-Tools, etc)") [πŸ‘€](#review-briandennis "Reviewed Pull Requests") | [<img src="https://avatars0.githubusercontent.com/u/8397708?v=4" width="100px;"/><br /><sub><b>mfix22</b></sub>](https://github.com/mfix22)<br />[πŸ’¬](#question-mfix22 "Answering Questions") [πŸ’»](https://github.com/dawnlabs/carbon/commits?author=mfix22 "Code") [πŸ€”](#ideas-mfix22 "Ideas, Planning, & Feedback") | [<img src="https://avatars1.githubusercontent.com/u/10369094?v=4" width="100px;"/><br /><sub><b>jakedex</b></sub>](https://github.com/jakedex)<br />[πŸ’¬](#question-jakedex "Answering Questions") [πŸ’»](https://github.com/dawnlabs/carbon/commits?author=jakedex "Code") [🎨](#design-jakedex "Design") [πŸ“Ή](#video-jakedex "Videos") | [<img src="https://avatars1.githubusercontent.com/u/10191084?v=4" width="100px;"/><br /><sub><b>andrewda</b></sub>](https://github.com/andrewda)<br />[πŸ’¬](#question-andrewda "Answering Questions") [πŸ’»](https://github.com/dawnlabs/carbon/commits?author=andrewda "Code") [πŸ›](https://github.com/dawnlabs/carbon/issues?q=author%3Aandrewda "Bug reports") [πŸ‘€](#review-andrewda "Reviewed Pull Requests") | [<img src="https://avatars2.githubusercontent.com/u/14703164?v=4" width="100px;"/><br /><sub><b>yeskunall</b></sub>](https://github.com/yeskunall)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=yeskunall "Code") [πŸ“–](https://github.com/dawnlabs/carbon/commits?author=yeskunall "Documentation") [πŸ”§](#tool-yeskunall "Tools") [πŸ›](https://github.com/dawnlabs/carbon/issues?q=author%3Ayeskunall "Bug reports") | [<img src="https://avatars1.githubusercontent.com/u/2652676?v=4" width="100px;"/><br /><sub><b>stoshfabricius</b></sub>](https://github.com/stoshfabricius)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=stoshfabricius "Code") | [<img src="https://avatars1.githubusercontent.com/u/11639896?v=4" width="100px;"/><br /><sub><b>jkling38</b></sub>](https://github.com/jkling38)<br />[πŸ“–](https://github.com/dawnlabs/carbon/commits?author=jkling38 "Documentation") | | [<img src="https://avatars0.githubusercontent.com/u/10078572?v=4" width="100px;"/><br /><sub><b>briandennis</b></sub>](https://github.com/briandennis)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=briandennis "Code") [πŸ“–](https://github.com/dawnlabs/carbon/commits?author=briandennis "Documentation") [πŸš‡](#infra-briandennis "Infrastructure (Hosting, Build-Tools, etc)") [πŸ‘€](#review-briandennis "Reviewed Pull Requests") | [<img src="https://avatars0.githubusercontent.com/u/8397708?v=4" width="100px;"/><br /><sub><b>mfix22</b></sub>](https://github.com/mfix22)<br />[πŸ’¬](#question-mfix22 "Answering Questions") [πŸ’»](https://github.com/dawnlabs/carbon/commits?author=mfix22 "Code") [πŸ€”](#ideas-mfix22 "Ideas, Planning, & Feedback") | [<img src="https://avatars1.githubusercontent.com/u/10369094?v=4" width="100px;"/><br /><sub><b>jakedex</b></sub>](https://github.com/jakedex)<br />[πŸ’¬](#question-jakedex "Answering Questions") [πŸ’»](https://github.com/dawnlabs/carbon/commits?author=jakedex "Code") [🎨](#design-jakedex "Design") [πŸ“Ή](#video-jakedex "Videos") | [<img src="https://avatars1.githubusercontent.com/u/10191084?v=4" width="100px;"/><br /><sub><b>andrewda</b></sub>](https://github.com/andrewda)<br />[πŸ’¬](#question-andrewda "Answering Questions") [πŸ’»](https://github.com/dawnlabs/carbon/commits?author=andrewda "Code") [πŸ›](https://github.com/dawnlabs/carbon/issues?q=author%3Aandrewda "Bug reports") [πŸ‘€](#review-andrewda "Reviewed Pull Requests") | [<img src="https://avatars2.githubusercontent.com/u/14703164?v=4" width="100px;"/><br /><sub><b>yeskunall</b></sub>](https://github.com/yeskunall)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=yeskunall "Code") [πŸ“–](https://github.com/dawnlabs/carbon/commits?author=yeskunall "Documentation") [πŸ”§](#tool-yeskunall "Tools") [πŸ›](https://github.com/dawnlabs/carbon/issues?q=author%3Ayeskunall "Bug reports") | [<img src="https://avatars1.githubusercontent.com/u/2652676?v=4" width="100px;"/><br /><sub><b>stoshfabricius</b></sub>](https://github.com/stoshfabricius)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=stoshfabricius "Code") | [<img src="https://avatars1.githubusercontent.com/u/11639896?v=4" width="100px;"/><br /><sub><b>jkling38</b></sub>](https://github.com/jkling38)<br />[πŸ“–](https://github.com/dawnlabs/carbon/commits?author=jkling38 "Documentation") |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: | | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars1.githubusercontent.com/u/225946?v=4" width="100px;"/><br /><sub><b>otobrglez</b></sub>](https://github.com/otobrglez)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=otobrglez "Code") | [<img src="https://avatars3.githubusercontent.com/u/11488612?v=4" width="100px;"/><br /><sub><b>darahak</b></sub>](https://github.com/darahak)<br />[πŸ“–](https://github.com/dawnlabs/carbon/commits?author=darahak "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/246651?v=4" width="100px;"/><br /><sub><b>dom96</b></sub>](https://github.com/dom96)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=dom96 "Code") | [<img src="https://avatars3.githubusercontent.com/u/784056?v=4" width="100px;"/><br /><sub><b>elrumordelaluz</b></sub>](https://github.com/elrumordelaluz)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=elrumordelaluz "Code") | [<img src="https://avatars2.githubusercontent.com/u/21217?v=4" width="100px;"/><br /><sub><b>cjb</b></sub>](https://github.com/cjb)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=cjb "Code") | [<img src="https://avatars1.githubusercontent.com/u/5427083?v=4" width="100px;"/><br /><sub><b>Krzysztof-Cieslak</b></sub>](https://github.com/Krzysztof-Cieslak)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=Krzysztof-Cieslak "Code") | [<img src="https://avatars0.githubusercontent.com/u/2369851?v=4" width="100px;"/><br /><sub><b>fernahh</b></sub>](https://github.com/fernahh)<br />[πŸ“–](https://github.com/dawnlabs/carbon/commits?author=fernahh "Documentation") | | [<img src="https://avatars1.githubusercontent.com/u/225946?v=4" width="100px;"/><br /><sub><b>otobrglez</b></sub>](https://github.com/otobrglez)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=otobrglez "Code") | [<img src="https://avatars3.githubusercontent.com/u/11488612?v=4" width="100px;"/><br /><sub><b>darahak</b></sub>](https://github.com/darahak)<br />[πŸ“–](https://github.com/dawnlabs/carbon/commits?author=darahak "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/246651?v=4" width="100px;"/><br /><sub><b>dom96</b></sub>](https://github.com/dom96)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=dom96 "Code") | [<img src="https://avatars3.githubusercontent.com/u/784056?v=4" width="100px;"/><br /><sub><b>elrumordelaluz</b></sub>](https://github.com/elrumordelaluz)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=elrumordelaluz "Code") | [<img src="https://avatars2.githubusercontent.com/u/21217?v=4" width="100px;"/><br /><sub><b>cjb</b></sub>](https://github.com/cjb)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=cjb "Code") | [<img src="https://avatars1.githubusercontent.com/u/5427083?v=4" width="100px;"/><br /><sub><b>Krzysztof-Cieslak</b></sub>](https://github.com/Krzysztof-Cieslak)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=Krzysztof-Cieslak "Code") | [<img src="https://avatars0.githubusercontent.com/u/2369851?v=4" width="100px;"/><br /><sub><b>fernahh</b></sub>](https://github.com/fernahh)<br />[πŸ“–](https://github.com/dawnlabs/carbon/commits?author=fernahh "Documentation") |

@ -1,7 +1,6 @@
import { EOL } from 'os' import { EOL } from 'os'
import * as hljs from 'highlight.js' import * as hljs from 'highlight.js'
import React from 'react' import React from 'react'
import domtoimage from 'dom-to-image'
import Spinner from 'react-spinner' import Spinner from 'react-spinner'
import toHash from 'tohash' import toHash from 'tohash'
import debounce from 'lodash.debounce' import debounce from 'lodash.debounce'
@ -26,7 +25,9 @@ const DEFAULT_SETTINGS = {
dropShadowBlurRadius: '68px', dropShadowBlurRadius: '68px',
theme: 'seti', theme: 'seti',
windowTheme: 'none', windowTheme: 'none',
language: DEFAULT_LANGUAGE language: DEFAULT_LANGUAGE,
fontFamily: 'Fira Code',
fontSize: '14px'
} }
class Carbon extends React.Component { class Carbon extends React.Component {
@ -198,8 +199,10 @@ class Carbon extends React.Component {
min-width: inherit; min-width: inherit;
padding: 18px 18px; padding: 18px 18px;
${config.lineNumbers ? 'padding-left: 12px;' : ''} border-radius: 5px; ${config.lineNumbers ? 'padding-left: 12px;' : ''} border-radius: 5px;
font-family: Hack, monospace !important; font-family: ${config.fontFamily};
font-size: 0.8rem; font-size: ${config.fontSize};
font-variant-ligatures: contextual;
font-feature-settings: 'calt' 1;
user-select: none; user-select: none;
} }

@ -0,0 +1,84 @@
import React from 'react'
import Checkmark from './svg/Checkmark'
import { COLORS, FONTS } from '../lib/constants'
export default class extends React.Component {
constructor(props) {
super()
this.state = { isVisible: false }
this.select = this.select.bind(this)
this.toggle = this.toggle.bind(this)
}
select(fontId) {
if (this.props.selected !== fontId) {
this.props.onChange(fontId)
}
}
toggle() {
this.setState({ isVisible: !this.state.isVisible })
}
renderListItems() {
return FONTS.map((font, i) => (
<div className="list-item" key={i} onClick={this.select.bind(null, font.id)}>
<span style={{ fontFamily: font.id }}>{font.name}</span>
{this.props.selected === font.id ? <Checkmark /> : null}
<style jsx>{`
.list-item {
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
user-select: none;
padding: 8px 16px;
border-bottom: 0.5px solid ${COLORS.SECONDARY};
background: rgba(255, 255, 255, 0.165);
}
.list-item:first-of-type {
border-top: 0.5px solid ${COLORS.SECONDARY};
}
.list-item:last-of-type {
border-bottom: none;
}
`}</style>
</div>
))
}
render() {
const selectedFont = FONTS.filter(font => font.id === this.props.selected)[0]
return (
<div className="font-select-container">
<div
className={`display ${this.state.isVisible ? 'is-visible' : ''}`}
onClick={this.toggle}
>
<span className="label">Font family</span>
<span style={{ fontFamily: selectedFont.id }}>{selectedFont.name}</span>
</div>
<div className="list">{this.renderListItems()}</div>
<style jsx>{`
.display {
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
user-select: none;
padding: 8px;
}
.list {
display: none;
margin-top: -1px;
max-height: 80px;
overflow-y: scroll;
}
.is-visible + .list {
display: block;
}
`}</style>
</div>
)
}
}

@ -1,6 +1,7 @@
import Head from 'next/head' import Head from 'next/head'
import { THEMES, COLORS } from '../lib/constants' import { THEMES, COLORS } from '../lib/constants'
import Reset from './style/Reset' import Reset from './style/Reset'
import Font from './style/Font'
import Typography from './style/Typography' import Typography from './style/Typography'
export default () => ( export default () => (
@ -45,10 +46,10 @@ export default () => (
} }
/> />
))} ))}
<link rel="stylesheet" href="//cdn.jsdelivr.net/font-hack/2.020/css/hack-extended.min.css" />
<link rel="stylesheet" type="text/css" href="/static/react-spinner.css" /> <link rel="stylesheet" type="text/css" href="/static/react-spinner.css" />
</Head> </Head>
<Reset /> <Reset />
<Font />
<Typography /> <Typography />
<style jsx>{` <style jsx>{`
.meta { .meta {

@ -2,6 +2,7 @@ import React from 'react'
import enhanceWithClickOutside from 'react-click-outside' import enhanceWithClickOutside from 'react-click-outside'
import SettingsIcon from './svg/Settings' import SettingsIcon from './svg/Settings'
import ThemeSelect from './ThemeSelect' import ThemeSelect from './ThemeSelect'
import FontSelect from './FontSelect'
import Slider from './Slider' import Slider from './Slider'
import Toggle from './Toggle' import Toggle from './Toggle'
import WindowPointer from './WindowPointer' import WindowPointer from './WindowPointer'
@ -40,6 +41,17 @@ class Settings extends React.Component {
selected={this.props.enabled.windowTheme || 'none'} selected={this.props.enabled.windowTheme || 'none'}
onChange={this.props.onChange.bind(null, 'windowTheme')} onChange={this.props.onChange.bind(null, 'windowTheme')}
/> />
<FontSelect
selected={this.props.enabled.fontFamily || 'Fira Code'}
onChange={this.props.onChange.bind(null, 'fontFamily')}
/>
<Slider
label="Font size"
value={this.props.enabled.fontSize || 13}
minValue={10}
maxValue={18}
onChange={this.props.onChange.bind(null, 'fontSize')}
/>
<Toggle <Toggle
label="Window controls" label="Window controls"
enabled={this.props.enabled.windowControls} enabled={this.props.enabled.windowControls}

@ -27,9 +27,9 @@ export default class extends React.Component {
<div <div
className="slider-bg" className="slider-bg"
style={{ style={{
transform: `translate3d(${parseInt(this.props.value) * transform: `translate3d(${(parseInt(this.props.value) - minValue) *
1.0 / 1.0 /
maxValue * (maxValue - minValue) *
100}%, 0px, 0px)` 100}%, 0px, 0px)`
}} }}
/> />

@ -0,0 +1,93 @@
export default () => (
<style jsx global>{`
@font-face {
font-family: 'Hack';
src: url('http://cdn.jsdelivr.net/font-hack/2.020/fonts/eot/hack-regular-webfont.eot?v=2.020');
src: url('http://cdn.jsdelivr.net/font-hack/2.020/fonts/eot/hack-regular-webfont.eot?#iefix&v=2.020')
format('embedded-opentype'),
url('http://cdn.jsdelivr.net/font-hack/2.020/fonts/woff2/hack-regular-webfont.woff2?v=2.020')
format('woff2'),
url('http://cdn.jsdelivr.net/font-hack/2.020/fonts/woff/hack-regular-webfont.woff?v=2.020')
format('woff'),
url('http://cdn.jsdelivr.net/font-hack/2.020/fonts/web-ttf/hack-regular-webfont.ttf?v=2.020')
format('truetype');
font-weight: 400;
font-style: normal;
}
@font-face {
font-family: 'Fira Code';
src: url('http://cdn.rawgit.com/tonsky/FiraCode/1.204/distr/eot/FiraCode-Regular.eot');
src: url('http://cdn.rawgit.com/tonsky/FiraCode/1.204/distr/eot/FiraCode-Regular.eot')
format('embedded-opentype'),
url('http://cdn.rawgit.com/tonsky/FiraCode/1.204/distr/woff2/FiraCode-Regular.woff2')
format('woff2'),
url('http://cdn.rawgit.com/tonsky/FiraCode/1.204/distr/woff/FiraCode-Regular.woff')
format('woff'),
url('http://cdn.rawgit.com/tonsky/FiraCode/1.204/distr/ttf/FiraCode-Regular.ttf')
format('truetype');
font-weight: 400;
font-style: normal;
}
/* latin */
@font-face {
font-family: 'Anonymous Pro';
font-style: normal;
font-weight: 400;
src: local('Anonymous Pro Regular'), local('AnonymousPro-Regular'),
url(https://fonts.gstatic.com/s/anonymouspro/v11/Zhfjj_gat3waL4JSju74E3n3cbdKJftHIk87C9ihfO8.woff2)
format('woff2');
unicode-range: U+0000-00ff, U+0131, U+0152-0153, U+02bb-02bc, U+02c6, U+02da, U+02dc,
U+2000-206f, U+2074, U+20ac, U+2122, U+2212, U+2215;
}
/* latin */
@font-face {
font-family: 'Droid Sans Mono';
font-style: normal;
font-weight: 400;
src: local('Droid Sans Mono Regular'), local('DroidSansMono-Regular'),
url(https://fonts.gstatic.com/s/droidsansmono/v9/ns-m2xQYezAtqh7ai59hJVlgUn8GogvcKKzoM9Dh-4E.woff2)
format('woff2');
unicode-range: U+0000-00ff, U+0131, U+0152-0153, U+02bb-02bc, U+02c6, U+02da, U+02dc,
U+2000-206f, U+2074, U+20ac, U+2122, U+2212, U+2215;
}
/* latin */
@font-face {
font-family: 'Inconsolata';
font-style: normal;
font-weight: 400;
src: local('Inconsolata Regular'), local('Inconsolata-Regular'),
url(https://fonts.gstatic.com/s/inconsolata/v16/BjAYBlHtW3CJxDcjzrnZCIgp9Q8gbYrhqGlRav_IXfk.woff2)
format('woff2');
unicode-range: U+0000-00ff, U+0131, U+0152-0153, U+02bb-02bc, U+02c6, U+02da, U+02dc,
U+2000-206f, U+2074, U+20ac, U+2122, U+2212, U+2215;
}
/* latin */
@font-face {
font-family: 'Source Code Pro';
font-style: normal;
font-weight: 400;
src: local('Source Code Pro'), local('SourceCodePro-Regular'),
url(https://fonts.gstatic.com/s/sourcecodepro/v7/mrl8jkM18OlOQN8JLgasD5bPFduIYtoLzwST68uhz_Y.woff2)
format('woff2');
unicode-range: U+0000-00ff, U+0131, U+0152-0153, U+02bb-02bc, U+02c6, U+02da, U+02dc,
U+2000-206f, U+2074, U+20ac, U+2122, U+2212, U+2215;
}
/* latin */
@font-face {
font-family: 'Ubuntu Mono';
font-style: normal;
font-weight: 400;
src: local('Ubuntu Mono'), local('UbuntuMono-Regular'),
url(https://fonts.gstatic.com/s/ubuntumono/v7/ViZhet7Ak-LRXZMXzuAfkYgp9Q8gbYrhqGlRav_IXfk.woff2)
format('woff2');
unicode-range: U+0000-00ff, U+0131, U+0152-0153, U+02bb-02bc, U+02c6, U+02da, U+02dc,
U+2000-206f, U+2074, U+20ac, U+2122, U+2212, U+2215;
}
`}</style>
)

@ -1,5 +1,15 @@
import toHash from 'tohash' import toHash from 'tohash'
export const FONTS = [
{ id: 'Anonymous Pro', name: 'Anonymous Pro' },
{ id: 'Droid Sans Mono', name: 'Droid Sans Mono' },
{ id: 'Fira Code', name: 'Fira Code' },
{ id: 'Hack', name: 'Hack' },
{ id: 'Inconsolata', name: 'Inconsolata' },
{ id: 'Source Code Pro', name: 'Source Code Pro' },
{ id: 'Ubuntu Mono', name: 'Ubuntu Mono' }
]
export const THEMES = [ export const THEMES = [
{ {
id: '3024-night', id: '3024-night',

@ -190,8 +190,7 @@ class Editor extends React.Component {
)} )}
</ReadFileDropContainer> </ReadFileDropContainer>
</div> </div>
<style jsx> <style jsx>{`
{`
#editor { #editor {
background: ${COLORS.BLACK}; background: ${COLORS.BLACK};
border: 3px solid ${COLORS.SECONDARY}; border: 3px solid ${COLORS.SECONDARY};
@ -203,8 +202,7 @@ class Editor extends React.Component {
display: flex; display: flex;
margin-left: auto; margin-left: auto;
} }
`} `}</style>
</style>
</Page> </Page>
) )
} }

Loading…
Cancel
Save