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

[Fix] Box 컴포넌트의 text 스펙을 수정해요. #63

Merged
merged 42 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
360f575
feature: Box 컴포넌트 기본 세팅
eugene028 Jun 8, 2024
649a0b9
feature: RightIcon 추가
eugene028 Jun 8, 2024
ea24550
feature: storybook세팅
eugene028 Jun 8, 2024
23b4141
Merge branch 'main' into feature/box-component
eugene028 Jun 13, 2024
d01f964
fix: RightArrow 절대경로 수정
eugene028 Jun 13, 2024
1552e42
fix: 파이프라인 이름 수정
eugene028 Jun 19, 2024
89fc9ba
fix: panda config 수정
eugene028 Jun 19, 2024
800ee4d
fix: turbo 버전 조정
eugene028 Jun 19, 2024
3917c4b
fix: 상태관리 설정
eugene028 Jun 19, 2024
61f11f4
Merge branch 'main' into feature/box-component
eugene028 Jun 19, 2024
59c0280
fix: 스토리북 수정
eugene028 Jun 19, 2024
749bd72
fix: 스토리북 에러 수정
eugene028 Jun 19, 2024
63fb225
fix: storybook 문서화 추가
eugene028 Jun 20, 2024
a52a678
fix: 제네릭을 이용한 타입 정의
eugene028 Jun 20, 2024
89c7022
fix: p5 코드리뷰
eugene028 Jun 20, 2024
1bf23b5
fix: 제네릭 타입 깔끔하게 수정
eugene028 Jun 21, 2024
feabcea
fix: 코드리뷰 반영
eugene028 Jun 22, 2024
da94ee0
fix: 터보레포 버전 변경
eugene028 Jun 22, 2024
caaa341
fix: 파이프라인 수정
eugene028 Jun 22, 2024
9190473
fix: box props 네이밍 변경
eugene028 Jun 23, 2024
90c9573
feature: Box 컴포넌트 스펙 수정
eugene028 Jun 26, 2024
98aefc0
feature: Warn Icon 추가
eugene028 Jun 26, 2024
4d66913
Merge branch 'main' into feature/box-component
eugene028 Jun 26, 2024
df57819
fix: useCheckedState훅 두개로 분리
eugene028 Jun 26, 2024
e8131b2
fix: 개별 props 반영
eugene028 Jun 26, 2024
25c4395
fix: 개별 workflow 수정
eugene028 Jun 26, 2024
3ca4566
fix: workflow 수정
eugene028 Jun 26, 2024
68bac31
fix: workflow에 설치명 정확히 입력
eugene028 Jun 26, 2024
9d29df9
fix: 명령어 간단화
eugene028 Jun 26, 2024
2c273a6
fix: 워크플로우 수정
eugene028 Jun 27, 2024
fe6ba1e
fix: firefox 버전 확인
eugene028 Jun 27, 2024
62feccb
fix: 이것저것 시도하기
eugene028 Jun 27, 2024
be48955
fix : 워크플로우 수정
eugene028 Jun 27, 2024
98172ba
chore: playwright 패키지 설치
eugene028 Jun 27, 2024
1826f09
chore: Devdependency로 변경
eugene028 Jun 27, 2024
0cd64ea
fix: 코드리뷰 반영
eugene028 Jun 30, 2024
358eb36
Merge branch 'main' into feature/box-component
eugene028 Jun 30, 2024
1869ad7
fix: 배럴 파일 제거
eugene028 Jun 30, 2024
dae6491
fix: 경로 수정
eugene028 Jun 30, 2024
7484939
chore: playwright/test 패키지 설치
eugene028 Jun 30, 2024
eab22bf
fix: 찐 코드리뷰 마무리
eugene028 Jun 30, 2024
5d34fa5
Merge branch 'main' into feature/box-component
eugene028 Jun 30, 2024
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
3 changes: 2 additions & 1 deletion apps/wow-docs/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useState } from "react";
eugene028 marked this conversation as resolved.
Show resolved Hide resolved
import Checkbox from "wowds-ui/Checkbox";
import Chip from "wowds-ui/Chip";
import MultiGroup from "wowds-ui/MultiGroup";
Expand All @@ -16,7 +17,7 @@ const Home = () => {
<RadioButton label="2학년" value="2학년" />
</RadioGroup>
<MultiGroup variant="checkbox">
<Checkbox children="checkbox1" value="checkbox1" />
<Checkbox children="checkbox1" disabled={true} value="checkbox1" />
<Checkbox children="checkbox2" value="checkbox2" />
<Checkbox children="checkbox3" value="checkbox3" />
<Checkbox children="checkbox4" value="checkbox4" />
Expand Down
46 changes: 46 additions & 0 deletions packages/wow-icons/src/component/Warn.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { forwardRef } from "react";
import { color } from "wowds-tokens";

import type { IconProps } from "@/types/Icon.ts";

const Warn = forwardRef<SVGSVGElement, IconProps>(
(
{
className,
width = "24",
height = "25",
viewBox = "0 0 24 25",
stroke = "white",
fill = "white",
...rest
},
ref
) => {
return (
<svg
aria-label="warn icon"
className={className}
fill="none"
height={height}
ref={ref}
viewBox={viewBox}
width={width}
xmlns="http://www.w3.org/2000/svg"
{...rest}
>
<path
d="M21.3 12.5C21.3 17.6362 17.1362 21.8 12 21.8C6.86375 21.8 2.7 17.6362 2.7 12.5C2.7 7.36375 6.86375 3.2 12 3.2C17.1362 3.2 21.3 7.36375 21.3 12.5Z"
stroke={color[stroke]}
strokeWidth="1.4"
/>
<path
d="M12.766 6.81606L12.6566 14.9411H11.3441L11.2348 6.81606H12.766ZM12.0004 18.2223C11.4535 18.2223 10.9848 17.7692 11.0004 17.2067C10.9848 16.6598 11.4535 16.2067 12.0004 16.2067C12.5473 16.2067 13.0004 16.6598 13.0004 17.2067C13.0004 17.7692 12.5473 18.2223 12.0004 18.2223Z"
fill={color[fill]}
/>
</svg>
);
}
);

Warn.displayName = "Warn";
export default Warn;
1 change: 1 addition & 0 deletions packages/wow-icons/src/component/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as Check } from "./Check.tsx";
export { default as RightArrow } from "./RightArrow.tsx";
export { default as Warn } from "./Warn.tsx";
eugene028 marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions packages/wow-icons/src/svg/warn.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion packages/wow-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
"plop": "^4.0.1",
"rollup-plugin-peer-deps-external": "^2.2.4",
"storybook": "^8.1.9",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"@playwright/test": "^1.45.0"
eugene028 marked this conversation as resolved.
Show resolved Hide resolved
},
"dependencies": {
"wowds-icons": "workspace:^"
Expand Down
51 changes: 47 additions & 4 deletions packages/wow-ui/src/components/Box/Box.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, StoryObj } from "@storybook/react";
import { Flex, styled } from "@styled-system/jsx";
import { useState } from "react";

