Skip to content

Commit

Permalink
refactor: simplify variation & spacing declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
abelflopes committed Nov 2, 2023
1 parent f3701be commit 038a1c9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/components/all/src/container/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@ import React from "react";
import styles from "./index.module.scss";
import classNames from "classnames";

type ContainerVariation = "horizontal" | "vertical" | "small";
type ContainerVariation = "small";

interface ContainerProps extends React.HTMLAttributes<HTMLDivElement> {
export interface ContainerProps extends React.HTMLAttributes<HTMLDivElement> {
variation?: ContainerVariation | ContainerVariation[];
spacingX?: boolean;
spacingY?: boolean;
}

export const Container = ({
variation = "horizontal",
variation,
spacingX = true,
spacingY,
className,
...otherProps
}: Readonly<ContainerProps>): React.ReactElement => {
const computedVariations = Array.isArray(variation) ? variation : [variation];
const computedVariations =
Array.isArray(variation) || variation === undefined ? variation : [variation];

return (
<div
className={classNames(
styles.root,
{ [`${styles.horizontal}`]: spacingX, [`${styles.vertical}`]: spacingY },
computedVariations?.map((i) => styles[i]),
className,
computedVariations.map((i) => styles[i]),
)}
{...otherProps}
/>
Expand Down

0 comments on commit 038a1c9

Please sign in to comment.