@soul-refiner/design-system 1.0.6 → 1.1.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.
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const useClickOutside: (ref: React.Ref<HTMLElement>, cb: (...args: any[]) => unknown) => void;
@@ -0,0 +1,10 @@
1
+ 'use client';
2
+ import { useEventListener } from './event-listenter';
3
+ export const useClickOutside = (ref, cb) => {
4
+ useEventListener('click', (e) => {
5
+ if (ref?.current == null ||
6
+ ref?.current?.contains(e.target))
7
+ return;
8
+ cb(e);
9
+ }, document);
10
+ };
@@ -0,0 +1 @@
1
+ export declare const useEventListener: (eventType: string, callback: (...args: any[]) => unknown, element?: Window & typeof globalThis) => void;
@@ -0,0 +1,15 @@
1
+ 'use client';
2
+ import React from 'react';
3
+ export const useEventListener = (eventType, callback, element = window) => {
4
+ const callbackRef = React.useRef(callback);
5
+ React.useEffect(() => {
6
+ callbackRef.current = callback;
7
+ }, [callback]);
8
+ React.useEffect(() => {
9
+ if (element == null)
10
+ return;
11
+ const handler = (e) => callbackRef.current(e);
12
+ element.addEventListener(eventType, handler);
13
+ return () => element.removeEventListener(eventType, handler);
14
+ }, [eventType, element]);
15
+ };
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const useHover: (ref: React.Ref<HTMLElement>) => boolean;
@@ -0,0 +1,9 @@
1
+ 'use client';
2
+ import React from 'react';
3
+ import { useEventListener } from './event-listenter';
4
+ export const useHover = (ref) => {
5
+ const [hovered, setHovered] = React.useState(false);
6
+ useEventListener('mouseover', () => setHovered(true), ref?.current);
7
+ useEventListener('mouseout', () => setHovered(false), ref?.current);
8
+ return hovered;
9
+ };
@@ -0,0 +1,4 @@
1
+ export { useClickOutside } from './click-outside';
2
+ export { useEventListener } from './event-listenter';
3
+ export { useHover } from './hover';
4
+ export { useWindowSize } from './window-size';
@@ -0,0 +1,4 @@
1
+ export { useClickOutside } from './click-outside';
2
+ export { useEventListener } from './event-listenter';
3
+ export { useHover } from './hover';
4
+ export { useWindowSize } from './window-size';
@@ -0,0 +1,4 @@
1
+ export declare const useWindowSize: () => {
2
+ width: number;
3
+ height: number;
4
+ };
@@ -0,0 +1,13 @@
1
+ 'use client';
2
+ import React from 'react';
3
+ import { useEventListener } from './event-listenter';
4
+ export const useWindowSize = () => {
5
+ const [windowSize, setWindowSize] = React.useState({
6
+ width: window.innerWidth,
7
+ height: window.innerHeight,
8
+ });
9
+ useEventListener('resize', () => {
10
+ setWindowSize({ width: window.innerWidth, height: window.innerHeight });
11
+ });
12
+ return windowSize;
13
+ };
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ interface PlaylistItemProps {
3
+ duration: number;
4
+ onClick: () => void;
5
+ progress?: number;
6
+ shortDescription: string;
7
+ thumbnail: string;
8
+ title: string;
9
+ }
10
+ export declare const PlaylistItem: ({ duration, onClick, progress, shortDescription, thumbnail, title, }: PlaylistItemProps) => React.JSX.Element;
11
+ export {};
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import Image from 'next/image';
3
+ import styled from 'styled-components';
4
+ import { Box } from '../../atoms/box';
5
+ import { SecToDuration } from '../../atoms/seconds_to_duration';
6
+ import { P } from '../../atoms/typography';
7
+ import { PlaySolid } from '../../../icons/audio_video';
8
+ export const PlaylistItem = ({ duration, onClick, progress = 0, shortDescription, thumbnail, title, }) => {
9
+ return (React.createElement(Wrapper, { onClick: onClick },
10
+ React.createElement(PlaySolid, { color: "white", size: 16, sx: "position: absolute; left: 8px; bottom: 4px;" }),
11
+ React.createElement(Image, { alt: `thumbnail for ${title}`, height: 75, src: thumbnail, width: 133 }),
12
+ React.createElement(ProgressBar, { progressPercent: progress / duration }),
13
+ React.createElement(Box, { "$dir": "column", "$gap": 4, sx: "margin-left: 16px; margin-right: auto; flex: 0 1 auto; flex-basis: content;" },
14
+ React.createElement(P, { "$color": "grey-10", "$semiBold": true }, title),
15
+ React.createElement(P, { "$color": "grey-9", "$fontSize": 14, "$lineHeight": 20, "$textClampLines": 2, sx: "max-width: min(500px, 75%);" }, shortDescription)),
16
+ React.createElement(P, { "$color": "grey-8", "$fontSize": 14, "$lineHeight": 20, sx: "flex-shrink: 0;" },
17
+ React.createElement(SecToDuration, { seconds: duration }))));
18
+ };
19
+ const Wrapper = styled.div `
20
+ width: 100%;
21
+ flex: 0 1 auto;
22
+ display: flex;
23
+ align-items: center;
24
+ position: relative;
25
+ box-sizing: border-box;
26
+ cursor: pointer;
27
+ `;
28
+ const ProgressBar = ({ progressPercent }) => (React.createElement(ProgressBarSvg, { viewBox: "0 0 133 2", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
29
+ React.createElement("rect", { width: 133 * progressPercent, height: "2", fill: "var(--color-primary-blue-2)" }),
30
+ React.createElement("rect", { x: 133 * progressPercent, width: 133 - 133 * progressPercent, height: "2", fill: "var(--color-grey-8)" })));
31
+ const ProgressBarSvg = styled.svg `
32
+ width: 133px;
33
+ position: absolute;
34
+ bottom: 0px;
35
+ left: 0px;
36
+ `;
@@ -2,10 +2,11 @@ import React from 'react';
2
2
  interface PlaylistItemProps {
3
3
  duration: number;
4
4
  onClick: () => void;
5
+ playable?: boolean;
5
6
  progress?: number;
6
7
  shortDescription: string;
7
8
  thumbnail: string;
8
9
  title: string;
9
10
  }
10
- export declare const PlaylistItem: ({ duration, onClick, progress, shortDescription, thumbnail, title, }: PlaylistItemProps) => React.JSX.Element;
11
+ export declare const PlaylistItem: ({ duration, onClick, playable, progress, shortDescription, thumbnail, title, }: PlaylistItemProps) => React.JSX.Element;
11
12
  export {};
@@ -5,8 +5,8 @@ import { Box } from '../../atoms/box';
5
5
  import { SecToDuration } from '../../atoms/seconds_to_duration';
6
6
  import { P } from '../../atoms/typography';
7
7
  import { PlaySolid } from '../../../icons/audio_video';
8
- export const PlaylistItem = ({ duration, onClick, progress = 0, shortDescription, thumbnail, title, }) => {
9
- return (React.createElement(Wrapper, { onClick: onClick },
8
+ export const PlaylistItem = ({ duration, onClick, playable, progress = 0, shortDescription, thumbnail, title, }) => {
9
+ return (React.createElement(Wrapper, { onClick: playable ? onClick : undefined, "$playable": playable },
10
10
  React.createElement(PlaySolid, { color: "white", size: 16, sx: "position: absolute; left: 8px; bottom: 4px;" }),
11
11
  React.createElement(Image, { alt: `thumbnail for ${title}`, height: 75, src: thumbnail, width: 133 }),
12
12
  React.createElement(ProgressBar, { progressPercent: progress / duration }),
@@ -24,6 +24,7 @@ const Wrapper = styled.div `
24
24
  position: relative;
25
25
  box-sizing: border-box;
26
26
  cursor: pointer;
27
+ ${({ $playable }) => $playable ? '' : 'pointer-events: none; cursor: initial;'}
27
28
  `;
28
29
  const ProgressBar = ({ progressPercent }) => (React.createElement(ProgressBarSvg, { viewBox: "0 0 133 2", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
29
30
  React.createElement("rect", { width: 133 * progressPercent, height: "2", fill: "var(--color-primary-blue-2)" }),
@@ -34,6 +34,10 @@ export interface VideoPlayerProps {
34
34
  * @param pip picture in picture is enabled
35
35
  */
36
36
  pip?: boolean;
37
+ /**
38
+ * @param playable whether the video can play
39
+ */
40
+ playable: boolean;
37
41
  /**
38
42
  * @param playlist the media items in the player
39
43
  */
@@ -55,5 +59,5 @@ export interface VideoPlayerProps {
55
59
  * ReactPlayer props reference -> https://www.npmjs.com/package/react-player#props
56
60
  * HLS Option props reference -> https://github.com/video-dev/hls.js/blob/master/docs/API.md#fine-tuning
57
61
  */
58
- export declare const VideoPlayer: ({ activeIndex, pip, playlist, onPipChange, onProgress, orientation, setMediaItem, subtitle, title, }: VideoPlayerProps) => React.JSX.Element | null;
62
+ export declare const VideoPlayer: ({ activeIndex, pip, playable, playlist, onPipChange, onProgress, orientation, setMediaItem, subtitle, title, }: VideoPlayerProps) => React.JSX.Element | null;
59
63
  export {};
@@ -6,12 +6,13 @@ import styled from 'styled-components';
6
6
  import { Box } from '../../atoms/box';
7
7
  import { H, P } from '../../atoms/typography';
8
8
  import { Button } from '../../actions/button';
9
+ import { LockCircle, PlaySolid } from '../../../icons';
9
10
  import { PlaylistItem } from './playlist-item';
10
11
  /**
11
12
  * ReactPlayer props reference -> https://www.npmjs.com/package/react-player#props
12
13
  * HLS Option props reference -> https://github.com/video-dev/hls.js/blob/master/docs/API.md#fine-tuning
13
14
  */
14
- export const VideoPlayer = ({ activeIndex, pip, playlist, onPipChange, onProgress, orientation, setMediaItem, subtitle, title, }) => {
15
+ export const VideoPlayer = ({ activeIndex, pip, playable, playlist, onPipChange, onProgress, orientation, setMediaItem, subtitle, title, }) => {
15
16
  const [showingAll, setShowingAll] = React.useState(false);
16
17
  const ref = React.useRef(null);
17
18
  const mediaItem = playlist?.[activeIndex];
@@ -25,11 +26,11 @@ export const VideoPlayer = ({ activeIndex, pip, playlist, onPipChange, onProgres
25
26
  if (!mediaItem)
26
27
  return null;
27
28
  return (React.createElement(Wrapper, { "$orientation": orientation },
28
- React.createElement(InnerWrapper, { "$orientation": orientation },
29
+ React.createElement(InnerWrapper, { "$orientation": orientation, "$playable": playable },
29
30
  orientation === 'vertical' && (React.createElement(Box, { "$dir": "column", "$gap": 4, sx: "margin: 24px;" },
30
31
  React.createElement(H, { as: "h2", "$bold": true, "$color": "white", "$fontSize": 28, "$lineHeight": 36 }, title),
31
32
  React.createElement(P, { as: "h3", "$bold": true, "$color": "grey-8" }, subtitle))),
32
- React.createElement(ReactPlayer, { config: {
33
+ React.createElement(ReactPlayer, { className: "player", config: {
33
34
  file: {
34
35
  attributes: {
35
36
  crossOrigin: 'true',
@@ -45,7 +46,9 @@ export const VideoPlayer = ({ activeIndex, pip, playlist, onPipChange, onProgres
45
46
  srcLang: subtitle.locale,
46
47
  })),
47
48
  },
48
- }, controls: true, height: "100%", light: React.createElement(Image, { alt: `thumbnail for ${title}`, layout: "fill", priority: true, style: { objectFit: 'contain' }, src: mediaItem.thumbnail }), onDisablePIP: () => onPipChange && onPipChange(false), onEnablePIP: () => onPipChange && onPipChange(true), onProgress: onProgress, onReady: handleReady, pip: pip, playing: true, ref: ref, style: {
49
+ }, controls: true, height: "100%", light: React.createElement(Image, { alt: `thumbnail for ${title}`, layout: "fill", priority: true, style: {
50
+ objectFit: 'contain',
51
+ }, src: mediaItem.thumbnail }), progressInterval: 4000, onDisablePIP: () => onPipChange && onPipChange(false), onEnablePIP: () => onPipChange && onPipChange(true), onProgress: onProgress, onReady: handleReady, pip: pip, playIcon: playable ? (React.createElement(PlaySolid, { color: "white", size: 24, sx: "position: absolute; width: 54px; height: 54px;" })) : (React.createElement(LockCircle, { color: "white", size: 24, sx: "position: absolute; width: 54px; height: 54px;" })), playing: playable, ref: ref, style: {
49
52
  backgroundColor: 'var(--color-grey-0)',
50
53
  maxHeight: 720,
51
54
  maxWidth: 1280,
@@ -82,6 +85,16 @@ const InnerWrapper = styled.div `
82
85
  flex: 1;
83
86
  display: flex;
84
87
  justify-content: flex-end;
88
+
89
+ ${({ $playable }) => $playable
90
+ ? ''
91
+ : `
92
+ .player {
93
+ cursor: initial;
94
+ pointer-events: none;
95
+ user-select: none;
96
+ }`}
97
+
85
98
  ${({ $orientation }) => $orientation === 'vertical'
86
99
  ? `
87
100
  flex-direction: column;
@@ -0,0 +1 @@
1
+ export declare const abbrTimeBeforeDate: (date: Date) => string;
@@ -0,0 +1,26 @@
1
+ export const abbrTimeBeforeDate = (date) => {
2
+ const now = new Date();
3
+ const diff = now.getTime() - date.getTime();
4
+ if (diff < 60000) {
5
+ // under 1 min
6
+ return 'Just now';
7
+ }
8
+ else if (diff < 3600000) {
9
+ // under one hour
10
+ const minutes = Math.floor(diff / 60000);
11
+ return `${minutes} ${minutes === 1 ? 'min' : 'mins'}`;
12
+ }
13
+ else if (diff < 86400000) {
14
+ // under one day
15
+ const hours = Math.floor(diff / 3600000);
16
+ return `${hours} ${hours === 1 ? 'hour' : 'hours'}`;
17
+ }
18
+ else if (diff < 604800000) {
19
+ // under one week
20
+ const days = Math.floor(diff / 86400000);
21
+ return `${days} ${days === 1 ? 'day' : 'days'}`;
22
+ }
23
+ else {
24
+ return date.toDateString().slice(4);
25
+ }
26
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soul-refiner/design-system",
3
- "version": "1.0.6",
3
+ "version": "1.1.0",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "publishConfig": {