@growy/strapi-plugin-encrypted-field 2.0.5 → 2.0.6
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/admin/src/components/Input.jsx +36 -10
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
2
|
import { useIntl } from 'react-intl';
|
|
3
|
-
import { Field } from '@strapi/design-system';
|
|
3
|
+
import { Field, Flex, IconButton } from '@strapi/design-system';
|
|
4
|
+
import { Eye, EyeStriked, Duplicate } from '@strapi/icons';
|
|
4
5
|
|
|
5
6
|
const Input = (props) => {
|
|
6
7
|
const {
|
|
@@ -18,6 +19,7 @@ const Input = (props) => {
|
|
|
18
19
|
} = props;
|
|
19
20
|
|
|
20
21
|
const { formatMessage } = useIntl();
|
|
22
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
21
23
|
|
|
22
24
|
const handleChange = (e) => {
|
|
23
25
|
onChange({
|
|
@@ -29,7 +31,16 @@ const Input = (props) => {
|
|
|
29
31
|
});
|
|
30
32
|
};
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
const handleCopy = async () => {
|
|
35
|
+
if (value) {
|
|
36
|
+
await navigator.clipboard.writeText(value);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const toggleVisibility = () => {
|
|
41
|
+
setIsVisible(!isVisible);
|
|
42
|
+
};
|
|
43
|
+
|
|
33
44
|
const fieldName = name.includes('.') ? name.split('.').pop() : name;
|
|
34
45
|
const label = intlLabel?.id ? formatMessage(intlLabel) : (intlLabel || fieldName);
|
|
35
46
|
|
|
@@ -44,13 +55,28 @@ const Input = (props) => {
|
|
|
44
55
|
<Field.Label action={labelAction}>
|
|
45
56
|
{label}
|
|
46
57
|
</Field.Label>
|
|
47
|
-
<
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
<Flex gap={2}>
|
|
59
|
+
<Field.Input
|
|
60
|
+
type={isVisible ? 'text' : 'password'}
|
|
61
|
+
placeholder={placeholder}
|
|
62
|
+
value={value}
|
|
63
|
+
onChange={handleChange}
|
|
64
|
+
disabled={disabled}
|
|
65
|
+
style={{ flex: 1 }}
|
|
66
|
+
/>
|
|
67
|
+
<IconButton
|
|
68
|
+
onClick={toggleVisibility}
|
|
69
|
+
label={isVisible ? 'Ocultar' : 'Mostrar'}
|
|
70
|
+
icon={isVisible ? <EyeStriked /> : <Eye />}
|
|
71
|
+
disabled={disabled}
|
|
72
|
+
/>
|
|
73
|
+
<IconButton
|
|
74
|
+
onClick={handleCopy}
|
|
75
|
+
label="Copiar"
|
|
76
|
+
icon={<Duplicate />}
|
|
77
|
+
disabled={disabled || !value}
|
|
78
|
+
/>
|
|
79
|
+
</Flex>
|
|
54
80
|
<Field.Hint />
|
|
55
81
|
<Field.Error />
|
|
56
82
|
</Field.Root>
|