GithubHelp home page GithubHelp logo

mist-form's Introduction

<mist-form>

A web component that renders a form based on a JSONSchema & a UISchema specification.

This webcomponent follows the open-wc recommendations.

Installation

npm i @mistio/mist-form

Usage

Import mist-form

<script type="module">
  import '@mistio/mist-form/mist-form.js';
</script>

Add mist-form to the DOM, providing a JSON Schema document. You may also provide a UI Schema & the initial form data.

<mist-form .jsonSchema=${jsonSchema} .uiSchema=${uiSchema} .formData=${formData}>

</mist-form>

As an alternative, pass a url to the JSON Schema. The file may include the UI Schema & initial form data.

<mist-form method="POST" action="/api/v2/clouds"
  url="https://storage.googleapis.com/mist-api-spec/v2/master/mist-api-v2.json#/components/schemas/AddCloudRequest">
</mist-form>

Sample

Below is a sample html file that renders a simple form. Note the jsonSchema, uiSchema & formData objects that are passed to the form.

<!DOCTYPE html>
<html lang="en-US">
<body>
  <div id="bridgeOfDeath"></div>
  <script type="module">
    import { html, render } from 'lit-html';
    import '../../mist-form.js';

    const jsonSchema = {
        "title": "Bridge of death",
        "description": "Must answer me these questions three, 'ere the other side he see.",
        "type": "object",
        "required": [
          "name",
          "quest",
          "color",
          "velocity",
          "origin"
        ],
        "properties": {
          "name": {
            "type": "string",
            "title": "What is your name?"
          },
          "quest": {
            "type": "string",
            "title": "What is your quest?"
          },
          "color": {
            "type": "string",
            "title": "What is your favorite color?"
          },
          "capital": {
            "type": "string",
            "title": "What is the capital of Assyria?",
            "examples": ["Ashur", "Calah", "Nimrud", "Dur Sharrukin", "Khorsabad", "Nineveh"]
          },
          "velocity": {
            "type": "number",
            "title": "What is the air-speed velocity of an unladen swallow?",
            "minimum": 2,
            "maximum": 40
          },
          "origin": {
            "type": "string",
            "title": "Specify the swallow's origin",
            "enum": ["Africa", "Europe"]
          }
        }
      };
    const uiSchema = {
      "quest": {
        "ui:widget": "textarea"
      },
      "color": {
        "ui:widget": "color",
        "ui:options": {
          "style": "width: 190px;"
        }
      },
      "capital": {
        "ui:options": {
          "style": "min-width: 210px;"
        }
      },
      "velocity": {
        "ui:controls": true,
        "ui:suffix": "mph",
        "ui:options": {
          "style": "min-width: 350px;"
        }
      },
      "ui:submit": "Enter"
    };
    const formData = {
      "name": "Sir Lancelot of Camelot",
      "quest": "To seek the Holy Grail",
      "color": "#0000ff",
      "velocity": 24
    };

    render(
      html`
      <mist-form method="GET" action="/demo"
        .jsonSchema=${jsonSchema} .uiSchema=${uiSchema} .formData=${formData}
        @response=${() => {
          console.log('on response');
        }}
        @request=${() => {
          console.log('on request');
        }}
        @error=${() => {
          console.log('on error');
        }}
      </mist-form> `,
      document.querySelector('#bridgeOfDeath')
    );
  </script>
</body>
</html>

Linting with ESLint, Prettier, and Types

To scan the project for linting errors, run

npm run lint

You can lint with ESLint and Prettier individually as well

npm run lint:eslint
npm run lint:prettier

To automatically fix many linting errors, run

npm run format

You can format using ESLint and Prettier individually as well

npm run format:eslint
npm run format:prettier

Testing with Cypress

To run the suite of Cypress tests, run

npm run test:cypress

Tooling configs

For most of the tools, the configuration is in the package.json to reduce the amount of files in your project.

If you customize the configuration a lot, you can consider moving them to individual files.

Local Demo with es-dev-server

npm start

To run a local development server that serves the basic demo located in demo/index.html You can also see other form demos: demo/createVolume.html : Demo of the create volume form

Properties

Form properties

TODO

Field properties

TODO

Conditionals

TODO

Custom widgets

TODO

Styling

TODO

Supported json schema version

https://json-schema.org/draft/2019-09/schema

mist-form's People

Contributors

faysvas avatar d-mo avatar eis-d-z avatar

Stargazers

Mark avatar  avatar Manos Batsis avatar  avatar gparap avatar aristeakala avatar Veikko Eeva avatar Sam Clark avatar

Watchers

Dimitris Rozakis avatar Henry George Skupniewicz avatar  avatar

Forkers

devekkoio

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.