Skip to content
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"react": "19.1.0",
"react-dom": "19.1.0",
"react-native": "0.81.5",
"react-native-element-dropdown": "^2.12.4",
"react-native-gesture-handler": "~2.28.0",
"react-native-reanimated": "~4.1.1",
"react-native-safe-area-context": "~5.6.0",
Expand Down
34 changes: 34 additions & 0 deletions src/shared/styles/tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* RN style ๊ฐ์ฒด์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ํ† ํฐ ์ƒ์ˆ˜.
*
* NOTE:
* - React Native style์€ `var(--token)`์„ ์ง์ ‘ ํ•ด์„ํ•˜์ง€ ๋ชปํ•˜๋ฏ€๋กœ,
* `global.styles.css`์˜ ํ† ํฐ ๊ฐ’์„ ์—ฌ๊ธฐ์—๋„ "๋™์ผํ•œ ๊ฐ’"์œผ๋กœ ์œ ์ง€ํ•ฉ๋‹ˆ๋‹ค.
* - ๊ฐ’ ๋ณ€๊ฒฝ ์‹œ `global.styles.css`์™€ ํ•จ๊ป˜ ์ˆ˜์ •ํ•˜์„ธ์š”.
*/

export const colorTokens = {
/** global.styles.css: --color-primary (blue-500) */
primary: "#0068FE",
/** global.styles.css: --color-primary-tint (blue-100) */
primaryTint: "#E5F6FE",

/** global.styles.css: --color-neutral (gray-100) */
neutral: "#F4F4F5",
/** global.styles.css: --color-neutral-variant (gray-300) */
neutralVariant: "#DBDDE1",

/** global.styles.css: --color-canvas (white) */
canvas: "#FEFFFE",

/** global.styles.css: --color-danger (red-500) */
danger: "#FF6562",

/** global.styles.css: --color-content-primary (black) */
contentPrimary: "#040404",
/** global.styles.css: --color-content-secondary (gray-500) */
contentSecondary: "#8E9398",
/** global.styles.css: --color-content-inverse (blue-50) */
contentInverse: "#F4F6FE",
} as const;
Comment on lines +1 to +33

Choose a reason for hiding this comment

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

medium

tokens.ts์™€ global.styles.css์— ์ƒ‰์ƒ ํ† ํฐ์ด ๋ถ„๋ฆฌ๋˜์–ด ์žˆ์–ด ๋‘ ํŒŒ์ผ ๊ฐ„์˜ ๊ฐ’์ด ๋‹ฌ๋ผ์งˆ ์œ„ํ—˜์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” ์žฅ๊ธฐ์ ์ธ ์œ ์ง€๋ณด์ˆ˜์„ฑ์„ ์ €ํ•ดํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ํ•œ์ชฝ ํŒŒ์ผ์˜ ๊ฐ’๋งŒ ์ˆ˜์ •ํ•˜๋ฉด UI ๋ถˆ์ผ์น˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด, ๋””์ž์ธ ํ† ํฐ์„ JSON์ด๋‚˜ YAML ๊ฐ™์€ ๋‹จ์ผ ์†Œ์Šค ํŒŒ์ผ์—์„œ ๊ด€๋ฆฌํ•˜๊ณ , ๋นŒ๋“œ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ํ†ตํ•ด tokens.ts์™€ CSS ๋ณ€์ˆ˜๋ฅผ ๋ชจ๋‘ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ์‹์„ ๊ณ ๋ คํ•ด๋ณด์‹œ๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ํ† ํฐ ๊ฐ’์˜ ์ผ๊ด€์„ฑ์„ ๋ณด์žฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


2 changes: 2 additions & 0 deletions src/shared/ui/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./select";

158 changes: 158 additions & 0 deletions src/shared/ui/select/Select.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import { useMemo, useState } from "react";
import { Text, View } from "react-native";
import { Ionicons } from "@expo/vector-icons";
import { Dropdown } from "react-native-element-dropdown";

