-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
53 additions
and
42 deletions.
There are no files selected for viewing
Empty file.
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 |
---|---|---|
@@ -1,49 +1,59 @@ | ||
import { useState } from "react"; | ||
import { Button, ButtonGroup } from "@nextui-org/react"; | ||
import { useState } from 'react'; | ||
import { Button, ButtonGroup } from '@nextui-org/react'; | ||
|
||
interface Props { | ||
name: string; | ||
levels: string[]; | ||
defaultPrice: number; | ||
prices: number[]; | ||
setPrice: (newPrice: number) => void; | ||
name: string; | ||
levels: string[]; | ||
defaultPrice: number; | ||
prices: number[]; | ||
setPrice: (newPrice: number) => void; | ||
} | ||
|
||
export default function TextButtonGroup({ name, levels, defaultPrice, prices, setPrice }: Props) { | ||
const [selectedIndex, setSelectedIndex] = useState<number | null>(null); | ||
export default function TextButtonGroup({ | ||
name, | ||
levels, | ||
defaultPrice, | ||
prices, | ||
setPrice, | ||
}: Props) { | ||
const [selectedIndex, setSelectedIndex] = useState<number | null>(null); | ||
|
||
const handleIncrement = (index: number) => { | ||
setPrice(defaultPrice + prices[index]); | ||
setSelectedIndex(index); | ||
console.log(defaultPrice); | ||
}; | ||
const handleIncrement = (index: number) => { | ||
setPrice(defaultPrice + prices[index]); | ||
setSelectedIndex(index); | ||
console.log(defaultPrice); | ||
}; | ||
|
||
return ( | ||
<div className='flex mt-8'> | ||
<div className='text-white mt-2'> | ||
<b>{name}:</b> | ||
</div> | ||
<ButtonGroup className='ml-5'> | ||
{levels.map((level, index) => { | ||
let buttonClass = 'border duration-300 hover:bg-foodbg'; | ||
return ( | ||
<div className="flex mt-8"> | ||
<div className="text-white mt-2"> | ||
<b>{name}:</b> | ||
</div> | ||
<ButtonGroup className="ml-5"> | ||
{levels.map((level, index) => { | ||
let buttonClass = 'border duration-300 hover:bg-foodbg'; | ||
|
||
if (index === 0) { | ||
buttonClass += ' rounded-l-lg'; | ||
} else if (index === levels.length - 1) { | ||
buttonClass += ' rounded-r-lg'; | ||
} | ||
if (index === 0) { | ||
buttonClass += ' rounded-l-lg'; | ||
} else if (index === levels.length - 1) { | ||
buttonClass += ' rounded-r-lg'; | ||
} | ||
|
||
if (selectedIndex === index) { | ||
buttonClass += ' bg-foodbg text-white'; | ||
} | ||
if (selectedIndex === index) { | ||
buttonClass += ' bg-foodbg text-white'; | ||
} | ||
|
||
return ( | ||
<Button key={index} className={buttonClass} onClick={() => handleIncrement(index)}> | ||
{level} | ||
</Button> | ||
); | ||
})} | ||
</ButtonGroup> | ||
</div> | ||
); | ||
return ( | ||
<Button | ||
key={index} | ||
className={buttonClass} | ||
onClick={() => handleIncrement(index)} | ||
> | ||
{level}({prices[index]}) | ||
</Button> | ||
); | ||
})} | ||
</ButtonGroup> | ||
</div> | ||
); | ||
} |
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