-
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(ListItem): add shorthand #589
Comments
It looks like <List>
<List.Item icon='check mark'>jQuery Free</List.Item>
<List.Item icon='check mark'>Declarative API</List.Item>
<List.Item icon='check mark'>Augmentation</List.Item>
<List.Item icon='check mark'>Shorthand Props</List.Item>
<List.Item icon='check mark'>Sub Components</List.Item>
<List.Item icon='check mark'>Auto Controlled State</List.Item>
</List> I'd maybe update this issue to add |
Agreed and done, thanks. |
I had a chance to look at the all the possibilities for lists (there are a lot!) and put together some thoughts on this. I'd say this is roughly what we should support via shorthand: // With icon or image
<List.Item>
{List.Icon || Image}
<List.Content>
<List.Header />
<List.Description />
{content}
</List.Content>
</List.Item>
// Without icon or image
<List.Item>
<List.Header />
<List.Description />
{content}
</List.Item> Going to post what I found to be the unique variations with the shorthand below each: // Super basic
<List.Item>1</List.Item>
// Shorthand
<List.Item content='1' />
// Icon + Content (content has header + description)
<List.Item>
<List.Icon name='map marker' />
<List.Content>
<List.Header as='a'>Krowlewskie Jadlo</List.Header>
<List.Description>An excellent polish restaurant, quick delivery and hearty, filling meals.</List.Description>
</List.Content>
</List.Item>
// Shorthand
<List.Item
icon='map marker'
header={{ as: 'a', content: 'Krowlewskie Jadlo'}}
description='An excellent...'
/>
// Image + Content (content has header + description)
<List.Item>
<Image avatar src='http://semantic-ui.com/images/avatar2/small/rachel.png' />
<List.Content>
<List.Header as='a'>Rachel</List.Header>
<List.Description>Last seen watching <a><b>Arrested Development</b></a> just now.</List.Description>
</List.Content>
</List.Item>
// Shorthand
<List.Item
image={{ avatar: true, src: 'http...' }}
header={{ as: 'a', content: 'Rachel'}}
description='Last seen watching...'
/>
// Icon + Content (content just has text)
<List.Item>
<List.Icon name='users' />
<List.Content>Semantic UI</List.Content>
</List.Item>
// Shorthand
<List.Item
icon='users'
content='Semantic UI'
/>
// Header + naked content, not wrapped in List.Content
<List.Item>
<List.Header>New York City</List.Header>
A lovely city
</List.Item>
// Shorthand
<List.Item
header='New York City'
content='A lovely city'
/>
// Header + description, not wrapped in List.Content
<List.Item>
<List.Header as='a'>Header</List.Header>
<List.Description>
Click a link in our <a>description</a>.
</List.Description>
</List.Item>
// Shorthand
<List.Item
header={{ as: 'a', content: 'Header'}}
description='Click a link...'
/>
// Multiple "content"s mixed with other data
<List.Item>
<List.Content floated='right'>
<Button>Add</Button>
</List.Content>
<Image avatar src='http://semantic-ui.com/images/avatar2/small/lena.png' />
<List.Content>
Lena
</List.Content>
</List.Item>
// Shorthand
// Note: I don't think we can handle multiple contents.
// Nested list
<List.Item>
<div>Benefits</div>
<List.List>
<List.Item href='#'>Link to somewhere</List.Item>
<List.Item>Rebates</List.Item>
<List.Item>Discounts</List.Item>
</List.List>
</List.Item>
<List.Item>Warranty</List.Item>
// Shorthand
<List.Item
content={<List /** Shorthand or full JSX for list */ />}
/>
// Content with props
<List.Item>
<Image avatar src='http://semantic-ui.com/images/wireframe/square-image.png' />
<List.Content verticalAlign='middle'>
Middle
</List.Content>
</List.Item>
// Shorthand
<List.Item
image={{ avatar: true, src: '...' }}
content='Middle'
verticalAlign /** NOTE: This is passed-through to List.Content */
/> Note that last example where a prop is passed through to
I think going with the latter makes sense, even though it forces us to pass-through props, because the |
Agreed!
|
The double const iconNode = ListIcon.create(icon)
const imageNode = Image.create(image)
+ if (_.isPlainObject(content)) {
+ return (
+ <ElementType {...rest} className={classes} {...valueProp}>
+ {iconNode || imageNode}
+ {ListContent.create(content, { header: header, description: description })}
+ </ElementType>
+ )
+ }
const headerNode = ListHeader.create(header)
const descriptionNode = ListDescription.create(description)
if (iconNode || imageNode) {
return (
<ElementType {...rest} className={classes} {...valueProp}>
{iconNode || imageNode}
{(content || headerNode || descriptionNode) && (
<ListContent>
{headerNode}
{descriptionNode}
{content}
</ListContent>
)}
</ElementType>
)
}
return (
<ElementType {...rest} className={classes} {...valueProp}>
{headerNode}
{descriptionNode}
{content}
</ElementType>
)
} Doesn't add that much complexity I guess. Thoughts? |
Looks good to me, I think the public API wins out over a little funny business in the code. Suggest a code comment to clarify why the plain object check. |
The thing I don't love about that approach is that it deviates from our current shorthand pattern. In this case,
This might be a little more consistent: const iconNode = ListIcon.create(icon)
const imageNode = Image.create(image)
const headerNode = ListHeader.create(header)
const descriptionNode = ListDescription.create(description)
if (iconNode || imageNode || _.isPlainObject(content)) {
return (
<ElementType {...rest} className={classes} {...valueProp}>
{iconNode || imageNode}
- {(content || headerNode || descriptionNode) && (
- <ListContent>
- {headerNode}
- {descriptionNode}
- {content}
- </ListContent>
- )}
+ {(content || headerNode || descriptionNode) &&
+ ListContent.create(content || '', { header: header, description: description })}
</ElementType>
)
}
return (
<ElementType {...rest} className={classes} {...valueProp}>
{headerNode}
{descriptionNode}
{content}
</ElementType>
) Note that it's valid to only pass a header or description so we need a non-nil value for But even in that case, if:
|
After thinking about it I'd kinda prefer the first one and just comment on the inconsistency/break from pattern.
|
The
List
update broke the Introduction page:There may be other legacy usages as well. Suggest searching the codebase and updating all usages of
List
to the v1 API.The text was updated successfully, but these errors were encountered: