Skip to content

Commit

Permalink
fix: Make onCopy optional and rename to onCopyClick (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
floreks authored Mar 31, 2023
1 parent 8c0b347 commit ab31cdb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/components/Codeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ import CopyIcon from './icons/CopyIcon'

type CodelineProps = FlexProps & {
displayText?: string
onCopy: (text: string) => Promise<void>
onCopyClick?: (text: string) => Promise<void>
}

const propTypes = {}

function CodelineRef(
{ children, displayText, onCopy, ...props }: CodelineProps,
{ children, displayText, onCopyClick, ...props }: CodelineProps,
ref: Ref<any>
) {
const [copied, setCopied] = useState(false)
const theme = useTheme()

const handleCopy = useCallback(() => {
if (onCopy) {
onCopy(children as string).then(() => setCopied(true))
if (onCopyClick) {
onCopyClick(children as string).then(() => setCopied(true))

return
}

window.navigator.clipboard
.writeText(children as string)
.then(() => setCopied(true))
}, [children, onCopy])
}, [children, onCopyClick])

useEffect(() => {
if (copied) {
Expand Down
2 changes: 1 addition & 1 deletion src/stories/Codeline.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function CustomCopyTemplate(args: any) {
This codeline copy uses a custom onCopy function that returns a promise!
</span>
<Codeline
onCopy={onCopy}
onCopyClick={onCopy}
{...args}
/>
</Flex>
Expand Down

0 comments on commit ab31cdb

Please sign in to comment.