feat(context-menu): support danger kind for ContextMenuOption

This commit is contained in:
Eric Y Liu 2021-04-02 04:40:27 -07:00
commit b19696b9f1
6 changed files with 27 additions and 0 deletions

View file

@ -800,6 +800,7 @@ None.
| selected | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to use the selected variant | | selected | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to use the selected variant |
| icon | <code>let</code> | Yes | <code>typeof import("carbon-icons-svelte").CarbonIcon</code> | -- | Specify the icon from `carbon-icons-svelte` to render<br />Icon is rendered to the left of the label text | | icon | <code>let</code> | Yes | <code>typeof import("carbon-icons-svelte").CarbonIcon</code> | -- | Specify the icon from `carbon-icons-svelte` to render<br />Icon is rendered to the left of the label text |
| indented | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to indent the label | | indented | <code>let</code> | Yes | <code>boolean</code> | <code>false</code> | Set to `true` to indent the label |
| kind | <code>let</code> | No | <code>"default" &#124; "danger"</code> | <code>"default"</code> | Specify the kind of option |
| disabled | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to enable the disabled state | | disabled | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to enable the disabled state |
| labelText | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the label text<br />Alternatively, use the "labelText" slot (e.g., &lt;span slot="labelText"&gt;...&lt;/span&gt;) | | labelText | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the label text<br />Alternatively, use the "labelText" slot (e.g., &lt;span slot="labelText"&gt;...&lt;/span&gt;) |
| shortcutText | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the shortcut text<br />Alternatively, use the "shortcutText" slot (e.g., &lt;span slot="shortcutText"&gt;...&lt;/span&gt;) | | shortcutText | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the shortcut text<br />Alternatively, use the "shortcutText" slot (e.g., &lt;span slot="shortcutText"&gt;...&lt;/span&gt;) |

View file

@ -1656,6 +1656,16 @@
"moduleName": "ContextMenuOption", "moduleName": "ContextMenuOption",
"filePath": "src/ContextMenu/ContextMenuOption.svelte", "filePath": "src/ContextMenu/ContextMenuOption.svelte",
"props": [ "props": [
{
"name": "kind",
"kind": "let",
"description": "Specify the kind of option",
"type": "\"default\" | \"danger\"",
"value": "\"default\"",
"isFunction": false,
"constant": false,
"reactive": false
},
{ {
"name": "disabled", "name": "disabled",
"kind": "let", "kind": "let",

View file

@ -42,4 +42,6 @@
<ContextMenuOption id="1" labelText="Reduce noise" /> <ContextMenuOption id="1" labelText="Reduce noise" />
<ContextMenuOption id="2" labelText="Auto-sharpen" /> <ContextMenuOption id="2" labelText="Auto-sharpen" />
</ContextMenuGroup> </ContextMenuGroup>
<ContextMenuDivider />
<ContextMenuOption indented kind="danger" labelText="Delete" />
</ContextMenu> </ContextMenu>

View file

@ -1,4 +1,10 @@
<script> <script>
/**
* Specify the kind of option
* @type {"default" | "danger"}
*/
export let kind = "default";
/** Set to `true` to enable the disabled state */ /** Set to `true` to enable the disabled state */
export let disabled = false; export let disabled = false;
@ -158,6 +164,7 @@
class:bx--context-menu-option="{true}" class:bx--context-menu-option="{true}"
class:bx--context-menu-option--disabled="{true}" class:bx--context-menu-option--disabled="{true}"
class:bx--context-menu-option--active="{subOptions && submenuOpen}" class:bx--context-menu-option--active="{subOptions && submenuOpen}"
class:bx--context-menu-option--danger="{!subOptions && kind === 'danger'}"
indented="{indented}" indented="{indented}"
aria-checked="{isSelectable || isRadio ? selected : undefined}" aria-checked="{isSelectable || isRadio ? selected : undefined}"
data-nested="{ref && data-nested="{ref &&

View file

@ -17,6 +17,7 @@
<ContextMenu> <ContextMenu>
<ContextMenuOption <ContextMenuOption
kind="danger"
indented indented
labelText="Copy" labelText="Copy"
shortcutText="⌘C" shortcutText="⌘C"

View file

@ -3,6 +3,12 @@ import { SvelteComponentTyped } from "svelte";
export interface ContextMenuOptionProps export interface ContextMenuOptionProps
extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["li"]> { extends svelte.JSX.HTMLAttributes<HTMLElementTagNameMap["li"]> {
/**
* Specify the kind of option
* @default "default"
*/
kind?: "default" | "danger";
/** /**
* Set to `true` to enable the disabled state * Set to `true` to enable the disabled state
* @default false * @default false