-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🪟🧹 Introduce flex component (#20944)
- Loading branch information
Joe Reuter
authored
Jan 4, 2023
1 parent
2a83aec
commit 8dcca01
Showing
17 changed files
with
298 additions
and
58 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
8 changes: 0 additions & 8 deletions
8
airbyte-webapp/src/components/CreateConnection/DataResidency.module.scss
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,39 @@ | ||
import { ComponentStory, ComponentMeta } from "@storybook/react"; | ||
|
||
import { FlexContainer } from "./FlexContainer"; | ||
import { FlexItem } from "./FlexItem"; | ||
|
||
export default { | ||
title: "Ui/Flex", | ||
component: FlexContainer, | ||
} as ComponentMeta<typeof FlexContainer>; | ||
|
||
const Template: ComponentStory<typeof FlexContainer> = (args) => <FlexContainer {...args} />; | ||
|
||
const Item = ({ label, grow }: { label: string; grow?: boolean }) => ( | ||
<FlexItem grow={grow} style={{ backgroundColor: "#dddddd", borderRadius: 5, padding: 20 }}>{`<FlexItem${ | ||
grow ? " grow" : "" | ||
}>${label}</FlexItem>`}</FlexItem> | ||
); | ||
|
||
export const NoGrow = Template.bind({}); | ||
NoGrow.args = { | ||
children: ( | ||
<> | ||
<Item label="first" /> | ||
<Item label="second with a lot of content" /> | ||
<Item label="third" /> | ||
<Item label="forth" /> | ||
</> | ||
), | ||
}; | ||
|
||
export const Grow = Template.bind({}); | ||
Grow.args = { | ||
children: ( | ||
<> | ||
<Item label="first" grow /> | ||
<Item label="second" /> | ||
</> | ||
), | ||
}; |
89 changes: 89 additions & 0 deletions
89
airbyte-webapp/src/components/ui/Flex/FlexContainer.module.scss
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,89 @@ | ||
@use "scss/variables"; | ||
|
||
.container { | ||
display: flex; | ||
} | ||
|
||
.directionRow { | ||
flex-direction: row; | ||
} | ||
|
||
.directionColumn { | ||
flex-direction: column; | ||
} | ||
|
||
.directionColumnReverse { | ||
flex-direction: column-reverse; | ||
} | ||
|
||
.directionRowReverse { | ||
flex-direction: row-reverse; | ||
} | ||
|
||
.gapXs { | ||
gap: variables.$spacing-xs; | ||
} | ||
|
||
.gapSm { | ||
gap: variables.$spacing-sm; | ||
} | ||
|
||
.gapMd { | ||
gap: variables.$spacing-md; | ||
} | ||
|
||
.gapLg { | ||
gap: variables.$spacing-lg; | ||
} | ||
|
||
.gapXl { | ||
gap: variables.$spacing-xl; | ||
} | ||
|
||
.gap2xl { | ||
gap: variables.$spacing-2xl; | ||
} | ||
|
||
.alignItemsStart { | ||
align-items: flex-start; | ||
} | ||
|
||
.alignItemsEnd { | ||
align-items: flex-end; | ||
} | ||
|
||
.alignItemsCenter { | ||
align-items: center; | ||
} | ||
|
||
.alignItemsBaseline { | ||
align-items: baseline; | ||
} | ||
|
||
.alignItemsStretch { | ||
align-items: stretch; | ||
} | ||
|
||
.justifyContentStart { | ||
justify-content: flex-start; | ||
} | ||
|
||
.justifyContentEnd { | ||
justify-content: flex-end; | ||
} | ||
|
||
.justifyContentCenter { | ||
justify-content: center; | ||
} | ||
|
||
.justifyContentBetween { | ||
justify-content: space-between; | ||
} | ||
|
||
.justifyContentAround { | ||
justify-content: space-around; | ||
} | ||
|
||
.justifyContentEvenly { | ||
justify-content: space-evenly; | ||
} |
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,72 @@ | ||
import classNames from "classnames"; | ||
import React, { HTMLAttributes } from "react"; | ||
|
||
import styles from "./FlexContainer.module.scss"; | ||
|
||
interface FlexContainerProps { | ||
className?: string; | ||
/** | ||
* The flex-direction css property | ||
*/ | ||
direction?: "row" | "column" | "row-reverse" | "column-reverse"; | ||
/** | ||
* gap between the flex items - defaults to `md` if not provided. None means no gap is applied, the others map to the respective scss spacing variable. | ||
*/ | ||
gap?: "none" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl"; | ||
/** | ||
* The align-items css property | ||
*/ | ||
alignItems?: "flex-start" | "flex-end" | "center" | "baseline" | "stretch"; | ||
/** | ||
* The justify-content css property | ||
*/ | ||
justifyContent?: "flex-start" | "flex-end" | "center" | "space-between" | "space-around" | "space-evenly"; | ||
} | ||
|
||
/** | ||
* Renders a div element which layouts its children as flex items as specified by the props. | ||
* Children of a `FlexContainer` can but don't have to be `FlexItem` elements. | ||
*/ | ||
export const FlexContainer: React.FC<React.PropsWithChildren<FlexContainerProps & HTMLAttributes<HTMLDivElement>>> = ({ | ||
className, | ||
direction = "row", | ||
gap = "md", | ||
alignItems = "stretch", | ||
justifyContent = "flex-start", | ||
children, | ||
...otherProps | ||
}) => { | ||
const fullClassName = classNames( | ||
{ | ||
[styles.directionRow]: direction === "row", | ||
[styles.directionColumn]: direction === "column", | ||
[styles.directionRowReverse]: direction === "row-reverse", | ||
[styles.directionColumnReverse]: direction === "column-reverse", | ||
[styles.gapXs]: gap === "xs", | ||
[styles.gapSm]: gap === "sm", | ||
[styles.gapMd]: gap === "md", | ||
[styles.gapLg]: gap === "lg", | ||
[styles.gapXl]: gap === "xl", | ||
[styles.gap2xl]: gap === "2xl", | ||
[styles.alignItemsStart]: alignItems === "flex-start", | ||
[styles.alignItemsEnd]: alignItems === "flex-end", | ||
[styles.alignItemsCenter]: alignItems === "center", | ||
[styles.alignItemsBaseline]: alignItems === "baseline", | ||
[styles.alignItemsStretch]: alignItems === "stretch", | ||
[styles.justifyContentStart]: justifyContent === "flex-start", | ||
[styles.justifyContentEnd]: justifyContent === "flex-end", | ||
[styles.justifyContentCenter]: justifyContent === "center", | ||
[styles.justifyContentBetween]: justifyContent === "space-between", | ||
[styles.justifyContentAround]: justifyContent === "space-around", | ||
[styles.justifyContentEvenly]: justifyContent === "space-evenly", | ||
}, | ||
styles.container, | ||
className | ||
); | ||
|
||
return ( | ||
<div className={fullClassName} {...otherProps}> | ||
{children} | ||
</div> | ||
); | ||
}; |
25 changes: 25 additions & 0 deletions
25
airbyte-webapp/src/components/ui/Flex/FlexItem.module.scss
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,25 @@ | ||
@use "scss/variables"; | ||
|
||
.alignSelfStart { | ||
align-items: flex-end; | ||
} | ||
|
||
.alignSelfEnd { | ||
align-items: flex-end; | ||
} | ||
|
||
.alignSelfCenter { | ||
align-items: center; | ||
} | ||
|
||
.alignSelfBaseline { | ||
align-items: baseline; | ||
} | ||
|
||
.alignSelfStretch { | ||
align-items: stretch; | ||
} | ||
|
||
.grow { | ||
flex-grow: 1; | ||
} |
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,47 @@ | ||
import classNames from "classnames"; | ||
import React, { HTMLAttributes } from "react"; | ||
|
||
import styles from "./FlexItem.module.scss"; | ||
|
||
interface FlexItemProps { | ||
className?: string; | ||
/** | ||
* Sets `flex-grow` to 1 if truthy | ||
*/ | ||
grow?: boolean; | ||
/** | ||
* The `align-self` css property | ||
*/ | ||
alignSelf?: "flex-start" | "flex-end" | "center" | "baseline" | "stretch"; | ||
} | ||
|
||
/** | ||
* Renders a div element which sets css properties for flex children as given by the props. | ||
* This component can be used within a `FlexContainer` parent if grow or self-align props should be set, but it can also be omitted | ||
* in case no special flex properties are required. | ||
*/ | ||
export const FlexItem: React.FC<React.PropsWithChildren<FlexItemProps & HTMLAttributes<HTMLDivElement>>> = ({ | ||
className, | ||
grow, | ||
alignSelf, | ||
children, | ||
...otherProps | ||
}) => { | ||
const fullClassName = classNames( | ||
{ | ||
[styles.grow]: grow, | ||
[styles.alignSelfStart]: alignSelf === "flex-start", | ||
[styles.alignSelfEnd]: alignSelf === "flex-end", | ||
[styles.alignSelfCenter]: alignSelf === "center", | ||
[styles.alignSelfBaseline]: alignSelf === "baseline", | ||
[styles.alignSelfStretch]: alignSelf === "stretch", | ||
}, | ||
className | ||
); | ||
|
||
return ( | ||
<div className={fullClassName} {...otherProps}> | ||
{children} | ||
</div> | ||
); | ||
}; |
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,2 @@ | ||
export { FlexContainer } from "./FlexContainer"; | ||
export { FlexItem } from "./FlexItem"; |
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.