@groupeactual/ui-kit 0.4.2 → 0.4.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/index.d.ts CHANGED
@@ -40,8 +40,9 @@ interface Props$4 {
40
40
  disabled?: boolean;
41
41
  isValid?: boolean;
42
42
  endAdornment?: ReactNode;
43
+ maxLength?: number;
43
44
  }
44
- declare const TextField: ({ name, value, error, onBlur, onChange, label, disabled, endAdornment, isValid, placeholder, ...props }: Omit<TextFieldProps, 'error'> & Props$4) => JSX.Element;
45
+ declare const TextField: ({ name, value, error, onBlur, onChange, label, disabled, endAdornment, isValid, placeholder, maxLength, ...props }: Omit<TextFieldProps, 'error'> & Props$4) => JSX.Element;
45
46
 
46
47
  interface Props$3 {
47
48
  error?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@groupeactual/ui-kit",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "A simple template for a custom React component library",
5
5
  "devDependencies": {
6
6
  "@babel/core": "^7.20.5",
@@ -7,6 +7,7 @@ import {
7
7
  } from 'react';
8
8
 
9
9
  import MuiTextField, { TextFieldProps } from '@mui/material/TextField';
10
+ import { Table } from '@mui/material';
10
11
 
11
12
  interface Props {
12
13
  error?: string;
@@ -19,6 +20,7 @@ interface Props {
19
20
  disabled?: boolean;
20
21
  isValid?: boolean;
21
22
  endAdornment?: ReactNode;
23
+ maxLength?: number;
22
24
  }
23
25
  const TextField = ({
24
26
  name,
@@ -31,6 +33,7 @@ const TextField = ({
31
33
  endAdornment,
32
34
  isValid,
33
35
  placeholder = '',
36
+ maxLength,
34
37
  ...props
35
38
  }: Omit<TextFieldProps, 'error'> & Props): JSX.Element => {
36
39
  const [internalValue, setInternalValue] = useState(value);
@@ -47,11 +50,9 @@ const TextField = ({
47
50
  label={label}
48
51
  value={internalValue}
49
52
  placeholder={placeholder}
53
+ FormHelperTextProps={{ component: 'div' } as any}
50
54
  InputLabelProps={{ shrink: true }}
51
55
  onClick={(e) => e.stopPropagation()}
52
- InputProps={{
53
- endAdornment
54
- }}
55
56
  onChange={(e) => {
56
57
  setInternalValue(e.currentTarget.value);
57
58
  onChange(e);
@@ -60,9 +61,29 @@ const TextField = ({
60
61
  onBlur(e);
61
62
  }}
62
63
  error={!!error}
63
- helperText={error ?? ''}
64
64
  disabled={disabled}
65
+ InputProps={{ endAdornment }}
66
+ inputProps={{ maxLength }}
65
67
  {...props}
68
+ helperText={
69
+ <div style={{ display: 'table', width: '100%' }}>
70
+ {(error || props.helperText) && (
71
+ <div
72
+ style={{
73
+ display: maxLength ? 'table-cell' : '',
74
+ float: 'left'
75
+ }}
76
+ >
77
+ {error || props.helperText}
78
+ </div>
79
+ )}
80
+ {maxLength && (
81
+ <div style={{ display: 'table-cell', float: 'right' }}>
82
+ {internalValue.length}/{maxLength} caract.
83
+ </div>
84
+ )}
85
+ </div>
86
+ }
66
87
  />
67
88
  );
68
89
  };