This repository was archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
refactor(Label): cleanup docs and simplify render #642
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8a51b36
refactor(Label): cleanup docs and simplify render
e44c893
Merge branch 'master' into refactor/label
alinais 83c4892
fix shorthand tests logic
kuzhelov-ms aaa5fcf
Merge branch 'master' into refactor/label
kuzhelov 7fe9ca5
add changelog entry
kuzhelov-ms b35483b
Merge branch 'master' into refactor/label
df788cc
Merge branch 'master' into refactor/label
kuzhelov f85c130
Merge branch 'master' into refactor/label
kuzhelov 2c5692e
Merge branch 'master' into refactor/label
alinais 2d6c40a
Merge branches 'master' and 'refactor/label' of https://github.com/st…
layershifter e08fb64
Merge branches 'master' and 'refactor/label' of https://github.com/st…
layershifter 3db7b0a
Merge branch 'master' of https://github.com/stardust-ui/react into re…
layershifter bfa8a24
fix to avoid visual regressions
layershifter 094d6b6
Merge branch 'master' into refactor/label
layershifter 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 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,27 +25,27 @@ export interface LabelProps | |
| ContentComponentProps { | ||
| accessibility?: Accessibility | ||
|
|
||
| /** A label can be circular. */ | ||
| /** A Label can be circular. */ | ||
| circular?: boolean | ||
|
|
||
| /** A Label can take the width of its container. */ | ||
| /** A Label can take up the width of its container. */ | ||
| fluid?: boolean | ||
|
|
||
| /** Label can have an icon. */ | ||
| /** A Label can have an icon. */ | ||
| icon?: ShorthandValue | ||
|
|
||
| /** An icon label can format an Icon to appear before or after the text in the label */ | ||
| /** A Label can position its Icon at the start or end of the layout. */ | ||
| iconPosition?: 'start' | 'end' | ||
|
|
||
| /** Label can have an image. */ | ||
| /** A Label can contain an image. */ | ||
| image?: ShorthandValue | ||
|
|
||
| /** An icon label can format an Icon to appear before or after the text in the label */ | ||
| /** A Label can position its image at the start or end of the layout. */ | ||
| imagePosition?: 'start' | 'end' | ||
| } | ||
|
|
||
| /** | ||
| * A label is used to classify content. | ||
| * A Label is used to classify content. | ||
| */ | ||
| class Label extends UIComponent<ReactProps<LabelProps>, any> { | ||
| static displayName = 'Label' | ||
|
|
@@ -82,69 +82,58 @@ class Label extends UIComponent<ReactProps<LabelProps>, any> { | |
| renderComponent({ ElementType, classes, rest, variables, styles }) { | ||
| const { children, content, icon, iconPosition, image, imagePosition } = this.props | ||
|
|
||
| const imageElement = | ||
| image && | ||
| Image.create(image, { | ||
| defaultProps: { | ||
| styles: styles.image, | ||
| variables: variables.image, | ||
| }, | ||
| }) | ||
|
|
||
| const iconElement = | ||
| icon && | ||
| Icon.create(icon, { | ||
| defaultProps: { | ||
| styles: styles.icon, | ||
| variables: variables.icon, | ||
| }, | ||
| overrideProps: this.handleIconOverrides, | ||
| }) | ||
|
|
||
| let start: React.ReactNode = null | ||
| let end: React.ReactNode = null | ||
|
|
||
| // Default positioning of the image and icon | ||
| if (image && imagePosition === 'start') { | ||
| start = imageElement | ||
| } | ||
| if (icon && iconPosition === 'end') { | ||
| end = iconElement | ||
| if (childrenExist(children)) { | ||
| return ( | ||
| <ElementType {...rest} className={classes.root}> | ||
| {children} | ||
| </ElementType> | ||
| ) | ||
| } | ||
|
|
||
| // Custom positioning of the icon and image | ||
| if (icon && iconPosition === 'start') { | ||
| if (image && imagePosition === 'start') { | ||
| start = ( | ||
| <React.Fragment> | ||
| {imageElement} | ||
| {iconElement} | ||
| </React.Fragment> | ||
| ) | ||
| } else { | ||
| start = iconElement | ||
| } | ||
| } | ||
| if (image && imagePosition === 'end') { | ||
| if (icon && iconPosition === 'end') { | ||
| end = ( | ||
| <React.Fragment> | ||
| {iconElement} | ||
| {imageElement} | ||
| </React.Fragment> | ||
| ) | ||
| } else { | ||
| end = imageElement | ||
| } | ||
| } | ||
| const imageElement = Image.create(image, { | ||
|
||
| defaultProps: { | ||
| styles: styles.image, | ||
| variables: variables.image, | ||
| }, | ||
| }) | ||
| const iconElement = Icon.create(icon, { | ||
| defaultProps: { | ||
| styles: styles.icon, | ||
| variables: variables.icon, | ||
| }, | ||
| overrideProps: this.handleIconOverrides, | ||
| }) | ||
|
|
||
| const startImage = imagePosition === 'start' && imageElement | ||
| const startIcon = iconPosition === 'start' && iconElement | ||
| const endIcon = iconPosition === 'end' && iconElement | ||
| const endImage = imagePosition === 'end' && imageElement | ||
|
|
||
| const hasStartElement = startImage || startIcon | ||
| const hasEndElement = endIcon || endImage | ||
|
|
||
| return ( | ||
| <ElementType {...rest} className={classes.root}> | ||
| {childrenExist(children) ? ( | ||
| children | ||
| ) : ( | ||
| <Layout main={content} start={start} end={end} gap={pxToRem(3)} /> | ||
| )} | ||
| <Layout | ||
| start={ | ||
| hasStartElement && ( | ||
| <> | ||
| {startImage} | ||
| {startIcon} | ||
| </> | ||
| ) | ||
| } | ||
| main={content} | ||
| end={ | ||
| hasEndElement && ( | ||
| <> | ||
| {endIcon} | ||
| {endImage} | ||
| </> | ||
| ) | ||
| } | ||
| gap={pxToRem(3)} | ||
| /> | ||
| </ElementType> | ||
| ) | ||
| } | ||
|
|
||
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
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.
Make terminology consistent. Allowed prop values are "start" and "end", so we should use the same wording in the description.