-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d933fd
commit 4fde699
Showing
8 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { InputSize } from '.'; | ||
|
||
export type BaseInputProps = { | ||
size?: InputSize; | ||
disabled?: boolean; | ||
readOnly?: boolean; | ||
error?: boolean; | ||
className?: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from './queryable-component.model'; | ||
export * from './base-input-props.model'; | ||
export * from './input-size.model'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type InputSize = 'md' | 'sm'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './text-input.component'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, { ComponentPropsWithRef, forwardRef } from 'react'; | ||
import clsx from 'clsx'; | ||
|
||
import { BaseInputProps } from '../../models'; | ||
import { getTextBasedInputClasses } from '../../utils/text-based-input.utils'; | ||
|
||
type TextInputProps = BaseInputProps & ComponentPropsWithRef<'input'>; | ||
|
||
export const TextInput = forwardRef<HTMLInputElement, TextInputProps>( | ||
({ disabled, readOnly, error, size, className, ...rest }, ref) => { | ||
return ( | ||
<> | ||
<input | ||
ref={ref} | ||
type="text" | ||
disabled={disabled} | ||
readOnly={readOnly} | ||
aria-invalid={error || undefined} | ||
className={clsx( | ||
getTextBasedInputClasses({ | ||
disabled: disabled || readOnly, | ||
error, | ||
size, | ||
}), | ||
className | ||
)} | ||
{...rest} | ||
/> | ||
</> | ||
); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
|
||
import { TextInput } from './text-input.component'; | ||
|
||
export default { | ||
title: 'Atoms/TextInput', | ||
component: TextInput, | ||
} as ComponentMeta<typeof TextInput>; | ||
|
||
export const Default: ComponentStory<typeof TextInput> = () => <TextInput />; | ||
|
||
export const Disabled: ComponentStory<typeof TextInput> = () => ( | ||
<TextInput disabled={true} /> | ||
); | ||
|
||
export const Readonly: ComponentStory<typeof TextInput> = () => ( | ||
<TextInput readOnly={true} /> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import clsx from 'clsx'; | ||
|
||
import { InputSize } from '../models'; | ||
|
||
type TextBasedInputClassProps = { | ||
disabled?: boolean; | ||
error?: boolean; | ||
size?: InputSize; | ||
}; | ||
|
||
export const getTextBasedInputClasses = ({ | ||
disabled, | ||
error, | ||
size = 'md', | ||
}: TextBasedInputClassProps) => | ||
clsx( | ||
'appearance-none border rounded focus:outline-none placeholder-primary-300 bg-slate-100', | ||
{ | ||
'py-1 px-2 text-sm': size === 'sm', | ||
'py-3 px-4 text-base': size === 'md', | ||
// 'text-primary-400': disabled, | ||
// 'text-primary-500': !disabled, | ||
// 'border-red-500 focus:ring-1 focus:ring-red-500': error, | ||
'border-primary-150 focus:shadow-primary-100': !error, | ||
} | ||
); |