1
+ import { ComponentPropsWithoutRef } from "react"
1
2
import { useRouter } from "next/router"
2
3
import { useTranslation } from "next-i18next"
3
4
import { BsCheck } from "react-icons/bs"
4
- import {
5
- Badge ,
6
- Box ,
7
- Flex ,
8
- forwardRef ,
9
- Icon ,
10
- MenuItem as ChakraMenuItem ,
11
- type MenuItemProps as ChakraMenuItemProps ,
12
- Text ,
13
- } from "@chakra-ui/react"
14
5
15
6
import type { LocaleDisplayInfo } from "@/lib/types"
16
7
17
- import { BaseLink } from "@/components/Link"
8
+ import { cn } from "@/lib/utils/cn"
9
+
10
+ import { Badge } from "../ui/badge"
11
+ import { CommandItem } from "../ui/command"
18
12
19
13
import ProgressBar from "./ProgressBar"
20
14
21
- type ItemProps = ChakraMenuItemProps & {
15
+ type ItemProps = ComponentPropsWithoutRef < typeof CommandItem > & {
22
16
displayInfo : LocaleDisplayInfo
23
17
}
24
18
25
- const MenuItem = forwardRef ( ( { displayInfo, ...props } : ItemProps , ref ) => {
19
+ const MenuItem = ( { displayInfo, ...props } : ItemProps ) => {
26
20
const {
27
21
localeOption,
28
22
sourceName,
@@ -32,7 +26,7 @@ const MenuItem = forwardRef(({ displayInfo, ...props }: ItemProps, ref) => {
32
26
isBrowserDefault,
33
27
} = displayInfo
34
28
const { t } = useTranslation ( "common" )
35
- const { asPath , locale } = useRouter ( )
29
+ const { locale } = useRouter ( )
36
30
const isCurrent = localeOption === locale
37
31
38
32
const getProgressInfo = ( approvalProgress : number , wordsApproved : number ) => {
@@ -48,86 +42,49 @@ const MenuItem = forwardRef(({ displayInfo, ...props }: ItemProps, ref) => {
48
42
const { progress, words } = getProgressInfo ( approvalProgress , wordsApproved )
49
43
50
44
return (
51
- < ChakraMenuItem
52
- as = { BaseLink }
53
- ref = { ref }
54
- flexDir = "column"
55
- w = "full"
56
- mb = "1"
57
- display = "block"
58
- pt = "2 !important"
59
- alignItems = "start"
60
- borderRadius = "base"
61
- bg = { isCurrent ? "background.base" : "transparent" }
62
- color = "body.base"
63
- textDecoration = "none"
64
- onFocus = { ( e ) => {
65
- e . target . scrollIntoView ( { block : "nearest" } )
66
- } }
67
- scrollMarginY = "8"
68
- _hover = { {
69
- bg : "primary.lowContrast" ,
70
- textDecoration : "none" ,
71
- "p.language-name" : { color : "primary.base" } ,
72
- } }
73
- _focus = { { bg : "primary.lowContrast" } }
74
- sx = { {
75
- p : {
76
- textDecoration : "none" ,
77
- overflow : "hidden" ,
78
- textOverflow : "ellipsis" ,
79
- whiteSpace : "nowrap" ,
80
- } ,
81
- } }
82
- href = { asPath }
83
- locale = { localeOption }
45
+ < CommandItem
46
+ value = { localeOption }
47
+ className = { cn (
48
+ "group mb-1 flex-col items-start rounded pt-2 text-body hover:bg-primary-low-contrast" ,
49
+ isCurrent
50
+ ? "bg-background hover:bg-primary-low-contrast"
51
+ : "bg-transparent"
52
+ ) }
84
53
{ ...props }
85
54
>
86
- < Flex alignItems = "center" w = "full" >
87
- < Box flex = { 1 } >
88
- < Flex alignItems = "center" gap = { 2 } >
89
- < Text
90
- className = "language-name"
91
- fontSize = "lg"
92
- color = { isCurrent ? "primary.highContrast" : "body.base" }
55
+ < div className = "flex w-full items-center" >
56
+ < div className = "flex-1" >
57
+ < div className = "flex items-center gap-2" >
58
+ < p
59
+ className = { cn (
60
+ "language-name text-lg group-aria-selected:text-primary" ,
61
+ isCurrent ? "text-primary-high-contrast" : "text-body"
62
+ ) }
93
63
>
94
64
{ targetName }
95
- </ Text >
65
+ </ p >
96
66
{ isBrowserDefault && (
97
67
< Badge
98
- border = "1px"
99
- borderColor = "body.medium"
100
- color = "body.medium"
101
- lineHeight = "none"
102
- fontSize = "2xs"
103
- p = "1"
104
- h = "fit-content"
105
- bg = "none"
68
+ className = "h-fit-content rounded border-body-medium p-1 text-2xs font-normal uppercase leading-none text-body-medium"
69
+ variant = "outline"
106
70
>
107
71
{ t ( "page-languages-browser-default" ) }
108
72
</ Badge >
109
73
) }
110
- </ Flex >
111
- < Text textTransform = "uppercase" fontSize = "xs" color = "body.base" >
112
- { sourceName }
113
- </ Text >
114
- </ Box >
74
+ </ div >
75
+ < p className = "text-xs uppercase text-body" > { sourceName } </ p >
76
+ </ div >
115
77
{ isCurrent && (
116
- < Icon as = { BsCheck } fontSize = " 2xl" color = " primary.highContrast " />
78
+ < BsCheck className = "text- 2xl text- primary-high-contrast " />
117
79
) }
118
- </ Flex >
119
- < Text
120
- textTransform = "lowercase"
121
- fontSize = "xs"
122
- color = "body.medium"
123
- maxW = "full"
124
- >
80
+ </ div >
81
+ < p className = "max-w-full text-xs lowercase text-body-medium" >
125
82
{ progress } { t ( "page-languages-translated" ) } • { words } { " " }
126
83
{ t ( "page-languages-words" ) }
127
- </ Text >
84
+ </ p >
128
85
< ProgressBar value = { approvalProgress } />
129
- </ ChakraMenuItem >
86
+ </ CommandItem >
130
87
)
131
- } )
88
+ }
132
89
133
90
export default MenuItem
0 commit comments