Skip to content

Commit

Permalink
feat: support copy conf path
Browse files Browse the repository at this point in the history
  • Loading branch information
drl990114 committed Aug 30, 2023
1 parent 795b796 commit 2ddf092
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
47 changes: 47 additions & 0 deletions apps/desktop/src/components/CopyBtn/CopyBtn.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import classNames from 'classnames'
import styled from 'styled-components'
import type { FC } from 'react'
import { useCallback, useState } from 'react'
import { writeText } from '@tauri-apps/api/clipboard'

type CopyBtnProps = {
text: string
}

type ContainerProps = {
checking: boolean
}

const Container = styled.span<ContainerProps>`
padding: 4px;
cursor: pointer;
color: ${(props) => (props.checking ? props.theme.successColor : props.theme.primaryFontColor)};
`

export const CopyBtn: FC<CopyBtnProps> = (props) => {
const { text } = props
const [checking, setChecking] = useState(false)

const copy = useCallback(async () => {
if (checking) return

setChecking(true)

await writeText(text)

setTimeout(() => {
setChecking(false)
}, 3000)
}, [checking, text])

const iconCls = classNames({
'ri-file-copy-line': !checking,
'ri-check-fill': checking,
})

return (
<Container checking={checking} onClick={copy}>
<i className={iconCls}></i>
</Container>
)
}
1 change: 1 addition & 0 deletions apps/desktop/src/components/CopyBtn/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './CopyBtn'
2 changes: 2 additions & 0 deletions apps/desktop/src/hooks/useTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const lightThemeColors = {
bgColor: '#fdfdfd',
warnColor: '#dc2626',
tipsBgColor: '#f6f7f9',
successColor: '#00c853',
boxShadowColor: 'rgba(0, 0, 0, 0.08)',
scrollbarThumbColor: '#C4C4C4 ',
scrollbarTrackColor: '#e4e4e7',
Expand All @@ -30,6 +31,7 @@ const darkThemeColors = {
bgColor: '#11191f',
warnColor: '#dc2626',
tipsBgColor: '#0e1419',
successColor: '#00c853',
boxShadowColor: 'rgba(255, 255, 255, 0.04)',
scrollbarThumbColor: '#2C3C52',
scrollbarTrackColor: '#0e1419',
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/src/router/Setting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Logo from '@/assets/logo.svg'
import { invoke } from '@tauri-apps/api'
import TitleBar from '@/components/TitleBar'
import { KeyboardTable } from './KeyboardTable'
import { CopyBtn } from '@/components/CopyBtn'

export interface DialogTitleProps {
children?: ReactNode
Expand Down Expand Up @@ -87,7 +88,7 @@ function Setting() {
</div>
<div id="detail">
<div className="conf-path">
<small>Path: {confPath}</small>
<small>Path: {confPath} <CopyBtn text={confPath}/></small>
</div>
{renderCurrentSettingData()}
</div>
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/src/router/Setting/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { TITLEBAR_HEIGHT } from '@/constants/styled'
import styled from 'styled-components'

export const Container = styled.div`
height: calc(100vh - ${TITLEBAR_HEIGHT});
display: flex;
height: calc(100vh - ${TITLEBAR_HEIGHT});
margin-top: ${TITLEBAR_HEIGHT};
#sidebar {
width: 250px;
Expand Down

0 comments on commit 2ddf092

Please sign in to comment.