proton-native/examples/Notepad/index.js
Niklas Mischkulnig 6d2d32f6fc More Area features (#168)
* Add scrolling area

* Gradients

* Fix typo and add scrolling to area docs

* Implement imperative gradient api

As per discussion in #130

* Fix links in area documentation

* Update example for area gradients

* Add docs for new gradient api

* Format all docs with prettier

* Really fix docs hyperlinks

* Added to docs: ignore ...opacity for gradients
2018-11-08 18:04:32 -08:00

68 lines
1.5 KiB
JavaScript

import React, { Component } from 'react';
import fs from 'fs';
import {
render,
Window,
App,
TextInput,
Dialog,
Menu,
Box,
} from 'proton-native';
class Notepad extends Component {
state = { text: '' };
save() {
const filename = Dialog('Save');
if (filename) {
fs.writeFileSync(filename, this.state.text);
}
}
open() {
const filename = Dialog('Open');
if (filename) {
let data = fs.readFileSync(filename);
this.setState({ text: data });
}
}
shouldComponentUpdate(nextProps, nextState) {
if (typeof nextState.text === 'string') return false;
// nextState is set from input
else return true; // nextState is set from file
}
render() {
return (
<App onShouldQuit={() => console.log('Quitting')}>
<Menu label="File">
<Menu.Item type="Item" onClick={() => this.open()}>
Open
</Menu.Item>
<Menu.Item type="Item" onClick={() => this.save()}>
Save
</Menu.Item>
<Menu.Item type="Quit" />
</Menu>
<Window
onClose={() => console.log('Closing')}
title="Notes"
size={{ w: 500, h: 500 }}
>
<Box>
<TextInput
onChange={text => this.setState({ text })}
multiline={true}
>
{this.state.text}
</TextInput>
</Box>
</Window>
</App>
);
}
}
render(<Notepad />);