import type { SelectItem, SelectProps } from "./types";
import { colorTokens } from "@/shared/styles/tokens";
import { shadows } from "@/shared/styles/shadows";

const SIZES = {
sm: {
fieldPx: 12,
fieldPy: 10,
fontSize: 14,
},
md: {
fieldPx: 12,
fieldPy: 12,
fontSize: 16,
},
} as const;

export function Select({
items,
value,
onChange,
placeholder = "์„ ํƒ",
disabled = false,
label,
helperText,
errorText,
size = "md",
testID,
}: SelectProps) {
const sizeToken = SIZES[size];
const [isOpen, setIsOpen] = useState(false);

const dropdownData = useMemo(() => {
// react-native-element-dropdown์€ disabled key๊ฐ€ ์—†์–ด์„œ
// item ๋ Œ๋”๋ง/์„ ํƒ ๋กœ์ง์—์„œ ์ง์ ‘ ์ฒ˜๋ฆฌํ•œ๋‹ค.
return items;
}, [items]);
Comment on lines +38 to +42

Choose a reason for hiding this comment

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

medium

useMemo ํ›…์ด ์—ฌ๊ธฐ์„œ๋Š” ๋‹จ์ˆœํžˆ items prop์„ ๋ฐ˜ํ™˜ํ•˜๊ณ  ์žˆ์–ด ๋ฉ”๋ชจ์ด์ œ์ด์…˜์˜ ์ด์ ์ด ์—†์Šต๋‹ˆ๋‹ค. ์ฝ”๋“œ๋ฅผ ๋‹จ์ˆœํ™”ํ•˜๊ธฐ ์œ„ํ•ด useMemo๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  Dropdown ์ปดํฌ๋„ŒํŠธ์˜ data prop์— items๋ฅผ ์ง์ ‘ ์ „๋‹ฌํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. useMemo ๋‚ด์˜ ์ฃผ์„์€ ์œ ์šฉํ•˜์ง€๋งŒ, disabled ๋กœ์ง์ด ์‹ค์ œ๋กœ ์ฒ˜๋ฆฌ๋˜๋Š” onChange ํ•ธ๋“ค๋Ÿฌ ๊ทผ์ฒ˜๋กœ ์˜ฎ๊ธฐ๋Š” ๊ฒƒ์ด ๋” ์ ์ ˆํ•ด ๋ณด์ž…๋‹ˆ๋‹ค.

Copy link
Contributor

Choose a reason for hiding this comment

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

์ €ํฌ items๊ฐ€ ๋Œ€๋ถ€๋ถ„ ๊ณ ์ • ๋ฐ์ดํ„ฐ์ผ ๊ฑฐ ๊ฐ™์•„์„œ useMemo ๋ฆฌ๋ทฐ๋Š” ์ˆ˜์šฉํ•ด๋„ ๋  ๊ฑฐ ๊ฐ™๋„ค์š”! ๐Ÿ˜


return (
<View testID={testID}>
{!!label && (
<Text className="mb-2 font-regular text-content-primary color-content-secondary">
{label}
</Text>
)}

<Dropdown
data={dropdownData}
labelField="label"
valueField="value"
disable={disabled}
placeholder={placeholder}
value={value}
onFocus={() => setIsOpen(true)}
onBlur={() => setIsOpen(false)}
onChange={(item: SelectItem) => {
// disabled ํ•ญ๋ชฉ์€ ์„ ํƒ ๋ฌด์‹œ
if (item?.disabled) return;
onChange(item?.value ?? null);
}}
// NOTE: Dropdown์˜ `style`์€ ๋‚ด๋ถ€์—์„œ width๋ฅผ ์ธก์ •ํ•˜๋Š” ์ปจํ…Œ์ด๋„ˆ(View)์— ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.
// ๋”ฐ๋ผ์„œ ํ•„๋“œ UI(๋ณด๋”/ํŒจ๋”ฉ)๋ฅผ ์—ฌ๊ธฐ๋กœ ์˜ฎ๊ธฐ๋ฉด, ์˜ต์…˜ ๋ฆฌ์ŠคํŠธ ์ปจํ…Œ์ด๋„ˆ ํญ๋„ ํ•„๋“œ์™€ ๋™์ผํ•˜๊ฒŒ ๋งž์Šต๋‹ˆ๋‹ค.
style={{
...(isOpen
? {
borderTopLeftRadius: 12,
borderTopRightRadius: 12,
borderBottomLeftRadius: 0,
borderBottomRightRadius: 0,
borderBottomWidth: 2,
borderBottomColor: colorTokens.neutralVariant,
}
: {
borderRadius: 12,
}),
backgroundColor: colorTokens.neutral,
paddingHorizontal: sizeToken.fieldPx,
paddingVertical: sizeToken.fieldPy,
opacity: disabled ? 0.3 : 1,
}}
containerStyle={{
marginTop: -2,
borderBottomLeftRadius: 12,
borderBottomRightRadius: 12,
overflow: "hidden",
backgroundColor: colorTokens.neutral,
...shadows.neutral,
}}
itemContainerStyle={{
paddingHorizontal: 16,
paddingVertical: 14,
opacity: 1,
}}
// activeColor={colorTokens.primaryTint}
renderRightIcon={() => (
<Ionicons
name={isOpen ? "chevron-up" : "chevron-down"}
size={20}
color={colorTokens.contentPrimary}
/>
)}
placeholderStyle={{
fontFamily: "Pretendard-Regular",
fontSize: sizeToken.fontSize,
color: colorTokens.contentSecondary,
}}
selectedTextStyle={{
fontFamily: "Pretendard-Regular",
fontSize: sizeToken.fontSize,
color: colorTokens.contentPrimary,
}}
renderItem={(item: SelectItem) => {
const isSelected = item.value === value;

return (
<View
className="flex-row items-center justify-between"
>
<Text
style={{
fontFamily: "Pretendard-Regular",
fontSize: sizeToken.fontSize,
color: isSelected
? colorTokens.primary
: colorTokens.contentPrimary,
}}
>
{item.label}
</Text>
Comment on lines +124 to +134

Choose a reason for hiding this comment

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

medium

์ปดํฌ๋„ŒํŠธ ๋‚ด ๋‹ค๋ฅธ ๋ถ€๋ถ„์—์„œ๋Š” className์„ ์‚ฌ์šฉํ•˜์—ฌ ์Šคํƒ€์ผ์„ ์ ์šฉํ•˜๊ณ  ์žˆ์ง€๋งŒ, renderItem์˜ Text ์ปดํฌ๋„ŒํŠธ์—์„œ๋Š” ์ธ๋ผ์ธ style ๊ฐ์ฒด์™€ ํ•˜๋“œ์ฝ”๋”ฉ๋œ fontFamily๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Šคํƒ€์ผ๋ง ๋ฐฉ์‹์— ์ผ๊ด€์„ฑ์ด ๋ถ€์กฑํ•ฉ๋‹ˆ๋‹ค. placeholderStyle๊ณผ selectedTextStyle์—๋„ ๋™์ผํ•œ ๋ฌธ์ œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

์œ ์ง€๋ณด์ˆ˜์„ฑ๊ณผ ์ผ๊ด€์„ฑ์„ ๋†’์ด๊ธฐ ์œ„ํ•ด className์„ ์‚ฌ์šฉํ•˜๊ณ , ํฐํŠธ ์ด๋ฆ„ ํ•˜๋“œ์ฝ”๋”ฉ์„ ํ”ผํ•˜๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค. size prop์— ๋”ฐ๋ผ ๋™์ ์œผ๋กœ ํด๋ž˜์Šค๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Suggested change
<Text
style={{
fontFamily: "Pretendard-Regular",
fontSize: sizeToken.fontSize,
color: isSelected
? colorTokens.primary
: colorTokens.contentPrimary,
}}
>
{item.label}
</Text>
<Text
className={`font-regular ${
size === "sm" ? "text-sm" : "text-base"
} ${
isSelected
? "text-primary"
: "text-content-primary"
}`}
>
{item.label}
</Text>


{isSelected && (
<Ionicons
name="checkmark"
size={18}
color={colorTokens.primary}
/>
)}
</View>
);
}}
/>

{errorText ? (
<Text className="mt-2 text-danger font-regular">{errorText}</Text>
) : helperText ? (
<Text className="mt-2 text-content-secondary font-regular">
{helperText}
</Text>
) : null}
</View>
);
}

