import { TextInput } from '../ui/text-input'; import { NumberInput } from '../ui/number-input'; import { Switch } from '../ui/switch'; import { Select } from '../ui/select'; import { Combobox } from '../ui/combobox'; import { Option } from '@aiostreams/core'; import React from 'react'; import MarkdownLite from './markdown-lite'; import { Alert } from '../ui/alert'; import { SocialIcon } from './social-icon'; import { PasswordInput } from '../ui/password-input'; // this component, accepts an option and returns a component that renders the option. // string - TextInput // number - NumberInput // boolean - Checkbox // select - Select // multi-select - ComboBox // url - TextInput (with url validation) // Props for the template option component interface TemplateOptionProps { option: Option; value: any; disabled?: boolean; onChange: (value: any) => void; } const TemplateOption: React.FC = ({ option, value, onChange, disabled, }) => { const { id, name, description, type, required, options, constraints, forced, default: defaultValue, intent, socials, emptyIsUndefined = false, } = option; const isDisabled = disabled || !!forced; switch (type) { case 'socials': return (
{socials?.map((social) => ( ))}
); case 'alert': return ( {description}} /> ); case 'password': return (
onChange(emptyIsUndefined ? value || undefined : value) } required={required} disabled={isDisabled} /> {description && (
{description}
)}
); case 'string': return (
onChange(emptyIsUndefined ? value || undefined : value) } required={required} minLength={constraints?.min} maxLength={constraints?.max} disabled={isDisabled} /> {description && (
{description}
)}
); case 'number': return (
onChange(value) } required={required} step={constraints?.max ? constraints?.max / 100 : 1} disabled={isDisabled} /> {description && (
{description}
)}
); case 'boolean': return (
{name}
{description && (
{description}
)}
); case 'select': return (