-
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(Dimmer): Add component #447
Conversation
ComponentIt seems that Simple dimmerSUI offers Simple dimmer in native CSS, but seems it's not part of Dimmer component. Dimmer eventsAny ideas how we can handle events in automatic mode like there? UsageI think that in this part there is nothing that should be in the component. SettingsI think we need take following from settings part:
@levithomason Other ideas? |
ping @levithomason |
ResponsesComponentI think we first go with a stateless component here. The Simple dimmerThere is actually no difference in markup between the "simple css dimmer" and a regular dimmer. The only difference is in how you use it. The jQuery dimmer simply adds the Dimmer eventsSince the component will be controlled by parent state, I don't think we need events. Let's leave those for future feature requests, if needed. UsageAgreed, let's leave these out. Settings
events - yes, let's skip and go stateless API IdeasThe parent component can be any component and also needs The dimmer itself can also have child content, which means we'll need an API for specifying the dimmed component's children and the dimmer's children. The dimmer centers content horizontally and vertically. Vertical centering requires two child divs. I think we include these two divs in all dimmer content.
I'm proposing that the Dimmer have an API to control both the dimmed parent component as well as the dimmer child. Content DimmerProposing the <Dimmer dimmable={Segment} dimmed>
<Header>Overlayable Section</Header>
<Dimmer active>
<Header inverted icon='heart' content='Dimmed Message!' />
</Dimmer>
</Dimmer> <div class="ui segment dimmable dimmed">
<h3 class="ui header">
Overlayable Section
</h3>
<div class="ui dimmer transition visible active">
<div class="content">
<div class="center">
<h2 class="ui inverted icon header">
<i class="heart icon"></i>
Dimmed Message!
</h2>
</div>
</div>
</div>
</div> Page DimmerIn this case the <Dimmer page active>
<Header inverted icon='mail' content='Dimmer Message' subheader='Dimmer sub-header' />
</Dimmer> <body>
<div class="ui page dimmer transition visible active">
<div class="content">
<div class="center">
<h2 class="ui inverted icon header">
<i class="mail icon"></i>
Dimmer Message
<div class="sub header">Dimmer sub-header</div>
</h2>
</div>
</div>
</div>
</body> |
I will start on it next week 🍰 |
ComponentAfter use in production, I can agree about stateless I think that it will be class (will have export default class Dimmer {
handleClick = () => {}
handleEscape = () => {}
render () {}
} Dimmable
It's real pain there, any ideas about <Segment>
<Dimmer active={false}>...</Dimmer>
...
</Segment> There is simple solution, but it's pretty shitty: const active = true;
<Segment className={Dimmer.dimmable(active)}>
<Dimmer active={active}>...</Dimmer>
...
</Segment> @levithomason @jcarbo Please advise me something better 🤐 |
Note, there are 2 types of Dimmers. A "Content Dimmer" and a "Page Dimmer". The "Page Dimmer" has the I've proposed an API for each use case in #447 (comment) above. See above for more, specifics are here: Content DimmerRenders the <Dimmer dimmable={Segment} dimmed /> Page DimmerRenders to body. <Dimmer page active /> ConclusionI think we'll need to render with these two different approaches based on props:
|
99b85ab
to
df1c96a
Compare
Current coverage is 99.48% (diff: 100%)
|
PageDimmable/DimmedSUI adds I've done this, any better solution there? handlePageMount = () => {
debug('handleMount()')
document.body.classList.add('dimmed', 'dimmable')
}
handlePageUnmount = () => {
debug('handleUnmount()')
document.body.classList.remove('dimmed', 'dimmable')
}
} <Portal onMount={this.handlePageMount} onUnmount={this.handlePageUnmount} /> Handle clickOutsideThere is problem with handling outside click. I can't use there So, I need handle it inside component, but I can't simply write |
@layershifter - Also once #666 is merged you will have a little more control in that regard. You can either specify |
@jcarbo is this due to event bubbling? If so, that makes sense because the Dimmer click bubbles to the Could you clarify? P.S. I also left a comment on #666 regarding closing multiple Modals, LMK. |
@levithomason I'll added I don't like that we need handle also |
|
||
const DimmerExampleDisabled = () => ( | ||
<Segment> | ||
<Dimmer disabled /> |
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.
Hm, do you know what this is supposed to do? The dimmer still is made active when I add:
<Dimmer active disabled />
Though, the description says:
A disabled dimmer cannot be activated
Perhaps this is only applicable to the jQuery plugin in SUI core? Thoughts?
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.
I think we can remove disabled
prop, it's quite strange to use disabled
when you have control of active
.
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.
Agreed, especially since it does not override the active
prop. Let's remove it.
|
||
return ( | ||
<div> | ||
<Dimmer blurring dimmable={Segment} dimmed={active}> |
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.
This currently does not pass extra props to the Segment. Example, adding color='red'
should pass color
to the Segment
. What if we went with this API, it does pass extra props:
<Dimmer.Dimmable as={Segment} blurring dimmed={active} color='red'>
<Dimmer active={active} />
<p>
<img src='http://semantic-ui.com/images/wireframe/short-paragraph.png' />
</p>
<p>
<img src='http://semantic-ui.com/images/wireframe/short-paragraph.png' />
</p>
</Dimmer.Dimmable>
I tested the above with only these changes required:
- Expose
Dimmer.Dimmable = DimmerDimmable
- Rename
DimmmerDimmable
propComponent
toas
and use our standardgetElementType()
util and render<ElementType />
instead. - I did not do this, but we should then remove all
dimmable
prop reference and logic from the mainDimmer
.
This might be more in line with our existing patterns.
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.
Yep, you said that I thinked 👍
handlePageMount = () => { | ||
debug('handleMount()') | ||
|
||
document.body.classList.add('dimmed', 'dimmable') |
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.
I believe we only want to add dimmed
if active
is true. Is that correct?
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.
Not exactly, it added on Portal
s mount, while Portal
will mount on active
. This was plan.
Left some comments. I think we must handle |
I've made cleanup there, all examples where added, except example with Seems, we need initial review there, I'll add tests after it. |
Updated to latest @levithomason waiting for review 😄 All is ready except, |
Added new example with |
import ImageGroup from './ImageGroup' | ||
import Dimmer from '../../modules/Dimmer/Dimmer' | ||
import Label from '../Label/Label' |
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.
Just an FYI. There should be index files for all components so we can import ../Label
instead of ../Label/Label
. We can merge this as is still.
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.
Looks good, left one question regarding stopPropagation. I'm also not sure what you'd like to review on rendersChildren(), please expound.
</DimmerDimmable> | ||
) | ||
_.invoke(children, 'props.onClick', e) | ||
e.stopPropagation() |
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.
Do we need to stop propagation here? Would prefer we not prevent handlers above this component from firing.
If we're trying to prevent our own handlers from firing, perhaps we should instead detect if the click was inside rather than stop the event.
common.hasUIClassName(Dimmer) | ||
|
||
// TODO: Renders children / content | ||
// common.rendersChildren() |
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.
I saw your request to take a look here, but I'm not sure what the issue is. Did this test not work for this component?
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.
Yes, this test is broken. I think problem in cloneElement
that I use for handling click. I'll try rework click
handling without stopPropagation
.
|
|
||
if (onClick) onClick(e, this.props) | ||
if (this.center && (this.center !== e.target && this.center.contains(e.target))) return | ||
if (onClickOutside) onClickOutside(e, this.props) |
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.
onClickOutside
must be called outside children like in SUI.
@levithomason Any chance for review? 😺 |
Thanks much! |
Released in |
Fixes #190