Перевел дизайн на материал

jwt
Rinsvent 2 years ago
parent bb977edb2c
commit f63cd5c87b
  1. 4
      components/elements/commands/elements/argument/index.tsx
  2. 2
      components/elements/commands/elements/command/index.tsx
  3. 4
      components/elements/commands/elements/command/styles.module.css
  4. 10
      components/elements/commands/elements/option/index.tsx
  5. 65
      components/elements/commands/elements/options/index.tsx
  6. 4
      components/elements/commands/styles.module.css

@ -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"/>&nbsp; <TextField onInput={onInput} placeholder={argument.name} value={value} size="small" variant="outlined" />&nbsp;
{/*<input onInput={onInput} placeholder={argument.name} value={value} type="text"/>&nbsp;*/}
</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}&nbsp; {command.name}&nbsp;
<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"/>}&nbsp; {option.shortcut ? '-' : '--'}
{option.acceptValue ? '' : (option.shortcut || option.name)}
{option.acceptValue &&
<TextField
label={option.shortcut || option.name}
onInput={onInput}
size="small"
variant="outlined" />}&nbsp;
</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>&nbsp;</>} 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>
&nbsp;
</>}
{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…
Cancel
Save