mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-12-02 21:25:26 +09:00
35 lines
1.4 KiB
React
35 lines
1.4 KiB
React
import { useState } from 'react';
|
|
import { Star } from 'lucide-react';
|
|
import { cn } from '@/lib/utils';
|
|
import { isFavorite, toggleFavorite } from '@/utils/recents';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { Button as SharedButton } from '@/components/ui/button';
|
|
|
|
// Pin/unpin an entity as a favorite (surfaced in the command palette's
|
|
// Favorites section). Sits in detail-page title areas.
|
|
//
|
|
// <FavoriteStar type="service" id={service.id} path={`/services/${service.id}`} label={service.name} />
|
|
export function FavoriteStar({ type, id, path, label, className }) {
|
|
const { t } = useTranslation();
|
|
const [fav, setFav] = useState(() => isFavorite(type, id));
|
|
|
|
const toggle = () => {
|
|
setFav(toggleFavorite({ type, id, path, label }));
|
|
};
|
|
|
|
return (
|
|
<SharedButton variant="unstyled"
|
|
type="button"
|
|
className={cn('fav-star', fav && 'is-on', className)}
|
|
onClick={toggle}
|
|
title={fav ? t('app.favoriteStar.removeFromFavorites', 'Remove from favorites') : t('app.favoriteStar.addToFavorites', 'Add to favorites')}
|
|
aria-label={fav ? t('app.favoriteStar.removeFromFavorites', 'Remove from favorites') : t('app.favoriteStar.addToFavorites', 'Add to favorites')}
|
|
aria-pressed={fav}
|
|
>
|
|
<Star size={15} fill={fav ? 'currentColor' : 'none'} />
|
|
</SharedButton>
|
|
);
|
|
}
|
|
|
|
export default FavoriteStar;
|