-
Notifications
You must be signed in to change notification settings - Fork 317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/hadas/flex #456
Merged
Merged
Feature/hadas/flex #456
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3969118
flex component
ebaa2b5
Merge branch 'master' of github.com:mondaycom/monday-ui-react-core in…
4000643
flex component
8f49677
flex component
b463e6e
flex component
47caba5
flex component
baa4d71
try to fix order stories problem
8e73f71
Merge branch 'master' of github.com:mondaycom/monday-ui-react-core in…
7becd35
try to fix order stories problem
75975f1
fix code review notes
7977977
fix snapshot tests
03e7ee5
try to fix order stories problem
79c1d4d
fix linter
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,88 @@ | ||
import React, { useRef, forwardRef, useMemo } from "react"; | ||
import PropTypes from "prop-types"; | ||
import cx from "classnames"; | ||
import useMergeRefs from "../../hooks/useMergeRefs"; | ||
import { FLEX_POSITIONS, FLEX_GAPS, FLEX_DIRECTIONS } from "./FlexConstants"; | ||
import { BASE_POSITIONS } from "../../constants/positions"; | ||
import Clickable from "../Clickable/Clickable"; | ||
import classes from "./Flex.module.scss"; | ||
|
||
const Flex = forwardRef( | ||
({ className, id, elementType, direction, wrap, children, justify, align, gap, onClick, style }, ref) => { | ||
const componentRef = useRef(null); | ||
const mergedRef = useMergeRefs({ refs: [ref, componentRef] }); | ||
const overrideStyle = useMemo(() => ({ ...style, gap: `${gap}px` }), [style, gap]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hadasfa what happen if i don't pass any gap value? |
||
const Element = onClick ? Clickable : elementType; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love it! 😎 |
||
|
||
return ( | ||
<Element | ||
id={id} | ||
// in case the element is clickable, we will pass the real element type in this prop | ||
elementType={elementType} | ||
ref={mergedRef} | ||
className={cx( | ||
classes.container, | ||
classes[`direction${direction}`], | ||
classes[`justify${justify}`], | ||
classes[`align${align}`], | ||
className, | ||
{ | ||
[classes.wrap]: wrap | ||
} | ||
)} | ||
onClick={onClick} | ||
style={overrideStyle} | ||
> | ||
{children} | ||
</Element> | ||
); | ||
} | ||
); | ||
|
||
Flex.justify = FLEX_POSITIONS; | ||
Flex.align = BASE_POSITIONS; | ||
Flex.gaps = FLEX_GAPS; | ||
Flex.directions = FLEX_DIRECTIONS; | ||
|
||
Flex.propTypes = { | ||
/** | ||
* class name to be add to the wrapper | ||
*/ | ||
className: PropTypes.string, | ||
/** | ||
* id to be add to the wrapper | ||
*/ | ||
id: PropTypes.string, | ||
style: PropTypes.object, | ||
direction: PropTypes.oneOf([Flex.directions.ROW, Flex.directions.COLUMN]), | ||
elementType: PropTypes.string, | ||
wrap: PropTypes.bool, | ||
children: PropTypes.oneOfType([PropTypes.element, PropTypes.arrayOf(PropTypes.element)]), | ||
justify: PropTypes.oneOf([ | ||
Flex.justify.START, | ||
Flex.justify.CENTER, | ||
Flex.justify.END, | ||
Flex.justify.SPACE_BETWEEN, | ||
Flex.justify.SPACE_AROUND | ||
]), | ||
align: PropTypes.oneOf([Flex.align.START, Flex.align.CENTER, Flex.align.END]), | ||
gap: PropTypes.oneOfType([ | ||
PropTypes.oneOf([Flex.gaps.NONE, Flex.gaps.SMALL, Flex.gaps.MEDIUM, Flex.gaps.LARGE]), | ||
PropTypes.number | ||
]) | ||
}; | ||
|
||
Flex.defaultProps = { | ||
className: "", | ||
id: undefined, | ||
elementType: "div", | ||
style: undefined, | ||
wrap: false, | ||
children: undefined, | ||
direction: Flex.directions.ROW, | ||
justify: Flex.justify.START, | ||
align: Flex.align.CENTER, | ||
gap: Flex.gaps.NONE | ||
}; | ||
|
||
export default Flex; |
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,48 @@ | ||
@import "../../styles/themes.scss"; | ||
|
||
.container { | ||
display: flex; | ||
flex-direction: row; | ||
&.justify { | ||
&Start { | ||
justify-content: flex-start; | ||
} | ||
|
||
&End { | ||
justify-content: flex-end; | ||
} | ||
|
||
&Center { | ||
justify-content: center; | ||
} | ||
|
||
&SpaceBetween { | ||
justify-content: space-between; | ||
} | ||
|
||
&SpaceAround { | ||
justify-content: space-around; | ||
} | ||
} | ||
&.align { | ||
&Start { | ||
align-items: flex-start; | ||
} | ||
|
||
&End { | ||
align-items: flex-end; | ||
} | ||
|
||
&Center { | ||
align-items: center; | ||
} | ||
} | ||
&.direction { | ||
&Column { | ||
flex-direction: column; | ||
} | ||
} | ||
&.wrap { | ||
flex-wrap: wrap; | ||
} | ||
} |
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,20 @@ | ||
import { BASE_POSITIONS } from "../../constants/positions"; | ||
|
||
export const FLEX_POSITIONS = Object.freeze({ | ||
...BASE_POSITIONS, | ||
SPACE_AROUND: "SpaceAround", | ||
SPACE_BETWEEN: "SpaceBetween" | ||
}); | ||
|
||
export const FLEX_GAPS = Object.freeze({ | ||
XS: 4, | ||
SMALL: 8, | ||
MEDIUM: 16, | ||
LARGE: 24, | ||
NONE: 0 | ||
}); | ||
|
||
export const FLEX_DIRECTIONS = Object.freeze({ | ||
ROW: "Row", | ||
COLUMN: "Column" | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hadasfa can we upgrade the version of Storybook (it might solve it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we currently in very advanced alpha version. I can try to update to the most recent alpha version (we are few patches behind), that's ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can upgrade but could be for a different PR