Closed
Conversation
Contributor
Author
|
I added Gutenberg part as a reference to how I tried to override In a nutshell, I tried the following: /**
* External dependencies
*/
import { get, isString } from 'lodash';
import { createElement as createElementDefault } from 'react';
import {
Circle,
Defs,
Ellipse,
G,
Line,
Path,
Polygon,
TextPath,
TSpan,
Svg,
} from 'react-native-svg';
const htmlTagToNativeComponent = {
circle: Circle,
defs: Defs,
ellipse: Ellipse,
g: G,
line: Line,
path: Path,
polygon: Polygon,
svg: Svg,
textPath: TextPath,
tspan: TSpan,
/*Polyline,
Text,
Rect,
Use,
Image,
Symbol,
LinearGradient,
RadialGradient,
Stop,
ClipPath*/
};
const mapHTMLTagToNativeComponent = ( type ) => {
if ( ! isString( type ) ) {
return type;
}
return get( htmlTagToNativeComponent, [ type ], type );
};
/**
* Returns a new element of given type. Type can be either a string tag name or
* another function which itself returns an element.
*
* @param {?(string|Function)} type Tag name or element creator.
* @param {Object} props Element properties, either attribute
* set to apply to node or values to
* pass through to element creator.
* @param {...WPElement} children Descendant elements.
*
* @return {WPElement} Element.
*/
const createElement = ( type, props, ...children ) => {
return createElementDefault(
mapHTMLTagToNativeComponent( type ),
props,
...children
);
};
export default createElement;It didn't work properly. |
d03935d to
c6f2f33
Compare
144f7f9 to
bc632f1
Compare
Closed
4 tasks
Contributor
Author
|
You made Flow and Jest unhappy, it probably needs more works for the configuration. However, this is exactly what should happen in terms of using Babel and consuming WordPress packages 👍 |
Merged
6316975 to
2656bce
Compare
2656bce to
fbaba3a
Compare
Contributor
Author
|
I don't think it is still valid. We can always reopen :) |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR tries to refactor code to use
createElementthrough@wordpres/elementrather than directly to stay closer to how Gutenberg web works.It's old PR which worked with Babel 6, we probably would have to rework it to make it up to date.
It also is part of my exploration of overriding
createElementto allow usage of HTML tags as component names.Requires WordPress/gutenberg#11129
/cc @Tug