All files / presentation/ui/src/places SavedPlacesList.tsx

100% Statements 4/4
100% Branches 5/5
100% Functions 4/4
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72                                                          12x     13x                           12x                       4x                          
import { Button, Card, CardBody, CardHeader } from "@wintermuted/ui-react";
import React from "react";
import { PlaceResultRow, type PlaceResultLinkProps } from "./PlaceResultRow";
import "./SavedPlacesList.scss";
 
export interface SavedPlaceItem {
  id: string;
  name: string;
  secondary?: React.ReactNode;
  icon?: React.ReactNode;
  renderLink: (props: PlaceResultLinkProps) => React.ReactNode;
}
 
export interface SavedPlacesListProps {
  places: readonly SavedPlaceItem[];
  onRemove: (id: string) => void;
  status?: React.ReactNode;
  emptyContent?: React.ReactNode;
  title?: string;
  removeLabel?: (place: SavedPlaceItem) => string;
  removeText?: string;
}
 
export function SavedPlacesList({
  places,
  onRemove,
  status,
  emptyContent,
  title = "Saved places",
  removeLabel = (place) => `Remove ${place.name} from saved places`,
  removeText = "Remove",
}: SavedPlacesListProps) {
  return (
    <Card>
      <CardHeader>
        <div className="bookmark-places-heading">
          <span>{title}</span>
          {status}
        </div>
      </CardHeader>
      <CardBody>
        {!places.length ? (
          emptyContent
        ) : (
          <ul className="bookmark-places-list" aria-label={title}>
            {places.map((place) => (
              <PlaceResultRow
                key={place.id}
                variant="saved"
                name={place.name}
                secondary={place.secondary}
                icon={place.icon}
                renderLink={place.renderLink}
                action={
                  <Button
                    size="sm"
                    variant="ghost"
                    aria-label={removeLabel(place)}
                    onClick={() => onRemove(place.id)}
                  >
                    {removeText}
                  </Button>
                }
              />
            ))}
          </ul>
        )}
      </CardBody>
    </Card>
  );
}