import React, { ComponentProps } from 'react';
import { GestureResponderEvent, StyleSheet, View } from 'react-native';
import { TouchableHighlight } from 'react-native';
import { Icon, SemanticColor, Typo, TypoIncludingEmoji } from '../../foundation';
import { ThrottleOptions, useThrottledPressHandler } from '../../internal/utils/useThrottledPressHandler';
import { isNotNil } from '../../internal/utils/functions';
type Props =
| {
/**
* ## 버튼 타입
*
* ### 'social_button'
* 소셜 로그인 버튼 타입입니다.
*
* ### 'social_link'
* 소셜 공유 버튼 타입입니다.
*/
type: unknown; // 실제 타입은 아래에 각각 정의돼있습니다.
onPress: (e: GestureResponderEvent) => void;
} & ThrottleOptions &
(
| {
type: 'social_button';
/**
* ## 로그인 할 플랫폼
* 'kakao' | 'naver' | 'apple'
*/
platformToLogin: LoginPlatformUnion; // (왜 속성명이 platform이 아닌가요? -> 버튼과 링크 타입의 플랫폼 string union 내용이 합쳐져 추론되는 문제를 해결하려고 속성명을 분리했습니다.)
/**
* ## 버튼 라벨 텍스트
* 기본값: "OOO로 시작하기"
*/
label?: string;
}
| {
type: 'social_link';
/**
* ## 공유할 플랫폼
* 'kakao' | 'facebook' | 'twitter' | 'share'
*/
platformToShare: SharePlatformUnion;
}
);
type LoginPlatformUnion = 'kakao' | 'naver' | 'apple';
type SharePlatformUnion = 'kakao' | 'facebook' | 'twitter' | 'share';
/**
* SocialButton 컴포넌트
*
* @public
*/
export function SocialButton(props: Props): React.JSX.Element {
const throttledPressHandler = useThrottledPressHandler(props.onPress, props.throttle);
switch (props.type) {
case 'social_button': {
return (
);
}
case 'social_link': {
return ;
}
}
}
// 외부 플랫폼 상징 색상이므로 프리즈마 시스템에 등록하지 않고 하드코딩하여 사용합니다.
/** @private */
const PLATFORM_BUTTON_COLOR: Record = {
kakao: {
enabled: '#FEE500',
pressed: '#E0C714',
},
naver: {
enabled: '#03C75A',
pressed: '#14A93C',
},
apple: {
enabled: '#000000',
pressed: '#404040',
},
};
/** @private */
function ButtonType(
props: Omit & { platformButton: LoginPlatformUnion; label?: string },
): React.JSX.Element {
const backgroundColor = PLATFORM_BUTTON_COLOR[props.platformButton].enabled;
const underlayColor = PLATFORM_BUTTON_COLOR[props.platformButton].pressed;
const iconName: ComponentProps['name'] = (() => {
switch (props.platformButton) {
case 'kakao':
return 'social_kakao_message';
case 'naver':
return 'social_naver';
case 'apple':
return 'social_apple';
}
})();
const { content, color }: { content: string; color: ComponentProps['color'] } = (() => {
switch (props.platformButton) {
case 'kakao':
return { content: '카카오로 시작하기', color: 'text_primary' };
case 'naver':
return { content: '네이버로 시작하기', color: 'text_white' };
case 'apple':
return { content: 'Apple로 시작하기', color: 'text_white' };
}
})();
return (
{isNotNil(props.label) ? props.label : content}
);
}
/** @private */
function LinkType(props: Omit & { platformLink: SharePlatformUnion }): React.JSX.Element {
const underlayColor = SemanticColor.bg_quinary;
const iconName: ComponentProps['name'] = (() => {
switch (props.platformLink) {
case 'kakao':
return 'social_kakao_message';
case 'facebook':
return 'social_facebook';
case 'twitter':
return 'social_twitter';
case 'share':
return 'link_outlined';
}
})();
return (
);
}
const buttonStyle = StyleSheet.create({
touchable: {
width: '100%', // 시스템 정의상 로그인 버튼은 화면 가로를 채우도록 디자인되었습니다.
paddingHorizontal: 16,
borderRadius: 8,
height: 48,
},
content: {
flex: 1,
flexDirection: 'row',
gap: 4,
justifyContent: 'center',
alignItems: 'center',
},
});
const linkStyle = StyleSheet.create({
touchable: {
borderRadius: Number.MAX_SAFE_INTEGER,
width: 40,
aspectRatio: 1,
padding: 8,
backgroundColor: SemanticColor.bg_tertiary,
},
});