From 9a7ef85aa426e30671efb2aba2b365c7a67c98a9 Mon Sep 17 00:00:00 2001 From: kyle Date: Tue, 12 Dec 2017 14:33:41 -0800 Subject: [PATCH] Clarify wrapComponent interface in Plugin API docs --- docs/customization/plugin-api.md | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/docs/customization/plugin-api.md b/docs/customization/plugin-api.md index db88ca71..245b5a14 100644 --- a/docs/customization/plugin-api.md +++ b/docs/customization/plugin-api.md @@ -293,7 +293,7 @@ const MyWrapSelectorsPlugin = function(system) { Wrap Components allow you to override a component registered within the system. -Wrap Components are function factories with the signature `(OriginalComponent, system) => props => ReactElement`. +Wrap Components are function factories with the signature `(OriginalComponent, system) => props => ReactElement`. If you'd prefer to provide a React component class, `(OriginalComponent, system) => ReactClass` works as well. ```javascript const MyWrapBuiltinComponentPlugin = function(system) { @@ -310,9 +310,12 @@ const MyWrapBuiltinComponentPlugin = function(system) { } ``` +Here's another example that includes a code sample of a component that will be wrapped: + ```javascript -// Overriding a component from a plugin +///// Overriding a component from a plugin +// Here's our normal, unmodified component. const MyNumberDisplayPlugin = function(system) { return { components: { @@ -321,6 +324,7 @@ const MyNumberDisplayPlugin = function(system) { } } +// Here's a component wrapper defined as a function. const MyWrapComponentPlugin = function(system) { return { wrapComponents: { @@ -328,6 +332,7 @@ const MyWrapComponentPlugin = function(system) { if(props.number > 10) { return

Warning! Big number ahead.

+
} else { return @@ -336,8 +341,30 @@ const MyWrapComponentPlugin = function(system) { } } } + +// Alternatively, here's the same component wrapper defined as a class. +const MyWrapComponentPlugin = function(system) { + return { + wrapComponents: { + NumberDisplay: (Original, system) => class WrappedNumberDisplay extends React.component { + render() { + if(props.number > 10) { + return
+

Warning! Big number ahead.

+ +
+ } else { + return + } + } + } + } + } +} ``` + + ##### fn The fn interface allows you to add helper functions to the system for use elsewhere.