@ldelia/react-media 0.2.2 → 0.2.4

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/README.md CHANGED
@@ -23,4 +23,14 @@ Make sure storybook is already installed by running npx storybook@latest init
23
23
  Launch the test suite collection:
24
24
 
25
25
  ##### `npm test`
26
-
26
+
27
+
28
+ ## Publishing on npm
29
+
30
+ Build the project
31
+
32
+ ##### `npm run build`
33
+
34
+ Publish the project
35
+
36
+ ##### `npm publish`
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const react_1 = __importDefault(require("react"));
7
7
  const client_1 = require("react-dom/client");
8
- const timeline_1 = __importDefault(require("../../timeline"));
8
+ const timeline_1 = require("../../timeline");
9
9
  describe('Timeline', () => {
10
10
  let props;
11
11
  beforeEach(() => {
@@ -21,7 +21,7 @@ describe('Timeline', () => {
21
21
  it('renders a timeline', () => {
22
22
  const rootElement = document.createElement('div');
23
23
  const root = (0, client_1.createRoot)(rootElement);
24
- root.render(react_1.default.createElement(timeline_1.default, Object.assign({}, props)));
24
+ root.render(react_1.default.createElement(timeline_1.Timeline, Object.assign({}, props)));
25
25
  });
26
26
  });
27
27
  });
@@ -13,5 +13,4 @@ export type ZoomContextType = {
13
13
  pixelsInSecond: number;
14
14
  };
15
15
  export declare const ZoomContext: React.Context<ZoomContextType>;
16
- declare const Timeline: React.FC<TimelineProps>;
17
- export default Timeline;
16
+ export declare const Timeline: React.FC<TimelineProps>;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ZoomContext = void 0;
6
+ exports.Timeline = exports.ZoomContext = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const styled_components_1 = __importDefault(require("styled-components"));
9
9
  const react_2 = require("react");
@@ -74,4 +74,4 @@ const Timeline = ({ duration, value, zoomLevel = 0, selectedRange = [], onChange
74
74
  react_1.default.createElement(RangeSelectorCanvas_1.default, { selectedRange: selectedRange, onChange: onChange, onRangeChange: onRangeChange }),
75
75
  react_1.default.createElement(TickTimeCollectionDisplay_1.default, { tickTimes: blockStartingTimes })))));
76
76
  };
77
- exports.default = Timeline;
77
+ exports.Timeline = Timeline;
@@ -5,9 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.WithSelectedRange = exports.Default = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
- const timeline_1 = __importDefault(require("../components/timeline"));
8
+ const timeline_1 = require("../components/timeline");
9
9
  const styled_components_1 = __importDefault(require("styled-components"));
