Skip to content
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

feat: data table cell text style #1433

Closed
Closed
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
28 changes: 19 additions & 9 deletions src/components/DataTable/DataTableCell.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { StyleSheet, StyleProp, ViewStyle } from 'react-native';
import { StyleSheet, StyleProp, ViewStyle, TextStyle } from 'react-native';
import Text from '../Typography/Text';
import TouchableRipple from '../TouchableRipple';
import { $RemoveChildren } from '../../types';
Expand All @@ -18,20 +18,26 @@ type Props = $RemoveChildren<typeof TouchableRipple> & {
*/
onPress?: () => void;
style?: StyleProp<ViewStyle>;
/**
* Style of the text inside the cell
*/
textStyle?: StyleProp<TextStyle>;
};

class DataTableCell extends React.Component<Props> {
static displayName = 'DataTable.Cell';

render() {
const { children, style, numeric, ...rest } = this.props;
const { children, style, numeric, textStyle, ...rest } = this.props;

return (
<TouchableRipple
{...rest}
style={[styles.container, numeric && styles.right, style]}
>
<Text numberOfLines={1}>{children}</Text>
<TouchableRipple {...rest} style={[styles.container, style]}>
<Text
numberOfLines={1}
style={[styles.text, textStyle, numeric && styles.numeric]}
>
{children}
</Text>
</TouchableRipple>
);
}
Expand All @@ -44,8 +50,12 @@ const styles = StyleSheet.create({
alignItems: 'center',
},

right: {
justifyContent: 'flex-end',
numeric: {
textAlign: 'right',
},

Copy link
Collaborator

@wojteg1337 wojteg1337 Nov 14, 2019

Choose a reason for hiding this comment

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

remove extra lines between all styles

text: {
flex: 1,
},
});

Expand Down
22 changes: 16 additions & 6 deletions src/components/__tests__/__snapshots__/DataTable.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ exports[`renders data table cell 1`] = `
"flexDirection": "row",
},
undefined,
undefined,
],
]
}
Expand All @@ -35,7 +34,13 @@ exports[`renders data table cell 1`] = `
"fontWeight": "400",
"textAlign": "left",
},
null,
Array [
Object {
"flex": 1,
},
undefined,
undefined,
],
]
}
>
Expand Down Expand Up @@ -785,9 +790,6 @@ exports[`renders right aligned data table cell 1`] = `
"flex": 1,
"flexDirection": "row",
},
Object {
"justifyContent": "flex-end",
},
undefined,
],
]
Expand All @@ -803,7 +805,15 @@ exports[`renders right aligned data table cell 1`] = `
"fontWeight": "400",
"textAlign": "left",
},
null,
Array [
Object {
"flex": 1,
},
undefined,
Object {
"textAlign": "right",
},
],
]
}
>
Expand Down