Skip to content

Commit

Permalink
feat(packages/ui): Spacing 컴포넌트
Browse files Browse the repository at this point in the history
  • Loading branch information
kongnayeon committed Jan 9, 2025
1 parent 8461f8b commit d4cb9b8
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"devDependencies": {
"@repo/eslint-config": "workspace:*",
"@repo/typescript-config": "workspace:*",
"@repo/ui": "workspace:*",
"@types/node": "^20.11.24",
"@types/react": "18.3.0",
"@types/react-dom": "18.3.1",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"dependencies": {
"@vanilla-extract/css": "^1.17.0",
"@vanilla-extract/dynamic": "^2.1.2",
"@vanilla-extract/recipes": "^0.5.5"
}
}
11 changes: 11 additions & 0 deletions packages/ui/src/components/Spacing/Spacing.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createVar, style } from '@vanilla-extract/css';

export const sizeVar = createVar();
export const directionVar = createVar();

export const spacingStyle = style({
display: 'flex',
flexDirection: directionVar,
width: sizeVar,
height: sizeVar,
});
37 changes: 37 additions & 0 deletions packages/ui/src/components/Spacing/Spacing.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { FC } from 'react';
import { tokens } from '@repo/theme';
import { directionVar, sizeVar, spacingStyle } from './Spacing.css';
import { assignInlineVars } from '@vanilla-extract/dynamic';

interface SpacingProps extends React.HTMLAttributes<HTMLDivElement> {
direction?: 'row' | 'column';
size: keyof typeof tokens.spacing;
}

export const Spacing: FC<SpacingProps> = ({
direction = 'column',
size,
...rest
}: SpacingProps) => {
const sizeValue =
direction === 'row'
? tokens.spacing[size]
: direction === 'column'
? tokens.spacing[size]
: 'auto';

return (
<div
className={spacingStyle}
style={JSON.parse(
JSON.stringify(
assignInlineVars({
[directionVar]: direction,
[sizeVar]: sizeValue,
})
)
)}
{...rest}
/>
);
};
2 changes: 1 addition & 1 deletion packages/ui/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
//export * from './TestComponent';
export * from './Spacing/Spacing';
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d4cb9b8

Please sign in to comment.