Skip to content

Commit

Permalink
fix: ref 타입 미정
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene028 committed Jun 7, 2024
1 parent 323e3ef commit a2da49d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
10 changes: 9 additions & 1 deletion packages/wow-ui/panda.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { defineConfig } from "@pandacss/dev";
import { defineConfig, defineGlobalStyles } from "@pandacss/dev";
import { semanticTokens, textStyles, tokens } from "theme";
import { removeUnusedCssVars, removeUnusedKeyframes } from "theme/utils";

const globalCss = defineGlobalStyles({
body: {
div: "border-box",
button: "border-box",
},
});

export default defineConfig({
globalCss,
preflight: true,
minify: true,
watch: true,
Expand Down
7 changes: 4 additions & 3 deletions packages/wow-ui/src/components/Chip/Chip.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,24 @@ type Story = StoryObj<typeof meta>;
export const Default: Story = {
args: {
label: "Chip",
as: "button",
element: "button",
clickable: true,
},
};

export const DivChip: Story = {
args: {
label: "Chip",
clickable: false,
as: "div",
element: "div",
},
};
export const DisabledChip: Story = {
args: {
label: "Chip",
clickable: true,
disabled: true,
as: "button",
element: "button",
},
};

Expand Down
32 changes: 17 additions & 15 deletions packages/wow-ui/src/components/Chip/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"use client";
import { cva } from "@styled-system/css";
import { styled } from "@styled-system/jsx";
import type { ElementType, ReactNode } from "react";
import type { ReactNode } from "react";
import { forwardRef, useEffect, useState } from "react";

import type {
ButtonElementType,
PolymorphicComponentProps,
PolymorphicRef,
ToggleButtonProps,
} from "@/types";
} from "../../types";

/**
* @template T 렌더링할 요소 또는 컴포넌트 타입
Expand All @@ -30,13 +31,13 @@ export interface _ChipProps extends ToggleButtonProps {
onDelete?: () => void;
}

export type ChipProps<C extends ElementType> = PolymorphicComponentProps<
export type ChipProps<C extends ButtonElementType> = PolymorphicComponentProps<
C,
_ChipProps
>;

type ChipComponent = <T extends ElementType = "button">(
props: ChipProps<T>
type ChipComponent = <T extends ButtonElementType = "button">(
props: ChipProps<T> & { ref?: PolymorphicRef<T> }
) => ReactNode;

const ChipLabel = ({
Expand All @@ -49,7 +50,7 @@ const ChipLabel = ({
disabled: boolean;
}) => {
return (
<styled.span
<styled.div
data-disabled={disabled}
data-selected={isChecked}
textStyle="label2"
Expand All @@ -58,14 +59,14 @@ const ChipLabel = ({
})}
>
{label}
</styled.span>
</styled.div>
);
};

const Chip: ChipComponent & { displayName?: string } = forwardRef(
<T extends ElementType = "button">(
<T extends ButtonElementType = "button">(
{
element,
as,
label,
clickable,
onKeyDown,
Expand All @@ -75,9 +76,9 @@ const Chip: ChipComponent & { displayName?: string } = forwardRef(
disabled = false,
...rest
}: ChipProps<T>,
ref: PolymorphicRef<T>
ref: any
) => {
const Component = element || "button";
const Component = as || "button";
const [isChecked, setIsChecked] = useState(() =>
checkedProp ? checkedProp : defaultChecked
);
Expand Down Expand Up @@ -106,16 +107,16 @@ const Chip: ChipComponent & { displayName?: string } = forwardRef(

return (
<Component
aria-label={`chip ${isChecked ? "activated" : "inactivated"}`}
data-selected={isChecked}
ref={ref}
style={rest.customStyle}
className={chip({
clickable: disabled ? false : clickable,
disabled: disabled,
})}
onClick={handleClick}
onKeyDown={handleKeyDown}
{...rest.customStyle}
aria-label={`chip ${isChecked ? "activated" : "inactivated"}`}
data-selected={isChecked}
>
<ChipLabel disabled={disabled} isChecked={isChecked} label={label} />
</Component>
Expand Down Expand Up @@ -155,7 +156,8 @@ const chip = cva({
minWidth: "3.5rem",
height: "1.875rem",
borderRadius: "1.25rem",
padding: "xs s",
paddingY: "xs",
paddingX: "sm",
},
variants: {
clickable: {
Expand Down
4 changes: 2 additions & 2 deletions packages/wow-ui/src/types/button.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { CSSProperties } from "react";
import type { CSSProperties, ElementType } from "react";

export type ButtonElementType = "button" | "div" | "span";
export type ButtonElementType = Extract<ElementType, "button" | "div" | "span">;

// 버튼의 주요한 HTML Attributes를 미리 정의한 ButtonProps 타입입니다. [https://www.w3schools.com/tags/tag_button.asp]

Expand Down

0 comments on commit a2da49d

Please sign in to comment.