-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
9 changed files
with
170 additions
and
13 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import "react"; | ||
|
||
declare module "react" { | ||
interface CSSProperties { | ||
[key: `--${string}`]: string | number; | ||
} | ||
} |
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,36 @@ | ||
"use client"; | ||
|
||
import { Button } from "pentatrion-design/components/button"; | ||
import { Input } from "pentatrion-design/components/input"; | ||
import { useCopyToClipboard } from "~/hooks/useCopyToClipboard"; | ||
|
||
const text = "npm i maplibre-react-components"; | ||
|
||
export default function NpmInput() { | ||
const [copiedText, copy] = useCopyToClipboard(); | ||
|
||
function handleClickCopy() { | ||
copy(text); | ||
} | ||
return ( | ||
<Input | ||
value={text} | ||
className="bg-gray-0" | ||
readOnly | ||
suffix={ | ||
<> | ||
{copiedText === text && <span>copied</span>} | ||
<Button | ||
onClick={handleClickCopy} | ||
withRipple={false} | ||
icon | ||
variant="text" | ||
color="gray" | ||
> | ||
<i className="fe-copy"></i> | ||
</Button> | ||
</> | ||
} | ||
/> | ||
); | ||
} |
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,46 @@ | ||
"use client"; | ||
|
||
import clsx from "clsx"; | ||
import { useEventListener } from "pentatrion-design/hooks"; | ||
import { CSSProperties, ReactNode, useRef } from "react"; | ||
|
||
interface Props { | ||
children: ReactNode; | ||
className?: string; | ||
} | ||
|
||
const style: CSSProperties = { | ||
"--spotlight-color-stops": "#FFFAC7,#DBA726,transparent", | ||
"--spotlight-size": "300px", | ||
}; | ||
|
||
export default function SpotCard({ children, className }: Props) { | ||
const ref = useRef<HTMLDivElement>(null!); | ||
|
||
useEventListener("mousemove", (event) => { | ||
const { top, left } = ref.current.getBoundingClientRect(); | ||
const x = event.clientX - left; | ||
const y = event.clientY - top; | ||
|
||
ref.current.style.setProperty("--x", `${x}px`); | ||
ref.current.style.setProperty("--y", `${y}px`); | ||
}); | ||
|
||
return ( | ||
<div | ||
ref={ref} | ||
className="relative mx-auto w-full max-w-2xl transform-gpu overflow-hidden rounded-2xl bg-white/10 p-4 [--radius:theme(borderRadius.2xl)] before:absolute before:inset-0 before:bg-[radial-gradient(var(--spotlight-size)_circle_at_var(--x)_var(--y),var(--spotlight-color-stops))]" | ||
style={style} | ||
> | ||
<div className="absolute inset-px rounded-2xl bg-gray-0"></div> | ||
<div | ||
className={clsx( | ||
"relative flex h-full items-center justify-center", | ||
className, | ||
)} | ||
> | ||
{children} | ||
</div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useCallback, useState } from "react"; | ||
|
||
type CopiedValue = string | null; | ||
|
||
type CopyFn = (text: string) => Promise<boolean>; | ||
|
||
export function useCopyToClipboard(): [CopiedValue, CopyFn] { | ||
const [copiedText, setCopiedText] = useState<CopiedValue>(null); | ||
|
||
const copy: CopyFn = useCallback(async (text) => { | ||
if (!navigator?.clipboard) { | ||
console.warn("Clipboard not supported"); | ||
return false; | ||
} | ||
|
||
// Try to save to clipboard then save it in the state if worked | ||
try { | ||
await navigator.clipboard.writeText(text); | ||
setCopiedText(text); | ||
return true; | ||
} catch (error) { | ||
console.warn("Copy failed", error); | ||
setCopiedText(null); | ||
return false; | ||
} | ||
}, []); | ||
|
||
return [copiedText, copy]; | ||
} |
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.
Binary file not shown.