Skip to content

Single choice

This component is a simple component that prompts the user to select a single option among many.

PropertyValue
InteractivityRequired (fails otherwise)

Demo

A gif that shows the component in action. The developer uses the key strokes up and down arrows to move their selection

Demo of the toggleable filter mode

A gif that shows the component in action. The developer uses the key strokes up and down arrows to move their selection. They also type a few letters to filter the options

API

Example with a case iterable enum

swift
enum ProjectOption: String, CaseIterable, CustomStringConvertible {
    case createTuistProject
    case useExistingXcodeProjectOrWorkspace
    case continueWithoutProject

    var description: String {
        switch self {
        case .createTuistProject:
            return "Create a Tuist project"
        case .useExistingXcodeProjectOrWorkspace:
            return "Add it to an existing Xcode project or workspace"
        case .continueWithoutProject:
            return "Continue without integrating it into a project"
        }
    }
}

let selectedOption: ProjectOption = Noora().singleChoicePrompt(
    title: "Project",
    question: "Would you like to create a new Tuist project or use an existing Xcode project?",
    description: "Tuist extend the capabilities of your projects.",
    theme: NooraTheme.tuist()
)

Example with an Equatable and CustomStringConvertible type

swift
let selectedOption = Noora().singleChoicePrompt(
    title: "Project",
    question: "Would you like to create a new Tuist project or use an existing Xcode project?",
    options: [
        "Create a new project",
        "Use existing Xcode project"
    ]
    description: "Tuist extend the capabilities of your projects.",
    theme: NooraTheme.tuist()
)

Options

AttributeDescriptionRequiredDefault value
titleThe title of the prompt.No
questionThe question that the user will answer.Yes
descriptionA description that provides more context about the question.No
collapseOnSelectionWhether the prompt should collapse after the user selects an option.Notrue
filterModeWhether the list of options should be filterable.Nodisabled
autoselectSingleChoiceWhether the prompt should automatically select the first item when options only contains one item.Notrue

Released under the MIT License.