Skip to content

🎥 Make videos programmatically with React

remove styled components

Jonny Burger27c2c9b44132
diff --git a/packages/bundler/package.json b/packages/bundler/package.json
index 9725150ea4..97a68b41dd 100644
--- a/packages/bundler/package.json
+++ b/packages/bundler/package.json
@@ -32,7 +32,6 @@
"remotion": "^2.3.3",
"semver": "7.3.4",
"style-loader": "^2.0.0",
- "styled-components": "^5.2.1",
"webpack": "5.37.0",
"webpack-hot-middleware": "^2.25.0"
},
diff --git a/packages/bundler/src/webpack-config.ts b/packages/bundler/src/webpack-config.ts
index da1b1dfeeb..1ebe8198d3 100644
--- a/packages/bundler/src/webpack-config.ts
+++ b/packages/bundler/src/webpack-config.ts
@@ -104,7 +104,6 @@ export const webpackConfig = ({
'react/jsx-runtime': require.resolve('react/jsx-runtime'),
react: require.resolve('react'),
remotion: require.resolve('remotion'),
- 'styled-components': require.resolve('styled-components'),
'react-native$': 'react-native-web',
},
},
diff --git a/packages/cli/package.json b/packages/cli/package.json
index 9ad7add136..ecc0902096 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -44,7 +44,6 @@
"@types/node": "^16.7.5",
"@types/react": "17.0.19",
"@types/react-dom": "^17.0.0",
- "@types/styled-components": "^5.1.1",
"eslint": "^7.25.0",
"jest": "^26.6.3",
"prettier": "^2.0.5",
diff --git a/packages/cli/src/editor/components/CompositionSelector.tsx b/packages/cli/src/editor/components/CompositionSelector.tsx
index 270ba9f455..5fd9325286 100644
--- a/packages/cli/src/editor/components/CompositionSelector.tsx
+++ b/packages/cli/src/editor/components/CompositionSelector.tsx
@@ -1,62 +1,25 @@
import React, {useCallback, useContext, useEffect} from 'react';
import {Internals, TComposition} from 'remotion';
-import styled from 'styled-components';
-import {CLEAR_HOVER, LIGHT_TEXT, SELECTED_BACKGROUND} from '../helpers/colors';
-import {isCompositionStill} from '../helpers/is-composition-still';
-import {FilmIcon} from '../icons/film';
-import {StillIcon} from '../icons/still';
import {useZIndex} from '../state/z-index';
+import {CompositionSelectorItem} from './CompositionSelectorItem';
import {CurrentComposition} from './CurrentComposition';
import {
getCurrentCompositionFromUrl,
getFrameForComposition,
} from './FramePersistor';
-const Container = styled.div`
- border-right: 1px solid black;
- position: absolute;
- height: 100%;
- width: 100%;
- flex: 1;
-`;
-
-const List = styled.div`
- padding: 5px;
- height: calc(100% - 100px);
- overflow-y: auto;
-`;
-
-const Item = styled.a<{
- selected: boolean;
-}>`
- background: ${(props) =>
- props.selected ? SELECTED_BACKGROUND : 'transparent'};
- color: ${(props) => (props.selected ? 'white' : LIGHT_TEXT)};
- padding-left: 8px;
- padding-right: 8px;
- padding-top: 6px;
- padding-bottom: 6px;
- font-size: 13px;
- font-family: Arial, Helvetica, sans-serif;
- display: flex;
- border-radius: 2px;
- text-decoration: none;
- cursor: default;
- align-items: center;
- border-width: 1px;
- border-style: solid;
- border-color: transparent;
- margin-bottom: 1px;
- &:hover {
- border-color: ${(props) => (props.selected ? 'transparent' : CLEAR_HOVER)};
- background: ${(props) =>
- props.selected ? SELECTED_BACKGROUND : CLEAR_HOVER};
- color: white;
- }
-`;
+const container: React.CSSProperties = {
+ borderRight: '1px solid black',
+ position: 'absolute',
+ height: '100%',
+ width: '100%',
+ flex: 1,
+};
-const spacer: React.CSSProperties = {
- width: 6,
+const list: React.CSSProperties = {
+ padding: 5,
+ height: 'calc(100% - 100px)',
+ overflowY: 'auto',
};
export const CompositionSelector: React.FC = () => {
@@ -97,32 +60,21 @@ export const CompositionSelector: React.FC = () => {
}, [compositions, currentComposition, selectComposition]);
return (
- <Container>
+ <div style={container}>
<CurrentComposition />
- <List>
+ <div style={list}>
{compositions.map((c) => {
return (
- <Item
+ <CompositionSelectorItem
key={c.id}
- href={c.id}
- selected={currentComposition === c.id}
+ currentComposition={currentComposition}
+ selectComposition={selectComposition}
tabIndex={tabIndex}
- onClick={(evt) => {
- evt.preventDefault();
- selectComposition(c);
- }}
- >
- {isCompositionStill(c) ? (
- <StillIcon style={{height: 18, width: 18}} />
- ) : (
- <FilmIcon style={{height: 18, width: 18}} />
- )}
- <div style={spacer} />
- {c.id}
- </Item>
+ composition={c}
+ />
);
})}
- </List>
- </Container>
+ </div>
+ </div>
);
};
diff --git a/packages/cli/src/editor/components/CompositionSelectorItem.tsx b/packages/cli/src/editor/components/CompositionSelectorItem.tsx
new file mode 100644
index 0000000000..bf4c60f88b
--- /dev/null
+++ b/packages/cli/src/editor/components/CompositionSelectorItem.tsx
@@ -0,0 +1,71 @@
+import React, {useCallback, useState} from 'react';
+import {TComposition} from 'remotion';
+import {CLEAR_HOVER, LIGHT_TEXT, SELECTED_BACKGROUND} from '../helpers/colors';
+import {FONT_FAMILY} from '../helpers/font';
+import {isCompositionStill} from '../helpers/is-composition-still';
+import {FilmIcon} from '../icons/film';
+import {StillIcon} from '../icons/still';
+import {Spacing} from './layout';
+
+const item: React.CSSProperties = {
+ paddingLeft: 8,
+ paddingRight: 8,
+ paddingTop: 6,
+ paddingBottom: 6,
+ fontSize: 13,
+ fontFamily: FONT_FAMILY,
+ display: 'flex',
+ textDecoration: 'none',
+ cursor: 'default',
+ alignItems: 'center',
+ marginBottom: 1,
+};
+
+export const CompositionSelectorItem: React.FC<{
+ composition: TComposition<unknown>;
+ currentComposition: string | null;
+ tabIndex: number;
+ selectComposition: (c: TComposition) => void;
+}> = ({composition, currentComposition, tabIndex, selectComposition}) => {
+ const selected = currentComposition === composition.id;
+ const [hovered, setHovered] = useState(false);
+ const onPointerEnter = useCallback(() => {
+ setHovered(true);
+ }, []);
+
+ const onPointerLeave = useCallback(() => {
+ setHovered(false);
+ }, []);
+
+ return (
+ <a
+ style={{
+ ...item,
+ backgroundColor: hovered
+ ? selected
+ ? SELECTED_BACKGROUND
+ : CLEAR_HOVER
+ : selected
+ ? SELECTED_BACKGROUND
+ : 'transparent',
+ color: selected || hovered ? 'white' : LIGHT_TEXT,
+ }}
+ onPointerEnter={onPointerEnter}
+ onPointerLeave={onPointerLeave}
+ href={composition.id}
+ tabIndex={tabIndex}
+ onClick={(evt) => {
+ evt.preventDefault();
+ selectComposition(composition);
+ }}
+ >
+ {isCompositionStill(composition) ? (
+ <StillIcon style={{height: 18, width: 18}} />
+ ) : (
+ <FilmIcon style={{height: 18, width: 18}} />
+ )}
+ <Spacing x={0.5} />
+ {composition.id}
+ </a>
+ );
+};
diff --git a/packages/cli/src/editor/components/CurrentComposition.tsx b/packages/cli/src/editor/components/CurrentComposition.tsx
index 668bd10581..8a00c8510e 100644
--- a/packages/cli/src/editor/components/CurrentComposition.tsx
+++ b/packages/cli/src/editor/components/CurrentComposition.tsx
@@ -1,40 +1,39 @@
import React, {useContext} from 'react';
import {Internals} from 'remotion';
-import styled from 'styled-components';
+import {FONT_FAMILY} from '../helpers/font';
import {isCompositionStill} from '../helpers/is-composition-still';
import {renderFrame} from '../state/render-frame';
import {RichTimelineContext} from '../state/rich-timeline';
+import {Spacing} from './layout';
import {Thumbnail} from './Thumbnail';
-const Container = styled.div`
- min-height: 100px;
- display: block;
- border-bottom: 1px solid black;
- padding: 16px;
- color: white;
- line-height: 18px;
-`;
-
-const Title = styled.div`
- font-weight: bold;
- font-family: Arial, Helvetica, sans-serif;
- font-size: 12px;
-`;
+const container: React.CSSProperties = {
+ minHeight: 100,
+ display: 'block',
+ borderBottom: '1px solid black',
+ padding: 16,
+ color: 'white',
+ lineHeight: '18px',
+};
-const Subtitle = styled.div`
- font-family: Arial, Helvetica, sans-serif;
- font-size: 12px;
- opacity: 0.8;
-`;
+const title: React.CSSProperties = {
+ fontWeight: 'bold',
+ fontFamily: FONT_FAMILY,
+ fontSize: 12,
+ whiteSpace: 'nowrap',
+};
-const Row = styled.div`
- display: flex;
- flex-direction: row;
-`;
+const subtitle: React.CSSProperties = {
+ fontFamily: FONT_FAMILY,
+ fontSize: 12,
+ opacity: 0.8,
+ whiteSpace: 'nowrap',
+};
-const Space = styled.div`
- width: 12px;
-`;
+const row: React.CSSProperties = {
+ display: 'flex',
+ flexDirection: 'row',
+};
const targetHeight = 60;
const targetWidth = (targetHeight * 16) / 9;
@@ -43,13 +42,13 @@ export const CurrentComposition = () => {
const richTimelineContext = useContext(RichTimelineContext);
const video = Internals.useVideo();
if (!video) {
- return <Container />;
+ return <div style={container} />;
}
const frameToDisplay = Math.floor(video.durationInFrames / 2);
return (
- <Container>
- <Row>
+ <div style={container}>
+ <div style={row}>
{richTimelineContext.richTimeline ? (
<>
<Thumbnail
@@ -58,24 +57,24 @@ export const CurrentComposition = () => {
targetWidth={targetWidth}
frameToDisplay={frameToDisplay}
/>
- <Space />
+ <Spacing />
</>
) : null}
<div>
- <Title>{video.id}</Title>
- <Subtitle>
+ <div style={title}>{video.id}</div>
+ <div style={subtitle}>
{video.width}x{video.height}
{isCompositionStill(video) ? null : `, ${video.fps} FPS`}
- </Subtitle>
+ </div>
{isCompositionStill(video) ? (
- <Subtitle>Still</Subtitle>
+ <div style={subtitle}>Still</div>
) : (
- <Subtitle>
+ <div style={subtitle}>
Duration {renderFrame(video.durationInFrames, video.fps)}
- </Subtitle>
+ </div>
)}
</div>
- </Row>
- </Container>
+ </div>
+ </div>
);
};
diff --git a/packages/cli/src/editor/components/Editor.tsx b/packages/cli/src/editor/components/Editor.tsx
index 16383680ee..ce7388dc44 100644
--- a/packages/cli/src/editor/components/Editor.tsx
+++ b/packages/cli/src/editor/components/Editor.tsx
@@ -5,7 +5,6 @@ import {
MediaVolumeContextValue,
SetMediaVolumeContextValue,
} from 'remotion';
-import styled from 'styled-components';
import {BACKGROUND} from '../helpers/colors';
import {noop} from '../helpers/noop';
import {
@@ -34,14 +33,14 @@ import {KeyboardShortcuts} from './KeyboardShortcutsModal';
import NewComposition from './NewComposition/NewComposition';
import {UpdateModal} from './UpdateModal/UpdateModal';
-const Background = styled.div`
- background: ${BACKGROUND};
- display: flex;
- width: 100%;
- height: 100%;
- flex-direction: column;
- position: absolute;
-`;
+const background: React.CSSProperties = {
+ backgroundColor: BACKGROUND,
+ display: 'flex',
+ width: '100%',
+ height: '100%',
+ flexDirection: 'column',
+ position: 'absolute',
+};
const Root = Internals.getRoot();
@@ -151,12 +150,12 @@ export const Editor: React.FC = () => {
>
<HighestZIndexProvider>
<HigherZIndex onEscape={noop} onOutsideClick={noop}>
- <Background>
+ <div style={background}>
<Root />
<FramePersistor />
<EditorContent />
<GlobalKeybindings />
- </Background>
+ </div>
{modalContextType &&
modalContextType.type === 'new-comp' && (
<NewComposition
diff --git a/packages/cli/src/editor/components/Preview.tsx b/packages/cli/src/editor/components/Preview.tsx
index bb09cb09ef..c01185d4a2 100644
--- a/packages/cli/src/editor/components/Preview.tsx
+++ b/packages/cli/src/editor/components/Preview.tsx
@@ -1,7 +1,6 @@
import {PlayerInternals, Size} from '@remotion/player';
import React, {Suspense, useContext, useMemo} from 'react';
import {getInputProps, Internals, useVideoConfig} from 'remotion';
-import styled from 'styled-components';
import {
checkerboardBackgroundColor,
checkerboardBackgroundImage,
@@ -13,32 +12,32 @@ import {PreviewSizeContext} from '../state/preview-size';
const checkerboardSize = 49;
-export const Container = styled.div<{
+const containerStyle = (options: {
scale: number;
xCorrection: number;
yCorrection: number;
width: number;
height: number;
checkerboard: boolean;
-}>`
- transform: scale(${(props): number => props.scale});
- margin-left: ${(props): number => props.xCorrection}px;
- margin-top: ${(props): number => props.yCorrection}px;
- width: ${(props): number => props.width}px;
- height: ${(props): number => props.height}px;
- display: flex;
- position: absolute;
- background-color: ${(props) =>
- checkerboardBackgroundColor(props.checkerboard)};
- background-image: ${(props) =>
- checkerboardBackgroundImage(props.checkerboard)};
- background-size: ${getCheckerboardBackgroundSize(
- checkerboardSize
- )}; /* Must be a square */
- background-position: ${getCheckerboardBackgroundPos(
- checkerboardSize
- )}; /* Must be half of one side of the square */
-`;
+}): React.CSSProperties => {
+ return {
+ transform: `scale(${options.scale})`,
+ marginLeft: options.xCorrection,
+ marginTop: options.yCorrection,
+ width: options.width,
+ height: options.height,
+ display: 'flex',
+ position: 'absolute',
+ backgroundColor: checkerboardBackgroundColor(options.checkerboard),
+ backgroundImage: checkerboardBackgroundImage(options.checkerboard),
+ backgroundSize: getCheckerboardBackgroundSize(
+ checkerboardSize
+ ) /* Must be a square */,
+ backgroundPosition: getCheckerboardBackgroundPos(
+ checkerboardSize
+ ) /* Must be half of one side of the square */,
+ };
+};
const Inner: React.FC<{
canvasSize: Size;
@@ -75,29 +74,38 @@ const Inner: React.FC<{
};
}, [centerX, centerY, config.height, config.width, scale]);
+ const style = useMemo((): React.CSSProperties => {
+ return containerStyle({
+ checkerboard,
+ scale,
+ xCorrection,
+ yCorrection,
+ width: config.width,
+ height: config.height,
+ });
+ }, [
+ checkerboard,
+ config.height,
+ config.width,
+ scale,
+ xCorrection,
+ yCorrection,
+ ]);
+
const Component = video ? video.component : null;
const inputProps = getInputProps();
return (
<Suspense fallback={<div>loading...</div>}>
<div style={outer}>
- <Container
- {...{
- checkerboard,
- scale,
- xCorrection,
- yCorrection,
- width: config.width,
- height: config.height,
- }}
- >
+ <div style={style}>
{Component ? (
<Component
{...(((video?.props as unknown) as {}) ?? {})}
{...inputProps}
/>
) : null}
- </Container>
+ </div>
</div>
</Suspense>
);
diff --git a/packages/cli/src/editor/components/PreviewToolbar.tsx b/packages/cli/src/editor/components/PreviewToolbar.tsx
index 1ad4fe0c3f..9f33874cb2 100644
--- a/packages/cli/src/editor/components/PreviewToolbar.tsx
+++ b/packages/cli/src/editor/components/PreviewToolbar.tsx
@@ -1,57 +1,53 @@
import React from 'react';
-import styled from 'styled-components';
import {TIMELINE_PADDING} from '../helpers/timeline-layout';
import {CheckboardToggle} from './CheckboardToggle';
import {FpsCounter} from './FpsCounter';
+import {Flex} from './layout';
import {PlayPause} from './PlayPause';
import {RichTimelineToggle} from './RichTimelineToggle';
import {SizeSelector} from './SizeSelector';
import {TimeValue} from './TimeValue';
-const Container = styled.div`
- display: flex;
- justify-content: center;
- border-top: 1px solid rgba(0, 0, 0, 0.5);
- padding-top: 2px;
- padding-bottom: 2px;
- align-items: center;
- flex-direction: row;
-`;
-
-const SideContainer = styled.div`
- width: 300px;
- height: 38px;
- display: flex;
- flex-direction: row;
- align-items: center;
-`;
+const container: React.CSSProperties = {
+ display: 'flex',
+ justifyContent: 'center',
+ borderTop: '1px solid rgba(0, 0, 0, 0.5)',
+ paddingTop: 2,
+ paddingBottom: 2,
+ alignItems: 'center',
+ flexDirection: 'row',
+};
-const Flex = styled.div`
- flex: 1;
-`;
+const sideContainer: React.CSSProperties = {
+ width: 300,
+ height: 38,
+ display: 'flex',
+ flexDirection: 'row',
+ alignItems: 'center',
+};
-const Padding = styled.div`
- width: ${TIMELINE_PADDING}px;
-`;
+const padding: React.CSSProperties = {
+ width: TIMELINE_PADDING,
+};
export const PreviewToolbar: React.FC = () => {
return (
- <Container>
- <SideContainer>
- <Padding />
+ <div style={container}>
+ <div style={sideContainer}>
+ <div style={padding} />
<TimeValue />
- </SideContainer>
+ </div>
<Flex />
<SizeSelector />
<PlayPause />
<CheckboardToggle />
<RichTimelineToggle />
<Flex />
- <SideContainer>
+ <div style={sideContainer}>
<Flex />
<FpsCounter />
- <Padding />
- </SideContainer>
- </Container>
+ <div style={padding} />
+ </div>
+ </div>
);
};
diff --git a/packages/cli/src/editor/components/TimeValue.tsx b/packages/cli/src/editor/components/TimeValue.tsx
index abc279d23f..495690697a 100644
--- a/packages/cli/src/editor/components/TimeValue.tsx
+++ b/packages/cli/src/editor/components/TimeValue.tsx
@@ -1,29 +1,29 @@
import React from 'react';
import {Internals, useCurrentFrame} from 'remotion';
-import styled from 'styled-components';
+import {FONT_FAMILY} from '../helpers/font';
import {useIsStill} from '../helpers/is-current-selected-still';
import {renderFrame} from '../state/render-frame';
-const Text = styled.div`
- color: white;
- font-size: 16px;
- font-family: Helvetica, Arial, sans-serif;
- display: flex;
- flex-direction: column;
- justify-content: center;
- font-variant-numeric: tabular-nums;
- line-height: 1;
-`;
+const text: React.CSSProperties = {
+ color: 'white',
+ fontSize: 16,
+ fontFamily: FONT_FAMILY,
+ display: 'flex',
+ flexDirection: 'column',
+ justifyContent: 'center',
+ fontVariantNumeric: 'tabular-nums',
+ lineHeight: 1,
+};
-const Time = styled.div`
- display: inline-block;
-`;
+const time: React.CSSProperties = {
+ display: 'inline-block',
+};
-const Frame = styled.span`
- color: #ccc;
- font-size: 10px;
- font-weight: 500;
-`;
+const frameStyle: React.CSSProperties = {
+ color: '#ccc',
+ fontSize: 10,
+ fontWeight: 500,
+};
export const TimeValue: React.FC = () => {
const frame = useCurrentFrame();
@@ -39,11 +39,11 @@ export const TimeValue: React.FC = () => {
}
return (
- <Text>
- <Time>{renderFrame(frame, config.fps)}</Time>{' '}
- <Frame>
+ <div style={text}>
+ <div style={time}>{renderFrame(frame, config.fps)}</div>{' '}
+ <div style={frameStyle}>
{frame} <span>({config.fps} fps)</span>
- </Frame>
- </Text>
+ </div>
+ </div>
);
};
diff --git a/packages/cli/styles/styles.css b/packages/cli/styles/styles.css
index 00f6ae396f..85d4f3da29 100644
--- a/packages/cli/styles/styles.css
+++ b/packages/cli/styles/styles.css
@@ -29,5 +29,5 @@ button:focus,
a:focus {
outline: none;
box-shadow: 0 0 1px 2px rgba(255, 255, 255, 0.35);
- border-radius: 3px;
+ border-radius: 2px;
}