Skip to content

Commit

Permalink
Merge pull request #4786 from open-formulieren/feature/4707-allow-res…
Browse files Browse the repository at this point in the history
…ize-of-json-widget

✨ [#4707] Resizable json widget
  • Loading branch information
sergei-maertens authored Nov 8, 2024
2 parents d387129 + 2d3356a commit 19b45bd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/openforms/js/components/admin/forms/JsonWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import classNames from 'classnames';
import jsonLogic from 'json-logic-js';
import {isEqual} from 'lodash';
import PropTypes from 'prop-types';
import React, {useEffect, useRef, useState} from 'react';
import {useEffect, useRef, useState} from 'react';
import {useIntl} from 'react-intl';
import {useGlobalState} from 'state-pool';

Expand Down Expand Up @@ -79,7 +79,7 @@ const JsonWidget = ({
>
{isExpanded && (
<div
className="json-widget__input"
className="json-widget__input json-widget__input--resizable"
style={{
'--of-json-widget-cols': cols,
'--of-json-widget-rows': Math.min(maxRows, Math.max(MIN_LINES, numRows)),
Expand All @@ -90,6 +90,7 @@ const JsonWidget = ({
onChange={onJsonChange}
lineCountCallback={(numLines = 1) => setNumRows(numLines)}
theme={theme}
automaticLayout={true}
/>
</div>
)}
Expand Down
20 changes: 11 additions & 9 deletions src/openforms/scss/components/admin/_json-editor.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
$json_editor_min_inline_size: var(
--of-json-widget-min-inline-size,
// assume monospace font, multiply the width of one char times the number of cols requested
// and add the space for the editor margin
calc(
var(--of-json-widget-cols, 10) * var(--of-json-widget-char-size, 8.44px) +
var(--of-json-widget-margin-inline-size, 68px)
)
);

// Set up height/width based on the number of requested rows/cols.
// You can customize this per instance by providing an inline style attribute for
// the rows/cols.
Expand All @@ -6,15 +16,7 @@
flex-direction: column;

block-size: calc(var(--of-json-widget-rows, 3) * var(--_of-json-widget-row-block-size, 19px));
min-inline-size: var(
--of-json-widget-min-inline-size,
// assume monospace font, multiply the width of one char times the number of cols requested
// and add the space for the editor margin
calc(
var(--of-json-widget-cols, 10) * var(--of-json-widget-char-size, 8.44px) +
var(--of-json-widget-margin-inline-size, 68px)
)
);
min-inline-size: $json_editor_min_inline_size;
max-inline-size: var(--of-json-widget-max-inline-size, var(--of-admin-input-field-size));

border: 1px solid var(--border-color);
Expand Down
23 changes: 23 additions & 0 deletions src/openforms/scss/components/admin/_json-widget.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@
.json-widget {
@include bem.element('input') {
@include json-editor.container;

@include bem.modifier('resizable') {
position: relative;
resize: both;
overflow: auto;
padding-block-end: 0.8em;
inline-size: json-editor.$json_editor_min_inline_size;
max-inline-size: unset;
z-index: 0;

// Purely to give the resize handle some space from the input
&::after {
position: absolute;
content: '';
left: 0;
right: 0;
bottom: 0;
height: 0.8em;
border-block-start: 1px solid var(--border-color);
background-color: var(--form-input-bg);
z-index: 1;
}
}
}

@include bem.modifier('collapsed') {
Expand Down

0 comments on commit 19b45bd

Please sign in to comment.