Skip to content

Commit e48ffe6

Browse files
authored
Merge pull request #19 from titicacadev/feature/add-floating-install-button
💫 floating-install-button 패키지 추가
2 parents b51ffe2 + 92da4f9 commit e48ffe6

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# `floating-install-button`
2+
3+
퍼블릭 웹뷰에서 공통으로 쓰이는 플로팅 설치 유도 버튼입니다.
4+
5+
꼭 퍼블릭 웹뷰 환경에서만 쓰일 수 있도록 유의 부탁드립니다.
6+
7+
## Usage
8+
9+
```javascript
10+
import FloatingInstallButton from '@titicaca/floating-install-button'
11+
```
12+
13+
```jsx harmony
14+
<FloatingInstallButton appInstallLink="href" isPublic={isPublic} />
15+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@titicaca/floating-install-button",
3+
"version": "1.0.0-alpha.5",
4+
"description": "floating triple install button",
5+
"main": "lib/index.js",
6+
"types": "lib/index.d.ts",
7+
"files": [
8+
"lib/"
9+
],
10+
"repository": {
11+
"type": "git",
12+
"url": "git+https://github.com/titicacadev/triple-design-system.git"
13+
},
14+
"keywords": [
15+
"triple",
16+
"floating",
17+
"install",
18+
"button"
19+
],
20+
"license": "UNLICENSED",
21+
"bugs": {
22+
"url": "https://github.com/titicacadev/triple-frontend/issues"
23+
},
24+
"homepage": "https://github.com/titicacadev/triple-frontend#readme",
25+
"dependencies": {
26+
"@titicaca/triple-design-system": "^1.0.0-alpha.5"
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
declare var window: any
2+
3+
import React, { useState, useEffect } from 'react'
4+
import styled from 'styled-components'
5+
import { GetGlobalColor, Text, Container } from '@titicaca/triple-design-system'
6+
7+
const MIN_DESKTOP_WIDTH = 1142
8+
const CLOSE_INSTALL_BUTTON_KEY = 'close_install_button'
9+
10+
const FloatingButton = styled.div`
11+
position: fixed;
12+
height: 84px;
13+
border-radius: 42px;
14+
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.07);
15+
background-color: rgba(${GetGlobalColor('blue')}, 0.98);
16+
bottom: 0;
17+
left: 10px;
18+
right: 10px;
19+
margin-bottom: 30px;
20+
overflow: hidden;
21+
22+
@media (min-width: ${MIN_DESKTOP_WIDTH}px) {
23+
display: none;
24+
}
25+
`
26+
27+
const InstallDescription = styled(Text)`
28+
height: 21px;
29+
font-size: 18px;
30+
font-weight: bold;
31+
margin: 23px 0px 0px 32px;
32+
color: rgb(${GetGlobalColor('white')});
33+
`
34+
35+
const Description = styled(Text)`
36+
width: 200px;
37+
height: 15px;
38+
font-size: 12px;
39+
font-weight: 500;
40+
color: rgba(${GetGlobalColor('white')}, 0.6);
41+
margin: 3px 0px 22px 32px;
42+
`
43+
44+
const GoAppButton = styled.img`
45+
width: 20px;
46+
height: 20px;
47+
`
48+
49+
const CloseButton = styled.img`
50+
width: 30px;
51+
height: 30px;
52+
margin: 27px 16px 27px 0;
53+
`
54+
55+
export default function FloatingInstallButton({
56+
appInstallLink,
57+
isPublic,
58+
trackEvent,
59+
trackEventParams,
60+
}: {
61+
appInstallLink?: string
62+
isPublic?: boolean
63+
trackEvent?: any
64+
trackEventParams?: {
65+
onShow?: any
66+
onSelect?: any
67+
onClose?: any
68+
}
69+
}) {
70+
const [buttonVisibility, setButtonVisibility] = useState(false)
71+
72+
const sendTrackEventRequest = (param) => {
73+
trackEvent && param && trackEvent(param)
74+
}
75+
76+
useEffect(() => {
77+
const visitedPages = window.sessionStorage.getItem(CLOSE_INSTALL_BUTTON_KEY)
78+
if (!visitedPages) {
79+
setButtonVisibility(true)
80+
sendTrackEventRequest(trackEventParams && trackEventParams.onShow)
81+
}
82+
})
83+
84+
const onClose = () => {
85+
setButtonVisibility(false)
86+
window.sessionStorage.setItem(CLOSE_INSTALL_BUTTON_KEY, 'true')
87+
sendTrackEventRequest(trackEventParams && trackEventParams.onClose)
88+
}
89+
90+
const onSelect = () => {
91+
sendTrackEventRequest(trackEventParams && trackEventParams.onSelect)
92+
}
93+
94+
return buttonVisibility && isPublic ? (
95+
<FloatingButton>
96+
<Container floated="left">
97+
<InstallDescription>
98+
<a href={appInstallLink} onClick={onSelect}>
99+
<Container floated="left">트리플 앱 설치하기</Container>
100+
<GoAppButton src="https://assets.triple.guide/images/[email protected]" />
101+
</a>
102+
</InstallDescription>
103+
<Description>가이드북, 일정짜기, 길찾기, 맛집</Description>
104+
</Container>
105+
<Container floated="right" onClick={onClose}>
106+
<CloseButton src="https://assets.triple.guide/images/[email protected]" />
107+
</Container>
108+
</FloatingButton>
109+
) : null
110+
}

0 commit comments

Comments
 (0)