Skip to content

Commit 8c2ec7f

Browse files
committed
[NDGL-51] NDGLModal 추가
1 parent d5bb4fc commit 8c2ec7f

1 file changed

Lines changed: 171 additions & 0 deletions

File tree

  • core/ui/src/main/java/com/yapp/ndgl/core/ui/designSystem
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package com.yapp.ndgl.core.ui.designsystem
2+
3+
import androidx.compose.foundation.layout.Arrangement
4+
import androidx.compose.foundation.layout.Column
5+
import androidx.compose.foundation.layout.Row
6+
import androidx.compose.foundation.layout.fillMaxWidth
7+
import androidx.compose.foundation.layout.padding
8+
import androidx.compose.foundation.layout.wrapContentHeight
9+
import androidx.compose.foundation.shape.RoundedCornerShape
10+
import androidx.compose.material3.Surface
11+
import androidx.compose.material3.Text
12+
import androidx.compose.runtime.Composable
13+
import androidx.compose.ui.Alignment
14+
import androidx.compose.ui.Modifier
15+
import androidx.compose.ui.text.style.TextAlign
16+
import androidx.compose.ui.tooling.preview.Preview
17+
import androidx.compose.ui.unit.dp
18+
import androidx.compose.ui.window.Dialog
19+
import com.yapp.ndgl.core.ui.theme.NDGLTheme
20+
21+
@Composable
22+
fun NDGLModal(
23+
onDismissRequest: () -> Unit,
24+
title: String,
25+
body: String,
26+
positiveButtonText: String,
27+
onPositiveButtonClick: () -> Unit,
28+
modifier: Modifier = Modifier,
29+
description: String? = null,
30+
negativeButtonText: String? = null,
31+
onNegativeButtonClick: (() -> Unit) = {},
32+
) {
33+
Dialog(onDismissRequest = onDismissRequest) {
34+
Surface(
35+
modifier = modifier.wrapContentHeight(),
36+
shape = RoundedCornerShape(8.dp),
37+
color = NDGLTheme.colors.white,
38+
shadowElevation = 16.dp,
39+
) {
40+
Column(
41+
modifier = Modifier
42+
.padding(horizontal = 28.dp)
43+
.padding(top = 28.dp, bottom = 24.dp),
44+
verticalArrangement = Arrangement.spacedBy(28.dp),
45+
horizontalAlignment = Alignment.CenterHorizontally,
46+
) {
47+
ModalContent(
48+
title = title,
49+
body = body,
50+
description = description,
51+
)
52+
ModalButtons(
53+
onDismissRequest = onDismissRequest,
54+
positiveButtonText = positiveButtonText,
55+
onPositiveButtonClick = onPositiveButtonClick,
56+
negativeButtonText = negativeButtonText,
57+
onNegativeButtonClick = onNegativeButtonClick,
58+
)
59+
}
60+
}
61+
}
62+
}
63+
64+
@Composable
65+
private fun ModalContent(
66+
title: String,
67+
body: String,
68+
description: String?,
69+
) {
70+
Column(
71+
verticalArrangement = Arrangement.spacedBy(16.dp),
72+
) {
73+
Text(
74+
text = title,
75+
modifier = Modifier.fillMaxWidth(),
76+
color = NDGLTheme.colors.black900,
77+
textAlign = TextAlign.Center,
78+
style = NDGLTheme.typography.subtitleLgSemiBold,
79+
)
80+
Text(
81+
text = body,
82+
modifier = Modifier
83+
.fillMaxWidth()
84+
.padding(top = 16.dp),
85+
color = NDGLTheme.colors.black500,
86+
textAlign = TextAlign.Center,
87+
style = NDGLTheme.typography.bodyLgMedium,
88+
)
89+
description?.let {
90+
Text(
91+
text = it,
92+
modifier = Modifier
93+
.fillMaxWidth()
94+
.padding(top = 12.dp),
95+
color = NDGLTheme.colors.black400,
96+
textAlign = TextAlign.Center,
97+
style = NDGLTheme.typography.bodyMdMedium,
98+
)
99+
}
100+
}
101+
}
102+
103+
@Composable
104+
private fun ModalButtons(
105+
onDismissRequest: () -> Unit,
106+
positiveButtonText: String,
107+
onPositiveButtonClick: () -> Unit,
108+
negativeButtonText: String?,
109+
onNegativeButtonClick: (() -> Unit),
110+
) {
111+
Row(
112+
modifier = Modifier.fillMaxWidth(),
113+
horizontalArrangement = Arrangement.spacedBy(16.dp),
114+
) {
115+
if (negativeButtonText != null) {
116+
NDGLCTAButton(
117+
type = NDGLCTAButtonAttr.Type.SECONDARY,
118+
size = NDGLCTAButtonAttr.Size.MEDIUM,
119+
status = NDGLCTAButtonAttr.Status.ACTIVE,
120+
label = negativeButtonText,
121+
onClick = {
122+
onNegativeButtonClick()
123+
onDismissRequest()
124+
},
125+
modifier = Modifier.weight(1f),
126+
)
127+
}
128+
NDGLCTAButton(
129+
type = NDGLCTAButtonAttr.Type.PRIMARY,
130+
size = NDGLCTAButtonAttr.Size.MEDIUM,
131+
status = NDGLCTAButtonAttr.Status.ACTIVE,
132+
label = positiveButtonText,
133+
onClick = {
134+
onPositiveButtonClick()
135+
onDismissRequest()
136+
},
137+
modifier = Modifier.weight(1f),
138+
)
139+
}
140+
}
141+
142+
@Preview(showBackground = true)
143+
@Composable
144+
private fun NDGLModalWithDescriptionPreview() {
145+
NDGLTheme {
146+
NDGLModal(
147+
onDismissRequest = {},
148+
title = "장소 변경",
149+
body = "장소를 다음과 같이 변경할까요?",
150+
description = "젤라테리아 파씨 (Gelateria Fassi) → 콜로세움 (colosseo)",
151+
negativeButtonText = "취소",
152+
onNegativeButtonClick = {},
153+
positiveButtonText = "변경하기",
154+
onPositiveButtonClick = {},
155+
)
156+
}
157+
}
158+
159+
@Preview(showBackground = true)
160+
@Composable
161+
private fun NDGLModalWithoutDescriptionPreview() {
162+
NDGLTheme {
163+
NDGLModal(
164+
onDismissRequest = {},
165+
title = "장소 변경",
166+
body = "장소를 다음과 같이 변경할까요?",
167+
positiveButtonText = "변경하기",
168+
onPositiveButtonClick = {},
169+
)
170+
}
171+
}

0 commit comments

Comments
 (0)