Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(player): remove styled-components #1094

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ If you want to import the player as a React component into your own code, or use
parts of the player, you'll need to install the package as a dependency.
You will also need to install a number of peer dependencies
such as [luxon](https://github.com/moment/luxon), which we use for date and time purposes,
`react`/`react-dom`, `styled-components`.
`react`/`react-dom`.
You can find an example of this under `example-player-react`, e.g.:

```js
Expand Down
18 changes: 7 additions & 11 deletions example-overlay-react/App.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React, { useState } from 'react'

import styled from 'styled-components'

import {
Foundation,
Liner,
Expand All @@ -25,13 +23,6 @@ const MIDDLE_AREA = [
[0.5, -0.5], // bottom right coordinate
]

const Layers = styled.div`
position: relative;
width: 80vw;
height: 80vh;
border: 1px solid deepskyblue;
`

const App = () => {
const [textPos1, setTextPos1] = useState([-1, 0.8])
const [textPos2, setTextPos2] = useState([-0.4, -0.5])
Expand All @@ -54,7 +45,12 @@ const App = () => {
<p>
To get started, edit <code>src/App.tsx</code> and save to reload.
</p>
<Layers>
<div style={{
position: 'relative',
width: '80vw',
height: '80vh',
border: '1px solid deepskyblue',
}}>
<Foundation
userBasis={USER_BASIS}
style={{
Expand Down Expand Up @@ -111,7 +107,7 @@ const App = () => {
interact with the SVGs below me
</Text>
</Foundation>
</Layers>
</div>
</div>
)
}
Expand Down
15 changes: 5 additions & 10 deletions example-overlay-react/Circle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,12 @@ import React, {
useState,
} from 'react'

import styled from 'styled-components'

import {
FoundationContext,
LinerContext,
useDraggable,
} from 'media-stream-library/overlay'

const SvgCircle = styled.circle`
fill: rgb(0.5, 0.5, 0.5, 0.2);
stroke: grey;
`

/*
* Circle
*
Expand All @@ -36,7 +29,7 @@ export const Circle = forwardRef(

const [cx, cy] = toSvgBasis(pos)

return <SvgCircle cx={cx} cy={cy} ref={ref} {...circleProps} />
return <circle style={{ fill: 'rgb(0.5,0.5,0.5,0.2)', stroke: 'grey' }} cx={cx} cy={cy} ref={ref} {...circleProps} />
}
)

Expand Down Expand Up @@ -99,7 +92,8 @@ export const DraggableCircle = forwardRef(({ pos, onChangePos, ...circleProps },
const [cx, cy] = svgPos

return (
<SvgCircle
<circle
style={{ fill: 'rgb(0.5,0.5,0.5,0.2)', stroke: 'grey' }}
name="circle"
cx={cx}
cy={cy}
Expand Down Expand Up @@ -165,7 +159,8 @@ export const FastDraggableCircle = ({
const [cx, cy] = toSvgBasis(pos)

return (
<SvgCircle
<circle
style={{ fill: 'rgb(0.5,0.5,0.5,0.2)', stroke: 'grey' }}
ref={circleRef}
name="circle"
cx={cx}
Expand Down
27 changes: 4 additions & 23 deletions example-overlay-react/Polygon.jsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
import React, { useContext, useEffect, useState } from 'react'

import styled from 'styled-components'

import {
FoundationContext,
LinerContext,
useDraggable,
} from 'media-stream-library/overlay'

const SvgCircleCorner = styled.circle`
fill: rgb(0.5, 0.5, 0.5);
stroke: grey;
`

const SvgCircleHandle = styled.circle`
fill: rgb(0.5, 0.5, 0.5, 0);
&:hover {
fill: rgb(0.5, 0.5, 0.5, 0.6);
}
`

const SvgPolygon = styled.polygon`
fill: rgb(0.5, 0.5, 0.5, 0.2);
stroke: grey;
`

export const Polygon = ({ pos, onChangePos }) => {
const { toSvgBasis, toUserBasis } = useContext(FoundationContext)
const { clampCoord, clampCoordArray } = useContext(LinerContext)
Expand Down Expand Up @@ -86,15 +66,16 @@ export const Polygon = ({ pos, onChangePos }) => {

return (
<g name="g" onPointerDown={startDrag}>
<SvgPolygon points={svgPos.map(([x, y]) => `${x},${y}`).join(' ')} />
<polygon style={{ fill: 'rgb(0.5, 0.5, 0.5, 0.2)', stroke: 'grey' }} points={svgPos.map(([x, y]) => `${x},${y}`).join(' ')} />
{svgPos.map(([x, y], index) => {
// The visible corners
return <SvgCircleCorner key={index} r={3} cx={x} cy={y} />
return <circle style={{ fill: 'rgb(0.5, 0.5, 0.5)', stroke: 'grey' }} key={index} r={3} cx={x} cy={y} />
})}
{svgPos.map(([x, y], index) => {
// The invisible handles
return (
<SvgCircleHandle
<circle
style={{ fill: 'rgb(0.5, 0.5, 0.5, 0)' }}
key={index}
name={`p${index}`}
r={5}
Expand Down
9 changes: 2 additions & 7 deletions example-overlay-react/Text.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import React, { useContext, useEffect, useRef } from 'react'

import styled from 'styled-components'

import {
FoundationContext,
LinerContext,
useDraggable,
} from 'media-stream-library/overlay'

const SvgText = styled.text`
user-select: none;
`

export const Text = ({
x: userX,
y: userY,
Expand Down Expand Up @@ -62,7 +57,7 @@ export const Text = ({
const [x, y] = toSvgBasis([userX, userY])

return (
<SvgText
<text style={{ userSelect: 'none' }}
name="text"
ref={textRef}
x={x}
Expand All @@ -71,6 +66,6 @@ export const Text = ({
onPointerDown={startDragging}
>
{children}
</SvgText>
</text>
)
}
14 changes: 5 additions & 9 deletions example-overlay-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@
"private": true,
"dependencies": {
"media-stream-library": "workspace:^",
"pepjs": "0.5.3",
"react": "18.3.1",
"react-dom": "18.3.1",
"styled-components": "5.3.11"
"pepjs": "^0.5.3",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@types/react": "18.3.18",
"@types/react-dom": "18.3.5",
"@types/styled-components": "5.1.34",
"@vitejs/plugin-react": "4.3.4",
"vite": "6.0.7"
"@vitejs/plugin-react": "^4.3.4",
"vite": "^6.0.7"
}
}
76 changes: 37 additions & 39 deletions example-player-react/App.jsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
import React, { useCallback, useState } from 'react'

import styled, { createGlobalStyle } from 'styled-components'

import { BasicStream } from './BasicStream'
import { MultiStream } from './MultiStream'
import { SingleStream } from './SingleStream'

const GlobalStyle = createGlobalStyle`
body {
margin: 0;
font-family: sans-serif;
}
`

const AppContainer = styled.div`
const style = `
body {
margin: 0;
font-family: sans-serif;
}
.appContainer {
width: 100vw;
height: 90vh;
display: flex;
flex-direction: column;
align-items: center;
`

const ButtonContainer = styled.div`
}
.buttonContainer {
margin: 8px;
text-align: center;
& button {
padding: 8px 12px;
margin: 4px;
background-color: lightpink;
&.selected {
background-color: lightgreen;
}
}
}
`

const Button = styled.button`
padding: 8px 12px;
margin: 4px;
background-color: ${({ selected }) =>
selected ? 'lightgreen' : 'lightpink'};
`

const LOCALSTORAGE_KEY = 'media-stream-player-example'

export const App = () => {
Expand All @@ -55,23 +51,25 @@ export const App = () => {
}, [setState])

return (
<AppContainer>
<GlobalStyle />
<h1>Media Stream Player</h1>
<ButtonContainer>
<Button onClick={single} selected={state === 'single'}>
Single stream (with controls)
</Button>
<Button onClick={basic} selected={state === 'basic'}>
Single stream (basic)
</Button>
<Button onClick={multi} selected={state === 'multi'}>
Multi stream
</Button>
</ButtonContainer>
{state === 'single' ? <SingleStream /> : null}
{state === 'basic' ? <BasicStream /> : null}
{state === 'multi' ? <MultiStream /> : null}
</AppContainer>
<>
<style>{style}</style>
<div className='appContainer'>
<h1>Media Stream Player</h1>
<div className='buttonContainer'>
<button onClick={single} className={state === 'single' && 'selected'}>
Single stream (with controls)
</button>
<button onClick={basic} className={state === 'basic' && 'selected'}>
Single stream (basic)
</button>
<button onClick={multi} className={state === 'multi' && 'selected'}>
Multi stream
</button>
</div>
{state === 'single' ? <SingleStream /> : null}
{state === 'basic' ? <BasicStream /> : null}
{state === 'multi' ? <MultiStream /> : null}
</div>
</>
)
}
31 changes: 7 additions & 24 deletions example-player-react/MultiStream.jsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
import React, { useEffect, useState } from 'react'

