@evoke-platform/ui-components 1.0.0-dev.123 → 1.0.0-dev.124

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/published/form-components/Boolean.d.ts +16 -0
  2. package/dist/published/form-components/Boolean.js +22 -0
  3. package/dist/published/form-components/Button.d.ts +8 -0
  4. package/dist/published/form-components/Button.js +30 -0
  5. package/dist/published/form-components/Buttons.d.ts +8 -0
  6. package/dist/published/form-components/Buttons.js +26 -0
  7. package/dist/published/form-components/Date.d.ts +17 -0
  8. package/dist/published/form-components/Date.js +44 -0
  9. package/dist/published/form-components/DateTime.d.ts +16 -0
  10. package/dist/published/form-components/DateTime.js +22 -0
  11. package/dist/published/form-components/Decimal.d.ts +16 -0
  12. package/dist/published/form-components/Decimal.js +35 -0
  13. package/dist/published/form-components/FieldWrapper.d.ts +21 -0
  14. package/dist/published/form-components/FieldWrapper.js +84 -0
  15. package/dist/published/form-components/Integer.d.ts +16 -0
  16. package/dist/published/form-components/Integer.js +34 -0
  17. package/dist/published/form-components/Select.d.ts +16 -0
  18. package/dist/published/form-components/Select.js +22 -0
  19. package/dist/published/form-components/SharedCustomizations.d.ts +32 -0
  20. package/dist/published/form-components/SharedCustomizations.js +59 -0
  21. package/dist/published/form-components/Text.d.ts +17 -0
  22. package/dist/published/form-components/Text.js +80 -0
  23. package/dist/published/form-components/index.d.ts +37 -0
  24. package/dist/published/form-components/index.js +24 -0
  25. package/dist/published/index.d.ts +3 -2
  26. package/dist/published/index.js +3 -2
  27. package/package.json +2 -1
