Skip to content

Commit 2352985

Browse files
committed
[NDGL-51] NDGLOutlinedButton 추가
1 parent bef1719 commit 2352985

1 file changed

Lines changed: 132 additions & 0 deletions

File tree

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package com.yapp.ndgl.core.ui.designsystem
2+
3+
import androidx.annotation.DrawableRes
4+
import androidx.compose.foundation.background
5+
import androidx.compose.foundation.border
6+
import androidx.compose.foundation.clickable
7+
import androidx.compose.foundation.layout.Arrangement
8+
import androidx.compose.foundation.layout.Row
9+
import androidx.compose.foundation.layout.height
10+
import androidx.compose.foundation.layout.padding
11+
import androidx.compose.foundation.layout.size
12+
import androidx.compose.foundation.shape.RoundedCornerShape
13+
import androidx.compose.material3.Icon
14+
import androidx.compose.material3.Text
15+
import androidx.compose.runtime.Composable
16+
import androidx.compose.ui.Alignment
17+
import androidx.compose.ui.Modifier
18+
import androidx.compose.ui.draw.clip
19+
import androidx.compose.ui.graphics.Color
20+
import androidx.compose.ui.graphics.vector.ImageVector
21+
import androidx.compose.ui.res.vectorResource
22+
import androidx.compose.ui.tooling.preview.Preview
23+
import androidx.compose.ui.unit.dp
24+
import com.yapp.ndgl.core.ui.R
25+
import com.yapp.ndgl.core.ui.theme.NDGLTheme
26+
27+
object NDGLOutlinedButtonAttr {
28+
enum class Status {
29+
ACTIVE,
30+
DISABLED,
31+
}
32+
}
33+
34+
@Composable
35+
fun NDGLOutlinedButton(
36+
status: NDGLOutlinedButtonAttr.Status,
37+
label: String,
38+
onClick: () -> Unit,
39+
modifier: Modifier = Modifier,
40+
@DrawableRes leadingIcon: Int? = null,
41+
@DrawableRes trailingIcon: Int? = null,
42+
) {
43+
val contentColor = status.contentColor()
44+
45+
Row(
46+
modifier = modifier
47+
.height(40.dp)
48+
.clip(RoundedCornerShape(8.dp))
49+
.background(status.containerColor())
50+
.border(
51+
width = 1.dp,
52+
color = NDGLTheme.colors.black200,
53+
shape = RoundedCornerShape(8.dp),
54+
)
55+
.clickable(
56+
enabled = status != NDGLOutlinedButtonAttr.Status.DISABLED,
57+
onClick = onClick,
58+
)
59+
.padding(horizontal = 16.dp, vertical = 8.dp),
60+
horizontalArrangement = Arrangement.spacedBy(
61+
space = 8.dp,
62+
alignment = Alignment.CenterHorizontally,
63+
),
64+
verticalAlignment = Alignment.CenterVertically,
65+
) {
66+
leadingIcon?.let { icon ->
67+
Icon(
68+
imageVector = ImageVector.vectorResource(icon),
69+
contentDescription = null,
70+
modifier = Modifier.size(20.dp),
71+
tint = contentColor,
72+
)
73+
}
74+
75+
Text(
76+
text = label,
77+
style = NDGLTheme.typography.bodyMdSemiBold,
78+
color = contentColor,
79+
)
80+
81+
trailingIcon?.let { icon ->
82+
Icon(
83+
imageVector = ImageVector.vectorResource(icon),
84+
contentDescription = null,
85+
modifier = Modifier.size(20.dp),
86+
tint = contentColor,
87+
)
88+
}
89+
}
90+
}
91+
92+
@Composable
93+
private fun NDGLOutlinedButtonAttr.Status.containerColor(): Color {
94+
return when (this) {
95+
NDGLOutlinedButtonAttr.Status.ACTIVE -> NDGLTheme.colors.white
96+
NDGLOutlinedButtonAttr.Status.DISABLED -> NDGLTheme.colors.black300
97+
}
98+
}
99+
100+
@Composable
101+
private fun NDGLOutlinedButtonAttr.Status.contentColor(): Color {
102+
return when (this) {
103+
NDGLOutlinedButtonAttr.Status.ACTIVE -> NDGLTheme.colors.black600
104+
NDGLOutlinedButtonAttr.Status.DISABLED -> NDGLTheme.colors.black400
105+
}
106+
}
107+
108+
@Preview
109+
@Composable
110+
private fun NDGLOutlinedButtonActivePreview() {
111+
NDGLTheme {
112+
NDGLOutlinedButton(
113+
status = NDGLOutlinedButtonAttr.Status.ACTIVE,
114+
label = "Active",
115+
leadingIcon = R.drawable.ic_20_tv,
116+
onClick = {},
117+
)
118+
}
119+
}
120+
121+
@Preview
122+
@Composable
123+
private fun NDGLOutlinedButtonDisabledPreview() {
124+
NDGLTheme {
125+
NDGLOutlinedButton(
126+
status = NDGLOutlinedButtonAttr.Status.DISABLED,
127+
label = "Disabled",
128+
leadingIcon = R.drawable.ic_20_tv,
129+
onClick = {},
130+
)
131+
}
132+
}

0 commit comments

Comments
 (0)