Перевел дизайн на материал
This commit is contained in:
parent
bb977edb2c
commit
f63cd5c87b
@ -1,6 +1,7 @@
|
|||||||
import styles from './styles.module.css'
|
import styles from './styles.module.css'
|
||||||
import {useContext, useEffect, useState} from "react";
|
import {useContext, useEffect, useState} from "react";
|
||||||
import Context, {ContextInterface} from "../command/context";
|
import Context, {ContextInterface} from "../command/context";
|
||||||
|
import {TextField} from "@mui/material";
|
||||||
|
|
||||||
export interface ArgumentInterface {
|
export interface ArgumentInterface {
|
||||||
name: string,
|
name: string,
|
||||||
@ -27,7 +28,8 @@ export default function Argument(argument: ArgumentInterface) {
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<span>
|
<span>
|
||||||
<input onInput={onInput} placeholder={argument.name} value={value} type="text"/>
|
<TextField onInput={onInput} placeholder={argument.name} value={value} size="small" variant="outlined" />
|
||||||
|
{/*<input onInput={onInput} placeholder={argument.name} value={value} type="text"/> */}
|
||||||
</span>
|
</span>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ export default function Command({command, callback}: CommandComponentInterface)
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Provider value={{optionList, setOptionList, argumentList, setArgumentList}}>
|
<Provider value={{optionList, setOptionList, argumentList, setArgumentList}}>
|
||||||
<div className={styles.task}>
|
<div>
|
||||||
<div title={command.description}>
|
<div title={command.description}>
|
||||||
{command.name}
|
{command.name}
|
||||||
<Options optionList={command.options} />
|
<Options optionList={command.options} />
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
.task {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 11fr 1fr;
|
|
||||||
}
|
|
@ -1,6 +1,7 @@
|
|||||||
import styles from './styles.module.css'
|
import styles from './styles.module.css'
|
||||||
import {useContext} from "react";
|
import {useContext} from "react";
|
||||||
import Context, {ContextInterface} from "../command/context";
|
import Context, {ContextInterface} from "../command/context";
|
||||||
|
import {TextField} from "@mui/material";
|
||||||
|
|
||||||
export interface OptionInterface {
|
export interface OptionInterface {
|
||||||
name: string,
|
name: string,
|
||||||
@ -27,7 +28,14 @@ export default function Option(option: OptionInterface) {
|
|||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<span>
|
<span>
|
||||||
{option.shortcut ? '-' : '--'}{option.shortcut || option.name} {option.acceptValue && <input onInput={onInput} type="text"/>}
|
{option.shortcut ? '-' : '--'}
|
||||||
|
{option.acceptValue ? '' : (option.shortcut || option.name)}
|
||||||
|
{option.acceptValue &&
|
||||||
|
<TextField
|
||||||
|
label={option.shortcut || option.name}
|
||||||
|
onInput={onInput}
|
||||||
|
size="small"
|
||||||
|
variant="outlined" />}
|
||||||
</span>
|
</span>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import styles from './styles.module.css'
|
|||||||
import Option, {OptionInterface} from '../option'
|
import Option, {OptionInterface} from '../option'
|
||||||
import {useContext, useEffect, useState} from "react";
|
import {useContext, useEffect, useState} from "react";
|
||||||
import Context, {ContextInterface} from "../command/context";
|
import Context, {ContextInterface} from "../command/context";
|
||||||
|
import {Select, MenuItem, Checkbox, ListItemText} from "@mui/material";
|
||||||
|
|
||||||
interface OptionsInterface {
|
interface OptionsInterface {
|
||||||
optionList: OptionInterface[]
|
optionList: OptionInterface[]
|
||||||
@ -9,46 +10,58 @@ interface OptionsInterface {
|
|||||||
|
|
||||||
export default function Options({optionList}: OptionsInterface) {
|
export default function Options({optionList}: OptionsInterface) {
|
||||||
let {optionList: ol, setOptionList} = useContext<ContextInterface>(Context)
|
let {optionList: ol, setOptionList} = useContext<ContextInterface>(Context)
|
||||||
let [availableOptions, setAvailableOptions] = useState<OptionInterface[]>(optionList);
|
let [selectedOptions, setSelectedOptions] = useState<OptionInterface[]>([]);
|
||||||
let [values, setValues] = useState<OptionInterface[]>([]);
|
let [values, setValues] = useState<OptionInterface[]>([]);
|
||||||
|
let [selectedValues, setSelectedValues] = useState<string[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let result: OptionInterface[] = [];
|
let result: OptionInterface[] = [];
|
||||||
optionList.forEach((value, index, array) => {
|
optionList.forEach((value, index, array) => {
|
||||||
let check = values.find(item => item === value)
|
let check = selectedValues.find(item => item === value.name)
|
||||||
!check && result.push(value)
|
check && result.push(value)
|
||||||
})
|
})
|
||||||
setAvailableOptions(result)
|
setSelectedOptions(result)
|
||||||
}, [values]);
|
|
||||||
|
let temp: any = {}
|
||||||
|
optionList.forEach((value, index, array) => {
|
||||||
|
let check = selectedValues.find(item => item === value.name)
|
||||||
|
check && (temp[value.name] = value.acceptValue ? '' : null)
|
||||||
|
})
|
||||||
|
setOptionList(temp)
|
||||||
|
}, [selectedValues]);
|
||||||
|
|
||||||
if (!optionList.length) {
|
if (!optionList.length) {
|
||||||
return <></>
|
return <></>
|
||||||
}
|
}
|
||||||
|
|
||||||
let onChange = (event: any) => {
|
const handleChange = (event: any) => {
|
||||||
let selectedValue = event.target.value
|
const { target: { value }} = event
|
||||||
let selectedOption = availableOptions.find(item => item.name === selectedValue)
|
setSelectedValues(typeof value === 'string' ? value.split(',') : value)
|
||||||
selectedOption && values.push(selectedOption)
|
};
|
||||||
setValues([ ...values ])
|
|
||||||
event.target.value = '';
|
|
||||||
|
|
||||||
let temp = {
|
|
||||||
...ol
|
|
||||||
}
|
|
||||||
if (selectedOption) {
|
|
||||||
temp[selectedOption.name] = selectedOption.acceptValue ? '' : null;
|
|
||||||
}
|
|
||||||
setOptionList(temp)
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{availableOptions.length > 0 && <><select onChange={onChange}>
|
{optionList.length > 0 &&
|
||||||
<option value="">-</option>
|
<>
|
||||||
{availableOptions.map((option: OptionInterface, index: number) => (
|
<Select
|
||||||
<option key={index} value={option.name}>{option.name}</option>
|
value={selectedValues}
|
||||||
))}
|
label="Option"
|
||||||
</select> </>}
|
multiple
|
||||||
{values.map((option: OptionInterface, index: number) => (
|
displayEmpty
|
||||||
|
onChange={handleChange}
|
||||||
|
renderValue={(selectedValues) => `Options`}
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
{optionList.map((option: OptionInterface, index: number) => (
|
||||||
|
<MenuItem key={index} value={option.name}>
|
||||||
|
<Checkbox checked={selectedValues.indexOf(option.name) > -1} />
|
||||||
|
<ListItemText primary={option.name} />
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
|
||||||
|
</>}
|
||||||
|
{selectedOptions.map((option: OptionInterface, index: number) => (
|
||||||
<Option key={index} {...option} />
|
<Option key={index} {...option} />
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
.task {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 11fr 1fr;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user