@prosperitainova/dumbo-react-native
Version:
Dumbo for React Native Library
100 lines (98 loc) • 2.74 kB
JavaScript
;
import React from 'react';
import { StyleSheet, Pressable, View } from 'react-native';
import { getColor } from '../../styles/colors';
import { pressableFeedbackStyle, styleReferenceBreaker } from '../../helpers';
import { Text } from '../Text';
/** Props for DataTableCell component */
import { jsx as _jsx } from "react/jsx-runtime";
/**
* DataTableCell component for rendering a data table cell.
* Used as a child of DataTable
*
* {@link https://github.com/carbon-design-system/carbon-react-native/blob/main/example/src/Views/DataTable.tsx | Example code}
*/
export class DataTableCell extends React.Component {
get styles() {
const {
noPadding
} = this.props;
return StyleSheet.create({
wrapper: {
padding: noPadding ? 0 : 16,
paddingBottom: noPadding ? 0 : 15,
paddingTop: noPadding ? 0 : 15,
flex: 1,
justifyContent: 'center'
}
});
}
get content() {
const {
content,
type,
breakMode
} = this.props;
if (typeof content === 'string') {
switch (type) {
case 'header':
return /*#__PURE__*/_jsx(Text, {
type: "heading-compact-01",
text: content,
breakMode: breakMode || 'tail'
});
case 'default':
default:
return /*#__PURE__*/_jsx(Text, {
type: "body-compact-01",
text: content,
breakMode: breakMode || 'tail'
});
}
} else {
return content;
}
}
getStateStyle = state => {
return state.pressed ? {
backgroundColor: getColor('layerActive01')
} : undefined;
};
render() {
const {
componentProps,
style,
type,
onPress,
onLongPress,
cellText,
content,
width
} = this.props;
const finalStyles = styleReferenceBreaker(this.styles.wrapper, style);
if (type === 'header') {
finalStyles.backgroundColor = getColor('layerAccent01');
}
finalStyles.maxWidth = width;
const finalProps = {
...(componentProps || {}),
onPress: onPress,
onLongPress: onLongPress,
accessibilityLabel: cellText || typeof content === 'string' ? String(content) : undefined
};
if (typeof onPress === 'function' || typeof onLongPress === 'function') {
return /*#__PURE__*/_jsx(Pressable, {
...finalProps,
style: state => pressableFeedbackStyle(state, finalStyles, this.getStateStyle),
children: this.content
});
} else {
return /*#__PURE__*/_jsx(View, {
...finalProps,
style: finalStyles,
children: this.content
});
}
}
}
//# sourceMappingURL=DataTableCell.js.map