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.

1.3 KB
Raw Blame
import type { ResolvedValues } from '@platform/core/resolvedValues';
import type { SettingFieldProps } from '@platform/ui/settings/contracts';

import { SettingControl } from '@platform/ui/settings/SettingControl';
import { readBuiltIn, useLayeredSetting } from '@workbench/settings/useLayeredSetting';
import { useCallback } from 'react';

import { getPreviewComparisonMode, getPreviewFilmstripVisible } from './previewSettings';

export const Field = ({ field, surface, target }: SettingFieldProps) => {
  const read: (values: ResolvedValues) => boolean | string =
    field.id === 'comparisonMode' ? getPreviewComparisonMode : getPreviewFilmstripVisible;
  const { disabled, layer, set, value } = useLayeredSetting<boolean | string>(
    'preview',
    field.id,
    target,
    read,
    readBuiltIn(read),
    field
  );
  const onChange = useCallback(
    (next: boolean | string | number) => {
      if (field.id === 'comparisonMode' && (next === 'slider' || next === 'side-by-side' || next === 'hover')) {
        set(next);
      } else if (field.id === 'filmstripVisible' && typeof next === 'boolean') {
        set(next);
      }
    },
    [field.id, set]
  );
  return (
    <SettingControl
      layer={layer}
      disabled={disabled}
      field={field}
      surface={surface}
      value={value}
      onChange={onChange}
    />
  );
};