1
+ package com.yourssu.handy.compose
2
+
3
+ import androidx.compose.foundation.background
4
+ import androidx.compose.foundation.clickable
5
+ import androidx.compose.foundation.layout.Box
6
+ import androidx.compose.foundation.layout.Column
7
+ import androidx.compose.foundation.layout.Row
8
+ import androidx.compose.foundation.layout.Spacer
9
+ import androidx.compose.foundation.layout.fillMaxWidth
10
+ import androidx.compose.foundation.layout.height
11
+ import androidx.compose.foundation.layout.padding
12
+ import androidx.compose.foundation.layout.width
13
+ import androidx.compose.foundation.shape.RoundedCornerShape
14
+ import androidx.compose.runtime.Composable
15
+ import androidx.compose.ui.Alignment
16
+ import androidx.compose.ui.Modifier
17
+ import androidx.compose.ui.unit.dp
18
+ import com.yourssu.handy.compose.DialogDefaults.dialogButtonSpacing
19
+ import com.yourssu.handy.compose.DialogDefaults.dialogPadding
20
+ import com.yourssu.handy.compose.DialogDefaults.dialogTextInsidePadding
21
+ import com.yourssu.handy.compose.DialogDefaults.dialogWidth
22
+ import com.yourssu.handy.compose.button.BoxButton
23
+ import com.yourssu.handy.compose.button.BoxButtonSize
24
+ import com.yourssu.handy.compose.button.BoxButtonType
25
+ import com.yourssu.handy.compose.foundation.HandyTypography
26
+ import com.yourssu.handy.compose.foundation.Radius
27
+ import com.yourssu.handy.compose.icons.HandyIcons
28
+ import com.yourssu.handy.compose.icons.filled.Close
29
+
30
+
31
+ /* *
32
+ * OneButtonDialog : 선택 버튼이 하나 있는 Dialog 입니다.
33
+ *
34
+ * @param title Dialog 제목 text
35
+ * @param positiveText 확인 버튼 text
36
+ * @param onPositiveClick 확인 버튼 클릭 시 실행되는 함수
37
+ * @param onDismiss 닫기(X) 버튼 클릭시 실행되는 함수
38
+ * @param description Dialog 안의 설명 text (optional)
39
+ * @param content Dialog 안의 content. 주로 이미지가 들어감(optional)
40
+ **/
41
+ @Composable
42
+ fun OneButtonDialog (
43
+ title : String ,
44
+ positiveText : String ,
45
+ onPositiveClick : () -> Unit ,
46
+ onDismiss : () -> Unit ,
47
+ modifier : Modifier = Modifier ,
48
+ description : String? ,
49
+ content : @Composable (() -> Unit )? = null,
50
+ ) {
51
+ Box (
52
+ modifier = modifier
53
+ .background(
54
+ color = HandyTheme .colors.bgBasicDefault,
55
+ shape = RoundedCornerShape (Radius .XL .dp)
56
+ )
57
+ .width(dialogWidth)
58
+ .padding(dialogPadding),
59
+ ) {
60
+ Column {
61
+ Row (
62
+ modifier = Modifier .fillMaxWidth(),
63
+ ) {
64
+ Text (
65
+ text = title,
66
+ style = HandyTypography .T1Sb20 ,
67
+ color = HandyTheme .colors.textBasicPrimary,
68
+ maxLines = 3 ,
69
+ modifier = Modifier
70
+ .weight(1f )
71
+ )
72
+
73
+ Icon (
74
+ imageVector = HandyIcons .Filled .Close ,
75
+ contentDescription = " Close" ,
76
+ modifier = Modifier .clickable { onDismiss() }
77
+ )
78
+ }
79
+
80
+ Spacer (modifier = Modifier .height(dialogTextInsidePadding))
81
+
82
+ if (description != null ) {
83
+ Text (text = description)
84
+ }
85
+
86
+ Spacer (modifier = Modifier .height(dialogPadding))
87
+
88
+ if (content != null ) {
89
+ Box (
90
+ modifier = Modifier
91
+ .align(Alignment .CenterHorizontally )
92
+ .padding(bottom = dialogPadding)
93
+ ) {
94
+ content()
95
+ }
96
+ }
97
+
98
+ BoxButton (
99
+ modifier = Modifier .fillMaxWidth(),
100
+ text = positiveText,
101
+ onClick = { onPositiveClick() },
102
+ sizeType = BoxButtonSize .L ,
103
+ )
104
+ }
105
+ }
106
+ }
107
+
108
+
109
+ /* *
110
+ * TwoButtonDialog : 버튼이 두개 있는 다이알로그 입니다.
111
+ *
112
+ * @param title Dialog 제목 text
113
+ * @param positiveText 확인 버튼 text
114
+ * @param negativeText 취소 버튼 text
115
+ * @param onPositiveClick 확인 버튼 클릭 시 실행되는 함수
116
+ * @param onNegativeClick 취소 버튼 클릭 시 실행되는 함수
117
+ * @param onDismiss 닫기(X) 버튼 클릭시 실행되는 함수
118
+ * @param description Dialog 안의 설명 text (optional)
119
+ * @param content Dialog 안의 content. 주로 이미지가 들어감(optional)
120
+ **/
121
+ @Composable
122
+ fun TwoButtonDialog (
123
+ title : String ,
124
+ positiveText : String ,
125
+ negativeText : String ,
126
+ onPositiveClick : () -> Unit ,
127
+ onNegativeClick : () -> Unit ,
128
+ onDismiss : () -> Unit ,
129
+ modifier : Modifier = Modifier ,
130
+ description : String? ,
131
+ content : @Composable (() -> Unit )? = null,
132
+ ) {
133
+ Box (
134
+ modifier = modifier
135
+ .background(
136
+ color = HandyTheme .colors.bgBasicDefault,
137
+ shape = RoundedCornerShape (Radius .XL .dp)
138
+ )
139
+ .width(dialogWidth)
140
+ .padding(dialogPadding),
141
+ ) {
142
+ Column {
143
+ Row (
144
+ modifier = Modifier .fillMaxWidth(),
145
+ ) {
146
+ Text (
147
+ text = title,
148
+ style = HandyTypography .T1Sb20 ,
149
+ color = HandyTheme .colors.textBasicPrimary,
150
+ maxLines = 3 ,
151
+ modifier = Modifier
152
+ .weight(1f )
153
+ )
154
+
155
+ Icon (
156
+ imageVector = HandyIcons .Filled .Close ,
157
+ contentDescription = " Close" ,
158
+ modifier = Modifier .clickable { onDismiss() }
159
+ )
160
+ }
161
+
162
+ Spacer (modifier = Modifier .height(dialogTextInsidePadding))
163
+
164
+ if (description != null ) {
165
+ Text (text = description)
166
+ }
167
+
168
+ Spacer (modifier = Modifier .height(dialogPadding))
169
+
170
+ if (content != null ) {
171
+ Box (
172
+ Modifier
173
+ .align(Alignment .CenterHorizontally )
174
+ .padding(bottom = dialogPadding)
175
+ ) {
176
+ content()
177
+ }
178
+ }
179
+
180
+ Row (
181
+ modifier = Modifier .align(Alignment .CenterHorizontally )
182
+ ) {
183
+ BoxButton (
184
+ modifier = Modifier .weight(1f ),
185
+ text = negativeText,
186
+ onClick = { onNegativeClick() },
187
+ sizeType = BoxButtonSize .L ,
188
+ buttonType = BoxButtonType .Secondary
189
+ )
190
+
191
+ Spacer (modifier = Modifier .width(dialogButtonSpacing))
192
+
193
+ BoxButton (
194
+ modifier = Modifier .weight(1f ),
195
+ text = positiveText,
196
+ onClick = { onPositiveClick() },
197
+ sizeType = BoxButtonSize .L ,
198
+ )
199
+ }
200
+ }
201
+ }
202
+
203
+ }
204
+
205
+ object DialogDefaults {
206
+ val dialogWidth = 296 .dp
207
+ val dialogPadding = 20 .dp
208
+ val dialogTextInsidePadding = 16 .dp
209
+ val dialogButtonSpacing = 8 .dp
210
+ }
0 commit comments