@weareconceptstudio/form 0.1.6 → 0.1.8
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.
- package/dist/error-message/index.d.ts +1 -8
- package/dist/error-message/index.js +5 -4
- package/dist/form/Builder/style.js +16 -1
- package/dist/form/Item/index.js +12 -5
- package/dist/input/Input.d.ts +1 -4
- package/dist/input/Input.js +4 -3
- package/dist/input/TextArea/index.d.ts +1 -4
- package/dist/input/TextArea/index.js +4 -3
- package/dist/select/index.js +2 -2
- package/dist/styles/formStyle.js +20 -5
- package/dist/upload/UploadButton/index.js +1 -1
- package/dist/upload/utils.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
export default ErrorMessage;
|
|
2
|
-
declare function ErrorMessage(
|
|
3
|
-
[x: string]: any;
|
|
4
|
-
as: any;
|
|
5
|
-
errors: any;
|
|
6
|
-
name: any;
|
|
7
|
-
message: any;
|
|
8
|
-
render: any;
|
|
9
|
-
}): any;
|
|
2
|
+
declare function ErrorMessage(props: any): any;
|
|
10
3
|
declare namespace ErrorMessage {
|
|
11
4
|
let displayName: string;
|
|
12
5
|
}
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import React, { Fragment, isValidElement, cloneElement, createElement } from 'react';
|
|
2
2
|
import { useFormContext, get } from 'react-hook-form';
|
|
3
|
-
const ErrorMessage = (
|
|
3
|
+
const ErrorMessage = (props) => {
|
|
4
|
+
const { as, errors, name, message, render, ...rest } = props;
|
|
4
5
|
const methods = useFormContext();
|
|
5
6
|
const error = get(errors || methods.formState.errors, name);
|
|
6
7
|
if (!error) {
|
|
7
8
|
return null;
|
|
8
9
|
}
|
|
9
10
|
const { message: messageFromRegister, types } = error;
|
|
10
|
-
const
|
|
11
|
+
const inlineProps = Object.assign({}, rest, {
|
|
11
12
|
children: messageFromRegister || message,
|
|
12
13
|
});
|
|
13
14
|
return isValidElement(as)
|
|
14
|
-
? cloneElement(as,
|
|
15
|
+
? cloneElement(as, inlineProps)
|
|
15
16
|
: render
|
|
16
17
|
? render({
|
|
17
18
|
message: messageFromRegister || message,
|
|
18
19
|
messages: types,
|
|
19
20
|
})
|
|
20
|
-
: createElement(as || Fragment,
|
|
21
|
+
: createElement(as || Fragment, inlineProps);
|
|
21
22
|
};
|
|
22
23
|
if (process.env.NODE_ENV !== 'production') {
|
|
23
24
|
ErrorMessage.displayName = 'ErrorMessage';
|
|
@@ -1,3 +1,18 @@
|
|
|
1
1
|
import styled from 'styled-components';
|
|
2
|
-
const BuilderStyle = styled.div
|
|
2
|
+
const BuilderStyle = styled.div `
|
|
3
|
+
.react-select__value-container {
|
|
4
|
+
input {
|
|
5
|
+
width: unset !important;
|
|
6
|
+
background-color: unset !important;
|
|
7
|
+
color: unset !important;
|
|
8
|
+
font-size: unset !important;
|
|
9
|
+
line-height: unset !important;
|
|
10
|
+
font-family: unset !important;
|
|
11
|
+
font-weight: unset !important;
|
|
12
|
+
border-radius: unset !important;
|
|
13
|
+
border: unset !important;
|
|
14
|
+
padding: unset !important;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
3
18
|
export default BuilderStyle;
|
package/dist/form/Item/index.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import React, { cloneElement, isValidElement } from 'react';
|
|
1
|
+
import React, { cloneElement, isValidElement, useRef } from 'react';
|
|
2
2
|
import lodashGet from 'lodash.get';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
|
-
import { useTranslation } from '@weareconceptstudio/core';
|
|
4
|
+
import { isForwardRefChild, useTranslation } from '@weareconceptstudio/core';
|
|
5
5
|
import ErrorMessage from '../../error-message';
|
|
6
6
|
import { useInput } from '../hooks/useInput';
|
|
7
7
|
import { useRules } from '../hooks/rules';
|
|
8
8
|
const FormItem = ({ label, name, children, className, errorKey, required = true, requiredMessage, rules = [] }) => {
|
|
9
|
+
if (!isValidElement(children)) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const childRef = useRef(null);
|
|
9
13
|
const { translate } = useTranslation();
|
|
10
14
|
const { formState } = useInput({
|
|
11
15
|
name,
|
|
@@ -15,7 +19,7 @@ const FormItem = ({ label, name, children, className, errorKey, required = true,
|
|
|
15
19
|
requiredMessage,
|
|
16
20
|
errorKey: errorKey || label,
|
|
17
21
|
// @ts-ignore
|
|
18
|
-
childType:
|
|
22
|
+
childType: childRef?.current?.childType || '',
|
|
19
23
|
}),
|
|
20
24
|
errorKey: errorKey || label,
|
|
21
25
|
});
|
|
@@ -23,15 +27,18 @@ const FormItem = ({ label, name, children, className, errorKey, required = true,
|
|
|
23
27
|
const classString = classNames('form-item', {
|
|
24
28
|
[className]: className,
|
|
25
29
|
'has-error': hasError,
|
|
26
|
-
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
disabled: children.props.disabled,
|
|
27
32
|
});
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
const inlineProps = isForwardRefChild(children) ? { ref: childRef, name } : { name };
|
|
28
35
|
return (React.createElement("div", { className: classString },
|
|
29
36
|
React.createElement("div", { className: 'form-item-row' },
|
|
30
37
|
label ? (React.createElement("div", { className: 'form-item-label' },
|
|
31
38
|
React.createElement("label", { htmlFor: name, "data-required": required },
|
|
32
39
|
translate(label),
|
|
33
40
|
required ? React.createElement("span", { className: 'required-symbol' }, "*") : null))) : null,
|
|
34
|
-
React.createElement("div", { className: 'form-item-control' },
|
|
41
|
+
React.createElement("div", { className: 'form-item-control' }, cloneElement(children, inlineProps)),
|
|
35
42
|
React.createElement(ErrorMessage, { name: name, as: React.createElement("div", { className: 'error-message' }) }))));
|
|
36
43
|
};
|
|
37
44
|
export default FormItem;
|
package/dist/input/Input.d.ts
CHANGED
package/dist/input/Input.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { forwardRef, useImperativeHandle } from 'react';
|
|
2
2
|
import BaseInput from './BaseInput';
|
|
3
3
|
import { useInput } from '../form/hooks/useInput';
|
|
4
4
|
import { useTranslation } from '@weareconceptstudio/core';
|
|
5
|
-
const Input = (props) => {
|
|
5
|
+
const Input = forwardRef((props, ref) => {
|
|
6
|
+
useImperativeHandle(ref, () => ({ childType: 'input' }));
|
|
6
7
|
const { name, autoComplete = 'new-password', onChange, onFocus, onBlur, onKeyDown, onKeyUp, disabled, className, type = 'text', placeholder } = props;
|
|
7
8
|
const { translate } = useTranslation();
|
|
8
9
|
const { field } = useInput({
|
|
@@ -13,7 +14,7 @@ const Input = (props) => {
|
|
|
13
14
|
});
|
|
14
15
|
return (React.createElement(BaseInput, { ...props, value: field.value, disabled: disabled },
|
|
15
16
|
React.createElement("input", { type: type, onFocus: onFocus, onKeyUp: onKeyUp, disabled: disabled, className: className, onKeyDown: onKeyDown, placeholder: translate(placeholder), autoComplete: autoComplete, ...field })));
|
|
16
|
-
};
|
|
17
|
+
});
|
|
17
18
|
if (process.env.NODE_ENV !== 'production') {
|
|
18
19
|
Input.displayName = 'Input';
|
|
19
20
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { forwardRef, useImperativeHandle } from 'react';
|
|
2
2
|
import BaseInput from '../BaseInput';
|
|
3
3
|
import { useInput } from '../../form/hooks/useInput';
|
|
4
4
|
import { useTranslation } from '@weareconceptstudio/core';
|
|
5
|
-
const TextArea = (props) => {
|
|
5
|
+
const TextArea = forwardRef((props, ref) => {
|
|
6
|
+
useImperativeHandle(ref, () => ({ childType: 'textarea' }));
|
|
6
7
|
const { translate } = useTranslation();
|
|
7
8
|
const { name, placeholder, rows = 5, onChange, onFocus, onBlur, onKeyDown, onKeyUp, disabled, className, autoComplete } = props;
|
|
8
9
|
const input = name ? useInput({ name, onChange, onBlur }) : null;
|
|
@@ -12,7 +13,7 @@ const TextArea = (props) => {
|
|
|
12
13
|
};
|
|
13
14
|
return (React.createElement(BaseInput, { ...props },
|
|
14
15
|
React.createElement("textarea", { ...field, rows: rows, onFocus: onFocus, onKeyUp: onKeyUp, disabled: disabled, className: className, onKeyDown: onKeyDown, autoComplete: autoComplete, placeholder: translate(placeholder) })));
|
|
15
|
-
};
|
|
16
|
+
});
|
|
16
17
|
if (process.env.NODE_ENV !== 'production') {
|
|
17
18
|
TextArea.displayName = 'TextArea';
|
|
18
19
|
}
|
package/dist/select/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import useFormInstance from '../form/hooks/useFormInstance';
|
|
|
7
7
|
import { useTranslation } from '@weareconceptstudio/core';
|
|
8
8
|
import { useFormContext } from '../FormProvider';
|
|
9
9
|
const Select = (props) => {
|
|
10
|
-
const { name, placeholder, value, onChange, multiple = false, allowClear = false, allowSearch =
|
|
10
|
+
const { name, placeholder, value, onChange, multiple = false, allowClear = false, allowSearch = false, disabled = false, loading = false, options: list = [], className, select_arrow = false, select_empty = false, optionKey, optionValue, optGroup } = props;
|
|
11
11
|
const { selectIcon } = useFormContext();
|
|
12
12
|
const { translate } = useTranslation();
|
|
13
13
|
const formInstance = useFormInstance();
|
|
@@ -58,7 +58,7 @@ const Select = (props) => {
|
|
|
58
58
|
const customStyles = {
|
|
59
59
|
menuList: (provided) => ({
|
|
60
60
|
...provided,
|
|
61
|
-
maxHeight: '
|
|
61
|
+
maxHeight: '200px',
|
|
62
62
|
}),
|
|
63
63
|
};
|
|
64
64
|
const options = useMemo(() => {
|
package/dist/styles/formStyle.js
CHANGED
|
@@ -226,9 +226,11 @@ const FormStyle = createGlobalStyle `${css `
|
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
/* //! Hover */
|
|
229
|
-
@media (
|
|
230
|
-
|
|
231
|
-
|
|
229
|
+
@media (pointer: fine) {
|
|
230
|
+
@media (hover: hover) {
|
|
231
|
+
&:hover {
|
|
232
|
+
border-color: var(--form_selectBorderHoverColor);
|
|
233
|
+
}
|
|
232
234
|
}
|
|
233
235
|
}
|
|
234
236
|
|
|
@@ -291,8 +293,16 @@ const FormStyle = createGlobalStyle `${css `
|
|
|
291
293
|
padding: var(--form_inputPadTBL) var(--form_inputPadR) var(--form_inputPadTBL) var(--form_inputPadTBL);
|
|
292
294
|
background-color: var(--form_selectOptionBgColor);
|
|
293
295
|
|
|
294
|
-
&.react-select__option--is-focused {
|
|
296
|
+
/* &.react-select__option--is-focused {
|
|
295
297
|
background-color: var(--form_selectOptionFocusBgColor);
|
|
298
|
+
} */
|
|
299
|
+
|
|
300
|
+
@media (pointer: fine) {
|
|
301
|
+
@media (hover: hover) {
|
|
302
|
+
&:hover {
|
|
303
|
+
background-color: var(--form_selectOptionFocusBgColor);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
296
306
|
}
|
|
297
307
|
|
|
298
308
|
&.react-select__option--is-selected {
|
|
@@ -368,7 +378,7 @@ const FormStyle = createGlobalStyle `${css `
|
|
|
368
378
|
input:not(input[type='radio']),
|
|
369
379
|
textarea {
|
|
370
380
|
background-color: var(--form_inputErrorBgColor);
|
|
371
|
-
border: 2px solid var(--form_inputBorderErrorColor);
|
|
381
|
+
border: 2px solid var(--form_inputBorderErrorColor) !important;
|
|
372
382
|
color: var(--form_inputErrorColor);
|
|
373
383
|
|
|
374
384
|
&::placeholder {
|
|
@@ -395,6 +405,11 @@ const FormStyle = createGlobalStyle `${css `
|
|
|
395
405
|
font-weight: 400;
|
|
396
406
|
color: var(--form_errorMessageColor);
|
|
397
407
|
transform: translateY(var(--form_errorDistance));
|
|
408
|
+
text-transform: lowercase;
|
|
409
|
+
|
|
410
|
+
&::first-letter {
|
|
411
|
+
text-transform: uppercase;
|
|
412
|
+
}
|
|
398
413
|
}
|
|
399
414
|
|
|
400
415
|
/* //! Disabled Styles */
|
|
@@ -3,7 +3,7 @@ import { rawFileToAsset } from '../utils';
|
|
|
3
3
|
import UploadButtonStyle from './style';
|
|
4
4
|
const UploadButton = (props) => {
|
|
5
5
|
const { accept, disabled, multiple, setFileList } = props;
|
|
6
|
-
const inputRef = useRef();
|
|
6
|
+
const inputRef = useRef(null);
|
|
7
7
|
const handleFiles = async (files) => {
|
|
8
8
|
const newFiles = [];
|
|
9
9
|
for (let i = 0; i < files.length; i++) {
|
package/dist/upload/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function typeFromMime(mime: any): "
|
|
1
|
+
export function typeFromMime(mime: any): "audio" | "video" | "image" | "document" | "pdf";
|
|
2
2
|
export function rawFileToAsset({ rawFile, isReplace }: {
|
|
3
3
|
rawFile: any;
|
|
4
4
|
isReplace?: boolean;
|