components#PriceLabel TypeScript Examples

The following examples show how to use components#PriceLabel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProductCard.tsx    From Shopping-Cart with MIT License 5 votes vote down vote up
ProductCard: FC<PropTypes> = props => {
  const { Meta } = Card;
  const { id, title, coverImage, price } = props.product;
  const { onClick } = props;
  const [carted, setCarted] = useState<boolean>(false);

  useEffect(() => {
    if (storageService.checkCart(id)) {
      setCarted(true);
    }
  }, [onClick]);

  const handleIconClick = useCallback(
    (id: ProductModel['id']) => {
      onClick(id);
      if (storageService.checkCart(id)) {
        setCarted(true);
      } else {
        setCarted(false);
      }
    },
    [onClick],
  );

  return (
    <Card
      style={{ width: 320, marginBottom: 10 }}
      cover={
        <div style={{ overflow: 'hidden', width: 320, height: 180 }}>
          <img
            alt={title}
            src={coverImage}
            style={{ width: '100%', height: 'auto' }}
          />
        </div>
      }
      actions={[
        <span>
          <PriceLabel value={price} strong={true} />
        </span>,
        <span
          onClick={() => handleIconClick(id)}
          style={carted ? { color: '#1890ff', fontWeight: 'bold' } : {}}
        >
          <Icon
            type="shopping-cart"
            style={{
              fontSize: '20px',
              marginRight: '4px',
            }}
          />
          {carted ? '빼기' : '담기'}
        </span>,
      ]}
      hoverable={true}
    >
      <Tooltip placement="bottom" title={title}>
        <Meta title={title} />
      </Tooltip>
    </Card>
  );
}