forked from equinox-fund/equinox-lib
-
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.
datefield and multiselect to form component
- Loading branch information
Showing
14 changed files
with
535 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,3 +1,2 @@ | ||
export { default } from './Checkbox' | ||
|
||
export type { CheckboxProps } from './Checkbox' |
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,24 @@ | ||
import { Story, Meta } from '@storybook/react' | ||
import DateField, { DateFieldProps } from './DateField' | ||
|
||
export default { | ||
title: 'components/form/DateField', | ||
component: DateField | ||
} as Meta | ||
|
||
const Template: Story<DateFieldProps> = (args) => { | ||
return ( | ||
<div className="p-12"> | ||
<DateField {...args} /> | ||
</div> | ||
) | ||
} | ||
|
||
export const Default = Template.bind({}) | ||
Default.args = { | ||
name: 'birthdate', | ||
placeholder: 'Enter your date of birth', | ||
error: '', | ||
helper: '', | ||
label: '' | ||
} |
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,81 @@ | ||
import classnames from 'classnames' | ||
import { FC } from 'react' | ||
import Typography from '../../common/Typography' | ||
import styles from './styles' | ||
|
||
export interface DateFieldProps { | ||
name: string | ||
label?: string | ||
helper?: string | ||
size?: 'small' | 'medium' | ||
error?: string | ||
placeholder?: string | ||
className?: string | ||
onChange?(event: React.ChangeEvent<HTMLInputElement>): void | ||
[t: string]: any | ||
borders?: boolean | ||
} | ||
|
||
const DateField: FC<DateFieldProps> = ({ | ||
name, | ||
label, | ||
value, | ||
error, | ||
placeholder, | ||
icon, | ||
helper, | ||
size = 'small', | ||
borders = true, | ||
onChange | ||
}) => { | ||
const handleKeyDown = (e) => { | ||
if (e.key === 'Enter') { | ||
e.target.blur() | ||
} | ||
} | ||
|
||
const handleFocus = (e) => { | ||
e.target.type = 'date' | ||
} | ||
|
||
return ( | ||
<div css={styles({ size, borders })}> | ||
{label && ( | ||
<div className="mb-1.5"> | ||
<Typography color="muted" size="large" caption> | ||
{label} | ||
</Typography> | ||
</div> | ||
)} | ||
|
||
<div className="input-wrapper"> | ||
<input | ||
name={name} | ||
type={value ? 'date' : 'text'} | ||
defaultValue={value} | ||
onFocus={handleFocus} | ||
className={classnames({ ['error']: error })} | ||
placeholder={placeholder} | ||
onKeyDown={handleKeyDown} | ||
onChange={onChange} | ||
/> | ||
{icon && <span className="icon">{icon}</span>} | ||
</div> | ||
|
||
<div className="helper"> | ||
{error && ( | ||
<Typography color="error" size="medium" caption> | ||
{error} | ||
</Typography> | ||
)} | ||
{helper && !error && ( | ||
<Typography color="muted" size="medium" caption lineBreaks> | ||
{helper} | ||
</Typography> | ||
)} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default DateField |
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 @@ | ||
export { default } from './DateField' | ||
|
||
export type { DateFieldProps } from './DateField' |
Oops, something went wrong.