@lunit/oui 2.0.0 → 2.0.1

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,20 +1,29 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef, useRef, useState } from 'react';
2
+ import { forwardRef, useState } from 'react';
3
3
  import { InputMsg, BaseTextFieldContainer, BaseTextFieldBox, } from '../../BaseTextField/BaseTextField.styled';
4
4
  import { BaseTextInput, LeftIconContainer, RightIconContainer } from '../TextInput.styled';
5
5
  import { FileInputWrapperButton } from './Buttons';
6
6
  import { Project } from '../../../icons';
7
+ import { uniqueId } from 'lodash';
7
8
  const FileInput = forwardRef((props, ref) => {
8
9
  const { error, helperMsg, leftIcon, rightIcon, onClearButtonClick, inputSX, type: inputType, ...inputProps } = props;
10
+ // Unique ID used to select hidden file input and click on it
11
+ const uID = uniqueId('hidden-file-input-');
9
12
  const [fileName, setFileName] = useState('');
10
- const fileRef = useRef(null);
11
13
  const baseSX = inputSX ?? {
12
14
  paddingRight: '44px',
13
15
  pointerEvents: 'none',
16
+ width: '100%',
14
17
  };
15
- return (_jsxs(BaseTextFieldBox, { ...props.OuterBoxProps, width: props.width, children: [_jsxs(BaseTextFieldContainer, { ...props.InputContainerProps, width: props.width, children: [leftIcon && (_jsx(LeftIconContainer, { sx: inputProps.disabled ? { opacity: '0.8' } : undefined, children: leftIcon })), _jsx("input", { ref: fileRef, type: "file", accept: props.accept, style: { display: 'none' }, onChange: (e) => {
18
+ const handleButtonClicksFile = () => {
19
+ const fileInput = document.getElementsByName(uID);
20
+ if (!fileInput.length)
21
+ return;
22
+ fileInput[0].click();
23
+ };
24
+ return (_jsxs(BaseTextFieldBox, { ...props.OuterBoxProps, width: props.width, children: [_jsxs(BaseTextFieldContainer, { ...props.InputContainerProps, width: props.width, children: [leftIcon && (_jsx(LeftIconContainer, { sx: inputProps.disabled ? { opacity: '0.8' } : undefined, children: leftIcon })), _jsx("input", { ref: ref, type: "file", name: uID, accept: props.accept, style: { display: 'none' }, onChange: (e) => {
16
25
  setFileName(e.target.value.split('\\').pop());
17
- } }), _jsxs(FileInputWrapperButton, { onClick: () => fileRef?.current?.click(), width: props.width, children: [_jsx(BaseTextInput, { ...inputProps, ref: ref, type: "text", error: !!error, value: fileName,
26
+ } }), _jsxs(FileInputWrapperButton, { onClick: () => handleButtonClicksFile(), width: props.width, children: [_jsx(BaseTextInput, { ...inputProps, type: "text", error: !!error, value: fileName,
18
27
  // @Tobio89: this dummy onchange clears an error without triggering unwanted style changes
19
28
  onChange: () => { }, leftIcon: leftIcon, sx: baseSX }), _jsx(RightIconContainer, { children: _jsx(Project, {}) })] })] }), error ? (_jsx(InputMsg, { variant: "body5", error: true, children: error })) : (helperMsg && _jsx(InputMsg, { variant: "body5", children: helperMsg }))] }));
20
29
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunit/oui",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "validate-branch-name": {
5
5
  "pattern": "^(main|develop)|(feature|fix|release|hotfix|qe)/.+$",
6
6
  "errorMsg": "The branch name is not correct. Please check the pattern. (ex. feature/add-something)"