Code Monkey home page Code Monkey logo

controls's Introduction

๐ŸŽ› Controls

Build Status

A control panel to develop and prototype React UI

Installation

npm install @itsjonq/controls

Usage

import React from 'react';
import { useControls, Controls } from '@itsjonq/controls';

function Example() {
	const { text, number } = useControls();
	const title = text('Title', 'My Title');
	const amount = number('Amount', 10, { min: 0, max: 50 });

	return (
		<div>
			<Controls />
			<h2>{title}</h2>
			<p>{amount}</p>
		</div>
	);
}

Fields

import React from 'react';
import { useControls, Controls } from '@itsjonq/controls';

function Example() {
	const {
		// Fields
		boolean,
		color,
		date,
		number,
		select,
		text,
		textarea,
		// All attributes
		attributes,
	} = useControls();

	boolean('checked', true);
	color('mainColor', 'red');
	date('publishDate', 'December 8, 2019');
	number('amount', 10, { min: 0, max: 50 });
	select(
		'status',
		{
			Published: 'published',
			Draft: 'draft',
			Private: 'private',
		},
		'published',
	);
	text('title', 'My Title');
	textarea('description', 'Words...');

	// The names of the attributes registered with the fields
	const {
		checked,
		mainColor,
		publishDate,
		amount,
		status,
		title,
		description,
	} = attributes;

	return <div>...</div>;
}

"Controlled" Fields

To manually update a field (or fields), use the updateField or updateFields function.

import React from 'react';
import {
	useControls,
	Controls,
	updateField,
	updateFields,
} from '@itsjonq/controls';

function Example() {
	const { text } = useControls();

	text('title', 'My Title');
	text('description', 'My Description');
	text('caption', 'My Caption');

	// The names of the attributes registered with the fields
	const { title, description, caption } = attributes;

	const handleOnManualUpdateFields = () => {
		// Update a single field
		updateField('title', 'New Title');
		// Update multiple fields
		updateFields({
			description: 'New Description',
			caption: 'New Caption',
		});
	};

	return <div>...</div>;
}

controls's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

controls's Issues

Add support for nested controls

It would be cool if to add nested controls support using dot notation (.) when using a knob from useControls(), example:

import React from 'react'
import { useControls } from '@itsjonq/controls'

const Example = () => {
  const { text } = useControls()

  text('Button.mainColor', 'red')

  return <div>...</div>
}

This would render a UI like this (within the <Controls />)

Button

<input type="text" value="red" />

The UI can be collapsible, but should not be collapsed by default. This will allow for fields to be better organized :).

There should be a limitation though... It can only nest 1 level deep.


Accessing the attributes can use the dot notation as well, example:

import React from 'react'
import { useControls } from '@itsjonq/controls'

const Example = () => {
  const { text, attributes } = useControls()

  text('Button.mainColor', 'red')

  const value = attributes.Button.mainColor

  return <div>...</div>
}

Maybe we can provide a special get method as well, example:

import React from 'react'
import { useControls } from '@itsjonq/controls'

const Example = () => {
  const { text, get } = useControls()

  text('Button.mainColor', 'red')

  const value = get('Button.mainColor')

  return <div>...</div>
}

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.