@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.
@@ -1,12 +1,5 @@
1
1
  export default ErrorMessage;
2
- declare function ErrorMessage({ as, errors, name, message, render, ...rest }: {
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 = ({ as, errors, name, message, render, ...rest }) => {
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 props = Object.assign({}, rest, {
11
+ const inlineProps = Object.assign({}, rest, {
11
12
  children: messageFromRegister || message,
12
13
  });
13
14
  return isValidElement(as)
14
- ? cloneElement(as, props)
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, props);
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;
@@ -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: children?.type?.displayName || children?.type?.name || '',
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
- disabled: isValidElement(children) && children.props.disabled,
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' }, isValidElement(children) && cloneElement(children, { name })),
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;
@@ -1,6 +1,3 @@
1
1
  export default Input;
2
- declare function Input(props: any): React.JSX.Element;
3
- declare namespace Input {
4
- let displayName: string;
5
- }
2
+ declare const Input: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
6
3
  import React from 'react';
@@ -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,6 +1,3 @@
1
1
  export default TextArea;
2
- declare function TextArea(props: any): React.JSX.Element;
3
- declare namespace TextArea {
4
- let displayName: string;
5
- }
2
+ declare const TextArea: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
6
3
  import React from 'react';
@@ -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
  }
@@ -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 = true, disabled = false, loading = false, options: list = [], className, select_arrow = false, select_empty = false, optionKey, optionValue, optGroup } = props;
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: '144px',
61
+ maxHeight: '200px',
62
62
  }),
63
63
  };
64
64
  const options = useMemo(() => {
@@ -226,9 +226,11 @@ const FormStyle = createGlobalStyle `${css `
226
226
  }
227
227
 
228
228
  /* //! Hover */
229
- @media (hover: hover) {
230
- &:hover {
231
- border-color: var(--form_selectBorderHoverColor);
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++) {
@@ -1,4 +1,4 @@
1
- export function typeFromMime(mime: any): "document" | "image" | "video" | "audio" | "pdf";
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weareconceptstudio/form",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Concept Studio Form",
5
5
  "author": "Concept Studio",
6
6
  "license": "ISC",