Skip to content

Commit

Permalink
fix(website): fix InheritedColorControl
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte authored and Raphaël Benitte committed May 9, 2019
1 parent a54ac59 commit 862fa0b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
21 changes: 17 additions & 4 deletions website/src/components/controls/InheritedColorControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const themeProperties = ['background', 'grid.line.stroke', 'labels.text.fill'].m
value: prop,
}))

const defaultInheritableProperties = ['color']

const InheritedColorControl = ({
id,
property,
Expand All @@ -32,8 +34,8 @@ const InheritedColorControl = ({
defaultCustomColor,
defaultThemeProperty,
defaultFrom,
inheritableProperties,
onChange,
options: { inheritableProperties = defaultInheritableProperties } = {},
}) => {
const [customColor, setCustomColor] = useState(isString(value) ? value : defaultCustomColor)
const [themeProp, setThemeProp] = useState(
Expand Down Expand Up @@ -64,6 +66,16 @@ const InheritedColorControl = ({
},
[onChange, setThemeProp]
)
const handleFromPropertyChange = useCallback(
value => {
setFromProp(value.value)
onChange({
from: value.value,
modifiers,
})
},
[onChange, setThemeProp]
)
const handleModifierChange = useCallback(
index => modifier => {
const newModifiers = [...modifiers]
Expand Down Expand Up @@ -117,7 +129,7 @@ const InheritedColorControl = ({
<Select
options={propertyOptions}
value={propertyOptions.find(prop => prop.value === value.from)}
//onChange={handleThemePropertyChange}
onChange={handleFromPropertyChange}
/>
<SubLabel>modifiers</SubLabel>
{modifiers.length === 0 && <NoModifiers>No modifier.</NoModifiers>}
Expand Down Expand Up @@ -173,17 +185,18 @@ InheritedColorControl.propTypes = {
flavors: PropTypes.arrayOf(PropTypes.oneOf(['svg', 'html', 'canvas', 'api'])).isRequired,
currentFlavor: PropTypes.oneOf(['svg', 'html', 'canvas', 'api']).isRequired,
onChange: PropTypes.func.isRequired,
inheritableProperties: PropTypes.arrayOf(PropTypes.string).isRequired,
defaultCustomColor: PropTypes.string.isRequired,
defaultThemeProperty: PropTypes.string.isRequired,
defaultFrom: PropTypes.string.isRequired,
value: inheritedColorPropType.isRequired,
options: PropTypes.shape({
inheritableProperties: PropTypes.arrayOf(PropTypes.string),
}),
}
InheritedColorControl.defaultProps = {
defaultCustomColor: 'black',
defaultThemeProperty: 'background',
defaultFrom: 'color',
inheritableProperties: ['color'],
}

export default InheritedColorControl
Expand Down
12 changes: 12 additions & 0 deletions website/src/data/components/network/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ const props = [
group: 'Nodes',
type: 'string | object | (link: Link) => string',
help: `Control nodes' border color.`,
defaultValue: NetworkDefaultProps.nodeBorderColor,
controlType: 'inheritedColor',
},
{
Expand All @@ -158,6 +159,17 @@ const props = [
defaultValue: NetworkDefaultProps.linkThickness,
controlType: 'lineWidth',
},
{
key: 'linkColor',
group: 'Links',
type: 'string | (link: Link) => string',
help: `Control links' color.`,
defaultValue: NetworkDefaultProps.linkColor,
controlType: 'inheritedColor',
controlOptions: {
inheritableProperties: ['source.color', 'target.color'],
},
},
{
key: 'layers',
group: 'Customization',
Expand Down
1 change: 1 addition & 0 deletions website/src/pages/network/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const initialProperties = Object.freeze({
nodeBorderWidth: 1,
nodeBorderColor: { theme: 'background' },

linkColor: NetworkCanvasDefaultProps.linkColor,
linkThickness: 1,

isInteractive: true,
Expand Down
1 change: 1 addition & 0 deletions website/src/pages/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const initialProperties = Object.freeze({
modifiers: [['darker', 0.8]],
},

linkColor: NetworkDefaultProps.linkColor,
linkThickness: link => (2 - link.source.depth) * 2,

isInteractive: true,
Expand Down

0 comments on commit 862fa0b

Please sign in to comment.