@@ -0,0 +1,16 @@
1
+ declare const Select: {
2
+ new (component: any, options: any, data: any): {
3
+ [x: string]: any;
4
+ errorDetails: any;
5
+ conditionallyHidden(): any;
6
+ validateRequired(value: any): void;
7
+ renderComponentToElement(component: any, element: any): void;
8
+ };
9
+ [x: string]: any;
10
+ };
11
+ declare class Boolean extends Select {
12
+ constructor(component: any, options: any, data: any);
13
+ handleChange: (key: string, value: string) => void;
14
+ attach(element: Element): void;
15
+ }
16
+ export default Boolean;
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { Components } from 'formiojs';
3
+ import FieldWrapper from './FieldWrapper';
4
+ import { FormField } from '../components/custom';
5
+ import { addSharedCustomizations } from './SharedCustomizations';
6
+ const Select = addSharedCustomizations(Components.components.select);
7
+ class Boolean extends Select {
8
+ constructor(component, options, data) {
9
+ super(component, options, data);
10
+ this.handleChange = (key, value) => {
11
+ this.validateRequired(value);
12
+ super.setValue(value, {});
13
+ };
14
+ this.handleChange = this.handleChange.bind(this);
15
+ }
16
+ attach(element) {
17
+ this.renderComponentToElement(React.createElement("div", null, !this.conditionallyHidden() && (React.createElement(FieldWrapper, Object.assign({}, this.component, { onChange: this.handleChange, errorDetails: this.errorDetails }),
18
+ React.createElement(FormField, Object.assign({}, this.component, { errorMessage: Object.values(this.errorDetails).join(', '), min: this.component.validate.min, max: this.component.validate.max }))))), element);
19
+ super.attach(element);
20
+ }
21
+ }
22
+ export default Boolean;
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ declare const FormIOButton: import("formiojs").ClassWithEditForm<typeof import("formiojs/types/components/_classes/field/field").Field>;
3
+ declare class CustomButton extends FormIOButton {
4
+ constructor(component: any, options: any, data: any);
5
+ render(): JSX.Element;
6
+ attach(element: Element): void;
7
+ }
8
+ export default CustomButton;
@@ -0,0 +1,30 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import React from 'react';
13
+ import { Components } from 'formiojs';
14
+ import ReactDOMClient from 'react-dom/client';
15
+ import { Button } from '../components/core';
16
+ const FormIOButton = Components.components.button;
17
+ class CustomButton extends FormIOButton {
18
+ constructor(component, options, data) {
19
+ super(component, options, data);
20
+ }
21
+ render() {
22
+ const _a = this.component, { label } = _a, rest = __rest(_a, ["label"]);
23
+ return (React.createElement("div", null,
24
+ React.createElement(Button, Object.assign({}, rest), label)));
25
+ }
26
+ attach(element) {
27
+ ReactDOMClient.createRoot(element).render(this.render());
28
+ }
29
+ }
30
+ export default CustomButton;
@@ -0,0 +1,8 @@
1
+ declare const ButtonComponent: any;
2
+ declare class Buttons extends ButtonComponent {
3
+ constructor(component: any, options: any, data: any);
4
+ handleCancel: (event: any) => void;
5
+ handleSubmit: (event: any) => void;
6
+ attach(element: any): void;
7
+ }
8
+ export default Buttons;
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { Components } from 'formiojs';
3
+ import ReactDOMClient from 'react-dom/client';
4
+ import { Button as EvokeButton } from '../components/core';
5
+ const ButtonComponent = Components.components.button;
6
+ class Buttons extends ButtonComponent {
7
+ constructor(component, options, data) {
8
+ super(component, options, data);
9
+ this.handleCancel = (event) => {
10
+ this.component.components[0].onCancel(event);
11
+ };
12
+ this.handleSubmit = (event) => {
13
+ const submission = this.root.getValue();
14
+ this.component.components[1].onSubmit(submission);
15
+ this.onSubmit();
16
+ };
17
+ this.handleCancel = this.handleCancel.bind(this);
18
+ this.handleSubmit = this.handleSubmit.bind(this);
19
+ }
20
+ attach(element) {
21
+ ReactDOMClient.createRoot(element).render(React.createElement("div", { style: { width: '100%', display: 'flex', justifyContent: 'flex-end' } },
22
+ React.createElement(EvokeButton, { sx: { margin: '5px' }, variant: this.component.components[0].variant, onClick: this.handleCancel }, this.component.components[0].label),
23
+ React.createElement(EvokeButton, { sx: { margin: '5px' }, variant: this.component.components[1].variant, onClick: this.handleSubmit }, this.component.components[1].label)));
24
+ }
25
+ }
26
+ export default Buttons;
@@ -0,0 +1,17 @@
1
+ declare const DateTime: {
2
+ new (component: any, options: any, data: any): {
3
+ [x: string]: any;
4
+ errorDetails: any;
5
+ conditionallyHidden(): any;
6
+ validateRequired(value: any): void;
7
+ renderComponentToElement(component: any, element: any): void;
8
+ };
9
+ [x: string]: any;
10
+ };
11
+ declare class DateField extends DateTime {
12
+ constructor(component: any, options: any, data: any);
13
+ handleValidation: (value: string) => void;
14
+ handleChange: (key: string, value: string) => void;
15
+ attach(element: Element): void;
16
+ }
17
+ export default DateField;
@@ -0,0 +1,44 @@
1
+ import React from 'react';
2
+ import { Components } from 'formiojs';
3
+ import FieldWrapper from './FieldWrapper';
4
+ import { FormField } from '../components/custom';
5
+ import { addSharedCustomizations } from './SharedCustomizations';
6
+ const DateTime = addSharedCustomizations(Components.components.datetime);
7
+ class DateField extends DateTime {
8
+ constructor(component, options, data) {
9
+ super(component, options, data);
10
+ this.handleValidation = (value) => {
11
+ if (this.component.validate.minDate) {
12
+ if (value < this.component.validate.minDate) {
13
+ this.errorDetails['minDate'] =
14
+ 'Date must be after ' + new Date(this.component.validate.minDate).toLocaleDateString();
15
+ }
16
+ else {
17
+ delete this.errorDetails['minDate'];
18
+ }
19
+ }
20
+ if (this.component.validate.maxDate) {
21
+ if (value > this.component.validate.maxDate) {
22
+ this.errorDetails['maxDate'] =
23
+ 'Date must be before ' + new Date(this.component.validate.maxDate).toLocaleDateString();
24
+ }
25
+ else {
26
+ delete this.errorDetails['maxDate'];
27
+ }
28
+ }
29
+ this.validateRequired(value);
30
+ };
31
+ this.handleChange = (key, value) => {
32
+ super.setValue(value, {});
33
+ this.handleValidation(value);
34
+ this.attach(this.element);
35
+ };
36
+ this.handleChange = this.handleChange.bind(this);
37
+ }
38
+ attach(element) {
39
+ this.renderComponentToElement(React.createElement(FieldWrapper, Object.assign({}, this.component, { onChange: this.handleChange, errorMessage: Object.values(this.errorDetails).join(', ') }),
40
+ React.createElement(FormField, Object.assign({}, this.component))), element);
41
+ super.attach(element);
42
+ }
43
+ }
44
+ export default DateField;
@@ -0,0 +1,16 @@
1
+ declare const DateTimeFormIO: {
2
+ new (component: any, options: any, data: any): {
3
+ [x: string]: any;
4
+ errorDetails: any;
5
+ conditionallyHidden(): any;
6
+ validateRequired(value: any): void;
7
+ renderComponentToElement(component: any, element: any): void;
8
+ };
9
+ [x: string]: any;
10
+ };
11
+ declare class DateTime extends DateTimeFormIO {
12
+ constructor(component: any, options: any, data: any);
13
+ handleChange: (key: string, value: string) => void;
14
+ attach(element: Element): void;
15
+ }
16
+ export default DateTime;
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { Components } from 'formiojs';
3
+ import { FormField } from '../components/custom';
4
+ import { addSharedCustomizations } from './SharedCustomizations';
5
+ import FieldWrapper from './FieldWrapper';
6
+ const DateTimeFormIO = addSharedCustomizations(Components.components.datetime);
7
+ class DateTime extends DateTimeFormIO {
8
+ constructor(component, options, data) {
9
+ super(component, options, data);
10
+ this.handleChange = (key, value) => {
11
+ this.validateRequired(value);
12
+ super.setValue(value, {});
13
+ };
14
+ this.handleChange = this.handleChange.bind(this);
15
+ }
16
+ attach(element) {
17
+ this.renderComponentToElement(React.createElement(FieldWrapper, Object.assign({}, this.component, { onChange: this.handleChange, errorMessage: Object.values(this.errorDetails).join(', ') }),
18
+ React.createElement(FormField, Object.assign({}, this.component))), element);
19
+ super.attach(element);
20
+ }
21
+ }
22
+ export default DateTime;
@@ -0,0 +1,16 @@
1
+ declare const Number: {
2
+ new (component: any, options: any, data: any): {
3
+ [x: string]: any;
4
+ errorDetails: any;
5
+ conditionallyHidden(): any;
6
+ validateRequired(value: any): void;
7
+ renderComponentToElement(component: any, element: any): void;
8
+ };
9
+ [x: string]: any;
10
+ };
11
+ declare class Decimal extends Number {
12
+ constructor(component: any, options: any, data: any);
13
+ handleChange: (key: string, value: string) => void;
14
+ attach(element: Element): void;
15
+ }
16
+ export default Decimal;
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ import { Components } from 'formiojs';
3
+ import FieldWrapper from './FieldWrapper';
4
+ import { FormField } from '../components/custom';
5
+ import { addSharedCustomizations } from './SharedCustomizations';
6
+ const Number = addSharedCustomizations(Components.components.number);
7
+ class Decimal extends Number {
8
+ constructor(component, options, data) {
9
+ super(component, options, data);
10
+ this.handleChange = (key, value) => {
11
+ super.setValue(value, {});
12
+ if (this.component.validate.min && value < this.component.validate.min) {
13
+ this.errorDetails['min'] = `Min value is ${this.component.validate.min}`;
14
+ }
15
+ else {
16
+ delete this.errorDetails['min'];
17
+ }
18
+ if (this.component.validate.max && value > this.component.validate.max) {
19
+ this.errorDetails['max'] = `Max value is ${this.component.validate.max}`;
20
+ }
21
+ else {
22
+ delete this.errorDetails['max'];
23
+ }
24
+ this.validateRequired(value);
25
+ this.attach(this.element);
26
+ };
27
+ this.handleChange = this.handleChange.bind(this);
28
+ }
29
+ attach(element) {
30
+ this.renderComponentToElement(React.createElement(FieldWrapper, Object.assign({}, this.component, { onChange: this.handleChange, errorDetails: this.errorDetails }),
31
+ React.createElement(FormField, Object.assign({}, this.component, { errorMessage: Object.values(this.errorDetails).join(', ') }))), element);
32
+ super.attach(element);
33
+ }
34
+ }
35
+ export default Decimal;
@@ -0,0 +1,21 @@
1
+ /// <reference types="react" />
2
+ declare type FieldWrapperProps = {
3
+ label: string;
4
+ description?: string;
5
+ tooltip?: string;
6
+ prefix?: string;
7
+ suffix?: string;
8
+ value?: string;
9
+ validate: any;
10
+ errorMessage: string;
11
+ showCharCount?: boolean;
12
+ type: string;
13
+ onChange: Function;
14
+ children: any;
15
+ };
16
+ /**
17
+ * A component that wraps a FormField and adds a label,
18
+ * description, tooltip, prefix, suffix and word/char counts
19
+ */
20
+ declare const FieldWrapper: (props: FieldWrapperProps) => JSX.Element;
21
+ export default FieldWrapper;
@@ -0,0 +1,84 @@
1
+ import React, { useEffect, useRef } from 'react';
2
+ import { Box } from '../components/layout';
3
+ import { IconButton, Tooltip, Typography } from '../components/core';
4
+ import { Help } from '../icons';
5
+ const PrefixSuffix = (props) => {
6
+ const { prefix, suffix, height } = props;
7
+ const text = prefix || suffix;
8
+ const prefixSuffixStyles = Object.assign(Object.assign(Object.assign({ display: 'inline-flex', alignItems: 'center', background: '#f5f5f5', padding: '5px', border: '1px solid #ccc' }, (suffix && {
9
+ borderTopRightRadius: '5px',
10
+ borderBottomRightRadius: '5px',
11
+ marginLeft: '-5px',
12
+ paddingLeft: '10px',
13
+ })), (prefix && {
14
+ borderTopLeftRadius: '5px',
15
+ borderBottomLeftRadius: '5px',
16
+ marginRight: '-5px',
17
+ paddingRight: '10px',
18
+ })), { height: height });
19
+ if (!prefix && !suffix)
20
+ return null;
21
+ return (React.createElement(Box, { sx: prefixSuffixStyles },
22
+ React.createElement(Typography, null, text)));
23
+ };
24
+ /**
25
+ * A component that wraps a FormField and adds a label,
26
+ * description, tooltip, prefix, suffix and word/char counts
27
+ */
28
+ const FieldWrapper = (props) => {
29
+ const { label, description, tooltip, prefix, suffix, value, validate, errorMessage, showCharCount, type, onChange, children, } = props;
30
+ const [fieldHeight, setFieldHeight] = React.useState(40);
31
+ const [fieldValue, setFieldValue] = React.useState(value);
32
+ const { maxLength } = validate;
33
+ const fieldRef = useRef(null);
34
+ useEffect(() => {
35
+ //get height of field to sync with height of prefix and suffix
36
+ const fieldElement = fieldRef.current;
37
+ if (fieldElement && (prefix || suffix)) {
38
+ setFieldHeight(fieldElement.getBoundingClientRect().height - 12);
39
+ }
40
+ }, [fieldRef]);
41
+ const underFieldStyles = {
42
+ display: 'flex',
43
+ flexDirection: 'row',
44
+ justifyContent: 'space-between',
45
+ alignItems: 'center',
46
+ };
47
+ const descriptionStyles = {
48
+ color: '#999',
49
+ whiteSpace: 'normal',
50
+ };
51
+ let charCount = fieldValue && type === 'textfield' ? fieldValue.length : 0;
52
+ if (maxLength)
53
+ charCount = maxLength - charCount;
54
+ const handleChange = (key, value) => {
55
+ onChange(key, value);
56
+ setFieldValue(value);
57
+ };
58
+ return (React.createElement(Box, { sx: { margin: '10px' } },
59
+ React.createElement(Box, null,
60
+ React.createElement(Typography, { sx: { fontWeight: 600 }, variant: "subtitle2" },
61
+ label,
62
+ validate.required ? React.createElement("span", { style: { color: 'red' } },
63
+ ` *`,
64
+ " ") : null,
65
+ tooltip && (React.createElement(Tooltip, { placement: "right", title: tooltip },
66
+ React.createElement(IconButton, null,
67
+ React.createElement(Help, { sx: { fontSize: '14px' } }))))),
68
+ React.createElement(Typography, { variant: "caption", sx: descriptionStyles }, description),
69
+ React.createElement(Box, { sx: { display: 'flex', flexDirection: 'row' } },
70
+ React.createElement(PrefixSuffix, { prefix: prefix, height: fieldHeight }),
71
+ React.createElement("div", { style: { width: '100%' }, ref: fieldRef }, React.Children.map(children, (child) => {
72
+ return React.cloneElement(child, { onChange: handleChange });
73
+ })),
74
+ React.createElement(PrefixSuffix, { suffix: suffix, height: fieldHeight }))),
75
+ React.createElement(Box, { sx: underFieldStyles },
76
+ React.createElement(Box, { sx: { width: '100%', display: 'flex', justifyContent: 'space-between' } },
77
+ errorMessage ? (React.createElement(Typography, { sx: { color: 'red', whiteSpace: 'normal' }, variant: "caption" }, ' ⚠ ' + errorMessage)) : (React.createElement("span", null)),
78
+ showCharCount && (React.createElement(Typography, { variant: "caption", sx: { color: '#999', whiteSpace: 'nowrap' } },
79
+ charCount,
80
+ " ",
81
+ charCount === 1 ? 'character' : 'characters',
82
+ !!maxLength && ` remaining`))))));
83
+ };
84
+ export default FieldWrapper;
@@ -0,0 +1,16 @@
1
+ declare const Number: {
2
+ new (component: any, options: any, data: any): {
3
+ [x: string]: any;
4
+ errorDetails: any;
5
+ conditionallyHidden(): any;
6
+ validateRequired(value: any): void;
7
+ renderComponentToElement(component: any, element: any): void;
8
+ };
9
+ [x: string]: any;
10
+ };
11
+ declare class Integer extends Number {
12
+ constructor(component: any, options: any, data: any);
13
+ handleChange: (key: string, value: string) => void;
14
+ attach(element: Element): void;
15
+ }
16
+ export default Integer;
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import { Components } from 'formiojs';
3
+ import FieldWrapper from './FieldWrapper';
4
+ import { FormField } from '../components/custom';
5
+ import { addSharedCustomizations } from './SharedCustomizations';
6
+ const Number = addSharedCustomizations(Components.components.number);
7
+ class Integer extends Number {
8
+ constructor(component, options, data) {
9
+ super(component, options, data);
10
+ this.handleChange = (key, value) => {
11
+ super.setValue(value, {});
12
+ if (this.component.validate.min && value < this.component.validate.min) {
13
+ this.errorDetails['min'] = `Min value is ${this.component.validate.min}`;
14
+ }
15
+ else {
16
+ delete this.errorDetails['min'];
17
+ }
18
+ if (this.component.validate.max && value > this.component.validate.max) {
19
+ this.errorDetails['max'] = `Max value is ${this.component.validate.max}`;
20
+ }
21
+ else {
22
+ delete this.errorDetails['max'];
23
+ }
24
+ this.validateRequired(value);
25
+ this.attach(this.element);
26
+ };
27
+ }
28
+ attach(element) {
29
+ this.renderComponentToElement(React.createElement("div", null, !this.conditionallyHidden() && (React.createElement(FieldWrapper, Object.assign({}, this.component, { onChange: this.handleChange, errorDetails: this.errorDetails }),
30
+ React.createElement(FormField, Object.assign({}, this.component, { errorMessage: Object.values(this.errorDetails).join(', ') }))))), element);
31
+ super.attach(element);
32
+ }
33
+ }
34
+ export default Integer;
@@ -0,0 +1,16 @@
1
+ declare const SelectFormIOComponent: {
2
+ new (component: any, options: any, data: any): {
3
+ [x: string]: any;
4
+ errorDetails: any;
5
+ conditionallyHidden(): any;
6
+ validateRequired(value: any): void;
7
+ renderComponentToElement(component: any, element: any): void;
8
+ };
9
+ [x: string]: any;
10
+ };
11
+ declare class Select extends SelectFormIOComponent {
12
+ constructor(component: any, options: any, data: any);
13
+ handleChange: (key: string, value: string) => void;
14
+ attach(element: Element): void;
15
+ }
16
+ export default Select;
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { Components } from 'formiojs';
3
+ import FieldWrapper from './FieldWrapper';
4
+ import { FormField } from '../components/custom';
5
+ import { addSharedCustomizations } from './SharedCustomizations';
6
+ const SelectFormIOComponent = addSharedCustomizations(Components.components.select);
7
+ class Select extends SelectFormIOComponent {
8
+ constructor(component, options, data) {
9
+ super(component, options, data);
10
+ this.handleChange = (key, value) => {
11
+ this.validateRequired(value);
12
+ super.setValue(value, {});
13
+ };
14
+ this.handleChange = this.handleChange.bind(this);
15
+ }
16
+ attach(element) {
17
+ this.renderComponentToElement(React.createElement("div", null, !this.conditionallyHidden() && (React.createElement(FieldWrapper, Object.assign({}, this.component, { onChange: this.handleChange, errorMessage: Object.values(this.errorDetails).join(', ') }),
18
+ React.createElement(FormField, Object.assign({}, this.component))))), element);
19
+ super.attach(element);
20
+ }
21
+ }
22
+ export default Select;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Adds shared customizations such as errorDetails, validateRequired() and
3
+ * conditionallyHidden() to a component class.
4
+ * @param {any} superClass - The component class to extend.
5
+ * @returns {any} - The extended component class with shared customizations.
6
+ */
7
+ export declare function addSharedCustomizations(superClass: any): {
8
+ new (component: any, options: any, data: any): {
9
+ [x: string]: any;
10
+ errorDetails: any;
11
+ /**
12
+ * Checks if the component should be conditionally hidden based on its
13
+ * configuration and the values within of other fields
14
+ * @returns {boolean}
15
+ */
16
+ conditionallyHidden(): any;
17
+ /**
18
+ * Checks if a value is required and adds an error message if it is empty.
19
+ * @param {any} value - The value to check.
20
+ * @returns {void}
21
+ */
22
+ validateRequired(value: any): void;
23
+ /**
24
+ * Renders a React component to a DOM element.
25
+ * @param {any} component - The React component to render.
26
+ * @param {any} element - The DOM element to render the component to.
27
+ * @returns {void}
28
+ */
29
+ renderComponentToElement(component: any, element: any): void;
30
+ };
31
+ [x: string]: any;
32
+ };
@@ -0,0 +1,59 @@
1
+ import { isEmpty } from 'lodash';
2
+ import ReactDOM from 'react-dom';
3
+ /**
4
+ * Adds shared customizations such as errorDetails, validateRequired() and
5
+ * conditionallyHidden() to a component class.
6
+ * @param {any} superClass - The component class to extend.
7
+ * @returns {any} - The extended component class with shared customizations.
8
+ */
9
+ export function addSharedCustomizations(superClass) {
10
+ return class extends superClass {
11
+ constructor(component, options, data) {
12
+ super(component, options, data);
13
+ this.errorDetails = {};
14
+ }
15
+ /**
16
+ * Checks if the component should be conditionally hidden based on its
17
+ * configuration and the values within of other fields
18
+ * @returns {boolean}
19
+ */
20
+ conditionallyHidden() {
21
+ const { conditional } = this.component;
22
+ const prerequisiteField = conditional.when;
23
+ const prerequisiteValue = conditional.eq;
24
+ const prerequisiteFieldValue = this.root.getValue().data[prerequisiteField];
25
+ prerequisiteField && prerequisiteFieldValue !== prerequisiteValue
26
+ ? (this.component.hidden = true)
27
+ : (this.component.hidden = false);
28
+ return this.component.hidden;
29
+ }
30
+ /**
31
+ * Checks if a value is required and adds an error message if it is empty.
32
+ * @param {any} value - The value to check.
33
+ * @returns {void}
34
+ */
35
+ validateRequired(value) {
36
+ if (this.component.validate.required) {
37
+ if (isEmpty(value)) {
38
+ this.errorDetails['required'] = 'This field is required';
39
+ }
40
+ else {
41
+ delete this.errorDetails['required'];
42
+ }
43
+ }
44
+ }
45
+ /**
46
+ * Renders a React component to a DOM element.
47
+ * @param {any} component - The React component to render.
48
+ * @param {any} element - The DOM element to render the component to.
49
+ * @returns {void}
50
+ */
51
+ renderComponentToElement(component, element) {
52
+ let root = ReactDOM.findDOMNode(element);
53
+ if (!root) {
54
+ root = element;
55
+ }
56
+ ReactDOM.render(!this.conditionallyHidden() && component, root);
57
+ }
58
+ };
59
+ }
@@ -0,0 +1,17 @@
1
+ declare const TextField: {
2
+ new (component: any, options: any, data: any): {
3
+ [x: string]: any;
4
+ errorDetails: any;
5
+ conditionallyHidden(): any;
6
+ validateRequired(value: any): void;
7
+ renderComponentToElement(component: any, element: any): void;
8
+ };
9
+ [x: string]: any;
10
+ };
11
+ declare class Text extends TextField {
12
+ constructor(component: any, options: any, data: any);
13
+ handleValidation(value: string): void;
14
+ handleChange: (key: string, value: string) => void;
15
+ attach(element: Element): void;
16
+ }
17
+ export default Text;
@@ -0,0 +1,80 @@
1
+ import React from 'react';
2
+ import { Components } from 'formiojs';
3
+ import FieldWrapper from './FieldWrapper';
4
+ import { isEmpty } from 'lodash';
5
+ import { FormField } from '../components/custom';
6
+ import { addSharedCustomizations } from './SharedCustomizations';
7
+ const TextField = addSharedCustomizations(Components.components.textfield);
8
+ class Text extends TextField {
9
+ constructor(component, options, data) {
10
+ super(component, options, data);
11
+ this.handleChange = (key, value) => {
12
+ super.setValue(value, {});
13
+ this.handleValidation(value);
14
+ this.attach(this.element);
15
+ };
16
+ this.handleChange = this.handleChange.bind(this);
17
+ }
18
+ handleValidation(value) {
19
+ const { inputMask, validate } = this.component;
20
+ const mask = inputMask;
21
+ if (mask) {
22
+ const maskRegex = mask === null || mask === void 0 ? void 0 : mask.replace(/[\\^$.+?()[\]{}|]/g, '\\$&').replaceAll('9', '\\d').replaceAll('a', '[a-zA-Z]').replaceAll('*', '[a-zA-Z0-9]');
23
+ if (maskRegex) {
24
+ const regex = new RegExp(maskRegex);
25
+ if (!regex.test(value)) {
26
+ this.errorDetails['inputMask'] = 'Value must match the format ' + mask;
27
+ }
28
+ else {
29
+ delete this.errorDetails['inputMask'];
30
+ }
31
+ }
32
+ }
33
+ if (!isEmpty(validate.regexes)) {
34
+ const regexes = validate.regexes;
35
+ const failedRules = validate.regexes.filter((rule) => {
36
+ if (!RegExp(rule.regex).test(value)) {
37
+ return true;
38
+ }
39
+ return false;
40
+ });
41
+ if (failedRules.length === 0) {
42
+ delete this.errorDetails['regexes'];
43
+ }
44
+ else {
45
+ if (validate.operator === 'all') {
46
+ this.errorDetails['regexes'] = failedRules.map((rule) => rule.errorMessage).join(' and ');
47
+ }
48
+ else if (validate.operator === 'any') {
49
+ if (regexes.length > failedRules.length) {
50
+ delete this.errorDetails['regexes'];
51
+ }
52
+ else {
53
+ this.errorDetails['regexes'] = failedRules.map((rule) => rule.errorMessage).join(' or ');
54
+ }
55
+ }
56
+ }
57
+ }
58
+ if (validate.maxLength && value.length > validate.maxLength) {
59
+ this.errorDetails['maxLength'] = `Max length is ${validate.maxLength}`;
60
+ }
61
+ else {
62
+ delete this.errorDetails['maxLength'];
63
+ }
64
+ if (validate.minLength && value.length < validate.minLength) {
65
+ this.errorDetails['minLength'] = `Min length is ${validate.minLength}`;
66
+ }
67
+ else {
68
+ delete this.errorDetails['minLength'];
69
+ }
70
+ this.validateRequired(value);
71
+ }
72
+ attach(element) {
73
+ const { inputMask } = this.component;
74
+ this.renderComponentToElement(React.createElement("div", null,
75
+ React.createElement(FieldWrapper, Object.assign({}, this.component, { onChange: this.handleChange, errorMessage: Object.values(this.errorDetails).join(', ') }),
76
+ React.createElement(FormField, Object.assign({}, this.component, { mask: inputMask })))), element);
77
+ super.attach(element);
78
+ }
79
+ }
80
+ export default Text;
@@ -0,0 +1,37 @@
1
+ /// <reference types="react" />
2
+ import Boolean from './Boolean';
3
+ import DateTime from './DateTime';
4
+ import DateField from './Date';
5
+ import Select from './Select';
6
+ import Text from './Text';
7
+ import Decimal from './Decimal';
8
+ import Integer from './Integer';
9
+ import Buttons from './Buttons';
10
+ import Button from './Button';
11
+ import { addSharedCustomizations } from './SharedCustomizations';
12
+ export declare const FormComponents: {
13
+ Boolean: typeof Boolean;
14
+ DateTime: typeof DateTime;
15
+ DateField: typeof DateField;
16
+ Select: typeof Select;
17
+ Text: typeof Text;
18
+ Decimal: typeof Decimal;
19
+ Integer: typeof Integer;
20
+ Button: typeof Button;
21
+ Buttons: typeof Buttons;
22
+ FieldWrapper: (props: {
23
+ label: string;
24
+ description?: string | undefined;
25
+ tooltip?: string | undefined;
26
+ prefix?: string | undefined;
27
+ suffix?: string | undefined;
28
+ value?: string | undefined;
29
+ validate: any;
30
+ errorMessage: string;
31
+ showCharCount?: boolean | undefined;
32
+ type: string;
33
+ onChange: Function;
34
+ children: any;
35
+ }) => JSX.Element;
36
+ addSharedCustomizations: typeof addSharedCustomizations;
37
+ };
@@ -0,0 +1,24 @@
1
+ import Boolean from './Boolean';
2
+ import DateTime from './DateTime';
3
+ import DateField from './Date';
4
+ import Select from './Select';
5
+ import Text from './Text';
6
+ import Decimal from './Decimal';
7
+ import Integer from './Integer';
8
+ import Buttons from './Buttons';
9
+ import Button from './Button';
10
+ import { addSharedCustomizations } from './SharedCustomizations';
11
+ import FieldWrapper from './FieldWrapper';
12
+ export const FormComponents = {
13
+ Boolean,
14
+ DateTime,
15
+ DateField,
16
+ Select,
17
+ Text,
18
+ Decimal,
19
+ Integer,
20
+ Button,
21
+ Buttons,
22
+ FieldWrapper,
23
+ addSharedCustomizations,
24
+ };
@@ -1,6 +1,7 @@
1
- export { ClickAwayListener, FormControlProps, FormHelperTextProps, GridSize, Toolbar, createTheme } from '@mui/material';
1
+ export { ClickAwayListener, FormControlProps, FormHelperTextProps, GridSize, Toolbar, createTheme, } from '@mui/material';
2
2
  export { CalendarPicker, DateTimePicker, MonthPicker, PickersDay, StaticDateTimePicker, StaticTimePicker, TimePicker, YearPicker, } from '@mui/x-date-pickers';
