Skip to content
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(Item.Image): Add size prop #747

Merged

Conversation

clemensw
Copy link
Contributor

@codecov-io
Copy link

codecov-io commented Oct 25, 2016

Current coverage is 99.48% (diff: 100%)

No coverage report found for master at 24e9490.

Powered by Codecov. Last update 24e9490...3f0533c

@layershifter
Copy link
Member

layershifter commented Oct 25, 2016

This PR will break all other except case with size, it cannot be merged as is.


_427

For a common understanding, we are talking about the example. This example uses size prop that will pass to Image component, but CSS for item.image doesn't handle size (what is right).

So, we need add ui when there is size prop and skip it in other cases.

<Item.Image /> // <div class="ui image">
<Item.Image size="small" /> // <div class="ui small image">

I think it's not responsibility of Image, so we need fix in Item.Image.

- import React from 'react'
+ import React, { PropTypes } from 'react'
import {
  META,
+ SUI, 
} from '../../lib'
import Image from '../../elements/Image'

function ItemImage(props) {
-  return <Image {...props} ui={false} wrapped />
+ const { size } = props
+ const rest = getUnhandledProps(ItemImage, props)
+
+ return <Image {...props} size={size} ui={!!size} wrapped />
}

ItemImage._meta = {
  name: 'ItemImage',
  parent: 'Item',
  type: META.TYPES.VIEW,
}

+ ItemImage.propTypes = {
+  /** An image may appear at different sizes */
+  size: PropTypes.oneOf(Image._meta.props.size),
+ },

export default ItemImage
import React from 'react'
import ItemImage from 'src/views/Item/ItemImage'

describe('ItemImage', () => {
  it('renders Image component', () => {
    shallow(<ItemImage />)
      .should.have.descendants('Image')
  })

  it('is wrapped without ui', () => {
    const wrapper = shallow(<ItemImage />)

    wrapper.should.have.prop('wrapped', true)
    wrapper.should.have.prop('ui', false)
  })

+  it('has ui with size prop', () => {
+    shallow(<ItemImage size='small' />)
+      .should.have.prop('ui', true)
+  })
})

@levithomason
Copy link
Member

Let's also use ui={!!size} so the value is coerced to a boolean value. Otherwise, when the passes a size such as small the prop would be ui='small'.

@layershifter
Copy link
Member

@clemensw do you have plans for PR update?

@levithomason
Copy link
Member

levithomason commented Oct 27, 2016

Would like to merge @clemensw's work, however, whoever has time to get to this first let's ship it! :)

@clemensw
Copy link
Contributor Author

Thank you for the review. I'm seriously confused by the logic behind Semantic UI 's use of the ui class in css. I've updated the PR based on your suggestions (substituting getUnhandledProps for SUI on the import and rest for props on the Image attributes). I booleanized size by checking against undefined, but will re-push the PR with your solution.

…y to work

* Resolves Semantic-Org#746
* Add ui class only for sized images
* Renders similar to the example at http://semantic-ui.com/views/item.html#image
* Images now render left aligned and sized.
@layershifter
Copy link
Member

@clemensw Thanks for updates 😺
@levithomason LGTM, ready to go?

@levithomason levithomason changed the title fix(Item.Image): Add ui class to wrapped Image to enable size property to work feat(Item.Image): Add ui class to wrapped Image to enable size property to work Oct 28, 2016
@levithomason levithomason changed the title feat(Item.Image): Add ui class to wrapped Image to enable size property to work feat(Item.Image): Add size prop Oct 28, 2016
@levithomason levithomason merged commit 3d20c73 into Semantic-Org:master Oct 28, 2016
@levithomason
Copy link
Member

Thanks for the update and help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants