replace all html buttons with button component

This commit is contained in:
Anika Raemer 2025-09-21 10:45:24 +02:00
parent f1f6f5f438
commit 9cb5b52ac9
7 changed files with 58 additions and 54 deletions

View file

@ -33,16 +33,26 @@
} }
/* buttons */ /* buttons */
.default-button{ .basic-button{
@apply bg-gray-300 px-4 py-2 shadow-md rounded-lg hover:bg-gray-400 whitespace-nowrap text-gray-600 @apply px-4 py-2 shadow-md rounded-lg whitespace-nowrap
}hover:bg-gray-400 }
.default-button-bg {
.primary-button { @apply bg-gray-300 hover:bg-gray-400
}
.default-button-text{
@apply text-gray-600
}
.primary-button-bg {
@apply bg-blue-300 hover:bg-blue-400 text-gray-600 @apply bg-blue-300 hover:bg-blue-400 text-gray-600
} }
.primary-button-text {
.dark-button{ @apply text-gray-600
@apply bg-gray-600 hover:bg-gray-800 text-white shadow-md rounded px-4 py-2 whitespace-nowrap }
.dark-button-bg{
@apply bg-gray-600 hover:bg-gray-800
}
.dark-button-text{
@apply text-white
} }
/* input fields like input and textarea */ /* input fields like input and textarea */

View file

@ -1,35 +1,35 @@
import SvgIcon, { Icon } from "./SvgIcon" import SvgIcon, { Icon } from "./SvgIcon"
type ButtonProps = { type ButtonProps = {
onClicked: () => void, onClick: () => void,
icon?: Icon, icon?: Icon,
text?: string, text?: string,
buttonType : ButtonType buttonType? : ButtonType
} }
export const ButtonType = { export const ButtonType = {
DarkButton: { DarkButton: {
textColor: "text-white", textColor: "dark-button-text",
backgroundColor: "bg-gray-600 hover:bg-gray-800" backgroundColor: "dark-button-bg"
}, },
PrimaryButton: { PrimaryButton: {
textColor: "text-gray-600", textColor: "primary-button-text",
backgroundColor: "bg-blue-300 hover:bg-blue-400" backgroundColor: "primary-button-bg"
}, },
DefaultButton: { DefaultButton: {
textColor: "text-gray-600", textColor: "default-button-text",
backgroundColor: "bg-gray-300 hover:bg-gray-400" backgroundColor: "default-button-bg"
} }
} as const; } as const;
export type ButtonType = typeof ButtonType[keyof typeof ButtonType]; export type ButtonType = typeof ButtonType[keyof typeof ButtonType];
export default function Button ({onClicked, icon, text, buttonType = ButtonType.DefaultButton} : ButtonProps){ export default function Button ({onClick: onClick, icon, text, buttonType = ButtonType.DefaultButton} : ButtonProps){
return( return(
<button <button
type="button" type="button"
className={`px-4 py-2 shadow-md rounded-lg whitespace-nowrap ${buttonType.backgroundColor} ${buttonType.textColor}`} className={`basic-button ${buttonType.backgroundColor} ${buttonType.textColor}`}
onClick={onClicked} onClick={onClick}
> >
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
{/* Render icon only if defined */} {/* Render icon only if defined */}

View file

@ -44,13 +44,11 @@ export function IngredientGroupListEditor({ ingredientGroupList, onChange }: Ing
value = {ingGrp.title} value = {ingGrp.title}
onChange={ e => handleUpdate(index, "title", e.target.value)} onChange={ e => handleUpdate(index, "title", e.target.value)}
/> />
<button <Button
type="button"
className="dark-button"
onClick={() => handleRemove(index)} onClick={() => handleRemove(index)}
> text={"Remove Group"}
Remove Group buttonType={ButtonType.DarkButton}
</button> />
</div> </div>
<IngredientListEditor <IngredientListEditor
ingredients={ingGrp.ingredientList} ingredients={ingGrp.ingredientList}
@ -59,7 +57,7 @@ export function IngredientGroupListEditor({ ingredientGroupList, onChange }: Ing
</div> </div>
))} ))}
<Button <Button
onClicked={handleAdd} onClick={handleAdd}
icon={Icon.Plus} icon={Icon.Plus}
text={"Add Ingredient Group"} text={"Add Ingredient Group"}
buttonType={ButtonType.PrimaryButton} buttonType={ButtonType.PrimaryButton}

View file

@ -51,19 +51,15 @@ export function IngredientListEditor({ ingredients, onChange }: IngredientListEd
value={ing.name} value={ing.name}
onChange={e => handleUpdate(index, "name", e.target.value)} onChange={e => handleUpdate(index, "name", e.target.value)}
/> />
<button <Button
type="button"
className="dark-button"
onClick={() => handleRemove(index)} onClick={() => handleRemove(index)}
> icon={Icon.X}
<SvgIcon buttonType={ButtonType.DarkButton}
icon = {Icon.X} />
/>
</button>
</div> </div>
))} ))}
<Button <Button
onClicked={handleAdd} onClick={handleAdd}
icon={Icon.Plus} icon={Icon.Plus}
text={"Add Ingredient"} text={"Add Ingredient"}
buttonType={ButtonType.PrimaryButton} buttonType={ButtonType.PrimaryButton}

View file

@ -125,13 +125,13 @@ export default function RecipeDetailPage() {
<div className="button-group"> <div className="button-group">
<Link <Link
to={ getRecipeEditUrl(recipe.id) } to={ getRecipeEditUrl(recipe.id) }
className="primary-button" className="basic-button primary-button-bg primary-button-text"
> >
Bearbeiten Bearbeiten
</Link> </Link>
<Link <Link
to={getRecipeListUrl()} to={getRecipeListUrl()}
className="default-button" className="basic-button default-button-bg default-button-text"
> >
Zurueck Zurueck
</Link> </Link>

View file

@ -2,6 +2,7 @@ import { useState } from "react"
import type { Recipe } from "../../types/recipe" import type { Recipe } from "../../types/recipe"
import type { IngredientGroup } from "../../types/ingredientGroup" import type { IngredientGroup } from "../../types/ingredientGroup"
import { IngredientGroupListEditor } from "./IngredientGroupListEditor" import { IngredientGroupListEditor } from "./IngredientGroupListEditor"
import Button, { ButtonType } from "../basics/Button"
type RecipeEditorProps = { type RecipeEditorProps = {
recipe: Recipe recipe: Recipe
@ -129,18 +130,15 @@ export default function RecipeEditor({ recipe, onSave, onCancel }: RecipeEditorP
<div className="button-group"> <div className="button-group">
{/* Save Button */} {/* Save Button */}
<button <Button
className="primary-button"
onClick={() => handleSave(draft)} onClick={() => handleSave(draft)}
> text={"Save"}
Save buttonType={ButtonType.PrimaryButton}
</button> />
<button <Button
className="default-button"
onClick={() => onCancel()} onClick={() => onCancel()}
> text={"Cancel"}
Cancel />
</button>
</div> </div>
</div> </div>
) )

View file

@ -1,3 +1,5 @@
import { ButtonType } from "../basics/Button"
import Button from "../basics/Button"
import SearchField from "../basics/SearchField" import SearchField from "../basics/SearchField"
/** /**
@ -22,12 +24,12 @@ export default function RecipeListToolbar({onSearchStringChanged, onAddClicked,
<div className="flex-1 md:flex-none md:max-w-[500px]"> <div className="flex-1 md:flex-none md:max-w-[500px]">
<SearchField onSearchStringChanged={onSearchStringChanged} /> <SearchField onSearchStringChanged={onSearchStringChanged} />
</div> </div>
<button <Button
className="primary-button flex-shrink-0" buttonType = {ButtonType.PrimaryButton}
onClick={onAddClicked} //className="flex-shrink-0"
> onClick={onAddClicked}
Add recipe text = "Add recipe"
</button> />
</div> </div>
</div> </div>
) )