Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [#4707] Resizable json widget #4786

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading