Code Monkey home page Code Monkey logo

easydialogs's Introduction

EasyDialogs

EasyDialogs simplifies the task of programmatically creating forms and input dialogs on macOS.

The focus is on ease of use for the developer rather than customization or beautiful controls. As such, the intended use is for the quick creation of internal tools rather than consumer applications. But don't let me stop you if that's your goal :-)

This library provides input dialogs for text, numbers, dropdown, multiple selection and more. All controls are intended to be created programmatically, i.e. without using interface builder.

The library offers two different approaches to asynchronicity: one based on closures (callbacks), and one based on futures.

Example

Example

To create a modal form window like the one seen in the screenshot, all you need is this code:

let nameInput = TextFieldInput<String>(
    label: "Name",
    validationRules: [Validation.NotEmptyString().any]
)

let ageInput = TextFieldInput<Int>(
    label: "Age",
    value: 18,
    validationRules: [Validation.Custom({$0 != nil && $0! >= 0 && $0! < 200}).any]
)

let colorInput = MultipleSelectionInput(
    label: "Favorite color",
    possibleValues: ["red", "blue", "yellow"]
)

FormWindow<(colors: String, name: String, age: Int)>.displayForm(
    inputs: [
        nameInput,
        ageInput,
        colorInput
    ],
    headerText: "Please tell me about yourself",
    validateValue: {
        let colors = colorInput.value!.isEmpty ? "no color" : colorInput.value!.joined(separator: ", ")
        guard let name = nameInput.value else { return nil }
        guard let age = ageInput.value else { return nil }
        return (colors: colors, name: name, age: age)
    },
    onConfirm: {
        print("\($0.name), age \($0.age), likes \($0.colors)")
    }
)

Documentation

Documentation can be found in the docs folder.

easydialogs's People

Contributors

lamar8 avatar marcoconti83 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.