-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
177 additions
and
2 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
superset/assets/javascripts/explore/components/controls/ColorPickerControl.jsx
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,92 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { OverlayTrigger, Popover } from 'react-bootstrap'; | ||
import { SketchPicker } from 'react-color'; | ||
|
||
import ControlHeader from '../ControlHeader'; | ||
import { bnbColors } from '../../../modules/colors'; | ||
|
||
const propTypes = { | ||
onChange: PropTypes.func, | ||
value: PropTypes.object, | ||
}; | ||
|
||
const defaultProps = { | ||
onChange: () => {}, | ||
}; | ||
|
||
const swatchCommon = { | ||
position: 'absolute', | ||
width: '50px', | ||
height: '20px', | ||
top: '0px', | ||
left: '0px', | ||
right: '0px', | ||
bottom: '0px', | ||
}; | ||
|
||
const styles = { | ||
swatch: { | ||
width: '50px', | ||
height: '20px', | ||
position: 'relative', | ||
padding: '5px', | ||
borderRadius: '1px', | ||
display: 'inline-block', | ||
cursor: 'pointer', | ||
boxShadow: 'rgba(0, 0, 0, 0.15) 0px 0px 0px 1px inset, rgba(0, 0, 0, 0.25) 0px 0px 4px inset', | ||
}, | ||
color: { | ||
...swatchCommon, | ||
borderRadius: '2px', | ||
}, | ||
checkboard: { | ||
...swatchCommon, | ||
background: 'url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAMUlEQVQ4T2NkYGAQYcAP3uCTZhw1gGGYhAGBZIA/nYDCgBDAm9BGDWAAJyRCgLaBCAAgXwixzAS0pgAAAABJRU5ErkJggg==") left center', | ||
}, | ||
}; | ||
export default class ColorPickerControl extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.onChange = this.onChange.bind(this); | ||
} | ||
onChange(col) { | ||
this.props.onChange(col.rgb); | ||
} | ||
renderPopover() { | ||
return ( | ||
<Popover id="filter-popover" className="color-popover"> | ||
<SketchPicker | ||
color={this.props.value} | ||
onChange={this.onChange} | ||
presetColors={bnbColors.filter((s, i) => i < 7)} | ||
/> | ||
</Popover>); | ||
} | ||
render() { | ||
const c = this.props.value || { r: 0, g: 0, b: 0, a: 0 }; | ||
const colStyle = Object.assign( | ||
{}, styles.color, { background: `rgba(${c.r}, ${c.g}, ${c.b}, ${c.a})` }); | ||
return ( | ||
<div> | ||
<ControlHeader {...this.props} /> | ||
<OverlayTrigger | ||
container={document.body} | ||
trigger="click" | ||
rootClose | ||
ref="trigger" | ||
placement="right" | ||
overlay={this.renderPopover()} | ||
> | ||
<div style={styles.swatch}> | ||
<div style={styles.checkboard} /> | ||
<div style={colStyle} /> | ||
</div> | ||
</OverlayTrigger> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
ColorPickerControl.propTypes = propTypes; | ||
ColorPickerControl.defaultProps = defaultProps; |
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
41 changes: 41 additions & 0 deletions
41
superset/assets/spec/javascripts/explore/components/ColorPickerControl_spec.jsx
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,41 @@ | ||
/* eslint-disable no-unused-expressions */ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { describe, it, beforeEach } from 'mocha'; | ||
import { shallow } from 'enzyme'; | ||
import { OverlayTrigger } from 'react-bootstrap'; | ||
import { SketchPicker } from 'react-color'; | ||
|
||
import ColorPickerControl from | ||
'../../../../javascripts/explore/components/controls/ColorPickerControl'; | ||
import ControlHeader from '../../../../javascripts/explore/components/ControlHeader'; | ||
|
||
const defaultProps = { | ||
value: { }, | ||
}; | ||
|
||
describe('ColorPickerControl', () => { | ||
let wrapper; | ||
let inst; | ||
beforeEach(() => { | ||
wrapper = shallow(<ColorPickerControl {...defaultProps} />); | ||
inst = wrapper.instance(); | ||
}); | ||
|
||
it('renders a OverlayTrigger', () => { | ||
const controlHeader = wrapper.find(ControlHeader); | ||
expect(controlHeader).to.have.lengthOf(1); | ||
expect(wrapper.find(OverlayTrigger)).to.have.length(1); | ||
}); | ||
|
||
it('renders a OverlayTrigger', () => { | ||
const controlHeader = wrapper.find(ControlHeader); | ||
expect(controlHeader).to.have.lengthOf(1); | ||
expect(wrapper.find(OverlayTrigger)).to.have.length(1); | ||
}); | ||
|
||
it('renders a Popover with a SketchPicker', () => { | ||
const popOver = shallow(inst.renderPopover()); | ||
expect(popOver.find(SketchPicker)).to.have.lengthOf(1); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
superset/assets/spec/javascripts/explore/components/ColorScheme_spec.jsx
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,25 @@ | ||
/* eslint-disable no-unused-expressions */ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { describe, it, beforeEach } from 'mocha'; | ||
import { mount } from 'enzyme'; | ||
import { Creatable } from 'react-select'; | ||
|
||
import ColorSchemeControl from | ||
'../../../../javascripts/explore/components/controls/ColorSchemeControl'; | ||
import { ALL_COLOR_SCHEMES } from '../../../../javascripts/modules/colors'; | ||
|
||
const defaultProps = { | ||
options: Object.keys(ALL_COLOR_SCHEMES).map(s => ([s, s])), | ||
}; | ||
|
||
describe('ColorSchemeControl', () => { | ||
let wrapper; | ||
beforeEach(() => { | ||
wrapper = mount(<ColorSchemeControl {...defaultProps} />); | ||
}); | ||
|
||
it('renders a Creatable', () => { | ||
expect(wrapper.find(Creatable)).to.have.length(1); | ||
}); | ||
}); |