npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jsonforms/vue2-vanilla

v3.1.0

Published

Vue 2 Vanilla renderers for JSON Forms

Downloads

1,882

Readme

JSON Forms - More Forms. Less Code

Complex Forms in the blink of an eye

JSON Forms eliminates the tedious task of writing fully-featured forms by hand by leveraging the capabilities of JSON, JSON Schema and Javascript.

Vue 2 Vanilla Renderers

This is the JSON Forms Vue 2 Vanilla renderers package which provides a HTML5-based renderer set for JSON Forms Vue 2.

JSON Forms Vue 2 seed app

See our JSON Forms Vue seed repository to get started as quickly as possible. Make sure to switch to branch vue2.

Quick start

Install JSON Forms Core, Vue 2 and Vue 2 Vanilla Renderers.

npm i --save @jsonforms/core @jsonforms/vue2 @jsonforms/vue2-vanilla

Also add the packages to the transpile dependencies in the vue.config.js file:

module.exports = {
  transpileDependencies: [
    '@jsonforms/core',
    '@jsonforms/vue2',
    '@jsonforms/vue2-vanilla',
  ],
};

Use the json-forms component for each form you want to render and hand over the renderer set.

<script>
import { JsonForms } from '@jsonforms/vue2';
import { vanillaRenderers } from '@jsonforms/vue2-vanilla';
import { defineComponent } from 'vue';

const renderers = [
  ...vanillaRenderers,
  // here you can add custom renderers
];

const schema = {
  type: 'object',
  properties: {
    name: {
      type: 'string',
      minLength: 1,
    },
    done: {
      type: 'boolean',
    },
    due_date: {
      type: 'string',
      format: 'date',
    },
    recurrence: {
      type: 'string',
      enum: ['Never', 'Daily', 'Weekly', 'Monthly'],
    },
  },
  required: ['name', 'due_date'],
};

const uischema = {
  type: 'VerticalLayout',
  elements: [
    {
      type: 'Control',
      label: false,
      scope: '#/properties/done',
    },
    {
      type: 'Control',
      scope: '#/properties/name',
    },
    {
      type: 'HorizontalLayout',
      elements: [
        {
          type: 'Control',
          scope: '#/properties/due_date',
        },
        {
          type: 'Control',
          scope: '#/properties/recurrence',
        },
      ],
    },
  ],
};
const data = {};

export default defineComponent({
  name: 'app',
  components: {
    JsonForms,
  },
  data() {
    return {
      renderers: Object.freeze(renderers),
      data,
      schema,
      uischema,
    };
  },
  methods: {
    onChange(event) {
      this.data = event.data;
    },
  },
});
</script>
<template>
  <json-forms
    :data="data"
    :schema="schema"
    :uischema="uischema"
    :renderers="renderers"
    @change="onChange"
  />
</template>

By default the Vanilla Renderers don't apply any CSS at all. For a quick start you can use @jsonforms/vue-vanilla/vanilla.css.

For more information on how JSON Forms can be configured, please see the README of @jsonforms/vue2.

Styling

Each rendered HTML element specifies a CSS class which can be used to style it. This process can also be customized so that each element declares user-specified CSS classes. Therefore JSON Forms Vue Vanilla can be integrated with any CSS-only UI framework quite easily.

You can find the default CSS classes in `defaultStyles.ts.

To render your own classes simply provide them as styles. These styles replace the defaultStyles. If you want to fall back to defaultStyles or combine them with your own classes you'll need to do so programmatically, e.g.:

<script>
import { JsonForms } from '@jsonforms/vue2';
import {
  defaultStyles,
  mergeStyles,
  vanillaRenderers,
} from '@jsonforms/vue2-vanilla';
import { defineComponent } from 'vue';

const renderers = [
  ...vanillaRenderers,
  // here you can add custom renderers
];

// mergeStyles combines all classes from both styles definitions
const myStyles = mergeStyles(defaultStyles, {
  control: { root: 'my-control' },
});

export default defineComponent({
  name: 'app',
  components: {
    JsonForms,
  },
  data() {
    return {
      renderers: Object.freeze(renderers),
      data,
      schema,
      uischema,
    };
  },
  methods: {
    onChange(event) {
      this.data = event.data;
    },
  },
  provide() {
    return {
      styles: myStyles,
    };
  },
});
</script>
<template>
  <json-forms
    :data="data"
    :schema="schema"
    :uischema="uischema"
    :renderers="renderers"
    @change="onChange"
  />
</template>

You can also use specify styles in the ui schema via the options.styles property. Attributes specified here override the respective defaultStyles or provided styles. Attributes not specified here fall back to either the defaultStyles or provided styles.

{
  "type": "Control",
  "scope": "#/properties/name",
  "options": {
    "styles": {
      "control": {
        "root": "my-control-root"
      }
    }
  }
}

License

The JSONForms project is licensed under the MIT License. See the LICENSE file for more information.

Roadmap

Our current roadmap is available here.

Migration

See our migration guide when updating JSON Forms.