11import { useTextField } from "@react-aria/textfield" ;
22import { HTMLAttributes , useRef } from "react" ;
3- import useDimensions from "react-cool-dimensions" ;
43import { LocalizedString , Box , Field , IconButton } from ".." ;
54import { inputRecipe } from "../Field/Field.css" ;
65import { bodyRecipe } from "../Typography/Body/Body.css" ;
7- import { input } from "./SearchBar.css" ;
6+ import { input , inputContainer } from "./SearchBar.css" ;
87import { useDefaultMessages } from "../util/useDefaultMessages" ;
98import { useBentoConfig } from "../BentoConfigContext" ;
109import { AtLeast } from "../util/AtLeast" ;
@@ -25,16 +24,6 @@ export function SearchBar(props: Props) {
2524 const config = useBentoConfig ( ) . searchBar ;
2625 const inputRef = useRef < HTMLInputElement > ( null ) ;
2726
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-
3827 const { labelProps, inputProps, descriptionProps, errorMessageProps } = useTextField (
3928 {
4029 ...props ,
@@ -64,19 +53,17 @@ export function SearchBar(props: Props) {
6453 assistiveTextProps = { descriptionProps }
6554 errorMessageProps = { errorMessageProps }
6655 >
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" >
8067 { config . searchIcon ( { size : config . searchIconSize } ) }
8168 </ Box >
8269 < Box
@@ -90,7 +77,6 @@ export function SearchBar(props: Props) {
9077 height = { undefined }
9178 className = { [
9279 input ,
93- inputRecipe ( { validation : "valid" } ) ,
9480 bodyRecipe ( {
9581 color : props . disabled ? "disabled" : "primary" ,
9682 weight : "default" ,
@@ -99,29 +85,10 @@ export function SearchBar(props: Props) {
9985 } ) ,
10086 ] }
10187 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 }
11189 />
11290 { 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" >
12592 { rightAccessoryContent }
12693 </ Box >
12794 ) }
0 commit comments