@weareconceptstudio/form 0.1.2 → 0.1.3

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.
@@ -0,0 +1,7 @@
1
+ export function useFormContext(): any;
2
+ export function FormProvider({ fontFamily, children, selectIcon }: {
3
+ fontFamily?: string;
4
+ children: any;
5
+ selectIcon: any;
6
+ }): React.JSX.Element;
7
+ import React from 'react';
@@ -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
+ };
@@ -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: "form-item-row" },
23
- label ? (React.createElement("div", { className: "form-item-label" },
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: "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" }) }))));
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;
@@ -4,6 +4,8 @@ export const validationPatterns = ({ type, pattern, message, translate }) => {
4
4
  switch (type) {
5
5
  case 'email':
6
6
  return { value: /^[^\s@]+@[^\s@]+\.[^\s@]+$/g, message: message || translate('validateMessages.email') };
7
+ case 'password':
8
+ return { value: /(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}/, message: message || translate('validateMessages.password') };
7
9
  case 'number':
8
10
  return { value: /[0-9]/g, message };
9
11
  default:
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './FormConfig';
1
+ export * from './FormProvider';
2
2
  export { default as Form } from './form';
3
3
  export { default as FormBuilder } from './form/Builder';
4
4
  export { default as ErrorMessage } from './error-message';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- export * from './FormConfig';
2
+ export * from './FormProvider';
3
3
  export { default as Form } from './form';
4
4
  export { default as FormBuilder } from './form/Builder';
5
5
  export { default as ErrorMessage } from './error-message';
@@ -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 = {
@@ -5,6 +5,7 @@ declare const _default: {
5
5
  default: string;
6
6
  required: string;
7
7
  email: string;
8
+ password: string;
8
9
  enum: string;
9
10
  whitespace: string;
10
11
  date: {
@@ -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: {
@@ -5,6 +5,7 @@ declare const _default: {
5
5
  default: string;
6
6
  required: string;
7
7
  email: string;
8
+ password: string;
8
9
  enum: string;
9
10
  whitespace: string;
10
11
  date: {
@@ -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: {
@@ -5,6 +5,7 @@ declare const _default: {
5
5
  default: string;
6
6
  required: string;
7
7
  email: string;
8
+ password: string;
8
9
  enum: string;
9
10
  whitespace: string;
10
11
  date: {
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weareconceptstudio/form",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Concept Studio Form",
5
5
  "author": "Concept Studio",
6
6
  "license": "ISC",
@@ -1,5 +0,0 @@
1
- export function FormConfig({ fontFamily, children }: {
2
- fontFamily?: string;
3
- children: any;
4
- }): React.JSX.Element;
5
- import React from 'react';
@@ -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
- };