Skip to content

25 add missing flex properties to flex #26

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

Merged
merged 7 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import {

import type {
TFlexDirection,
TFlexOption,
TFlexOptionContent,
TFlexOptionItems,
TFlexWrap,
TFlexGrow,
TFlexShrink,
TFlexBasis,
TFlexShorthandDimensions,
TFlexPosition,
} from "@components/layout/Flex/types";
Expand All @@ -25,9 +30,14 @@ type TProps = {
children: ReactNode;
position?: TFlexPosition;
direction?: TFlexDirection;
justifyContent?: TFlexOption;
alignItems?: TFlexOption;
wrap?: boolean;
justifyContent?: TFlexOptionContent;
alignItems?: TFlexOptionItems;
alignContent?: TFlexOptionContent;
alignSelf?: TFlexOptionItems;
grow?: TFlexGrow;
noShrink?: TFlexShrink;
basis?: TFlexBasis;
wrap?: TFlexWrap;
className?: string;
gap?: TThemeSpacing;
margin?: TThemeShorthandSpacing;
Expand All @@ -49,8 +59,14 @@ type TProps = {
* - `direction`: flex-direction property
* - `justifyContent`: justify-content property
* - `alignItems`: align-items property
* - `alignContent`: align-content property
* - `alignSelf`: align-self property
* - `wrap`: flex-wrap property
* - `gap`: gap between children, with fixed predefined values from the design system, not discriminating between horizontal and vertical gap (because there are literally the same values)
* - `grow`: shorthand for flex-grow property
* - `noShrink`: shorthand for flex-shrink property, noShrik is the same as flex-shrink: 0
* - `basis`: shorthand for flex-basis property, only global values are supported, for specific values use className prop
* - `position`: position property, supports all global values
* - `margin`: margin property, using the same values like gap, expects the shorthand notation
* - `padding`: same like margin, but for padding, concrete example below
*
Expand All @@ -74,15 +90,33 @@ type TProps = {
*
*
* @default
* direction = "row", justifyContent = "start", alignItems = "start", wrap = false, gap = "None", margin = ["None"], padding = ["None"], shHeight = "auto", shWidth = "auto"
* direction = "row",
* position = "static",
* justifyContent = "start",
* alignItems = "stretch",
* alignContent = "stretch",
* alignSelf = "auto",
* grow = false,
* noShrink = false,
* wrap = false,
* gap = "None",
* margin = ["None"],
* padding = ["None"],
* shHeight = "auto",
* shWidth = "auto"
*/
export default function Flex({
direction = "row",
position = "static",
justifyContent = "start",
alignItems = "start",
alignContent = "stretch",
alignItems = "stretch",
alignSelf = "auto",
wrap = false,
gap = "None",
grow = false,
noShrink = false,
basis = "auto",
margin = ["None"],
padding = ["None"],
shHeight = "auto",
Expand All @@ -92,7 +126,17 @@ export default function Flex({
children,
...rest
}: TProps) {
const flexBoxClass = useFlexBox(justifyContent, alignItems, direction, wrap);
const flexBoxClass = useFlexBox(
justifyContent,
alignContent,
alignItems,
alignSelf,
direction,
wrap,
grow,
noShrink,
basis,
);
const gapClass = useGap(gap);
const marginClass = useMargin(margin);
const paddingClass = usePadding(padding);
Expand Down
46 changes: 39 additions & 7 deletions src/components/layout/Flex/hooks/useFlexBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,65 @@ import { useFlexBoxClasses } from "@components/layout/Flex/styles";

import type {
TFlexDirection,
TFlexOption,
TFlexOptionContent,
TFlexOptionItems,
TFlexShrink,
TFlexGrow,
TFlexBasis,
TFlexWrap,
} from "@components/layout/Flex/types";

export default function useFlexBox(
justifyContent?: TFlexOption,
alignItems?: TFlexOption,
justifyContent?: TFlexOptionContent,
alignContent?: TFlexOptionContent,
alignItems?: TFlexOptionItems,
alignSelf?: TFlexOptionItems,
direction?: TFlexDirection,
wrap?: boolean,
wrap?: TFlexWrap,
grow?: TFlexGrow,
noShrink?: TFlexShrink,
basis?: TFlexBasis,
) {
const classes = useFlexBoxClasses();

const directionClass = direction
? classes[`${direction}Direction`]
: undefined;

const justifyContentClass = justifyContent
? classes[`${justifyContent}Content`]
? classes[`${justifyContent}JustifyContent`]
: undefined;

const alignContentClass = alignContent
? classes[`${alignContent}AlignContent`]
: undefined;

const alignItemsClass = alignItems
? classes[`${alignItems}Items`]
? classes[`${alignItems}AlignItems`]
: undefined;

const alignSelfClass = alignSelf
? classes[`${alignSelf}AlignSelf`]
: undefined;

const wrapClass = wrap ? classes.wrap : classes.nowrap;
const basisClass = basis ? classes[`${basis}Basis`] : undefined;

const growClass = grow ? classes.growOne : classes.growZero;
const shrinkClass = noShrink ? classes.shrinkZero : classes.shrinkOne;
const wrapClass = wrap
? (wrap === "reverse" && classes.wrapReverse) || classes.wrap
: classes.nowrap;

return mergeClasses(
classes.base,
directionClass,
justifyContentClass,
alignContentClass,
alignItemsClass,
alignSelfClass,
growClass,
shrinkClass,
basisClass,
wrapClass,
);
}
2 changes: 1 addition & 1 deletion src/components/layout/Flex/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Flex from "@components/layout/Flex/component";
import Flex from "@components/layout/Flex/func";

export default Flex;
124 changes: 107 additions & 17 deletions src/components/layout/Flex/styles/flexBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,97 @@ const useFlexBoxClasses = makeStyles({
columnDirection: {
flexDirection: "column",
},
rowReverseDirection: {
flexDirection: "row-reverse",
},
columnReverseDirection: {
flexDirection: "column-reverse",
},

// justify-content
centerContent: {
centerJustifyContent: {
justifyContent: "center",
},
startContent: {
startJustifyContent: {
justifyContent: "flex-start",
},
endContent: {
endJustifyContent: {
justifyContent: "flex-end",
},
spaceBetweenContent: {
spaceBetweenJustifyContent: {
justifyContent: "space-between",
},
spaceAroundContent: {
spaceAroundJustifyContent: {
justifyContent: "space-around",
},
spaceEvenlyContent: {
spaceEvenlyJustifyContent: {
justifyContent: "space-evenly",
},
stretchContent: {
stretchJustifyContent: {
justifyContent: "stretch",
},

// align-items
centerItems: {
autoAlignItems: {
alignItems: "auto",
},
centerAlignItems: {
alignItems: "center",
},
startItems: {
startAlignItems: {
alignItems: "flex-start",
},
endItems: {
endAlignItems: {
alignItems: "flex-end",
},
stretchItems: {
stretchAlignItems: {
alignItems: "stretch",
},
spaceBetweenItems: {
alignItems: "space-between",
baselineAlignItems: {
alignItems: "baseline",
},

// align-self
autoAlignSelf: {
alignSelf: "auto",
},
startAlignSelf: {
alignSelf: "flex-start",
},
endAlignSelf: {
alignSelf: "flex-end",
},
spaceAroundItems: {
alignItems: "space-around",
centerAlignSelf: {
alignSelf: "center",
},
spaceEvenlyItems: {
alignItems: "space-evenly",
stretchAlignSelf: {
alignSelf: "stretch",
},
baselineAlignSelf: {
alignSelf: "baseline",
},

// align-content
centerAlignContent: {
alignContent: "center",
},
startAlignContent: {
alignContent: "flex-start",
},
endAlignContent: {
alignContent: "flex-end",
},
stretchAlignContent: {
alignContent: "stretch",
},
spaceBetweenAlignContent: {
alignContent: "space-between",
},
spaceAroundAlignContent: {
alignContent: "space-around",
},
spaceEvenlyAlignContent: {
alignContent: "space-evenly",
},

// wrap
Expand All @@ -62,6 +110,48 @@ const useFlexBoxClasses = makeStyles({
nowrap: {
flexWrap: "nowrap",
},
wrapReverse: {
flexWrap: "wrap-reverse",
},

// grow
growOne: {
flexGrow: 1,
},
growZero: {
flexGrow: 0,
},

// shrink
shrinkOne: {
flexShrink: 1,
},
shrinkZero: {
flexShrink: 0,
},

// basis
autoBasis: {
flexBasis: "auto",
},
"0Basis": {
flexBasis: 0,
},
fillBasis: {
flexBasis: "fill",
},
maxContentBasis: {
flexBasis: "max-content",
},
minContentBasis: {
flexBasis: "min-content",
},
fitContentBasis: {
flexBasis: "fit-content",
},
contentBasis: {
flexBasis: "content",
},
});

export default useFlexBoxClasses;
Loading
Loading