-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
feat(ElementType): new wrapper for all elements #2306
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d117cf6
feat(ElementType): new wrapper for all elements
layershifter 3c6adc4
Merge branches 'feat/element-type' and 'master' of https://github.com…
layershifter 93cde4d
fix(Image): fix merge problems
layershifter a6b9ac1
fix(isConformant): merge master
levithomason File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ import { | |
childrenUtils, | ||
createShorthandFactory, | ||
customPropTypes, | ||
getElementType, | ||
ElementType, | ||
getUnhandledProps, | ||
META, | ||
partitionHTMLProps, | ||
|
@@ -16,6 +16,7 @@ import { | |
useKeyOrValueAndKey, | ||
useValueAndKey, | ||
useVerticalAlignProp, | ||
withComputedType, | ||
} from '../../lib' | ||
import Dimmer from '../../modules/Dimmer' | ||
import Label from '../Label/Label' | ||
|
@@ -27,8 +28,9 @@ const imageProps = ['alt', 'height', 'src', 'srcSet', 'width'] | |
* An image is a graphic representation of something. | ||
* @see Icon | ||
*/ | ||
function Image(props) { | ||
const InnerImage = (props) => { | ||
const { | ||
as, | ||
avatar, | ||
bordered, | ||
centered, | ||
|
@@ -48,7 +50,6 @@ function Image(props) { | |
size, | ||
spaced, | ||
verticalAlign, | ||
wrapped, | ||
ui, | ||
} = props | ||
|
||
|
@@ -70,37 +71,27 @@ function Image(props) { | |
'image', | ||
className, | ||
) | ||
const rest = getUnhandledProps(Image, props) | ||
const rest = getUnhandledProps(InnerImage, props) | ||
const [imgTagProps, rootProps] = partitionHTMLProps(rest, { htmlProps: imageProps }) | ||
const ElementType = getElementType(Image, props, () => { | ||
if (!_.isNil(dimmer) || !_.isNil(label) || !_.isNil(wrapped) || !childrenUtils.isNil(children)) return 'div' | ||
}) | ||
|
||
if (!childrenUtils.isNil(children)) { | ||
return <ElementType {...rest} className={classes}>{children}</ElementType> | ||
return <ElementType {...rest} as={as} className={classes}>{children}</ElementType> | ||
} | ||
if (!childrenUtils.isNil(content)) { | ||
return <ElementType {...rest} className={classes}>{content}</ElementType> | ||
return <ElementType {...rest} as={as} className={classes}>{content}</ElementType> | ||
} | ||
|
||
if (ElementType === 'img') return <ElementType {...rootProps} {...imgTagProps} className={classes} /> | ||
if (as === 'img') return <ElementType {...rootProps} {...imgTagProps} as={as} className={classes} /> | ||
return ( | ||
<ElementType {...rootProps} className={classes} href={href}> | ||
<ElementType {...rootProps} as={as} className={classes} href={href}> | ||
{Dimmer.create(dimmer)} | ||
{Label.create(label)} | ||
<img {...imgTagProps} /> | ||
</ElementType> | ||
) | ||
} | ||
|
||
Image.Group = ImageGroup | ||
|
||
Image._meta = { | ||
name: 'Image', | ||
type: META.TYPES.ELEMENT, | ||
} | ||
|
||
Image.propTypes = { | ||
InnerImage.propTypes = { | ||
/** An element type to render as (string or function). */ | ||
as: customPropTypes.as, | ||
|
||
|
@@ -174,11 +165,24 @@ Image.propTypes = { | |
wrapped: PropTypes.bool, | ||
} | ||
|
||
Image.defaultProps = { | ||
InnerImage.defaultProps = { | ||
as: 'img', | ||
ui: true, | ||
} | ||
|
||
const computeType = ({ children, dimmer, label, wrapped }) => { | ||
if (!_.isNil(dimmer) || !_.isNil(label) || !_.isNil(wrapped) || !childrenUtils.isNil(children)) return 'div' | ||
} | ||
|
||
const Image = withComputedType(computeType)(InnerImage) | ||
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. Type computing function moved to HOC |
||
|
||
Image.Group = ImageGroup | ||
|
||
Image._meta = { | ||
name: 'Image', | ||
type: META.TYPES.ELEMENT, | ||
} | ||
|
||
Image.create = createShorthandFactory(Image, value => ({ src: value })) | ||
|
||
export default Image |
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
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
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
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.
Container
is wrapped with HOC, we can't userprototype.name
. So, we can use arrow functions for components_meta
should be exported on the default export, now it's an enhanced component. However, I'm not happy aboutInner-
prefix