Skip to content

Commit

Permalink
feat: add <Dimmable> renderOverlay()
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Mar 4, 2018
1 parent ddb8ae7 commit 1779593
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
13 changes: 10 additions & 3 deletions src/Dimmable/__story__/story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ storiesOf('UI/Dimmable', module)
Inline...
</div>
</Dimmable>
<div onClick={toggle}>Toggle: {on ? 'on' : 'off'}</div>
<button onClick={toggle}>Toggle: {on ? 'on' : 'off'}</button>
</div>
}</Toggle>
)
Expand All @@ -30,7 +30,7 @@ storiesOf('UI/Dimmable', module)
</div>
</div>
</Dimmable>
<div onClick={toggle}>Toggle: {on ? 'on' : 'off'}</div>
<button onClick={toggle}>Toggle: {on ? 'on' : 'off'}</button>
</div>
}</Toggle>
)
Expand All @@ -47,7 +47,7 @@ storiesOf('UI/Dimmable', module)
</div>
</div>
</Dimmable>
<div onClick={toggle}>Toggle: {on ? 'on' : 'off'}</div>
<button onClick={toggle}>Toggle: {on ? 'on' : 'off'}</button>
</div>
}</Toggle>
)
Expand All @@ -58,3 +58,10 @@ storiesOf('UI/Dimmable', module)
</div>
</Dimmable>
)
.add('renderOverlay', () =>
<Dimmable dim renderOverlay={(on) => 'Hello'}>
<div style={{width: 500, height: 300, border: '1px solid tomato'}}>
Inline...
</div>
</Dimmable>
)
5 changes: 3 additions & 2 deletions src/Dimmable/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {IDimmableProps} from './index';
import {Component, Children, cloneElement} from 'react';
import {h} from '../util';
import {h, noop} from '../util';
import {Dimmer, IDimmerProps} from '../Dimmer';

export interface IDimmableProps extends IDimmerProps {
dim?: boolean;
blur?: number;
renderOverlay?: (dim?: boolean) => React.ReactChild;
}

export class Dimmable extends Component<IDimmableProps> {
Expand All @@ -32,7 +33,7 @@ export class Dimmable extends Component<IDimmableProps> {

return cloneElement(element, {},
elementChild,
h(Dimmer, rest),
h(Dimmer, rest, (this.props.renderOverlay || noop)(dim)),
);
}
}
2 changes: 1 addition & 1 deletion src/Dimmer/__story__/story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ storiesOf('UI/Dimmer', module)
Children...
</Dimmer>
</div>
<div onClick={toggle}>Toggle: {on ? 'on' : 'off'}</div>
<button onClick={toggle}>Toggle: {on ? 'on' : 'off'}</button>
</div>
}</Toggle>
)

0 comments on commit 1779593

Please sign in to comment.