-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(atoms): add FormError component
- Loading branch information
Showing
4 changed files
with
553 additions
and
10 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
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,51 @@ | ||
// @flow | ||
|
||
import React from 'react'; | ||
|
||
import { createStyledTag, createTheme, getThemeStyle } from '../../../utils'; | ||
import { Row } from '../../FlexLayout/FlexLayout'; | ||
import { Text } from '../../typography/Text'; | ||
import { Icon } from '../../typography/Icon'; | ||
|
||
type FormErrorProps = { | ||
/** form error */ | ||
error?: ?string, | ||
/** form error */ | ||
children?: ?React$Node, | ||
}; | ||
|
||
const name = 'formError'; | ||
|
||
const theme = createTheme(name, (colors: *, sizes: *): * => ({ | ||
errorPlate: { | ||
border: `1px solid ${colors.DANGER}`, | ||
borderRadius: sizes.MAIN_BORDER_RADIUS, | ||
padding: '1.6rem', | ||
}, | ||
|
||
modifiers: { }, | ||
defaults: { }, | ||
})); | ||
|
||
const FormErrorPlateTag = createStyledTag(name, props => ({ | ||
...getThemeStyle(props, name).errorPlate, | ||
})); | ||
|
||
function FormError({ error, children }: FormErrorProps) { | ||
return ( | ||
<FormErrorPlateTag tagName="div" > | ||
<Row gap="md"> | ||
<Icon name="Alert" color="DANGER" size="lg" /> | ||
<Text color="GRAY1" lineHeight="lg">{ error || children }</Text> | ||
</Row> | ||
</FormErrorPlateTag> | ||
); | ||
} | ||
|
||
FormError.defaultProps = { | ||
...theme[name].defaults, | ||
component: 'form', | ||
direction: 'column', | ||
}; | ||
|
||
export { FormError, theme }; |
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
Oops, something went wrong.