Skip to content

Commit

Permalink
TextInput box (#8)
Browse files Browse the repository at this point in the history
* basic with icon and pic

* with unit and text abbreviation

* disabled and error

* simplify to atomic

* icons added

* add cursor disabled
  • Loading branch information
sitongliu-klaytn authored Sep 16, 2024
1 parent 2d86668 commit 3c3dfe1
Show file tree
Hide file tree
Showing 28 changed files with 592 additions and 1 deletion.
99 changes: 98 additions & 1 deletion example/src/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import {
KaText,
useKaTheme,
KaRadio,
KaTextInput,
} from '@kaiachain/kaia-design-system'

import { Row } from './components/Row'
import Buttons from './Buttons'
import CheckBoxes from './CheckBoxes'
import Texts from './Texts'
import { useState } from 'react'

const StyledContainer = styled(Row)`
padding: 20px;
Expand Down Expand Up @@ -40,6 +42,7 @@ const Home = ({
setTheme: React.Dispatch<React.SetStateAction<'light' | 'dark'>>
}) => {
const { getTheme } = useKaTheme()
const [value, setValue] = useState<string>('')

return (
<StyledContainer style={{ backgroundColor: getTheme('gray', '10') }}>
Expand Down Expand Up @@ -100,6 +103,53 @@ const Home = ({
style={{ width: 30, height: 20 }}
stroke="blue"
/>
<Row>
<KaIcon.KaiaBrandmark_white
style={{ width: 20, height: 20 }}
stroke="blue"
/>
<KaIcon.KaiaBrandmark_neonlime style={{ width: 20, height: 20 }} />
<KaIcon.KaiaBrandmark_black style={{ width: 20, height: 20 }} />
<KaIcon.KaiaWordmark_white
style={{ width: 50, height: 20 }}
stroke="blue"
/>

<KaIcon.KaiaWordmark_neonlime style={{ width: 50, height: 20 }} />
<KaIcon.KaiaWordmark_black style={{ width: 50, height: 20 }} />
</Row>
<Row>
<KaIcon.Dark_Symbol_KaiaCritters
style={{ width: 60, height: 60 }}
/>
<KaIcon.Light_Symbol_KaiaCritters
style={{ width: 60, height: 60 }}
/>
<KaIcon.Dark_Symbol_KaiaSquare style={{ width: 60, height: 60 }} />
<KaIcon.Light_Symbol_KaiaSquare style={{ width: 60, height: 60 }} />
<KaIcon.Dark_Symbol_KaiaPortal style={{ width: 60, height: 60 }} />
<KaIcon.Light_Symbol_KaiaPortal style={{ width: 60, height: 60 }} />
<KaIcon.Dark_Symbol_KaiaScan style={{ width: 60, height: 60 }} />
<KaIcon.Light_Symbol_KaiaScan style={{ width: 60, height: 60 }} />
<KaIcon.Dark_Symbol_KaiaDoc style={{ width: 60, height: 60 }} />
<KaIcon.Light_Symbol_KaiaDoc style={{ width: 60, height: 60 }} />
<KaIcon.Dark_Symbol_KaiaGovernanceForum
style={{ width: 60, height: 60 }}
/>
<KaIcon.Light_Symbol_KaiaGovernanceForum
style={{ width: 60, height: 60 }}
/>
<KaIcon.Dark_Symbol_KaiaDevHub style={{ width: 60, height: 60 }} />
<KaIcon.Light_Symbol_KaiaDevHub style={{ width: 60, height: 60 }} />
<KaIcon.Dark_Symbol_KaiaWallet style={{ width: 60, height: 60 }} />
<KaIcon.Light_Symbol_KaiaWallet style={{ width: 60, height: 60 }} />
<KaIcon.Dark_Symbol_KaiaDevForum
style={{ width: 60, height: 60 }}
/>
<KaIcon.Light_Symbol_KaiaDevForum
style={{ width: 60, height: 60 }}
/>
</Row>
</StyledSection>
<StyledSection>
<KaText fontType="title/lg_700">Labels</KaText>
Expand All @@ -109,7 +159,54 @@ const Home = ({
<KaLabel size="md" color="red" text="text" type="line" />
<KaLabel size="md" color="red" text="text" type="paleBorder" />
</StyledSection>

<StyledSection>
<KaText fontType="title/lg_700">TextInput</KaText>
<KaTextInput
inputProps={{
placeholder: 'placeholder',
value: value,
onChangeText: setValue,
}}
leftIcon="search"
leftUnit="$"
rightUnit="SGD"
/>
<KaTextInput
inputProps={{
placeholder: 'placeholder',
}}
leftIcon="close"
leftUnit="$"
/>
<KaTextInput
inputProps={{
placeholder: 'search here and see the sentence is very long',
}}
leftIcon="search"
width="300px"
rightIcon={'close'}
/>
<KaTextInput
inputProps={{
placeholder: 'search here and see the sentence is very long',
}}
leftIcon="search"
leftUnit="$"
rightUnit="Unit"
rightIcon={'close'}
isError={true}
/>
<KaTextInput
inputProps={{
placeholder: 'search here and see the sentence is very long',
}}
leftIcon="search"
leftUnit="$"
rightUnit="Unit"
rightIcon={'close'}
disabled={true}
/>
</StyledSection>
<StyledSection>
<KaText fontType="title/lg_700">Custom </KaText>
<StyledCustom>CustomCustomCustom</StyledCustom>
Expand Down
223 changes: 223 additions & 0 deletions src/components/Input/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
import { ReactElement, useState } from 'react'
import styled from '@emotion/styled'
import { themeFunc } from '../../styles'
import { KaText } from '../Text/Text'
import { useKaTheme } from '../../hooks'
import MathClose from '../../icons/MathClose.svg'
import SearchNormal from '../../icons/SearchNormal.svg'

const StyledContainer = styled.div<{ width?: string }>`
display: flex;
flex-direction: column;
width: ${(props) => props.width || '100%'};
gap: 5px;
`
const StyledInputContainer = styled.div<{ width?: string }>`
display: flex;
flex-direction: row;
flex: 1;
border-radius: var(--Radius-6, 360px);
border: none;
gap: 3px;
background-color: ${themeFunc('elevation', '9')};
align-items: center;
padding: 0;
width: ${(props) => props.width || 'auto'};
`

const StyledWrapper = styled.div`
display: flex;
flex-direction: row;
border-radius: var(--Radius-6, 360px);
box-sizing: border-box;
border: ${(props) => (props.isError ? '1px' : '4px')} solid
${(props: {
isFocused: boolean
borderColor: string
isError: boolean | undefined
errorColor: string
}): string =>
props.isError
? props.errorColor
: props.isFocused
? props.borderColor
: 'transparent'};
transition: border-color 0.3s ease;
`
const StyledInput = styled.input<{ isError?: boolean }>`
flex: 1;
width: 100%;
font-size: 14px;
font-weight: 400;
height: var(--Sizing-8, 40px);
background-color: transparent;
text-overflow: ellipsis;
color: ${themeFunc('gray', '0')};
border: none;
padding-left: 8px;
box-sizing: border-box;
::placeholder {
font-size: 14px;
font-family: Manrope;
line-height: 20px;
font-weight: 600;
color: ${(props) =>
props.isError
? themeFunc('danger', '6')
: props.disabled
? themeFunc('elevation', '6')
: themeFunc('elevation', '5')};
}
:focus {
outline: none;
}
:disabled {
cursor: not-allowed;
}
`
const StyledIconBox = styled.div`
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
`
const IconList = ['search', 'close'] as const
type IconType = (typeof IconList)[number]

export interface KaTextInputProps {
inputProps?: {
placeholder?: string
value?: string
onChangeText?: (value: string) => void
}
leftIcon?: IconType | ReactElement
rightIcon?: IconType | ReactElement
leftUnit?: string
rightUnit?: string
width?: string
disabled?: boolean
isError?: boolean
}

export const KaTextInput = ({
leftIcon,
rightIcon,
leftUnit,
rightUnit,
width,
inputProps,
disabled,
isError,
}: KaTextInputProps): ReactElement => {
const { getTheme } = useKaTheme()
const [onFocus, setOnFocus] = useState(false)
const Icons = (type: IconType) => {
switch (type) {
case 'search':
return (
<SearchNormal
style={{
width: 'var(--Sizing-3, 12px)',
height: 'var(--Sizing-3, 12px)',
}}
fill={disabled ? getTheme('elevation', '7') : getTheme('gray', '0')}
/>
)
case 'close':
return (
<MathClose
style={{
width: 'var(--Sizing-3, 12px)',
height: 'var(--Sizing-3, 12px)',
}}
fill={disabled ? getTheme('elevation', '7') : getTheme('gray', '0')}
/>
)
default:
return null
}
}
return (
<StyledContainer width={width}>
<StyledWrapper
isFocused={onFocus}
borderColor={getTheme('elevation', '8')}
isError={isError}
errorColor={getTheme('danger', '6')}
>
<StyledInputContainer>
{typeof leftIcon === 'string' && IconList.includes(leftIcon) ? (
<StyledIconBox
style={{
paddingLeft: '10px',
width: 'var(--Sizing-5, 24px)',
height: 'var(--Sizing-5, 24px)',
}}
>
{Icons(leftIcon)}
</StyledIconBox>
) : (
leftIcon
)}
{leftUnit && (
<KaText
fontType="body/md_400"
style={{
color: disabled
? getTheme('elevation', '7')
: getTheme('elevation', '4'),
marginLeft: leftIcon ? '3px' : '8px',
}}
>
{leftUnit}
</KaText>
)}

<StyledInput
onFocus={(): void => {
setOnFocus(true)
}}
onBlur={(): void => {
setOnFocus(false)
}}
isError={isError}
onChange={({ target: { value } }): void => {
inputProps?.onChangeText?.(value)
}}
disabled={disabled}
{...inputProps}
/>
{rightUnit && (
<KaText
fontType="body/md_400"
style={{
color: disabled
? getTheme('elevation', '7')
: getTheme('elevation', '4'),
marginRight: rightIcon ? '3px' : '10px',
}}
>
{rightUnit}
</KaText>
)}
{typeof rightIcon === 'string' && IconList.includes(rightIcon) ? (
<StyledIconBox
style={{
width: 'var(--Sizing-5, 24px)',
height: 'var(--Sizing-5, 24px)',
paddingRight: '10px',
}}
>
{Icons(rightIcon)}
</StyledIconBox>
) : (
rightIcon
)}
</StyledInputContainer>
</StyledWrapper>
</StyledContainer>
)
}
1 change: 1 addition & 0 deletions src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './Label/Label'
export * from './Text/Text'
export * from './Radio/Radio'
export * from './CheckBox/CheckBox'
export * from './Input/index'
4 changes: 4 additions & 0 deletions src/icons/Dark_Symbol_KaiaCritters.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/icons/Dark_Symbol_KaiaDevForum.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/icons/Dark_Symbol_KaiaDevHub.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/icons/Dark_Symbol_KaiaDoc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/icons/Dark_Symbol_KaiaGovernanceForum.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3c3dfe1

Please sign in to comment.