-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] - Recharts issue 3113 filterProps #4127
Closed
BuddhikaGeasman
wants to merge
3
commits into
recharts:master
from
BuddhikaGeasman:recharts-issue-3113-init-poc
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -9,9 +9,14 @@ import { isFragment } from 'react-is'; | |
import { DotProps } from '..'; | ||
import { isNumber } from './DataUtils'; | ||
import { shallowEqual } from './ShallowEqual'; | ||
import { FilteredSvgElementType, FilteredElementKeyMap, SVGElementPropKeys, EventKeys } from './types'; | ||
import { AreaDot } from '../cartesian/Area'; | ||
import { LineDot } from '../cartesian/Line'; | ||
import { getSVGElementAttributesInCamelCase, getSVGElementTags, findAllAttributesPresent } from './svgUtils/SVGUtils'; | ||
import { svgElementAttributes } from './svgUtils/SVGElementAttributes'; | ||
|
||
// @Types | ||
import { FilteredSvgElementType, EventKeys } from './types'; | ||
import { SVGElementType } from './svgUtils/types'; | ||
|
||
const REACT_BROWSER_EVENT_MAP: Record<string, string> = { | ||
click: 'onClick', | ||
|
@@ -183,87 +188,7 @@ export const validateWidthHeight = (el: any): boolean => { | |
return true; | ||
}; | ||
|
||
const SVG_TAGS: string[] = [ | ||
'a', | ||
'altGlyph', | ||
'altGlyphDef', | ||
'altGlyphItem', | ||
'animate', | ||
'animateColor', | ||
'animateMotion', | ||
'animateTransform', | ||
'circle', | ||
'clipPath', | ||
'color-profile', | ||
'cursor', | ||
'defs', | ||
'desc', | ||
'ellipse', | ||
'feBlend', | ||
'feColormatrix', | ||
'feComponentTransfer', | ||
'feComposite', | ||
'feConvolveMatrix', | ||
'feDiffuseLighting', | ||
'feDisplacementMap', | ||
'feDistantLight', | ||
'feFlood', | ||
'feFuncA', | ||
'feFuncB', | ||
'feFuncG', | ||
'feFuncR', | ||
'feGaussianBlur', | ||
'feImage', | ||
'feMerge', | ||
'feMergeNode', | ||
'feMorphology', | ||
'feOffset', | ||
'fePointLight', | ||
'feSpecularLighting', | ||
'feSpotLight', | ||
'feTile', | ||
'feTurbulence', | ||
'filter', | ||
'font', | ||
'font-face', | ||
'font-face-format', | ||
'font-face-name', | ||
'font-face-url', | ||
'foreignObject', | ||
'g', | ||
'glyph', | ||
'glyphRef', | ||
'hkern', | ||
'image', | ||
'line', | ||
'lineGradient', | ||
'marker', | ||
'mask', | ||
'metadata', | ||
'missing-glyph', | ||
'mpath', | ||
'path', | ||
'pattern', | ||
'polygon', | ||
'polyline', | ||
'radialGradient', | ||
'rect', | ||
'script', | ||
'set', | ||
'stop', | ||
'style', | ||
'svg', | ||
'switch', | ||
'symbol', | ||
'text', | ||
'textPath', | ||
'title', | ||
'tref', | ||
'tspan', | ||
'use', | ||
'view', | ||
'vkern', | ||
]; | ||
const SVG_TAGS: string[] = getSVGElementTags(svgElementAttributes); | ||
|
||
const isSvgElement = (child: any) => child && child.type && isString(child.type) && SVG_TAGS.indexOf(child.type) >= 0; | ||
|
||
|
@@ -282,18 +207,22 @@ export const isValidSpreadableProp = ( | |
property: unknown, | ||
key: string, | ||
includeEvents?: boolean, | ||
svgElementType?: FilteredSvgElementType, | ||
svgElementType?: SVGElementType, | ||
) => { | ||
/** | ||
* If the svg element type is explicitly included, check against the filtered element key map | ||
* to determine if there are attributes that should only exist on that element type. | ||
* @todo Add an internal cjs version of https://github.com/wooorm/svg-element-attributes for full coverage. | ||
*/ | ||
const matchingElementTypeKeys = FilteredElementKeyMap?.[svgElementType] ?? []; | ||
const svgElementAttributesInCamelCase = getSVGElementAttributesInCamelCase(svgElementAttributes); | ||
const matchingElementTypeKeys = svgElementAttributesInCamelCase?.[svgElementType] ?? []; | ||
|
||
const { polygon, polyline, svg, ...rest } = svgElementAttributesInCamelCase; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do these three need to be extracted out? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was me, messing with things! |
||
const svgAttributes = findAllAttributesPresent(rest); | ||
|
||
return ( | ||
(!isFunction(property) && | ||
((svgElementType && matchingElementTypeKeys.includes(key)) || SVGElementPropKeys.includes(key))) || | ||
((svgElementType && matchingElementTypeKeys.includes(key)) || svgAttributes.includes(key))) || | ||
(includeEvents && EventKeys.includes(key)) | ||
); | ||
}; | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the props we accept are also in camel case for the same reason (react), why do we need to do any transformation here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created the
getSVGElementAttributesInCamelCase
cause thesvgElementAttributes
object structured as follows. I should have simply create the util to return the converted object without having to do the conversion multiple times.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can probably do the conversion and once and keep it stored as camel case, we don't need to do it at runtime