Skip to content

Latest commit

 

History

History
285 lines (186 loc) · 8.91 KB

context-menu.md

File metadata and controls

285 lines (186 loc) · 8.91 KB

ContextMenu

Source

Gives people access to additional functionality related to onscreen items without cluttering the interface.

Usage

You should have the chayns-components package installed. If that is not the case already, run

yarn add chayns-components

or

npm i chayns-components

After the chayns-components package is installed, you can import the component and use it with React:

import React from 'react'
import { ContextMenu } from 'chayns-components';

// ...

<ContextMenu {...} />

Methods

To open or close the context menu imperatively, call the show() and hide() on its reference.

Props

The ContextMenu-component takes the following props:

Name Type Default Required
onLayerClick function
onShow function
onHide function
coordinates { x: number, y: number }
items Array<{ className: string, onClick: function, text: string | ReactNode, stringName: string, icon: string | Object }> []
position number
positionOnChildren number 1
parent custom
children ReactNode <Icon icon="ts-ellipsis_v" />
onChildrenClick function
childrenStyle { [key: string]: string | number }
childrenClassName string
stopPropagation boolean false
minWidth number
maxWidth number
showTriggerBackground boolean false
className string
style object
removeParentSpace boolean false
disableDialog boolean false
arrowDistance number 0

onLayerClick

onLayerClick?: function

This callback will be called when the ContextMenu is shown and the user clicks away from it.


onShow

onShow?: function

This callback will be called when the context menu becomes visible


onHide

onHide?: function

This callback will be called when the ContextMenu hides


coordinates

coordinates?: { x: number, y: number }

The coordinates at which the context menu will get rendered.


items

items?: Array<{ className: string, onClick: function, text: string | ReactNode, stringName: string, icon: string | Object }>

The action items inside of the context menu. Their shape should look like this: { className: <string>, onClick: <function>, text: <string>, icon: <string> }, stringName: <string>.


position

position?: number

This specifies where the menu will appear relative to the components provided in the children-prop. Possible values are: 0 for top left, 1 for bottom left, 2 for bottom right, 3 for top right, 4 for top center and 5 for bottom center.


positionOnChildren

positionOnChildren?: number

The position of the arrow relative to the children. Possible values are 0 for left, 1 for center and 2 for right.


parent

parent?: custom

Specifies the DOM node the context menu will be rendered into.


children

children?: ReactNode

The React node that the context menu refers to.


onChildrenClick

onChildrenClick?: function

Called when the onclick-event is triggered on the children.


childrenStyle

childrenStyle?: { [key: string]: string | number }

A React style object that will be applied to the children wrapper.


childrenClassName

childrenClassName?: string

A classname string that will be applied to the children wrapper.


stopPropagation

stopPropagation?: boolean

Wether to stop propagation of click events on the children elements.


minWidth

minWidth?: number

The minimum width of the context menu.


maxWidth

maxWidth?: number

The maximum width of the context menu.


showTriggerBackground

showTriggerBackground?: boolean

Adds a white background to the children wrapper, for when it would otherwise be difficult to view (e.g. on images or video).


className

className?: string

A classname string applied to the Bubble component.


style

style?: object

A React style object that is applied to the Bubble component.


removeParentSpace

removeParentSpace?: boolean

Removes the parent padding to the page borders from the context menu position. This is needed when the parent is padded and relatively positioned.


disableDialog

disableDialog?: boolean

Disables the use of a dialog on mobile.


arrowDistance

arrowDistance?: number

Adjust the distance of the arrow and the end of the children. This only applies if positionOnChildren is set to left (0) or right (2).