3 changes: 3 additions & 0 deletions src/shared/ui/select/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { Select } from "./Select";
export type { SelectItem, SelectProps, SelectSize } from "./types";

40 changes: 40 additions & 0 deletions src/shared/ui/select/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export type SelectItem = {
label: string;
value: string;
disabled?: boolean;
};

export type SelectSize = "sm" | "md";

export type SelectProps = {
/** ์˜ต์…˜ ๋ชฉ๋ก */
items: SelectItem[];

/** ์„ ํƒ๋œ ๊ฐ’ (์—†์œผ๋ฉด null) */
value: string | null;

/** ๊ฐ’ ๋ณ€๊ฒฝ ์ฝœ๋ฐฑ */
onChange: (value: string | null) => void;

/** placeholder ํ…์ŠคํŠธ */
placeholder?: string;

/** ๋น„ํ™œ์„ฑํ™” */
disabled?: boolean;

/** (์˜ต์…˜) ์ƒ๋‹จ ๋ผ๋ฒจ */
label?: string;

/** (์˜ต์…˜) ๋„์›€๋ง */
helperText?: string;

/** (์˜ต์…˜) ์—๋Ÿฌ ๋ฌธ๊ตฌ. ๊ฐ’์ด ์žˆ์œผ๋ฉด ์—๋Ÿฌ ์ƒํƒœ๋กœ ๋ Œ๋”๋ง */
errorText?: string;

/** ์‚ฌ์ด์ฆˆ */
size?: SelectSize;

/** ํ…Œ์ŠคํŠธ์šฉ id */
testID?: string;
};

