card.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import styled from '@emotion/styled';
  2. import capitalize from 'lodash/capitalize';
  3. import Button from 'app/components/button';
  4. import {IconEdit, IconLock} from 'app/icons';
  5. import {t} from 'app/locale';
  6. import space from 'app/styles/space';
  7. type Props = {
  8. data: Record<string, any>;
  9. onDelete: () => void;
  10. };
  11. function Card({data, onDelete}: Props) {
  12. return (
  13. <Wrapper>
  14. <IconWrapper>
  15. <IconLock size="lg" />
  16. </IconWrapper>
  17. <Content>
  18. {Object.entries(data).map(([key, value]) => {
  19. if (!value) {
  20. return undefined;
  21. }
  22. const label = key
  23. .split(/(?<=[a-z])(?=[A-Z])/)
  24. .map(splittedKey => capitalize(splittedKey))
  25. .join(' ');
  26. return (
  27. <ContentItem key={key}>
  28. <strong>{`${label}:`}</strong>
  29. <span>{value}</span>
  30. </ContentItem>
  31. );
  32. })}
  33. </Content>
  34. <div>
  35. <Button icon={<IconEdit />} label={t('Edit')} size="small" onClick={onDelete} />
  36. </div>
  37. </Wrapper>
  38. );
  39. }
  40. export default Card;
  41. const Wrapper = styled('div')`
  42. display: grid;
  43. grid-template-columns: max-content 1fr max-content;
  44. grid-gap: ${space(1)};
  45. `;
  46. const Content = styled('div')`
  47. display: flex;
  48. justify-content: center;
  49. flex-direction: column;
  50. `;
  51. const IconWrapper = styled('div')`
  52. display: flex;
  53. align-items: center;
  54. padding: 0 ${space(1.5)};
  55. `;
  56. const ContentItem = styled(Wrapper)`
  57. font-size: ${p => p.theme.fontSizeMedium};
  58. `;