Major rework of context menus
parent
d0d5012e07
commit
9afb8b4d5e
@ -1,68 +1,61 @@
|
|||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
import { SessionIcon, SessionIconSize, SessionIconType } from './icon/';
|
import { SessionIcon, SessionIconSize, SessionIconType } from './icon/';
|
||||||
import { generateID } from './tools/ComponentTools';
|
import { generateID } from './tools/ComponentTools';
|
||||||
|
|
||||||
|
|
||||||
export enum SessionDropDownItemType {
|
export enum SessionDropDownItemType {
|
||||||
Default = 'default',
|
Default = 'default',
|
||||||
Danger = 'danger',
|
Danger = 'danger',
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
id: string,
|
id: string;
|
||||||
content: string,
|
content: string;
|
||||||
type: SessionDropDownItemType,
|
type: SessionDropDownItemType;
|
||||||
icon: SessionIconType | null,
|
icon: SessionIconType | null;
|
||||||
active: boolean,
|
active: boolean;
|
||||||
onClick: any,
|
onClick: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SessionDropdownItem extends React.PureComponent<Props> {
|
export class SessionDropdownItem extends React.PureComponent<Props> {
|
||||||
public static defaultProps = {
|
public static defaultProps = {
|
||||||
id: generateID(),
|
id: generateID(),
|
||||||
type: SessionDropDownItemType.Default,
|
type: SessionDropDownItemType.Default,
|
||||||
icon: null,
|
icon: null,
|
||||||
active: false,
|
active: false,
|
||||||
onClick: () => null,
|
onClick: () => null,
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(props: any) {
|
constructor(props: any) {
|
||||||
super(props);
|
super(props);
|
||||||
this.clickHandler = this.clickHandler.bind(this);
|
this.clickHandler = this.clickHandler.bind(this);
|
||||||
}
|
|
||||||
|
|
||||||
public render() {
|
|
||||||
const { id, content, type, icon, active } = this.props;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<li
|
|
||||||
id={id}
|
|
||||||
className={classNames(active ? 'active' : '', type || '')}
|
|
||||||
onClick={this.clickHandler}
|
|
||||||
>
|
|
||||||
{ icon ? <SessionIcon
|
|
||||||
iconType = { icon }
|
|
||||||
iconSize = { SessionIconSize.Small }
|
|
||||||
/>
|
|
||||||
: ''
|
|
||||||
}
|
|
||||||
<div className="item-content">
|
|
||||||
{content}
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private clickHandler(e: any){
|
|
||||||
if (this.props.onClick) {
|
|
||||||
e.stopPropagation();
|
|
||||||
this.props.onClick();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public render() {
|
||||||
|
const { id, content, type, icon, active } = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<li
|
||||||
|
id={id}
|
||||||
|
className={classNames(active ? 'active' : '', type || '')}
|
||||||
|
role="button"
|
||||||
|
onClick={this.clickHandler}
|
||||||
|
>
|
||||||
|
{icon ? (
|
||||||
|
<SessionIcon iconType={icon} iconSize={SessionIconSize.Small} />
|
||||||
|
) : (
|
||||||
|
''
|
||||||
|
)}
|
||||||
|
<div className="item-content">{content}</div>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private clickHandler(e: any) {
|
||||||
|
if (this.props.onClick) {
|
||||||
|
e.stopPropagation();
|
||||||
|
this.props.onClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
//mouseButton: Number;
|
||||||
|
posX: number;
|
||||||
|
posY: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SessionDropdownTrigger extends React.Component<Props> {
|
||||||
|
public static defaultProps = {
|
||||||
|
//mouseButton: 2, // 0 is left click, 2 is right click
|
||||||
|
posX: 0,
|
||||||
|
posY: 0,
|
||||||
|
};
|
||||||
|
constructor(props: any) {
|
||||||
|
super(props);
|
||||||
|
}
|
||||||
|
|
||||||
|
public handleDropdownClick = (event: any) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
let x = event.clientX || (event.touches && event.touches[0].pageX);
|
||||||
|
let y = event.clientY || (event.touches && event.touches[0].pageY);
|
||||||
|
|
||||||
|
if (this.props.posX) {
|
||||||
|
x -= this.props.posX;
|
||||||
|
}
|
||||||
|
if (this.props.posY) {
|
||||||
|
y -= this.props.posY;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public render() {
|
||||||
|
return <div role="button" onClick={this.handleDropdownClick} />;
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
// This is a collection of tools which can be ued to simplify the esign and rendering process of your components.
|
// This is a collection of tools which can be ued to simplify the esign and rendering process of your components.
|
||||||
|
|
||||||
export function generateID(){
|
export function generateID() {
|
||||||
// Generates a unique ID for your component
|
// Generates a unique ID for your component
|
||||||
return Math.random().toString(36).substring(3);
|
const buffer = new Uint32Array(10);
|
||||||
}
|
|
||||||
|
|
||||||
|
return window.crypto.getRandomValues(buffer)[0].toString();
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue