Skip to content

Commit

Permalink
Fixed types for CardsList
Browse files Browse the repository at this point in the history
  • Loading branch information
rafawendel committed Feb 25, 2021
1 parent b3361e5 commit 44c7184
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions client/app/components/cards-list/CardsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,28 @@ import PropTypes from "prop-types";
import React, { useState } from "react";
import Input from "antd/lib/input";
import EmptyState from "@/components/items-list/components/EmptyState";
import Button from "@/components/PlainButton";
import PlainButton from "@/components/PlainButton";
import Link from "@/components/Link";

import "./CardsList.less";

export interface CardsListItem {
interface BaseCardsListItem {
title: string;
imgSrc: string;
}

interface ButtonCardsListItem extends BaseCardsListItem {
onClick?: () => void;
href?: string;
href?: never;
}

interface LinkCardsListItem extends BaseCardsListItem {
href: string;
onClick?: never;
}

export type CardsListItem = ButtonCardsListItem | LinkCardsListItem;

export interface CardsListProps {
items?: CardsListItem[];
showSearch?: boolean;
Expand All @@ -25,10 +36,20 @@ interface ListItemProps {
}

function ListItem({ item, keySuffix }: ListItemProps) {
return (
<PlainButton key={`card${keySuffix}`} className="visual-card" onClick={item.onClick} href={item.href}>
const content = (
<>
<img alt={item.title} src={item.imgSrc} />
<h3>{item.title}</h3>
</>
);

return item.href ? (
<Link key={`card${keySuffix}`} className="visual-card" href={item.href}>
{content}
</Link>
) : (
<PlainButton key={`card${keySuffix}`} className="visual-card" onClick={item.onClick}>
{content}
</PlainButton>
);
}
Expand Down

0 comments on commit 44c7184

Please sign in to comment.