Skip to content

Commit

Permalink
refactor : itemMap 객체에서 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
SeieunYoo committed Jul 28, 2024
1 parent 6ca0434 commit 6440016
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions packages/scripts/generateBuildConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const excludedComponents = [
"DropDownTrigger",
"DropDownWrapper",
"CollectionContext",
"DropDownOptionList",
];

const getFilteredComponentFiles = async (directoryPath: string) => {
Expand Down
7 changes: 4 additions & 3 deletions packages/wow-ui/src/components/DropDown/DropDownOption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { styled } from "@styled-system/jsx";
import type { ReactNode } from "react";
import { forwardRef, useCallback, useEffect } from "react";

import { useDropDownContext } from "../../components/DropDown/context/DropDownContext";
import { useDropDownContext } from "@/components/DropDown/context/DropDownContext";

import { useCollection } from "./context/CollectionContext";

/**
Expand Down Expand Up @@ -39,8 +40,8 @@ const DropDownOption = forwardRef<HTMLLIElement, DropDownOptionProps>(

useEffect(() => {
const currentItem = itemMap.get(value);
if (!currentItem || currentItem.text !== text) {
itemMap.set(value, { text });
if (!currentItem || currentItem !== text) {
itemMap.set(value, text);
}
}, [itemMap, value, text]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const DropDownOptionList = ({
updateFocusedValue(-1);
event.preventDefault();
} else if (key === "Enter" && focusedValue !== null) {
handleSelect(focusedValue, itemMap.get(focusedValue)?.text);
handleSelect(focusedValue, itemMap.get(focusedValue));
event.preventDefault();
}
},
Expand Down
7 changes: 4 additions & 3 deletions packages/wow-ui/src/components/DropDown/DropDownTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import type { KeyboardEvent } from "react";
import { cloneElement, useCallback } from "react";
import { DownArrow } from "wowds-icons";

import type { DropDownProps } from "../../components/DropDown";
import { useDropDownContext } from "../../components/DropDown/context/DropDownContext";
import type { DropDownProps } from "@/components/DropDown";
import { useDropDownContext } from "@/components/DropDown/context/DropDownContext";

import { useCollection } from "./context/CollectionContext";

interface DropDownTriggerProps {
Expand All @@ -27,7 +28,7 @@ const DropDownTrigger = ({
const { open, selectedValue, setOpen, setFocusedValue } =
useDropDownContext();

const selectedText = itemMap.get(selectedValue)?.text;
const selectedText = itemMap.get(selectedValue);

const toggleDropdown = useCallback(() => {
setOpen((prevOpen) => {
Expand Down
5 changes: 3 additions & 2 deletions packages/wow-ui/src/components/DropDown/DropDownWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Flex } from "@styled-system/jsx";
import { type PropsWithChildren, useCallback, useRef } from "react";

import type { DropDownProps } from "../../components/DropDown";
import useClickOutside from "../../hooks/useClickOutside";
import type { DropDownProps } from "@/components/DropDown";
import useClickOutside from "@/hooks/useClickOutside";

import { useDropDownContext } from "./context/DropDownContext";

interface DropDownWrapperProps extends PropsWithChildren {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { PropsWithChildren, ReactNode } from "react";
import { createContext, useMemo } from "react";

import useSafeContext from "../../../hooks/useSafeContext";
import useSafeContext from "@/hooks/useSafeContext";

type ItemData = {
value: string;
text: ReactNode;
};

type ContextValue = {
itemMap: Map<ItemData["value"], { text: ItemData["text"] }>;
itemMap: Map<ItemData["value"], ItemData["text"]>;
};

const CollectionContext = createContext<ContextValue | null>(null);
Expand All @@ -21,7 +21,7 @@ export const useCollectionContext = () => {

export const CollectionProvider = ({ children }: PropsWithChildren) => {
const itemMap = useMemo(
() => new Map<ItemData["value"], { text: ItemData["text"] }>(),
() => new Map<ItemData["value"], ItemData["text"]>(),
[]
);

Expand Down
9 changes: 5 additions & 4 deletions packages/wow-ui/src/components/DropDown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import type {
} from "react";
import { useId } from "react";

import { DropDownContext } from "../../components/DropDown/context/DropDownContext";
import { DropDownOptionList } from "../../components/DropDown/DropDownOptionList";
import DropDownTrigger from "../../components/DropDown/DropDownTrigger";
import useDropDownState from "../../hooks/useDropDownState";
import { DropDownContext } from "@/components/DropDown/context/DropDownContext";
import { DropDownOptionList } from "@/components/DropDown/DropDownOptionList";
import DropDownTrigger from "@/components/DropDown/DropDownTrigger";
import useDropDownState from "@/hooks/useDropDownState";

import { CollectionProvider } from "./context/CollectionContext";
import { DropDownWrapper } from "./DropDownWrapper";
export interface DropDownWithTriggerProps extends PropsWithChildren {
Expand Down

0 comments on commit 6440016

Please sign in to comment.