keep-around/af30b88d367751c9e05a735e4a0467a96238ef47
parent
2fff5da887
commit
e29b1b3889
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.6 KiB |
@ -1,5 +1,20 @@ |
|||||||
import React from 'react' |
import React from 'react' |
||||||
|
|
||||||
import { Wrapper } from './styled' |
import { useScoreStore } from './store' |
||||||
|
import { |
||||||
|
Switch, |
||||||
|
Title, |
||||||
|
Icon, |
||||||
|
} from './styled' |
||||||
|
|
||||||
export const ToggleScore = () => <Wrapper /> |
export * from './store' |
||||||
|
|
||||||
|
export const ToggleScore = () => { |
||||||
|
const { isVisible, toggle } = useScoreStore() |
||||||
|
return ( |
||||||
|
<Switch onClick={toggle}> |
||||||
|
<Title t='hide_score' /> |
||||||
|
<Icon isOn={isVisible} /> |
||||||
|
</Switch> |
||||||
|
) |
||||||
|
} |
||||||
|
|||||||
@ -0,0 +1,28 @@ |
|||||||
|
import type { ReactNode } from 'react' |
||||||
|
import React, { |
||||||
|
createContext, |
||||||
|
useContext, |
||||||
|
} from 'react' |
||||||
|
|
||||||
|
import { useToggle } from 'hooks' |
||||||
|
|
||||||
|
type ScoreStore = { |
||||||
|
isVisible: boolean, |
||||||
|
toggle: () => void, |
||||||
|
} |
||||||
|
|
||||||
|
type Props = { children: ReactNode } |
||||||
|
|
||||||
|
const ScoreContext = createContext({} as ScoreStore) |
||||||
|
|
||||||
|
export const ScoreStore = ({ children }: Props) => { |
||||||
|
const { isOpen, toggle } = useToggle() |
||||||
|
|
||||||
|
return ( |
||||||
|
<ScoreContext.Provider value={{ isVisible: isOpen, toggle }}> |
||||||
|
{children} |
||||||
|
</ScoreContext.Provider> |
||||||
|
) |
||||||
|
} |
||||||
|
|
||||||
|
export const useScoreStore = () => useContext(ScoreContext) |
||||||
@ -1,3 +1,43 @@ |
|||||||
import styled from 'styled-components/macro' |
import styled from 'styled-components/macro' |
||||||
|
|
||||||
export const Wrapper = styled.div`` |
import { T9n } from 'features/T9n' |
||||||
|
|
||||||
|
export const Switch = styled.div` |
||||||
|
position: absolute; |
||||||
|
right: 99px; |
||||||
|
top: 32px; |
||||||
|
display: flex; |
||||||
|
align-items: center; |
||||||
|
cursor: pointer; |
||||||
|
` |
||||||
|
|
||||||
|
export const Title = styled(T9n)` |
||||||
|
font-style: normal; |
||||||
|
font-weight: 600; |
||||||
|
font-size: 14px; |
||||||
|
letter-spacing: -0.03em; |
||||||
|
color: #999999; |
||||||
|
margin-right: 5px; |
||||||
|
` |
||||||
|
|
||||||
|
type IconProps = { |
||||||
|
isOn: boolean, |
||||||
|
} |
||||||
|
|
||||||
|
export const Icon = styled.div<IconProps>` |
||||||
|
width: 28px; |
||||||
|
height: 16px; |
||||||
|
color: white; |
||||||
|
background-repeat: no-repeat; |
||||||
|
${({ isOn }) => ( |
||||||
|
isOn |
||||||
|
? ` |
||||||
|
background-image: url(/images/switchOn.svg); |
||||||
|
background-position: 0 -1px; |
||||||
|
` |
||||||
|
: ` |
||||||
|
background-image: url(/images/switchOff.svg); |
||||||
|
background-position: -2px -1px; |
||||||
|
` |
||||||
|
)}; |
||||||
|
` |
||||||
|
|||||||
Loading…
Reference in new issue