-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add copy to clipboard option for OIDC client information
- Loading branch information
1 parent
a4a90a1
commit f82020c
Showing
4 changed files
with
91 additions
and
2 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,41 @@ | ||
<script lang="ts"> | ||
import * as Tooltip from '$lib/components/ui/tooltip'; | ||
import { LucideCheck } from 'lucide-svelte'; | ||
import type { Snippet } from 'svelte'; | ||
let { value, children }: { value: string; children: Snippet } = $props(); | ||
let open = $state(false); | ||
let copied = $state(false); | ||
function onClick() { | ||
open = true; | ||
copyToClipboard(); | ||
} | ||
function onOpenChange(state: boolean) { | ||
open = state; | ||
if (!state) { | ||
copied = false; | ||
} | ||
} | ||
function copyToClipboard() { | ||
navigator.clipboard.writeText(value); | ||
copied = true; | ||
setTimeout(() => onOpenChange(false), 1000); | ||
} | ||
</script> | ||
|
||
<button onclick={onClick}> | ||
<Tooltip.Root closeOnPointerDown={false} {onOpenChange} {open}> | ||
<Tooltip.Trigger>{@render children()}</Tooltip.Trigger> | ||
<Tooltip.Content onclick={copyToClipboard}> | ||
{#if copied} | ||
<span class="flex items-center"><LucideCheck class="mr-1 h-4 w-4" /> Copied</span> | ||
{:else} | ||
<span>Click to copy</span> | ||
{/if} | ||
</Tooltip.Content> | ||
</Tooltip.Root> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Tooltip as TooltipPrimitive } from "bits-ui"; | ||
import Content from "./tooltip-content.svelte"; | ||
|
||
const Root = TooltipPrimitive.Root; | ||
const Trigger = TooltipPrimitive.Trigger; | ||
|
||
export { | ||
Root, | ||
Trigger, | ||
Content, | ||
// | ||
Root as Tooltip, | ||
Content as TooltipContent, | ||
Trigger as TooltipTrigger, | ||
}; |
28 changes: 28 additions & 0 deletions
28
frontend/src/lib/components/ui/tooltip/tooltip-content.svelte
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,28 @@ | ||
<script lang="ts"> | ||
import { Tooltip as TooltipPrimitive } from "bits-ui"; | ||
import { cn, flyAndScale } from "$lib/utils/style.js"; | ||
type $$Props = TooltipPrimitive.ContentProps; | ||
let className: $$Props["class"] = undefined; | ||
export let sideOffset: $$Props["sideOffset"] = 4; | ||
export let transition: $$Props["transition"] = flyAndScale; | ||
export let transitionConfig: $$Props["transitionConfig"] = { | ||
y: 8, | ||
duration: 150, | ||
}; | ||
export { className as class }; | ||
</script> | ||
|
||
<TooltipPrimitive.Content | ||
{transition} | ||
{transitionConfig} | ||
{sideOffset} | ||
class={cn( | ||
"bg-popover text-popover-foreground z-50 overflow-hidden rounded-md border px-3 py-1.5 text-sm shadow-md", | ||
className | ||
)} | ||
{...$$restProps} | ||
> | ||
<slot /> | ||
</TooltipPrimitive.Content> |
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