Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 81 additions & 48 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,58 +15,91 @@ export const goods = [
'Garlic',
];

export const App: React.FC = () => (
<main className="section container">
<h1 className="title">No goods selected</h1>
type State = {
selectedGood: string;
};

<h1 className="title is-flex is-align-items-center">
Jam is selected
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */}
<button data-cy="ClearButton" type="button" className="delete ml-3" />
</h1>
export class App extends React.Component<{}, State> {
state = {
selectedGood: 'Jam',
};

<table className="table">
<tbody>
<tr data-cy="Good">
<td>
<button data-cy="AddButton" type="button" className="button">
+
</button>
</td>
goodHandler = (good: string) => {
this.setState({ selectedGood: good });
};

<td data-cy="GoodTitle" className="is-vcentered">
Dumplings
</td>
</tr>
removeHandler = () => {
this.setState({ selectedGood: '' });
};

<tr data-cy="Good" className="has-background-success-light">
<td>
<button
data-cy="RemoveButton"
type="button"
className="button is-info"
>
-
</button>
</td>
render() {
const { selectedGood } = this.state;

<td data-cy="GoodTitle" className="is-vcentered">
Jam
</td>
</tr>
return (
<main className="section container">
{selectedGood ? (
<h1 className="title is-flex is-align-items-center">
{`${selectedGood} is selected`}
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */}

<tr data-cy="Good">
<td>
<button data-cy="AddButton" type="button" className="button">
+
</button>
</td>
<button
data-cy="ClearButton"
type="button"
className="delete ml-3"
onClick={() => {
this.removeHandler();
}}
></button>
</h1>
) : (
<h1 className="title">No goods selected</h1>
)}

<td data-cy="GoodTitle" className="is-vcentered">
Garlic
</td>
</tr>
</tbody>
</table>
</main>
);
<table className="table">
<tbody>
{goods.map(good => (
<tr
data-cy="Good"
key={good}
className={
selectedGood === good
? 'has-background-success-light'
: undefined
}
>
<td>
{selectedGood !== good ? (
<button
data-cy="AddButton"
type="button"
className="button"
onClick={() => {
this.goodHandler(good);
}}
>
+
</button>
) : (
<button
data-cy="RemoveButton"
type="button"
className="button is-info"
onClick={() => {
this.removeHandler();
}}
>
-
</button>
)}
</td>
<td data-cy="GoodTitle" className="is-vcentered">
{good}
</td>
</tr>
))}
</tbody>
</table>
</main>
);
}
}