Skip to content

Commit 5b2adbf

Browse files
committed
Fix Input structure
1 parent da4d3ed commit 5b2adbf

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { useState } from 'react'
2+
3+
import { Input } from '.'
4+
5+
export function Controlled() {
6+
const [value, setValue] = useState('d')
7+
8+
return <Input onChange={(e) => setValue(e.target.value)} value={value} />
9+
}

packages/components/src/components/Input/Input.stories.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Meta, StoryObj } from '@storybook/react-vite'
22

3+
import { Controlled } from './Controlled'
34
import { GlassIcon } from './GlassIcon'
45
import { Input } from './index'
56

@@ -24,6 +25,13 @@ export const Default: Story = {
2425
},
2526
}
2627

28+
export const ControlledInput: Story = {
29+
args: {
30+
placeholder: 'Input text',
31+
},
32+
render: () => <Controlled />,
33+
}
34+
2735
export const Error: Story = {
2836
args: {
2937
placeholder: 'Input text',

packages/components/src/components/Input/index.tsx

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
Box,
55
Button,
66
Center,
7-
css,
87
DevupThemeTypography,
98
Input as DevupInput,
109
Text,
@@ -44,27 +43,29 @@ export function Input({
4443
typography,
4544
error = false,
4645
errorMessage,
47-
allowClear = false,
46+
allowClear = true,
4847
icon,
4948
colors,
5049
disabled,
5150
classNames,
51+
ref,
5252
...props
5353
}: InputProps) {
54-
const [value, setValue] = useState(defaultValue ?? '')
54+
const [value, setValue] = useState(defaultValue || '')
5555
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
5656
setValue(e.target.value)
57+
onChangeProp?.(e)
5758
}
5859
const handleClear = () => {
5960
setValue('')
6061
}
61-
const clearButtonVisible = value && !disabled
62+
const clearButtonVisible = value && !disabled && allowClear
6263

6364
return (
6465
<Box
66+
display="inline-block"
6567
pos="relative"
6668
selectors={{ '&,&>*': { boxSizing: 'border-box' } }}
67-
w="fit-content"
6869
>
6970
{icon && (
7071
<Center
@@ -86,11 +87,10 @@ export function Input({
8687
</Center>
8788
)}
8889
<DevupInput
90+
ref={ref}
8991
_disabled={{
90-
selectors: {
91-
'&::placeholder': {
92-
color: 'var(--inputDisabledText, light-dark(#D6D7DE, #373737))',
93-
},
92+
_placeholder: {
93+
color: 'var(--inputDisabledText, light-dark(#D6D7DE, #373737))',
9494
},
9595
bg: 'var(--inputDisabledBg, light-dark(#F0F0F3, #414244))',
9696
border: '1px solid var(--border, light-dark(#E4E4E4, #434343))',
@@ -104,6 +104,9 @@ export function Input({
104104
_hover={{
105105
border: '1px solid var(--primary, light-dark(red, blue))',
106106
}}
107+
_placeholder={{
108+
color: 'var(--inputPlaceholder, light-dark(#A9A8AB, #CBCBCB))',
109+
}}
107110
aria-label="input"
108111
bg="var(--inputBg, light-dark(#FFFFFF, #2E2E2E))"
109112
borderColor={
@@ -116,15 +119,10 @@ export function Input({
116119
borderWidth="1px"
117120
className={classNames?.input}
118121
disabled={disabled}
119-
onChange={onChangeProp ?? handleChange}
122+
onChange={handleChange}
120123
pl={icon ? '36px' : '12px'}
121124
pr={['36px', null, allowClear ? '36px' : '12px']}
122125
py="12px"
123-
selectors={{
124-
'&::placeholder': {
125-
color: 'var(--inputPlaceholder, light-dark(#A9A8AB, #CBCBCB))',
126-
},
127-
}}
128126
styleOrder={1}
129127
styleVars={{
130128
primary: colors?.primary,
@@ -142,14 +140,7 @@ export function Input({
142140
value={valueProp ?? value}
143141
{...props}
144142
/>
145-
{clearButtonVisible && (
146-
<ClearButton
147-
className={css({
148-
display: ['flex', null, allowClear ? 'flex' : 'none'],
149-
})}
150-
onClick={handleClear}
151-
/>
152-
)}
143+
{clearButtonVisible && <ClearButton onClick={handleClear} />}
153144
{errorMessage && (
154145
<Text
155146
aria-label="error-message"
@@ -174,7 +165,7 @@ export function ClearButton(props: ComponentProps<'button'>) {
174165
<Button
175166
alignItems="center"
176167
aria-label="clear-button"
177-
bg="var(--negative20, light-dark(#00000033, #FFFFFF66))"
168+
bg="var(--negative20, light-dark(#0003, #FFF6))"
178169
border="none"
179170
borderRadius="50%"
180171
boxSize="20px"

packages/components/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { Button } from './components/Button'
2+
export { Input } from './components/Input'

0 commit comments

Comments
 (0)