import React from 'react'; import { Pressable, PressableProps, StyleProp, StyleSheet, Text, TextStyle, ViewStyle } from 'react-native'; import theme from '@/theme'; export type ButtonVariant = keyof typeof theme.buttons; export type ButtonProps = Omit & { /** primary is the orange call to action, secondary the beige one, as on neuf.no */ variant?: ButtonVariant; style?: StyleProp; /** Applies when children is a string */ textStyle?: StyleProp; icon?: React.ReactNode; fullWidth?: boolean; small?: boolean; children?: React.ReactNode; }; const Button = ({ variant = 'secondary', style, textStyle, icon, fullWidth, small, disabled, children, ...rest }: ButtonProps) => { const colors = theme.buttons[variant]; return ( [ styles.base, { backgroundColor: colors.background }, small && styles.small, fullWidth && styles.fullWidth, style, pressed && styles.pressed, disabled && styles.disabled, ]} {...rest} > {icon} {typeof children === 'string' ? ( {children} ) : ( children )} ); }; const styles = StyleSheet.create({ base: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 8, paddingVertical: 12, paddingHorizontal: 20, borderRadius: 999, }, small: { paddingVertical: 6, paddingHorizontal: 14, }, fullWidth: { alignSelf: 'stretch', }, pressed: { opacity: 0.8, }, disabled: { opacity: 0.6, }, text: { fontSize: 16, fontWeight: '500', }, textSmall: { fontSize: 14, }, }); export default Button;