diff --git a/package-lock.json b/package-lock.json index e99a306fb..901eb7699 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ }, "devDependencies": { "@cypress/react18": "^2.0.1", - "@mate-academy/scripts": "^1.8.5", + "@mate-academy/scripts": "^2.1.2", "@mate-academy/students-ts-config": "*", "@mate-academy/stylelint-config": "*", "@types/node": "^20.14.10", @@ -1170,10 +1170,11 @@ } }, "node_modules/@mate-academy/scripts": { - "version": "1.8.5", - "resolved": "https://registry.npmjs.org/@mate-academy/scripts/-/scripts-1.8.5.tgz", - "integrity": "sha512-mHRY2FkuoYCf5U0ahIukkaRo5LSZsxrTSgMJheFoyf3VXsTvfM9OfWcZIDIDB521kdPrScHHnRp+JRNjCfUO5A==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@mate-academy/scripts/-/scripts-2.1.2.tgz", + "integrity": "sha512-gUXFdqqOfYzF9R3RSx2pCa5GLdOkxB9bFbF+dpUpzucdgGAANqOGdqpmNnMj+e3xA9YHraUWq3xo9cwe5vD9pQ==", "dev": true, + "license": "MIT", "dependencies": { "@octokit/rest": "^17.11.2", "@types/get-port": "^4.2.0", diff --git a/package.json b/package.json index db76807cc..87c1ad065 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ }, "devDependencies": { "@cypress/react18": "^2.0.1", - "@mate-academy/scripts": "^1.8.5", + "@mate-academy/scripts": "^2.1.2", "@mate-academy/students-ts-config": "*", "@mate-academy/stylelint-config": "*", "@types/node": "^20.14.10", diff --git a/src/App.tsx b/src/App.tsx index 168716b91..76be10a82 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -15,58 +15,97 @@ export const goods = [ 'Garlic', ]; -export const App: React.FC = () => ( -
-

No goods selected

+type State = { + selectedGood: string; +}; -

- Jam is selected - {/* eslint-disable-next-line jsx-a11y/control-has-associated-label */} -

+export class App extends React.Component<{}, State> { + state = { + selectedGood: 'Jam', + }; - - - - + selectGood = (goodName: string) => { + this.setState({ selectedGood: goodName }); + }; - - + clearSelection = () => { + this.setState({ selectedGood: '' }); + }; - - + className="delete ml-3" + onClick={this.clearSelection} + /> + + )} + +
- - - Dumplings -
+ handleClick = (event: React.MouseEvent) => { + const button = event.currentTarget; + const goodName = button.dataset.goodName; + + if (goodName) { + this.selectGood(goodName); + } + }; + + render() { + const isSelected = this.state.selectedGood !== ''; + + return ( +
+ {!isSelected ? ( +

No goods selected

+ ) : ( +

+ {this.state.selectedGood} is selected + {/* eslint-disable-next-line jsx-a11y/control-has-associated-label */} -

+ + {goods.map(good => { + const rowClass = + good === this.state.selectedGood + ? 'has-background-success-light' + : ''; - - + const isCurrentGoodSelected = good === this.state.selectedGood; + // const isAnyGoodSelected = isSelected; - - + return ( + + - - - -
- Jam -
- -
+ {isCurrentGoodSelected ? ( + + ) : ( + + )} + - Garlic -
-
-); + + {good} + + + ); + })} + + + + ); + } +}