import styled from 'styled-components'

import { Player } from 'media-stream-library/player'

const MediaPlayer = styled(Player)`
max-width: 400px;
max-height: 300px;
margin: 8px;
`

const MediaPlayerContainer = styled.div`
width: 400px;
height: 300px;
margin: 8px;
`

const Centered = styled.div`
text-align: center;
`

// force auth
const authorize = async (host) => {
// Force a login by fetching usergroup
Expand Down Expand Up @@ -73,21 +55,22 @@ export const MultiStream = () => {
{state.length > 0 ? (
state.map((device) => {
return device.authorized ? (
<MediaPlayerContainer key={device.hostname}>
<Centered>{device.hostname}</Centered>
<MediaPlayer
<div style={{ width: '400px', height: '300px', margin: '8px', }} key={device.hostname}>
<div style={{ textAlign: 'center' }}>{device.hostname}</div>
<Player
style={{ maxWidth: '400px', maxHeight: '300px', margin: '8px', }}
hostname={device.hostname}
initialFormat="JPEG"
autoPlay
autoRetry
vapixParams={{ resolution: '800x600' }}
/>
</MediaPlayerContainer>
</div>
) : (
<MediaPlayerContainer key={device.hostname}>
<div style={{ width: '400px', height: '300px', margin: '8px', }} key={device.hostname}>
<Centered>{device.hostname}</Centered>
<Centered>Not authorized</Centered>
</MediaPlayerContainer>
</div>
)
})
) : (
Expand Down
11 changes: 5 additions & 6 deletions example-player-react/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"private": true,
"devDependencies": {
"@vitejs/plugin-react": "4.3.4",
"luxon": "3.5.0",
"@vitejs/plugin-react": "^4.3.4",
"luxon": "^3.5.0",
"media-stream-library": "workspace:^",
"react": "18.3.1",
"react-dom": "18.3.1",
"styled-components": "5.3.11",
"vite": "6.0.7"
"react": "^18.3.1",
"react-dom": "^18.3.1",
"vite": "^6.0.7"
}
}
Loading
Loading