feat: add level selection logic
This commit is contained in:
@@ -9,13 +9,33 @@ import ChevronDown from "@/components/Icons/ChevronDown"
|
|||||||
import Image from "@/components/Image"
|
import Image from "@/components/Image"
|
||||||
import Title from "@/components/Title"
|
import Title from "@/components/Title"
|
||||||
|
|
||||||
|
import levelsData from "./data/EN.json"
|
||||||
|
|
||||||
import styles from "./overviewTable.module.css"
|
import styles from "./overviewTable.module.css"
|
||||||
|
|
||||||
|
const defaultCardProps = {
|
||||||
|
title: "title",
|
||||||
|
description: `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
|
||||||
|
eiusmod tempor incididunt ut labore et dolore magna aliqua.`,
|
||||||
|
comparedValues: { a: false, b: true },
|
||||||
|
}
|
||||||
|
|
||||||
export default function OverviewTable() {
|
export default function OverviewTable() {
|
||||||
const options = [
|
const [selectedLevelA, setSelectedLevelA] = useState("1")
|
||||||
{ value: "a", label: "a" },
|
const [selectedLevelB, setSelectedLevelB] = useState("2")
|
||||||
{ value: "b", label: "b" },
|
|
||||||
]
|
function handleSelectChangeA(event: React.ChangeEvent<HTMLSelectElement>) {
|
||||||
|
setSelectedLevelA(event.target.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleSelectChangeB(event: React.ChangeEvent<HTMLSelectElement>) {
|
||||||
|
setSelectedLevelB(event.target.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
const levelOptions = levelsData.levels.map((level) => ({
|
||||||
|
label: level.name,
|
||||||
|
value: `${level.tier}`,
|
||||||
|
}))
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
<Title
|
<Title
|
||||||
@@ -41,18 +61,37 @@ export default function OverviewTable() {
|
|||||||
<div className={styles.rightColumn} />
|
<div className={styles.rightColumn} />
|
||||||
<div className={styles.columnHeaderContainer}>
|
<div className={styles.columnHeaderContainer}>
|
||||||
<div className={styles.columnHeader}>
|
<div className={styles.columnHeader}>
|
||||||
<Select options={options} />
|
<Select
|
||||||
<LevelSummary level={"1"} />
|
options={levelOptions}
|
||||||
|
defaultOption={selectedLevelA}
|
||||||
|
onChange={handleSelectChangeA}
|
||||||
|
/>
|
||||||
|
<LevelSummary
|
||||||
|
level={
|
||||||
|
levelsData.levels.find(
|
||||||
|
(level) => `${level.tier}` === selectedLevelA
|
||||||
|
) as Level
|
||||||
|
}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.columnHeader}>
|
<div className={styles.columnHeader}>
|
||||||
<Select options={options} />
|
<Select
|
||||||
<LevelSummary level={"2"} />
|
options={levelOptions}
|
||||||
|
defaultOption={selectedLevelB}
|
||||||
|
onChange={handleSelectChangeB}
|
||||||
|
/>
|
||||||
|
<LevelSummary
|
||||||
|
level={
|
||||||
|
levelsData.levels.find(
|
||||||
|
(level) => `${level.tier}` === selectedLevelB
|
||||||
|
) as Level
|
||||||
|
}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<PerkCard />
|
<PerkCard {...defaultCardProps} />
|
||||||
<PerkCard />
|
<PerkCard {...defaultCardProps} />
|
||||||
<PerkCard />
|
<PerkCard {...defaultCardProps} />
|
||||||
<PerkCard />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@@ -63,22 +102,25 @@ type SelectProps = {
|
|||||||
label: string
|
label: string
|
||||||
value: string
|
value: string
|
||||||
}[]
|
}[]
|
||||||
|
defaultOption: string
|
||||||
|
onChange: (event: React.ChangeEvent<HTMLSelectElement>) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
function Select({ options }: SelectProps) {
|
function Select({ options, defaultOption, onChange }: SelectProps) {
|
||||||
console.log({ options })
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.selectContainer}>
|
<div className={styles.selectContainer}>
|
||||||
<select className={styles.select}>
|
<select className={styles.select} onChange={onChange}>
|
||||||
{options.map((option) => (
|
{options.map((option) => (
|
||||||
<option key={option.label} value={option.value}>
|
<option
|
||||||
|
key={option.label}
|
||||||
|
value={option.value}
|
||||||
|
selected={option.value === defaultOption}
|
||||||
|
>
|
||||||
{option.label}
|
{option.label}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
<label className={styles.selectLabel} htmlFor="">
|
<label className={styles.selectLabel}>{_("Level")}</label>
|
||||||
{_("Level")}
|
|
||||||
</label>
|
|
||||||
<span className={styles.selectChevron}>
|
<span className={styles.selectChevron}>
|
||||||
<ChevronDown />
|
<ChevronDown />
|
||||||
</span>
|
</span>
|
||||||
@@ -86,28 +128,37 @@ function Select({ options }: SelectProps) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function LevelSummary({ level }: { level: string }) {
|
type Level = {
|
||||||
|
tier: number
|
||||||
|
name: string
|
||||||
|
description: string
|
||||||
|
requirement: string
|
||||||
|
icon: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type LevelSummaryProps = {
|
||||||
|
level: Level
|
||||||
|
}
|
||||||
|
|
||||||
|
function LevelSummary({ level }: LevelSummaryProps) {
|
||||||
return (
|
return (
|
||||||
<div className={styles.levelSummary}>
|
<div className={styles.levelSummary}>
|
||||||
<Image
|
<Image src={level.icon} alt={level.name} height={50} width={100} />
|
||||||
src="/_static/icons/loyaltylevels/new-friend.svg"
|
<span className={styles.levelRequirements}>{level.requirement}</span>
|
||||||
alt="level"
|
<p className={styles.levelSummaryText}>{level.description}</p>
|
||||||
height={50}
|
|
||||||
width={100}
|
|
||||||
/>
|
|
||||||
<span className={styles.levelRequirements}>10 000p or X nights</span>
|
|
||||||
<p className={styles.levelSummaryText}>
|
|
||||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
|
|
||||||
tempor incididunt ut labore et dolore magna aliqua. Arcu risus quis
|
|
||||||
varius quam quisque id diam vel. Rhoncus urna neque viverra justo.
|
|
||||||
Mattis aliquam faucibus purus in massa. Id cursus metus aliquam eleifend
|
|
||||||
mi in nulla posuere.
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function PerkCard() {
|
type PerkCardProps = {
|
||||||
|
comparedValues: {
|
||||||
|
a: boolean | string
|
||||||
|
b: boolean | string
|
||||||
|
}
|
||||||
|
title: string
|
||||||
|
description: string
|
||||||
|
}
|
||||||
|
function PerkCard({ comparedValues, title, description }: PerkCardProps) {
|
||||||
const [isExpanded, setIsExpanded] = useState(false)
|
const [isExpanded, setIsExpanded] = useState(false)
|
||||||
return (
|
return (
|
||||||
<div className={styles.perkCard}>
|
<div className={styles.perkCard}>
|
||||||
@@ -116,26 +167,22 @@ function PerkCard() {
|
|||||||
<summary className={styles.summary}>
|
<summary className={styles.summary}>
|
||||||
<hgroup className={styles.perkCardHeader}>
|
<hgroup className={styles.perkCardHeader}>
|
||||||
<Title as="h5" level="h2" className={styles.perkCardTitle}>
|
<Title as="h5" level="h2" className={styles.perkCardTitle}>
|
||||||
title
|
{title}
|
||||||
</Title>
|
</Title>
|
||||||
<span className={styles.chevron}>
|
<span className={styles.chevron}>
|
||||||
<ChevronDown />
|
<ChevronDown />
|
||||||
</span>
|
</span>
|
||||||
</hgroup>
|
</hgroup>
|
||||||
</summary>
|
</summary>
|
||||||
<p className={styles.perkCardDescription}>
|
<p className={styles.perkCardDescription}>{description}</p>
|
||||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
|
|
||||||
eiusmod tempor incididunt ut labore et dolore magna aliqua. Sed
|
|
||||||
adipiscing diam donec adipiscing tristique risus nec feugiat.
|
|
||||||
</p>
|
|
||||||
</details>
|
</details>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.perkComparison}>
|
<div className={styles.perkComparison}>
|
||||||
<div className={styles.comparisonItem}>
|
<div className={styles.comparisonItem}>
|
||||||
<CheckCircle />
|
{comparedValues.a ? <CheckCircle /> : "-"}
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.comparisonItem}>
|
<div className={styles.comparisonItem}>
|
||||||
<CheckCircle />
|
{comparedValues.b ? <CheckCircle /> : "-"}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user