diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4195626607..2b396e4015 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,6 +25,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Adding `behaviors` section to the menu, under the components @kolaps33 ([#119](https://github.com/stardust-ui/react/pull/119))
- Add `avatar` prop to `Chat.Message` subcomponent @Bugaa92 ([#159](https://github.com/stardust-ui/react/pull/159))
- add `iconOnly` prop to `Button` @mnajdova ([#182](https://github.com/stardust-ui/react/pull/182))
+- Add Label `image` and `imagePosition`, removed `onIconClick` prop @mnajdova ([#55](https://github.com/stardust-ui/react/pull/55/))
## [v0.5.0](https://github.com/stardust-ui/react/tree/v0.5.0) (2018-08-30)
diff --git a/docs/src/examples/components/Label/Types/LabelExample.shorthand.tsx b/docs/src/examples/components/Label/Content/LabelExample.shorthand.tsx
similarity index 100%
rename from docs/src/examples/components/Label/Types/LabelExample.shorthand.tsx
rename to docs/src/examples/components/Label/Content/LabelExample.shorthand.tsx
diff --git a/docs/src/examples/components/Label/Types/LabelExample.tsx b/docs/src/examples/components/Label/Content/LabelExample.tsx
similarity index 100%
rename from docs/src/examples/components/Label/Types/LabelExample.tsx
rename to docs/src/examples/components/Label/Content/LabelExample.tsx
diff --git a/docs/src/examples/components/Label/Variations/LabelExampleOnIconClick.shorthand.tsx b/docs/src/examples/components/Label/Content/LabelExampleContentCustomization.shorthand.tsx
similarity index 51%
rename from docs/src/examples/components/Label/Variations/LabelExampleOnIconClick.shorthand.tsx
rename to docs/src/examples/components/Label/Content/LabelExampleContentCustomization.shorthand.tsx
index d2292f0b65..a818f06a31 100644
--- a/docs/src/examples/components/Label/Variations/LabelExampleOnIconClick.shorthand.tsx
+++ b/docs/src/examples/components/Label/Content/LabelExampleContentCustomization.shorthand.tsx
@@ -1,7 +1,7 @@
import React from 'react'
import { Label } from '@stardust-ui/react'
-class LabelExampleOnIconClickShorthand extends React.Component {
+class LabelExampleContentCustomizationShorthand extends React.Component {
state = { hidden: false }
hide = () => {
@@ -16,14 +16,19 @@ class LabelExampleOnIconClickShorthand extends React.Component {
return (
)
}
}
-export default LabelExampleOnIconClickShorthand
+export default LabelExampleContentCustomizationShorthand
diff --git a/docs/src/examples/components/Label/Variations/LabelExampleIcon.shorthand.tsx b/docs/src/examples/components/Label/Content/LabelExampleIcon.shorthand.tsx
similarity index 53%
rename from docs/src/examples/components/Label/Variations/LabelExampleIcon.shorthand.tsx
rename to docs/src/examples/components/Label/Content/LabelExampleIcon.shorthand.tsx
index d40bb3855b..804d24c52e 100644
--- a/docs/src/examples/components/Label/Variations/LabelExampleIcon.shorthand.tsx
+++ b/docs/src/examples/components/Label/Content/LabelExampleIcon.shorthand.tsx
@@ -1,6 +1,6 @@
import React from 'react'
import { Label } from '@stardust-ui/react'
-const LabelExampleIconShorthand = () =>
+const LabelExampleIconShorthand =
export default LabelExampleIconShorthand
diff --git a/docs/src/examples/components/Label/Content/LabelExampleIconPosition.shorthand.tsx b/docs/src/examples/components/Label/Content/LabelExampleIconPosition.shorthand.tsx
new file mode 100644
index 0000000000..f2b9ca1184
--- /dev/null
+++ b/docs/src/examples/components/Label/Content/LabelExampleIconPosition.shorthand.tsx
@@ -0,0 +1,8 @@
+import React from 'react'
+import { Label } from '@stardust-ui/react'
+
+const LabelExampleIconPositionShorthand = (
+
+)
+
+export default LabelExampleIconPositionShorthand
diff --git a/docs/src/examples/components/Label/Content/LabelExampleImage.shorthand.tsx b/docs/src/examples/components/Label/Content/LabelExampleImage.shorthand.tsx
new file mode 100644
index 0000000000..eb82161e09
--- /dev/null
+++ b/docs/src/examples/components/Label/Content/LabelExampleImage.shorthand.tsx
@@ -0,0 +1,8 @@
+import React from 'react'
+import { Label } from '@stardust-ui/react'
+
+const LabelExampleImageShorthand = () => (
+
+)
+
+export default LabelExampleImageShorthand
diff --git a/docs/src/examples/components/Label/Content/LabelExampleImagePosition.shorthand.tsx b/docs/src/examples/components/Label/Content/LabelExampleImagePosition.shorthand.tsx
new file mode 100644
index 0000000000..14c7993747
--- /dev/null
+++ b/docs/src/examples/components/Label/Content/LabelExampleImagePosition.shorthand.tsx
@@ -0,0 +1,8 @@
+import React from 'react'
+import { Label } from '@stardust-ui/react'
+
+const LabelExampleImageShorthand = () => (
+
+)
+
+export default LabelExampleImageShorthand
diff --git a/docs/src/examples/components/Label/Content/index.tsx b/docs/src/examples/components/Label/Content/index.tsx
new file mode 100644
index 0000000000..64cafbca7e
--- /dev/null
+++ b/docs/src/examples/components/Label/Content/index.tsx
@@ -0,0 +1,40 @@
+import React from 'react'
+import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample'
+import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection'
+
+const Content = () => (
+
+
+
+
+
+
+
+
+)
+
+export default Content
diff --git a/docs/src/examples/components/Label/Types/index.tsx b/docs/src/examples/components/Label/Types/index.tsx
deleted file mode 100644
index 4142db1e7f..0000000000
--- a/docs/src/examples/components/Label/Types/index.tsx
+++ /dev/null
@@ -1,15 +0,0 @@
-import React from 'react'
-import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample'
-import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection'
-
-const Types = () => (
-
-
-
-)
-
-export default Types
diff --git a/docs/src/examples/components/Label/Variations/LabelExampleIcon.tsx b/docs/src/examples/components/Label/Variations/LabelExampleIcon.tsx
deleted file mode 100644
index d2549d9826..0000000000
--- a/docs/src/examples/components/Label/Variations/LabelExampleIcon.tsx
+++ /dev/null
@@ -1,11 +0,0 @@
-import React from 'react'
-import { Label, Icon } from '@stardust-ui/react'
-
-const LabelExampleIcon = () => (
-
-)
-
-export default LabelExampleIcon
diff --git a/docs/src/examples/components/Label/Variations/LabelExampleIconPosition.shorthand.tsx b/docs/src/examples/components/Label/Variations/LabelExampleIconPosition.shorthand.tsx
deleted file mode 100644
index 69dad03c31..0000000000
--- a/docs/src/examples/components/Label/Variations/LabelExampleIconPosition.shorthand.tsx
+++ /dev/null
@@ -1,8 +0,0 @@
-import React from 'react'
-import { Label } from '@stardust-ui/react'
-
-const LabelExampleIconPositionShorthand = () => (
-
-)
-
-export default LabelExampleIconPositionShorthand
diff --git a/docs/src/examples/components/Label/Variations/LabelExampleIconPosition.tsx b/docs/src/examples/components/Label/Variations/LabelExampleIconPosition.tsx
deleted file mode 100644
index 694763d553..0000000000
--- a/docs/src/examples/components/Label/Variations/LabelExampleIconPosition.tsx
+++ /dev/null
@@ -1,11 +0,0 @@
-import React from 'react'
-import { Label, Icon } from '@stardust-ui/react'
-
-const LabelExampleIconPosition = () => (
-
-)
-
-export default LabelExampleIconPosition
diff --git a/docs/src/examples/components/Label/Variations/LabelExampleIconProps.shorthand.tsx b/docs/src/examples/components/Label/Variations/LabelExampleIconProps.shorthand.tsx
deleted file mode 100644
index 17dfd19c08..0000000000
--- a/docs/src/examples/components/Label/Variations/LabelExampleIconProps.shorthand.tsx
+++ /dev/null
@@ -1,33 +0,0 @@
-import React from 'react'
-import { Label } from '@stardust-ui/react'
-
-class LabelExampleIconAsShorthand extends React.Component<{}, { display: string }> {
- constructor(props) {
- super(props)
- this.state = {
- display: 'inline-block',
- }
- }
-
- public hide = () => {
- this.setState({ display: 'none' })
- }
-
- public render() {
- const { display } = this.state
- return (
-
- )
- }
-}
-
-export default LabelExampleIconAsShorthand
diff --git a/docs/src/examples/components/Label/Variations/index.tsx b/docs/src/examples/components/Label/Variations/index.tsx
index c04dc4bbbf..9ce0989539 100644
--- a/docs/src/examples/components/Label/Variations/index.tsx
+++ b/docs/src/examples/components/Label/Variations/index.tsx
@@ -9,26 +9,6 @@ const Variations = () => (
description="A label can be circular."
examplePath="components/Label/Variations/LabelExampleCircular"
/>
-
-
-
-
)
diff --git a/docs/src/examples/components/Label/index.tsx b/docs/src/examples/components/Label/index.tsx
index 0bbe416146..83d4865f48 100644
--- a/docs/src/examples/components/Label/index.tsx
+++ b/docs/src/examples/components/Label/index.tsx
@@ -1,10 +1,10 @@
import React from 'react'
-import Types from './Types'
+import Content from './Content'
import Variations from './Variations'
const LabelExamples = () => (
-
+
)
diff --git a/src/components/Image/Image.tsx b/src/components/Image/Image.tsx
index a6afce7f8f..30e1709aff 100644
--- a/src/components/Image/Image.tsx
+++ b/src/components/Image/Image.tsx
@@ -1,7 +1,7 @@
import * as PropTypes from 'prop-types'
import * as React from 'react'
-import { customPropTypes, UIComponent } from '../../lib'
+import { createShorthandFactory, customPropTypes, UIComponent } from '../../lib'
import { ImageBehavior } from '../../lib/accessibility'
import { Accessibility } from '../../lib/accessibility/interfaces'
@@ -34,6 +34,8 @@ export interface IImageProps {
* - when alt property is used in combination with aria-label, arialabbeledby or title, additional screen readers verification is needed as each screen reader handles this combination differently.
*/
class Image extends UIComponent, any> {
+ static create: Function
+
static className = 'ui-image'
static displayName = 'Image'
@@ -85,4 +87,6 @@ class Image extends UIComponent, any> {
}
}
+Image.create = createShorthandFactory(Image, src => ({ src }))
+
export default Image
diff --git a/src/components/Label/Label.tsx b/src/components/Label/Label.tsx
index 016f922e3a..4e117ea782 100644
--- a/src/components/Label/Label.tsx
+++ b/src/components/Label/Label.tsx
@@ -1,26 +1,19 @@
import * as PropTypes from 'prop-types'
import * as React from 'react'
-import * as _ from 'lodash'
import {
- callable,
childrenExist,
createShorthandFactory,
customPropTypes,
+ pxToRem,
UIComponent,
} from '../../lib'
+import { Icon, Image, Layout } from '../..'
import { Accessibility } from '../../lib/accessibility/interfaces'
import { ComponentVariablesInput, IComponentPartStylesInput } from '../../../types/theme'
-import {
- Extendable,
- ReactChildren,
- ItemShorthand,
- ComponentEventHandler,
-} from '../../../types/utils'
-
-import { Icon } from '../..'
+import { Extendable, ReactChildren, ItemShorthand } from '../../../types/utils'
export interface ILabelProps {
accessibility?: Accessibility
@@ -32,7 +25,8 @@ export interface ILabelProps {
fluid?: boolean
icon?: ItemShorthand
iconPosition?: 'start' | 'end'
- onIconClick?: ComponentEventHandler
+ image?: ItemShorthand
+ imagePosition?: 'start' | 'end'
styles?: IComponentPartStylesInput
variables?: ComponentVariablesInput
}
@@ -64,18 +58,16 @@ class Label extends UIComponent, any> {
content: customPropTypes.contentShorthand,
/** Label can have an icon. */
- icon: customPropTypes.some([PropTypes.string, PropTypes.object]),
+ icon: customPropTypes.itemShorthand,
/** An icon label can format an Icon to appear before or after the text in the label */
iconPosition: PropTypes.oneOf(['start', 'end']),
- /**
- * Function called when the icon is clicked.
- *
- * @param {SyntheticEvent} event - React's original SyntheticEvent.
- * @param {object} data - All props.
- */
- onIconClick: PropTypes.func,
+ /** Label can have an icon. */
+ image: customPropTypes.itemShorthand,
+
+ /** An icon label can format an Icon to appear before or after the text in the label */
+ imagePosition: PropTypes.oneOf(['start', 'end']),
/** Custom styles to be applied for component. */
styles: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
@@ -92,61 +84,102 @@ class Label extends UIComponent, any> {
'content',
'icon',
'iconPosition',
- 'onIconClick',
+ 'image',
+ 'imagePosition',
'styles',
'variables',
]
static defaultProps = {
- as: 'label',
+ as: 'span',
+ imagePosition: 'start',
+ iconPosition: 'end',
}
handleIconOverrides = iconProps => {
- const { onIconClick, iconPosition, content, variables } = this.props
- const iconVariables = callable(iconProps.variables)() || {}
- const labelVariables = callable(variables)() || {}
-
return {
- onClick: e => {
- _.invoke(iconProps, 'onClick', e)
- _.invoke(this.props, 'onIconClick', e, this.props)
- },
- ...((iconProps.onClick || onIconClick) && { tabIndex: '0' }),
- ...((!iconVariables || !iconVariables.color) && {
- variables: { color: labelVariables.color },
- }),
+ ...(iconProps.onClick && { tabIndex: '0' }),
...(!iconProps.xSpacing && {
- xSpacing: !content ? 'none' : iconPosition === 'end' ? 'before' : 'after',
+ xSpacing: 'none',
}),
}
}
- renderComponent({ ElementType, classes, rest, styles }) {
- const { children, content, icon, iconPosition } = this.props
- const getContent = (): React.ReactNode => {
- const iconAtEnd = iconPosition === 'end'
- const iconAtStart = !iconAtEnd
+ renderComponent({ ElementType, classes, rest, variables, styles }) {
+ const { children, content, icon, iconPosition, image, imagePosition } = this.props
- const iconElement = Icon.create(icon, {
+ const imageElement =
+ image &&
+ Image.create(image, {
+ defaultProps: { styles: { root: styles.image } },
generateKey: false,
+ })
+
+ const iconElement =
+ icon &&
+ Icon.create(icon, {
defaultProps: {
- styles: { root: styles.icon },
+ styles: {
+ root: styles.icon,
+ },
+ ...(!(
+ typeof icon === 'object' &&
+ (icon as any).variables &&
+ (icon as any).variables.color
+ ) && {
+ variables: {
+ color: variables.color,
+ },
+ }),
},
+ generateKey: false,
overrideProps: this.handleIconOverrides,
})
- return (
-
- {iconAtStart && icon && iconElement}
- {content}
- {iconAtEnd && icon && iconElement}
-
- )
+ 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
+ }
+
+ // Custom positioning of the icon and image
+ if (icon && iconPosition === 'start') {
+ if (image && imagePosition === 'start') {
+ start = (
+
+ {imageElement}
+ {iconElement}
+
+ )
+ } else {
+ start = iconElement
+ }
+ }
+ if (image && imagePosition === 'end') {
+ if (icon && iconPosition === 'end') {
+ end = (
+
+ {iconElement}
+ {imageElement}
+
+ )
+ } else {
+ end = imageElement
+ }
}
return (
- {childrenExist(children) ? children : getContent()}
+ {childrenExist(children) ? (
+ children
+ ) : (
+
+ )}
)
}
diff --git a/src/themes/teams/components/Label/labelStyles.ts b/src/themes/teams/components/Label/labelStyles.ts
index 3561b0c1f0..e81fb6f456 100644
--- a/src/themes/teams/components/Label/labelStyles.ts
+++ b/src/themes/teams/components/Label/labelStyles.ts
@@ -3,24 +3,45 @@ import { ICSSInJSStyle } from '../../../../../types/theme'
import { ILabelProps } from '../../../../components/Label/Label'
const labelStyles = {
- root: ({ props, variables }: { props: ILabelProps; variables: any }): ICSSInJSStyle => ({
+ root: ({
+ props: { image, imagePosition, circular },
+ variables,
+ }: {
+ props: ILabelProps
+ variables: any
+ }): ICSSInJSStyle => ({
padding: variables.padding,
- fontWeight: 500,
- backgroundColor: 'rgb(232, 232, 232)',
+ ...(image &&
+ imagePosition === 'start' && {
+ paddingLeft: variables.startPaddingLeft,
+ }),
+ ...(image &&
+ imagePosition === 'end' && {
+ paddingRight: variables.endPaddingRight,
+ }),
+ display: 'inline-flex',
+ alignItems: 'center',
+ height: variables.height,
+ fontSize: pxToRem(14),
+ lineHeight: variables.height,
+ backgroundColor: variables.backgroundColor,
color: variables.color,
borderRadius: pxToRem(3),
- ...(props.circular && {
+ ...(circular && {
borderRadius: variables.circularRadius,
}),
+ overflow: 'hidden',
+ }),
+ image: ({ variables }): ICSSInJSStyle => ({
+ height: variables.height,
+ width: variables.height,
}),
-
icon: ({ props }: { props: ILabelProps }): ICSSInJSStyle => ({
- position: 'relative',
- top: '-0.15em',
- ...((props.onIconClick ||
- (props.icon && typeof props.icon === 'object' && (props.icon as any).onClick)) && {
- cursor: 'pointer',
- }),
+ ...(props.icon &&
+ typeof props.icon === 'object' &&
+ (props.icon as any).onClick && {
+ cursor: 'pointer',
+ }),
}),
}
diff --git a/src/themes/teams/components/Label/labelVariables.ts b/src/themes/teams/components/Label/labelVariables.ts
index 69302b6995..2ed7f03612 100644
--- a/src/themes/teams/components/Label/labelVariables.ts
+++ b/src/themes/teams/components/Label/labelVariables.ts
@@ -2,8 +2,12 @@ import { pxToRem } from '../../../../lib'
export default () => {
const vars: any = {}
- vars.circularRadius = pxToRem(5000)
- vars.padding = `${pxToRem(6)} ${pxToRem(8)}`
+ vars.circularRadius = pxToRem(9999)
+ vars.padding = `0 ${pxToRem(4)} 0 ${pxToRem(4)}`
vars.color = 'rgba(0, 0, 0, 0.6)'
+ vars.backgroundColor = 'rgb(232, 232, 232)'
+ vars.startPaddingLeft = '0px'
+ vars.endPaddingRight = '0px'
+ vars.height = pxToRem(20)
return vars
}
diff --git a/src/themes/teams/components/Layout/layoutStyles.ts b/src/themes/teams/components/Layout/layoutStyles.ts
index 688a478307..e60b0c0478 100644
--- a/src/themes/teams/components/Layout/layoutStyles.ts
+++ b/src/themes/teams/components/Layout/layoutStyles.ts
@@ -54,6 +54,8 @@ const layoutStyles: IComponentPartStylesInput = {
start: ({ props }): ICSSInJSStyle => ({
...(props.debug && debugArea()),
...(props.truncateStart && truncateStyle),
+ display: 'inline-flex',
+ alignItems: 'center',
...props.startCSS,
}),
@@ -66,6 +68,8 @@ const layoutStyles: IComponentPartStylesInput = {
end: ({ props }): ICSSInJSStyle => ({
...(props.debug && debugArea()),
...(props.truncateEnd && truncateStyle),
+ display: 'inline-flex',
+ alignItems: 'center',
...props.endCSS,
}),
}
diff --git a/test/specs/components/Label/Label-test.tsx b/test/specs/components/Label/Label-test.tsx
index 0ae3c3e079..c220d32db6 100644
--- a/test/specs/components/Label/Label-test.tsx
+++ b/test/specs/components/Label/Label-test.tsx
@@ -2,20 +2,25 @@ import * as React from 'react'
import { isConformant } from 'test/specs/commonTests'
import Label from 'src/components/Label/Label'
+import Icon from 'src/components/Icon/Icon'
+import Image from 'src/components/Image/Image'
import { mountWithProvider } from '../../../utils'
+import { implementsShorthandProp } from '../../commonTests'
+
+const labelImplementsShorthandProp = implementsShorthandProp(Label)
describe('Label', () => {
isConformant(Label)
+ labelImplementsShorthandProp('icon', Icon, { mapsValueToProp: 'name' })
+ labelImplementsShorthandProp('image', Image, { mapsValueToProp: 'src' })
- describe('onIconClick', () => {
- it('calls onIconClick when the icon is clicked', () => {
- const onClick = jest.fn()
- const button = mountWithProvider(
- ,
+ describe('icon', () => {
+ it('sets tabIndex="0" if the icon has onClick prop', () => {
+ const icon = mountWithProvider(
+