-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: prism component with super powers (#563)
* feat: prism component with super powers * fix: quick fix * fix: build errors
- Loading branch information
1 parent
6945a52
commit 6c2161d
Showing
2 changed files
with
47 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { PrismProps } from '@mantine/prism'; | ||
import { Prism } from '@mantine/prism'; | ||
import classNames from 'classnames'; | ||
import { useCallback, useState } from 'react'; | ||
|
||
//just Prism component with some additional powers! | ||
|
||
export default function PrismPlus({ children, ...props }: PrismProps) { | ||
const [isSecretVisible, setIsSecretVisible] = useState(false); | ||
|
||
const toggleSecretVisibility = useCallback(() => setIsSecretVisible(!isSecretVisible), [isSecretVisible, setIsSecretVisible]); | ||
|
||
const Switch = useCallback(() => { | ||
return ( | ||
<span | ||
onClick={toggleSecretVisibility} | ||
className="bg-gray-300 hover:bg-gray-400 rounded px-2 py-1 text-sm text-gray-600 cursor-pointer absolute z-10 top-3 right-10" | ||
> | ||
{isSecretVisible ? 'hide' : 'show'} | ||
</span> | ||
); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [isSecretVisible]); | ||
|
||
return ( | ||
<div className="relative"> | ||
{isSecretVisible ? ( | ||
<Switch /> | ||
) : ( | ||
<div className={classNames('absolute z-10', { 'h-full w-full backdrop-blur-sm bg-black/0': !isSecretVisible })}> | ||
<Switch /> | ||
</div> | ||
)} | ||
|
||
<Prism {...props}>{children}</Prism> | ||
</div> | ||
); | ||
} |
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