This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
forked from FelixHenninger/lab.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97d2c36
commit 3c851e8
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
packages/builder/src/components/ComponentOptions/components/Content/Loop/Grid/header.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import React, { useState } from 'react' | ||
|
||
import { InputGroupButtonDropdown, DropdownToggle, DropdownMenu, DropdownItem, | ||
InputGroup } from 'reactstrap' | ||
import classnames from 'classnames' | ||
|
||
import Icon from '../../../../../Icon' | ||
import { FastField, useField } from 'formik' | ||
|
||
const CellTypeDropdown = ({ name, disabled=false }) => { | ||
const [field, , helpers] = useField(name) | ||
const [dropdownOpen, setDropdownOpen] = useState(false) | ||
|
||
return ( | ||
<InputGroupButtonDropdown | ||
addonType="append" | ||
disabled={ disabled } | ||
isOpen={ dropdownOpen } | ||
toggle={ () => setDropdownOpen(!dropdownOpen) } | ||
> | ||
<DropdownToggle | ||
caret={ !disabled } | ||
disabled={ disabled } | ||
outline color="secondary" | ||
// Ensure that the right-hand side always has rounded corners | ||
// (this didn't work if the button was disabled) | ||
className="rounded-right" | ||
> | ||
<Icon | ||
icon={{ | ||
string: 'font', | ||
number: 'tachometer', | ||
boolean: 'adjust' | ||
}[field.value]} | ||
fixedWidth | ||
/> | ||
</DropdownToggle> | ||
<DropdownMenu right> | ||
<DropdownItem header>Data type</DropdownItem> | ||
<DropdownItem | ||
className={ classnames({ | ||
'dropdown-item-active': field.value === 'string' | ||
}) } | ||
onClick={ () => helpers.setValue('string') } | ||
> | ||
Text <span className="text-muted">(categorical)</span> | ||
</DropdownItem> | ||
<DropdownItem | ||
className={ classnames({ | ||
'dropdown-item-active': field.value === 'number' | ||
}) } | ||
onClick={ () => helpers.setValue('number') } | ||
> | ||
Numerical <span className="text-muted">(continuous)</span> | ||
</DropdownItem> | ||
<DropdownItem | ||
className={ classnames({ | ||
'dropdown-item-active': field.value === 'boolean' | ||
}) } | ||
onClick={ () => helpers.setValue('boolean') } | ||
> | ||
Boolean <span className="text-muted">(binary)</span> | ||
</DropdownItem> | ||
</DropdownMenu> | ||
</InputGroupButtonDropdown> | ||
) | ||
} | ||
|
||
export const HeaderCell = ({ index }) => | ||
<InputGroup> | ||
<FastField | ||
name={ `templateParameters.columns[${ index }].name` } | ||
placeholder={ `parameter${ index }` } | ||
className="form-control text-monospace font-weight-bolder" | ||
style={{ height: '42px' }} | ||
/> | ||
<CellTypeDropdown name={ `templateParameters.columns[${ index }].type` } /> | ||
</InputGroup> | ||
|
||
export default ({ name, columns }) => | ||
<thead> | ||
<tr> | ||
<th></th> | ||
{ Array(columns).fill(null).map((_, i) => | ||
<th key={ `${ name }-header-${ i }` }> | ||
<HeaderCell index={ i } /> | ||
</th> | ||
) } | ||
<th></th> | ||
</tr> | ||
</thead> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters