Skip to content

Commit

Permalink
✨ [open-formulieren/open-forms#2177] added interaction configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmolen committed Dec 12, 2024
1 parent 5d2d324 commit ebe3c35
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/registry/map/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {useErrorChecker} from '@/utils/errors';

import {EditFormDefinition} from '../types';
import MapConfiguration from './map-configuration';
import InteractionConfiguration from '@/registry/map/interaction-configuration';

/**
* Form to configure a Formio 'map' type component.
Expand Down Expand Up @@ -65,7 +66,8 @@ const EditForm: EditFormDefinition<MapComponentSchema> = () => {
'useConfigDefaultMapSettings',
'defaultZoom',
'initialCenter',
'tileLayerIdentifier'
'tileLayerIdentifier',
'interactions'
)}
/>
<BuilderTabs.Advanced hasErrors={hasAnyError('conditional')} />
Expand All @@ -87,6 +89,7 @@ const EditForm: EditFormDefinition<MapComponentSchema> = () => {
<UseConfigDefaultMapSettings />
{!values.useConfigDefaultMapSettings && <MapConfiguration />}
<TileLayer />
<InteractionConfiguration />
</TabPanel>

{/* Advanced tab */}
Expand Down Expand Up @@ -139,6 +142,12 @@ EditForm.defaultValues = {
lng: undefined,
},
tileLayerIdentifier: undefined,
interactions: {
circle: false,
polygon: false,
polyline: false,
marker: true,
},
defaultValue: null,
// Advanced tab
conditional: {
Expand Down
100 changes: 100 additions & 0 deletions src/registry/map/interaction-configuration.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import {FormattedMessage, useIntl} from 'react-intl';
import {Checkbox, Panel} from '@/components/formio';

const CircleInteraction: React.FC = () => {
const intl = useIntl();
const tooltip = intl.formatMessage({
description: "Tooltip for 'interactions.circle' builder field",
defaultMessage: 'Whether users are allowed to draw a circle when working with the map',
});
return (
<Checkbox
name="interactions.circle"
label={
<FormattedMessage
description="Label for 'interactions.circle' builder field"
defaultMessage="Allow circle interactions"
/>
}
tooltip={tooltip}
/>
);
};

const PolygonInteraction: React.FC = () => {
const intl = useIntl();
const tooltip = intl.formatMessage({
description: "Tooltip for 'interactions.polygon' builder field",
defaultMessage: 'Whether users are allowed to draw a polygon when working with the map',
});
return (
<Checkbox
name="interactions.polygon"
label={
<FormattedMessage
description="Label for 'interactions.polygon' builder field"
defaultMessage="Allow polygon interactions"
/>
}
tooltip={tooltip}
/>
);
};

const PolylineInteraction: React.FC = () => {
const intl = useIntl();
const tooltip = intl.formatMessage({
description: "Tooltip for 'interactions.polyline' builder field",
defaultMessage: 'Whether users are allowed to draw a polyline when working with the map',
});
return (
<Checkbox
name="interactions.polyline"
label={
<FormattedMessage
description="Label for 'interactions.polyline' builder field"
defaultMessage="Allow polyline interactions"
/>
}
tooltip={tooltip}
/>
);
};

const MarkerInteraction: React.FC = () => {
const intl = useIntl();
const tooltip = intl.formatMessage({
description: "Tooltip for 'interactions.marker' builder field",
defaultMessage: 'Whether users are allowed to set a marker when working with the map',
});
return (
<Checkbox
name="interactions.marker"
label={
<FormattedMessage
description="Label for 'interactions.marker' builder field"
defaultMessage="Allow marker interactions"
/>
}
tooltip={tooltip}
/>
);
};

const InteractionConfiguration: React.FC = () => (
<Panel
title={
<FormattedMessage
description="Interaction configuration panel title"
defaultMessage="Available map interactions"
/>
}
>
<CircleInteraction />
<PolygonInteraction />
<PolylineInteraction />
<MarkerInteraction />
</Panel>
);

export default InteractionConfiguration;

0 comments on commit ebe3c35

Please sign in to comment.