/** @module Survey Builder Configuration Panel Controls */ import { ColorScale } from '../color-scales'; import { SerializedQDSIcon } from '../icons'; import { Leaves } from '../nested-types'; /** * Representation of a non-generic section */ export interface AdditionalSectionConfig

= any> { /** * Text which appears above the control */ label: string; /** * A list of controls contained within the configuration panel section */ controls: Control[]; /** * An object for configuring logic for the control to conditionally appear. */ condition?: Conditions; /** * A boolean which declares whether the configuration panel section is expanded or collapsed by default */ isExpandedByDefault?: boolean; /** * The name of the section */ name?: string; /** * The tooltip popover text of the section */ tooltipText?: string; } export interface SingleValueBehaviorControl { behavior?: { /** * A callback function to be fired when the user interacts with the control */ action?: (value: T) => Promise; /** * A callback function for returning the current value of the control's associated property */ getPropertyValue?: () => Promise; }; } export interface SingleValueBehaviorControlWithValidation { behavior?: { /** * A callback function to be fired when the user interacts with the control * If validation is included on this control, this callback will not be fired until the input is valid */ action?: (value: T) => Promise; /** * A callback function for returning the current value of the control's associated property */ getPropertyValue?: () => Promise; /** * An optional object containing the information needed for validation */ validation?: { /** * The regex that will be used to validate the control's value on the client side. * If the control's value passes validation, the value will be saved and the action callback will be fired */ regex: string; }; }; } export interface NamedActionBehaviorControl { /** * A callback function to be fired when the user interacts with the control */ action: () => Promise; /** * A unique identifier string for the action */ actionName: string; } /** * A dropdown list control */ export interface DropdownControl> extends ControlWithOptions, SingleValueBehaviorControl { /** * This value indicates the type of control in use */ type: 'dropdown'; /** * This value indicates whether the dropdown menu supports multiple selections */ isMultiSelect?: false; } /** * A dropdown list control */ export interface MultiDropdownControl> extends ControlWithOptions, SingleValueBehaviorControl { /** * This value indicates the type of control in use */ type: 'dropdown'; /** * This value indicates whether the dropdown menu supports multiple selections */ isMultiSelect: true; } /** * A set of radio buttons */ export interface RadioControl> extends ControlWithOptions, SingleValueBehaviorControl { /** * This value indicates the type of control in use */ type: 'radio'; } /** * A toggle switch control */ export interface ToggleControl> extends BaseControl, SingleValueBehaviorControl { /** * This value indicates the type of control in use */ type: 'toggle'; /** * If declared, this list of controls will appear when the toggle is enabled. */ controls?: Control[]; } /** * A numeric text field with a minus (-) and plus (+) button on either side, which can be used to decrement or increment the value. */ export interface StepperControl> extends BaseControl, SingleValueBehaviorControl { /** * This value indicates the type of control in use */ type: 'stepper'; /** * The maximum allowed value */ max?: number; /** * A function for returning the maximum allowed value */ getMax?: () => Promise; /** * The minimum allowed value */ min?: number; /** * A function for returning the minimum allowed value */ getMin?: () => Promise; /** * The amount by which the value should increment or decrement. * For example, if `step` is `2`, then pressing `+` would increment a `10` value to `12` */ step?: number; /** * A function for validating the numeric value. * Return an error message if the value is invalid. * Return an empty string if the value is valid. */ getCustomError?: (val: number) => Promise; } /** * A button which fires a callback function when pressed */ export interface ButtonControl> extends BaseControl { /** * This value indicates the type of control in use */ type: 'button'; /** * A configuration object for defining the button's behavior */ behavior: NamedActionBehaviorControl; } /** * A button which fires a callback function when pressed. * It also displays an icon to the left of the button text. */ export interface TextIconButtonControl> extends BaseControl { /** * This value indicates the type of control in use */ type: 'textIconButton'; /** * A QDS icon serialized to a string. Icons can be found at https://designsystem.qualtrics.com/icon */ icon: SerializedQDSIcon; /** * A configuration object for defining the button's behavior */ behavior: NamedActionBehaviorControl; } /** * An informative element that just shows text and optionally an icon. */ export interface TextIconInfo> extends BaseControl { /** * This value indicates the type of control in use */ type: 'textIconInfo'; /** * Informative plain text to be shown */ label: string; /** * Optional: A QDS icon serialized to a string. Icons can be found at https://designsystem.qualtrics.com/icon */ icon?: SerializedQDSIcon; } /** * A text field control */ export interface TextFieldControl> extends BaseControl, SingleValueBehaviorControlWithValidation { /** * This value indicates the type of control in use */ type: 'textField'; /** * The type of text field to display */ textType?: 'number' | 'text' | 'password' | 'email' | 'tel' | 'url'; } /** * A checkbox control */ export interface CheckBoxControl> extends BaseControl, SingleValueBehaviorControl { /** * This value indicates the type of control in use */ type: 'checkBox'; } /** * A control containing two numeric text fields whose values together define a number range */ export interface NumberRangeControl> extends BaseControl { /** * This value indicates the type of control in use */ type: 'numberRange'; labels: { /** * The label for the left number field */ left: string; /** * The label for the right number field */ right: string; }; /** * A configuration object for defining the number range control's behavior */ behavior: { /** * A callback function to be fired when the user interacts with the control */ action?: (leftVal: number, rightVal: number) => Promise; /** * A callback function for validating the left and right values */ validation?: (leftVal: number, rightVal: number) => Promise<{ left: string | null; right: string | null; } | null>; /** * A callback function for returning the current value of the control's associated property */ getPropertyValue?: () => Promise<{ left: number; right: number; }>; }; } /** * A control for choosing text size */ export interface TextSizeControl> extends BaseControl, SingleValueBehaviorControl { /** * This value indicates the type of control in use */ type: 'textSize'; } /** * A control for choosing color schemes */ export interface ColorSchemeControl> extends BaseControl { /** * This value indicates the type of control in use */ type: 'colorScheme'; /** * A configuration object for defining the color scheme control's behavior */ behavior: { /** * A callback function to be fired when the user interacts with the control */ action: (newScale: ColorScale) => Promise; /** * A callback function for returning the current value of the control's associated property */ getPropertyValue: () => Promise<{ value: ColorScale; reversed: boolean; numOptions: number; }>; }; } /** * A control for creating strings which include piped text expressions */ export interface PipedTextControl> extends BaseControl, SingleValueBehaviorControl { /** * This value indicates the type of control in use */ type: 'pipedText'; /** * This value determines whether freeform text entry is allowed. If true, only a dropdown list of piped text options will be displayed, with no text entry field. */ disableTextEntry?: boolean; /** * The placeholder text to display when no selection has been made yet. */ placeholder?: string; /** * An object declaring which piped text sources to display. */ sources: { /** * If enabled, display question piped text sources */ question?: boolean; /** * If enabled, embedded data piped text sources */ embeddedData?: boolean; }; } /** * Representation of a single control. */ interface BaseControl> { /** * Text which appears above the control */ label?: string; /** * A string representing the json path where the property will be stored inside question.QuestionTypePluginProperties.AdditionalProperties. * The json path is represented by concatenating the keys together with the period "." character. For this reason, object keys with a period may misbehave. * * If your control overrides the action and getPropertyValue behaviors for this control, you will simply need to make this string something unique. */ property: K; /** * An object for configuring logic for the control to conditionally appear. */ condition?: Conditions; /** * An object for configuring logic for the control to conditionally be disabled. */ disableControl?: { /** * A callback function which returns `true` if the control should be disabled */ isDisabled: CustomConditionFunction; /** * A unique identifier string */ property: string; }; /** * Descriptor for the size, formatting, and indentation of the control and its labels. * L1 elements may contain L2 elements. L2 elements may contain L3 elements. L3 elements may contain L4 elements. */ elementType: 'l1' | 'l2' | 'l3' | 'l4'; } /** * A control for choosing a secure credential to use within your question * Note: the property value of this control will be stored as a key in the QuestionTypePluginProperties.Credentials object rather than in QuestionTypePluginProperties.AdditionalProperties. */ interface AuthenticationControl> extends BaseControl { type: 'authentication'; } export type CustomConditionFunction = () => Promise; /** * A union type of all possible configuration panel controls */ export type Control

= any> = DropdownControl | MultiDropdownControl | RadioControl | StepperControl | ButtonControl | TextIconButtonControl | TextIconInfo | ToggleControl | TextFieldControl | CheckBoxControl | NumberRangeControl | TextSizeControl | ColorSchemeControl | PipedTextControl | AuthenticationControl; /** * An array of all supported control types. Used for control sanitization. * Must manually append new controls to this list since TS does not * currently support instantiating an array from a union type. * Source: https://stackoverflow.com/a/45486495 */ export declare const supportedControlTypes: readonly ["button", "checkBox", "colorScheme", "dropdown", "numberRange", "pipedText", "radio", "stepper", "textField", "textIconButton", "textIconInfo", "textSize", "toggle", "authentication"]; export interface ControlWithOptions> extends BaseControl { options: Option[]; } /** * Representation of a single option for a control. */ export interface Option { /** * Text which appears for the option */ label: string; /** * The value associated with the option */ value: string; /** * An object for configuring logic for the option to conditionally appear. */ condition?: Conditions; } /** * This object can be configured to declare the conditions under which a component should appear. * The only supported mechanism right now is a callback function. */ export interface Conditions { custom: CustomConditionFunction; } export {}; //# sourceMappingURL=config-panel-controls.d.ts.map