forked from external-repos/squoosh
Convert remaining components to TypeScript.
This commit is contained in:
@@ -3,6 +3,7 @@ import { updater, toggle, When } from '../../lib/util';
|
|||||||
import Fab from '../fab';
|
import Fab from '../fab';
|
||||||
import Header from '../header';
|
import Header from '../header';
|
||||||
// import Drawer from 'async!../drawer';
|
// import Drawer from 'async!../drawer';
|
||||||
|
const Drawer = require('async!../drawer').default;
|
||||||
import Home from '../home';
|
import Home from '../home';
|
||||||
import * as style from './style.scss';
|
import * as style from './style.scss';
|
||||||
|
|
||||||
@@ -81,6 +82,9 @@ export default class App extends Component<Props, State> {
|
|||||||
|
|
||||||
render({ url }, { showDrawer, showFab, files }) {
|
render({ url }, { showDrawer, showFab, files }) {
|
||||||
if (showDrawer) this.enableDrawer = true;
|
if (showDrawer) this.enableDrawer = true;
|
||||||
|
|
||||||
|
if (showFab===true) showFab = files.length>0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="app" class={style.app}>
|
<div id="app" class={style.app}>
|
||||||
<Fab showing={showFab} />
|
<Fab showing={showFab} />
|
||||||
@@ -88,11 +92,9 @@ export default class App extends Component<Props, State> {
|
|||||||
<Header toggleDrawer={this.toggleDrawer} loadFile={this.loadFile} />
|
<Header toggleDrawer={this.toggleDrawer} loadFile={this.loadFile} />
|
||||||
|
|
||||||
{/* Avoid loading & rendering the drawer until the first time it is shown. */}
|
{/* Avoid loading & rendering the drawer until the first time it is shown. */}
|
||||||
{/*
|
|
||||||
<When value={showDrawer}>
|
<When value={showDrawer}>
|
||||||
<Drawer showing={showDrawer} openDrawer={this.openDrawer} closeDrawer={this.closeDrawer} />
|
<Drawer showing={showDrawer} openDrawer={this.openDrawer} closeDrawer={this.closeDrawer} />
|
||||||
</When>
|
</When>
|
||||||
*/}
|
|
||||||
|
|
||||||
{/*
|
{/*
|
||||||
Note: this is normally where a <Router> with auto code-splitting goes.
|
Note: this is normally where a <Router> with auto code-splitting goes.
|
||||||
|
|||||||
@@ -3,20 +3,31 @@ import Icon from 'preact-material-components/Icon';
|
|||||||
import 'preact-material-components/Icon/style.css';
|
import 'preact-material-components/Icon/style.css';
|
||||||
import Fab from 'preact-material-components/Fab';
|
import Fab from 'preact-material-components/Fab';
|
||||||
import RadialProgress from 'material-radial-progress';
|
import RadialProgress from 'material-radial-progress';
|
||||||
import style from './style';
|
import * as style from './style.scss';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
showing: boolean
|
||||||
|
};
|
||||||
|
type State = {
|
||||||
|
loading: boolean
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class AppFab extends Component<Props, State> {
|
||||||
|
state: State = {
|
||||||
|
loading: false
|
||||||
|
};
|
||||||
|
|
||||||
export default class AppFab extends Component {
|
|
||||||
handleClick = () => {
|
handleClick = () => {
|
||||||
console.log('TODO: Save the file to disk.');
|
console.log('TODO: Save the file to disk.');
|
||||||
this.setState({ loading: true });
|
this.setState({ loading: true });
|
||||||
setTimeout( () => {
|
setTimeout( () => {
|
||||||
this.setState({ loading: false });
|
this.setState({ loading: false });
|
||||||
}, 100000);
|
}, 1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
render({}, { loading }) {
|
render({ showing }, { loading }) {
|
||||||
return (
|
return (
|
||||||
<Fab ripple secondary class={style.fab} onClick={this.handleClick}>
|
<Fab ripple secondary exited={showing===false} class={style.fab} onClick={this.handleClick}>
|
||||||
{ loading ? (
|
{ loading ? (
|
||||||
<RadialProgress primary class={style.progress} />
|
<RadialProgress primary class={style.progress} />
|
||||||
) : (
|
) : (
|
||||||
@@ -1,13 +1,30 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component } from 'preact';
|
||||||
import Toolbar from 'preact-material-components/Toolbar';
|
import Toolbar from 'preact-material-components/Toolbar';
|
||||||
import cx from 'classnames';
|
import cx from 'classnames';
|
||||||
import style from './style';
|
import * as style from './style.scss';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
toggleDrawer?(),
|
||||||
|
showHeader?(),
|
||||||
|
showFab?(),
|
||||||
|
loadFile?(File)
|
||||||
|
};
|
||||||
|
|
||||||
|
type State = {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class Header extends Component<Props, State> {
|
||||||
|
input: HTMLInputElement;
|
||||||
|
|
||||||
export default class Header extends Component {
|
|
||||||
setInputRef = c => {
|
setInputRef = c => {
|
||||||
this.input = c;
|
this.input = c;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
upload = () => {
|
||||||
|
this.input.click();
|
||||||
|
};
|
||||||
|
|
||||||
handleFiles = () => {
|
handleFiles = () => {
|
||||||
let files = this.input.files;
|
let files = this.input.files;
|
||||||
if (files.length) {
|
if (files.length) {
|
||||||
@@ -15,18 +32,6 @@ export default class Header extends Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
upload = () => {
|
|
||||||
// let input = document.createElement('input');
|
|
||||||
// input.type = 'file';
|
|
||||||
// // input.multiple = true;
|
|
||||||
// document.body.appendChild(input);
|
|
||||||
// input.addEventListener('change', e => {
|
|
||||||
|
|
||||||
// });
|
|
||||||
// input.click();
|
|
||||||
this.input.click();
|
|
||||||
};
|
|
||||||
|
|
||||||
render({ toggleDrawer, showHeader, showFab }) {
|
render({ toggleDrawer, showHeader, showFab }) {
|
||||||
return (
|
return (
|
||||||
<Toolbar fixed class={cx(style.toolbar, 'inert', showHeader===false && style.minimal)}>
|
<Toolbar fixed class={cx(style.toolbar, 'inert', showHeader===false && style.minimal)}>
|
||||||
Reference in New Issue
Block a user