@ldelia/react-media 0.2.0 → 0.2.2
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/dist/components/__tests__/timeline/timeline.test.d.ts +1 -0
- package/dist/components/__tests__/timeline/timeline.test.js +27 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +17 -0
- package/dist/components/timeline/RangeSelectorCanvas.d.ts +8 -0
- package/dist/components/timeline/RangeSelectorCanvas.js +133 -0
- package/dist/components/timeline/TickTime.d.ts +7 -0
- package/dist/components/timeline/TickTime.js +31 -0
- package/dist/components/timeline/TickTimeCollectionDisplay.d.ts +6 -0
- package/dist/components/timeline/TickTimeCollectionDisplay.js +24 -0
- package/dist/components/timeline/VaLueLineCanvas.d.ts +7 -0
- package/dist/components/timeline/VaLueLineCanvas.js +69 -0
- package/dist/components/timeline/constants.d.ts +1 -0
- package/dist/components/timeline/constants.js +16 -0
- package/dist/components/timeline/index.d.ts +17 -0
- package/dist/components/timeline/index.js +77 -0
- package/dist/components/timeline/utils/utils.d.ts +3 -0
- package/dist/components/timeline/utils/utils.js +12 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/reportWebVitals.d.ts +3 -0
- package/dist/reportWebVitals.js +37 -0
- package/dist/setupTests.d.ts +1 -0
- package/dist/setupTests.js +7 -0
- package/dist/stories/Button.d.ts +29 -0
- package/dist/stories/Button.js +30 -0
- package/dist/stories/Button.stories.js +47 -0
- package/dist/stories/timeline.stories.d.ts +5 -0
- package/dist/stories/timeline.stories.js +37 -0
- package/package.json +4 -2
- package/src/components/__tests__/timeline/timeline.test.tsx +1 -1
- package/src/components/timeline/index.tsx +1 -3
- package/src/stories/timeline.stories.tsx +1 -1
- package/tsconfig.json +8 -21
- package/src/stories/Button.stories.ts +0 -52
- package/src/stories/Button.tsx +0 -52
- package/src/stories/button.css +0 -30
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
const client_1 = require("react-dom/client");
|
|
8
|
+
const timeline_1 = __importDefault(require("../../timeline"));
|
|
9
|
+
describe('Timeline', () => {
|
|
10
|
+
let props;
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
props = {
|
|
13
|
+
duration: 300,
|
|
14
|
+
value: 15,
|
|
15
|
+
onChange: jest.fn(),
|
|
16
|
+
onRangeChange: jest.fn(),
|
|
17
|
+
zoomLevel: 0,
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
describe('render()', () => {
|
|
21
|
+
it('renders a timeline', () => {
|
|
22
|
+
const rootElement = document.createElement('div');
|
|
23
|
+
const root = (0, client_1.createRoot)(rootElement);
|
|
24
|
+
root.render(react_1.default.createElement(timeline_1.default, Object.assign({}, props)));
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './timeline';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./timeline"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface RangeSelectorCanvasProps {
|
|
3
|
+
selectedRange: number[];
|
|
4
|
+
onChange: (value: number) => void;
|
|
5
|
+
onRangeChange: (value: number[]) => void;
|
|
6
|
+
}
|
|
7
|
+
declare const _default: React.NamedExoticComponent<RangeSelectorCanvasProps>;
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
8
|
+
const index_1 = require("./index");
|
|
9
|
+
const react_2 = require("react");
|
|
10
|
+
const utils_1 = require("./utils/utils");
|
|
11
|
+
const OverlayCanvas = styled_components_1.default.canvas `
|
|
12
|
+
position: absolute;
|
|
13
|
+
top: 0;
|
|
14
|
+
left: 0;
|
|
15
|
+
width: 100%;
|
|
16
|
+
height: 100%;
|
|
17
|
+
color: cadetblue;
|
|
18
|
+
`;
|
|
19
|
+
const RangeSelectorCanvas = ({ selectedRange, onChange, onRangeChange, }) => {
|
|
20
|
+
const canvasRef = (0, react_2.useRef)(null);
|
|
21
|
+
const zoomContextValue = (0, react_2.useContext)(index_1.ZoomContext);
|
|
22
|
+
let isSelectingRange = false;
|
|
23
|
+
let selectedRangeInPixels = (0, react_2.useMemo)(() => [], []);
|
|
24
|
+
if (selectedRange.length === 2) {
|
|
25
|
+
selectedRangeInPixels = [
|
|
26
|
+
(0, utils_1.secondsToPixel)(zoomContextValue, selectedRange[0]),
|
|
27
|
+
(0, utils_1.secondsToPixel)(zoomContextValue, selectedRange[1]),
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
let lastValidSelectedRangeInPixels = [];
|
|
31
|
+
const getMousePointerPixelPosition = (e) => {
|
|
32
|
+
const canvas = canvasRef.current;
|
|
33
|
+
let rect = canvas.getBoundingClientRect();
|
|
34
|
+
return e.clientX - rect.left;
|
|
35
|
+
};
|
|
36
|
+
const drawRect = (pixelX0, pixelX1) => {
|
|
37
|
+
const canvas = canvasRef.current;
|
|
38
|
+
const context = canvas.getContext('2d');
|
|
39
|
+
context.globalAlpha = 0.3;
|
|
40
|
+
context.fillStyle = window
|
|
41
|
+
.getComputedStyle(canvas)
|
|
42
|
+
.getPropertyValue('color');
|
|
43
|
+
context.fillRect(pixelX0, 0, pixelX1 - pixelX0, context.canvas.height);
|
|
44
|
+
context.globalAlpha = 1.0;
|
|
45
|
+
};
|
|
46
|
+
const onCanvasDoubleClick = (e) => {
|
|
47
|
+
const x0 = getMousePointerPixelPosition(e);
|
|
48
|
+
onChange((0, utils_1.pixelToSeconds)(zoomContextValue, x0));
|
|
49
|
+
selectedRangeInPixels = lastValidSelectedRangeInPixels;
|
|
50
|
+
};
|
|
51
|
+
const isPixelNearSelectedRange = (x0) => {
|
|
52
|
+
if (selectedRangeInPixels.length === 2) {
|
|
53
|
+
const diff = Math.min(Math.abs(selectedRangeInPixels[0] - x0), Math.abs(selectedRangeInPixels[1] - x0));
|
|
54
|
+
return diff <= zoomContextValue.pixelsInSecond / 2;
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
};
|
|
58
|
+
const onCanvasMouseDown = (e) => {
|
|
59
|
+
const mouseCurrentPosition = getMousePointerPixelPosition(e);
|
|
60
|
+
if (!isPixelNearSelectedRange(mouseCurrentPosition)) {
|
|
61
|
+
// Keep track of the first position of the new range.
|
|
62
|
+
selectedRangeInPixels = [mouseCurrentPosition, mouseCurrentPosition];
|
|
63
|
+
}
|
|
64
|
+
isSelectingRange = true;
|
|
65
|
+
};
|
|
66
|
+
const onCanvasMouseMove = (e) => {
|
|
67
|
+
const canvas = canvasRef.current;
|
|
68
|
+
const context = canvas.getContext('2d');
|
|
69
|
+
const mouseCurrentPosition = getMousePointerPixelPosition(e);
|
|
70
|
+
if (selectedRangeInPixels.length === 2) {
|
|
71
|
+
const diff = Math.min(Math.abs(selectedRangeInPixels[0] - mouseCurrentPosition), Math.abs(selectedRangeInPixels[1] - mouseCurrentPosition));
|
|
72
|
+
// Change the mouse's cursor if it's near a selected range.
|
|
73
|
+
canvas.style.cursor =
|
|
74
|
+
diff <= zoomContextValue.pixelsInSecond / 2 ? 'col-resize' : 'default';
|
|
75
|
+
if (!isSelectingRange)
|
|
76
|
+
return;
|
|
77
|
+
if (mouseCurrentPosition < selectedRangeInPixels[0]) {
|
|
78
|
+
// The left side must be enlarged.
|
|
79
|
+
selectedRangeInPixels[0] = mouseCurrentPosition;
|
|
80
|
+
}
|
|
81
|
+
else if (mouseCurrentPosition > selectedRangeInPixels[1]) {
|
|
82
|
+
// The right side must be enlarged.
|
|
83
|
+
selectedRangeInPixels[1] = mouseCurrentPosition;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
const diffX0 = mouseCurrentPosition - selectedRangeInPixels[0];
|
|
87
|
+
const diffX1 = selectedRangeInPixels[1] - mouseCurrentPosition;
|
|
88
|
+
if (diffX0 < diffX1) {
|
|
89
|
+
// The left side must be shrunk.
|
|
90
|
+
selectedRangeInPixels[0] = mouseCurrentPosition;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// The right side must be shrunk.
|
|
94
|
+
selectedRangeInPixels[1] = mouseCurrentPosition;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
98
|
+
drawRect(selectedRangeInPixels[0], selectedRangeInPixels[1]);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const onCanvasMouseUp = (e) => {
|
|
102
|
+
if (selectedRangeInPixels.length !== 2)
|
|
103
|
+
return;
|
|
104
|
+
isSelectingRange = false;
|
|
105
|
+
const mouseCurrentPosition = getMousePointerPixelPosition(e);
|
|
106
|
+
const pixelRange = [
|
|
107
|
+
Math.min(selectedRangeInPixels[0], mouseCurrentPosition),
|
|
108
|
+
Math.max(selectedRangeInPixels[1], mouseCurrentPosition),
|
|
109
|
+
];
|
|
110
|
+
if (pixelRange[1] - pixelRange[0] <= 1) {
|
|
111
|
+
// It was just a click
|
|
112
|
+
selectedRangeInPixels = lastValidSelectedRangeInPixels;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
lastValidSelectedRangeInPixels = pixelRange;
|
|
116
|
+
onRangeChange([
|
|
117
|
+
(0, utils_1.pixelToSeconds)(zoomContextValue, pixelRange[0]),
|
|
118
|
+
(0, utils_1.pixelToSeconds)(zoomContextValue, pixelRange[1]),
|
|
119
|
+
]);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
(0, react_2.useEffect)(() => {
|
|
123
|
+
const canvas = canvasRef.current;
|
|
124
|
+
// https://stackoverflow.com/questions/8696631/canvas-drawings-like-lines-are-blurry
|
|
125
|
+
canvas.width = canvas.offsetWidth;
|
|
126
|
+
canvas.height = canvas.offsetHeight;
|
|
127
|
+
if (selectedRangeInPixels.length === 0)
|
|
128
|
+
return;
|
|
129
|
+
drawRect(selectedRangeInPixels[0], selectedRangeInPixels[1]);
|
|
130
|
+
}, [selectedRangeInPixels]);
|
|
131
|
+
return (react_1.default.createElement(OverlayCanvas, { ref: canvasRef, onDoubleClick: onCanvasDoubleClick, onMouseDown: onCanvasMouseDown, onMouseMove: onCanvasMouseMove, onMouseUp: onCanvasMouseUp, className: 'media-timeline-range-selector-canvas' }));
|
|
132
|
+
};
|
|
133
|
+
exports.default = react_1.default.memo(RangeSelectorCanvas);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
8
|
+
const TickTimeContainer = styled_components_1.default.span.attrs((props) => ({
|
|
9
|
+
style: {
|
|
10
|
+
left: props.left,
|
|
11
|
+
},
|
|
12
|
+
})) `
|
|
13
|
+
background: transparent;
|
|
14
|
+
position: absolute;
|
|
15
|
+
padding-left: 8px;
|
|
16
|
+
color: #646464;
|
|
17
|
+
user-select: none;
|
|
18
|
+
min-width: 20px;
|
|
19
|
+
max-width: 20px;
|
|
20
|
+
align-self: flex-end;
|
|
21
|
+
`;
|
|
22
|
+
const TickTime = ({ start, leftPosition }) => {
|
|
23
|
+
const minutes = Math.floor(start / 60);
|
|
24
|
+
let seconds = start - minutes * 60;
|
|
25
|
+
let secondsFormatted = seconds < 10 ? '0' + seconds : seconds.toString();
|
|
26
|
+
return (react_1.default.createElement(TickTimeContainer, { left: leftPosition, className: 'media-timeline-tick-time' },
|
|
27
|
+
minutes,
|
|
28
|
+
":",
|
|
29
|
+
secondsFormatted));
|
|
30
|
+
};
|
|
31
|
+
exports.default = TickTime;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
8
|
+
const TickTime_1 = __importDefault(require("./TickTime"));
|
|
9
|
+
const index_1 = require("./index");
|
|
10
|
+
const TickTimeCollectionDisplayContainer = styled_components_1.default.div `
|
|
11
|
+
position: absolute;
|
|
12
|
+
display: flex;
|
|
13
|
+
align-self: flex-end;
|
|
14
|
+
height: 100%;
|
|
15
|
+
`;
|
|
16
|
+
const TickTimeCollectionDisplay = ({ tickTimes = [], }) => {
|
|
17
|
+
return (react_1.default.createElement(index_1.ZoomContext.Consumer, null, (value) => {
|
|
18
|
+
return (react_1.default.createElement(TickTimeCollectionDisplayContainer, null, tickTimes.map((tickTimeValue, index) => {
|
|
19
|
+
const leftPosition = tickTimeValue * value.pixelsInSecond + 'px';
|
|
20
|
+
return (react_1.default.createElement(TickTime_1.default, { key: index, start: tickTimeValue, leftPosition: leftPosition }));
|
|
21
|
+
})));
|
|
22
|
+
}));
|
|
23
|
+
};
|
|
24
|
+
exports.default = TickTimeCollectionDisplay;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
8
|
+
const index_1 = require("./index");
|
|
9
|
+
const react_2 = require("react");
|
|
10
|
+
const utils_1 = require("./utils/utils");
|
|
11
|
+
const OverlayCanvas = styled_components_1.default.canvas `
|
|
12
|
+
position: absolute;
|
|
13
|
+
top: 0;
|
|
14
|
+
left: 0;
|
|
15
|
+
width: 100%;
|
|
16
|
+
height: 100%;
|
|
17
|
+
color: #c9c9c9;
|
|
18
|
+
`;
|
|
19
|
+
const ValueLine = styled_components_1.default.span `
|
|
20
|
+
position: absolute;
|
|
21
|
+
width: 1px;
|
|
22
|
+
height: 100%;
|
|
23
|
+
background-color: #575757;
|
|
24
|
+
`;
|
|
25
|
+
const VaLueLineCanvas = ({ blockStartingTimes = [], value, }) => {
|
|
26
|
+
const canvasRef = (0, react_2.useRef)(null);
|
|
27
|
+
const valueLineRef = (0, react_2.useRef)(null);
|
|
28
|
+
const zoomContextValue = (0, react_2.useContext)(index_1.ZoomContext);
|
|
29
|
+
const showBlocks = (0, react_2.useCallback)((canvas) => {
|
|
30
|
+
const blockHeight = 20;
|
|
31
|
+
const context = canvas.getContext('2d');
|
|
32
|
+
for (const blockStartingTime of blockStartingTimes) {
|
|
33
|
+
const x0Pixel = (0, utils_1.secondsToPixel)(zoomContextValue, blockStartingTime);
|
|
34
|
+
const x1Pixel = (0, utils_1.secondsToPixel)(zoomContextValue, blockStartingTime + zoomContextValue.blockOffset);
|
|
35
|
+
context.beginPath();
|
|
36
|
+
context.moveTo(x0Pixel, canvas.height);
|
|
37
|
+
context.lineTo(x0Pixel, canvas.height - blockHeight);
|
|
38
|
+
context.lineTo(x1Pixel, canvas.height - blockHeight);
|
|
39
|
+
context.lineTo(x1Pixel, canvas.height);
|
|
40
|
+
context.strokeStyle = window
|
|
41
|
+
.getComputedStyle(canvas)
|
|
42
|
+
.getPropertyValue('color');
|
|
43
|
+
context.stroke();
|
|
44
|
+
}
|
|
45
|
+
}, [blockStartingTimes, zoomContextValue]);
|
|
46
|
+
const showValueLine = (0, react_2.useCallback)(() => {
|
|
47
|
+
const linePosition = (0, utils_1.secondsToPixel)(zoomContextValue, value);
|
|
48
|
+
const valueLineElement = valueLineRef.current;
|
|
49
|
+
const elementWidthCSSProperty = window
|
|
50
|
+
.getComputedStyle(valueLineElement)
|
|
51
|
+
.getPropertyValue('width')
|
|
52
|
+
.replace(/[^-\d]/g, '');
|
|
53
|
+
const elementWidth = parseInt(elementWidthCSSProperty);
|
|
54
|
+
const linePositionAtValueLineMiddle = linePosition - elementWidth / 2;
|
|
55
|
+
valueLineElement.style.left = linePositionAtValueLineMiddle + 'px';
|
|
56
|
+
}, [value, zoomContextValue]);
|
|
57
|
+
(0, react_2.useEffect)(() => {
|
|
58
|
+
const canvas = canvasRef.current;
|
|
59
|
+
// https://stackoverflow.com/questions/8696631/canvas-drawings-like-lines-are-blurry
|
|
60
|
+
canvas.width = canvas.offsetWidth;
|
|
61
|
+
canvas.height = canvas.offsetHeight;
|
|
62
|
+
showBlocks(canvas);
|
|
63
|
+
showValueLine();
|
|
64
|
+
}, [showBlocks, showValueLine]);
|
|
65
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
66
|
+
react_1.default.createElement(OverlayCanvas, { ref: canvasRef, className: 'media-timeline-value-line-canvas' }),
|
|
67
|
+
react_1.default.createElement(ValueLine, { ref: valueLineRef, className: 'media-timeline-value-line' })));
|
|
68
|
+
};
|
|
69
|
+
exports.default = VaLueLineCanvas;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const zoomLevelConfigurations: number[][];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.zoomLevelConfigurations = void 0;
|
|
4
|
+
//[blockOffset, pixelsInSecond] when zoomLevel === 0, each block has an offset of 20 seconds, and each second has a width of 7px.
|
|
5
|
+
exports.zoomLevelConfigurations = [
|
|
6
|
+
[20, 7],
|
|
7
|
+
[10, 10],
|
|
8
|
+
[10, 15],
|
|
9
|
+
[5, 20],
|
|
10
|
+
[5, 25],
|
|
11
|
+
[2, 35],
|
|
12
|
+
[2, 50],
|
|
13
|
+
[1, 60],
|
|
14
|
+
[1, 75],
|
|
15
|
+
[1, 90],
|
|
16
|
+
];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface TimelineProps {
|
|
3
|
+
duration: number;
|
|
4
|
+
value: number;
|
|
5
|
+
zoomLevel?: number;
|
|
6
|
+
className?: string;
|
|
7
|
+
selectedRange?: number[];
|
|
8
|
+
onChange?: (value: number) => void;
|
|
9
|
+
onRangeChange?: (value: number[]) => void;
|
|
10
|
+
}
|
|
11
|
+
export type ZoomContextType = {
|
|
12
|
+
blockOffset: number;
|
|
13
|
+
pixelsInSecond: number;
|
|
14
|
+
};
|
|
15
|
+
export declare const ZoomContext: React.Context<ZoomContextType>;
|
|
16
|
+
declare const Timeline: React.FC<TimelineProps>;
|
|
17
|
+
export default Timeline;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ZoomContext = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
9
|
+
const react_2 = require("react");
|
|
10
|
+
const TickTimeCollectionDisplay_1 = __importDefault(require("./TickTimeCollectionDisplay"));
|
|
11
|
+
const VaLueLineCanvas_1 = __importDefault(require("./VaLueLineCanvas"));
|
|
12
|
+
const RangeSelectorCanvas_1 = __importDefault(require("./RangeSelectorCanvas"));
|
|
13
|
+
const constants_1 = require("./constants");
|
|
14
|
+
const TimelineContainer = styled_components_1.default.div `
|
|
15
|
+
background-color: #f0f0f0;
|
|
16
|
+
border: 1px solid #c9c9c9;
|
|
17
|
+
height: 80px;
|
|
18
|
+
width: 100%;
|
|
19
|
+
max-width: 100%;
|
|
20
|
+
overflow-x: auto;
|
|
21
|
+
position: relative;
|
|
22
|
+
display: flex;
|
|
23
|
+
`;
|
|
24
|
+
const TimelineWrapper = styled_components_1.default.div `
|
|
25
|
+
position: absolute;
|
|
26
|
+
height: 100%;
|
|
27
|
+
`;
|
|
28
|
+
exports.ZoomContext = react_1.default.createContext({
|
|
29
|
+
blockOffset: 0,
|
|
30
|
+
pixelsInSecond: 0,
|
|
31
|
+
});
|
|
32
|
+
const Timeline = ({ duration, value, zoomLevel = 0, selectedRange = [], onChange = () => { }, onRangeChange = () => { }, className = '', }) => {
|
|
33
|
+
const timeLineContainerRef = (0, react_2.useRef)(null);
|
|
34
|
+
let zoomLevelValue = zoomLevel ? zoomLevel : 0;
|
|
35
|
+
if (zoomLevelValue < 0 || zoomLevelValue >= constants_1.zoomLevelConfigurations.length) {
|
|
36
|
+
console.warn('Invalid value for property zoomLevel.');
|
|
37
|
+
zoomLevelValue = 0;
|
|
38
|
+
}
|
|
39
|
+
if (value < 0 || value > duration) {
|
|
40
|
+
console.warn('Invalid value.');
|
|
41
|
+
}
|
|
42
|
+
if (!(selectedRange.length === 0 || selectedRange.length === 2)) {
|
|
43
|
+
selectedRange = [];
|
|
44
|
+
console.warn('The selected range must contain only two values.');
|
|
45
|
+
}
|
|
46
|
+
if (selectedRange.length === 2 &&
|
|
47
|
+
!(0 <= selectedRange[0] &&
|
|
48
|
+
selectedRange[0] < selectedRange[1] &&
|
|
49
|
+
selectedRange[1] <= duration)) {
|
|
50
|
+
selectedRange = [];
|
|
51
|
+
console.warn('The selected range is inconsistent.');
|
|
52
|
+
}
|
|
53
|
+
const zoomParams = (0, react_2.useMemo)(() => {
|
|
54
|
+
return {
|
|
55
|
+
blockOffset: constants_1.zoomLevelConfigurations[zoomLevelValue][0],
|
|
56
|
+
pixelsInSecond: constants_1.zoomLevelConfigurations[zoomLevelValue][1],
|
|
57
|
+
};
|
|
58
|
+
}, [zoomLevelValue]);
|
|
59
|
+
let blockStartingTimes = [0];
|
|
60
|
+
const blockCounts = Math.ceil(duration / zoomParams.blockOffset);
|
|
61
|
+
for (let i = 1; i < blockCounts; i++) {
|
|
62
|
+
blockStartingTimes.push(blockStartingTimes[blockStartingTimes.length - 1] +
|
|
63
|
+
zoomParams.blockOffset);
|
|
64
|
+
}
|
|
65
|
+
(0, react_2.useEffect)(() => {
|
|
66
|
+
const timeLineWrapper = timeLineContainerRef.current;
|
|
67
|
+
const scrollPosition = value * zoomParams.pixelsInSecond - 300;
|
|
68
|
+
timeLineWrapper.scrollLeft = Math.max(0, scrollPosition);
|
|
69
|
+
}, [value, zoomParams]);
|
|
70
|
+
return (react_1.default.createElement(TimelineContainer, { ref: timeLineContainerRef, className: className },
|
|
71
|
+
react_1.default.createElement(TimelineWrapper, { style: { width: duration * zoomParams.pixelsInSecond + 'px' } },
|
|
72
|
+
react_1.default.createElement(exports.ZoomContext.Provider, { value: zoomParams },
|
|
73
|
+
react_1.default.createElement(VaLueLineCanvas_1.default, { blockStartingTimes: blockStartingTimes, value: value }),
|
|
74
|
+
react_1.default.createElement(RangeSelectorCanvas_1.default, { selectedRange: selectedRange, onChange: onChange, onRangeChange: onRangeChange }),
|
|
75
|
+
react_1.default.createElement(TickTimeCollectionDisplay_1.default, { tickTimes: blockStartingTimes })))));
|
|
76
|
+
};
|
|
77
|
+
exports.default = Timeline;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pixelToSeconds = exports.secondsToPixel = void 0;
|
|
4
|
+
const secondsToPixel = (zoomContextValue, seconds) => {
|
|
5
|
+
return zoomContextValue.pixelsInSecond * seconds;
|
|
6
|
+
};
|
|
7
|
+
exports.secondsToPixel = secondsToPixel;
|
|
8
|
+
const pixelToSeconds = (zoomContextValue, pixel) => {
|
|
9
|
+
const seconds = pixel / zoomContextValue.pixelsInSecond;
|
|
10
|
+
return Math.round((seconds + Number.EPSILON) * 100) / 100;
|
|
11
|
+
};
|
|
12
|
+
exports.pixelToSeconds = pixelToSeconds;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./components"), exports);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const reportWebVitals = (onPerfEntry) => {
|
|
27
|
+
if (onPerfEntry && onPerfEntry instanceof Function) {
|
|
28
|
+
Promise.resolve().then(() => __importStar(require('web-vitals'))).then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
|
|
29
|
+
getCLS(onPerfEntry);
|
|
30
|
+
getFID(onPerfEntry);
|
|
31
|
+
getFCP(onPerfEntry);
|
|
32
|
+
getLCP(onPerfEntry);
|
|
33
|
+
getTTFB(onPerfEntry);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.default = reportWebVitals;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
|
4
|
+
// allows you to do things like:
|
|
5
|
+
// expect(element).toHaveTextContent(/react/i)
|
|
6
|
+
// learn more: https://github.com/testing-library/jest-dom
|
|
7
|
+
require("@testing-library/jest-dom");
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './button.css';
|
|
3
|
+
interface ButtonProps {
|
|
4
|
+
/**
|
|
5
|
+
* Is this the principal call to action on the page?
|
|
6
|
+
*/
|
|
7
|
+
primary?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* What background color to use
|
|
10
|
+
*/
|
|
11
|
+
backgroundColor?: string;
|
|
12
|
+
/**
|
|
13
|
+
* How large should the button be?
|
|
14
|
+
*/
|
|
15
|
+
size?: 'small' | 'medium' | 'large';
|
|
16
|
+
/**
|
|
17
|
+
* Button contents
|
|
18
|
+
*/
|
|
19
|
+
label: string;
|
|
20
|
+
/**
|
|
21
|
+
* Optional click handler
|
|
22
|
+
*/
|
|
23
|
+
onClick?: () => void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Primary UI component for user interaction
|
|
27
|
+
*/
|
|
28
|
+
export declare const Button: ({ primary, size, backgroundColor, label, ...props }: ButtonProps) => React.JSX.Element;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Button = void 0;
|
|
18
|
+
const react_1 = __importDefault(require("react"));
|
|
19
|
+
require("./button.css");
|
|
20
|
+
/**
|
|
21
|
+
* Primary UI component for user interaction
|
|
22
|
+
*/
|
|
23
|
+
const Button = (_a) => {
|
|
24
|
+
var { primary = false, size = 'medium', backgroundColor, label } = _a, props = __rest(_a, ["primary", "size", "backgroundColor", "label"]);
|
|
25
|
+
const mode = primary
|
|
26
|
+
? 'storybook-button--primary'
|
|
27
|
+
: 'storybook-button--secondary';
|
|
28
|
+
return (react_1.default.createElement("button", Object.assign({ type: "button", className: ['storybook-button', `storybook-button--${size}`, mode].join(' '), style: { backgroundColor } }, props), label));
|
|
29
|
+
};
|
|
30
|
+
exports.Button = Button;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Small = exports.Large = exports.Secondary = exports.Primary = void 0;
|
|
4
|
+
const test_1 = require("@storybook/test");
|
|
5
|
+
const Button_1 = require("./Button");
|
|
6
|
+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
|
|
7
|
+
const meta = {
|
|
8
|
+
title: 'Example/Button',
|
|
9
|
+
component: Button_1.Button,
|
|
10
|
+
parameters: {
|
|
11
|
+
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
|
|
12
|
+
layout: 'centered',
|
|
13
|
+
},
|
|
14
|
+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
15
|
+
tags: ['autodocs'],
|
|
16
|
+
// More on argTypes: https://storybook.js.org/docs/api/argtypes
|
|
17
|
+
argTypes: {
|
|
18
|
+
backgroundColor: { control: 'color' },
|
|
19
|
+
},
|
|
20
|
+
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
|
|
21
|
+
args: { onClick: (0, test_1.fn)() },
|
|
22
|
+
};
|
|
23
|
+
exports.default = meta;
|
|
24
|
+
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
|
25
|
+
exports.Primary = {
|
|
26
|
+
args: {
|
|
27
|
+
primary: true,
|
|
28
|
+
label: 'Button',
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
exports.Secondary = {
|
|
32
|
+
args: {
|
|
33
|
+
label: 'Button',
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
exports.Large = {
|
|
37
|
+
args: {
|
|
38
|
+
size: 'large',
|
|
39
|
+
label: 'Button',
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
exports.Small = {
|
|
43
|
+
args: {
|
|
44
|
+
size: 'small',
|
|
45
|
+
label: 'Button',
|
|
46
|
+
},
|
|
47
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TimelineProps } from '../components/timeline';
|
|
2
|
+
declare const _default: import("@storybook/types").ComponentAnnotations<import("@storybook/react/dist/types-bf5e6555").R, import("@storybook/types").Args>;
|
|
3
|
+
export default _default;
|
|
4
|
+
export declare const Default: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-bf5e6555").R, TimelineProps>;
|
|
5
|
+
export declare const WithSelectedRange: import("@storybook/types").AnnotatedStoryFn<import("@storybook/react/dist/types-bf5e6555").R, TimelineProps>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WithSelectedRange = exports.Default = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const timeline_1 = __importDefault(require("../components/timeline"));
|
|
9
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
10
|
+
const StyledTimeline = (0, styled_components_1.default)(timeline_1.default) `
|
|
11
|
+
.media-timeline-value-line {
|
|
12
|
+
background-color: red;
|
|
13
|
+
width: 5px;
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
exports.default = {
|
|
17
|
+
title: 'Timeline',
|
|
18
|
+
component: timeline_1.default,
|
|
19
|
+
argTypes: {
|
|
20
|
+
onChange: { action: 'changed' },
|
|
21
|
+
onRangeChange: { action: 'range changed' },
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
const Template = (args) => (react_1.default.createElement(StyledTimeline, Object.assign({}, args)));
|
|
25
|
+
exports.Default = Template.bind({});
|
|
26
|
+
exports.Default.args = {
|
|
27
|
+
duration: 305,
|
|
28
|
+
value: 301,
|
|
29
|
+
zoomLevel: 0,
|
|
30
|
+
};
|
|
31
|
+
exports.WithSelectedRange = Template.bind({});
|
|
32
|
+
exports.WithSelectedRange.args = {
|
|
33
|
+
duration: 305,
|
|
34
|
+
value: 31,
|
|
35
|
+
zoomLevel: 0,
|
|
36
|
+
selectedRange: [20, 30],
|
|
37
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ldelia/react-media",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "A React components collection for media-related features.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"keywords": [
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
"author": "Lisandro Delia",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"bugs": "https://github.com/ldelia/react-media/issues",
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
13
15
|
"dependencies": {
|
|
14
16
|
"react": "^18.3.1",
|
|
15
17
|
"react-dom": "^18.3.1",
|
|
@@ -20,7 +22,7 @@
|
|
|
20
22
|
},
|
|
21
23
|
"scripts": {
|
|
22
24
|
"start": "react-scripts start",
|
|
23
|
-
"build": "
|
|
25
|
+
"build": "tsc",
|
|
24
26
|
"test": "react-scripts test",
|
|
25
27
|
"format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,css,scss,md}\"",
|
|
26
28
|
"eject": "react-scripts eject",
|
|
@@ -40,7 +40,7 @@ export const ZoomContext = React.createContext<ZoomContextType>({
|
|
|
40
40
|
pixelsInSecond: 0,
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
const Timeline: React.FC<TimelineProps> = ({
|
|
43
|
+
export const Timeline: React.FC<TimelineProps> = ({
|
|
44
44
|
duration,
|
|
45
45
|
value,
|
|
46
46
|
zoomLevel = 0,
|
|
@@ -121,5 +121,3 @@ const Timeline: React.FC<TimelineProps> = ({
|
|
|
121
121
|
</TimelineContainer>
|
|
122
122
|
);
|
|
123
123
|
};
|
|
124
|
-
|
|
125
|
-
export default Timeline;
|
package/tsconfig.json
CHANGED
|
@@ -1,26 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"esnext"
|
|
8
|
-
],
|
|
9
|
-
"allowJs": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"allowSyntheticDefaultImports": true,
|
|
3
|
+
"target": "ES6",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"outDir": "./dist",
|
|
13
7
|
"strict": true,
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"moduleResolution": "node",
|
|
18
|
-
"resolveJsonModule": true,
|
|
19
|
-
"isolatedModules": true,
|
|
20
|
-
"noEmit": true,
|
|
21
|
-
"jsx": "react-jsx"
|
|
8
|
+
"jsx": "react",
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true
|
|
22
11
|
},
|
|
23
|
-
"include": [
|
|
24
|
-
"src"
|
|
25
|
-
]
|
|
12
|
+
"include": ["src"]
|
|
26
13
|
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { fn } from '@storybook/test';
|
|
3
|
-
import { Button } from './Button';
|
|
4
|
-
|
|
5
|
-
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
|
|
6
|
-
const meta = {
|
|
7
|
-
title: 'Example/Button',
|
|
8
|
-
component: Button,
|
|
9
|
-
parameters: {
|
|
10
|
-
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
|
|
11
|
-
layout: 'centered',
|
|
12
|
-
},
|
|
13
|
-
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
14
|
-
tags: ['autodocs'],
|
|
15
|
-
// More on argTypes: https://storybook.js.org/docs/api/argtypes
|
|
16
|
-
argTypes: {
|
|
17
|
-
backgroundColor: { control: 'color' },
|
|
18
|
-
},
|
|
19
|
-
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
|
|
20
|
-
args: { onClick: fn() },
|
|
21
|
-
} satisfies Meta<typeof Button>;
|
|
22
|
-
|
|
23
|
-
export default meta;
|
|
24
|
-
type Story = StoryObj<typeof meta>;
|
|
25
|
-
|
|
26
|
-
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
|
27
|
-
export const Primary: Story = {
|
|
28
|
-
args: {
|
|
29
|
-
primary: true,
|
|
30
|
-
label: 'Button',
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const Secondary: Story = {
|
|
35
|
-
args: {
|
|
36
|
-
label: 'Button',
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const Large: Story = {
|
|
41
|
-
args: {
|
|
42
|
-
size: 'large',
|
|
43
|
-
label: 'Button',
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const Small: Story = {
|
|
48
|
-
args: {
|
|
49
|
-
size: 'small',
|
|
50
|
-
label: 'Button',
|
|
51
|
-
},
|
|
52
|
-
};
|
package/src/stories/Button.tsx
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import './button.css';
|
|
3
|
-
|
|
4
|
-
interface ButtonProps {
|
|
5
|
-
/**
|
|
6
|
-
* Is this the principal call to action on the page?
|
|
7
|
-
*/
|
|
8
|
-
primary?: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* What background color to use
|
|
11
|
-
*/
|
|
12
|
-
backgroundColor?: string;
|
|
13
|
-
/**
|
|
14
|
-
* How large should the button be?
|
|
15
|
-
*/
|
|
16
|
-
size?: 'small' | 'medium' | 'large';
|
|
17
|
-
/**
|
|
18
|
-
* Button contents
|
|
19
|
-
*/
|
|
20
|
-
label: string;
|
|
21
|
-
/**
|
|
22
|
-
* Optional click handler
|
|
23
|
-
*/
|
|
24
|
-
onClick?: () => void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Primary UI component for user interaction
|
|
29
|
-
*/
|
|
30
|
-
export const Button = ({
|
|
31
|
-
primary = false,
|
|
32
|
-
size = 'medium',
|
|
33
|
-
backgroundColor,
|
|
34
|
-
label,
|
|
35
|
-
...props
|
|
36
|
-
}: ButtonProps) => {
|
|
37
|
-
const mode = primary
|
|
38
|
-
? 'storybook-button--primary'
|
|
39
|
-
: 'storybook-button--secondary';
|
|
40
|
-
return (
|
|
41
|
-
<button
|
|
42
|
-
type="button"
|
|
43
|
-
className={['storybook-button', `storybook-button--${size}`, mode].join(
|
|
44
|
-
' ',
|
|
45
|
-
)}
|
|
46
|
-
style={{ backgroundColor }}
|
|
47
|
-
{...props}
|
|
48
|
-
>
|
|
49
|
-
{label}
|
|
50
|
-
</button>
|
|
51
|
-
);
|
|
52
|
-
};
|
package/src/stories/button.css
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
.storybook-button {
|
|
2
|
-
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
|
3
|
-
font-weight: 700;
|
|
4
|
-
border: 0;
|
|
5
|
-
border-radius: 3em;
|
|
6
|
-
cursor: pointer;
|
|
7
|
-
display: inline-block;
|
|
8
|
-
line-height: 1;
|
|
9
|
-
}
|
|
10
|
-
.storybook-button--primary {
|
|
11
|
-
color: white;
|
|
12
|
-
background-color: #1ea7fd;
|
|
13
|
-
}
|
|
14
|
-
.storybook-button--secondary {
|
|
15
|
-
color: #333;
|
|
16
|
-
background-color: transparent;
|
|
17
|
-
box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 0px 1px inset;
|
|
18
|
-
}
|
|
19
|
-
.storybook-button--small {
|
|
20
|
-
font-size: 12px;
|
|
21
|
-
padding: 10px 16px;
|
|
22
|
-
}
|
|
23
|
-
.storybook-button--medium {
|
|
24
|
-
font-size: 14px;
|
|
25
|
-
padding: 11px 20px;
|
|
26
|
-
}
|
|
27
|
-
.storybook-button--large {
|
|
28
|
-
font-size: 16px;
|
|
29
|
-
padding: 12px 24px;
|
|
30
|
-
}
|