Skip to content

Commit

Permalink
fix: Box
Browse files Browse the repository at this point in the history
  • Loading branch information
malangcat committed Jan 19, 2025
1 parent ca7aea9 commit da39b9d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 6 deletions.
69 changes: 63 additions & 6 deletions packages/react/src/components/Box/Box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,63 @@ function handleRadius(radius: string | undefined) {
return vars.$radius[radius] ?? undefined;
}

function handleDisplay(
display: "block" | "flex" | "inlineFlex" | "inline" | "inlineBlock" | "none" | undefined,
) {
if (!display) {
return undefined;
}

return {
block: "block",
flex: "flex",
inlineFlex: "inline-flex",
inline: "inline",
inlineBlock: "inline-block",
none: "none",
}[display];
}

function handleFlexDirection(flexDirection: string | undefined) {
if (!flexDirection) {
return undefined;
}

return {
row: "row",
column: "column",
rowReverse: "row-reverse",
columnReverse: "column-reverse",
}[flexDirection];
}

function handleJustifyContent(justifyContent: string | undefined) {
if (!justifyContent) {
return undefined;
}

return {
flexStart: "flex-start",
flexEnd: "flex-end",
center: "center",
spaceBetween: "space-between",
spaceAround: "space-around",
}[justifyContent];
}

function handleAlignItems(alignItems: string | undefined) {
if (!alignItems) {
return undefined;
}

return {
flexStart: "flex-start",
flexEnd: "flex-end",
center: "center",
stretch: "stretch",
}[alignItems];
}

export interface BoxProps extends React.HTMLAttributes<HTMLDivElement> {
as?: React.ElementType;

Expand Down Expand Up @@ -224,18 +281,18 @@ export const Box = React.forwardRef<HTMLDivElement, BoxProps>((props, ref) => {
"--seed-box-padding-bottom": handleDimension(paddingBottom),
"--seed-box-padding-left": handleDimension(paddingLeft),
"--seed-box-gap": handleDimension(gap),
"--seed-box-display": display,
"--seed-box-display": handleDisplay(display),
"--seed-box-position": position,
"--seed-box-overflow-x": overflowX,
"--seed-box-overflow-y": overflowY,
"--seed-box-flex-grow": flexGrow,
"--seed-box-flex-shrink": flexShrink,
"--seed-box-flex-direction": flexDirection,
"--seed-box-flex-direction": handleFlexDirection(flexDirection),
"--seed-box-flex-wrap": flexWrap,
"--seed-box-justify-content": justifyContent,
"--seed-box-align-items": alignItems,
"--seed-box-align-content": alignContent,
"--seed-box-align-self": alignSelf,
"--seed-box-justify-content": handleJustifyContent(justifyContent),
"--seed-box-align-items": handleAlignItems(alignItems),
"--seed-box-align-content": handleAlignItems(alignContent),
"--seed-box-align-self": handleAlignItems(alignSelf),
...style,
} as React.CSSProperties
}
Expand Down
2 changes: 2 additions & 0 deletions packages/stylesheet/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@
--seed-box-justify-content: initial;
--seed-box-align-items: stretch;
--seed-box-align-content: stretch;
--seed-box-align-self: auto;
--seed-box-gap: initial;
flex-direction: var(--seed-box-flex-direction);
flex-wrap: var(--seed-box-flex-wrap);
justify-content: var(--seed-box-justify-content);
align-items: var(--seed-box-align-items);
align-content: var(--seed-box-align-content);
align-self: var(--seed-box-align-self);
gap: var(--seed-box-gap);
}

Expand Down

0 comments on commit da39b9d

Please sign in to comment.