import { __ } from '@wordpress/i18n'; import { InspectorControls } from '@wordpress/block-editor'; import { BaseControl, ButtonGroup, Button, PanelBody, TabPanel, ToggleControl, SelectControl, TextControl, RangeControl, } from '@wordpress/components'; import CodeMirrorControl from '../../code-snippet/src/components/CodeMirrorControl'; import { THEME_OPTIONS, CODE_SNIPPET_WRAPPER_MARGIN, CODE_SNIPPET_WRAPPER_PADDING, CODE_SNIPPET_HEADER_PADDING, CODE_SNIPPET_LINE_NUMBERS_PADDING, CODE_SNIPPET_CODE_PADDING, } from '../../code-snippet/src/constants'; import ResponsiveDimensionsControl from '../../../util/dimensions-control-v2'; import ColorControl from '../../../util/color-control'; import objAttributes from './attributes'; // Response bodies default to JSON but any of these are selectable per tab. const RESPONSE_LANGUAGE_OPTIONS = [ { label: __('JSON', 'betterdocs'), value: 'json' }, { label: __('XML', 'betterdocs'), value: 'xml' }, { label: __('YAML', 'betterdocs'), value: 'yaml' }, { label: __('JavaScript', 'betterdocs'), value: 'javascript' }, { label: __('PHP', 'betterdocs'), value: 'php' }, { label: __('Python', 'betterdocs'), value: 'python' }, { label: __('Bash', 'betterdocs'), value: 'bash' }, { label: __('HTML', 'betterdocs'), value: 'html' }, { label: __('Plain Text', 'betterdocs'), value: 'text' }, ]; const Inspector = ({ attributes, setAttributes }) => { const { responses = [], showCopyButton, showHeader, showLineNumbers, theme, lineNumberColor, lineNumberBgColor, lineNumberBorderColor, lineNumberBorderWidth, resOption, wrapperBackgroundColor, wrapperBorderColor, wrapperBorderWidth, wrapperBorderRadius, headerBackgroundColor, headerBorderColor, headerBorderWidth, copyButtonColor, copyButtonBorderColor, codeBackgroundColor, } = attributes; const resRequiredProps = { setAttributes, resOption, attributes, objAttributes }; const addResponse = () => { setAttributes({ responses: [ ...responses, { status: '', language: 'json', codeContent: '' }, ], }); }; const updateResponse = (index, key, value) => { const next = responses.map((response, i) => i === index ? { ...response, [key]: value } : response ); setAttributes({ responses: next }); }; const removeResponse = (index) => { setAttributes({ responses: responses.filter((_, i) => i !== index) }); }; return (
{(tab) => (
{tab.name === 'general' && ( <> {responses.map((response, index) => (
{__('Response', 'betterdocs')} {index + 1}
updateResponse(index, 'status', value)} placeholder={__('e.g. 200, 404', 'betterdocs')} __next40pxDefaultSize __nextHasNoMarginBottom /> updateResponse(index, 'language', value)} __next40pxDefaultSize __nextHasNoMarginBottom /> updateResponse(index, 'codeContent', value)} placeholder={__('Paste the example response here…', 'betterdocs')} rows={10} />
))}
{THEME_OPTIONS.map((option) => ( ))} setAttributes({ showHeader: value })} help={__('Toggle the status tabs + copy button.', 'betterdocs')} /> {showHeader && ( setAttributes({ showCopyButton: value })} help={__('Show a one-click copy-to-clipboard icon.', 'betterdocs')} /> )} help={__('Display a tooltip (‘Copied!’) on copy button hover or click.', 'betterdocs')} /> )} setAttributes({ showLineNumbers: value })} help={__('Display line numbers in the response body.', 'betterdocs')} /> )} {tab.name === 'styles' && (
setAttributes({ wrapperBackgroundColor: colorValue })} /> setAttributes({ wrapperBorderColor: colorValue })} /> setAttributes({ wrapperBorderWidth: value })} min={0} max={10} step={1} /> setAttributes({ wrapperBorderRadius: value })} min={0} max={50} step={1} /> {showHeader && ( setAttributes({ headerBackgroundColor: colorValue })} /> setAttributes({ headerBorderColor: colorValue })} /> setAttributes({ headerBorderWidth: value })} min={0} max={10} step={1} help={__('Controls border bottom width', 'betterdocs')} /> setAttributes({ copyButtonColor: colorValue })} /> setAttributes({ copyButtonBorderColor: colorValue })} /> )} {showLineNumbers && ( setAttributes({ lineNumberColor: colorValue })} /> setAttributes({ lineNumberBgColor: colorValue })} /> setAttributes({ lineNumberBorderColor: colorValue })} /> setAttributes({ lineNumberBorderWidth: value })} min={0} max={10} step={1} help={__('Controls border right width', 'betterdocs')} /> )} setAttributes({ codeBackgroundColor: colorValue })} />
)}
)}
); }; export default Inspector;