Skip to content

Commit

Permalink
Merge pull request #359 from npocccties/feat-video-style
Browse files Browse the repository at this point in the history
feat: 閲覧時の動画は40vhを最大高さに&Vimeoの表示領域を確保するように
  • Loading branch information
knokmki612 authored Mar 31, 2021
2 parents 9fb8401 + 6aba81d commit ac3b1f9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions components/molecules/TopicViewerContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Video from "$organisms/Video";
import Item from "$atoms/Item";
import useStickyProps from "$utils/useStickyProps";
import languages from "$utils/languages";
import { gray } from "$theme/colors";

function formatInterval(start: Date | number, end: Date | number) {
const duration = intervalToDuration({ start, end });
Expand All @@ -19,6 +20,14 @@ const useStyles = makeStyles((theme) => ({
marginRight: theme.spacing(-3),
marginBottom: theme.spacing(2),
marginLeft: theme.spacing(-3),
backgroundColor: gray[800],
"& > *": {
/* NOTE: 各動画プレイヤーのレスポンシブ対応により、高さはpaddingTopによってwidthのpercentage分
* 確保されるため、heightによる制限ではなくwidthによる制限をおこなう必要がある */
// NOTE: 4:3前提なので、16:9では40vhよりも狭い高さになる
maxWidth: "calc(40vh * 4 / 3)",
margin: "0 auto",
},
},
title: {
marginBottom: theme.spacing(0.5),
Expand Down
14 changes: 13 additions & 1 deletion components/organisms/Video/Vimeo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import { useEffect, useRef } from "react";
import Player, { Options } from "@vimeo/player";
import { usePlayerTrackingAtom } from "$store/playerTracker";
import volumePersister from "$utils/volumePersister";
import { makeStyles } from "@material-ui/core/styles";

const useStyles = makeStyles({
player: {
"&:empty": {
// NOTE: @vimeo/player によって iframe がぶら下がる前の高さを確保する
paddingTop: "56.25%",
},
},
});

type VimeoProps = {
options: Options;
Expand All @@ -14,8 +24,10 @@ const defaultOptions: Options = {
export function Vimeo({ options }: VimeoProps) {
const ref = useRef(document.createElement("div"));
const tracking = usePlayerTrackingAtom();
const classes = useStyles();
useEffect(() => {
const element = document.createElement("div");
element.classList.add(classes.player);
ref.current.appendChild(element);
const player = new Player(element, {
...defaultOptions,
Expand All @@ -29,6 +41,6 @@ export function Vimeo({ options }: VimeoProps) {
player.pause();
element.style.display = "none";
};
}, [options, tracking]);
}, [options, tracking, classes]);
return <div ref={ref} />;
}

1 comment on commit ac3b1f9

@vercel
Copy link

@vercel vercel bot commented on ac3b1f9 Mar 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.