Skip to content

Commit af57922

Browse files
committed
[NDGL-51] chore: NDGLModal 추가
1 parent bed736e commit af57922

File tree

1 file changed

+169
-0
lines changed
  • core/ui/src/main/java/com/yapp/ndgl/core/ui/designsystem

1 file changed

+169
-0
lines changed
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
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+
Text(
72+
text = title,
73+
modifier = Modifier.fillMaxWidth(),
74+
color = NDGLTheme.colors.black900,
75+
textAlign = TextAlign.Center,
76+
style = NDGLTheme.typography.subtitleLgSemiBold,
77+
)
78+
Text(
79+
text = body,
80+
modifier = Modifier
81+
.fillMaxWidth()
82+
.padding(top = 16.dp),
83+
color = NDGLTheme.colors.black500,
84+
textAlign = TextAlign.Center,
85+
style = NDGLTheme.typography.bodyLgMedium,
86+
)
87+
description?.let {
88+
Text(
89+
text = it,
90+
modifier = Modifier
91+
.fillMaxWidth()
92+
.padding(top = 12.dp),
93+
color = NDGLTheme.colors.black400,
94+
textAlign = TextAlign.Center,
95+
style = NDGLTheme.typography.bodyMdMedium,
96+
)
97+
}
98+
}
99+
}
100+
101+
@Composable
102+
private fun ModalButtons(
103+
onDismissRequest: () -> Unit,
104+
positiveButtonText: String,
105+
onPositiveButtonClick: () -> Unit,
106+
negativeButtonText: String?,
107+
onNegativeButtonClick: (() -> Unit),
108+
) {
109+
Row(
110+
modifier = Modifier.fillMaxWidth(),
111+
horizontalArrangement = Arrangement.spacedBy(16.dp),
112+
) {
113+
if (negativeButtonText != null) {
114+
NDGLCTAButton(
115+
type = NDGLCTAButtonAttr.Type.SECONDARY,
116+
size = NDGLCTAButtonAttr.Size.MEDIUM,
117+
status = NDGLCTAButtonAttr.Status.ACTIVE,
118+
label = negativeButtonText,
119+
onClick = {
120+
onNegativeButtonClick()
121+
onDismissRequest()
122+
},
123+
modifier = Modifier.weight(1f),
124+
)
125+
}
126+
NDGLCTAButton(
127+
type = NDGLCTAButtonAttr.Type.PRIMARY,
128+
size = NDGLCTAButtonAttr.Size.MEDIUM,
129+
status = NDGLCTAButtonAttr.Status.ACTIVE,
130+
label = positiveButtonText,
131+
onClick = {
132+
onPositiveButtonClick()
133+
onDismissRequest()
134+
},
135+
modifier = Modifier.weight(1f),
136+
)
137+
}
138+
}
139+
140+
@Preview(showBackground = true)
141+
@Composable
142+
private fun NDGLModalWithDescriptionPreview() {
143+
NDGLTheme {
144+
NDGLModal(
145+
onDismissRequest = {},
146+
title = "장소 변경",
147+
body = "장소를 다음과 같이 변경할까요?",
148+
description = "젤라테리아 파씨 (Gelateria Fassi) → 콜로세움 (colosseo)",
149+
negativeButtonText = "취소",
150+
onNegativeButtonClick = {},
151+
positiveButtonText = "변경하기",
152+
onPositiveButtonClick = {},
153+
)
154+
}
155+
}
156+
157+
@Preview(showBackground = true)
158+
@Composable
159+
private fun NDGLModalWithoutDescriptionPreview() {
160+
NDGLTheme {
161+
NDGLModal(
162+
onDismissRequest = {},
163+
title = "장소 변경",
164+
body = "장소를 다음과 같이 변경할까요?",
165+
positiveButtonText = "변경하기",
166+
onPositiveButtonClick = {},
167+
)
168+
}
169+
}

0 commit comments

Comments
 (0)