-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/#6 drop down #7
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
Changes from all commits
83f196b
a6a3edf
6311b69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export * from "./select"; | ||
|
|
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ปดํฌ๋ํธ ๋ด ๋ค๋ฅธ ๋ถ๋ถ์์๋ ์ ์ง๋ณด์์ฑ๊ณผ ์ผ๊ด์ฑ์ ๋์ด๊ธฐ ์ํด
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| {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> | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| 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"; | ||
|
|
| 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; | ||
| }; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tokens.ts์global.styles.css์ ์์ ํ ํฐ์ด ๋ถ๋ฆฌ๋์ด ์์ด ๋ ํ์ผ ๊ฐ์ ๊ฐ์ด ๋ฌ๋ผ์ง ์ํ์ด ์์ต๋๋ค. ์ด๋ ์ฅ๊ธฐ์ ์ธ ์ ์ง๋ณด์์ฑ์ ์ ํดํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด, ํ์ชฝ ํ์ผ์ ๊ฐ๋ง ์์ ํ๋ฉด UI ๋ถ์ผ์น๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค.์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด, ๋์์ธ ํ ํฐ์ JSON์ด๋ YAML ๊ฐ์ ๋จ์ผ ์์ค ํ์ผ์์ ๊ด๋ฆฌํ๊ณ , ๋น๋ ์คํฌ๋ฆฝํธ๋ฅผ ํตํด
tokens.ts์ CSS ๋ณ์๋ฅผ ๋ชจ๋ ์์ฑํ๋ ๋ฐฉ์์ ๊ณ ๋ คํด๋ณด์๋ ๊ฒ์ ์ถ์ฒํฉ๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด ํ ํฐ ๊ฐ์ ์ผ๊ด์ฑ์ ๋ณด์ฅํ ์ ์์ต๋๋ค.