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

feat(feel): add number feel entry #248

Merged
merged 1 commit into from
May 30, 2023
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
82 changes: 82 additions & 0 deletions src/components/entries/FEEL/Feel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import FeelIcon from './FeelIcon';

import { ToggleSwitch } from '../ToggleSwitch';

import { NumberField } from '../NumberField';

const noop = () => { };

function FeelTextfield(props) {
Expand Down Expand Up @@ -273,6 +275,59 @@ const OptionalFeelInput = forwardRef((props, ref) => {
});


const OptionalFeelNumberField = forwardRef((props, ref) => {
const {
id,
debounce,
disabled,
onInput,
value,
min,
max,
step,
onFocus,
onBlur
} = props;

const inputRef = useRef();

// To be consistent with the FEEL editor, set focus at start of input
// this ensures clean editing experience when switching with the keyboard
ref.current = {
focus: (position) => {
const input = inputRef.current;
if (!input) {
return;
}

input.focus();
if (typeof position === 'number' && position !== Infinity) {
if (position > value.length) {
position = value.length;
}
input.setSelectionRange(position, position);
}

}
};

return <NumberField
id={ id }
debounce={ debounce }
disabled={ disabled }
displayLabel={ false }
inputRef={ inputRef }
max={ max }
min={ min }
onInput={ onInput }
step={ step }
value={ value }
onFocus={ onFocus }
onBlur={ onBlur }
/>;
});


const OptionalFeelTextArea = forwardRef((props, ref) => {
const {
id,
Expand Down Expand Up @@ -492,6 +547,7 @@ export default function FeelEntry(props) {
}
data-entry-id={ id }>
<FeelTextfield
{ ...props }
debounce={ debounce }
disabled={ disabled }
feel={ feel }
Expand All @@ -516,6 +572,32 @@ export default function FeelEntry(props) {
);
}

/**
* @param {Object} props
* @param {Object} props.element
* @param {String} props.id
* @param {String} props.description
* @param {Boolean} props.debounce
* @param {Boolean} props.disabled
* @param {String} props.max
* @param {String} props.min
* @param {String} props.step
* @param {Boolean} props.feel
* @param {String} props.label
* @param {Function} props.getValue
* @param {Function} props.setValue
* @param {Function} props.tooltipContainer
* @param {Function} props.validate
* @param {Function} props.show
* @param {Function} props.example
* @param {Function} props.variables
* @param {Function} props.onFocus
* @param {Function} props.onBlur
*/
export function FeelNumberEntry(props) {
return <FeelEntry class="bio-properties-panel-feel-number" OptionalComponent={ OptionalFeelNumberField } { ...props } />;
}

/**
* @param {Object} props
* @param {Object} props.element
Expand Down
7 changes: 5 additions & 2 deletions src/components/entries/NumberField.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import {
usePrevious
} from '../../hooks';

function NumberField(props) {
export function NumberField(props) {

const {
debounce,
disabled,
displayLabel = true,
id,
inputRef,
label,
max,
min,
Expand Down Expand Up @@ -62,9 +64,10 @@ function NumberField(props) {

return (
<div class="bio-properties-panel-numberfield">
<label for={ prefixId(id) } class="bio-properties-panel-label">{ label }</label>
{displayLabel && <label for={ prefixId(id) } class="bio-properties-panel-label">{ label }</label> }
<input
id={ prefixId(id) }
ref={ inputRef }
type="number"
name={ id }
spellCheck="false"
Expand Down
1 change: 1 addition & 0 deletions src/components/entries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export { default as DescriptionEntry } from './Description';
export {
default as FeelEntry,
FeelCheckboxEntry,
FeelNumberEntry,
FeelTextAreaEntry,
FeelTemplatingEntry,
FeelToggleSwitchEntry,
Expand Down
Loading