@comicrelief/component-library 7.18.4 → 7.19.0

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.
@@ -13,7 +13,7 @@ jobs:
13
13
  - name: Set up Node
14
14
  uses: actions/setup-node@v3
15
15
  with:
16
- node-version: 14
16
+ node-version-file: '.nvmrc'
17
17
 
18
18
  - name: Restore packages cache
19
19
  uses: actions/cache@v3
@@ -37,7 +37,7 @@ jobs:
37
37
  - name: Set up Node
38
38
  uses: actions/setup-node@v3
39
39
  with:
40
- node-version: 14
40
+ node-version-file: '.nvmrc'
41
41
 
42
42
  - name: Restore packages cache
43
43
  uses: actions/cache@v3
@@ -69,7 +69,7 @@ jobs:
69
69
  - name: Set up Node
70
70
  uses: actions/setup-node@v3
71
71
  with:
72
- node-version: 14
72
+ node-version-file: '.nvmrc'
73
73
 
74
74
  # see https://github.com/marketplace/actions/cypress-io
75
75
  - name: Run Cypress tests
@@ -110,7 +110,7 @@ jobs:
110
110
  - name: Set up Node
111
111
  uses: actions/setup-node@v3
112
112
  with:
113
- node-version: 14
113
+ node-version-file: '.nvmrc'
114
114
 
115
115
  - name: Restore packages cache
116
116
  uses: actions/cache@v3
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ v16.20.0
@@ -35,7 +35,7 @@ describe('Video Banner component', () => {
35
35
 
36
36
  describe('Video Banner section', () => {
37
37
  beforeEach(() => {
38
- cy.get('[data-testid="VideoBanner-example-0"]')
38
+ cy.get('[data-testid="VideoBanner-example-1"]')
39
39
  .as('container')
40
40
  .find('[data-preview="VideoBanner"]')
41
41
  .as('preview');
@@ -5,13 +5,12 @@
5
5
  <Select
6
6
  label="Label"
7
7
  description="Please choose an option"
8
+ // note: defaultValue is just using the built-in React defaultValue prop. It adds the HTML prop "selected" to one of the options elements. This is why defaultValue must be set to one of the existing options values:
9
+ defaultValue="Option four"
8
10
  errorMsg=""
9
11
  options={[
10
12
  { value: 'Option one', displayValue: 'The first option' },
11
- {
12
- value: 'Option two',
13
- displayValue: 'The second option'
14
- },
13
+ { value: 'Option two', displayValue: 'The second option' },
15
14
  { value: 'Option three', displayValue: 'The third option' },
16
15
  { value: 'Option four', displayValue: 'The fourth option' }
17
16
  ]}
@@ -17,10 +17,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
17
17
 
18
18
  var Video = _styledComponents.default.video.attrs(function () {
19
19
  return {
20
- autoPlay: true,
21
- playsInline: true,
22
- muted: true,
23
- loop: false
20
+ playsInline: true
24
21
  };
25
22
  }).withConfig({
26
23
  displayName: "VideoBanner__Video",
@@ -29,22 +26,48 @@ var Video = _styledComponents.default.video.attrs(function () {
29
26
 
30
27
  var VideoBanner = function VideoBanner(_ref) {
31
28
  var video = _ref.video,
32
- poster = _ref.poster;
29
+ poster = _ref.poster,
30
+ controls = _ref.controls,
31
+ autoPlay = _ref.autoPlay,
32
+ loop = _ref.loop,
33
+ muted = _ref.muted,
34
+ showPosterAfterPlaying = _ref.showPosterAfterPlaying;
33
35
  var videoEl = (0, _react.useRef)(null);
34
36
 
35
- var onPlay = function onPlay() {
37
+ var triggerPlay = function triggerPlay() {
36
38
  videoEl.current.play();
37
39
  };
38
40
 
39
41
  (0, _react.useEffect)(function () {
40
- onPlay();
42
+ // Trigger onload autoplay based on prop:
43
+ if (autoPlay) {
44
+ triggerPlay();
45
+ } // And attach event listener based on prop:
46
+
47
+
48
+ if (!loop && showPosterAfterPlaying) {
49
+ videoEl.current.addEventListener('ended', function () {
50
+ // Reloads video, which re-shows poster
51
+ videoEl.current.load();
52
+ });
53
+ }
41
54
  });
42
55
  return /*#__PURE__*/_react.default.createElement(Video, {
43
56
  poster: poster,
44
57
  src: video,
45
- ref: videoEl
58
+ ref: videoEl,
59
+ controls: controls,
60
+ loop: loop,
61
+ muted: muted
46
62
  }, "Your browser does not support video.");
47
63
  };
48
64
 
65
+ VideoBanner.defaultProps = {
66
+ showPosterAfterPlaying: true,
67
+ controls: false,
68
+ autoPlay: true,
69
+ loop: false,
70
+ muted: true
71
+ };
49
72
  var _default = VideoBanner;
50
73
  exports.default = _default;
@@ -1,7 +1,26 @@
1
+ Default Video Banner (autoplay, no loop, no poster re-show)
1
2
  ```js
2
- import poster from '../../../styleguide/assets/poster.png';
3
+ import poster from '../../../styleguide/assets/VideoBannerPosterImage.png';
3
4
  const src =
4
5
  'https://www.comicrelief.com/sites/default/files/downloads/Creativists_Logo_Web_small_V2_0.mp4';
5
6
 
6
7
  <VideoBanner poster={poster} video={src} />;
7
8
  ```
9
+ Looping Video Banner With Controls (autoplay, loop)
10
+ ```js
11
+ import poster from '../../../styleguide/assets/VideoBannerPosterImage.png';
12
+ const src =
13
+ 'https://www.comicrelief.com/sites/default/files/downloads/Creativists_Logo_Web_small_V2_0.mp4';
14
+
15
+ <VideoBanner poster={poster} video={src} loop={true} controls={true} autoPlay={true}
16
+ />;
17
+ ```
18
+
19
+ Non-autoplay Video Banner (reshows poster image after playing)
20
+ ```js
21
+ import poster from '../../../styleguide/assets/VideoBannerPosterImage.png';
22
+ const src =
23
+ 'https://www.comicrelief.com/sites/default/files/downloads/Creativists_Logo_Web_small_V2_0.mp4';
24
+
25
+ <VideoBanner poster={poster} video={src} showPosterAfterPlaying={true} />;
26
+ ```
@@ -10,13 +10,13 @@ var _shallowWithTheme = _interopRequireDefault(require("../../../hoc/shallowWith
10
10
 
11
11
  var _VideoBanner = _interopRequireDefault(require("./VideoBanner"));
12
12
 
13
- var _poster = _interopRequireDefault(require("../../../styleguide/assets/poster.png"));
13
+ var _VideoBannerPosterImage = _interopRequireDefault(require("../../../styleguide/assets/VideoBannerPosterImage.png"));
14
14
 
15
- it('renders correctly', function () {
16
- var src = 'https://www.comicrelief.com/sites/default/files/downloads/Creativists_Logo_Web_small_V2_0.mp4';
15
+ it("renders correctly", function () {
16
+ var src = "https://www.comicrelief.com/sites/default/files/downloads/Creativists_Logo_Web_small_V2_0.mp4";
17
17
  var tree = (0, _shallowWithTheme.default)( /*#__PURE__*/_react.default.createElement(_VideoBanner.default, {
18
- poster: _poster.default,
18
+ poster: _VideoBannerPosterImage.default,
19
19
  video: src
20
20
  })).toJSON();
21
- expect(tree).toMatchInlineSnapshot("\n .c0 {\n width: 100%;\n height: 100%;\n }\n\n <video\n autoPlay={true}\n className=\"c0\"\n loop={false}\n muted={true}\n playsInline={true}\n poster=\"mock.asset\"\n src=\"https://www.comicrelief.com/sites/default/files/downloads/Creativists_Logo_Web_small_V2_0.mp4\"\n >\n Your browser does not support video.\n </video>\n ");
21
+ expect(tree).toMatchInlineSnapshot("\n .c0 {\n width: 100%;\n height: 100%;\n }\n\n <video\n className=\"c0\"\n controls={false}\n loop={false}\n muted={true}\n playsInline={true}\n poster=\"mock.asset\"\n src=\"https://www.comicrelief.com/sites/default/files/downloads/Creativists_Logo_Web_small_V2_0.mp4\"\n >\n Your browser does not support video.\n </video>\n ");
22
22
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@comicrelief/component-library",
3
3
  "author": "Comic Relief Engineering Team",
4
- "version": "7.18.4",
4
+ "version": "7.19.0",
5
5
  "main": "dist/index.js",
6
6
  "license": "ISC",
7
7
  "jest": {
@@ -5,13 +5,12 @@
5
5
  <Select
6
6
  label="Label"
7
7
  description="Please choose an option"
8
+ // note: defaultValue is just using the built-in React defaultValue prop. It adds the HTML prop "selected" to one of the options elements. This is why defaultValue must be set to one of the existing options values:
9
+ defaultValue="Option four"
8
10
  errorMsg=""
9
11
  options={[
10
12
  { value: 'Option one', displayValue: 'The first option' },
11
- {
12
- value: 'Option two',
13
- displayValue: 'The second option'
14
- },
13
+ { value: 'Option two', displayValue: 'The second option' },
15
14
  { value: 'Option three', displayValue: 'The third option' },
16
15
  { value: 'Option four', displayValue: 'The fourth option' }
17
16
  ]}
@@ -3,36 +3,66 @@ import PropTypes from 'prop-types';
3
3
  import styled from 'styled-components';
4
4
 
5
5
  const Video = styled.video.attrs(() => ({
6
- autoPlay: true,
7
- playsInline: true,
8
- muted: true,
9
- loop: false
6
+ playsInline: true
10
7
  }))`
11
8
  width: 100%;
12
9
  height: 100%;
13
10
  `;
14
11
 
15
- const VideoBanner = ({ video, poster }) => {
12
+ const VideoBanner = ({
13
+ video, poster, controls, autoPlay, loop, muted, showPosterAfterPlaying
14
+ }) => {
16
15
  const videoEl = useRef(null);
17
16
 
18
- const onPlay = () => {
17
+ const triggerPlay = () => {
19
18
  videoEl.current.play();
20
19
  };
21
20
 
22
21
  useEffect(() => {
23
- onPlay();
22
+ // Trigger onload autoplay based on prop:
23
+ if (autoPlay) {
24
+ triggerPlay();
25
+ }
26
+
27
+ // And attach event listener based on prop:
28
+ if (!loop && showPosterAfterPlaying) {
29
+ videoEl.current.addEventListener('ended', () => {
30
+ // Reloads video, which re-shows poster
31
+ videoEl.current.load();
32
+ });
33
+ }
24
34
  });
25
35
 
26
36
  return (
27
- <Video poster={poster} src={video} ref={videoEl}>
37
+ <Video
38
+ poster={poster}
39
+ src={video}
40
+ ref={videoEl}
41
+ controls={controls}
42
+ loop={loop}
43
+ muted={muted}
44
+ >
28
45
  Your browser does not support video.
29
46
  </Video>
30
47
  );
31
48
  };
32
49
 
50
+ VideoBanner.defaultProps = {
51
+ showPosterAfterPlaying: true,
52
+ controls: false,
53
+ autoPlay: true,
54
+ loop: false,
55
+ muted: true
56
+ };
57
+
33
58
  VideoBanner.propTypes = {
59
+ showPosterAfterPlaying: PropTypes.bool,
34
60
  video: PropTypes.string.isRequired,
35
- poster: PropTypes.string.isRequired
61
+ poster: PropTypes.string.isRequired,
62
+ controls: PropTypes.bool,
63
+ autoPlay: PropTypes.bool,
64
+ loop: PropTypes.bool,
65
+ muted: PropTypes.bool
36
66
  };
37
67
 
38
68
  export default VideoBanner;
@@ -1,7 +1,26 @@
1
+ Default Video Banner (autoplay, no loop, no poster re-show)
1
2
  ```js
2
- import poster from '../../../styleguide/assets/poster.png';
3
+ import poster from '../../../styleguide/assets/VideoBannerPosterImage.png';
3
4
  const src =
4
5
  'https://www.comicrelief.com/sites/default/files/downloads/Creativists_Logo_Web_small_V2_0.mp4';
5
6
 
6
7
  <VideoBanner poster={poster} video={src} />;
7
8
  ```
9
+ Looping Video Banner With Controls (autoplay, loop)
10
+ ```js
11
+ import poster from '../../../styleguide/assets/VideoBannerPosterImage.png';
12
+ const src =
13
+ 'https://www.comicrelief.com/sites/default/files/downloads/Creativists_Logo_Web_small_V2_0.mp4';
14
+
15
+ <VideoBanner poster={poster} video={src} loop={true} controls={true} autoPlay={true}
16
+ />;
17
+ ```
18
+
19
+ Non-autoplay Video Banner (reshows poster image after playing)
20
+ ```js
21
+ import poster from '../../../styleguide/assets/VideoBannerPosterImage.png';
22
+ const src =
23
+ 'https://www.comicrelief.com/sites/default/files/downloads/Creativists_Logo_Web_small_V2_0.mp4';
24
+
25
+ <VideoBanner poster={poster} video={src} showPosterAfterPlaying={true} />;
26
+ ```
@@ -1,12 +1,13 @@
1
- import React from 'react';
2
- import 'jest-styled-components';
1
+ import React from "react";
2
+ import "jest-styled-components";
3
3
 
4
- import renderWithTheme from '../../../hoc/shallowWithTheme';
5
- import VideoBanner from './VideoBanner';
6
- import poster from '../../../styleguide/assets/poster.png';
4
+ import renderWithTheme from "../../../hoc/shallowWithTheme";
5
+ import VideoBanner from "./VideoBanner";
6
+ import poster from "../../../styleguide/assets/VideoBannerPosterImage.png";
7
7
 
8
- it('renders correctly', () => {
9
- const src = 'https://www.comicrelief.com/sites/default/files/downloads/Creativists_Logo_Web_small_V2_0.mp4';
8
+ it("renders correctly", () => {
9
+ const src =
10
+ "https://www.comicrelief.com/sites/default/files/downloads/Creativists_Logo_Web_small_V2_0.mp4";
10
11
 
11
12
  const tree = renderWithTheme(
12
13
  <VideoBanner poster={poster} video={src} />
@@ -19,8 +20,8 @@ it('renders correctly', () => {
19
20
  }
20
21
 
21
22
  <video
22
- autoPlay={true}
23
23
  className="c0"
24
+ controls={false}
24
25
  loop={false}
25
26
  muted={true}
26
27
  playsInline={true}
Binary file
Binary file