-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3444e3
commit b9da326
Showing
49 changed files
with
199 additions
and
126 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
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
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,105 @@ | ||
import React, { forwardRef, ReactNode, Ref } from "react"; | ||
import { filterDOMProps } from "@react-aria/utils"; | ||
import { css } from "@emotion/react"; | ||
|
||
import { DOMProps, FlexStyleProps } from "@phoenix/components/types"; | ||
import { | ||
passthroughStyle, | ||
responsiveDimensionValue, | ||
StyleHandlers, | ||
useStyleProps, | ||
} from "@phoenix/components/utils"; | ||
|
||
export interface FlexProps extends DOMProps, FlexStyleProps { | ||
/** Children of the flex container. */ | ||
children: ReactNode; | ||
} | ||
|
||
const flexCSS = css` | ||
display: flex; | ||
`; | ||
|
||
const flexStyleProps: StyleHandlers = { | ||
direction: ["flexDirection", passthroughStyle], | ||
wrap: ["flexWrap", flexWrapValue], | ||
justifyContent: ["justifyContent", flexAlignValue], | ||
alignItems: ["alignItems", flexAlignValue], | ||
alignContent: ["alignContent", flexAlignValue], | ||
}; | ||
|
||
function Flex(props: FlexProps, ref: Ref<HTMLDivElement>) { | ||
const { children, ...otherProps } = props; | ||
|
||
const matchedBreakpoints = ["base"]; | ||
const { styleProps } = useStyleProps(otherProps); | ||
const { styleProps: flexStyle } = useStyleProps(otherProps, flexStyleProps); | ||
|
||
// If no gaps, or native support exists, then we only need to render a single div. | ||
const style = { | ||
...styleProps.style, | ||
...flexStyle.style, | ||
}; | ||
|
||
if (props.gap != null) { | ||
style.gap = responsiveDimensionValue(props.gap, matchedBreakpoints); | ||
} | ||
|
||
if (props.columnGap != null) { | ||
style.columnGap = responsiveDimensionValue( | ||
props.columnGap, | ||
matchedBreakpoints | ||
); | ||
} | ||
|
||
if (props.rowGap != null) { | ||
style.rowGap = responsiveDimensionValue(props.rowGap, matchedBreakpoints); | ||
} | ||
|
||
return ( | ||
<div | ||
css={flexCSS} | ||
{...filterDOMProps(otherProps)} | ||
className="flex" | ||
style={style} | ||
ref={ref} | ||
> | ||
{children} | ||
</div> | ||
); | ||
} | ||
|
||
/** | ||
* Normalize 'start' and 'end' alignment values to 'flex-start' and 'flex-end' | ||
* in flex containers for browser compatibility. | ||
*/ | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
function flexAlignValue(value: any) { | ||
if (value === "start") { | ||
return "flex-start"; | ||
} | ||
|
||
if (value === "end") { | ||
return "flex-end"; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
/** | ||
* Takes a boolean and translates it to flex wrap or nowrap. | ||
*/ | ||
function flexWrapValue(value: boolean | "wrap" | "nowrap") { | ||
if (typeof value === "boolean") { | ||
return value ? "wrap" : "nowrap"; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
/** | ||
* A layout container using flexbox. Provides dimension values, and supports the gap | ||
* property to define consistent spacing between items. | ||
*/ | ||
const _Flex = forwardRef(Flex); | ||
export { _Flex as 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 @@ | ||
export * from "./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
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
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
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.