-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from MailOnline/feat/modal
Feat/modal
- Loading branch information
Showing
26 changed files
with
364 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const gulp = require('gulp'); | ||
const ts = require('gulp-typescript'); | ||
const tsConfig = require('../tsconfig'); | ||
const path = require('path'); | ||
|
||
const ignore = [ | ||
'!../src/**/__tests__/**', | ||
'!../src/**/__story__/**', | ||
'!../src/**/__docs__/**', | ||
'!../src/**/story.ts', | ||
'!../src/**/story.tsx' | ||
]; | ||
|
||
gulp.task('build-ts', () => { | ||
return gulp.src([ | ||
'../src/**/*.ts', | ||
...ignore | ||
]).pipe(ts({ | ||
...tsConfig.compilerOptions, | ||
target: 'es5', | ||
module: 'commonjs' | ||
})).pipe(gulp.dest('../lib')); | ||
}); | ||
|
||
gulp.task('build-modules', () => { | ||
return gulp.src([ | ||
'../src/**/*.ts', | ||
...ignore | ||
]).pipe(ts({ | ||
...tsConfig.compilerOptions, | ||
target: 'ESNext', | ||
module: 'ESNext' | ||
})).pipe(gulp.dest('../modules')); | ||
}); | ||
|
||
gulp.task('build', () => { | ||
gulp.start('build-ts'); | ||
gulp.start('build-modules'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# `<Modal>` | ||
|
||
Creates a modal overlay. This component is similar to [`<Overlay>`](./Overlay.md) but provides the following extras: | ||
|
||
- traps tabbing focus inside the overlay. | ||
- makes all other root level elements inert to user input. | ||
- sets aria title and description ids. | ||
|
||
### Usage | ||
|
||
Basic example. | ||
|
||
```jsx | ||
import {Modal} from 'libreact/lib/Modal'; | ||
|
||
<Modal> | ||
This is modal. | ||
</Modal> | ||
``` | ||
|
||
Set aria title, description, and close button. | ||
|
||
```jsx | ||
<Modal>{({idTitle, idDescription, close}) => | ||
<div> | ||
<h1 id={idTitle}>My title</h1> | ||
<p id={idDescription}>This is description.</p> | ||
|
||
<button onClick={close}>Cancel</button> | ||
</div> | ||
}</Modal> | ||
``` | ||
|
||
Track when user intends to close the the modal. | ||
|
||
```jsx | ||
<Modal onClick={} onEsc={}> | ||
This is modal. | ||
</Modal> | ||
``` | ||
|
||
|
||
## Props | ||
|
||
Accepts all [`<Overlay>`](./Overlay.md) props in addition to: | ||
|
||
- `onEsc` — optional, callback, called when user presses `Esc` button. | ||
- `onClose` — optional, callback, called when `close()` is executed. | ||
|
||
|
||
## State | ||
|
||
`<Modal>` is a render prop that injects its state into the render function. State has the following keys. | ||
|
||
- `close()` — method to calle `onClose` event. | ||
- `idTitle` — id to set for aria title element. | ||
- `idDescription` — id to set for aria description element. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import {createElement as h} from 'react'; | ||
import {storiesOf} from '@storybook/react'; | ||
import {action} from '@storybook/addon-actions'; | ||
import {linkTo} from '@storybook/addon-links'; | ||
import {Modal} from '..'; | ||
import ShowDocs from '../../../.storybook/ShowDocs' | ||
|
||
storiesOf('UI/Modal', module) | ||
.add('Documentation', () => h(ShowDocs, {md: require('../../../docs/en/Modal.md')})) | ||
.add('Basic example', () => | ||
<div> | ||
<Modal> | ||
foobar | ||
</Modal> | ||
</div> | ||
) | ||
.add('Button underneath', () => | ||
<div> | ||
<button onClick={() => alert('CLICKED')}>Click me!</button> | ||
<Modal> | ||
foobar | ||
</Modal> | ||
</div> | ||
) | ||
.add('With inputs', () => | ||
<div> | ||
<button onClick={() => alert('CLICKED')}>Click me!</button> | ||
<Modal> | ||
<div style={{background: 'white'}}> | ||
This is modal... | ||
<button>OK</button> | ||
<button>Cancel</button> | ||
</div> | ||
</Modal> | ||
</div> | ||
) | ||
.add('Modal UI', () => | ||
<div> | ||
<Modal color='tomato' onClick={action('onClick')} onEsc={action('onEsc')}> | ||
<div | ||
style={{ | ||
width: 300, | ||
height: 200, | ||
background: '#fff', | ||
borderRadius: 4, | ||
boxShadow: '0 2px 4px rgba(0,0,0,.3)', | ||
padding: 30, | ||
}} | ||
> | ||
foobar | ||
</div> | ||
</Modal> | ||
</div> | ||
) |
Oops, something went wrong.