44 HoverCardPortal ,
55 HoverCardTrigger ,
66} from '@radix-ui/react-hover-card' ;
7+ import { cva } from 'class-variance-authority' ;
78import { type FeatureAccessLevelDto } from 'marble-api/generated/feature-access-api' ;
89import { useTranslation } from 'react-i18next' ;
910import { match } from 'ts-pattern' ;
@@ -19,6 +20,35 @@ type NudgeProps = {
1920 collapsed ?: boolean ;
2021} ;
2122
23+ const triggerClassName = cva ( 'flex items-center justify-center text-white ' , {
24+ variants : {
25+ kind : {
26+ test : 'bg-purple-65' ,
27+ restricted : 'bg-purple-82' ,
28+ missing_configuration : 'bg-yellow-50' ,
29+ } ,
30+ collapsed : {
31+ true : 'absolute top-v2-sm right-v2-sm translate-x-[50%] -translate-y-[50%] rounded-full' ,
32+ false : 'rounded-sm' ,
33+ } ,
34+ } ,
35+ defaultVariants : {
36+ collapsed : false ,
37+ } ,
38+ } ) ;
39+
40+ const iconClassName = cva ( '' , {
41+ variants : {
42+ collapsed : {
43+ true : 'size-2.5' ,
44+ false : 'size-3' ,
45+ } ,
46+ } ,
47+ defaultVariants : {
48+ collapsed : false ,
49+ } ,
50+ } ) ;
51+
2252export const Nudge = ( {
2353 content,
2454 link,
@@ -28,109 +58,16 @@ export const Nudge = ({
2858 collapsed = false ,
2959} : NudgeProps ) => {
3060 const { t } = useTranslation ( [ 'common' ] ) ;
31-
32- // When collapsed, render a small circular indicator
33- if ( collapsed ) {
34- return (
35- < HoverCard >
36- < HoverCardTrigger
37- tabIndex = { - 1 }
38- className = { cn (
39- 'absolute -top-0.5 -right-0.5 flex h-1 w-1 items-center justify-center rounded-full' ,
40- { 'bg-purple-65' : kind === 'test' } ,
41- { 'bg-purple-82' : kind === 'restricted' } ,
42- { 'bg-yellow-50' : kind === 'missing_configuration' } ,
43- className ,
44- ) }
45- >
46- < Icon
47- icon = { match < typeof kind , IconName > ( kind )
48- . with ( 'restricted' , ( ) => 'lock' )
49- . with ( 'test' , ( ) => 'unlock-right' )
50- . with ( 'missing_configuration' , ( ) => 'warning' )
51- . exhaustive ( ) }
52- className = "size-2 text-white"
53- aria-hidden
54- />
55- </ HoverCardTrigger >
56- < HoverCardPortal >
57- < HoverCardContent
58- side = "right"
59- align = "start"
60- sideOffset = { 8 }
61- alignOffset = { - 8 }
62- className = { cn (
63- 'bg-grey-100 z-50 flex w-60 flex-col items-center gap-6 rounded-sm border p-4 pointer-events-auto shadow-lg' ,
64- {
65- 'border-purple-82' : kind !== 'missing_configuration' ,
66- 'border-yellow-50' : kind === 'missing_configuration' ,
67- } ,
68- ) }
69- >
70- < span className = "text-m font-bold" >
71- { match < typeof kind , string > ( kind )
72- . with ( 'missing_configuration' , ( ) => t ( 'common:missing_configuration_title' ) )
73- . otherwise ( ( ) => t ( 'common:premium' ) ) }
74- </ span >
75- < div className = "flex w-full flex-col items-center gap-2" >
76- < p className = "text-s w-full text-center font-medium" >
77- { match < typeof kind , string > ( kind )
78- . with ( 'missing_configuration' , ( ) => t ( 'common:missing_configuration' ) )
79- . otherwise ( ( ) => content ) }
80- </ p >
81- { link ? (
82- < a
83- className = "text-s text-purple-65 inline-block w-full text-center hover:underline"
84- target = "_blank"
85- rel = "noreferrer"
86- href = { link }
87- onClick = { ( e ) => e . stopPropagation ( ) }
88- >
89- { t ( 'common:check_on_docs' ) }
90- </ a >
91- ) : null }
92- </ div >
93- { kind !== 'missing_configuration' ? (
94- < a
95- className = { CtaClassName ( {
96- variant : 'primary' ,
97- color : 'purple' ,
98- className : 'mt-4 text-center' ,
99- } ) }
100- href = "https://checkmarble.com/upgrade"
101- target = "_blank"
102- rel = "noreferrer"
103- onClick = { ( e ) => e . stopPropagation ( ) }
104- >
105- { t ( 'common:upgrade' ) }
106- </ a >
107- ) : null }
108- </ HoverCardContent >
109- </ HoverCardPortal >
110- </ HoverCard >
111- ) ;
112- }
113-
114- // Default expanded state
11561 return (
11662 < HoverCard >
117- < HoverCardTrigger
118- tabIndex = { - 1 }
119- className = { cn (
120- 'text-grey-100 flex flex-row items-center justify-center rounded-sm' ,
121- { 'bg-purple-65' : kind === 'test' } ,
122- { 'bg-purple-82' : kind === 'restricted' } ,
123- { 'bg-yellow-50' : kind === 'missing_configuration' } ,
124- className ,
125- ) }
126- >
63+ < HoverCardTrigger tabIndex = { - 1 } className = { triggerClassName ( { kind, collapsed, className } ) } >
12764 < Icon
12865 icon = { match < typeof kind , IconName > ( kind )
12966 . with ( 'restricted' , ( ) => 'lock' )
13067 . with ( 'test' , ( ) => 'unlock-right' )
13168 . with ( 'missing_configuration' , ( ) => 'warning' )
13269 . exhaustive ( ) }
133- className = { cn ( 'size-3.5' , iconClass ) }
70+ className = { iconClassName ( { collapsed , className : iconClass } ) }
13471 aria-hidden
13572 />
13673 </ HoverCardTrigger >
0 commit comments