1
1
import { useTextField } from "@react-aria/textfield" ;
2
2
import { HTMLAttributes , useRef } from "react" ;
3
- import useDimensions from "react-cool-dimensions" ;
4
3
import { LocalizedString , Box , Field , IconButton } from ".." ;
5
4
import { inputRecipe } from "../Field/Field.css" ;
6
5
import { bodyRecipe } from "../Typography/Body/Body.css" ;
7
- import { input } from "./SearchBar.css" ;
6
+ import { input , inputContainer } from "./SearchBar.css" ;
8
7
import { useDefaultMessages } from "../util/useDefaultMessages" ;
9
8
import { useBentoConfig } from "../BentoConfigContext" ;
10
9
import { AtLeast } from "../util/AtLeast" ;
@@ -25,16 +24,6 @@ export function SearchBar(props: Props) {
25
24
const config = useBentoConfig ( ) . searchBar ;
26
25
const inputRef = useRef < HTMLInputElement > ( null ) ;
27
26
28
- const { observe : leftAccessoryRef , width : leftAccessoryWidth } = useDimensions ( {
29
- // This is needed to include the padding in the width calculation
30
- useBorderBoxSize : true ,
31
- } ) ;
32
-
33
- const { observe : rightAccessoryRef , width : rightAccessoryWidth } = useDimensions ( {
34
- // This is needed to include the padding in the width calculation
35
- useBorderBoxSize : true ,
36
- } ) ;
37
-
38
27
const { labelProps, inputProps, descriptionProps, errorMessageProps } = useTextField (
39
28
{
40
29
...props ,
@@ -64,19 +53,17 @@ export function SearchBar(props: Props) {
64
53
assistiveTextProps = { descriptionProps }
65
54
errorMessageProps = { errorMessageProps }
66
55
>
67
- < Box position = "relative" display = "flex" >
68
- < Box
69
- ref = { leftAccessoryRef }
70
- position = "absolute"
71
- display = "flex"
72
- justifyContent = "center"
73
- alignItems = "center"
74
- paddingLeft = { config . paddingX }
75
- paddingRight = { config . internalSpacing }
76
- top = { 0 }
77
- bottom = { 0 }
78
- left = { 0 }
79
- >
56
+ < Box
57
+ display = "flex"
58
+ className = { [ inputRecipe ( { validation : "valid" } ) , inputContainer ] }
59
+ gap = { config . internalSpacing }
60
+ paddingX = { config . paddingX }
61
+ background = { config . background . default }
62
+ paddingY = { config . paddingY }
63
+ { ...getRadiusPropsFromConfig ( config . radius ) }
64
+ style = { getReadOnlyBackgroundStyle ( config ) }
65
+ >
66
+ < Box display = "flex" justifyContent = "center" alignItems = "center" >
80
67
{ config . searchIcon ( { size : config . searchIconSize } ) }
81
68
</ Box >
82
69
< Box
@@ -90,7 +77,6 @@ export function SearchBar(props: Props) {
90
77
height = { undefined }
91
78
className = { [
92
79
input ,
93
- inputRecipe ( { validation : "valid" } ) ,
94
80
bodyRecipe ( {
95
81
color : props . disabled ? "disabled" : "primary" ,
96
82
weight : "default" ,
@@ -99,29 +85,10 @@ export function SearchBar(props: Props) {
99
85
} ) ,
100
86
] }
101
87
display = "flex"
102
- style = { {
103
- flexGrow : 1 ,
104
- paddingLeft : leftAccessoryWidth ,
105
- paddingRight : rightAccessoryWidth ,
106
- ...getReadOnlyBackgroundStyle ( config ) ,
107
- } }
108
- { ...getRadiusPropsFromConfig ( config . radius ) }
109
- paddingY = { config . paddingY }
110
- background = { config . background . default }
88
+ flexGrow = { 1 }
111
89
/>
112
90
{ rightAccessoryContent && (
113
- < Box
114
- ref = { rightAccessoryRef }
115
- position = "absolute"
116
- display = "flex"
117
- justifyContent = "center"
118
- alignItems = "center"
119
- paddingLeft = { config . internalSpacing }
120
- paddingRight = { config . paddingX }
121
- top = { 0 }
122
- bottom = { 0 }
123
- right = { 0 }
124
- >
91
+ < Box display = "flex" justifyContent = "center" alignItems = "center" >
125
92
{ rightAccessoryContent }
126
93
</ Box >
127
94
) }
0 commit comments