smart-grid.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { Text } from 'app/design/typography'
  2. import { View } from 'app/design/view'
  3. import Image from 'app/ui/atoms/image';
  4. import { BlockWrapper } from 'app/components/block-wrapper'
  5. export default function ({ blockWrapperProps, data }) {
  6. const initedData = data.content.sm;
  7. return (
  8. <BlockWrapper {...blockWrapperProps}>
  9. <View className='w-full'>
  10. {initedData?.map(a =>(getCell(a)))}
  11. </View>
  12. </BlockWrapper>
  13. )
  14. }
  15. function getCell(block, bAllowEdit) {
  16. let blockContent;
  17. switch (block.type) {
  18. case "image":
  19. blockContent = <View className='w-full aspect-video'><Image view='cover' className=" u-cover " alt='' src={block.content} /></View>
  20. break;
  21. case "text":
  22. blockContent = <View className="py-2 px-4 items-start justify-start"><Text className='text-lg text-popover-foreground '>{block.content}</Text></View>;
  23. break;
  24. case "link":
  25. const ImageComponent = ({ className, src }) => (
  26. <Image view='cover' className={className} alt='' src={src} />
  27. );
  28. blockContent = block.content_data && (
  29. <View className={`items-left justify-between p-4 ${block.h == 1 && block.w == 2 ? 'flex-row' : ''}`}>
  30. <View className={block.h == 1 && block.w == 2 ? 'w-1/2' : ''}>
  31. <View className="h-8 w-8 rounded-full">
  32. <ImageComponent className="u-cover rounded-full" src={block.content_data.logo} />
  33. </View>
  34. <Text className=' text-base mt-2 font-semibold tracking-tight' numberOfLines={1}>{block.content_data.title}</Text>
  35. {(block.h > 1 || block.w > 1) && <Text className=' text-base my-2' numberOfLines={block.h == 1 && block.w == 2 ? 3 : 4}>{block.content_data.description}</Text>}
  36. <Text className='text-sm'>{block.content_data.domain}</Text>
  37. </View>
  38. <View className={`${block.h == 1 && block.w == 2 ? 'w-1/2 items-center justify-center pl-4' : 'w-full aspect-video rounded-2xl'}`}>
  39. <View className="aspect-video rounded-2xl w-full">
  40. <ImageComponent className="u-cover rounded-lg" src={block.content_data.image} />
  41. </View>
  42. </View>
  43. </View>
  44. );
  45. break;
  46. case "map":
  47. blockContent = <></>;//<Map height={100 * block.h} data={{ caption: block.content.content_state + ', ' + block.content.content_city + ', ' + block.content.content_street, location: { lat: block.content.content_lat, lng: block.content.content_lng } }} />
  48. break;
  49. default:
  50. blockContent = null;
  51. }
  52. return (
  53. <View key={block.i} className="mb-1 mx-1 shadow groupweb:duration-200 overflow-hidden bg-card">
  54. {blockContent}
  55. </View>
  56. );
  57. }