12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4966,6 +4966,11 @@ lodash.throttle@^4.1.1:
resolved "https://registry.npmjs.org/lodash.throttle/-/lodash.throttle-4.1.1.tgz"
integrity sha512-wIkUCfVKpVsWo3JSZlc+8MB5it+2AN5W8J7YVMST30UrvcQNZ1Okbj+rbVniijTWE6FGYy4XJq/rHkas8qJMLQ==

lodash@^4.17.21:
version "4.17.23"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.23.tgz#f113b0378386103be4f6893388c73d0bde7f2c5a"
integrity sha512-LgVTMpQtIopCi79SJeDiP0TfWi5CNEc/L/aRdTh3yIvmZXTnheWpKjSZhnvMl8iXbC1tFg9gdHHDMLoV7CnG+w==

log-symbols@^2.2.0:
version "2.2.0"
resolved "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz"
Expand Down Expand Up @@ -5960,6 +5965,13 @@ react-native-css-interop@0.2.1:
lightningcss "~1.27.0"
semver "^7.6.3"

react-native-element-dropdown@^2.12.4:
version "2.12.4"
resolved "https://registry.yarnpkg.com/react-native-element-dropdown/-/react-native-element-dropdown-2.12.4.tgz#259db84e673b9f4fc03090a54760efd4f4a1456c"
integrity sha512-abZc5SVji9FIt7fjojRYrbuvp03CoeZJrgvezQoDoSOrpiTqkX69ix5m+j06W2AVncA0VWvbT+vCMam8SoVadw==
dependencies:
lodash "^4.17.21"

react-native-gesture-handler@~2.28.0:
version "2.28.0"
resolved "https://registry.npmjs.org/react-native-gesture-handler/-/react-native-gesture-handler-2.28.0.tgz"
Expand Down