1
0

fix: correct insert column button

This commit is contained in:
Rokas Puzonas 2022-02-07 23:42:05 +02:00
parent 0903a24433
commit de20681bce
3 changed files with 47 additions and 42 deletions

View File

@ -5,44 +5,49 @@ import TableMethodCodeBlock from './TableMethodCodeBlock';
import { TableColumns } from './TableMethodGenerator'; import { TableColumns } from './TableMethodGenerator';
function App() { function App() {
let [columns, setColumns] = useState<TableColumns>([ let initialColumns: TableColumns = []
{
name: "Miestas", if (process.env.NODE_ENV === "development") {
field: "City", initialColumns = [
width: 10, {
alignment: "left" name: "Miestas",
}, field: "City",
{ width: 10,
name: "Atsakingas", alignment: "left"
field: "Manager", },
width: 20, {
alignment: "left" name: "Atsakingas",
}, field: "Manager",
{ width: 20,
name: "Vardas", alignment: "left"
field: "Name", },
width: 18, {
alignment: "left" name: "Vardas",
}, field: "Name",
{ width: 18,
name: "Address", alignment: "left"
field: "Adress", },
width: 15, {
alignment: "left" name: "Address",
}, field: "Adress",
{ width: 15,
name: "Metai", alignment: "left"
field: "Year", },
width: 5, {
alignment: "right" name: "Metai",
} field: "Year",
]) width: 5,
alignment: "right"
}
]
}
let [columns, setColumns] = useState<TableColumns>(initialColumns)
// let [generatorOptions, setGeneratorOptions] = useState<TableMethodGeneratorOptions>({}); // let [generatorOptions, setGeneratorOptions] = useState<TableMethodGeneratorOptions>({});
const onChange = (e: TableColumns) => { const onChange = (e: TableColumns) => {
columns = e setColumns([...e])
setColumns(e)
} }
return ( return (

View File

@ -59,10 +59,12 @@ function TableDefinitionForm(props: TableDefinitionProps) {
let [columns, setColumns] = useState<TableColumns>(props.value) let [columns, setColumns] = useState<TableColumns>(props.value)
const addRow = () => { const addRow = () => {
columns.push({ name: currentName }) if (currentName.length > 0) {
setCurrentName("") columns.push({ name: currentName })
if (props.onChange !== undefined) { setCurrentName("")
props.onChange(columns) if (props.onChange !== undefined) {
props.onChange(columns)
}
} }
} }
@ -92,7 +94,7 @@ function TableDefinitionForm(props: TableDefinitionProps) {
onChange={(e) => setCurrentName(e.target.value)} onChange={(e) => setCurrentName(e.target.value)}
onKeyPress={(e) => e.key === "Enter" && addRow()} onKeyPress={(e) => e.key === "Enter" && addRow()}
/> />
<button onClick={onClickCopy}>Insert column</button> <button onClick={addRow}>Insert column</button>
<button onClick={onClickCopy}>Copy code 📋!</button> <button onClick={onClickCopy}>Copy code 📋!</button>
<ol> <ol>
{columns.map((item, i) => {columns.map((item, i) =>

View File

@ -11,12 +11,10 @@ interface Props {
} }
function TableMethodCodeBlock(props: Props) { function TableMethodCodeBlock(props: Props) {
let script = generate(props.columns, props.options)
return ( return (
<div> <div>
<SyntaxHighlighter language="csharp" style={vs2015}> <SyntaxHighlighter language="csharp" style={vs2015}>
{script} {generate(props.columns, props.options)}
</SyntaxHighlighter> </SyntaxHighlighter>
</div> </div>
) )