Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: input control sizes and icon sizes #321

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions src/components/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BsX, BsPersonFill, BsSearch } from '@/assets'

const leftSideVariants = cva(['flex', 'items-center', 'text-inherit'])

const rightSideVariants = cva(['flex', 'self-center text-inherit'])
const rightSideVariants = cva(['flex', 'items-center', 'size-3', 'pb-1'])

const formVariants = cva(
[
Expand All @@ -14,9 +14,10 @@ const formVariants = cva(
'border-2',
'rounded-lg',
'overflow-hidden',
'p-3',
'items-center',
'gap-1.5',
'pl-3',
'pr-3',
'[&:has(:disabled)]:border-none'
],
{
Expand Down Expand Up @@ -48,7 +49,15 @@ const formVariants = cva(
'hover:border-green-700',
'focus-within:shadow-green'
]
},
size: {
sm: ['h-9.25'],
md: ['h-10.5']
}
},
defaultVariants: {
variant: 'primary',
size: 'md'
}
}
)
Expand All @@ -69,9 +78,10 @@ const inputVariants = cva(
}
)

interface InputProps extends React.HTMLProps<HTMLInputElement> {
interface InputProps extends Omit<React.HTMLProps<HTMLInputElement>, 'size'> {
variant: 'primary' | 'error' | 'success'
type: 'text' | 'search'
size: 'sm' | 'md'
formClassName?: string
leftSideClassName?: string
leftSideChild?: React.ReactNode
Expand All @@ -86,7 +96,7 @@ const convertTypeToComponent = {
}
}

const Input = React.forwardRef<HTMLInputElement, InputProps>(
const Input = React.forwardRef<HTMLButtonElement, InputProps>(
(
{
type,
Expand All @@ -96,17 +106,20 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
variant,
leftSideChild,
rightSideChild,
size,
onClear,
...props
},
ref
) => {
const leftSideComponent =
leftSideChild ?? convertTypeToComponent.left[`${type}`]
const rightSideComponent = rightSideChild ?? <BsX strokeWidth={0.6} />
const rightSideComponent = rightSideChild ?? (
<BsX width={3} height={3} viewBox="0 0 12 12" strokeWidth={0.6} />
)

return (
<form className={cn(formVariants({ variant }), formClassName)}>
<form className={cn(formVariants({ variant, size }), formClassName)}>
<div className={cn(leftSideVariants(), leftSideClassName)}>
{leftSideComponent}
</div>
Expand All @@ -116,7 +129,6 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
ref={ref}
{...props}
/>
<div className="input-right-side"></div>
<button type="button" onClick={onClear} className={rightSideVariants()}>
{rightSideComponent}
</button>
Expand Down
4 changes: 4 additions & 0 deletions stories/Input/Docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ A search is a user interface element that includes a search bar or input field,

<Canvas of={InputStories.SuccessInput} />

## Small Text

<Canvas of={InputStories.SmallInput} />

## Disabled Text

<Canvas of={InputStories.Disabled} />
Expand Down
3 changes: 2 additions & 1 deletion stories/Input/Input.example.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react'
import { Input, InputProps } from '@/index'

const InputDemo = ({ variant, type, disabled }: InputProps) => {
const InputDemo = ({ variant, type, disabled, size }: InputProps) => {
const [value, setValue] = useState('')
const handleOnClear = () => {
setValue('')
Expand All @@ -14,6 +14,7 @@ const InputDemo = ({ variant, type, disabled }: InputProps) => {
value={value}
variant={variant}
type={type}
size={size}
onClear={handleOnClear}
onChange={handleOnChange}
disabled={disabled}
Expand Down
16 changes: 16 additions & 0 deletions stories/Input/Input.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const meta = {
options: [true, false, 'indeterminate'],
control: { type: 'radio' }
},
size: {
options: ['sm', 'md'],
controls: { type: 'radio' }
},
className: {
controle: 'text',
description: 'Alter the className to change the style'
Expand All @@ -30,32 +34,44 @@ type Story = StoryObj<typeof meta>
// More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
export const PrimaryInput: Story = {
args: {
size: 'md',
variant: 'primary',
type: 'text'
}
}
export const ErrorInput: Story = {
args: {
size: 'md',
variant: 'error',
type: 'text'
}
}

export const SuccessInput: Story = {
args: {
size: 'md',
variant: 'success',
type: 'text'
}
}
export const SmallInput: Story = {
args: {
size: 'sm',
variant: 'primary',
type: 'text'
}
}
export const Disabled: Story = {
args: {
size: 'md',
variant: 'primary',
type: 'text',
disabled: true
}
}
export const Search: Story = {
args: {
size: 'md',
variant: 'primary',
type: 'search'
}
Expand Down
6 changes: 5 additions & 1 deletion tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export default {
},
extend: {
keyframes: animations.keyframes,
animation: animations.animation
animation: animations.animation,
height: {
'9.25': '37px',
'10.5': '42px'
}
}
}
}
Loading