Skip to content

Instantly share code, notes, and snippets.

@yuschick
Last active November 9, 2017 07:00
Show Gist options
  • Save yuschick/7323e40b4d441ab8d442b05e71727c2a to your computer and use it in GitHub Desktop.
Save yuschick/7323e40b4d441ab8d442b05e71727c2a to your computer and use it in GitHub Desktop.
Accessible Web Apps with React, TypeScript & Ally.js
interface AppState {
showDialog: boolean;
}
class App extends React.Component<{}, AppState> {
state: AppState;
constructor(props: {}) {
super(props);
this.state = {
showDialog: false
};
}
toggleDialog() {
this.setState({ showDialog: !this.state.showDialog });
}
checkForDialog() {
if (this.state.showDialog) {
return this.getDialog();
} else {
return false;
}
}
getDialog() {
return (
<Dialog
title="Favourite Holiday Dialog"
description="Add your favourite holiday to the list"
close={() => { this.toggleDialog(); }}
>
<form className="dialog-content">
<header>
<h1 id="dialog-title">Holiday Entry</h1>
<p id="dialog-description">Please enter your favourite holiday.</p>
</header>
<section>
<div className="field-container">
<label htmlFor="within-dialog">Favourite Holiday</label>
<input id="within-dialog" />
</div>
</section>
<footer>
<div className="btns-container">
<Button
type="secondary"
clickHandler={() => { this.toggleDialog(); }}
msg="Close"
/>
<Button
type="primary"
clickHandler={() => { this.toggleDialog(); }}
msg="Save"
/>
</div>
</footer>
</form>
</Dialog>
);
}
render() {
return (
<div className="site-container">
{this.checkForDialog()}
<header>
<h1>Ally.js with React &amp; Typescript</h1>
</header>
<main className="content-container">
<div className="field-container">
<label htmlFor="name-field">Name:</label>
<input type="text" id="name-field" placeholder="Enter your name" />
</div>
<div className="field-container">
<label htmlFor="food-field">Favourite Food:</label>
<input type="text" id="food-field" placeholder="Enter your favourite food" />
</div>
<div className="field-container">
<Button
type="primary"
msg="Show Dialog"
clickHandler={() => { this.toggleDialog(); }}
/>
</div>
</main>
<footer className="content-container has-spacer">
<h2>Web App Accessibility with React &amp; Typescript</h2>
</footer>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment