Skip to content

A Web Component for generating input forms from OGraf/GDD schemas.

License

Notifications You must be signed in to change notification settings

SuperFlyTV/ograf-form

Repository files navigation

OGraf-form

NPM Version

This is a Web Component for generating input forms from OGraf/GDD schemas.

Getting Started

npm install ograf-form

Or you can use a CDN: https://cdn.jsdelivr.net/npm/ograf-form

Example usage

Example implementation

<!DOCTYPE html>
<html>
  <body>
    <script
      type="module"
      src="https://cdn.jsdelivr.net/npm/ograf-form"
    ></script>
    <!-- <script type="module" src="/dist/main.js"></script> -->

    <div id="form-container" style="width: 100vw">
      <superflytv-ograf-form
        id="ograf-form"
        schema='{"type":"object","properties":{"name":{"type":"string","gddType":"single-line","default":"John Doe","description":"This is the name of the thing"}}}'
      ></superflytv-ograf-form>
    </div>
    <div id="data" style="white-space: pre"></div>

    <script type="text/javascript">
      // Listen to changes:
      const form = document.getElementById("ograf-form");
      const dataDiv = document.getElementById("data");
      form.addEventListener("change", (e) => {
        console.log("Caught change event", e.target.value);
        // The change event is fired when a user changes a value in the form
        // It does NOT fire on each key stroke.
        // This is a good time to update our data object:
        dataDiv.innerHTML = JSON.stringify(e.target.value, null, 2);
      });
      form.addEventListener("keyup", (e) => {
        console.log("Caught keyup event", e.target.value);
      });
    </script>
  </body>
</html>

For Developers

# Install dependencies
yarn

# Start in dev mode
yarn dev

# Build for production
yarn build

# Bump release version (remember to push branch and tag)
yarn release

TODO

  • Support patternProperties, additionalProperties, unevaluatedProperties
  • Support tuples (prefixItems / items as array) & additionalItems

About

A Web Component for generating input forms from OGraf/GDD schemas.

Topics

Resources

License

Stars

Watchers

Forks

Languages