Skip to content

Commit ee8408c

Browse files
authored
fix: Set input background color based on parent fill level (#606)
1 parent bdd6961 commit ee8408c

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

src/components/Input.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { ExtendTheme, Input as HonorableInput, mergeTheme } from 'honorable'
22
import type { InputProps as HonorableInputProps } from 'honorable'
33
import { type ComponentProps, type ReactNode, forwardRef, useRef } from 'react'
4-
import styled from 'styled-components'
4+
import styled, { useTheme } from 'styled-components'
55
import { mergeRefs } from 'react-merge-refs'
66
import { mergeProps } from 'react-aria'
77

88
import { simulateInputChange } from '../utils/simulateInputChange'
99

10-
import { useFillLevel } from './contexts/FillLevelContext'
10+
import { type FillLevel, useFillLevel } from './contexts/FillLevelContext'
1111
import { TitleContent } from './Select'
1212
import Tooltip from './Tooltip'
1313
import IconFrame from './IconFrame'
@@ -45,6 +45,13 @@ const startEndStyles = {
4545
paddingLeft: 0,
4646
}
4747

48+
const parentFillLevelToBackground = {
49+
0: 'fill-one',
50+
1: 'fill-two',
51+
2: 'fill-three',
52+
3: 'fill-three',
53+
} as const satisfies Record<FillLevel, string>
54+
4855
const ClearButton = styled(
4956
({
5057
className,
@@ -90,6 +97,7 @@ const Input = forwardRef(
9097
}: InputProps,
9198
ref
9299
) => {
100+
const theme = useTheme()
93101
const inputRef = useRef<HTMLInputElement>(null)
94102

95103
inputProps = {
@@ -193,6 +201,9 @@ const Input = forwardRef(
193201
</>
194202
) : undefined
195203
}
204+
backgroundColor={
205+
theme.colors[parentFillLevelToBackground[parentFillLevel]]
206+
}
196207
inputProps={inputProps}
197208
{...props}
198209
/>

src/stories/Input.stories.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import CaretDownIcon from '../components/icons/CaretDownIcon'
88
import SearchIcon from '../components/icons/SearchIcon'
99
import Input from '../components/Input'
1010
import Input2 from '../components/Input2'
11+
import { Card } from '../index'
1112

1213
export default {
1314
title: 'Input',
@@ -18,7 +19,7 @@ function InputSet(props: any) {
1819
return (
1920
<Flex
2021
direction="column"
21-
maxWidth="400px"
22+
maxWidth="500px"
2223
gap="large"
2324
>
2425
<Input {...props} />
@@ -51,7 +52,7 @@ function Template(args: any) {
5152
return (
5253
<Flex
5354
direction="column"
54-
maxWidth="400px"
55+
maxWidth="500px"
5556
gap="large"
5657
>
5758
<InputSet
@@ -63,6 +64,21 @@ function Template(args: any) {
6364
{...props}
6465
small
6566
/>
67+
<Card padding="large">
68+
<InputSet {...props} />
69+
</Card>
70+
<Card
71+
fillLevel={2}
72+
padding="large"
73+
>
74+
<InputSet {...props} />
75+
</Card>
76+
<Card
77+
fillLevel={3}
78+
padding="large"
79+
>
80+
<InputSet {...props} />
81+
</Card>
6682
</Flex>
6783
)
6884
}
@@ -81,7 +97,7 @@ function CustomInputTemplate(args: any) {
8197
return (
8298
<Flex
8399
direction="column"
84-
maxWidth="400px"
100+
maxWidth="500px"
85101
>
86102
<Div>
87103
<Input
@@ -123,7 +139,7 @@ function CustomInputV2Template(args: any) {
123139
return (
124140
<Flex
125141
direction="column"
126-
maxWidth="400px"
142+
maxWidth="500px"
127143
>
128144
<Div marginTop="medium">
129145
<Input2

0 commit comments

Comments
 (0)