Badge.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import * as React from "react";
  2. import { useTheme, Text, Button } from "@ui-kitten/components";
  3. export default function Badge(props) {
  4. const theme = useTheme();
  5. const {status,appearance,style,children}=props
  6. const useColor = React.useMemo(() => {
  7. if (props.status) {
  8. return theme[`text-${ props.status }-color`];
  9. }
  10. return theme["text-danger-color"];
  11. }, [status]);
  12. if (appearance === "filled") {
  13. return (
  14. <Button
  15. appearance='badge'
  16. status={props.status || "primary"}
  17. style={{
  18. marginRight: props.right || 0,
  19. marginBottom: props.bottom || 0,
  20. flexShrink: 0,
  21. }}
  22. >
  23. {props.children}
  24. </Button>
  25. );
  26. }
  27. return (
  28. <Text
  29. category='h1'
  30. status={status || "danger"}
  31. style={[
  32. {
  33. borderWidth: appearance === "ghost" ? 0 : 1,
  34. borderRadius: 20,
  35. paddingHorizontal: appearance === "ghost" ? 0 : 3,
  36. borderColor: useColor,
  37. },
  38. style,
  39. ]}
  40. >
  41. {children}
  42. </Text>
  43. );
  44. }