123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- import { Engine } from "babylonjs/Engines/engine";
- import * as React from "react";
- import { GlobalState } from '../globalState';
- import { Utilities } from '../tools/utilities';
- interface ICommandDropdownComponentProps {
- globalState: GlobalState;
- icon?: string;
- tooltip: string;
- defaultValue?: string;
- items: {
- label: string,
- onClick?: () => void,
- onCheck?: (value: boolean) => void,
- storeKey?: string,
- isActive?: boolean,
- defaultValue?: boolean | string;
- subItems?: string[];
- }[];
- toRight?: boolean;
- }
- export class CommandDropdownComponent extends React.Component<ICommandDropdownComponentProps, {isExpanded: boolean, activeState: string}> {
-
- public constructor(props: ICommandDropdownComponentProps) {
- super(props);
- this.state = {isExpanded: false, activeState: Utilities.ReadStringFromStore(this.props.tooltip, this.props.defaultValue!)};
- this.props.globalState.OnNewDropdownButtonClicked.add((source) => {
- if (source === this) {
- return;
- }
- this.setState({isExpanded: false});
- });
- }
- public render() {
- var engineVersionSub = Engine.Version.indexOf("-");
- var engineVersion = Engine.Version;
- if (engineVersionSub ! -1) {
- engineVersion = engineVersion.substr(0, engineVersionSub);
- }
- return (
- <>
- {
- this.state.isExpanded &&
- <div className="command-dropdown-blocker" onClick={() => {
- this.setState({isExpanded: false});
- }}>
- </div>
- }
- <div className="command-dropdown-root">
- <div className={"command-dropdown" + (this.state.isExpanded ? " activated" : "")} title={this.props.tooltip}
- onClick={() => {
- this.props.globalState.OnNewDropdownButtonClicked.notifyObservers(this);
- this.setState({isExpanded: !this.state.isExpanded});
- }}>
- {
- this.props.icon &&
- <div className="command-dropdown-icon">
- <img src={"imgs/" + this.props.icon + ".svg"}/>
- </div>
- }
- {
- !this.props.icon &&
- <div className="command-dropdown-active">
- {
- this.state.activeState === "Latest" ? engineVersion : this.state.activeState
- }
- </div>
- }
- </div>
- {
- this.state.isExpanded &&
- <div className={"command-dropdown-content sub1" + (this.props.toRight ? " toRight" : "")}>
- {
- this.props.items.map(m => {
- return (
- <div className={"command-dropdown-label" + (m.isActive ? " active" : "")} key={m.label} onClick={() => {
- if (!m.onClick) {
- let newValue = !Utilities.ReadBoolFromStore(m.storeKey!, (m.defaultValue as boolean) || false);
- Utilities.StoreBoolToStore(m.storeKey!, newValue);
- this.forceUpdate();
- m.onCheck!(newValue);
- return;
- }
- if (!m.subItems) {
- m.onClick();
- Utilities.StoreStringToStore(this.props.tooltip, m.label);
- this.setState({isExpanded: false, activeState: m.label});
- }
- }} title={m.label}>
- <div className="command-dropdown-label-text">
- {(m.isActive ? "> " : "") + m.label}
- </div>
- {
- m.onCheck &&
- <input type="checkBox" className="command-dropdown-label-check"
- onChange={(evt) => {
- Utilities.StoreBoolToStore(m.storeKey!, evt.target.checked);
- this.forceUpdate();
- m.onCheck!(evt.target.checked);
- }}
- checked={Utilities.ReadBoolFromStore(m.storeKey!, (m.defaultValue as boolean) || false)}/>
- }
- {
- m.subItems &&
- <div className="command-dropdown-arrow">
- {">"}
- </div>
- }
- {
- m.subItems &&
- <div className={"sub-items " + (this.props.globalState.language === "JS" ? "background-js" : "background-ts")}>
- {
- m.subItems.map(s => {
- return (
- <div key={s} className={"sub-item" + (Utilities.ReadStringFromStore(m.storeKey!, m.defaultValue as string) === s ? " checked" : "")}
- onClick={() => {
- Utilities.StoreStringToStore(m.storeKey!, s);
- m.onClick!();
- this.setState({isExpanded: false});
- }}>
- <div className="sub-item-label">
- {s}
- </div>
- </div>
- )
- })
- }
- </div>
- }
- </div>
- )
- })
- }
- </div>
- }
- </div>
- </>
- );
- }
- }
|