forked from zhihu/griffith
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
110 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
packages/griffith/src/components/__tests__/__snapshots__/Hover.spec.tsx.snap
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
packages/griffith/src/components/__tests__/__snapshots__/Tooltip.spec.tsx.snap
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
packages/griffith/src/components/items/ControllerTooltip.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
46
packages/griffith/src/components/items/FullScreenButtonItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
48
packages/griffith/src/components/items/PageFullScreenButtonItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
4 changes: 2 additions & 2 deletions
4
...src/components/__tests__/Tooltip.spec.tsx → ...tems/__tests__/ControllerTooltip.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) |
Oops, something went wrong.