Skip to content

Commit

Permalink
Remove support for browsers that don't support gap in flexbox
Browse files Browse the repository at this point in the history
According to our browserslist configuration,
this is only iOS Safari 12.something,
with only 0.01% above our cutoff.
This is a mobile browser, though,
which we don't support at all right now.
  • Loading branch information
JulianKniephoff committed Jun 19, 2024
1 parent 0d94884 commit 5395dd0
Show file tree
Hide file tree
Showing 21 changed files with 51 additions and 133 deletions.
50 changes: 6 additions & 44 deletions src/cssStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { css, Global, keyframes } from "@emotion/react";
import React from "react";
import emotionNormalize from "emotion-normalize";
import { checkFlexGapSupport } from "./util/utilityFunctions";
import { createTheme } from "@mui/material/styles";
import { Theme, useTheme } from "./themes";
import { StylesConfig } from "react-select";
Expand Down Expand Up @@ -39,43 +38,6 @@ export const globalStyle = (theme: Theme) => css({
export const BREAKPOINT_SMALL = 450;
export const BREAKPOINT_MEDIUM = 650;


/**
* CSS for replacing flexbox gap in browers that do not support it
* Does not return a css prop, but is meant as a direct replacement for "gap"
* Example: ...(flexGapReplacementStyle(30, false))
*/
export const flexGapReplacementStyle = (flexGapValue: number, flexDirectionIsRow: boolean) => {

const half = flexGapValue / 2;
const quarter = flexGapValue / 4;

return (
{
// Use gap if supported
...(checkFlexGapSupport()) && { gap: `${flexGapValue}px` },
// Else use margins
...(!checkFlexGapSupport()) &&
{
">*": { // For each child
marginTop: `${quarter}px`,
marginBottom: `${quarter}px`,
marginRight: `${half}px`,
marginLeft: `${half}px`,
},
...(flexDirectionIsRow) && {
">*:first-of-type": {
marginLeft: "0px",
},
">*:last-child": {
marginRight: "0px",
},
},
},
}
);
};

/**
* CSS for buttons
*/
Expand All @@ -94,7 +56,7 @@ export const basicButtonStyle = (theme: Theme) => css({
display: "flex",
justifyContent: "center",
alignItems: "center",
...(flexGapReplacementStyle(10, false)),
gap: "10px",
textAlign: "center" as const,
outline: `${theme.button_outline}`,
});
Expand All @@ -110,7 +72,7 @@ export const deactivatedButtonStyle = css({
display: "flex",
justifyContent: "center",
alignItems: "center",
...(flexGapReplacementStyle(10, false)),
gap: "10px",
textAlign: "center" as const,
});

Expand All @@ -131,7 +93,7 @@ export const navigationButtonStyle = (theme: Theme) => css({
export const backOrContinueStyle = css(({
display: "flex",
flexDirection: "row",
...(flexGapReplacementStyle(20, false)),
gap: "20px",
}));

/**
Expand All @@ -143,7 +105,7 @@ export const tileButtonStyle = (theme: Theme) => css({
display: "flex",
flexDirection: "column",
fontWeight: "bold",
...(flexGapReplacementStyle(30, false)),
gap: "30px",
boxShadow: `${theme.boxShadow_tiles}`,
background: `${theme.element_bg}`,
placeSelf: "center",
Expand Down Expand Up @@ -460,7 +422,7 @@ export const videosStyle = (theme: Theme) => css(({
marginTop: "24px",
boxSizing: "border-box",
padding: "10px",
...(flexGapReplacementStyle(10, false)),
gap: "10px",
}));

export const backgroundBoxStyle = (theme: Theme) => css(({
Expand All @@ -469,5 +431,5 @@ export const backgroundBoxStyle = (theme: Theme) => css(({
boxShadow: `${theme.boxShadow_tiles}`,
boxSizing: "border-box",
padding: "20px",
...(flexGapReplacementStyle(25, false)),
gap: "25px",
}));
4 changes: 2 additions & 2 deletions src/main/Discard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";

import { css } from "@emotion/react";
import { basicButtonStyle, backOrContinueStyle, navigationButtonStyle, flexGapReplacementStyle } from "../cssStyles";
import { basicButtonStyle, backOrContinueStyle, navigationButtonStyle } from "../cssStyles";

import { LuChevronLeft, LuXCircle } from "react-icons/lu";

Expand All @@ -28,7 +28,7 @@ const Discard: React.FC = () => {
display: finishState !== "Discard changes" ? "none" : "flex",
flexDirection: "column" as const,
alignItems: "center",
...(flexGapReplacementStyle(30, false)),
gap: "30px",
});

return (
Expand Down
3 changes: 1 addition & 2 deletions src/main/Error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { LuFrown } from "react-icons/lu";

import { useAppSelector } from "../redux/store";
import { selectErrorDetails, selectErrorIcon, selectErrorMessage, selectErrorTitle } from "../redux/errorSlice";
import { flexGapReplacementStyle } from "../cssStyles";

import { useTranslation } from "react-i18next";

Expand Down Expand Up @@ -36,7 +35,7 @@ const Error: React.FC = () => {
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
...(flexGapReplacementStyle(10, false)),
gap: "10px",
});

return (
Expand Down
4 changes: 2 additions & 2 deletions src/main/FinishMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";

import { css } from "@emotion/react";
import { basicButtonStyle, flexGapReplacementStyle, tileButtonStyle } from "../cssStyles";
import { basicButtonStyle, tileButtonStyle } from "../cssStyles";

import { IconType } from "react-icons";
import { LuSave, LuDatabase, LuXCircle } from "react-icons/lu";
Expand All @@ -22,7 +22,7 @@ const FinishMenu: React.FC = () => {
flexDirection: "row",
justifyContent: "center",
flexWrap: "wrap",
...(flexGapReplacementStyle(30, false)),
gap: "30px",
});

return (
Expand Down
8 changes: 4 additions & 4 deletions src/main/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { LuMoon, LuSun } from "react-icons/lu";
import { HiOutlineTranslate } from "react-icons/hi";
import { LuKeyboard } from "react-icons/lu";
import { MainMenuStateNames } from "../types";
import { basicButtonStyle, BREAKPOINT_MEDIUM, BREAKPOINT_SMALL, flexGapReplacementStyle } from "../cssStyles";
import { basicButtonStyle, BREAKPOINT_MEDIUM, BREAKPOINT_SMALL } from "../cssStyles";

import LogoSvg from "../img/opencast-editor.svg?react";
import { selectIsEnd } from "../redux/endSlice";
Expand Down Expand Up @@ -48,14 +48,14 @@ function Header() {
height: "100%",
alignItems: "center",
paddingRight: "24px",
...(flexGapReplacementStyle(16, false)),
gap: "16px",
});

const settingsButtonCSS = css({
display: "flex",
flexDirection: "row",
alignItems: "center",
...(flexGapReplacementStyle(8, false)),
gap: "8px",

fontSize: 16,
fontFamily: "inherit",
Expand Down Expand Up @@ -215,7 +215,7 @@ const HeaderButton = React.forwardRef<HTMLButtonElement, HeaderButtonProps>(
const themeSelectorButtonStyle = css({
display: "flex",
alignItems: "center",
...(flexGapReplacementStyle(8, false)),
gap: "8px",

fontSize: 16,
fontFamily: "inherit",
Expand Down
7 changes: 3 additions & 4 deletions src/main/KeyboardControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ParseKeys } from "i18next";
import React from "react";

import { useTranslation, Trans } from "react-i18next";
import { flexGapReplacementStyle } from "../cssStyles";
import { getGroupName, KEYMAP, rewriteKeys } from "../globalKeys";
import { useTheme } from "../themes";
import { titleStyle, titleStyleBold } from "../cssStyles";
Expand Down Expand Up @@ -52,7 +51,7 @@ const Entry: React.FC<{ name: string, sequences: string[][]; }> = ({ name, seque
justifyContent: "left",
width: "100%",
padding: "10px 0px",
...(flexGapReplacementStyle(10, true)),
gap: "10px",
});

const labelStyle = css({
Expand All @@ -66,7 +65,7 @@ const Entry: React.FC<{ name: string, sequences: string[][]; }> = ({ name, seque
const sequenceStyle = css({
display: "flex",
flexDirection: "row",
...(flexGapReplacementStyle(10, true)),
gap: "10px",
});

const singleKeyStyle = css({
Expand Down Expand Up @@ -121,7 +120,7 @@ const KeyboardControls: React.FC = () => {
flexDirection: "row" as const,
flexWrap: "wrap",
justifyContent: "center",
...(flexGapReplacementStyle(30, true)),
gap: "30px",
});

const render = () => {
Expand Down
3 changes: 1 addition & 2 deletions src/main/MainContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { useAppSelector } from "../redux/store";
import { selectMainMenuState } from "../redux/mainMenuSlice";

import { MainMenuStateNames } from "../types";
import { flexGapReplacementStyle } from "../cssStyles";

import { useBeforeunload } from "react-beforeunload";
import { selectHasChanges as videoSelectHasChanges } from "../redux/videoSlice";
Expand Down Expand Up @@ -48,7 +47,7 @@ const MainContent: React.FC = () => {
width: "100%",
paddingRight: "20px",
paddingLeft: "20px",
...(flexGapReplacementStyle(20, false)),
gap: "20px",
background: `${theme.background}`,
overflow: "auto",
});
Expand Down
4 changes: 2 additions & 2 deletions src/main/MainMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { setPageNumber } from "../redux/finishSlice";

import { MainMenuStateNames } from "../types";
import { settings } from "../config";
import { basicButtonStyle, flexGapReplacementStyle } from "../cssStyles";
import { basicButtonStyle } from "../cssStyles";
import { setIsPlaying } from "../redux/videoSlice";

import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -42,7 +42,7 @@ const MainMenu: React.FC = () => {
overflowX: "hidden",
overflowY: "auto",
background: `${theme.menu_background}`,
...(flexGapReplacementStyle(30, false)),
gap: "30px",
});

return (
Expand Down
4 changes: 2 additions & 2 deletions src/main/Save.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useEffect, useState } from "react";
import { css } from "@emotion/react";
import {
basicButtonStyle, backOrContinueStyle, ariaLive, errorBoxStyle,
navigationButtonStyle, flexGapReplacementStyle, spinningStyle,
navigationButtonStyle, spinningStyle,
} from "../cssStyles";

import { LuLoader, LuCheckCircle, LuAlertCircle, LuChevronLeft, LuSave, LuCheck } from "react-icons/lu";
Expand Down Expand Up @@ -57,7 +57,7 @@ const Save: React.FC = () => {
display: finishState !== "Save changes" ? "none" : "flex",
flexDirection: "column" as const,
alignItems: "center",
...(flexGapReplacementStyle(30, false)),
gap: "30px",
});

const render = () => {
Expand Down
8 changes: 4 additions & 4 deletions src/main/SubtitleEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";
import { css } from "@emotion/react";
import { basicButtonStyle, flexGapReplacementStyle } from "../cssStyles";
import { basicButtonStyle } from "../cssStyles";
import { LuChevronLeft, LuDownload, LuUpload } from "react-icons/lu";
import {
selectSubtitlesFromOpencastById,
Expand Down Expand Up @@ -98,14 +98,14 @@ const SubtitleEditor: React.FC = () => {
justifyContent: "space-between",
alignItems: "center",
width: "100%",
...(flexGapReplacementStyle(10, false)),
gap: "10px",
padding: "15px",
});

const topRightButtons = css({
display: "flex",
flexDirection: "row",
...(flexGapReplacementStyle(10, false)),
gap: "10px",
});

const subAreaStyle = css({
Expand All @@ -117,7 +117,7 @@ const SubtitleEditor: React.FC = () => {
width: "100%",
paddingTop: "10px",
paddingBottom: "10px",
...(flexGapReplacementStyle(30, true)),
gap: "30px",
borderBottom: `${theme.menuBorder}`,
});

Expand Down
8 changes: 4 additions & 4 deletions src/main/SubtitleListEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { shallowEqual } from "react-redux";
import { useAppDispatch, useAppSelector } from "../redux/store";
import { basicButtonStyle, flexGapReplacementStyle } from "../cssStyles";
import { basicButtonStyle } from "../cssStyles";
import { KEYMAP } from "../globalKeys";
import {
addCueAtIndex,
Expand Down Expand Up @@ -90,7 +90,7 @@ const SubtitleListEditor: React.FC = () => {
flexDirection: "column",
height: "100%",
width: "60%",
...(flexGapReplacementStyle(20, false)),
gap: "20px",
});

const calcEstimatedSize = React.useCallback(() => {
Expand Down Expand Up @@ -305,7 +305,7 @@ const SubtitleListSegment = React.memo((props: subtitleListSegmentProps) => {
flexDirection: "row",
justifyContent: "space-around",
alignItems: "center",
...(flexGapReplacementStyle(20, false)),
gap: "20px",
// Make function buttons visible when hovered or focused
"&:hover": {
"& .functionButtonAreaStyle": {
Expand Down Expand Up @@ -338,7 +338,7 @@ const SubtitleListSegment = React.memo((props: subtitleListSegmentProps) => {
flexDirection: "column",
justifyContent: "space-between",
alignItems: "center",
...(flexGapReplacementStyle(10, false)),
gap: "10px",
flexGrow: "0.5",
minWidth: "20px",
// Hackily moves buttons beyond the segment border.
Expand Down
5 changes: 2 additions & 3 deletions src/main/SubtitleSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useEffect } from "react";
import { css } from "@emotion/react";
import {
basicButtonStyle,
flexGapReplacementStyle,
tileButtonStyle,
disableButtonAnimation,
subtitleSelectStyle,
Expand Down Expand Up @@ -103,7 +102,7 @@ const SubtitleSelect: React.FC = () => {
flexDirection: "row",
justifyContent: "center",
flexWrap: "wrap",
...(flexGapReplacementStyle(30, false)),
gap: "30px",
});

const renderButtons = () => {
Expand Down Expand Up @@ -250,7 +249,7 @@ const SubtitleAddButton: React.FC<{
const subtitleAddFormStyle = css({
display: !isPlusDisplay ? "flex" : "none",
flexDirection: "column" as const,
...(flexGapReplacementStyle(30, false)),
gap: "30px",
width: "80%",
padding: "20px",
});
Expand Down
3 changes: 1 addition & 2 deletions src/main/SubtitleVideoArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
import { Flavor } from "../types";
import { settings } from "../config";
import { useTranslation } from "react-i18next";
import { flexGapReplacementStyle } from "../cssStyles";
import { serializeSubtitle } from "../util/utilityFunctions";
import { useTheme } from "../themes";
import { VideoPlayer } from "./VideoPlayers";
Expand Down Expand Up @@ -109,7 +108,7 @@ const SubtitleVideoArea: React.FC = () => {
justifyContent: "center",
alignItems: "center",
height: "100%",
...(flexGapReplacementStyle(10, false)),
gap: "10px",
});

const render = () => {
Expand Down
Loading

0 comments on commit 5395dd0

Please sign in to comment.