-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1203 from jansule/composition-docs
Add compositionContext docs
- Loading branch information
Showing
2 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
155 changes: 155 additions & 0 deletions
155
src/Component/CompositionContext/CompositionContext.example.md
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,155 @@ | ||
`CompositionContext` lets you disable fields and editors and/or replace fields with custom components. | ||
|
||
In order to compose your own editors, a CompositionContext provider has to be wrapped around the editor(s) to customize. All configurations have to be set within the object passed to the value property of CompositionContext. The corresponding interface is defined in `src/Components/CompositionContext/CompositionContext.tsx`. | ||
|
||
#### Disable single field | ||
|
||
Disables/Enables rotation field in IconEditor. | ||
|
||
```jsx | ||
import * as React from 'react'; | ||
import { CompositionContext, IconEditor } from 'geostyler'; | ||
import { Switch } from 'antd'; | ||
|
||
class CompositionContextExample extends React.Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
symbolizer: { | ||
kind: 'Icon' | ||
}, | ||
enableRotation: false | ||
} | ||
|
||
this.onSymbolizerChange = this.onSymbolizerChange.bind(this); | ||
this.onRotationChange = this.onRotationChange.bind(this); | ||
} | ||
|
||
onSymbolizerChange(symbolizer) { | ||
this.setState({ | ||
symbolizer: symbolizer | ||
}); | ||
} | ||
|
||
onRotationChange(enable) { | ||
this.setState({ | ||
enableRotation: enable | ||
}); | ||
} | ||
|
||
render() { | ||
const { | ||
symbolizer, | ||
enableRotation | ||
} = this.state; | ||
|
||
const composition = { | ||
IconEditor: { | ||
rotateField: enableRotation ? undefined : false | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<span>Enable rotation field </span> | ||
<Switch | ||
checked={enableRotation} | ||
onChange={this.onRotationChange} | ||
checkedChildren="true" | ||
unCheckedChildren="false" | ||
/> | ||
<hr/> | ||
<CompositionContext.Provider value={composition}> | ||
<IconEditor | ||
symbolizer={symbolizer} | ||
onSymbolizerChange={this.onSymbolizerChange} | ||
/> | ||
</CompositionContext.Provider> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
<CompositionContextExample /> | ||
``` | ||
|
||
#### Replace field with custom field | ||
Replaces rotation field with custom component that limits the rotation to 90 degrees in each direction. | ||
```jsx | ||
import * as React from 'react'; | ||
import { CompositionContext, IconEditor } from 'geostyler'; | ||
import { Switch, InputNumber } from 'antd'; | ||
|
||
class CompositionContextExample extends React.Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
symbolizer: { | ||
kind: 'Icon', | ||
rotate: 180 | ||
}, | ||
customRotation: false | ||
} | ||
|
||
this.onSymbolizerChange = this.onSymbolizerChange.bind(this); | ||
this.toggleCustomRotation = this.toggleCustomRotation.bind(this); | ||
} | ||
|
||
onSymbolizerChange(symbolizer) { | ||
this.setState({ | ||
symbolizer: symbolizer | ||
}); | ||
} | ||
|
||
toggleCustomRotation(enable) { | ||
this.setState({ | ||
customRotation: enable | ||
}); | ||
} | ||
|
||
render() { | ||
const { | ||
symbolizer, | ||
customRotation | ||
} = this.state; | ||
|
||
const composition = { | ||
IconEditor: { | ||
rotateField: customRotation ? ( | ||
<InputNumber | ||
className="editor-field rotate-field" | ||
min={-90} | ||
max={90} | ||
value={symbolizer.rotate} | ||
/> | ||
) : undefined | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<span>Use custom component </span> | ||
<Switch | ||
checked={customRotation} | ||
onChange={this.toggleCustomRotation} | ||
checkedChildren="true" | ||
unCheckedChildren="false" | ||
/> | ||
<hr/> | ||
<CompositionContext.Provider value={composition}> | ||
<IconEditor | ||
symbolizer={symbolizer} | ||
onSymbolizerChange={this.onSymbolizerChange} | ||
/> | ||
</CompositionContext.Provider> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
<CompositionContextExample /> | ||
``` |
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