Skip to content

Commit

Permalink
refactor: add ControllerTooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
ambar committed Jan 29, 2022
1 parent 63f554a commit d02ee66
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 236 deletions.
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"build": "vite build",
"start": "vite"
"start": "vite --host"
},
"dependencies": {
"@types/react-router-dom": "^5.1.8",
Expand Down
14 changes: 5 additions & 9 deletions packages/griffith/src/components/Controller.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,15 @@ export default StyleSheet.create({
color: '#fff',
},

fullScreenTooltip: {
pointerEvents: 'none',
},

fullScreenedTime: {
width: '150px',
},

fullScreenTooltipWide: {
left: '30%',
},

pipTooltip: {
tooltipContent: {
pointerEvents: 'none',
padding: '0.25em 0.5em',
fontSize: '0.875em',
whiteSpace: 'nowrap',
color: '#fff',
},
})
33 changes: 0 additions & 33 deletions packages/griffith/src/components/Hover.tsx

This file was deleted.

10 changes: 0 additions & 10 deletions packages/griffith/src/components/Tooltip.styles.ts

This file was deleted.

19 changes: 0 additions & 19 deletions packages/griffith/src/components/Tooltip.tsx

This file was deleted.

35 changes: 0 additions & 35 deletions packages/griffith/src/components/__tests__/Hover.spec.tsx

This file was deleted.

This file was deleted.

This file was deleted.

40 changes: 40 additions & 0 deletions packages/griffith/src/components/items/ControllerTooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react'
import {css} from 'aphrodite/no-important'
import {LocaleConfigKey} from '../../constants/locales'
import useBoolean from '../../hooks/useBoolean'
import TranslatedText from '../TranslatedText'
import styles from '../Controller.styles'

type Props = {
content: LocaleConfigKey
}

const canUseTouch =
typeof document !== 'undefined' && 'ontouchstart' in document.body

const ControllerTooltip: React.FC<Props> = ({content, children}) => {
const [isHovered, isHoveredSwitch] = useBoolean()

return (
<div
className={css(styles.menuContainer)}
onMouseEnter={isHoveredSwitch.on}
onMouseLeave={isHoveredSwitch.off}
>
{children}
{!canUseTouch && (
<div
className={css(
styles.menu,
isHovered && styles.menuShown,
styles.tooltipContent
)}
>
<TranslatedText name={content} />
</div>
)}
</div>
)
}

export default ControllerTooltip
46 changes: 11 additions & 35 deletions packages/griffith/src/components/items/FullScreenButtonItem.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,22 @@
import React from 'react'
import {css} from 'aphrodite/no-important'
import {ua} from 'griffith-utils'
import styles from '../Controller.styles'
import * as icons from '../icons/controller'
import Tooltip from '../Tooltip'
import Hover from '../Hover'
import ControllerTooltip from './ControllerTooltip'
import ControllerButton from './ControllerButton'

const {isMobile} = ua

const FullScreenButtonItem: React.FC<{
isFullScreen: boolean
onClick: React.HTMLAttributes<HTMLButtonElement>['onClick']
}> = ({isFullScreen, onClick}) => (
<Hover className={css(styles.menuContainer)}>
{(isFullScreenHovered) => (
<>
<ControllerButton
icon={isFullScreen ? icons.smallscreen : icons.fullscreen}
onClick={onClick}
/>
<div
className={css(
styles.fullScreenTooltip,
styles.menu,
isFullScreenHovered && styles.menuShown,
isFullScreen && styles.fullScreenTooltipWide
)}
>
{!isMobile && (
<Tooltip
content={
isFullScreen
? 'action-exit-fullscreen'
: 'action-enter-fullscreen'
}
/>
)}
</div>
</>
)}
</Hover>
<ControllerTooltip
content={
isFullScreen ? 'action-exit-fullscreen' : 'action-enter-fullscreen'
}
>
<ControllerButton
icon={isFullScreen ? icons.smallscreen : icons.fullscreen}
onClick={onClick}
/>
</ControllerTooltip>
)

export default FullScreenButtonItem
48 changes: 13 additions & 35 deletions packages/griffith/src/components/items/PageFullScreenButtonItem.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,24 @@
import React from 'react'
import {css} from 'aphrodite/no-important'
import {ua} from 'griffith-utils'
import styles from '../Controller.styles'
import * as icons from '../icons/controller'
import Tooltip from '../Tooltip'
import Hover from '../Hover'
import ControllerTooltip from './ControllerTooltip'
import ControllerButton from './ControllerButton'

const {isMobile} = ua

const PageFullScreenButtonItem: React.FC<{
isFullScreen: boolean
onClick: React.HTMLAttributes<HTMLButtonElement>['onClick'] | (() => void)
}> = ({isFullScreen, onClick}) => (
<Hover className={css(styles.menuContainer)}>
{(isFullScreenHovered) => (
<>
<ControllerButton
icon={isFullScreen ? icons.exitPageScreen : icons.enterPageScreen}
onClick={onClick}
/>
<div
className={css(
styles.fullScreenTooltip,
styles.menu,
isFullScreenHovered && styles.menuShown,
isFullScreen && styles.fullScreenTooltipWide
)}
>
{!isMobile && (
<Tooltip
content={
isFullScreen
? 'action-exit-page-fullscreen'
: 'action-enter-page-fullscreen'
}
/>
)}
</div>
</>
)}
</Hover>
<ControllerTooltip
content={
isFullScreen
? 'action-exit-page-fullscreen'
: 'action-enter-page-fullscreen'
}
>
<ControllerButton
icon={isFullScreen ? icons.exitPageScreen : icons.enterPageScreen}
onClick={onClick}
/>
</ControllerTooltip>
)

export default PageFullScreenButtonItem
35 changes: 7 additions & 28 deletions packages/griffith/src/components/items/PipButtonItem.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,18 @@
import React from 'react'
import {css} from 'aphrodite/no-important'
import {ua} from 'griffith-utils'
import styles from '../Controller.styles'
import * as icons from '../icons/controller'
import Tooltip from '../Tooltip'
import Hover from '../Hover'
import ControllerTooltip from './ControllerTooltip'
import ControllerButton from './ControllerButton'

const {isMobile} = ua

const PipButtonItem: React.FC<{
isPip: boolean
onClick: React.HTMLAttributes<HTMLButtonElement>['onClick']
}> = ({isPip, onClick}) => (
<Hover className={css(styles.menuContainer)}>
{(isPipHovered) => (
<>
<ControllerButton
icon={isPip ? icons.exitPip : icons.pip}
onClick={onClick}
/>
<div
className={css(
styles.pipTooltip,
styles.menu,
isPipHovered && styles.menuShown
)}
>
{!isMobile && (
<Tooltip content={isPip ? 'action-exit-pip' : 'action-enter-pip'} />
)}
</div>
</>
)}
</Hover>
<ControllerTooltip content={isPip ? 'action-exit-pip' : 'action-enter-pip'}>
<ControllerButton
icon={isPip ? icons.exitPip : icons.pip}
onClick={onClick}
/>
</ControllerTooltip>
)

export default PipButtonItem
5 changes: 3 additions & 2 deletions packages/griffith/src/components/items/PlayButtonItem.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import React from 'react'
import * as icons from '../icons/controller'
import ControllerButton from './ControllerButton'
import ControllerTooltip from './ControllerTooltip'

const PlayButtonItem: React.FC<{
isPlaying: boolean
onClick: React.HTMLAttributes<HTMLButtonElement>['onClick']
}> = ({isPlaying, onClick}) => (
<div>
<ControllerTooltip content={isPlaying ? 'pause' : 'play'}>
<ControllerButton
icon={isPlaying ? icons.pause : icons.play}
onClick={onClick}
/>
</div>
</ControllerTooltip>
)

export default PlayButtonItem
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react'
import Renderer from 'react-test-renderer'
import Tooltip from '../Tooltip'
import ControllerTooltip from '../ControllerTooltip'

describe('Tooltip', () => {
it('get Tooltip component', () => {
expect(
Renderer.create(<Tooltip content="quality-hd" />).toJSON()
Renderer.create(<ControllerTooltip content="quality-hd" />).toJSON()
).toMatchSnapshot()
})
})
Loading

0 comments on commit d02ee66

Please sign in to comment.