@weareconceptstudio/form 0.1.2 → 0.1.4
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/FormProvider.d.ts +7 -0
- package/dist/FormProvider.js +25 -0
- package/dist/form/Item/index.js +6 -6
- package/dist/form/hooks/rules.js +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/select/index.js +3 -1
- package/dist/translations/en.d.ts +1 -0
- package/dist/translations/en.js +1 -0
- package/dist/translations/hy.d.ts +1 -0
- package/dist/translations/hy.js +1 -0
- package/dist/translations/index.d.ts +3 -0
- package/dist/translations/ru.d.ts +1 -0
- package/dist/translations/ru.js +1 -0
- package/package.json +1 -1
- package/dist/FormConfig.d.ts +0 -5
- package/dist/FormConfig.js +0 -19
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React, { useEffect, createContext, useContext } from 'react';
|
|
2
|
+
import { useTranslation } from '@weareconceptstudio/core';
|
|
3
|
+
import { ThemeProvider } from 'styled-components';
|
|
4
|
+
//* Translations
|
|
5
|
+
import translations from './translations';
|
|
6
|
+
//* Styles
|
|
7
|
+
import FormTheme from './styles/theme';
|
|
8
|
+
import FormVariables from './styles/variables';
|
|
9
|
+
import FormStyle from './styles/formStyle';
|
|
10
|
+
const FormContext = createContext(null);
|
|
11
|
+
export const useFormContext = () => {
|
|
12
|
+
const context = useContext(FormContext);
|
|
13
|
+
return context;
|
|
14
|
+
};
|
|
15
|
+
export const FormProvider = ({ fontFamily = 'core_Font', children, selectIcon }) => {
|
|
16
|
+
const { addTranslation } = useTranslation();
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
addTranslation(translations, 'prepend');
|
|
19
|
+
}, []);
|
|
20
|
+
return (React.createElement(FormContext.Provider, { value: { selectIcon } },
|
|
21
|
+
React.createElement(ThemeProvider, { theme: FormTheme },
|
|
22
|
+
React.createElement(FormVariables, { fontFamily: fontFamily }),
|
|
23
|
+
React.createElement(FormStyle, null),
|
|
24
|
+
children)));
|
|
25
|
+
};
|
package/dist/form/Item/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { 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
|
-
const FormItem = ({ label, name, children, className, errorKey, required = true, requiredMessage, rules = []
|
|
8
|
+
const FormItem = ({ label, name, children, className, errorKey, required = true, requiredMessage, rules = [] }) => {
|
|
9
9
|
const { translate } = useTranslation();
|
|
10
10
|
const { formState } = useInput({
|
|
11
11
|
name,
|
|
@@ -19,12 +19,12 @@ const FormItem = ({ label, name, children, className, errorKey, required = true,
|
|
|
19
19
|
disabled: isValidElement(children) && children.props.disabled,
|
|
20
20
|
});
|
|
21
21
|
return (React.createElement("div", { className: classString },
|
|
22
|
-
React.createElement("div", { className:
|
|
23
|
-
label ? (React.createElement("div", { className:
|
|
22
|
+
React.createElement("div", { className: 'form-item-row' },
|
|
23
|
+
label ? (React.createElement("div", { className: 'form-item-label' },
|
|
24
24
|
React.createElement("label", { htmlFor: name, "data-required": required },
|
|
25
25
|
translate(label),
|
|
26
|
-
required ? React.createElement("span", { className:
|
|
27
|
-
React.createElement("div", { className:
|
|
28
|
-
React.createElement(ErrorMessage, { name: name, as: React.createElement("div", { className:
|
|
26
|
+
required ? React.createElement("span", { className: 'required-symbol' }, "*") : null))) : null,
|
|
27
|
+
React.createElement("div", { className: 'form-item-control' }, isValidElement(children) && cloneElement(children, { name })),
|
|
28
|
+
React.createElement(ErrorMessage, { name: name, as: React.createElement("div", { className: 'error-message' }) }))));
|
|
29
29
|
};
|
|
30
30
|
export default FormItem;
|
package/dist/form/hooks/rules.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import React, { useMemo } from 'react';
|
|
2
2
|
import { useTranslation } from '@weareconceptstudio/core';
|
|
3
3
|
export const validationPatterns = ({ type, pattern, message, translate }) => {
|
|
4
|
+
console.log({ type });
|
|
4
5
|
switch (type) {
|
|
5
6
|
case 'email':
|
|
6
7
|
return { value: /^[^\s@]+@[^\s@]+\.[^\s@]+$/g, message: message || translate('validateMessages.email') };
|
|
8
|
+
case 'new-password':
|
|
9
|
+
return { value: /(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}/, message: message || translate('validateMessages.password') };
|
|
7
10
|
case 'number':
|
|
8
11
|
return { value: /[0-9]/g, message };
|
|
9
12
|
default:
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/select/index.js
CHANGED
|
@@ -5,8 +5,10 @@ import { bottom_arrow, empty } from './icons';
|
|
|
5
5
|
import { useInput } from '../form/hooks/useInput';
|
|
6
6
|
import useFormInstance from '../form/hooks/useFormInstance';
|
|
7
7
|
import { useTranslation } from '@weareconceptstudio/core';
|
|
8
|
+
import { useFormContext } from '../FormProvider';
|
|
8
9
|
const Select = (props) => {
|
|
9
10
|
const { name, placeholder, value, onChange, multiple = false, allowClear = false, allowSearch = true, disabled = false, loading = false, options: list = [], className, select_arrow = false, select_empty = false, optionKey, optionValue, optGroup } = props;
|
|
11
|
+
const { selectIcon } = useFormContext();
|
|
10
12
|
const { translate } = useTranslation();
|
|
11
13
|
const formInstance = useFormInstance();
|
|
12
14
|
let selectProps = {};
|
|
@@ -39,7 +41,7 @@ const Select = (props) => {
|
|
|
39
41
|
};
|
|
40
42
|
//! Custom DropdownIndicator
|
|
41
43
|
const DropdownIndicator = (props) => {
|
|
42
|
-
return React.createElement(components.DropdownIndicator, { ...props }, select_arrow || bottom_arrow);
|
|
44
|
+
return React.createElement(components.DropdownIndicator, { ...props }, selectIcon || select_arrow || bottom_arrow);
|
|
43
45
|
};
|
|
44
46
|
//! Custom Components
|
|
45
47
|
const customComponents = {
|
package/dist/translations/en.js
CHANGED
|
@@ -5,6 +5,7 @@ export default {
|
|
|
5
5
|
default: 'Validation error on field {errorKey}',
|
|
6
6
|
required: 'Please enter your {errorKey}',
|
|
7
7
|
email: 'Please enter a valid email address',
|
|
8
|
+
password: 'Password must contain lowercase, uppercase, number and has been min 8 characters.',
|
|
8
9
|
enum: '{errorKey} must be one of [{enum}]',
|
|
9
10
|
whitespace: '{errorKey} cannot be empty',
|
|
10
11
|
date: {
|
package/dist/translations/hy.js
CHANGED
|
@@ -5,6 +5,7 @@ export default {
|
|
|
5
5
|
default: 'Դաշտի {errorKey}-ի համար վավերացման սխալ',
|
|
6
6
|
required: 'Խնդրում ենք մուտքագրել ձեր {errorKey}-ը',
|
|
7
7
|
email: 'Խնդրում ենք մուտքագրել վավեր էլ. հասցե:',
|
|
8
|
+
password: 'Գաղտնաբառը պետք է պարունակի փոքրատառեր, մեծատառեր, թիվ և լինի նվազագույնը 8 նիշ:',
|
|
8
9
|
enum: '{errorKey}-ը պետք է լինի [{enum}] արժեքներից մեկը',
|
|
9
10
|
whitespace: '{errorKey}-ը չի կարող դատարկ լինել',
|
|
10
11
|
date: {
|
|
@@ -6,6 +6,7 @@ declare const _default: {
|
|
|
6
6
|
default: string;
|
|
7
7
|
required: string;
|
|
8
8
|
email: string;
|
|
9
|
+
password: string;
|
|
9
10
|
enum: string;
|
|
10
11
|
whitespace: string;
|
|
11
12
|
date: {
|
|
@@ -43,6 +44,7 @@ declare const _default: {
|
|
|
43
44
|
default: string;
|
|
44
45
|
required: string;
|
|
45
46
|
email: string;
|
|
47
|
+
password: string;
|
|
46
48
|
enum: string;
|
|
47
49
|
whitespace: string;
|
|
48
50
|
date: {
|
|
@@ -80,6 +82,7 @@ declare const _default: {
|
|
|
80
82
|
default: string;
|
|
81
83
|
required: string;
|
|
82
84
|
email: string;
|
|
85
|
+
password: string;
|
|
83
86
|
enum: string;
|
|
84
87
|
whitespace: string;
|
|
85
88
|
date: {
|
package/dist/translations/ru.js
CHANGED
|
@@ -5,6 +5,7 @@ export default {
|
|
|
5
5
|
default: 'Ошибка валидации для поля {errorKey}',
|
|
6
6
|
required: 'Пожалуйста, введите ваш {errorKey}',
|
|
7
7
|
email: 'Пожалуйста, введите действительный адрес электронной почты.',
|
|
8
|
+
password: 'Пароль должен содержать строчные и заглавные буквы, цифру и быть не менее 8 символов.',
|
|
8
9
|
enum: '{errorKey} должен быть одним из [{enum}]',
|
|
9
10
|
whitespace: '{errorKey} не может быть пустым',
|
|
10
11
|
date: {
|
package/package.json
CHANGED
package/dist/FormConfig.d.ts
DELETED
package/dist/FormConfig.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from 'react';
|
|
2
|
-
import { useTranslation } from '@weareconceptstudio/core';
|
|
3
|
-
import { ThemeProvider } from 'styled-components';
|
|
4
|
-
//* Translations
|
|
5
|
-
import translations from './translations';
|
|
6
|
-
//* Styles
|
|
7
|
-
import theme from './styles/theme';
|
|
8
|
-
import FormVariables from './styles/variables';
|
|
9
|
-
import FormStyle from './styles/formStyle';
|
|
10
|
-
export const FormConfig = ({ fontFamily = 'core_Font', children }) => {
|
|
11
|
-
const { addTranslation } = useTranslation();
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
addTranslation(translations, 'prepend');
|
|
14
|
-
}, []);
|
|
15
|
-
return (React.createElement(ThemeProvider, { theme: theme },
|
|
16
|
-
React.createElement(FormVariables, { fontFamily: fontFamily }),
|
|
17
|
-
React.createElement(FormStyle, null),
|
|
18
|
-
children));
|
|
19
|
-
};
|