Skip to content
Snippets Groups Projects
animations.tsx 2.16 KiB
Newer Older
brunoravera's avatar
brunoravera committed
import React from 'react'
import { Animation, Pattern } from 'src/models'
import { animations, patterns } from '../patterns'
import {
  Table,
  TableCaption,
  TableContainer,
  Tbody,
  Td,
  Th,
  Text,
  Thead,
  Tooltip,
  Tr,
  HStack,
  IconButton,
  Icon,
} from '@chakra-ui/react'
import { FaPlay, FaTrash } from 'react-icons/fa'

const tableHeaders = ['Titulo', 'Descripcion', 'Fecha de creacion', '']

export type AnimationsProps = {
  patternId: Pattern['id']
}
export const Animations: React.FC<AnimationsProps> = ({ patternId }) => {
  const pattern = patterns.find((p) => p.id === patternId)
  const patternAnimations = animations.filter(
    (animation) => animation.patternId === patternId
  )

  if (!pattern || !patternAnimations) {
    return null
  }

  return (
    <TableContainer>
      <Table variant="simple" size="lg">
        <TableCaption>Animaciones disponibles de {pattern.title}</TableCaption>
        <Thead>
          <Tr>
            {tableHeaders.map((header, index) => (
              <Th key={`th-${index}`}>{header}</Th>
            ))}
          </Tr>
        </Thead>
        <Tbody>
          {patternAnimations.map((animation, index) => (
            <Tr key={`animation-${animation.title}-${index}`}>
              <Td>{animation.title}</Td>
              <Td>
                <Tooltip label={animation.description} hasArrow>
                  <Text isTruncated maxW="sm">
                    {animation.description}
                  </Text>
                </Tooltip>
              </Td>
              <Td>{new Date(animation.creationDate).toUTCString()}</Td>
              <Td>
                <ActionsRow _animation={animation} />
              </Td>
            </Tr>
          ))}
        </Tbody>
      </Table>
    </TableContainer>
  )
}

type ActionsRowProps = {
  _animation: Animation
}
const ActionsRow: React.FC<ActionsRowProps> = ({ _animation }) => {
  return (
    <HStack>
      <IconButton
        aria-label="view animation"
        variant="unstyled"
        icon={<Icon as={FaPlay} />}
      />
      <IconButton
        aria-label="delete animation"
        variant="unstyled"
        icon={<Icon as={FaTrash} />}
      />
    </HStack>
  )
}