generated from agiledev-students-fall2023/generic-project-repository
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #123 from agiledev-students-fall2023/Jaden's-Branch
Walking-route display, UI overhaul
- Loading branch information
Showing
12 changed files
with
507 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useState, useEffect } from 'react'; | ||
function RouteButton({ route }) { | ||
const [color, setColor] = useState('rgba(0, 0, 0, 0)'); | ||
function hexToRGBA(hex, alpha) { | ||
if (hex === undefined) { | ||
return 'rgba(0, 0, 0, 0)'; // return transparent color if hex is undefined | ||
} | ||
let r = parseInt(hex.slice(1, 3), 16), | ||
g = parseInt(hex.slice(3, 5), 16), | ||
b = parseInt(hex.slice(5, 7), 16); | ||
|
||
if (alpha) { | ||
return `rgba(${r}, ${g}, ${b}, ${alpha})`; | ||
} else { | ||
return `rgb(${r}, ${g}, ${b})`; | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
setColor(hexToRGBA(route.color, 0.5)); | ||
}, [route.color]); | ||
|
||
return ( | ||
<button className="w-20 h-20" style={{ backgroundColor: color }}> | ||
{route.name} | ||
</button> | ||
); | ||
} | ||
|
||
export default RouteButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.