Skip to content

Commit 2ddf092

Browse files
committed
feat: support copy conf path
1 parent 795b796 commit 2ddf092

File tree

5 files changed

+54
-2
lines changed

5 files changed

+54
-2
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import classNames from 'classnames'
2+
import styled from 'styled-components'
3+
import type { FC } from 'react'
4+
import { useCallback, useState } from 'react'
5+
import { writeText } from '@tauri-apps/api/clipboard'
6+
7+
type CopyBtnProps = {
8+
text: string
9+
}
10+
11+
type ContainerProps = {
12+
checking: boolean
13+
}
14+
15+
const Container = styled.span<ContainerProps>`
16+
padding: 4px;
17+
cursor: pointer;
18+
color: ${(props) => (props.checking ? props.theme.successColor : props.theme.primaryFontColor)};
19+
`
20+
21+
export const CopyBtn: FC<CopyBtnProps> = (props) => {
22+
const { text } = props
23+
const [checking, setChecking] = useState(false)
24+
25+
const copy = useCallback(async () => {
26+
if (checking) return
27+
28+
setChecking(true)
29+
30+
await writeText(text)
31+
32+
setTimeout(() => {
33+
setChecking(false)
34+
}, 3000)
35+
}, [checking, text])
36+
37+
const iconCls = classNames({
38+
'ri-file-copy-line': !checking,
39+
'ri-check-fill': checking,
40+
})
41+
42+
return (
43+
<Container checking={checking} onClick={copy}>
44+
<i className={iconCls}></i>
45+
</Container>
46+
)
47+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './CopyBtn'

apps/desktop/src/hooks/useTheme.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const lightThemeColors = {
1717
bgColor: '#fdfdfd',
1818
warnColor: '#dc2626',
1919
tipsBgColor: '#f6f7f9',
20+
successColor: '#00c853',
2021
boxShadowColor: 'rgba(0, 0, 0, 0.08)',
2122
scrollbarThumbColor: '#C4C4C4 ',
2223
scrollbarTrackColor: '#e4e4e7',
@@ -30,6 +31,7 @@ const darkThemeColors = {
3031
bgColor: '#11191f',
3132
warnColor: '#dc2626',
3233
tipsBgColor: '#0e1419',
34+
successColor: '#00c853',
3335
boxShadowColor: 'rgba(255, 255, 255, 0.04)',
3436
scrollbarThumbColor: '#2C3C52',
3537
scrollbarTrackColor: '#0e1419',

apps/desktop/src/router/Setting/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Logo from '@/assets/logo.svg'
88
import { invoke } from '@tauri-apps/api'
99
import TitleBar from '@/components/TitleBar'
1010
import { KeyboardTable } from './KeyboardTable'
11+
import { CopyBtn } from '@/components/CopyBtn'
1112

1213
export interface DialogTitleProps {
1314
children?: ReactNode
@@ -87,7 +88,7 @@ function Setting() {
8788
</div>
8889
<div id="detail">
8990
<div className="conf-path">
90-
<small>Path: {confPath}</small>
91+
<small>Path: {confPath} <CopyBtn text={confPath}/></small>
9192
</div>
9293
{renderCurrentSettingData()}
9394
</div>

apps/desktop/src/router/Setting/styles.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { TITLEBAR_HEIGHT } from '@/constants/styled'
22
import styled from 'styled-components'
33

44
export const Container = styled.div`
5-
height: calc(100vh - ${TITLEBAR_HEIGHT});
65
display: flex;
6+
height: calc(100vh - ${TITLEBAR_HEIGHT});
7+
margin-top: ${TITLEBAR_HEIGHT};
78
89
#sidebar {
910
width: 250px;

0 commit comments

Comments
 (0)