Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

2.7 KB
Raw Blame
/* eslint-disable react-perf/jsx-no-jsx-as-prop, react-perf/jsx-no-new-array-as-prop, react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-new-object-as-prop */
import type { StarterModelBundle } from '@features/models/core/types';
import type { ReactNode } from 'react';

import { Badge, Box, HStack, Icon } from '@chakra-ui/react';
import { Button } from '@platform/ui/Button';
import { Scrollable } from '@platform/ui/Scrollable';
import { CheckIcon, FolderIcon } from 'lucide-react';
import { useTranslation } from 'react-i18next';

export const BundleChips = ({
  bundles,
  onSelect,
  selectedName,
  starterCount,
  trailing,
}: {
  bundles: StarterModelBundle[];
  onSelect: (name: string | null) => void;
  selectedName: string | null;
  starterCount: number;
  trailing?: ReactNode;
}) => {
  const { t } = useTranslation();

  if (bundles.length === 0 && !trailing) {
    return null;
  }

  return (
    <HStack align="center" gap="2" minW="0" px="3" pb="1">
      {bundles.length > 0 ? (
        <Scrollable
          flex="1"
          label={t('models.launchpad.starterBundles')}
          minW="0"
          orientation="horizontal"
          variant="hover"
        >
          {/* The overlay scrollbar gets its own gutter (its size plus margins) so it never covers chips or badges. */}
          <HStack gap="1.5" pb="var(--scrollbar-click-area)">
            <BundleChip
              isSelected={selectedName === null}
              label={t('common.all')}
              subLabel={`${starterCount}`}
              onSelect={() => onSelect(null)}
            />
            {bundles.map((bundle) => {
              const missingCount = bundle.models.filter((model) => !model.is_installed).length;

              return (
                <BundleChip
                  key={bundle.name}
                  isComplete={missingCount === 0}
                  isSelected={selectedName === bundle.name}
                  label={bundle.name}
                  subLabel={`${bundle.models.length}`}
                  onSelect={() => onSelect(bundle.name)}
                />
              );
            })}
          </HStack>
        </Scrollable>
      ) : (
        <Box flex="1" minW="0" />
      )}
      {trailing}
    </HStack>
  );
};

const BundleChip = ({
  isComplete = false,
  isSelected,
  label,
  onSelect,
  subLabel,
}: {
  isComplete?: boolean;
  isSelected: boolean;
  label: string;
  onSelect: () => void;
  subLabel: string;
}) => (
  <Button flexShrink={0} variant={isSelected ? 'solid' : 'subtle'} onClick={onSelect}>
    <Icon as={isComplete ? CheckIcon : FolderIcon} boxSize="3" />
    {label}
    <Badge variant="surface" ms="1" me="-1">
      {subLabel}
    </Badge>
  </Button>
);