Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

1.4 KB
Raw Blame
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;