add ComponentMapper to allow plugging in custom compoment implementations#119
add ComponentMapper to allow plugging in custom compoment implementations#119sfc-gh-pfinnigan wants to merge 1 commit intorefactor/StreamlitAppfrom
Conversation
| * limitations under the License. | ||
| */ | ||
|
|
||
| type ElementType = |
There was a problem hiding this comment.
this is copied from the .proto file since I couldn't figure out how to import it
There was a problem hiding this comment.
import {Element as ElementProto } from 'path/to/proto'
type ElementType = Exclude<ElementProto["type"], undefined>
| toast: MappingNotYetDefined | ||
| vegaLiteChart: MappingNotYetDefined | ||
| video: MappingNotYetDefined | ||
| heading: (props: { value: string }) => React.ReactElement |
There was a problem hiding this comment.
this is an example of how to type the plumbed properties
| switch (node.element.type) { | ||
| case "heading": | ||
| return componentFunc({ | ||
| value: node.element.heading?.body, |
There was a problem hiding this comment.
here's the transform from protobuf element to the properties to pass to the custom "heading" component
| <div className="card-body"> | ||
| <StreamlitView /> | ||
| <StreamlitView | ||
| componentMapper={{ |
There was a problem hiding this comment.
example of using the componentMapper to modify how "heading" gets rendered
There was a problem hiding this comment.
You should make it red or something to prove that it's really doing something :)
There was a problem hiding this comment.
I made it really big 🙃
kmcgrady
left a comment
There was a problem hiding this comment.
Found an typing tip, but looks great
| * limitations under the License. | ||
| */ | ||
|
|
||
| type ElementType = |
There was a problem hiding this comment.
import {Element as ElementProto } from 'path/to/proto'
type ElementType = Exclude<ElementProto["type"], undefined>
Describe your changes
Add a "ComponentMapper" which allows overriding the default component implementations with custom ones. This allows plugging in custom component implementations (e.g. core-ui, chakra, other component libraries, or custom rolled). There's a mapping from the protobuf element type e.g.
headingto what component should be rendered. This mapping also transforms props from the protobuf. Those are not yet defined (I just implementedvalueforheadingas an example how to do this).GitHub Issue Link (if applicable)
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.