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(@clayui/label): use a hybrid API appraoch to expose low-level components #3081

Merged
merged 3 commits into from
Mar 31, 2020

Conversation

bryceosterhaus
Copy link
Member

@bryceosterhaus bryceosterhaus commented Mar 27, 2020

continued conversation from #3066

@coveralls
Copy link

coveralls commented Mar 27, 2020

Pull Request Test Coverage Report for Build 4678

  • 12 of 12 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.08%) to 78.439%

Totals Coverage Status
Change from base Build 4677: 0.08%
Covered Lines: 2282
Relevant Lines: 2709

💛 - Coveralls

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 27, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 082a842:

Sandbox Source
compassionate-snyder-gyqhn Configuration
cranky-austin-xjikl Configuration

Copy link
Member

@matuzalemsteles matuzalemsteles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @bryceosterhaus it looks good to me, I think it just got better and opens doors in the future for us to make improvements.

/**
* Path to the location of the spritemap resource used for Icon.
*/
spritemap?: string;
}

const ClayLabel = React.forwardRef<HTMLAnchorElement | HTMLSpanElement, IProps>(
const ClayLabelBase = React.forwardRef<HTMLSpanElement, IBaseProps>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we went back to the name Base 😂, is a dead end!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha yeah I wasn't sure what else to call it. I'll update to be similar to our other components so that we avoid confusion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha no problem. I think we can keep the Base.

Comment on lines 112 to 125
{closeButtonProps && (
<span className="label-item label-item-after">
<ClayLabelItemAfter>
<button
{...closeButtonProps}
className="close"
className={classNames(
closeButtonProps.className,
'close'
)}
type="button"
>
<Icon spritemap={spritemap} symbol="times" />
<ClayIcon spritemap={spritemap} symbol="times" />
</button>
</span>
</ClayLabelItemAfter>
)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move this to ClayLabel below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was debating back and forth whether this should be an easier API, or if we should require the end user to wire up the appropriate close button. I sort of like having it internal to ClayLabelBase since it doesn't prohibit or get in the way at all, but I also could see moving it to just the high-level. Are you thinking we would name it ClayLabelWithClose? If that's the case, we could do what we did modal(withTitle) and add withClose as a prop that defaults to true, and then the withClose logic would ultimately get extracted to a high-level component

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, actually, I wasn't thinking of creating a ClayLabelWithClose now, just thinking of making ClayLabelBase cleaner and currently moving it to ClayLabel only, we will still keep supporting it. I don't think we need withClose here yet. We can extract it in the future when we better consolidate the ClayLabel API.

@bryceosterhaus
Copy link
Member Author

@matuzalemsteles check out the latest commit for an example of adding the pattern that we did with Modal

</ClayLabelItemExpand>

{closeButtonProps && (
<ClayLabelItemAfter>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this implementation doesn't consume ClayLabelItemBefore or am I wrong?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Rather than add a new prop to the API, I went the route of breaking up Label into its low-level components so that users have more flexibility in how they want to use it. You can see the example of how we would add a before item at https://github.com/liferay/clay/pull/3081/files#diff-d25f4565a23c4c3cc5475dedd79d9ad1R62-R67

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I see, good to know! Thanks

const testRenderer = TestRenderer.create(
<ClayLabel.Base>
<ClayLabel.ItemExpand>{'Label'}</ClayLabel.ItemExpand>
<ClayLabel.ItemAfter>{'Content before'}</ClayLabel.ItemAfter>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before → after

Obligatory copy-pasta image:

copy-pasta

@kresimir-coko kresimir-coko linked an issue Mar 30, 2020 that may be closed by this pull request
1 task
@bryceosterhaus bryceosterhaus force-pushed the pr-3066 branch 3 times, most recently from 964bccd to 70b33fe Compare March 30, 2020 22:54
@matuzalemsteles
Copy link
Member

hey @bryceosterhaus just to complement this change we can also add documents to clayui.com, perhaps to explain the addition of withClose.

@bryceosterhaus
Copy link
Member Author

@matuzalemsteles good call. I will add that in this PR as well

@bryceosterhaus bryceosterhaus marked this pull request as ready for review March 31, 2020 20:43
@bryceosterhaus bryceosterhaus changed the title refactor to preserve API and add low-level components feat(@clayui/label): use a hybrid API appraoch to expose low-level components Mar 31, 2020
@bryceosterhaus
Copy link
Member Author

@matuzalemsteles update docs. let me know what you think

Comment on lines +25 to +30
## Overview

`ClayLabel` offers two different APIs for use by toggling the prop `withClose`. By default(`withClose={true}`), `ClayLabel` behaves like a high-level component. If you want to use the lower-level components and compose multiple parts to your label, all you need to do is set `withClose={false}`.

Check out [this storybook example](storybook.clayui.com/?path=/story/components-claylabel--w-content-before) for a demo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bryceosterhaus as it is a typical feature that we don't want to support for a long time, it might be worth adding a warning about it and that we will remove this double behavior in a major version later. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matuzalemsteles I'm thinking its probably best to not mention that since they are essentially toggling the intended behavior of what this component will be. The next major version will likely behave the same even if withClose={false} is set.

When we do ever release 4.x, we can then note that with* props are moved to high-level components. But overall, I think it'd be unnecessary to mention at the moment since 4.x isn't really even on the radar yet. Once we get 4.x on the radar and have a better idea of what it would be, we can always add the note then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, no problem. LGTM

@bryceosterhaus bryceosterhaus merged commit ac4614e into liferay:master Mar 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clay label doesn't support icons inside
5 participants