3
+ export { FormComponents } from './form-components';
3
4
  export * from './components/core';
4
- export { CriteriaBuilder, DataGrid, FormField, MenuBar, MultiSelect, RepeatableField, UserAvatar } from './components/custom';
5
+ export { CriteriaBuilder, DataGrid, FormField, MenuBar, MultiSelect, RepeatableField, UserAvatar, } from './components/custom';
5
6
  export { Box, Container, Grid, Stack } from './components/layout';
6
7
  export * from './util';
@@ -1,6 +1,7 @@
1
- export { ClickAwayListener, Toolbar, createTheme } from '@mui/material';
1
+ export { ClickAwayListener, Toolbar, createTheme, } from '@mui/material';
2
2
  export { CalendarPicker, DateTimePicker, MonthPicker, PickersDay, StaticDateTimePicker, StaticTimePicker, TimePicker, YearPicker, } from '@mui/x-date-pickers';
3
+ export { FormComponents } from './form-components';
3
4
  export * from './components/core';
4
- export { CriteriaBuilder, DataGrid, FormField, MenuBar, MultiSelect, RepeatableField, UserAvatar } from './components/custom';
5
+ export { CriteriaBuilder, DataGrid, FormField, MenuBar, MultiSelect, RepeatableField, UserAvatar, } from './components/custom';
5
6
  export { Box, Container, Grid, Stack } from './components/layout';
6
7
  export * from './util';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evoke-platform/ui-components",
3
- "version": "1.0.0-dev.123",
3
+ "version": "1.0.0-dev.124",
4
4
  "description": "",
5
5
  "main": "dist/published/index.js",
6
6
  "module": "dist/published/index.js",
@@ -72,6 +72,7 @@
72
72
  "@mui/x-date-pickers": "^5.0.13",
73
73
  "@react-querybuilder/dnd": "^5.4.1",
74
74
  "@react-querybuilder/material": "^5.4.1",
75
+ "formiojs": "^4.15.0-rc.23",
75
76
  "lodash-es": "^4.17.21",
76
77
  "react-dropzone": "^14.2.2",
77
78
  "react-input-mask": "^2.0.4",