Skip to content

Commit

Permalink
feat: added honeypot field type
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini committed Sep 9, 2022
1 parent d8414a8 commit 272e3c3
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/components/Field.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
import { useIntl, defineMessages } from 'react-intl';

import WysiwygWidget from '@plone/volto/components/manage/Widgets/WysiwygWidget';

import EmailWidget from './Widget/EmailWidget';
import FileWidget from './Widget/FileWidget';
import DatetimeWidget from './Widget/DatetimeWidget';
Expand All @@ -13,6 +12,7 @@ import TextWidget from './Widget/TextWidget';
import TextareaWidget from './Widget/TextareaWidget';
import CheckboxListWidget from './Widget/CheckboxListWidget';
import RadioWidget from './Widget/RadioWidget';
import HoneypotWidget from './Widget/HoneypotWidget';

import './Field.css';

Expand Down Expand Up @@ -214,6 +214,17 @@ const Field = ({
) : (
<br />
))}

{field_type === 'honeypot' && (
<HoneypotWidget
id={name}
name={name}
title={label}
description={description}
onChange={onChange}
value={value}
/>
)}
{config.blocks.blocksConfig.form.additionalFields?.reduce((acc, val) => {
if (val.id === field_type)
return [
Expand Down
3 changes: 3 additions & 0 deletions src/components/Widget/HoneypotWidget.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.honey-wrapper {
display: none;
}
70 changes: 70 additions & 0 deletions src/components/Widget/HoneypotWidget.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* HoneypotWidget component.
* @module components/manage/Widgets/HoneypotWidget
*/

import React from 'react';
import PropTypes from 'prop-types';

import TextWidget from '@plone/volto/components/manage/Widgets/TextWidget';
import './HoneypotWidget.css';

/**
* HoneypotWidget component class.
* @function HoneypotWidget
* @returns {string} Markup of the component.
*/
const HoneypotWidget = ({
id,
title,
required,
description,
error,
value = [],
valueList,
onChange,
}) => {
return (
<div className="honey-wrapper">
<TextWidget
id={id}
name={id}
title={title}
description={description}
onChange={onChange}
value={value}
/>
</div>
);
};

/**
* Property types.
* @property {Object} propTypes Property types.
* @static
*/
HoneypotWidget.propTypes = {
id: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
description: PropTypes.string,
required: PropTypes.bool,
error: PropTypes.arrayOf(PropTypes.string),
wrapped: PropTypes.bool,
};

/**
* Default properties.
* @property {Object} defaultProps Default properties.
* @static
*/
HoneypotWidget.defaultProps = {
description: null,
required: false,
error: [],
value: [],
onChange: null,
onEdit: null,
onDelete: null,
};

export default HoneypotWidget;

0 comments on commit 272e3c3

Please sign in to comment.