diff --git a/src/components/Input.tsx b/src/components/Input.tsx index abdeee6b..5ecffc64 100644 --- a/src/components/Input.tsx +++ b/src/components/Input.tsx @@ -1,13 +1,13 @@ import { ExtendTheme, Input as HonorableInput, mergeTheme } from 'honorable' import type { InputProps as HonorableInputProps } from 'honorable' import { type ComponentProps, type ReactNode, forwardRef, useRef } from 'react' -import styled from 'styled-components' +import styled, { useTheme } from 'styled-components' import { mergeRefs } from 'react-merge-refs' import { mergeProps } from 'react-aria' import { simulateInputChange } from '../utils/simulateInputChange' -import { useFillLevel } from './contexts/FillLevelContext' +import { type FillLevel, useFillLevel } from './contexts/FillLevelContext' import { TitleContent } from './Select' import Tooltip from './Tooltip' import IconFrame from './IconFrame' @@ -45,6 +45,13 @@ const startEndStyles = { paddingLeft: 0, } +const parentFillLevelToBackground = { + 0: 'fill-one', + 1: 'fill-two', + 2: 'fill-three', + 3: 'fill-three', +} as const satisfies Record + const ClearButton = styled( ({ className, @@ -90,6 +97,7 @@ const Input = forwardRef( }: InputProps, ref ) => { + const theme = useTheme() const inputRef = useRef(null) inputProps = { @@ -193,6 +201,9 @@ const Input = forwardRef( ) : undefined } + backgroundColor={ + theme.colors[parentFillLevelToBackground[parentFillLevel]] + } inputProps={inputProps} {...props} /> diff --git a/src/stories/Input.stories.tsx b/src/stories/Input.stories.tsx index 08ae7731..52662959 100644 --- a/src/stories/Input.stories.tsx +++ b/src/stories/Input.stories.tsx @@ -8,6 +8,7 @@ import CaretDownIcon from '../components/icons/CaretDownIcon' import SearchIcon from '../components/icons/SearchIcon' import Input from '../components/Input' import Input2 from '../components/Input2' +import { Card } from '../index' export default { title: 'Input', @@ -18,7 +19,7 @@ function InputSet(props: any) { return ( @@ -51,7 +52,7 @@ function Template(args: any) { return ( + + + + + + + + + ) } @@ -81,7 +97,7 @@ function CustomInputTemplate(args: any) { return (