UNPKG

@itsjonq/controls

Version:

A control panel to develop React UI

42 lines (35 loc) 2.02 kB
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } import React from 'react'; import { updateField } from '../../store'; import { useControls } from '../../hooks'; import { Field } from '../Field'; import { Wrapper, Header, Body } from './Controls.styles'; /** * <BaseControls /> was separated from the preferred <Controls /> component * to provide a non-portaled way to render and test the component. */ export function BaseControls(props) { var _useControls = useControls(), fields = _useControls.fields; if (!fields.length) return React.createElement("div", null); var isDark = props.isDark, title = props.title, padding = props.padding, restProps = _objectWithoutProperties(props, ["isDark", "title", "padding"]); var handleOnChange = function (prop) { return function (nextValue) { updateField(prop, nextValue); }; }; return React.createElement(Wrapper, Object.assign({}, restProps, { isDark: isDark }), React.createElement(Header, null, title || 'Control Panel'), React.createElement(Body, { padding: padding || 8 }, fields.map(function (field) { return React.createElement(Field, Object.assign({}, field, { key: field.prop, onChange: handleOnChange(field.prop) })); }))); }