keep-around/fdb88b04b32b9392e76795099e2ec47c9856b38b
parent
efb25594dc
commit
f7b66696ec
@ -0,0 +1,40 @@ |
|||||||
|
import styled from 'styled-components/macro' |
||||||
|
|
||||||
|
type WmType = { |
||||||
|
leftWM: number, |
||||||
|
topWM: number, |
||||||
|
} |
||||||
|
|
||||||
|
export const ScWaterMark = styled.div<WmType>` |
||||||
|
position: absolute; |
||||||
|
top: ${({ topWM }) => `${topWM}%`}; |
||||||
|
left: ${({ leftWM }) => `${leftWM}%`}; |
||||||
|
transform: translate(-50%, -50%); |
||||||
|
z-index: 1; |
||||||
|
color: white; |
||||||
|
opacity: 0.4; |
||||||
|
transition-property: left, top; |
||||||
|
transition-duration: 3s; |
||||||
|
` |
||||||
|
|
||||||
|
type WaterMarkProps = { |
||||||
|
value: string | number | undefined, |
||||||
|
} |
||||||
|
|
||||||
|
export const WaterMark = ({ value }: WaterMarkProps) => { |
||||||
|
const calcCoordinate = () => { |
||||||
|
const leftWM = Math.floor(Math.random() * 100) |
||||||
|
let topWM |
||||||
|
if (leftWM < 10 || leftWM > 90) { |
||||||
|
topWM = Math.floor(Math.random() * 100) |
||||||
|
} else { |
||||||
|
topWM = Math.floor(Math.random() * 10) |
||||||
|
} |
||||||
|
return { leftWM, topWM } |
||||||
|
} |
||||||
|
return ( |
||||||
|
<ScWaterMark leftWM={calcCoordinate().leftWM} topWM={calcCoordinate().topWM}> |
||||||
|
{value} |
||||||
|
</ScWaterMark> |
||||||
|
) |
||||||
|
} |
||||||
Loading…
Reference in new issue