1
1
import React , { useEffect } from 'react' ;
2
+ import { useDispatch } from 'react-redux' ;
2
3
import { THelper } from '@services/Api' ;
4
+ import copyText from '@utils/copyText' ;
3
5
4
6
import Anchor from '@components/Anchor' ;
5
7
import Tooltip from '@components/Tooltip' ;
8
+ import Button from '@components/Button' ;
9
+ import ActionCreator from '@store/actions' ;
6
10
import { AppRoutes , HelperLinks } from '@consts/const' ;
7
11
8
12
type THelperItemProps = {
@@ -12,6 +16,8 @@ type THelperItemProps = {
12
16
13
17
const HelperItem : React . FC < THelperItemProps > = ( { helper, isOpen} ) => {
14
18
19
+ const dispatch = useDispatch ( ) ;
20
+
15
21
const codeLinesCount = ( helper . usage . match ( / \n / g) || [ ] ) . length + 1 ;
16
22
17
23
useEffect ( ( ) => {
@@ -24,6 +30,15 @@ const HelperItem: React.FC<THelperItemProps> = ({helper, isOpen}) => {
24
30
} catch ( e ) { }
25
31
} , [ ] ) ;
26
32
33
+ const copyClickHandler = ( text : string ) => {
34
+ const isCopied = copyText ( text ) ;
35
+ dispatch ( ActionCreator . setInfoMessage ( {
36
+ label : isCopied ? '😊' : '😭' ,
37
+ text : isCopied ? 'Copied' : 'Doesn\'t copied'
38
+ } ) ) ;
39
+ dispatch ( ActionCreator . showMessage ( ) ) ;
40
+ } ;
41
+
27
42
return (
28
43
< details className = "helper" open = { isOpen } >
29
44
< summary >
@@ -54,7 +69,9 @@ const HelperItem: React.FC<THelperItemProps> = ({helper, isOpen}) => {
54
69
</ div >
55
70
</ div >
56
71
< div className = "helper__column" >
57
- < h3 className = "helper__header" > What it used for?</ h3 >
72
+ < div className = "helper__header" >
73
+ < h3 > What it used for?</ h3 >
74
+ </ div >
58
75
< p
59
76
className = "helper__description"
60
77
dangerouslySetInnerHTML = {
@@ -66,7 +83,9 @@ const HelperItem: React.FC<THelperItemProps> = ({helper, isOpen}) => {
66
83
</ p >
67
84
{ helper . demo &&
68
85
< >
69
- < h3 className = "helper__header" > How it works?</ h3 >
86
+ < div className = "helper__header" >
87
+ < h3 > How it works?</ h3 >
88
+ </ div >
70
89
< a className = "helper__demo" href = { `${ HelperLinks . DEMO } /${ helper . demo } ` } target = "_blank" rel = "noreferrer" >
71
90
< img src = { `${ HelperLinks . DEMO } /${ helper . demo } ` } alt = "demo" />
72
91
< svg width = "18" height = "18" >
@@ -78,9 +97,20 @@ const HelperItem: React.FC<THelperItemProps> = ({helper, isOpen}) => {
78
97
</ div >
79
98
</ div >
80
99
< div className = "helper__example" >
81
- < h3 className = "helper__header" > How to use it?</ h3 >
100
+ < div className = "helper__header" >
101
+ < h3 > How to use it?</ h3 >
102
+ {
103
+ helper . usage
104
+ &&
105
+ < Button title = "Copy example code" clickHandler = { ( ) => copyClickHandler ( helper . usage ) } >
106
+ < svg width = "14" height = "14" >
107
+ < use xlinkHref = "#copy" />
108
+ </ svg >
109
+ </ Button >
110
+ }
111
+ </ div >
82
112
{
83
- helper . usage . length
113
+ helper . usage
84
114
?
85
115
< pre >
86
116
< div className = "helper__code-lines" >
0 commit comments