-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(file-input): add FileInput component
- Loading branch information
1 parent
9e2bfc9
commit 9a98418
Showing
3 changed files
with
114 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,67 @@ | ||
import React from 'react' | ||
import { Story, Meta } from '@storybook/react' | ||
|
||
import FileInput, { FileInputProps } from '.' | ||
|
||
export default { | ||
title: 'Data Input/FileInput', | ||
component: FileInput, | ||
args: { | ||
className: 'w-full max-w-xs', | ||
disabled: false, | ||
}, | ||
} as Meta | ||
|
||
const Template: Story<FileInputProps> = (args) => { | ||
return <FileInput {...args} /> | ||
} | ||
|
||
export const Default = Template.bind({}) | ||
Default.args = {} | ||
|
||
export const Colors: Story<FileInputProps> = (args) => { | ||
return ( | ||
<div className="w-full flex flex-col gap-2"> | ||
<FileInput {...args} color="primary" /> | ||
<FileInput {...args} color="secondary" /> | ||
<FileInput {...args} color="accent" /> | ||
<FileInput {...args} color="ghost" /> | ||
<FileInput {...args} color="info" /> | ||
<FileInput {...args} color="success" /> | ||
<FileInput {...args} color="warning" /> | ||
<FileInput {...args} color="error" /> | ||
</div> | ||
) | ||
} | ||
Colors.args = {} | ||
|
||
export const Sizes: Story<FileInputProps> = (args) => { | ||
return ( | ||
<div className="flex flex-col gap-4 w-full items-center"> | ||
<FileInput {...args} size="xs" /> | ||
<FileInput {...args} size="sm" /> | ||
<FileInput {...args} size="md" /> | ||
<FileInput {...args} size="lg" /> | ||
</div> | ||
) | ||
} | ||
Sizes.args = {} | ||
|
||
export const FormControlAndLabels: Story<FileInputProps> = (args) => { | ||
return ( | ||
<div className="flex w-full component-preview p-4 items-center justify-center gap-2 font-sans"> | ||
<div className="form-control w-full max-w-xs"> | ||
<label className="label"> | ||
<span className="label-text">Pick a file</span> | ||
<span className="label-text-alt">Alt label</span> | ||
</label> | ||
<FileInput {...args} /> | ||
<label className="label"> | ||
<span className="label-text-alt">Alt label</span> | ||
<span className="label-text-alt">Alt label</span> | ||
</label> | ||
</div> | ||
</div> | ||
) | ||
} | ||
FormControlAndLabels.args = {} |
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,44 @@ | ||
import clsx from 'clsx' | ||
import React, { forwardRef } from 'react' | ||
import { twMerge } from 'tailwind-merge' | ||
import { ComponentColor, ComponentSize, IComponentBaseProps } from '../types' | ||
|
||
export type FileInputProps = Omit< | ||
React.InputHTMLAttributes<HTMLInputElement>, | ||
'size' | ||
> & | ||
IComponentBaseProps & { | ||
size?: ComponentSize | ||
color?: ComponentColor | ||
bordered?: boolean | ||
} | ||
|
||
const FileInput = forwardRef<HTMLInputElement, FileInputProps>( | ||
( | ||
{ className, size, color, bordered, dataTheme, ...props }, | ||
ref | ||
): JSX.Element => { | ||
const classes = twMerge( | ||
'file-input', | ||
className, | ||
clsx({ | ||
[`file-input-${size}`]: size, | ||
[`file-input-${color}`]: color, | ||
'file-input-bordered': bordered, | ||
}) | ||
) | ||
return ( | ||
<input | ||
{...props} | ||
ref={ref} | ||
type="file" | ||
data-theme={dataTheme} | ||
className={classes} | ||
/> | ||
) | ||
} | ||
) | ||
|
||
FileInput.displayName = 'FileInput' | ||
|
||
export default FileInput |
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,3 @@ | ||
import FileInput, { FileInputProps as TFileInputProps } from './FileInput' | ||
export type FileInputProps = TFileInputProps | ||
export default FileInput |