10
- const StyledTimeline = (0, styled_components_1.default)(timeline_1.default) `
10
+ const StyledTimeline = (0, styled_components_1.default)(timeline_1.Timeline) `
11
11
  .media-timeline-value-line {
12
12
  background-color: red;
13
13
  width: 5px;
@@ -15,7 +15,7 @@ const StyledTimeline = (0, styled_components_1.default)(timeline_1.default) `
15
15
  `;
16
16
  exports.default = {
17
17
  title: 'Timeline',
18
- component: timeline_1.default,
18
+ component: timeline_1.Timeline,
19
19
  argTypes: {
20
20
  onChange: { action: 'changed' },
21
21
  onRangeChange: { action: 'range changed' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ldelia/react-media",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "A React components collection for media-related features.",
5
5
  "private": false,
6
6
  "keywords": [
@@ -36,7 +36,9 @@
36
36
  "plugin:storybook/recommended",
37
37
  "prettier"
38
38
  ],
39
- "plugins": ["prettier"],
39
+ "plugins": [
40
+ "prettier"
41
+ ],
40
42
  "rules": {
41
43
  "prettier/prettier": "error"
42
44
  }
@@ -0,0 +1,15 @@
1
+ .timeline-container {
2
+ background-color: #f0f0f0;
3
+ border: 1px solid #c9c9c9;
4
+ height: 80px;
5
+ width: 100%;
6
+ max-width: 100%;
7
+ overflow-x: auto;
8
+ position: relative;
9
+ display: flex;
10
+ }
11
+
12
+ .timeline-wrapper {
13
+ position: absolute;
14
+ height: 100%;
15
+ }
@@ -0,0 +1,116 @@
1
+ import React, { useEffect, useMemo, useRef } from 'react';
2
+ import TickTimeCollectionDisplay from './TickTimeCollectionDisplay';
3
+ import VaLueLineCanvas from './VaLueLineCanvas';
4
+ import RangeSelectorCanvas from './RangeSelectorCanvas';
5
+ import { zoomLevelConfigurations } from './constants';
6
+
7
+ import './Timeline.css';
8
+
9
+ export interface TimelineProps {
10
+ duration: number; // duration in seconds
11
+ value: number; // value in seconds
12
+ zoomLevel?: number; //0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
13
+ className?: string;
14
+ selectedRange?: number[];
15
+ withTimeBlocks?: boolean;
16
+ onChange?: (value: number) => void;
17
+ onRangeChange?: (value: number[]) => void;
18
+ }
19
+
20
+ export type ZoomContextType = {
21
+ blockOffset: number;
22
+ pixelsInSecond: number;
23
+ };
24
+ export const ZoomContext = React.createContext<ZoomContextType>({
25
+ blockOffset: 0,
26
+ pixelsInSecond: 0,
27
+ });
28
+
29
+ export const Timeline: React.FC<TimelineProps> = ({
30
+ duration,
31
+ value,
32
+ zoomLevel = 0,
33
+ selectedRange = [],
34
+ withTimeBlocks = true,
35
+ onChange = () => {},
36
+ onRangeChange = () => {},
37
+ className = '',
38
+ }) => {
39
+ const timeLineContainerRef = useRef(null);
40
+
41
+ let zoomLevelValue = zoomLevel ? zoomLevel : 0;
42
+ if (zoomLevelValue < 0 || zoomLevelValue >= zoomLevelConfigurations.length) {
43
+ console.warn('Invalid value for property zoomLevel.');
44
+ zoomLevelValue = 0;
45
+ }
46
+
47
+ if (value < 0 || value > duration) {
48
+ console.warn('Invalid value.');
49
+ }
50
+
51
+ if (!(selectedRange.length === 0 || selectedRange.length === 2)) {
52
+ selectedRange = [];
53
+ console.warn('The selected range must contain only two values.');
54
+ }
55
+
56
+ if (
57
+ selectedRange.length === 2 &&
58
+ !(
59
+ 0 <= selectedRange[0] &&
60
+ selectedRange[0] < selectedRange[1] &&
61
+ selectedRange[1] <= duration
62
+ )
63
+ ) {
64
+ selectedRange = [];
65
+ console.warn('The selected range is inconsistent.');
66
+ }
67
+
68
+ const zoomParams = useMemo(() => {
69
+ return {
70
+ blockOffset: zoomLevelConfigurations[zoomLevelValue][0],
71
+ pixelsInSecond: zoomLevelConfigurations[zoomLevelValue][1],
72
+ };
73
+ }, [zoomLevelValue]);
74
+
75
+ let blockStartingTimes = [0];
76
+ const blockCounts: number = Math.ceil(duration / zoomParams.blockOffset);
77
+ for (let i: number = 1; i < blockCounts; i++) {
78
+ blockStartingTimes.push(
79
+ blockStartingTimes[blockStartingTimes.length - 1] +
80
+ zoomParams.blockOffset,
81
+ );
82
+ }
83
+
84
+ useEffect(() => {
85
+ const timeLineWrapper: HTMLElement = timeLineContainerRef.current!;
86
+ const scrollPosition: number = value * zoomParams.pixelsInSecond - 300;
87
+ timeLineWrapper.scrollLeft = Math.max(0, scrollPosition);
88
+ }, [value, zoomParams]);
89
+
90
+ return (
91
+ <div
92
+ ref={timeLineContainerRef}
93
+ className={`timeline-container ${className}`}
94
+ >
95
+ <div
96
+ className={'timeline-wrapper'}
97
+ style={{ width: duration * zoomParams.pixelsInSecond + 'px' }}
98
+ >
99
+ <ZoomContext.Provider value={zoomParams}>
100
+ <VaLueLineCanvas
101
+ blockStartingTimes={withTimeBlocks ? blockStartingTimes : []}
102
+ value={value}
103
+ />
104
+ <RangeSelectorCanvas
105
+ selectedRange={selectedRange}
106
+ onChange={onChange}
107
+ onRangeChange={onRangeChange}
108
+ />
109
+ {withTimeBlocks && (
110
+ <TickTimeCollectionDisplay tickTimes={blockStartingTimes} />
111
+ )}
112
+ </ZoomContext.Provider>
113
+ </div>
114
+ </div>
115
+ );
116
+ };
@@ -1,123 +1 @@
1
- import React from 'react';
2
- import styled from 'styled-components';
3
- import { useEffect, useMemo, useRef } from 'react';
4
- import TickTimeCollectionDisplay from './TickTimeCollectionDisplay';
5
- import VaLueLineCanvas from './VaLueLineCanvas';
6
- import RangeSelectorCanvas from './RangeSelectorCanvas';
7
- import { zoomLevelConfigurations } from './constants';
8
-
9
- const TimelineContainer = styled.div`
10
- background-color: #f0f0f0;
11
- border: 1px solid #c9c9c9;
12
- height: 80px;
13
- width: 100%;
14
- max-width: 100%;
15
- overflow-x: auto;
16
- position: relative;
17
- display: flex;
18
- `;
19
- const TimelineWrapper = styled.div`
20
- position: absolute;
21
- height: 100%;
22
- `;
23
-
24
- export interface TimelineProps {
25
- duration: number;
26
- value: number;
27
- zoomLevel?: number; //0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
28
- className?: string;
29
- selectedRange?: number[];
30
- onChange?: (value: number) => void;
31
- onRangeChange?: (value: number[]) => void;
32
- }
33
-
34
- export type ZoomContextType = {
35
- blockOffset: number;
36
- pixelsInSecond: number;
37
- };
38
- export const ZoomContext = React.createContext<ZoomContextType>({
39
- blockOffset: 0,
40
- pixelsInSecond: 0,
41
- });
42
-
43
- export const Timeline: React.FC<TimelineProps> = ({
44
- duration,
45
- value,
46
- zoomLevel = 0,
47
- selectedRange = [],
48
- onChange = () => {},
49
- onRangeChange = () => {},
50
- className = '',
51
- }) => {
52
- const timeLineContainerRef = useRef(null);
53
-
54
- let zoomLevelValue = zoomLevel ? zoomLevel : 0;
55
- if (zoomLevelValue < 0 || zoomLevelValue >= zoomLevelConfigurations.length) {
56
- console.warn('Invalid value for property zoomLevel.');
57
- zoomLevelValue = 0;
58
- }
59
-
60
- if (value < 0 || value > duration) {
61
- console.warn('Invalid value.');
62
- }
63
-
64
- if (!(selectedRange.length === 0 || selectedRange.length === 2)) {
65
- selectedRange = [];
66
- console.warn('The selected range must contain only two values.');
67
- }
68
-
69
- if (
70
- selectedRange.length === 2 &&
71
- !(
72
- 0 <= selectedRange[0] &&
73
- selectedRange[0] < selectedRange[1] &&
74
- selectedRange[1] <= duration
75
- )
76
- ) {
77
- selectedRange = [];
78
- console.warn('The selected range is inconsistent.');
79
- }
80
-
81
- const zoomParams = useMemo(() => {
82
- return {
83
- blockOffset: zoomLevelConfigurations[zoomLevelValue][0],
84
- pixelsInSecond: zoomLevelConfigurations[zoomLevelValue][1],
85
- };
86
- }, [zoomLevelValue]);
87
-
88
- let blockStartingTimes = [0];
89
- const blockCounts: number = Math.ceil(duration / zoomParams.blockOffset);
90
- for (let i: number = 1; i < blockCounts; i++) {
91
- blockStartingTimes.push(
92
- blockStartingTimes[blockStartingTimes.length - 1] +
93
- zoomParams.blockOffset,
94
- );
95
- }
96
-
97
- useEffect(() => {
98
- const timeLineWrapper: HTMLElement = timeLineContainerRef.current!;
99
- const scrollPosition: number = value * zoomParams.pixelsInSecond - 300;
100
- timeLineWrapper.scrollLeft = Math.max(0, scrollPosition);
101
- }, [value, zoomParams]);
102
-
103
- return (
104
- <TimelineContainer ref={timeLineContainerRef} className={className}>
105
- <TimelineWrapper
106
- style={{ width: duration * zoomParams.pixelsInSecond + 'px' }}
107
- >
108
- <ZoomContext.Provider value={zoomParams}>
109
- <VaLueLineCanvas
110
- blockStartingTimes={blockStartingTimes}
111
- value={value}
112
- />
113
- <RangeSelectorCanvas
114
- selectedRange={selectedRange}
115
- onChange={onChange}
116
- onRangeChange={onRangeChange}
117
- />
118
- <TickTimeCollectionDisplay tickTimes={blockStartingTimes} />
119
- </ZoomContext.Provider>
120
- </TimelineWrapper>
121
- </TimelineContainer>
122
- );
123
- };
1
+ export * from './Timeline';
@@ -0,0 +1,3 @@
1
+ #storybook-root .this-class-redefines-values {
2
+ background-color: transparent;
3
+ }
@@ -4,6 +4,8 @@ import { Timeline, TimelineProps } from '../components/timeline';
4
4
  import { Meta, StoryFn } from '@storybook/react';
5
5
  import styled from 'styled-components';
6
6
 
7
+ import './timeline.stories.custom.css';
8
+
7
9
  const StyledTimeline = styled(Timeline)`
8
10
  .media-timeline-value-line {
9
11
  background-color: red;
@@ -29,6 +31,7 @@ Default.args = {
29
31
  value: 301,
30
32
  zoomLevel: 0,
31
33
  };
34
+
32
35
  export const WithSelectedRange = Template.bind({});
33
36
  WithSelectedRange.args = {
34
37
  duration: 305,
@@ -36,3 +39,19 @@ WithSelectedRange.args = {
36
39
  zoomLevel: 0,
37
40
  selectedRange: [20, 30],
38
41
  };
42
+
43
+ export const WithCustomClassName = Template.bind({});
44
+ WithCustomClassName.args = {
45
+ duration: 305,
46
+ value: 31,
47
+ zoomLevel: 0,
48
+ className: 'this-class-redefines-values',
49
+ };
50
+
51
+ export const WithOutTimeBlocks = Template.bind({});
52
+ WithOutTimeBlocks.args = {
53
+ duration: 305,
54
+ value: 31,
55
+ zoomLevel: 0,
56
+ withTimeBlocks: false,
57
+ };