mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 19:46:36 +00:00
add documentation section with example
This commit is contained in:
parent
cfc99c53bf
commit
6a67f4145a
2 changed files with 65 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
components: ["ContextMenu", "ContextMenuGroup", "ContextMenuRadioGroup", "ContextMenuOption", "ContextMenuDivider"]
|
components: ["ContextMenu", "ContextMenuInner", "ContextMenuGroup", "ContextMenuRadioGroup", "ContextMenuOption", "ContextMenuDivider"]
|
||||||
---
|
---
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
@ -14,4 +14,8 @@ In the examples, right click anywhere within the iframe.
|
||||||
|
|
||||||
### Radio groups
|
### Radio groups
|
||||||
|
|
||||||
<FileSource src="/framed/ContextMenu/ContextMenuGroups" />
|
<FileSource src="/framed/ContextMenu/ContextMenuGroups" />
|
||||||
|
|
||||||
|
### On specific element
|
||||||
|
|
||||||
|
<FileSource src="/framed/ContextMenu/ContextMenuInner" />
|
||||||
|
|
59
docs/src/pages/framed/ContextMenu/ContextMenuInner.svelte
Normal file
59
docs/src/pages/framed/ContextMenu/ContextMenuInner.svelte
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
<script>
|
||||||
|
import {
|
||||||
|
ContextMenuDivider,
|
||||||
|
ContextMenuOption,
|
||||||
|
ContextMenuInner,
|
||||||
|
} from "carbon-components-svelte";
|
||||||
|
import CopyFile16 from "carbon-icons-svelte/lib/CopyFile16";
|
||||||
|
import Cut16 from "carbon-icons-svelte/lib/Cut16";
|
||||||
|
|
||||||
|
let ref;
|
||||||
|
let open = false;
|
||||||
|
let x = 0;
|
||||||
|
let y = 0;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:window
|
||||||
|
on:click="{(e) => {
|
||||||
|
if (e.target.contains(ref)) open = false;
|
||||||
|
}}"
|
||||||
|
on:keydown="{(e) => {
|
||||||
|
if (open && e.key === 'Escape') open = false;
|
||||||
|
}}"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div
|
||||||
|
on:contextmenu|preventDefault="{(e) => {
|
||||||
|
x = e.x;
|
||||||
|
y = e.y;
|
||||||
|
open = true;
|
||||||
|
}}"
|
||||||
|
></div>
|
||||||
|
|
||||||
|
<ContextMenuInner bind:ref bind:open bind:x bind:y>
|
||||||
|
<ContextMenuOption
|
||||||
|
indented
|
||||||
|
labelText="Copy"
|
||||||
|
shortcutText="Ctrl+C"
|
||||||
|
icon="{CopyFile16}"
|
||||||
|
/>
|
||||||
|
<ContextMenuOption
|
||||||
|
indented
|
||||||
|
labelText="Cut"
|
||||||
|
shortcutText="Ctrl+X"
|
||||||
|
icon="{Cut16}"
|
||||||
|
/>
|
||||||
|
<ContextMenuDivider />
|
||||||
|
<ContextMenuOption indented kind="danger" labelText="Delete" />
|
||||||
|
</ContextMenuInner>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
div {
|
||||||
|
position: absolute;
|
||||||
|
width: 50%;
|
||||||
|
height: 50%;
|
||||||
|
left: 25%;
|
||||||
|
top: 25%;
|
||||||
|
background-color: black;
|
||||||
|
}
|
||||||
|
</style>
|
Loading…
Add table
Add a link
Reference in a new issue