-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create
FormLayout
component and make form fields ready for it (#44)
- Loading branch information
1 parent
e092552
commit 6ed876a
Showing
47 changed files
with
549 additions
and
15 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
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,58 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import styles from './FormLayout.scss'; | ||
|
||
const FormLayout = (props) => { | ||
const { | ||
children, | ||
fieldLayout, | ||
id, | ||
} = props; | ||
|
||
if (!children) { | ||
return null; | ||
} | ||
|
||
const fieldLayoutClass = (layout) => { | ||
if (layout === 'horizontal') { | ||
return styles.rootFieldLayoutHorizontal; | ||
} | ||
|
||
return styles.rootFieldLayoutVertical; | ||
}; | ||
|
||
return ( | ||
<div | ||
id={id} | ||
className={[ | ||
styles.root, | ||
fieldLayoutClass(fieldLayout), | ||
].join(' ')} | ||
> | ||
{React.Children.map(children, (child) => { | ||
if (!React.isValidElement(child)) { | ||
return null; | ||
} | ||
|
||
return React.cloneElement(child, { | ||
inFormLayout: true, | ||
layout: fieldLayout, | ||
}); | ||
})} | ||
</div> | ||
); | ||
}; | ||
|
||
FormLayout.defaultProps = { | ||
children: null, | ||
fieldLayout: 'vertical', | ||
id: undefined, | ||
}; | ||
|
||
FormLayout.propTypes = { | ||
children: PropTypes.node, | ||
fieldLayout: PropTypes.oneOf(['horizontal', 'vertical']), | ||
id: PropTypes.string, | ||
}; | ||
|
||
export default FormLayout; |
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,22 @@ | ||
@import '../../../styles/settings/forms'; | ||
@import '../../../styles/settings/forms-theme'; | ||
@import '../../../styles/settings/layouts'; | ||
@import '../../../styles/tools/breakpoints'; | ||
@import '../../../styles/tools/offset'; | ||
|
||
.root { | ||
margin-bottom: $layout-common-bottom-offset; | ||
} | ||
|
||
.rootFieldLayoutVertical, | ||
.rootFieldLayoutHorizontal { | ||
display: grid; | ||
grid-template-columns: 1fr; | ||
grid-row-gap: $form-field-vertical-outer-spacing; | ||
} | ||
|
||
.rootFieldLayoutHorizontal { | ||
@include breakpoint-up($form-field-horizontal-breakpoint) { | ||
grid-template-columns: $form-layout-horizontal-label-width 1fr; | ||
} | ||
} |
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 { default } from './FormLayout'; |
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
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.