Coder Social home page Coder Social logo

emgk / guten-block-fields Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 1.0 102 KB

Create Gutenberg block's toolbar <InspectorControls />

Home Page: https://www.npmjs.com/package/guten-block-fields

License: MIT License

JavaScript 95.83% PHP 1.62% CSS 2.55%
gutenberg gutenberg-blocks gutenberg-metadata fields wordpress npm-package

guten-block-fields's Introduction

Guten Block Fields

WordPress Gutenberg development tool.

NPM version npm GitHub stars

When you creating blocks in Gutenberg, You may want more fields to manage the block's content. Gutenberg has a section called Inspector Controller which appears on the right side of the block when you click on particular block on editor. This package will help you to create those field in more easy way.

Install

$ npm install guten-block-fields

Usage

$ guten-block-fields make 

Documentation

Click Here to see documentation.

Video Demo

Click Here To watch the video demo.

Create fields

To create or manage block's field you'll need to create a block-fields.json file in your plugin's root folder.

A block-fields.json file:

  • list the block's field and manage them anytime.
  • makes your field reproducible, and therefore much easier to share with another block.

"block-fields.json" options

name

Type: string

Name of your component.

output

Type: string

The path where you want to land of the generated files.

toggles

Type: object

List of the toggle

Example:

"toggles": {
        "bio": {
            "title": "Bio data",
            "isOpen": true,
        },
        "occuption": {
            "title":"Occuption",
            "isOpen":false
        }
    }

fields

Type: array

Pass the list of the field which needs to be required generated.

Options:
  • title Title or label of the field.
  • id id of the field.
  • type Type of the field.
  • value Default value of the field.
  • toggle Toggle id in which this field should be appear. See "toggle" option above.
  • baseControl Whether field should wrapper inside the or not.

Supported fields

text

Render

example:
{
    "title": "Your Name",
    "id": "your-name",
    "type": "text",
    "value": "john doe",
    "toggle": "bio",
    "baseControl": true
}

checkbox

Render

Additional option:

  • checked <true|false>
example:
{
    "title": "Accept t&c",
    "label": "Sample",
    "id": "sample",
    "toggle": "bio",
    "checked": true,
    "type": "checkbox"
},

button

Render <Button />

example:
{
    "title": "Save Changes",
    "type": "button",
    "id": "save-change",
    "toggle": "occuption",
    "default": false,
    "class": "save"
},

button-group

Render <ButtonGroup />

example:
{
    "title": "Button Group",
    "type": "button-group",
    "id": "button-group",
    "toggle": "occuption",
    "buttons": [
        {
            "isPrimary": true,
            "class": "red",
            "label": "Red",
            "id": "red"
        },
        {
            "isPrimary": false,
            "class": "blue",
            "label": "Blue",
            "id": "blue"
        }
    ]
},

select

Render <Select />

example
{
    "type": "select",
    "value": "india",
    "id": "country",
    "title": "Country",
    "options": [
        {
            "label": "India",
            "value": "india"
        },
        {
            "label": "USA",
            "value": "usa"
        }
    ]
},

radio

Render <RadioControl />

example:
{
    "type": "radio",
    "title": "Gender",
    "id": "gender",
    "value": "male",
    "options": [
        {
            "label": "Male",
            "value": "male"
        },
        {
            "label": "Female",
            "value": "female"
        }
    ]
},

range

Render <RangeControl />

Example
{
    "type": "range",
    "title": "Volume",
    "id": "volume",
    "min": 1,
    "max": 100,
    "value": 40
}

color

Render <ColorPalette />

Example
{
    "type": "color",
    "title": "Background Color",
    "id": "bg-color",
    "value": '#fff',
    "colors": [
        {
            "name": "red",
            "color": "#f00"
        },
        {
            "name": "blue",
            "color": "#00f"
        },
        {
            "name": "black",
            "color": "#000"
        }
    ]
}

tree

Render <TreeSelect />

Example
{
    "title": "Select Post",
    "type" : "tree",
    "optionlabel": "Select option",
    "selectedId": "p211",
    "tree":[
        {
            name: 'Post 1',
            id: 'p1',
            children: [
                { name: 'Descend 1 of post 1', id: 'p11' },
                { name: 'Descend 2 of post 1', id: 'p12' },
            ],
        },
        {
            name: 'post 2',
            id: 'p2',
            children: [
                {
                    name: 'Descend 1 of post 2',
                    id: 'p21',
                    children: [
                        {
                            name: 'Descend 1 of Descend 1 of post 2',
                            id: 'p211',
                        },
                    ],
                },
            ],
        },
    ]     
}

datetime

Render <DateTime />

Example
{
    "title": "Select Date and Time",
    "id": "date-posting",
    "type": "datetime",
    "is12hours": true,
    "locale": ""
}

Thanks! ;)

guten-block-fields's People

Contributors

emgk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.