Skip to content

Commit

Permalink
enchance: scalability of the Button component (/common/Button.tsx)
Browse files Browse the repository at this point in the history
  • Loading branch information
mst-mkt committed Mar 3, 2024
1 parent 2eb411d commit b97392a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/components/LoginFrom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { useMemo } from 'react'
import { useInput } from '../hooks/useInput'
import { useGreeterStore } from '../stores/greeterStore'
import { Avatar } from './Avatar'
import { IconButton } from './IconButton'
import { PasswordInput } from './PasswordInput'
import { IconButton } from './common/Button'

const opacityAnimation = keyframes({
from: {
Expand Down Expand Up @@ -60,7 +60,7 @@ export const LoginForm = () => {
<Avatar user={selectedUser ?? undefined} style={styles.avatar} />
<p {...props(styles.name)}>{name}</p>
<PasswordInput value={password} onChange={setPassword} onEnter={login} />
<IconButton Icon={LogInIcon} onClick={login} />
<IconButton LeftIcon={LogInIcon} onClick={login} />
</div>
)
}
28 changes: 23 additions & 5 deletions src/components/IconButton.tsx → src/components/common/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { StyleXStyles, create, props } from '@stylexjs/stylex'
import { LucideIcon } from 'lucide-react'
import { ButtonHTMLAttributes } from 'react'

const styles = create({
button: {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
width: '100%',
width: 'fit-content',
height: '100%',
border: 0,
borderRadius: 8,
outline: 0,
gap: 8,
padding: 8,
fontSize: 16,
fontFamily: "'Lexend Variable', sans-serif",
color: '#333',
backgroundColor: {
default: '#69c2f3',
':hover': '#5ab6f6',
Expand All @@ -28,17 +34,29 @@ const styles = create({
},
})

type Props = {
Icon: LucideIcon
type AdditionalProps = {
LeftIcon?: LucideIcon
RightIcon?: LucideIcon
onClick?: () => void
style?: StyleXStyles
size?: number
}

export const IconButton = ({ Icon, onClick, style, size = 18 }: Props) => {
type Props = AdditionalProps & Omit<ButtonHTMLAttributes<HTMLButtonElement>, keyof AdditionalProps>

export const IconButton = ({
LeftIcon,
RightIcon,
onClick,
style,
size = 18,
...buttonProps
}: Props) => {
return (
<button type="button" onClick={onClick} {...props(styles.button, style)}>
<Icon size={size} color="#333" />
{LeftIcon && <LeftIcon size={size} color="#333" />}
{buttonProps.children}
{RightIcon && <RightIcon size={size} color="#333" />}
</button>
)
}

0 comments on commit b97392a

Please sign in to comment.