-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
724874b
commit fc0b503
Showing
10 changed files
with
207 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
import { Snippet } from '@ant-design/pro-editor'; | ||
|
||
export default () => { | ||
return <Snippet />; | ||
return ( | ||
<Snippet | ||
language="sh" | ||
style={{ | ||
width: '350px', | ||
}} | ||
> | ||
pnpm install @ant-design/pro-chat | ||
</Snippet> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import copy from 'copy-to-clipboard'; | ||
import { Copy } from 'lucide-react'; | ||
import { memo } from 'react'; | ||
|
||
import ActionIcon from '@/ActionIcon'; | ||
import { useCopied } from '@/hooks/useCopied'; | ||
import { type TooltipProps } from 'antd'; | ||
import { DivProps } from 'react-layout-kit'; | ||
|
||
export interface CopyButtonProps extends DivProps { | ||
/** | ||
* @description Additional class name | ||
*/ | ||
className?: string; | ||
/** | ||
* @description The text content to be copied | ||
*/ | ||
content: string; | ||
/** | ||
* @description The placement of the tooltip | ||
* @enum ['top', 'left', 'right', 'bottom', 'topLeft', 'topRight', 'bottomLeft', 'bottomRight', 'leftTop', 'leftBottom', 'rightTop', 'rightBottom'] | ||
* @default 'right' | ||
*/ | ||
placement?: TooltipProps['placement']; | ||
} | ||
|
||
const CopyButton = memo<CopyButtonProps>( | ||
({ content, className, placement = 'right', ...props }) => { | ||
const { copied, setCopied } = useCopied(); | ||
|
||
return ( | ||
<ActionIcon | ||
{...props} | ||
className={className} | ||
icon={<Copy size={12} />} | ||
onClick={() => { | ||
copy(content); | ||
setCopied(); | ||
}} | ||
placement={placement} | ||
title={copied ? '✅ Success' : 'Copy'} | ||
/> | ||
); | ||
}, | ||
); | ||
|
||
export default CopyButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { memo, useEffect, useRef, useState } from 'react'; | ||
import { DivProps } from 'react-layout-kit'; | ||
import { useStyles } from './style'; | ||
|
||
const useMouseOffset = (): any => { | ||
const [offset, setOffset] = useState<{ x: number; y: number }>(); | ||
const [outside, setOutside] = useState(true); | ||
const reference = useRef<HTMLDivElement>(); | ||
|
||
useEffect(() => { | ||
if (reference.current && reference.current.parentElement) { | ||
const element = reference.current.parentElement; | ||
|
||
// debounce? | ||
const onMouseMove = (e: MouseEvent) => { | ||
const bound = element.getBoundingClientRect(); | ||
setOffset({ x: e.clientX - bound.x, y: e.clientY - bound.y }); | ||
setOutside(false); | ||
}; | ||
|
||
const onMouseLeave = () => { | ||
setOutside(true); | ||
}; | ||
element.addEventListener('mousemove', onMouseMove); | ||
element.addEventListener('mouseleave', onMouseLeave); | ||
return () => { | ||
element.removeEventListener('mousemove', onMouseMove); | ||
element.removeEventListener('mouseleave', onMouseLeave); | ||
}; | ||
} | ||
}, []); | ||
|
||
return [offset, outside, reference] as const; | ||
}; | ||
|
||
export interface SpotlightProps extends DivProps { | ||
/** | ||
* @description The size of the spotlight circle | ||
* @default 64 | ||
*/ | ||
size?: number; | ||
} | ||
|
||
const Spotlight = memo<SpotlightProps>(({ className, size = 64, ...properties }) => { | ||
const [offset, outside, reference] = useMouseOffset(); | ||
const { styles, cx } = useStyles({ offset, outside, size }); | ||
|
||
return <div className={cx(styles, className)} ref={reference} {...properties} />; | ||
}); | ||
|
||
export default Spotlight; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { createStyles } from 'antd-style'; | ||
|
||
export const useStyles = createStyles( | ||
( | ||
{ css, token, isDarkMode }, | ||
{ offset, outside, size }: { offset: { x: number; y: number }; outside: boolean; size: number }, | ||
) => { | ||
const spotlightX = (offset?.x ?? 0) + 'px'; | ||
const spotlightY = (offset?.y ?? 0) + 'px'; | ||
const spotlightOpacity = outside ? '0' : '.1'; | ||
const spotlightSize = size + 'px'; | ||
return css` | ||
pointer-events: none; | ||
position: absolute; | ||
z-index: 1; | ||
inset: 0; | ||
opacity: ${spotlightOpacity}; | ||
background: radial-gradient( | ||
${spotlightSize} circle at ${spotlightX} ${spotlightY}, | ||
${isDarkMode ? token.colorText : '#fff'}, | ||
${isDarkMode ? 'transparent' : token.colorTextQuaternary} | ||
); | ||
border-radius: inherit; | ||
transition: all 0.2s; | ||
`; | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useCallback, useEffect, useMemo, useState } from 'react'; | ||
|
||
export const useCopied = () => { | ||
const [copied, setCopy] = useState(false); | ||
|
||
useEffect(() => { | ||
if (!copied) return; | ||
|
||
const timer = setTimeout(() => { | ||
setCopy(false); | ||
}, 2000); | ||
|
||
return () => { | ||
clearTimeout(timer); | ||
}; | ||
}, [copied]); | ||
|
||
const setCopied = useCallback(() => setCopy(true), []); | ||
|
||
return useMemo(() => ({ copied, setCopied }), [copied]); | ||
}; |