From 659b6f911277b5665aa96d71073282cd8df678a7 Mon Sep 17 00:00:00 2001 From: brausjonas Date: Thu, 27 Apr 2023 21:59:12 +0200 Subject: [PATCH] Button with onhover and function paramter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Man kann eine Funktion als Parameter dem button übergeben, sodass er diese ausführt, sobald auf ihn geklickt wird --- projekt/package.json | 83 ++++++++++++++++--------------- projekt/src/App.css | 18 ++++--- projekt/src/App.js | 6 ++- projekt/src/Icons.js | 7 +++ projekt/src/components/Button.jsx | 41 +++++++++------ 5 files changed, 91 insertions(+), 64 deletions(-) create mode 100644 projekt/src/Icons.js diff --git a/projekt/package.json b/projekt/package.json index 31dc3cb..baec147 100644 --- a/projekt/package.json +++ b/projekt/package.json @@ -1,41 +1,42 @@ -{ - "name": "projekt", - "version": "0.1.0", - "private": true, - "dependencies": { - "@testing-library/jest-dom": "^5.16.5", - "@testing-library/react": "^13.4.0", - "@testing-library/user-event": "^13.5.0", - "react": "^18.2.0", - "react-dom": "^18.2.0", - "react-scripts": "5.0.1", - "web-vitals": "^2.1.4" - }, - "scripts": { - "start": "react-scripts start", - "build": "react-scripts build", - "test": "react-scripts test", - "eject": "react-scripts eject" - }, - "eslintConfig": { - "extends": [ - "react-app", - "react-app/jest" - ] - }, - "browserslist": { - "production": [ - ">0.2%", - "not dead", - "not op_mini all" - ], - "development": [ - "last 1 chrome version", - "last 1 firefox version", - "last 1 safari version" - ] - }, - "devDependencies": { - "tailwindcss": "^3.3.2" - } -} +{ + "name": "projekt", + "version": "0.1.0", + "private": true, + "dependencies": { + "@testing-library/jest-dom": "^5.16.5", + "@testing-library/react": "^13.4.0", + "@testing-library/user-event": "^13.5.0", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "react-scripts": "5.0.1", + "web-vitals": "^2.1.4" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": [ + "react-app", + "react-app/jest" + ] + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + }, + "devDependencies": { + "tailwindcss": "^3.3.2" + } + +} diff --git a/projekt/src/App.css b/projekt/src/App.css index 1e7f6b5..8a39ae1 100644 --- a/projekt/src/App.css +++ b/projekt/src/App.css @@ -4,12 +4,6 @@ border-width: 0; } -.default-button -{ - background-color: #0d52ce; - color: #ffffff; -} - .font-small { font-size: 15px; @@ -23,4 +17,14 @@ .font-big { font-size: 30px; -} \ No newline at end of file +} + +.button +{ + background-color: #0d52ce; +} + +.button:hover +{ + background-color: #585858; +} diff --git a/projekt/src/App.js b/projekt/src/App.js index bcca251..05f958a 100644 --- a/projekt/src/App.js +++ b/projekt/src/App.js @@ -1,10 +1,14 @@ import './App.css'; import Button from "./components/Button"; +import {arrowLeft} from "./Icons"; +import {arrowRight} from "./Icons"; function App() { + return (
-
); } diff --git a/projekt/src/Icons.js b/projekt/src/Icons.js new file mode 100644 index 0000000..f14b84e --- /dev/null +++ b/projekt/src/Icons.js @@ -0,0 +1,7 @@ +export const arrowLeft = ` + +` + +export const arrowRight = ` + +` \ No newline at end of file diff --git a/projekt/src/components/Button.jsx b/projekt/src/components/Button.jsx index d74ec90..56a6a89 100644 --- a/projekt/src/components/Button.jsx +++ b/projekt/src/components/Button.jsx @@ -3,26 +3,37 @@ import "../App.css" export default function Button(p) { let text = p.text; - let paddingY = p.paddingY, paddingX = p.paddingX; let width = p.width, height = p.height; - let color = p.color; + let iconHTML = p.icon; + let iconWidth = p.iconWidth, iconHeight = p.iconHeight; + let onClick = p.onClick; - if (paddingY == null) paddingY = 10; - if (paddingX == null) paddingX = 20; if (height == null) height = 50; if (width == null) width = 100; + if (iconWidth == null) iconWidth = 50; + if (iconHeight == null) iconHeight = 50; + if (onClick == null) onClick = () => {}; + if (iconHTML != null) { + let split = iconHTML.split("fill="); + split[1] = "fill=" + split[1]; + split[0] += " width=" + iconWidth + " height=" + iconHeight + " "; + iconHTML = split[0] + split[1] + } else { + iconHTML = ""; + } return ( - + <> + + ); -} \ No newline at end of file +}