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

@stateform/iview

v0.2.7

Published

StateForm implementation of iview

Downloads

23

Readme

StateForm implementation of iview@^3.0.0

Quick Start

import {createStateForm} from '@stateform/iview'
import "@stateform/iview/dist/stateform-iview.css"

const StateForm = createStateForm({
  upload: {
    handleUpload(file, props, cb) {
      // You should upload the file by yourself,
      // and call `cb` when the upload is completed
      cb({

        // "uploading" | "done" | "error"
        status: "done", 

        // By default, we will use the value of the `url` as the input value of this upload,
        // thus the outside world will only receive the url string.
        // If you want to input more infomation, you can set a `value` property, see below
        url: "http://xxxxx",

        // when error happened
        // error: "error message",
        
        // if there is an `value` property, we will use its value as the input value
        // value: {
        //  name: 'custom file name',
        //  url: 'http://xxxx'
        // }
      })
    },
    handleRemove(file) {
      // on file remove
    }
  },
  // components: customComponents
})

// now you can use StateForm as a component in vue 
// e.g., <StateForm :state="yourFormState" @input="inputHandler" @submit="submitHandler" />

Playground

Edit Vue Template

Install

npm install @stateform/iview  --save

vue and iview are peerDependencies

API

createStateForm

type createStateForm = (options?: StateFormOptions) => StateForm

interface StateFormOptions {
  // if you use Upload component, you should implement handleUpload and handleRemove 
  upload?: {
    handleUpload: (file: File, props: any, cb: UploadCallback) => void;
    handleRemove: (file: FileItem) => void;
  },
  // you are able to use custom components in StateForm
  components?: {
    [key: string]: Vue;
  }
}

type UploadCallback = (FileItem) => void;

interface FileItem {
  url: string;
  status: "uploading" | "done" | "error";
  thumbUrl?: undefined
  name?: string;
  error?: string;
  value?: any;
  uid?: string;
}

Example
see QuickStart

FormItemLayout

You can use this component in your custom component

interface FormItemLayoutProps {
  layout?: string;
  label?: string;
  cols?: StateForm.Cols;
  required?: boolean;
  className?: string;
  help?: string;
  error?: string;
  [key: string]: any;
}
interface FormItemLayout extends Vue {
}

Here is an example to define a custom component

<template>
  <FormItemLayout
    :layout="layout"
    :cols="cols"
    :label="label"
    :error="error"
    :required="required"
  >
    <Input
      :value="value"
      @input="$emit('input', $event)"
      :placeholder="placeholder"
    >
    </Input>
    <Button @click="sendCaptcha">Send</Button>
  </FormItemLayout>
</template>

<script>
import { Button , Input } from 'iview'
import { FormItemLayout } from '@stateform/iview'  
export default {
  components: {
    Button,
    Input,
    FormItemLayout
  },
  // Component will receive all props from the state node.
  // For example, below is the state object of the StateForm, 
  // then Captcha component will receive p1, p2 .... pn.
  // {
  //   // ....
  //   children: [
  //     // ....
  //     {
  //       component: 'Captcha',
  //       p1: '1',
  //       p2: '2',
  //       // ...
  //       pn: 'n'
  //     }
  //   ]
  // }
  methods: {
    sendCaptcha() {
      // ....
    }
  }
}
</script>

TODO

  • test

License

MIT