Files
web/apps/scandic-web/components/MyPages/LevelProgressCard/InnerCard/ProgressSection/index.tsx
Chuma Mcphoy (We Ahead) ae3537e008 Merged in fix/LOY-444-points-to-keep-left-text (pull request #3086)
fix(LOY-444): fix markerLabel text when left aligned

* fix(LOY-444): fix markerLabel text when left aligned


Approved-by: Matilda Landström
2025-11-07 11:21:17 +00:00

104 lines
3.0 KiB
TypeScript

"use client"
import { cx } from "class-variance-authority"
import { useIntl } from "react-intl"
import { Progress } from "@scandic-hotels/design-system/Progress"
import { Typography } from "@scandic-hotels/design-system/Typography"
import styles from "./progressSection.module.css"
import type { ProgressCalculation } from "../../types"
interface ProgressSectionProps {
earned: number
progress: ProgressCalculation
toKeepCurrent?: number
}
export default function ProgressSection({
earned,
progress,
toKeepCurrent,
}: ProgressSectionProps) {
const intl = useIntl()
const hasMarkerPosition = progress.markerPosition !== undefined
const shouldWrap =
hasMarkerPosition && toKeepCurrent && (progress.markerPosition ?? 0) < 30
return (
<div
className={cx(styles.progressSection, {
[styles.hasMarker]: hasMarkerPosition,
})}
data-wrap={shouldWrap ? "true" : undefined}
>
<div className={styles.progressContainer}>
<Progress
value={progress.percentage}
aria-label={intl.formatMessage(
{
id: "myPages.levelProgressWithPointsEarned",
defaultMessage:
"Level progress: {earned} of {total} points earned",
},
{
earned: intl.formatNumber(earned),
total: intl.formatNumber(progress.total),
}
)}
/>
{hasMarkerPosition && toKeepCurrent && (
<div
className={styles.levelMarker}
style={{ left: `${progress.markerPosition}%` }}
>
<div className={styles.markerPin} />
<div className={styles.markerLine} />
</div>
)}
</div>
{hasMarkerPosition && toKeepCurrent && (
<div className={styles.markerLabelContainer}>
<span
className={styles.markerLabel}
style={
{
"--marker-pos": `${progress.markerPosition}%`,
} as React.CSSProperties
}
>
{intl.formatMessage(
{
id: "myPages.pointsLeftToKeepLevel",
defaultMessage:
"{pointsAmount} <points>POINTS</points> <support>left to keep level</support>",
},
{
pointsAmount: (
<Typography variant="Title/Overline/sm">
<span>{intl.formatNumber(toKeepCurrent)}</span>
</Typography>
),
points: (str) => (
<Typography variant="Title/Overline/sm">
<span>{str}</span>
</Typography>
),
support: (str) => (
<Typography variant="Body/Supporting text (caption)/smRegular">
<span>{str}</span>
</Typography>
),
}
)}
</span>
</div>
)}
</div>
)
}