Skip to content

Commit bba1ef9

Browse files
authored
Merge pull request #38 from MailOnline/feat/modal
Feat/modal
2 parents 5ee0eee + eea744c commit bba1ef9

File tree

26 files changed

+364
-118
lines changed

26 files changed

+364
-118
lines changed

.nvmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# libreact
44

5-
[![][npm-badge]][npm-url] [![][travis-badge]][travis-url]
5+
[![][npm-badge]][npm-url] [![][travis-badge]][travis-url] [![React Universal Interface](https://img.shields.io/badge/React-Universal%20Interface-green.svg)](https://github.com/streamich/react-universal-interface)
66

77
React standard library — must-have toolbox for any React project.
88

@@ -33,11 +33,11 @@ const MyComponent = mock();
3333

3434
- [Introduction](./docs/en/Introduction.md)
3535
- [Dummies](./docs/en/Dummies.md)
36-
- [`mock()`](./docs/en/mock.md) and [`loadable()`](./docs/en/loadable.md)
36+
- [`mock()`](./docs/en/mock.md) and [`loadable()`](./docs/en/loadable.md) — [*example*](https://codesandbox.io/s/j2ovpr03z3)
3737
- [`lazy()`](./docs/en/lazy.md), [`delayed()`](./docs/en/delayed.md), and [`viewport()`](./docs/en/viewport.md)
3838
- [Inversion](./docs/en/Inversion.md)
3939
- [`<State>`](./docs/en/State.md) and [`withState()`](./docs/en/State.md#withstate-hoc)
40-
- [`<Toggle>`](./docs/en/Toggle.md), [`withToggle()`](./docs/en/Toggle.md#withtoggle-hoc), and [`@withToggle`](./docs/en/Toggle.md#withtoggle-decorator)
40+
- [`<Toggle>`](./docs/en/Toggle.md), [`withToggle()`](./docs/en/Toggle.md#withtoggle-hoc), and [`@withToggle`](./docs/en/Toggle.md#withtoggle-decorator) &mdash; [*example*](https://codesandbox.io/s/zwkl16vv93)
4141
- [`<Flipflop>`](./docs/en/Flipflop.md), [`withFlipflop()`](./docs/en/Flipflop.md#withflipflop-hoc), and [`@withFlipflop`](./docs/en/Flipflop.md#withflipflop-decorator)
4242
- [`<Value>`](./docs/en/Value.md), [`withValue()`](./docs/en/Value.md#withvalue-hoc), and [`@withValue`](./docs/en/Value.md#withvalue-decorator)
4343
- [`<Counter>`](./docs/en/Counter.md), [`withCounter()`](./docs/en/Counter.md#withcounter-hoc) and [`@withCounter`](./docs/en/Counter.md#withcounter-decorator)
@@ -48,20 +48,20 @@ const MyComponent = mock();
4848
- [Sensors](./docs/en/Sensors.md)
4949
- [`<ActiveSensor>`](./docs/en/ActiveSensor.md), [`withActive()`](./docs/en/ActiveSensor.md#withactive-hoc), and [`@withActive`](./docs/en/ActiveSensor.md#withactive-decorator)
5050
- [`<BatterySensor>`](./docs/en/BatterySensor.md), [`withBattery()`](./docs/en/BatterySensor.md#withbattery), and [`@withBattery`](./docs/en/BatterySensor.md#withbattery-1)
51-
- [`<ExitSensor>`](./docs/en/ExitSensor.md)
51+
- [`<ExitSensor>`](./docs/en/ExitSensor.md) &mdash; [*example*](https://codesandbox.io/s/7437x10z71)
5252
- [`<FocusSensor>`](./docs/en/FocusSensor.md), [`withFocus()`](./docs/en/FocusSensor.md#withfocus-hoc), and [`@withFocus`](./docs/en/FocusSensor.md#withfocus-decorator)
5353
- [`<GeoLocationSensor>`](./docs/en/GeoLocationSensor.md), [`withGeoLocation()`](./docs/en/GeoLocationSensor.md#withgeolocation-hoc), and [`@withGeoLocation`](./docs/en/GeoLocationSensor.md#withgeolocation-decorator)
5454
- [`<HoverSensor>`](./docs/en/HoverSensor.md), [`withHover()`](./docs/en/HoverSensor.md#withhover-hoc), and [`@withHover`](./docs/en/HoverSensor.md#withhover-decorator)
5555
- [`<MediaDeviceSensor>`](./docs/en/MediaDeviceSensor.md), [`withMediaDevices()`](./docs/en/MediaDeviceSensor.md#withmediadevices), and [`@withMediaDevices`](./docs/en/MediaDeviceSensor.md#withmediadevices-1)
5656
- [`<MediaSensor>`](./docs/en/MediaSensor.md), [`withMedia()`](./docs/en/MediaSensor.md#withmedia), and [`@withMedia`](./docs/en/MediaSensor.md#withmedia-1)
5757
- [`<MotionSensor>`](./docs/en/MotionSensor.md), [`withMotion()`](./docs/en/MotionSensor.md#withmotion-hoc), and [`@withMotion`](./docs/en/MotionSensor.md#withmotion-decorator)
58-
- [`<MouseSensor>`](./docs/en/MouseSensor.md), [`withMouse()`](./docs/en/MouseSensor.md#withmouse-hoc), and [`@withMouse`](./docs/en/MouseSensor.md#withmouse-decorator)
58+
- [`<MouseSensor>`](./docs/en/MouseSensor.md), [`withMouse()`](./docs/en/MouseSensor.md#withmouse-hoc), and [`@withMouse`](./docs/en/MouseSensor.md#withmouse-decorator) &mdash; [*example*](https://codesandbox.io/s/k3o16j7n47)
5959
- [`<NetworkSensor>`](./docs/en/NetworkSensor.md), [`withNetwork()`](./docs/en/NetworkSensor.md#withnetwork-hoc), and [`@withNetwork`](./docs/en/NetworkSensor.md#withnetwork-decorator)
6060
- [`<LightSensor>`](./docs/en/LightSensor.md), [`withLight()`](./docs/en/LightSensor.md#withlight-hoc), and [`@withLight`](./docs/en/LightSensor.md#withlight-decorator)
6161
- [`<LocationSensor>`](./docs/en/LocationSensor.md), [`withLocation()`](./docs/en/LocationSensor.md#withlocation-hoc), and [`@withLocation`](./docs/en/LocationSensor.md#withlocation-decora)
6262
- [`<OrientationSensor>`](./docs/en/OrientationSensor.md), [`withOrientation()`](./docs/en/OrientationSensor.md#withorientation-hoc), and [`@withOrientation`](./docs/en/OrientationSensor.md#withorientation-decorator)
6363
- [`<ScrollSensor>`](./docs/en/ScrollSensor.md)
64-
- [`<SizeSensor>`](./docs/en/SizeSensor.md), [`withSize()`](./docs/en/SizeSensor.md#withsize-hoc), and [`@withSize`](./docs/en/SizeSensor.md#withsize-decorator)
64+
- [`<SizeSensor>`](./docs/en/SizeSensor.md), [`withSize()`](./docs/en/SizeSensor.md#withsize-hoc), and [`@withSize`](./docs/en/SizeSensor.md#withsize-decorator) &mdash; [*example*](https://codesandbox.io/s/0y2qjm210p)
6565
- [`<WidthSensor>`](./docs/en/WidthSensor.md), [`withWidth()`](./docs/en/WidthSensor.md#withwidth-hoc-and-withwidth-decorator), and [`@withWidth`](./docs/en/WidthSensor.md#withwidth-hoc-and-withwidth-decorator)
6666
- [`<ViewportSensor>`](./docs/en/ViewportSensor.md), [`withViewport()`](./docs/en/ViewportSensor.md#withviewport-hoc), and [`@withViewport`](./docs/en/ViewportSensor.md#withviewport-decorator)
6767
- [`<ViewportScrollSensor>`](./docs/en/ViewportSensor.md#viewportscrollsensor) and [`<ViewportObserverSensor>`](./docs/en/ViewportSensor.md#viewportobserversensor)
@@ -74,7 +74,7 @@ const MyComponent = mock();
7474
- [`<Router>`](./docs/en/routing.md#router), [`<Route>`](./docs/en/routing.md#route), [`withRoute()`](./docs/en/routing.md#withroute), `@withRoute`, `go()`, and `<Go>`
7575
- [`<Translations>`](./docs/en/translate.md#translations), [`<Translate>`](./docs/en/translate.md#translate-or-t), [`<T>`](./docs/en/translate.md#translate-or-t), [`withT()`](./docs/en/translate.md#witht-hoc), and [`@withT`](./docs/en/translate.md#witht-decorator)
7676
- [UI](./docs/en/UI.md)
77-
- [`<Portal>`](./docs/en/Portal.md) and [`<Overlay>`](./docs/en/Overlay.md)
77+
- [`<Portal>`](./docs/en/Portal.md), [`<Overlay>`](./docs/en/Overlay.md), and [`<Modal>`](./docs/en/Modal.md)
7878
- [`<FullScreen>`](./docs/en/FullScreen.md)
7979
- [`<Slider>`](./docs/en/Slider.md)
8080
- [`<Audio>`](./docs/en/Audio.md) and [`<Video>`](./docs/en/Video.md)

build/gulpfile.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const gulp = require('gulp');
2+
const ts = require('gulp-typescript');
3+
const tsConfig = require('../tsconfig');
4+
const path = require('path');
5+
6+
const ignore = [
7+
'!../src/**/__tests__/**',
8+
'!../src/**/__story__/**',
9+
'!../src/**/__docs__/**',
10+
'!../src/**/story.ts',
11+
'!../src/**/story.tsx'
12+
];
13+
14+
gulp.task('build-ts', () => {
15+
return gulp.src([
16+
'../src/**/*.ts',
17+
...ignore
18+
]).pipe(ts({
19+
...tsConfig.compilerOptions,
20+
target: 'es5',
21+
module: 'commonjs'
22+
})).pipe(gulp.dest('../lib'));
23+
});
24+
25+
gulp.task('build-modules', () => {
26+
return gulp.src([
27+
'../src/**/*.ts',
28+
...ignore
29+
]).pipe(ts({
30+
...tsConfig.compilerOptions,
31+
target: 'ESNext',
32+
module: 'ESNext'
33+
})).pipe(gulp.dest('../modules'));
34+
});
35+
36+
gulp.task('build', () => {
37+
gulp.start('build-ts');
38+
gulp.start('build-modules');
39+
});

docs/en/Modal.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# `<Modal>`
2+
3+
Creates a modal overlay. This component is similar to [`<Overlay>`](./Overlay.md) but provides the following extras:
4+
5+
- traps tabbing focus inside the overlay.
6+
- makes all other root level elements inert to user input.
7+
- sets aria title and description ids.
8+
9+
### Usage
10+
11+
Basic example.
12+
13+
```jsx
14+
import {Modal} from 'libreact/lib/Modal';
15+
16+
<Modal>
17+
This is modal.
18+
</Modal>
19+
```
20+
21+
Set aria title, description, and close button.
22+
23+
```jsx
24+
<Modal>{({idTitle, idDescription, close}) =>
25+
<div>
26+
<h1 id={idTitle}>My title</h1>
27+
<p id={idDescription}>This is description.</p>
28+
29+
<button onClick={close}>Cancel</button>
30+
</div>
31+
}</Modal>
32+
```
33+
34+
Track when user intends to close the the modal.
35+
36+
```jsx
37+
<Modal onClick={} onEsc={}>
38+
This is modal.
39+
</Modal>
40+
```
41+
42+
43+
## Props
44+
45+
Accepts all [`<Overlay>`](./Overlay.md) props in addition to:
46+
47+
- `onEsc` &mdash; optional, callback, called when user presses `Esc` button.
48+
- `onClose` &mdash; optional, callback, called when `close()` is executed.
49+
50+
51+
## State
52+
53+
`<Modal>` is a render prop that injects its state into the render function. State has the following keys.
54+
55+
- `close()` &mdash; method to calle `onClose` event.
56+
- `idTitle` &mdash; id to set for aria title element.
57+
- `idDescription` &mdash; id to set for aria description element.

docs/en/Overlay.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ import {Overlay} from 'libreact/lib/Overlay';
1818

1919
- `color` &mdash; optional, string, overlay color, defaults to `rgba(0, 0, 0, 0.5)`.
2020
- `time` &mdash; optional, number, entrance opacity animation length in milliseconds, defaults to `300`.
21+
- `onElement` &mdash; optional, callback that receives the DOM element overlay created.
22+
- `onClick` &mdash; optional, callback, which is called when user click on overlay but not on its children.

docs/en/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
- [`<Router>`](./routing.md#router), [`<Route>`](./routing.md#route), [`withRoute()`](./routing.md#withroute), `@withRoute`, `go()`, and `<Go>`
4444
- [`<Translations>`](./translate.md#translations), [`<Translate>`](./translate.md#translate-or-t), [`<T>`](./translate.md#translate-or-t), [`withT()`](./translate.md#witht-hoc), and [`@withT`](./translate.md#witht-decorator)
4545
- [UI](./UI.md)
46-
- [`<Portal>`](./Portal.md) and [`<Overlay>`](./Overlay.md)
46+
- [`<Portal>`](./Portal.md), [`<Overlay>`](./Overlay.md), and [`<Modal>`](./Modal.md)
4747
- [`<FullScreen>`](./FullScreen.md)
4848
- [`<Slider>`](./Slider.md)
4949
- [`<Audio>`](./Audio.md) and [`<Video>`](./Video.md)

docs/en/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
* [UI](UI.md)
5353
* [Portal](Portal.md)
5454
* [Overlay](Overlay.md)
55+
* [Modal](Modal.md)
5556
* [FullScreen](FullScreen.md)
5657
* [Slider](Slider.md)
5758
* [Audio](Audio.md)

docs/en/cssvars.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Use [CSS Custom Properties](https://developer.mozilla.org/en-US/docs/Web/CSS/--*) (aka CSS variables) theming with automatic fallback
44
to [regular theming](./theme.md). Below components allow you to safely use CSS variables. You simply use `<CssVarsProvider>` similar
5-
to how you use [`<Theme>`](./theme.md#theme), but if CSS variables are supported by user's browser, *all values will be replaces instead
5+
to how you use [`<Theme>`](./theme.md#theme), but if CSS variables are supported by user's browser, *all values will be replaced
66
by CSS variables* and on subsequent re-renders it will try to *just modify the CSS variables without re-rendering* the children.
77

88
> If CSS Custom Properties are not supported, CssVars works like a typical theme provider.

gulpfile.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

package.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "libreact",
3-
"version": "0.6.3",
3+
"version": "0.6.6",
44
"description": "React standard library",
55
"main": "lib/index.js",
66
"repository": {
@@ -9,7 +9,7 @@
99
},
1010
"scripts": {
1111
"start": "npm run test:story",
12-
"build": "npm run clean && gulp build-ts && gulp build-modules",
12+
"build": "npm run clean && gulp --gulpfile build/gulpfile.js build",
1313
"clean": "rimraf lib modules && npm run test:story:clean && npm run docs:clean",
1414
"test": "npm run test:server && npm run test:client",
1515
"test:server": "mocha -r ts-node/register src/**/*.test-server.ts*",
@@ -28,11 +28,13 @@
2828
},
2929
"dependencies": {
3030
"throttle-debounce": "^1.0.1",
31-
"freestyler-context": "^1.3.3",
32-
"freestyler-renderer": "^1.3.2",
31+
"freestyler": "1.10.0",
3332
"screenfull": "^3.3.2",
3433
"fast-extend": "1.0.2",
35-
"fast-shallow-equal": "0.1.1"
34+
"fast-shallow-equal": "0.1.1",
35+
"tslib": "^1.9.0",
36+
"react-universal-interface": "^0.3.1",
37+
"react-focus-lock": "1.6.5"
3638
},
3739
"peerDependencies": {
3840
"react": "*",
@@ -165,6 +167,9 @@
165167
"link",
166168
"fullscreen",
167169
"css",
168-
"reset"
170+
"reset",
171+
"portal",
172+
"overlay",
173+
"modal"
169174
]
170175
}

0 commit comments

Comments
 (0)