Skip to content
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

feat: AppBar 컴포넌트 #32

Merged
merged 4 commits into from
Jan 20, 2025
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
29 changes: 29 additions & 0 deletions src/ui/app-bar/app-bar-element.styles.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { RecipeVariants, recipe } from '@vanilla-extract/recipes';

export const appBarElement = recipe({
base: {
position: 'absolute',
width: 44,
height: '100%',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
},
variants: {
direction: {
left: {
top: 0,
left: 3,
},
right: {
top: 0,
right: 10,
},
},
},
});

export type AppBarElementVariant = Exclude<
RecipeVariants<typeof appBarElement>,
undefined
>;
19 changes: 19 additions & 0 deletions src/ui/app-bar/app-bar-element.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ComponentProps } from 'react';
import { cx } from '../util.ts';
import * as styles from './app-bar-element.styles.css.ts';

export type AppBarElementProps = ComponentProps<'div'> &
styles.AppBarElementVariant;

export const AppBarElement = (props: AppBarElementProps) => {
const { children, className, direction, ...restProps } = props;

return (
<div
{...restProps}
className={cx(styles.appBarElement({ direction }), className)}
>
{children}
</div>
);
};
55 changes: 55 additions & 0 deletions src/ui/app-bar/app-bar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import type { Meta, StoryObj } from '@storybook/react';
import { ArrowLeft, Cart, Logo } from '../../assets/index.ts';
import { AppBar } from './app-bar.tsx';

const meta: Meta<typeof AppBar> = {
title: 'ui/AppBar',
component: AppBar,
argTypes: {
variant: {
options: ['default', 'page'],
control: 'radio',
},
},
parameters: {
layout: 'fullScreen',
},
tags: ['autodocs'],
} satisfies Meta<typeof AppBar>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {
render: (args) => (
<AppBar {...args}>
<Logo />
</AppBar>
),
};

export const DefaultWithRight: Story = {
render: (args) => (
<AppBar {...args} right={<Cart />}>
<Logo />
</AppBar>
),
};

export const Page: Story = {
args: {
variant: 'page',
},
render: (args) => <AppBar {...args}>title</AppBar>,
};

export const PageWithElement: Story = {
args: {
variant: 'page',
},
render: (args) => (
<AppBar {...args} left={<ArrowLeft />} right={<Cart />}>
title
</AppBar>
),
};
34 changes: 34 additions & 0 deletions src/ui/app-bar/app-bar.styles.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { RecipeVariants, recipe } from '@vanilla-extract/recipes';
import { typography } from '../typography.css.ts';

export const appBar = recipe({
base: {
position: 'relative',
height: 44,
display: 'flex',
alignItems: 'center',
maxWidth: 440,
},
variants: {
variant: {
default: [
typography('title_1_22_b'),
{
padding: '0 10px 0 20px',
},
],
Comment on lines +5 to +19
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리뷰 보고 css 코드 보니까 px을 안붙여도 가능하네요. 동환님 방식이 더 편한거 같습니다.
padding: '0 10px 0 20px', padding 부분은 px을 붙여야지 작동하나요?

page: [
typography('head_1_18_sb'),
{
justifyContent: 'center',
padding: '0 10px 0 3px',
},
],
},
},
defaultVariants: {
variant: 'default',
},
});

export type AppBarVariants = RecipeVariants<typeof appBar>;
21 changes: 21 additions & 0 deletions src/ui/app-bar/app-bar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ComponentProps, PropsWithChildren, ReactNode } from 'react';
import { cx } from '../util.ts';
import { AppBarElement } from './app-bar-element.tsx';
import * as styles from './app-bar.styles.css.ts';

export type AppBarProps = ComponentProps<'div'> & {
left?: ReactNode;
right?: ReactNode;
} & styles.AppBarVariants;

export const AppBar = (props: PropsWithChildren<AppBarProps>) => {
const { left, right, children, variant, className, ...restProps } = props;

return (
<div {...restProps} className={cx(styles.appBar({ variant }), className)}>
{left && <AppBarElement direction="left">{left}</AppBarElement>}
{children}
{right && <AppBarElement direction="right">{right}</AppBarElement>}
</div>
Comment on lines +15 to +19
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left center right 별로 다 달라서 외부에서 주입하는 거 잘하신거 같아요. AppBarElement를 통해 재사용성을 높인 부분도 좋네요👍

);
};
2 changes: 2 additions & 0 deletions src/ui/app-bar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { AppBar, type AppBarProps } from './app-bar.tsx';
export { AppBarElement, type AppBarElementProps } from './app-bar-element.tsx';
Loading