Skip to content

Commit

Permalink
use AutoSuggestComponent & configure web font loader
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtekeste committed Jun 11, 2017
1 parent 787624b commit f3bdc3d
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/components/TypeFace.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import React, { Component } from 'react';
import WebFont from 'webfontloader';
import PropTypes from 'prop-types';
import AutoSuggest from './AutoSuggest';

const fontFamilies = new Set();

export default class TypeFace extends Component {
static fetchFont(newVal) {
fontFamilies.add(newVal);
WebFont.load({
google: {
families: Array.from(fontFamilies),
},
});
}

export default class GoogleFont extends Component {
constructor(props) {
super(props);
this.state = {
Expand All @@ -10,21 +23,21 @@ export default class GoogleFont extends Component {
this.handleChange = this.handleChange.bind(this);
}

handleChange(event) {
const newVal = event.target.value;
handleChange(newVal) {
this.setState({ fontFamily: newVal });
this.props.handleChange(newVal);
TypeFace.fetchFont(newVal);
}

render() {
return (
<div>
<input type="text" value={this.state.fontFamily} onChange={this.handleChange} />
<AutoSuggest handleChange={this.handleChange} />
</div>
);
}
}

GoogleFont.propTypes = {
TypeFace.propTypes = {
handleChange: PropTypes.func.isRequired,
};

0 comments on commit f3bdc3d

Please sign in to comment.