Skip to content

Commit b57ed23

Browse files
committed
[NDGL-51] NDGLNavigationBar 추가
1 parent 2352985 commit b57ed23

1 file changed

Lines changed: 143 additions & 0 deletions

File tree

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package com.yapp.ndgl.core.ui.designsystem
2+
3+
import androidx.annotation.DrawableRes
4+
import androidx.compose.foundation.clickable
5+
import androidx.compose.foundation.layout.Arrangement
6+
import androidx.compose.foundation.layout.Row
7+
import androidx.compose.foundation.layout.RowScope
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.size
13+
import androidx.compose.foundation.shape.CircleShape
14+
import androidx.compose.material3.Icon
15+
import androidx.compose.material3.Text
16+
import androidx.compose.runtime.Composable
17+
import androidx.compose.ui.Alignment
18+
import androidx.compose.ui.Modifier
19+
import androidx.compose.ui.draw.clip
20+
import androidx.compose.ui.graphics.vector.ImageVector
21+
import androidx.compose.ui.res.vectorResource
22+
import androidx.compose.ui.text.style.TextAlign
23+
import androidx.compose.ui.tooling.preview.Preview
24+
import androidx.compose.ui.unit.dp
25+
import com.yapp.ndgl.core.ui.R
26+
import com.yapp.ndgl.core.ui.theme.NDGLTheme
27+
28+
object NDGLNavigationBarAttr {
29+
enum class TextAlignType {
30+
START,
31+
CENTER,
32+
}
33+
}
34+
35+
@Composable
36+
fun NDGLNavigationBar(
37+
textAlignType: NDGLNavigationBarAttr.TextAlignType,
38+
modifier: Modifier = Modifier,
39+
headline: String? = null,
40+
@DrawableRes leadingIcon: Int? = null,
41+
onLeadingIconClick: () -> Unit = {},
42+
trailingContents: (@Composable RowScope.() -> Unit)? = null,
43+
) {
44+
Row(
45+
modifier = modifier
46+
.fillMaxWidth()
47+
.height(48.dp)
48+
.padding(horizontal = 24.dp, vertical = 12.dp),
49+
horizontalArrangement = Arrangement.spacedBy(8.dp),
50+
verticalAlignment = Alignment.CenterVertically,
51+
) {
52+
leadingIcon?.let { icon ->
53+
NDGLNavigationIcon(
54+
icon = icon,
55+
onClick = onLeadingIconClick,
56+
)
57+
}
58+
59+
headline?.let { text ->
60+
Text(
61+
text = text,
62+
modifier = Modifier.weight(1f),
63+
style = NDGLTheme.typography.bodyLgMedium,
64+
color = NDGLTheme.colors.black700,
65+
textAlign = when (textAlignType) {
66+
NDGLNavigationBarAttr.TextAlignType.START -> TextAlign.Start
67+
NDGLNavigationBarAttr.TextAlignType.CENTER -> TextAlign.Center
68+
},
69+
)
70+
} ?: Spacer(modifier = Modifier.weight(1f))
71+
72+
trailingContents?.let { contents ->
73+
contents()
74+
}
75+
}
76+
}
77+
78+
@Composable
79+
fun NDGLNavigationIcon(
80+
@DrawableRes icon: Int,
81+
onClick: () -> Unit = {},
82+
) {
83+
Icon(
84+
imageVector = ImageVector.vectorResource(icon),
85+
contentDescription = null,
86+
modifier = Modifier
87+
.size(28.dp)
88+
.clip(CircleShape)
89+
.clickable(onClick = onClick),
90+
tint = NDGLTheme.colors.black700,
91+
)
92+
}
93+
94+
@Preview(showBackground = true)
95+
@Composable
96+
private fun NDGLNavigationBarCenterPreview() {
97+
NDGLTheme {
98+
NDGLNavigationBar(
99+
textAlignType = NDGLNavigationBarAttr.TextAlignType.CENTER,
100+
headline = "미리보기",
101+
leadingIcon = R.drawable.ic_28_chevron_left,
102+
trailingContents = {
103+
NDGLNavigationIcon(
104+
icon = R.drawable.ic_28_search,
105+
onClick = {},
106+
)
107+
NDGLNavigationIcon(
108+
icon = R.drawable.ic_28_settings,
109+
onClick = {},
110+
)
111+
},
112+
)
113+
}
114+
}
115+
116+
@Preview(showBackground = true)
117+
@Composable
118+
private fun NDGLNavigationBarStartPreview() {
119+
NDGLTheme {
120+
NDGLNavigationBar(
121+
textAlignType = NDGLNavigationBarAttr.TextAlignType.START,
122+
headline = "미리보기",
123+
leadingIcon = R.drawable.ic_28_chevron_left,
124+
)
125+
}
126+
}
127+
128+
@Preview(showBackground = true)
129+
@Composable
130+
private fun NDGLNavigationBarNoHeadlinePreview() {
131+
NDGLTheme {
132+
NDGLNavigationBar(
133+
textAlignType = NDGLNavigationBarAttr.TextAlignType.START,
134+
leadingIcon = R.drawable.ic_28_menu,
135+
trailingContents = {
136+
NDGLNavigationIcon(
137+
icon = R.drawable.ic_28_search,
138+
onClick = {},
139+
)
140+
},
141+
)
142+
}
143+
}

0 commit comments

Comments
 (0)