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

mui-fields

v1.7.1

Published

MUI TextField kết hợp react-hook-form

Downloads

176

Readme

mui-fields

NPM JavaScript Style Guide Ví dụ

Install

npm install --save mui-fields
or
yarn add mui-fields

Usage

import renderFields from 'mui-fields'
renderFields(settings, useFormMethods)

settings: {fieldName: attributes}:

fieldName (string): Tên của trường.

attributes (object): thuộc tính của trường (extends tất cả thuộc tính của MUI TextField) // xem thêm https://material-ui.com/api/text-field/

useFormMethods:

các methods của useForm // xem ví dụ bên dưới


import React, { useState } from 'react'
import useForm from 'react-hook-form'

import renderFields from 'mui-fields'

export default function App() {
  const [formValues, setFormValues] = useState(null)
  const methods = useForm()

  const _renderFieds = () => {
    return renderFields({
      // MuiTextFieldsAttributes là các thuộc tính TextField của MUI,
      // xem thêm https://material-ui.com/api/text-field/
      fullName: { label: 'Họ và tên', value: 'Lê Thành', required: true, autoFocus: true },
      cmnd: { label: 'Số cmnd/thẻ căn cước', type: 'number', fullWidth: false },
      dob: { label: 'Ngày sinh', type: 'date', defaultValue: '2010-01-20', fullWidth: false },
      province: {
        label: 'Nơi ở hiện tại',
        select: true,
        selections: [{ code: 'HAN', name: 'Hà Nội' }, { code: 'SGN', name: 'HCM' }],
        mapKey: opt => opt.code,
        mapValue: opt => opt.code,
        mapLabel: opt => opt.name,
      },
      sothich: {
        isMultipleSelect: true,
        label: 'Sở thích',
        selections: ['lập trình', 'đọc sách báo', 'chụp ảnh', 'du lịch'],
        fullWidth: true
      },
      dev: {
        isMultipleSelect: true,
        label: 'Dev',
        selections: [
          {
            value: 'web',
            label: 'Web'
          },
          {
            value: 'mobile-app',
            label: 'Mobile App'
          },
          {
            value: 'AI',
            label: 'AI'
          },
          {
            value: 'block-chain',
            label: 'Block Chain'
          }
        ],
        mapKey: sel => sel.value,
        mapValue: sel => sel.value,
        mapLabel: sel => sel.label
      },
      isVietNamese: {
        label: 'Là người Việt Nam',
        checkbox: true // để render checkbox field
        , checked: true
        , fullWidth: true
      },

    }, methods)
  }
  const _onSubmit = (data) => {
    console.log(data)
    setFormValues(data)
  }
  return (
    <form onSubmit={methods.handleSubmit(_onSubmit)} style={{ margin: 20 }}>
      {_renderFieds()}
      <div>
        <button type={'submit'}>Submit</button>
      </div>
      {
        formValues && <pre>{JSON.stringify(formValues, null, 2)}</pre>
      }
    </form>
  )
}

API

Default: type = 'text'

  • isSelectBox (bool): render box lựa chọn các giá trị của trường values
  • select (bool): render box lựa chọn các giá trị của trường values
    • values (array): các giá trị (required)
    • value (any): giá trị hiện tại của box
    • mapKey (func): map giá trị cho key từ trường values
    • mapValue (func): map giá trị cho value từ trường values
    • mapLabel (func): map giá trị cho label từ trường values
    • onChangeValue (func): value => {/* tác vụ với giá trị mới (value)*/}
  • isCheckBox (bool): render check box
  • check (bool): render check box
  • checkbox (bool): render check box
    • checked (bool): giá trị hiện tại checked or unchecked
    • onChangeChecked (func): checked => {/* tác vụ với giá trị mới (checked)*/}
  • isSwitch (bool)
  • switch (bool)
    • như isCheckBox
  • isMultipleSelect (bool): render multiple select

Xem thêm react-hook-form tại https://github.com/react-hook-form/react-hook-form

License

MIT