-
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.
+ Add tooltip logic directly to component + Apply tooltip on locations using score circle
- Loading branch information
1 parent
fa8b1e4
commit e6fb2b2
Showing
3 changed files
with
81 additions
and
38 deletions.
There are no files selected for viewing
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
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
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,26 +1,60 @@ | ||
import { Tooltip } from '@bigcommerce/big-design'; | ||
import clsx from 'clsx'; | ||
import { forwardRef, type ComponentProps } from 'react'; | ||
import { parseScore } from '~/utils/utils'; | ||
|
||
interface ScoreCircleProps { | ||
interface ScoreCircleBaseProps { | ||
className?: string; | ||
score?: number; | ||
} | ||
|
||
export const ScoreCircle = ({ score: scoreProp }: ScoreCircleProps) => { | ||
const score = parseScore(scoreProp); | ||
const ScoreCircleBase = forwardRef<HTMLDivElement, ScoreCircleBaseProps>( | ||
({ className, score: scoreProp, ...props }, ref) => { | ||
const score = parseScore(scoreProp); | ||
|
||
return ( | ||
<div | ||
className={clsx( | ||
'flex aspect-square w-9 items-center justify-center rounded-full font-semibold', | ||
{ | ||
'bg-green-200/80 text-green-800': score.isPositive, | ||
'bg-yellow-200/80 text-yellow-800': score.isNeutral, | ||
'bg-red-200/80 text-red-800': score.isNegative, | ||
'bg-gray-200/80 text-gray-500': score.isNull, | ||
} | ||
)} | ||
> | ||
{score.isNull ? '?' : scoreProp} | ||
</div> | ||
); | ||
return ( | ||
<div | ||
{...props} | ||
className={clsx( | ||
'flex aspect-square w-9 items-center justify-center rounded-full font-semibold', | ||
{ | ||
'bg-green-200/80 text-green-800': score.isPositive, | ||
'bg-yellow-200/80 text-yellow-800': score.isNeutral, | ||
'bg-red-200/80 text-red-800': score.isNegative, | ||
'bg-gray-200/80 text-gray-500': score.isNull, | ||
}, | ||
className | ||
)} | ||
ref={ref} | ||
> | ||
{score.isNull ? '?' : scoreProp} | ||
</div> | ||
); | ||
} | ||
); | ||
|
||
ScoreCircleBase.displayName = 'ScoreCircleBase'; | ||
|
||
interface ScoreCircleProps extends Omit<ScoreCircleBaseProps, 'className'> { | ||
tooltip?: React.ReactNode; | ||
tooltipPlacement?: ComponentProps<typeof Tooltip>['placement']; | ||
} | ||
|
||
export const ScoreCircle = ({ | ||
score, | ||
tooltip, | ||
tooltipPlacement = 'bottom', | ||
}: ScoreCircleProps) => { | ||
if (tooltip) { | ||
return ( | ||
<Tooltip | ||
placement={tooltipPlacement} | ||
trigger={<ScoreCircleBase className="cursor-help" score={score} />} | ||
> | ||
{tooltip} | ||
</Tooltip> | ||
); | ||
} | ||
|
||
return <ScoreCircleBase score={score} />; | ||
}; |