Chip.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import * as React from 'react';
  2. import { Chip, withTheme } from 'react-native-paper';
  3. import { getColor } from '../Utils/ColorUtils';
  4. function MyChip(props) {
  5. const { children, size, last, onPress, outline } = props;
  6. let { color, fontColor } = props;
  7. if (!color) {
  8. color = getColor();
  9. }
  10. if (!fontColor) {
  11. fontColor = '#fff';
  12. }
  13. let chipHeight = 20;
  14. let fontSize = 12;
  15. let fontLine = 12;
  16. if (size === 'mini') {
  17. fontSize = 10;
  18. fontLine = 10;
  19. chipHeight = 16;
  20. }
  21. let right = 6;
  22. if (last) {
  23. right = 0;
  24. }
  25. let mode = 'flat';
  26. if (outline) {
  27. mode = 'outlined';
  28. }
  29. return (
  30. <Chip
  31. theme={{ colors: { text: outline ? color : fontColor } }}
  32. color={color}
  33. mode={mode}
  34. style={[
  35. {
  36. padding: 0,
  37. margin: 0,
  38. height: chipHeight,
  39. marginRight: right,
  40. marginBottom: 6,
  41. },
  42. !outline && { backgroundColor: color },
  43. outline && { borderColor: color },
  44. ]}
  45. textStyle={[
  46. {
  47. fontSize,
  48. margin: 0,
  49. padding: 0,
  50. lineHeight: fontLine,
  51. minHeight: fontLine,
  52. },
  53. ]}
  54. onPress={onPress}
  55. >
  56. {children}
  57. </Chip>
  58. );
  59. }
  60. export default withTheme(MyChip);