项目作者: ItsJonQ

项目描述 :
🎛 A control panel for developing/prototyping React UI
高级语言: JavaScript
项目地址: git://github.com/ItsJonQ/controls.git
创建时间: 2019-12-07T17:03:42Z
项目社区:https://github.com/ItsJonQ/controls

开源协议:MIT License

下载


🎛 Controls

Build Status

A control panel to develop and prototype React UI

Installation

  1. npm install @itsjonq/controls

Usage

  1. import React from 'react';
  2. import { useControls, Controls } from '@itsjonq/controls';
  3. function Example() {
  4. const { text, number } = useControls();
  5. const title = text('Title', 'My Title');
  6. const amount = number('Amount', 10, { min: 0, max: 50 });
  7. return (
  8. <div>
  9. <Controls ></Controls>
  10. <h2>{title}</h2>
  11. <p>{amount}</p>
  12. </div>
  13. );
  14. }

Fields

  1. import React from 'react';
  2. import { useControls, Controls } from '@itsjonq/controls';
  3. function Example() {
  4. const {
  5. // Fields
  6. boolean,
  7. color,
  8. date,
  9. number,
  10. select,
  11. text,
  12. textarea,
  13. // All attributes
  14. attributes,
  15. } = useControls();
  16. boolean('checked', true);
  17. color('mainColor', 'red');
  18. date('publishDate', 'December 8, 2019');
  19. number('amount', 10, { min: 0, max: 50 });
  20. select(
  21. 'status',
  22. {
  23. Published: 'published',
  24. Draft: 'draft',
  25. Private: 'private',
  26. },
  27. 'published',
  28. );
  29. text('title', 'My Title');
  30. textarea('description', 'Words...');
  31. // The names of the attributes registered with the fields
  32. const {
  33. checked,
  34. mainColor,
  35. publishDate,
  36. amount,
  37. status,
  38. title,
  39. description,
  40. } = attributes;
  41. return <div>...</div>;
  42. }

“Controlled” Fields

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

  1. import React from 'react';
  2. import {
  3. useControls,
  4. Controls,
  5. updateField,
  6. updateFields,
  7. } from '@itsjonq/controls';
  8. function Example() {
  9. const { text } = useControls();
  10. text('title', 'My Title');
  11. text('description', 'My Description');
  12. text('caption', 'My Caption');
  13. // The names of the attributes registered with the fields
  14. const { title, description, caption } = attributes;
  15. const handleOnManualUpdateFields = () => {
  16. // Update a single field
  17. updateField('title', 'New Title');
  18. // Update multiple fields
  19. updateFields({
  20. description: 'New Description',
  21. caption: 'New Caption',
  22. });
  23. };
  24. return <div>...</div>;
  25. }