import Box from "@/components/Box";
Expand Down Expand Up @@ -26,8 +27,8 @@ const meta = {
},
variant: {
description: "박스의 타입을 설정합니다.",
mapping: ["text", "checkbox", "arrow"],
options: ["text", "checkbox", "arrow"],
mapping: ["text", "checkbox", "arrow", "warn"],
options: ["text", "checkbox", "arrow", "warn"],
control: {
type: "select",
labels: {
Expand All @@ -40,8 +41,8 @@ const meta = {
text: {
description: "박스에 메인으로 표기할 텍스트를 입력합니다.",
table: {
type: { summary: "string" },
defaultValue: { summary: "" },
type: { summary: "ReactNode" },
defaultValue: { summary: "{}" },
eugene028 marked this conversation as resolved.
Show resolved Hide resolved
},
control: {
type: "text",
Expand Down Expand Up @@ -201,6 +202,48 @@ export const LeftElementBox: Story = {
},
};

export const WarnBox: Story = {
args: {
text: "2024년 1학기 1차 정회원 지원 중이에요.",
subText: "정회원 가입 조건을 완료해주세요.",
status: "error",
variant: "warn",
},
};

export const TextReactElementBox: Story = {
args: {
text: (
<Flex direction="column" gap="sm">
<Flex align="center" direction="row" gap="xs">
<styled.span color="GrayText" textStyle="h3">
학번
</styled.span>
<styled.span color="textBlack">C000000</styled.span>
</Flex>
<Flex align="center" direction="row" gap="xs">
<styled.span color="GrayText" textStyle="h3">
학과
</styled.span>
<styled.span color="textBlack">컴퓨터공학과</styled.span>
</Flex>
<Flex align="center" direction="row" gap="xs">
<styled.span color="GrayText" textStyle="h3">
전화번호
</styled.span>
<styled.span color="textBlack">01000000000</styled.span>
</Flex>
<Flex align="center" direction="row" gap="xs">
<styled.span color="GrayText" textStyle="h3">
이메일
</styled.span>
<styled.span color="textBlack">[email protected]</styled.span>
</Flex>
</Flex>
),
},
};

const ControlledBox = () => {
const [checked, setChecked] = useState(false);

Expand Down
42 changes: 29 additions & 13 deletions packages/wow-ui/src/components/Box/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
import { cva } from "@styled-system/css";
import { Flex, styled } from "@styled-system/jsx";
import type { ColorToken } from "@styled-system/tokens";
import { RightArrow } from "wowds-icons";
import { RightArrow, Warn } from "wowds-icons";

import Checkbox from "@/components/Checkbox";
import { useCheckedState } from "@/hooks";

type BoxVariantType = "arrow" | "checkbox" | "text";
type BoxVariantType = "arrow" | "checkbox" | "text" | "warn";

export interface BoxProps<T extends BoxVariantType> {
variant?: T;
onClick?: T extends "arrow" ? () => void : never;
onChange?: T extends "checkbox" ? () => void : never;
checked?: T extends "checkbox" ? boolean : never;
leftElement?: React.ReactNode;
text: string;
text: React.ReactNode;
textColor?: ColorToken;
subText?: string;
subTextColor?: ColorToken;
Expand All @@ -31,7 +31,7 @@ export interface BoxProps<T extends BoxVariantType> {
* @param {string} [className] 체크박스에 전달하는 커스텀 클래스를 설정합니다.
* @param {string} [textColor] text의 색상을 변경할 수 있습니다.
* @param {"text" | "checkbox" | "arrow"} [variant] Box 컴포넌트의 타입을 설정합니다.
* @param {string} text Box 컴포넌트에 메인으로 표기할 텍스트를 입력합니다.
* @param {ReactNode} text Box 컴포넌트에 메인으로 표기할 텍스트를 입력합니다.
* @param {string} [subText] Box 컴포넌트에 작성할 추가 정보를 입력합니다.
* @param {string} [subTextColor] subtext의 색상을 변경할 수 있습니다.
* @param {"default" | "success" | "error"} [status] Box 컴포넌트를 통해 사용자의 상태를 반환합니다.
Expand All @@ -50,13 +50,13 @@ const Box = <T extends BoxVariantType = "text">({
status = "default",
onClick,
onChange,
style,
checked: checkedProp,
...rest
}: BoxProps<T>) => {
const { handleClick, checked } = useCheckedState({
checked: checkedProp,
onChange,
value: "checked",
});

const getStrokeColor = (status: "default" | "success" | "error") => {
Expand All @@ -74,6 +74,25 @@ const Box = <T extends BoxVariantType = "text">({
onClick();
}
};

const renderRightElement = (variant: BoxVariantType | undefined) => {
if (variant === "checkbox") {
return <Checkbox checked={checked} onClick={handleClick} />;
} else if (variant === "arrow") {
return (
<RightArrow height={20} stroke={getStrokeColor(status)} width={20} />
);
} else if (variant === "warn") {
return (
<Warn
fill={getStrokeColor(status)}
height={24}
stroke={getStrokeColor(status)}
width={24}
/>
);
} else return null;
};
eugene028 marked this conversation as resolved.
Show resolved Hide resolved
return (
<Flex
alignItems="center"
Expand All @@ -90,7 +109,7 @@ const Box = <T extends BoxVariantType = "text">({
<Flex direction="column" gap="xxs">
<styled.span
color={textColor ? textColor : "textBlack"}
textStyle="h3"
textStyle={typeof text === "string" ? "h3" : undefined}
eugene028 marked this conversation as resolved.
Show resolved Hide resolved
>
{text}
</styled.span>
Expand All @@ -102,13 +121,7 @@ const Box = <T extends BoxVariantType = "text">({
</styled.span>
</Flex>
</Flex>
<div>
{variant === "checkbox" ? (
<Checkbox checked={checked} onClick={handleClick} />
) : variant === "arrow" ? (
<RightArrow height={20} stroke={getStrokeColor(status)} width={20} />
) : null}
</div>
<div>{renderRightElement(variant)}</div>
</Flex>
);
};
Expand Down Expand Up @@ -151,6 +164,9 @@ const containerStyle = cva({
checkbox: {
cursor: "default",
},
warn: {
cursor: "default",
},
},
},
});
6 changes: 3 additions & 3 deletions packages/wow-ui/src/components/Checkbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
import { forwardRef, useId } from "react";
import { Check as CheckIcon } from "wowds-icons";

import { useCheckedState } from "@/hooks";
import { useGroupCheckedState } from "@/hooks";

/**
* @description 사용자가 선택하거나 선택 해제할 수 있는 체크박스 컴포넌트입니다.
Expand Down Expand Up @@ -77,7 +77,7 @@ const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
handleKeyUp,
handleMouseDown,
handleMouseUp,
} = useCheckedState({
} = useGroupCheckedState({
defaultChecked,
checked: checkedProp,
disabled: disabledProp,
Expand All @@ -86,7 +86,7 @@ const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
onClick,
onKeyDown,
});

console.log(checked);
eugene028 marked this conversation as resolved.
Show resolved Hide resolved
return (
<styled.label
alignItems="center"
Expand Down
4 changes: 2 additions & 2 deletions packages/wow-ui/src/components/Switch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Flex, styled } from "@styled-system/jsx";
import type { CSSProperties, InputHTMLAttributes, ReactNode } from "react";
import { forwardRef, useId } from "react";

import useCheckedState from "@/hooks/useCheckedState";
import { useGroupCheckedState } from "@/hooks";

/**
* @description on, off 두 가지 상태로 설정할 수 있는 스위치 컴포넌트입니다.
Expand Down Expand Up @@ -72,7 +72,7 @@ const Switch = forwardRef<HTMLInputElement, SwitchProps>(
handleKeyUp,
handleMouseUp,
handleMouseDown,
} = useCheckedState({
} = useGroupCheckedState({
defaultChecked,
checked: checkedProp,
disabled: disabledProp,
Expand Down
1 change: 1 addition & 0 deletions packages/wow-ui/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as useCheckedState } from "./useCheckedState";
export { default as useGroupCheckedState } from "./useGroupCheckedState";
eugene028 marked this conversation as resolved.
Show resolved Hide resolved
43 changes: 6 additions & 37 deletions packages/wow-ui/src/hooks/useCheckedState.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import type { KeyboardEvent } from "react";
import { useContext, useEffect, useState } from "react";

import MultiGroupContext from "@/components/MultiGroup/MultiGroupContext";
import { useEffect, useState } from "react";

interface CheckedStateProps {
defaultChecked?: boolean;
Expand All @@ -17,48 +15,21 @@ const useCheckedState = ({
defaultChecked = false,
checked: checkedProp,
disabled: disabledProp,
value,
onChange,
onClick,
onKeyDown,
}: CheckedStateProps) => {
const {
onChange: groupOnChange,
checked: groupCheckedValues,
disabled: groupDisabled,
} = useContext(MultiGroupContext);

const groupCheckedValue = groupCheckedValues?.includes(value);
const disabled = groupDisabled || disabledProp || false;
const disabled = disabledProp || false;

const [checkedValue, setCheckedValue] = useState<boolean>(
groupCheckedValue || checkedProp || defaultChecked
checkedProp || defaultChecked
);
const [pressed, setPressed] = useState<boolean>(false);

useEffect(() => {
if (groupCheckedValue !== undefined) {
setCheckedValue(groupCheckedValue);
}
}, [groupCheckedValue]);

useEffect(() => {
if (groupCheckedValue === undefined && checkedProp !== undefined) {
if (checkedProp) {
setCheckedValue(checkedProp);
}
}, [checkedProp, groupCheckedValue]);

const toggleCheckedState = (value: string) => {
if (disabled) return;

if (groupOnChange) {
groupOnChange(value);
} else if (onChange) {
onChange();
} else {
setCheckedValue((prev) => !prev);
}
};
}, [checkedProp]);
eugene028 marked this conversation as resolved.
Show resolved Hide resolved

const handleMouseDown = () => {
if (!disabled) setPressed(true);
Expand All @@ -68,8 +39,7 @@ const useCheckedState = ({
if (!disabled) setPressed(false);
};

const handleClick = (value: string) => {
toggleCheckedState(value);
const handleClick = () => {
eugene028 marked this conversation as resolved.
Show resolved Hide resolved
onClick?.();
};

Expand All @@ -83,7 +53,6 @@ const useCheckedState = ({
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
setPressed(true);
toggleCheckedState(value);
onKeyDown?.();
}
eugene028 marked this conversation as resolved.
Show resolved Hide resolved
};
Expand Down
Loading
Loading