@ndla/ui 3.3.7 → 3.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/Breadcrumb/Breadcrumb.js +2 -1
- package/es/NDLAFilm/FilmSlideshow.js +213 -247
- package/es/NDLAFilm/NavigationArrow.js +13 -60
- package/es/NDLAFilm/SlideshowIndicator.js +16 -63
- package/es/NDLAFilm/interfaces.js +0 -0
- package/es/NDLAFilm/shapes.js +0 -10
- package/es/Spinner/Spinner.js +3 -3
- package/lib/Breadcrumb/Breadcrumb.js +2 -1
- package/lib/NDLAFilm/FilmSlideshow.d.ts +16 -0
- package/lib/NDLAFilm/FilmSlideshow.js +214 -248
- package/lib/NDLAFilm/NavigationArrow.d.ts +15 -0
- package/lib/NDLAFilm/NavigationArrow.js +20 -65
- package/lib/NDLAFilm/SlideshowIndicator.d.ts +15 -0
- package/lib/NDLAFilm/SlideshowIndicator.js +16 -69
- package/lib/NDLAFilm/interfaces.d.ts +10 -0
- package/lib/NDLAFilm/interfaces.js +1 -0
- package/lib/NDLAFilm/shapes.d.ts +5 -0
- package/lib/NDLAFilm/shapes.js +1 -14
- package/lib/Spinner/Spinner.d.ts +3 -3
- package/lib/Spinner/Spinner.js +2 -2
- package/package.json +4 -4
- package/src/Breadcrumb/Breadcrumb.tsx +1 -1
- package/src/NDLAFilm/FilmSlideshow.tsx +264 -0
- package/src/NDLAFilm/NavigationArrow.tsx +42 -0
- package/src/NDLAFilm/SlideshowIndicator.tsx +40 -0
- package/src/NDLAFilm/interfaces.ts +10 -0
- package/src/NDLAFilm/shapes.ts +6 -0
- package/src/Spinner/Spinner.tsx +9 -5
- package/src/NDLAFilm/FilmSlideshow.jsx +0 -277
- package/src/NDLAFilm/NavigationArrow.jsx +0 -46
- package/src/NDLAFilm/SlideshowIndicator.jsx +0 -43
- package/src/NDLAFilm/shapes.js +0 -17
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2019-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { NDLAMovie } from './interfaces';
|
|
9
|
+
interface Props {
|
|
10
|
+
slideshow: NDLAMovie[];
|
|
11
|
+
activeSlide: number;
|
|
12
|
+
gotoSlide: (indexTarget: number, useAnimation: boolean) => void;
|
|
13
|
+
}
|
|
14
|
+
declare const SlideshowIndicator: ({ slideshow, activeSlide, gotoSlide }: Props) => JSX.Element;
|
|
15
|
+
export default SlideshowIndicator;
|
|
@@ -5,89 +5,36 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
|
|
8
|
-
var _react =
|
|
9
|
-
|
|
10
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
9
|
|
|
12
10
|
var _reactBemHelper = _interopRequireDefault(require("react-bem-helper"));
|
|
13
11
|
|
|
14
|
-
var _shapes = require("./shapes");
|
|
15
|
-
|
|
16
12
|
var _core = require("@emotion/core");
|
|
17
13
|
|
|
18
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
15
|
|
|
20
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
|
|
21
|
-
|
|
22
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
-
|
|
24
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
25
|
-
|
|
26
16
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
27
17
|
|
|
28
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
29
|
-
|
|
30
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
31
|
-
|
|
32
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
33
|
-
|
|
34
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
35
|
-
|
|
36
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
37
|
-
|
|
38
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
39
|
-
|
|
40
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
41
|
-
|
|
42
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
43
|
-
|
|
44
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
45
|
-
|
|
46
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
47
|
-
|
|
48
18
|
var classes = new _reactBemHelper["default"]({
|
|
49
19
|
name: 'film-slideshow',
|
|
50
20
|
prefix: 'c-'
|
|
51
21
|
});
|
|
52
22
|
|
|
53
|
-
var SlideshowIndicator =
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
var _this$props = this.props,
|
|
68
|
-
slideshow = _this$props.slideshow,
|
|
69
|
-
activeSlide = _this$props.activeSlide,
|
|
70
|
-
gotoSlide = _this$props.gotoSlide;
|
|
71
|
-
return (0, _core.jsx)("div", classes('indicator-wrapper'), slideshow.map(function (slide, index) {
|
|
72
|
-
return (0, _core.jsx)("button", _extends({
|
|
73
|
-
key: "indicator_".concat(index) // eslint-disable-line react/no-array-index-key
|
|
74
|
-
,
|
|
75
|
-
type: "button"
|
|
76
|
-
}, classes('indicator-dot', index === activeSlide ? 'active' : ''), {
|
|
77
|
-
onClick: function onClick() {
|
|
78
|
-
return gotoSlide(index, true);
|
|
79
|
-
}
|
|
80
|
-
}), (0, _core.jsx)("span", null));
|
|
81
|
-
}));
|
|
82
|
-
}
|
|
83
|
-
}]);
|
|
84
|
-
|
|
85
|
-
return SlideshowIndicator;
|
|
86
|
-
}(_react.Component);
|
|
87
|
-
|
|
88
|
-
SlideshowIndicator.propTypes = {
|
|
89
|
-
slideshow: _propTypes["default"].arrayOf(_shapes.movieShape),
|
|
90
|
-
activeSlide: _propTypes["default"].number
|
|
23
|
+
var SlideshowIndicator = function SlideshowIndicator(_ref) {
|
|
24
|
+
var slideshow = _ref.slideshow,
|
|
25
|
+
activeSlide = _ref.activeSlide,
|
|
26
|
+
gotoSlide = _ref.gotoSlide;
|
|
27
|
+
return (0, _core.jsx)("div", classes('indicator-wrapper'), slideshow.map(function (slide, index) {
|
|
28
|
+
return (0, _core.jsx)("button", _extends({
|
|
29
|
+
key: "indicator_".concat(index),
|
|
30
|
+
type: "button"
|
|
31
|
+
}, classes('indicator-dot', index === activeSlide ? 'active' : ''), {
|
|
32
|
+
onClick: function onClick() {
|
|
33
|
+
return gotoSlide(index, true);
|
|
34
|
+
}
|
|
35
|
+
}), (0, _core.jsx)("span", null));
|
|
36
|
+
}));
|
|
91
37
|
};
|
|
38
|
+
|
|
92
39
|
var _default = SlideshowIndicator;
|
|
93
40
|
exports["default"] = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/lib/NDLAFilm/shapes.js
CHANGED
|
@@ -3,25 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.topicShape =
|
|
6
|
+
exports.topicShape = void 0;
|
|
7
7
|
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
11
|
|
|
12
|
-
var movieShape = _propTypes["default"].shape({
|
|
13
|
-
id: _propTypes["default"].string.isRequired,
|
|
14
|
-
metaDescription: _propTypes["default"].string.isRequired,
|
|
15
|
-
title: _propTypes["default"].string.isRequired,
|
|
16
|
-
metaImage: _propTypes["default"].shape({
|
|
17
|
-
url: _propTypes["default"].string.isRequired,
|
|
18
|
-
alt: _propTypes["default"].string.isRequired
|
|
19
|
-
}),
|
|
20
|
-
path: _propTypes["default"].string.isRequired
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
exports.movieShape = movieShape;
|
|
24
|
-
|
|
25
12
|
var topicShape = _propTypes["default"].shape({
|
|
26
13
|
id: _propTypes["default"].string,
|
|
27
14
|
name: _propTypes["default"].string
|
package/lib/Spinner/Spinner.d.ts
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { SpacingNames } from '@ndla/core';
|
|
9
9
|
interface Props {
|
|
10
|
-
size
|
|
11
|
-
margin
|
|
12
|
-
inverted
|
|
10
|
+
size?: SpacingNames;
|
|
11
|
+
margin?: string;
|
|
12
|
+
inverted?: boolean;
|
|
13
13
|
}
|
|
14
14
|
declare const Spinner: ({ size, margin, inverted }: Partial<Props>) => JSX.Element;
|
|
15
15
|
export default Spinner;
|
package/lib/Spinner/Spinner.js
CHANGED
|
@@ -33,9 +33,9 @@ var SpinnerDiv = ( /*#__PURE__*/0, _styledBase["default"])('div', {
|
|
|
33
33
|
return _core.spacing[props.size];
|
|
34
34
|
}, ";width:", function (props) {
|
|
35
35
|
return _core.spacing[props.size];
|
|
36
|
-
}, ";
|
|
36
|
+
}, ";margin:", function (props) {
|
|
37
37
|
return props.margin;
|
|
38
|
-
}, ";@keyframes spinnerAnimation{0%{transform:rotate(0deg);}100%{transform:rotate(360deg);}}" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,
|
|
38
|
+
}, ";display:block;@keyframes spinnerAnimation{0%{transform:rotate(0deg);}100%{transform:rotate(360deg);}}" + (process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIlNwaW5uZXIudHN4Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQXNCNkMiLCJmaWxlIjoiU3Bpbm5lci50c3giLCJzb3VyY2VzQ29udGVudCI6WyIvKipcbiAqIENvcHlyaWdodCAoYykgMjAxOC1wcmVzZW50LCBORExBLlxuICpcbiAqIFRoaXMgc291cmNlIGNvZGUgaXMgbGljZW5zZWQgdW5kZXIgdGhlIEdQTHYzIGxpY2Vuc2UgZm91bmQgaW4gdGhlXG4gKiBMSUNFTlNFIGZpbGUgaW4gdGhlIHJvb3QgZGlyZWN0b3J5IG9mIHRoaXMgc291cmNlIHRyZWUuXG4gKlxuICovXG5cbmltcG9ydCBSZWFjdCBmcm9tICdyZWFjdCc7XG5pbXBvcnQgc3R5bGVkIGZyb20gJ0BlbW90aW9uL3N0eWxlZCc7XG5pbXBvcnQgeyBjb2xvcnMsIHNwYWNpbmcsIFNwYWNpbmdOYW1lcyB9IGZyb20gJ0BuZGxhL2NvcmUnO1xuXG5pbnRlcmZhY2UgUHJvcHMge1xuICBzaXplPzogU3BhY2luZ05hbWVzO1xuICBtYXJnaW4/OiBzdHJpbmc7XG4gIGludmVydGVkPzogYm9vbGVhbjtcbn1cblxuaW50ZXJmYWNlIFN0eWxlZFByb3BzIGV4dGVuZHMgUHJvcHMge1xuICBzaXplOiBTcGFjaW5nTmFtZXM7XG59XG5cbmNvbnN0IFNwaW5uZXJEaXYgPSBzdHlsZWQoJ2RpdicpPFN0eWxlZFByb3BzPmBcbiAgYm9yZGVyOiBjYWxjKCR7KHByb3BzKSA9PiBzcGFjaW5nW3Byb3BzLnNpemVdfSAvIDYuNSkgc29saWQgcmdiYSgwLCAwLCAwLCAwLjEpO1xuICBib3JkZXItYm90dG9tLWNvbG9yOiAkeyhwcm9wcykgPT4gKHByb3BzLmludmVydGVkID8gJyNmZmYnIDogY29sb3JzLmJyYW5kLnByaW1hcnkpfTtcbiAgYm9yZGVyLXJhZGl1czogNTAlO1xuICBhbmltYXRpb246IHNwaW5uZXJBbmltYXRpb24gMC43cyBsaW5lYXIgaW5maW5pdGU7XG4gIGhlaWdodDogJHsocHJvcHMpID0+IHNwYWNpbmdbcHJvcHMuc2l6ZV19O1xuICB3aWR0aDogJHsocHJvcHMpID0+IHNwYWNpbmdbcHJvcHMuc2l6ZV19O1xuICBtYXJnaW46ICR7KHByb3BzKSA9PiBwcm9wcy5tYXJnaW59O1xuICBkaXNwbGF5OiBibG9jaztcbiAgQGtleWZyYW1lcyBzcGlubmVyQW5pbWF0aW9uIHtcbiAgICAwJSB7XG4gICAgICB0cmFuc2Zvcm06IHJvdGF0ZSgwZGVnKTtcbiAgICB9XG4gICAgMTAwJSB7XG4gICAgICB0cmFuc2Zvcm06IHJvdGF0ZSgzNjBkZWcpO1xuICAgIH1cbiAgfVxuYDtcblxuY29uc3QgU3Bpbm5lciA9ICh7IHNpemUgPSAnbGFyZ2UnLCBtYXJnaW4gPSBgJHtzcGFjaW5nLm5vcm1hbH0gYXV0b2AsIGludmVydGVkIH06IFBhcnRpYWw8UHJvcHM+KSA9PiAoXG4gIDxTcGlubmVyRGl2IHNpemU9e3NpemV9IG1hcmdpbj17bWFyZ2lufSBpbnZlcnRlZD17ISFpbnZlcnRlZH0gLz5cbik7XG5cbmV4cG9ydCBkZWZhdWx0IFNwaW5uZXI7XG4iXX0= */"));
|
|
39
39
|
|
|
40
40
|
var Spinner = function Spinner(_ref) {
|
|
41
41
|
var _ref$size = _ref.size,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndla/ui",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.8",
|
|
4
4
|
"description": "UI component library for NDLA.",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@ndla/button": "^1.1.2",
|
|
35
|
-
"@ndla/carousel": "^1.0
|
|
35
|
+
"@ndla/carousel": "^1.1.0",
|
|
36
36
|
"@ndla/core": "^0.7.2",
|
|
37
37
|
"@ndla/hooks": "^1.0.7",
|
|
38
38
|
"@ndla/icons": "^1.3.2",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"react-facebook": "^6.0.15",
|
|
64
64
|
"react-prop-types": "0.4.0",
|
|
65
65
|
"react-sticky-el": "^2.0.6",
|
|
66
|
-
"react-swipeable": "^
|
|
66
|
+
"react-swipeable": "^6.2.0",
|
|
67
67
|
"react-syntax-highlighter": "^15.4.4",
|
|
68
68
|
"react-transition-group": "^2.5.3",
|
|
69
69
|
"shave": "^2.5.10"
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
"publishConfig": {
|
|
93
93
|
"access": "public"
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "5c0c46da877836c5e8dbaf52979a8965a41ca0ec"
|
|
96
96
|
}
|
|
@@ -43,7 +43,7 @@ const Breadcrumb: React.FunctionComponent<Props & WithTranslation> = ({ children
|
|
|
43
43
|
isCurrent={i === items.length - 1}
|
|
44
44
|
to={item.to}
|
|
45
45
|
name={item.name}>
|
|
46
|
-
{i === 0 ? <Home className="c-icon--20" /> : item.name}
|
|
46
|
+
{i === 0 ? <Home className="c-icon--20" title={item.name} /> : item.name}
|
|
47
47
|
</BreadcrumbItem>
|
|
48
48
|
))}
|
|
49
49
|
</ol>
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
10
|
+
import { SwipeEventData, useSwipeable } from 'react-swipeable';
|
|
11
|
+
import BEMHelper from 'react-bem-helper';
|
|
12
|
+
import SafeLink from '@ndla/safelink';
|
|
13
|
+
import { OneColumn } from '../Layout';
|
|
14
|
+
import Spinner from '../Spinner';
|
|
15
|
+
import { NDLAMovie } from './interfaces';
|
|
16
|
+
import NavigationArrow from './NavigationArrow';
|
|
17
|
+
import SlideshowIndicator from './SlideshowIndicator';
|
|
18
|
+
|
|
19
|
+
interface Props {
|
|
20
|
+
autoSlide: boolean;
|
|
21
|
+
randomStart: boolean;
|
|
22
|
+
slideshow: NDLAMovie[];
|
|
23
|
+
slideInterval: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const classes = new BEMHelper({
|
|
27
|
+
name: 'film-slideshow',
|
|
28
|
+
prefix: 'c-',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const defaultTransitionSwipeEnd = 'transform 600ms cubic-bezier(0, 0.76, 0.09, 1)';
|
|
32
|
+
const defaultTransitionText = 'opacity 600ms ease';
|
|
33
|
+
|
|
34
|
+
const renderSlideItem = (slide: NDLAMovie) => (
|
|
35
|
+
<div
|
|
36
|
+
{...classes('item')}
|
|
37
|
+
key={slide.id}
|
|
38
|
+
role="img"
|
|
39
|
+
aria-label={(slide.metaImage && slide.metaImage.alt) || ''}
|
|
40
|
+
style={{
|
|
41
|
+
backgroundImage: `url(${(slide.metaImage && slide.metaImage.url) || ''})`,
|
|
42
|
+
}}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const FilmSlideshow = ({ autoSlide = false, slideshow = [], slideInterval = 5000 }: Props) => {
|
|
47
|
+
const [swipeDistance, setSwipeDistance] = useState(0);
|
|
48
|
+
const [slideIndex, setSlideIndex] = useState(0);
|
|
49
|
+
const [slideIndexTarget, setSlideIndexTarget] = useState(0);
|
|
50
|
+
const [animationComplete, setAnimationComplete] = useState(true);
|
|
51
|
+
const slideRef = useRef<HTMLDivElement>(null);
|
|
52
|
+
const slideText = useRef<HTMLDivElement>(null);
|
|
53
|
+
let timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
54
|
+
|
|
55
|
+
const gotoSlide = useCallback((indexTarget: number, useAnimation = false) => {
|
|
56
|
+
setSwipeDistance(0);
|
|
57
|
+
if (timer.current) {
|
|
58
|
+
clearTimeout(timer.current);
|
|
59
|
+
}
|
|
60
|
+
setSlideIndexTarget(indexTarget);
|
|
61
|
+
setAnimationComplete(!useAnimation);
|
|
62
|
+
}, []);
|
|
63
|
+
|
|
64
|
+
const onChangedSlide = () => {
|
|
65
|
+
if (!animationComplete) {
|
|
66
|
+
if (slideRef.current) {
|
|
67
|
+
slideRef.current.style.transition = 'none';
|
|
68
|
+
slideRef.current.style.transform = `translateX(${slideIndexTarget * 100}vw))`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
setAnimationComplete(true);
|
|
72
|
+
setSlideIndex(slideIndexTarget);
|
|
73
|
+
} else if (slideIndexTarget === -1) {
|
|
74
|
+
if (slideRef.current) {
|
|
75
|
+
// Go to last slide for continuous loop
|
|
76
|
+
slideRef.current.style.transition = 'none';
|
|
77
|
+
slideRef.current.style.transform = `translateX(${slideshow.length * 100}vw))`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
setSlideIndex(slideshow.length - 1);
|
|
81
|
+
setSlideIndexTarget(slideshow.length - 1);
|
|
82
|
+
setAnimationComplete(true);
|
|
83
|
+
} else if (slideIndexTarget === slideshow.length) {
|
|
84
|
+
if (slideRef.current) {
|
|
85
|
+
// Go to first slide for continuous loop
|
|
86
|
+
slideRef.current.style.transition = 'none';
|
|
87
|
+
slideRef.current.style.transform = `translateX(100vw))`;
|
|
88
|
+
}
|
|
89
|
+
setSlideIndex(0);
|
|
90
|
+
setSlideIndexTarget(0);
|
|
91
|
+
setAnimationComplete(true);
|
|
92
|
+
} else {
|
|
93
|
+
setAnimationComplete(true);
|
|
94
|
+
setSlideIndex(slideIndexTarget);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const onSwipeEnd = () => {
|
|
99
|
+
let slide;
|
|
100
|
+
if (swipeDistance > 40) {
|
|
101
|
+
slide = -1;
|
|
102
|
+
} else if (swipeDistance < -40) {
|
|
103
|
+
slide = 1;
|
|
104
|
+
} else {
|
|
105
|
+
slide = 0;
|
|
106
|
+
}
|
|
107
|
+
if (slideRef.current && slideText.current) {
|
|
108
|
+
slideRef.current.style.transition = defaultTransitionSwipeEnd;
|
|
109
|
+
slideText.current.style.transition = defaultTransitionText;
|
|
110
|
+
slideText.current.style.opacity = '1';
|
|
111
|
+
}
|
|
112
|
+
setSwipeDistance(0);
|
|
113
|
+
|
|
114
|
+
initTimer();
|
|
115
|
+
|
|
116
|
+
if (slide !== 0) {
|
|
117
|
+
setSlideIndex(slideIndex + slide);
|
|
118
|
+
setSlideIndexTarget(slideIndex + slide);
|
|
119
|
+
} else {
|
|
120
|
+
// Reset transfrom
|
|
121
|
+
if (slideRef.current) {
|
|
122
|
+
slideRef.current.style.transform = getSlidePosition(slideIndex + slide);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const onSwipe = (eventData: SwipeEventData) => {
|
|
128
|
+
if (eventData.dir === 'Up' || eventData.dir === 'Down') {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (timer.current) {
|
|
132
|
+
clearTimeout(timer.current);
|
|
133
|
+
}
|
|
134
|
+
setSwipeDistance(eventData.deltaX);
|
|
135
|
+
if (slideRef && slideRef.current) {
|
|
136
|
+
slideRef.current.style.transition = 'none';
|
|
137
|
+
slideRef.current.style.transform = getSlidePosition(slideIndexTarget);
|
|
138
|
+
}
|
|
139
|
+
const opacityText = 1 - Math.min(100, Math.abs(swipeDistance)) / 100;
|
|
140
|
+
if (slideText && slideText.current) {
|
|
141
|
+
slideText.current.style.transition = 'none';
|
|
142
|
+
slideText.current.style.opacity = opacityText.toString();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const onTransitionEnd = () => {
|
|
147
|
+
const slideshowLength = slideshow.length;
|
|
148
|
+
if (slideIndex === -1) {
|
|
149
|
+
if (slideRef.current) {
|
|
150
|
+
slideRef.current.style.transition = 'none';
|
|
151
|
+
slideRef.current.style.transform = getSlidePosition(slideshowLength - 1);
|
|
152
|
+
}
|
|
153
|
+
setSlideIndex(slideshowLength - 1);
|
|
154
|
+
setSlideIndexTarget(slideshowLength - 1);
|
|
155
|
+
} else if (slideIndex >= slideshowLength) {
|
|
156
|
+
if (slideRef.current) {
|
|
157
|
+
slideRef.current.style.transition = 'none';
|
|
158
|
+
slideRef.current.style.transform = getSlidePosition(0);
|
|
159
|
+
}
|
|
160
|
+
setSlideIndex(0);
|
|
161
|
+
setSlideIndexTarget(0);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const getSlidePosition = (target: number) => {
|
|
166
|
+
if (swipeDistance !== 0) {
|
|
167
|
+
return `translateX(calc(${swipeDistance}px -
|
|
168
|
+
${(target + 1) * 100}vw))`;
|
|
169
|
+
}
|
|
170
|
+
return `translateX(-${(target + 1) * 100}vw)`;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const initTimer = useCallback(() => {
|
|
174
|
+
if (autoSlide) {
|
|
175
|
+
timer.current = setTimeout(() => {
|
|
176
|
+
gotoSlide(slideIndex + 1);
|
|
177
|
+
}, slideInterval);
|
|
178
|
+
}
|
|
179
|
+
}, [autoSlide, gotoSlide, slideInterval, slideIndex]);
|
|
180
|
+
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
initTimer();
|
|
183
|
+
}, [initTimer]);
|
|
184
|
+
|
|
185
|
+
const handlers = useSwipeable({
|
|
186
|
+
onSwiped: onSwipeEnd,
|
|
187
|
+
onSwiping: onSwipe,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
if (slideshow.length === 0) {
|
|
191
|
+
return (
|
|
192
|
+
<div>
|
|
193
|
+
<div {...classes('slideshow')}>
|
|
194
|
+
<Spinner inverted />
|
|
195
|
+
</div>
|
|
196
|
+
</div>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const slideshowWidth = `${(slideshow.length + 2) * 100}vw`;
|
|
201
|
+
let activeSlide = slideIndex;
|
|
202
|
+
if (activeSlide < 0) {
|
|
203
|
+
activeSlide = slideshow.length - 1;
|
|
204
|
+
} else if (activeSlide >= slideshow.length) {
|
|
205
|
+
activeSlide = 0;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return (
|
|
209
|
+
<section {...classes('')} {...handlers}>
|
|
210
|
+
<>
|
|
211
|
+
<div {...classes('slide-link-wrapper')}>
|
|
212
|
+
<OneColumn>
|
|
213
|
+
<SafeLink
|
|
214
|
+
to={slideshow[activeSlide].path}
|
|
215
|
+
{...classes('item-wrapper', 'text', {
|
|
216
|
+
out: !animationComplete,
|
|
217
|
+
})}>
|
|
218
|
+
<div {...classes('slide-info')} ref={slideText}>
|
|
219
|
+
<h1>{slideshow[activeSlide].title}</h1>
|
|
220
|
+
<p>{slideshow[activeSlide].metaDescription}</p>
|
|
221
|
+
</div>
|
|
222
|
+
</SafeLink>
|
|
223
|
+
</OneColumn>
|
|
224
|
+
</div>
|
|
225
|
+
<NavigationArrow
|
|
226
|
+
slideIndexTarget={slideIndexTarget > 0 ? slideIndexTarget - 1 : slideshow.length - 1}
|
|
227
|
+
gotoSlide={gotoSlide}
|
|
228
|
+
/>
|
|
229
|
+
<NavigationArrow
|
|
230
|
+
slideIndexTarget={slideIndexTarget < slideshow.length - 1 ? slideIndexTarget + 1 : 0}
|
|
231
|
+
gotoSlide={gotoSlide}
|
|
232
|
+
rightArrow
|
|
233
|
+
/>
|
|
234
|
+
{!animationComplete && (
|
|
235
|
+
<div
|
|
236
|
+
{...classes('item', 'fade-over')}
|
|
237
|
+
role="img"
|
|
238
|
+
onAnimationEnd={onChangedSlide}
|
|
239
|
+
style={{
|
|
240
|
+
backgroundImage: `url(${
|
|
241
|
+
(slideshow[activeSlide].metaImage && slideshow[activeSlide].metaImage.url) || ''
|
|
242
|
+
})`,
|
|
243
|
+
}}
|
|
244
|
+
/>
|
|
245
|
+
)}
|
|
246
|
+
<div
|
|
247
|
+
ref={slideRef}
|
|
248
|
+
{...classes('item-wrapper')}
|
|
249
|
+
onTransitionEnd={onTransitionEnd}
|
|
250
|
+
style={{
|
|
251
|
+
width: slideshowWidth,
|
|
252
|
+
transform: getSlidePosition(slideIndex),
|
|
253
|
+
}}>
|
|
254
|
+
{renderSlideItem(slideshow[slideshow.length - 1])}
|
|
255
|
+
{slideshow.map(renderSlideItem)}
|
|
256
|
+
{renderSlideItem(slideshow[0])}
|
|
257
|
+
</div>
|
|
258
|
+
<SlideshowIndicator slideshow={slideshow} activeSlide={activeSlide} gotoSlide={gotoSlide} />
|
|
259
|
+
</>
|
|
260
|
+
</section>
|
|
261
|
+
);
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
export default FilmSlideshow;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import React from 'react';
|
|
10
|
+
import BEMHelper from 'react-bem-helper';
|
|
11
|
+
import { ChevronRight, ChevronLeft } from '@ndla/icons/common';
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
slideIndexTarget: number;
|
|
15
|
+
slideshowLength?: number;
|
|
16
|
+
gotoSlide: (indexTarget: number, useAnimation: boolean) => void;
|
|
17
|
+
rightArrow?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const classes = new BEMHelper({
|
|
21
|
+
name: 'film-slideshow',
|
|
22
|
+
prefix: 'c-',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const NavigationArrow = ({ slideIndexTarget, gotoSlide, rightArrow }: Props) => {
|
|
26
|
+
const Chevron = rightArrow ? ChevronRight : ChevronLeft;
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div {...classes('navigation-arrows', rightArrow ? 'right' : '')}>
|
|
30
|
+
<button
|
|
31
|
+
type="button"
|
|
32
|
+
tabIndex={-1}
|
|
33
|
+
onClick={() => {
|
|
34
|
+
gotoSlide(slideIndexTarget, true);
|
|
35
|
+
}}>
|
|
36
|
+
<Chevron />
|
|
37
|
+
</button>
|
|
38
|
+
</div>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default NavigationArrow;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2019-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import React from 'react';
|
|
10
|
+
import BEMHelper from 'react-bem-helper';
|
|
11
|
+
import { NDLAMovie } from './interfaces';
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
slideshow: NDLAMovie[];
|
|
15
|
+
activeSlide: number;
|
|
16
|
+
gotoSlide: (indexTarget: number, useAnimation: boolean) => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const classes = new BEMHelper({
|
|
20
|
+
name: 'film-slideshow',
|
|
21
|
+
prefix: 'c-',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const SlideshowIndicator = ({ slideshow, activeSlide, gotoSlide }: Props) => {
|
|
25
|
+
return (
|
|
26
|
+
<div {...classes('indicator-wrapper')}>
|
|
27
|
+
{slideshow.map((slide, index) => (
|
|
28
|
+
<button
|
|
29
|
+
key={`indicator_${index}`}
|
|
30
|
+
type="button"
|
|
31
|
+
{...classes('indicator-dot', index === activeSlide ? 'active' : '')}
|
|
32
|
+
onClick={() => gotoSlide(index, true)}>
|
|
33
|
+
<span />
|
|
34
|
+
</button>
|
|
35
|
+
))}
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default SlideshowIndicator;
|
package/src/Spinner/Spinner.tsx
CHANGED
|
@@ -8,23 +8,27 @@
|
|
|
8
8
|
|
|
9
9
|
import React from 'react';
|
|
10
10
|
import styled from '@emotion/styled';
|
|
11
|
-
import {
|
|
11
|
+
import { colors, spacing, SpacingNames } from '@ndla/core';
|
|
12
12
|
|
|
13
13
|
interface Props {
|
|
14
|
+
size?: SpacingNames;
|
|
15
|
+
margin?: string;
|
|
16
|
+
inverted?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface StyledProps extends Props {
|
|
14
20
|
size: SpacingNames;
|
|
15
|
-
margin: string;
|
|
16
|
-
inverted: boolean;
|
|
17
21
|
}
|
|
18
22
|
|
|
19
|
-
const SpinnerDiv = styled('div')<
|
|
23
|
+
const SpinnerDiv = styled('div')<StyledProps>`
|
|
20
24
|
border: calc(${(props) => spacing[props.size]} / 6.5) solid rgba(0, 0, 0, 0.1);
|
|
21
25
|
border-bottom-color: ${(props) => (props.inverted ? '#fff' : colors.brand.primary)};
|
|
22
26
|
border-radius: 50%;
|
|
23
27
|
animation: spinnerAnimation 0.7s linear infinite;
|
|
24
28
|
height: ${(props) => spacing[props.size]};
|
|
25
29
|
width: ${(props) => spacing[props.size]};
|
|
26
|
-
display: block;
|
|
27
30
|
margin: ${(props) => props.margin};
|
|
31
|
+
display: block;
|
|
28
32
|
@keyframes spinnerAnimation {
|
|
29
33
|
0% {
|
|
30
34
|
transform: rotate(0deg);
|