Skip to content

Commit

Permalink
Make the LargeButton title text style overridable
Browse files Browse the repository at this point in the history
  • Loading branch information
SjaakSchilperoort committed Nov 28, 2024
1 parent 17b4dc0 commit 9f81cbf
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@observation.org/react-native-components",
"version": "1.47.0",
"version": "1.48.0",
"main": "src/index.ts",
"repository": "[email protected]:observation/react-native-components.git",
"author": "Observation.org",
Expand Down
6 changes: 4 additions & 2 deletions src/components/LargeButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { StyleProp, StyleSheet, Text, TouchableOpacity, View, ViewStyle } from 'react-native'
import { StyleProp, StyleSheet, Text, TextStyle, TouchableOpacity, View, ViewStyle } from 'react-native'

import { Icon } from './Icon'
import { IconName } from '../lib/Icons'
Expand All @@ -11,6 +11,7 @@ import theme from '../styles/theme'

type LargeButtonProps = {
title: string
titleStyle?: StyleProp<TextStyle>
onPress?: () => void
onPressIn?: () => void
iconName?: IconName
Expand Down Expand Up @@ -52,6 +53,7 @@ const LargeButton = ({
danger,
style,
title,
titleStyle,
iconName,
onPress,
onPressIn,
Expand All @@ -74,7 +76,7 @@ const LargeButton = ({
<Icon name={iconName} size={theme.icon.size.large} color={iconColor} />
</View>
)}
<Text style={[styles.title, textStyle]}>{title}</Text>
<Text style={[styles.title, titleStyle, textStyle]}>{title}</Text>
</View>
</TouchableOpacity>
)
Expand Down
14 changes: 14 additions & 0 deletions src/components/__tests__/LargeButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'

import { fireEvent, render } from '@testing-library/react-native'

import appTextStyle from '../../styles/text'
import LargeButton from '../LargeButton'

const onPress = jest.fn()
Expand Down Expand Up @@ -52,6 +53,19 @@ describe('LargeButton', () => {
expect(toJSON()).toMatchSnapshot()
})

test('Rendering, with title style', () => {
const { toJSON } = render(
<LargeButton
iconName="info-circle"
title="Press me"
titleStyle={appTextStyle.subtitle}
onPress={onPress}
style={{ flex: 1 }}
/>,
)
expect(toJSON()).toMatchSnapshot()
})

test('Click', async () => {
const { getByTestId } = render(<LargeButton title="Press me" onPress={onPress} style={{ flex: 1 }} />)
await fireEvent.press(getByTestId('touchable-opacity'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ exports[`BottomSheet Rendering Only buttons 1`] = `
"lineHeight": 20,
"textAlignVertical": "center",
},
undefined,
{
"color": "#FFFFFF",
},
Expand Down Expand Up @@ -313,6 +314,7 @@ exports[`BottomSheet Rendering With button 1`] = `
"lineHeight": 20,
"textAlignVertical": "center",
},
undefined,
{
"color": "#FFFFFF",
},
Expand Down
107 changes: 107 additions & 0 deletions src/components/__tests__/__snapshots__/LargeButton.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ exports[`LargeButton Rendering, disabled, primary 1`] = `
"lineHeight": 20,
"textAlignVertical": "center",
},
undefined,
{
"color": "#FFFFFF",
},
Expand Down Expand Up @@ -142,6 +143,7 @@ exports[`LargeButton Rendering, disabled, secondary 1`] = `
"lineHeight": 20,
"textAlignVertical": "center",
},
undefined,
{
"color": "#E6E6E6",
},
Expand Down Expand Up @@ -218,6 +220,7 @@ exports[`LargeButton Rendering, enabled, primary 1`] = `
"lineHeight": 20,
"textAlignVertical": "center",
},
undefined,
{
"color": "#FFFFFF",
},
Expand Down Expand Up @@ -296,6 +299,7 @@ exports[`LargeButton Rendering, enabled, secondary 1`] = `
"lineHeight": 20,
"textAlignVertical": "center",
},
undefined,
{
"color": "#0066B1",
},
Expand Down Expand Up @@ -372,6 +376,7 @@ exports[`LargeButton Rendering, primary, danger 1`] = `
"lineHeight": 20,
"textAlignVertical": "center",
},
undefined,
{
"color": "#FFFFFF",
},
Expand Down Expand Up @@ -450,6 +455,7 @@ exports[`LargeButton Rendering, secondary, danger 1`] = `
"lineHeight": 20,
"textAlignVertical": "center",
},
undefined,
{
"color": "#EA554B",
},
Expand Down Expand Up @@ -526,6 +532,7 @@ exports[`LargeButton Rendering, secondary, danger, disabled => defaults to prima
"lineHeight": 20,
"textAlignVertical": "center",
},
undefined,
{
"color": "#FFFFFF",
},
Expand Down Expand Up @@ -617,6 +624,106 @@ exports[`LargeButton Rendering, with icon 1`] = `
"lineHeight": 20,
"textAlignVertical": "center",
},
undefined,
{
"color": "#FFFFFF",
},
]
}
>
Press me
</Text>
</View>
</View>
`;

exports[`LargeButton Rendering, with title style 1`] = `
<View
accessibilityState={
{
"busy": undefined,
"checked": undefined,
"disabled": undefined,
"expanded": undefined,
"selected": undefined,
}
}
accessibilityValue={
{
"max": undefined,
"min": undefined,
"now": undefined,
"text": undefined,
}
}
accessible={true}
collapsable={false}
focusable={true}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
{
"alignItems": "center",
"backgroundColor": "#0066B1",
"borderRadius": 4,
"flex": 1,
"height": 32,
"justifyContent": "center",
"margin": 16,
"opacity": 1,
"overflow": "hidden",
}
}
testID="touchable-opacity"
>
<View
style={
{
"flexDirection": "row",
"marginHorizontal": 16,
}
}
>
<View
style={
{
"justifyContent": "center",
"paddingRight": 8,
}
}
>
<Icon
color="#FFFFFF"
name="circle-info"
size={16}
type="light"
/>
</View>
<Text
style={
[
{
"color": "#212121",
"fontFamily": "Ubuntu",
"fontSize": 14,
"fontStyle": "normal",
"fontWeight": "bold",
"lineHeight": 20,
"textAlignVertical": "center",
},
{
"color": "#212121",
"fontFamily": "Ubuntu",
"fontSize": 16,
"fontStyle": "normal",
"fontWeight": "bold",
"lineHeight": 26,
},
{
"color": "#FFFFFF",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ exports[`NotificationPopup Rendering Left and right buttons 1`] = `
"lineHeight": 20,
"textAlignVertical": "center",
},
undefined,
{
"color": "#FFFFFF",
},
Expand Down Expand Up @@ -265,6 +266,7 @@ exports[`NotificationPopup Rendering Left and right buttons 1`] = `
"lineHeight": 20,
"textAlignVertical": "center",
},
undefined,
{
"color": "#FFFFFF",
},
Expand Down Expand Up @@ -467,6 +469,7 @@ exports[`NotificationPopup Rendering Only left button 1`] = `
"lineHeight": 20,
"textAlignVertical": "center",
},
undefined,
{
"color": "#FFFFFF",
},
Expand Down Expand Up @@ -719,6 +722,7 @@ exports[`NotificationPopup Rendering With close button 1`] = `
"lineHeight": 20,
"textAlignVertical": "center",
},
undefined,
{
"color": "#FFFFFF",
},
Expand Down Expand Up @@ -800,6 +804,7 @@ exports[`NotificationPopup Rendering With close button 1`] = `
"lineHeight": 20,
"textAlignVertical": "center",
},
undefined,
{
"color": "#FFFFFF",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ exports[`Tooltip Rendering With button 1`] = `
"lineHeight": 20,
"textAlignVertical": "center",
},
undefined,
{
"color": "#FFFFFF",
},
Expand Down

0 comments on commit 9f81cbf

Please sign in to comment.