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

LH-374/selection #22

Merged
merged 23 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f969979
feat(toggle): Toggle 컴포넌트 추가
baegofda Apr 25, 2023
b1ccdd6
fix(toggle): export 누락
baegofda Apr 25, 2023
385304a
feat(selectButton): SelectButton 컴포넌트 작업중
baegofda Apr 26, 2023
5456dd8
fix: inline-flex 수정
baegofda Apr 27, 2023
09d6b45
fix: 타입 수정
baegofda Apr 27, 2023
5add6fd
feat(selectButton): SelectButton 컴포넌트 추가
baegofda Apr 27, 2023
537dd52
fix: 불필요한 children 제거
baegofda Apr 27, 2023
06aaaba
feat(selectRadio): SelectRadio 컴포넌트 추가
baegofda Apr 28, 2023
0ca829d
feat(selectCheck): SelectCheck 컴포넌트 추가
baegofda May 2, 2023
b1a8c95
feat(selectCheckBox): SelectCheckBox 컴포넌트 추가
baegofda May 2, 2023
82f7e52
feat(dropdown): Dropdown 공통 컴포넌트 제작
baegofda May 3, 2023
c5854a9
fix(selectCheckBox): 스토리북 경로 수정
baegofda May 3, 2023
d2d9e86
fix(dropdown): 스타일 초기화
baegofda May 3, 2023
119e421
fix(dropdown): 불필요한 props 정리
baegofda May 4, 2023
4305ce4
feat(selectDropBox): SelectDropBox 컴포넌트 추가
baegofda May 4, 2023
af744e6
fix: 최대 높이 추가
baegofda May 4, 2023
56edb44
fix: 말줄임 추가
baegofda May 4, 2023
93bdbf1
fix: export 누락
baegofda May 4, 2023
89b8f06
fix: divider 색상 변경
baegofda May 4, 2023
adfe235
fix: 빌드 에러 수정
baegofda May 8, 2023
64e626a
fix: hover 추가
baegofda May 8, 2023
cc1f181
style: 빈줄 제거
baegofda May 8, 2023
9782ff3
fix: 코멘트 관련 수정
baegofda May 8, 2023
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 @@ -12,7 +12,7 @@ import {
export type Props = {
gap?: number;
type?: AccordionType;
items: React.ReactNode[];
items: typeof AccordionItem[];
};

export const AccordionContext = createContext<Omit<Props, "items">>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default {
"Accordion에 표시될 리스트 입니다. Accordion.Item를 사용합니다.",
table: {
type: {
summary: "React.ReactNode[]",
summary: "AccordionItem[]",
},
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TmTheme, createStyles } from "@travelmakers-design-v2/styles";
import { Props } from "./NewBadge";

const NEWBADGE_SIZE = {
const NEW_BADGE_SIZE = {
small: "28px",
medium: "34px",
};
Expand All @@ -14,7 +14,7 @@ export default createStyles((theme: TmTheme, { type }: Props) => {
display: "inline-flex",
alignItems: "center",
justifyContent: "center",
height: NEWBADGE_SIZE[type],
height: NEW_BADGE_SIZE[type],
padding: `0 ${spacing.spacing30}`,
backgroundColor: colors.secondary,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const BottomBar: BottomBarComponent & { displayName?: string } =
{
onClick,
initSelectedId = 0,
children,
component,
className,
overrideStyles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default createStyles((theme) => {

return {
root: {
display: "inline-flex",
display: "flex",
flexDirection: "column",
rowGap: spacing.spacing10,
margin: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,21 @@ export default {
} as Meta;

export const Default = (props) => {
return <Callout title={data.title} {...props} items={data.items} />;
return (
<div style={{ display: "inline-flex" }}>
<Callout title={data.title} {...props} items={data.items} />
</div>
);
};

export const CalloutWithoutItems = (props) => {
return (
<Callout
title={dataWithoutItems.title}
items={dataWithoutItems.items}
{...props}
/>
<div style={{ display: "inline-flex" }}>
<Callout
title={dataWithoutItems.title}
items={dataWithoutItems.items}
{...props}
/>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { PolymorphicRef } from "@travelmakers-design-v2/styles";
import { createContext, forwardRef, useEffect, useRef, useState } from "react";
import { View } from "../../View";
import { DropdownItem } from "../DropdownItem";
import { DropdownItems } from "../DropdownItems";
import { DropdownTrigger } from "../DropdownTrigger";
import {
DropdownComponent,
DropdownContextValue,
DropdownProps,
} from "./Dropdown.type";

export interface Props {
trigger: React.ReactNode;
content: React.ReactNode;
}

export const DropdownContext =
createContext<DropdownContextValue | undefined>(undefined);
DropdownContext.displayName = "DropdownContext";

export const Dropdown: DropdownComponent & {
displayName?: string;
Trigger?: typeof DropdownTrigger;
Items?: typeof DropdownItems;
Item?: typeof DropdownItem;
} = forwardRef(
<C extends React.ElementType = "div">(
{ trigger, content, className, ...props }: DropdownProps<C>,
ref: PolymorphicRef<C>
) => {
const divRef = useRef(ref || null);
const [isToggle, setIsToggle] = useState(false);

const onClickOutside = (e: MouseEvent) => {
const el = divRef.current;
if (!el || el.contains(e.target as Node)) return;

setIsToggle(false);
};

useEffect(() => {
document.addEventListener("click", onClickOutside);

return () => document.removeEventListener("click", onClickOutside);
}, []);

return (
<DropdownContext.Provider value={{ isToggle, setIsToggle }}>
<View<React.ElementType>
component={"div"}
ref={divRef}
className={className}
{...props}
>
{trigger}
{isToggle && content}
</View>
</DropdownContext.Provider>
);
}
);

Dropdown.displayName = "Dropdown";
Dropdown.Trigger = DropdownTrigger;
Dropdown.Items = DropdownItems;
Dropdown.Item = DropdownItem;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { PolymorphicComponentProps } from "@travelmakers-design-v2/styles";
import { Dispatch, SetStateAction } from "react";
import { Props } from "./Dropdown";

export type DropdownContextValue = {
isToggle: boolean;
setIsToggle: Dispatch<SetStateAction<boolean>>;
};

interface SharedDropdownProps extends Props {}

export type DropdownProps<C extends React.ElementType> =
PolymorphicComponentProps<C, SharedDropdownProps>;

export type DropdownComponent = <C extends React.ElementType = "div">(
props: DropdownProps<C>
) => React.ReactElement;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { Dropdown } from "./Dropdown";
export type { DropdownProps } from "./Dropdown.type";
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { PolymorphicRef } from "@travelmakers-design-v2/styles";
import { PropsWithChildren, forwardRef, useContext } from "react";
import { View } from "../../View";
import { DropdownContext } from "../Dropdown/Dropdown";
import { DropdownItemComponent, DropdownItemProps } from "./DropdownItem.type";

export interface Props {
ariaSelected: boolean;
}

export const DropdownItem: DropdownItemComponent & {
displayName?: string;
} = forwardRef(
<C extends React.ElementType = "li">(
{
ariaSelected,
onClick,
children,
...props
}: PropsWithChildren<DropdownItemProps<C>>,
ref: PolymorphicRef<C>
) => {
const { isToggle, setIsToggle } = useContext(DropdownContext);

const onClickHandler = () => {
setIsToggle(false);
onClick?.();
};

return (
<View<React.ElementType>
component={"li"}
ref={ref}
onClick={onClickHandler}
tabIndex={isToggle ? 0 : -1}
aria-selected={ariaSelected}
role="option"
{...props}
>
{children}
</View>
);
}
);

DropdownItem.displayName = "DropdownItem";
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { PolymorphicComponentProps } from "@travelmakers-design-v2/styles";
import { Props } from "./DropdownItem";

interface SharedDropdownItemProps extends Props {}

export type DropdownItemProps<C extends React.ElementType> =
PolymorphicComponentProps<C, SharedDropdownItemProps>;

export type DropdownItemComponent = <C extends React.ElementType = "li">(
props: DropdownItemProps<C>
) => React.ReactElement;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { DropdownItem } from "./DropdownItem";
export type { DropdownItemProps } from "./DropdownItem.type";
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createStyles } from "@travelmakers-design-v2/styles";

export default createStyles((theme) => {
return {
root: {
listStyle: "none",
margin: 0,
padding: 0,
},
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { PolymorphicRef } from "@travelmakers-design-v2/styles";
import { forwardRef } from "react";
import { View } from "../../View";
import useStyles from "./DropdownItems.style";
import {
DropdownItemsComponent,
DropdownItemsProps,
} from "./DropdownItems.type";

export interface Props {
items: React.ReactNode[];
}

export const DropdownItems: DropdownItemsComponent & {
displayName?: string;
} = forwardRef(
<C extends React.ElementType = "ul">(
{ items, className, ...props }: DropdownItemsProps<C>,
ref: PolymorphicRef<C>
) => {
const { classes, cx } = useStyles();

return (
<View<React.ElementType>
component={"ul"}
className={cx(classes.root, className)}
role="listbox"
ref={ref}
{...props}
>
{items}
</View>
);
}
);

DropdownItems.displayName = "DropdownItems";
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
ClassNames,
PolymorphicComponentProps,
TmComponentProps,
} from "@travelmakers-design-v2/styles";
import { Props } from "./DropdownItems";
import useStyles from "./DropdownItems.style";

type SelectDropBoxStylesNames = ClassNames<typeof useStyles>;

interface SharedDropdownItemsProps
extends Props,
TmComponentProps<SelectDropBoxStylesNames> {}

export type DropdownItemsProps<C extends React.ElementType> =
PolymorphicComponentProps<C, SharedDropdownItemsProps>;

export type DropdownItemsComponent = <C extends React.ElementType = "ul">(
props: DropdownItemsProps<C>
) => React.ReactElement;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { DropdownItems } from "./DropdownItems";
export type { DropdownItemsProps } from "./DropdownItems.type";
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createStyles } from "@travelmakers-design-v2/styles";

export default createStyles((theme) => {
const { colors } = theme;

return {
root: {
padding: 0,
backgroundColor: colors.transparent,
border: 0,
outline: 0,
cursor: "pointer",

"&:disabled": { cursor: "default" },
},
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { PolymorphicRef } from "@travelmakers-design-v2/styles";
import React, { forwardRef, useContext } from "react";
import { View } from "../../View";
import { DropdownContext } from "../Dropdown/Dropdown";
import useStyles from "./DropdownTrigger.style";
import {
DropdownTriggerComponent,
DropdownTriggerProps,
} from "./DropdownTrigger.type";

export interface Props extends React.HTMLAttributes<HTMLButtonElement> {
children:
| ((props: { isToggle: boolean }) => React.ReactNode)
| React.ReactNode;
}

export const DropdownTrigger: DropdownTriggerComponent & {
displayName?: string;
} = forwardRef(
<C extends React.ElementType = "button">(
{ onClick, className, children, ...props }: DropdownTriggerProps<C>,
ref: PolymorphicRef<C>
) => {
const { classes, cx } = useStyles();
const { isToggle, setIsToggle } = useContext(DropdownContext);

const _children =
typeof children === "function" ? children({ isToggle }) : children;

const onClickHandler = (e: React.MouseEvent<HTMLButtonElement>) => {
setIsToggle((v) => !v);
onClick?.(e);
};

return (
<View<React.ElementType>
component={"button"}
ref={ref}
className={cx(classes.root, className)}
onClick={onClickHandler}
aria-haspopup="listbox"
aria-expanded={isToggle}
{...props}
>
{_children}
</View>
);
}
);

DropdownTrigger.displayName = "DropdownTrigger";
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
ClassNames,
PolymorphicComponentProps,
TmComponentProps,
} from "@travelmakers-design-v2/styles";
import { Props } from "./DropdownTrigger";
import useStyles from "./DropdownTrigger.style";

type SelectDropBoxStylesNames = ClassNames<typeof useStyles>;

interface SharedDropdownTriggerProps
extends Props,
TmComponentProps<SelectDropBoxStylesNames> {}

export type DropdownTriggerProps<C extends React.ElementType> =
PolymorphicComponentProps<C, SharedDropdownTriggerProps>;

export type DropdownTriggerComponent = <C extends React.ElementType = "button">(
props: DropdownTriggerProps<C>
) => React.ReactElement;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { DropdownTrigger } from "./DropdownTrigger";
export type { DropdownTriggerProps } from "./DropdownTrigger.type";
Loading