forked from elastic/kibana
-
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.
Feat: Element container style UI (elastic#154)
* chore: make labeled select generic component decouple it from the extended input template so it can be reused * feat: add container style argType UI * feat: add border radius to border form * chore: separate background color and image also, don't automatically append the 'px' on padding and border radius * fix: make labeled select value optional * feat: add container appearance form * fix: correctly build border property also make the value argument optional * feat: set the container ast also set the expected types on css values to string instead of number, since we're using the px values
- Loading branch information
Showing
16 changed files
with
265 additions
and
52 deletions.
There are no files selected for viewing
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
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
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
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
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,4 @@ | ||
import { pure } from 'recompose'; | ||
import { LabeledSelect as Component } from './labeled_select'; | ||
|
||
export const LabeledSelect = pure(Component); |
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
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
53 changes: 53 additions & 0 deletions
53
public/expression_types/arg_types/container_style/appearance_form.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,53 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { ControlLabel } from 'react-bootstrap'; | ||
import { ColorPickerMini } from '../../../components/color_picker_mini'; | ||
import { LabeledSelect } from '../../../components/labeled_select'; | ||
|
||
const paddings = [['0px', 'None'], '1px', '2px', '3px', '4px', '5px', '6px', '7px', '8px', '9px', '10px']; | ||
const opacities = [[1, '100%'], [0.9, '90%'], [0.7, '70%'], [0.5, '50%'], [0.3, '30%'], [0.1, '10%']]; | ||
|
||
export const AppearanceForm = ({ className, padding, opacity, backgroundColor, onChange }) => { | ||
const namedChange = name => ev => onChange(name, ev.target.value); | ||
|
||
return ( | ||
<div className={className}> | ||
<LabeledSelect | ||
className="padding" | ||
label="Padding" | ||
value={padding} | ||
values={paddings} | ||
onChange={namedChange('padding')} | ||
/> | ||
|
||
<LabeledSelect | ||
className="opacity" | ||
label="Opacity" | ||
value={opacity} | ||
values={opacities} | ||
onChange={namedChange('opacity')} | ||
/> | ||
|
||
<div className="border-color"> | ||
<ColorPickerMini | ||
value={backgroundColor} | ||
onChange={color => onChange('backgroundColor', color)} /> | ||
<ControlLabel>BG Color</ControlLabel> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
AppearanceForm.propTypes = { | ||
padding: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.number, | ||
]), | ||
backgroundColor: PropTypes.string, | ||
opacity: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.number, | ||
]), | ||
onChange: PropTypes.func.isRequired, | ||
className: PropTypes.string, | ||
}; |
66 changes: 66 additions & 0 deletions
66
public/expression_types/arg_types/container_style/border_form.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,66 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { ControlLabel } from 'react-bootstrap'; | ||
import { ColorPickerMini } from '../../../components/color_picker_mini'; | ||
import { LabeledSelect } from '../../../components/labeled_select'; | ||
|
||
const widths = [['0px', 'None'], '1px', '2px', '3px', '4px', '5px', '6px', '7px', '8px', '9px', '10px']; | ||
const styles = ['solid', 'dotted', 'dashed', 'double', 'groove', 'ridge', 'inset', 'outset']; | ||
|
||
export const BorderForm = ({ className, value, radius, onChange }) => { | ||
const border = value || ''; | ||
const [ borderWidth, borderStyle, borderColor ] = border.split(' '); | ||
|
||
const namedChange = name => ev => { | ||
const val = ev.target.value; | ||
|
||
if (name === 'borderWidth') return onChange('border', `${val} ${borderStyle} ${borderColor}`); | ||
if (name === 'borderStyle') return onChange('border', `${borderWidth} ${val} ${borderColor}`); | ||
|
||
onChange(name, ev.target.value); | ||
}; | ||
|
||
const borderColorChange = color => onChange('border', `${borderWidth} ${borderStyle} ${color}`); | ||
|
||
return ( | ||
<div className={className}> | ||
<LabeledSelect | ||
className="border-width" | ||
label="Width" | ||
value={borderWidth} | ||
values={[ ...widths ]} | ||
onChange={namedChange('borderWidth')} | ||
/> | ||
|
||
<LabeledSelect | ||
className="border-style" | ||
label="Style" | ||
value={borderStyle} | ||
values={styles} | ||
onChange={namedChange('borderStyle')} | ||
/> | ||
|
||
<LabeledSelect | ||
className="border-radius" | ||
label="Radius" | ||
value={radius} | ||
values={[ ...widths ]} | ||
onChange={namedChange('borderRadius')} | ||
/> | ||
|
||
<div className="border-color"> | ||
<ColorPickerMini | ||
value={borderColor} | ||
onChange={borderColorChange} /> | ||
<ControlLabel>Color</ControlLabel> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
BorderForm.propTypes = { | ||
value: PropTypes.string, | ||
radius: PropTypes.string, | ||
onChange: PropTypes.func.isRequired, | ||
className: PropTypes.string, | ||
}; |
58 changes: 58 additions & 0 deletions
58
public/expression_types/arg_types/container_style/container_style.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,58 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { get } from 'lodash'; | ||
import { set } from 'object-path-immutable'; | ||
import { ArgType } from '../../arg_type'; | ||
import { getStringType } from '../../../../common/types/get_type'; | ||
import { BorderForm } from './border_form'; | ||
import { AppearanceForm } from './appearance_form'; | ||
|
||
import './container_style.less'; | ||
|
||
const template = ({ onValueChange, argValue }) => { | ||
const args = get(argValue, 'chain.0.arguments', {}); | ||
|
||
const getArgValue = (args, name, alt) => get(args, [name, 0, 'value'], alt); | ||
|
||
const setArgValue = (args, name, val) => { | ||
const value = { | ||
value: val, | ||
type: getStringType(val), | ||
}; | ||
const newValue = set(argValue, ['chain', 0, 'arguments', name, 0], value); | ||
onValueChange(newValue); | ||
}; | ||
|
||
return ( | ||
<div className="canvas__argtype--containerStyle"> | ||
<div> | ||
<label>Appearance</label> | ||
<AppearanceForm | ||
className="canvas__argtype--containerStyle--appearance" | ||
padding={getArgValue(args, 'padding')} | ||
backgroundColor={getArgValue(args, 'backgroundColor')} | ||
opacity={getArgValue(args, 'opacity')} | ||
onChange={(...blah) => setArgValue(args, ...blah)} | ||
/> | ||
|
||
<label>Border</label> | ||
<BorderForm | ||
className="canvas__argtype--containerStyle--border" | ||
value={getArgValue(args, 'border', '')} | ||
radius={getArgValue(args, 'borderRadius')} | ||
onChange={(...blah) => setArgValue(args, ...blah)} /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
template.propTypes = { | ||
onValueChange: PropTypes.func.isRequired, | ||
argValue: PropTypes.object.isRequired, | ||
}; | ||
|
||
export const containerStyle = () => new ArgType('containerStyle', { | ||
displayName: 'Image Upload', | ||
description: 'Select or upload an image', | ||
template: template, | ||
}); |
18 changes: 18 additions & 0 deletions
18
public/expression_types/arg_types/container_style/container_style.less
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,18 @@ | ||
@import (reference) "../../../style/variables"; | ||
|
||
.canvas__argtype--containerStyle { | ||
.canvas__argtype--containerStyle--appearance, | ||
.canvas__argtype--containerStyle--border { | ||
display: flex; | ||
|
||
& > * { | ||
margin-right: @spacingXS; | ||
flex: 1; | ||
|
||
.control-label { | ||
display: block; | ||
margin-top: @spacingXS; | ||
} | ||
} | ||
} | ||
} |
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 @@ | ||
export { containerStyle } from './container_style'; |
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 |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import { containerStyle } from './container_style'; | ||
import { datacolumn } from './datacolumn'; | ||
import { expression } from './expression'; | ||
import { imageUpload } from './image_upload'; | ||
import { seriesStyle } from './series_style'; | ||
import { palette } from './palette'; | ||
import { select } from './select'; | ||
import { seriesStyle } from './series_style'; | ||
import { textarea } from './textarea'; | ||
import { palette } from './palette'; | ||
|
||
|
||
export default [ | ||
containerStyle, | ||
datacolumn, | ||
expression, | ||
imageUpload, | ||
seriesStyle, | ||
palette, | ||
select, | ||
seriesStyle, | ||
textarea, | ||
palette, | ||
]; |
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
Oops, something went wrong.