Skip to content

Commit

Permalink
added toast colors and util file
Browse files Browse the repository at this point in the history
  • Loading branch information
PepperLola committed Aug 22, 2023
1 parent a65278e commit f30bec6
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 47 deletions.
1 change: 1 addition & 0 deletions react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import ScoringZonesPanel from "./panels/configuring/scoring/ScoringZonesPanel"
import ZoneConfigPanel from "./panels/configuring/scoring/ZoneConfigPanel"
import ScoreboardPanel from "./panels/information/ScoreboardPanel"
import DriverStationPanel from "./panels/simulation/DriverStationPanel"
import Toast from "./components/Toast"

Check failure on line 49 in react/src/App.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint Format Validation

'Toast' is defined but never used

const initialModals = [
<SettingsModal modalId="settings" />,
Expand Down
16 changes: 13 additions & 3 deletions react/src/ThemeContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,23 @@ export type ColorName =
| "AcceptCancelButtonText"
| "MatchRedAlliance"
| "MatchBlueAlliance"
| "ToastInfo"
| "ToastWarning"
| "ToastError"

const colorNameToProp = (colorName: ColorName) => {
export const colorNameToTailwind = (colorName: ColorName) => {
return "bg" +
colorName
.replace(/([A-Z]+)/g, "-$1")
.replace(/(?<=[A-Z])([A-Z])(?![A-Z]|$)/g, "-$1")
.toLowerCase()
}
export const colorNameToProp = (colorName: ColorName) => {
return (
"-" +
colorName
.replace(/([A-Z]+)/g, "-$1")
.replace(/(?<=[A-Z])([A-Z])(?![A-Z])/g, "-$1")
.replace(/(?<=[A-Z])([A-Z])(?![A-Z]|$)/g, "-$1")
.toLowerCase()
)
}
Expand Down Expand Up @@ -113,7 +123,7 @@ export const ThemeProvider: React.FC<ThemeProviderProps> = ({
const propName = colorNameToProp(n as ColorName)
root.style.setProperty(
propName,
`rgba(${c.r}, ${c.g}, ${c.b}, ${c.a}`
`rgba(${c.r}, ${c.g}, ${c.b}, ${c.a})`
)
})
}
Expand Down
3 changes: 3 additions & 0 deletions react/src/ToastContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ export const ToastContainer: React.FC = () => {

return (
<div className="absolute right-0 bottom-0 pl-8 pb-8 w-min h-fit overflow-hidden flex flex-col gap-2">
<Toast id="id-info" title="Title" type="info" description="Test toast" />
<Toast id="id-warning" title="Title" type="warning" description="Test toast" />
<Toast id="id-error" title="Title" type="error" description="Test toast" />
<AnimatePresence>
{toasts.length > 0 &&
toasts.map(t => (
Expand Down
2 changes: 1 addition & 1 deletion react/src/components/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const Slider: React.FC<SliderProps> = ({
else percent += step - diff
}
const v = percent * (max - min) + min
onChange(v)
if (onChange) onChange(v)
setValue(v)
}
}
Expand Down
7 changes: 4 additions & 3 deletions react/src/components/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const TOAST_TIMEOUT: number = 5_000

const Toast: React.FC<ToastData> = ({ id, type, title, description }) => {
const { removeToast } = useToastContext()

useEffect(() => {
const timer = setTimeout(() => {
removeToast(id)
Expand All @@ -30,7 +31,7 @@ const Toast: React.FC<ToastData> = ({ id, type, title, description }) => {
className="h-full w-full text-main-text"
/>
)
className = "bg-purple-700"
className = "bg-toast-info"
break
case "warning":
icon = (
Expand All @@ -39,7 +40,7 @@ const Toast: React.FC<ToastData> = ({ id, type, title, description }) => {
className="h-full w-full text-main-text"
/>
)
className = "bg-yellow-500"
className = "bg-toast-warning"
break
case "error":
icon = (
Expand All @@ -48,7 +49,7 @@ const Toast: React.FC<ToastData> = ({ id, type, title, description }) => {
className="h-full w-full text-main-text"
/>
)
className = "bg-red-500"
className = "bg-toast-error"
break
}

Expand Down
3 changes: 3 additions & 0 deletions react/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const defaultColors: Theme = {
FloorGrid: { r: 93, g: 93, b: 93, a: 255 },
MatchRedAlliance: { r: 255, g: 0, b: 0, a: 255 },
MatchBlueAlliance: { r: 0, g: 0, b: 255, a: 255 },
ToastInfo: { r: 126, g: 34, b: 206, a: 255 },
ToastWarning: { r: 234, g: 179, b: 8, a: 255 },
ToastError: { r: 239, g: 68, b: 68, a: 255 },
}
const themes = {
Default: defaultColors,
Expand Down
24 changes: 11 additions & 13 deletions react/src/modals/configuring/theme-editor/ThemeEditorModal.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import React, { useState } from "react"
import { FaChessBoard } from "react-icons/fa6"
import Modal, { ModalPropsImpl } from "../../../components/Modal"
import Modal, { ModalPropsImpl } from "@/components/Modal"
import { RgbaColor, RgbaColorPicker } from "react-colorful"
import Stack, { StackDirection } from "../../../components/Stack"
import Dropdown from "../../../components/Dropdown"
import Button from "../../../components/Button"
import Stack, { StackDirection } from "@/components/Stack"
import Dropdown from "@/components/Dropdown"
import Button from "@/components/Button"
import {
ColorName,
Theme,
colorNameToProp,

Check failure on line 11 in react/src/modals/configuring/theme-editor/ThemeEditorModal.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint Format Validation

'colorNameToProp' is defined but never used
colorNameToTailwind,
defaultThemeName,
useTheme,
} from "../../../ThemeContext"
import { useModalControlContext } from "../../../ModalContext"
} from "@/ThemeContext"
import { useModalControlContext } from "@/ModalContext"

const ThemeEditorModal: React.FC<ModalPropsImpl> = ({ modalId }) => {
const { themes, currentTheme, setTheme, updateColor, applyTheme } =
Expand Down Expand Up @@ -97,18 +99,14 @@ const ThemeEditorModal: React.FC<ModalPropsImpl> = ({ modalId }) => {
{Object.entries(themes[selectedTheme]).map(([n, c]) => (

Check failure on line 99 in react/src/modals/configuring/theme-editor/ThemeEditorModal.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint Format Validation

'c' is defined but never used
<div
key={n}
className={`flex flex-row gap-2 content-middle align-center cursor-pointer rounded-md p-1 ${
n == selectedColor ? "bg-gray-700" : ""
}`}
className={`flex flex-row gap-2 content-middle align-center cursor-pointer rounded-md p-1 ${n == selectedColor ? "bg-background-secondary" : ""
}`}
onClick={() => {
setSelectedColor(n as ColorName)
}}
>
<div
className="w-6 h-6 rounded-md"
style={{
background: `rgba(${c.r}, ${c.g}, ${c.b}, ${c.a})`,
}}
className={`w-6 h-6 rounded-md ${colorNameToTailwind(n as ColorName)}`}
></div>
<div className="h-6 text-main-text">{n}</div>
</div>
Expand Down
11 changes: 11 additions & 0 deletions react/src/util/CEFAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const click = (btn: number, x: number, y: number) => {
const el = document.elementFromPoint(x, y);

const event = new MouseEvent("click", {
clientX: x,
clientY: y,
bubbles: true,
button: btn
})
el?.dispatchEvent(event)
}
63 changes: 36 additions & 27 deletions react/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,49 @@
/** @type {import('tailwindcss').Config} */

let colors = {
'interactive-element-solid': 'var(--interactive-element-solid)',
'interactive-element-left': 'var(--interactive-element-left)',
'interactive-element-right': 'var(--interactive-element-right)',
'background': 'var(--background)',
'background-secondary': 'var(--background-secondary)',
'interactive-background': 'var(--interactive-background)',
'background-hud': 'var(--background-hud)',
'interactive-hover': 'var(--interactive-hover)',
'interactive-select': 'var(--interactive-select)',
'main-text': 'var(--main-text)',
'scrollbar': 'var(--scrollbar)',
'accept-button': 'var(--accept-button)',
'cancel-button': 'var(--cancel-button)',
'interactive-element-text': 'var(--interactive-element-text)',
'icon': 'var(--icon)',
'main-hud-icon': 'var(--main-hud-icon)',
'main-hud-close-icon': 'var(--main-hud-close-icon)',
'highlight-hover': 'var(--highlight-hover)',
'highlight-select': 'var(--highlight-select)',
'skybox-top': 'var(--skybox-top)',
'skybox-bottom': 'var(--skybox-bottom)',
'floor-grid': 'var(--floor-grid)',
'accept-cancel-button-text': 'var(--accept-cancel-button-text)',
'match-red-alliance': 'var(--match-red-alliance)',
'match-blue-alliance': 'var(--match-blue-alliance)',
'toast-info': 'var(--toast-info)',
'toast-warning': 'var(--toast-warning)',
'toast-error': 'var(--toast-error)',
}

let safelist = Object.keys(colors).map(c => "bg-" + c);

export default {
content: [
"./index.html",
"./src/**/*.{js,jsx,ts,tsx}",
],
theme: {
extend: {
colors: {
'interactive-element-solid': 'var(--interactive-element-solid)',
'interactive-element-left': 'var(--interactive-element-left)',
'interactive-element-right': 'var(--interactive-element-right)',
'background': 'var(--background)',
'background-secondary': 'var(--background-secondary)',
'interactive-background': 'var(--interactive-background)',
'background-hud': 'var(--background-hud)',
'interactive-hover': 'var(--interactive-hover)',
'interactive-select': 'var(--interactive-select)',
'main-text': 'var(--main-text)',
'scrollbar': 'var(--scrollbar)',
'accept-button': 'var(--accept-button)',
'cancel-button': 'var(--cancel-button)',
'interactive-element-text': 'var(--interactive-element-text)',
'icon': 'var(--icon)',
'main-hud-icon': 'var(--main-hud-icon)',
'main-hud-close-icon': 'var(--main-hud-close-icon)',
'highlight-hover': 'var(--highlight-hover)',
'highlight-select': 'var(--highlight-select)',
'skybox-top': 'var(--skybox-top)',
'skybox-bottom': 'var(--skybox-bottom)',
'floor-grid': 'var(--floor-grid)',
'accept-cancel-button-text': 'var(--accept-cancel-button-text)',
'match-red-alliance': 'var(--match-red-alliance)',
'match-blue-alliance': 'var(--match-blue-alliance)',
}
colors: colors,
},
},
safelist: safelist,
plugins: [],
}

0 comments on commit f30bec6

Please sign in to comment.