Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Divider 제작 #16

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/git_toolbox_blame.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions app/src/main/kotlin/com/yourssu/handy/demo/DividerPreview.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.yourssu.handy.demo

import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.yourssu.handy.compose.Divider
import com.yourssu.handy.compose.DividerSize
import com.yourssu.handy.compose.HandyTheme
import com.yourssu.handy.compose.Text

@Preview(showBackground = true)
@Composable
fun DividerExample() {
Column {
Text("Section 1")
Divider(
dividerSize = DividerSize.TWO,
width = 100.dp,
color = HandyTheme.colors.bgBasicBlack
)
Text("Section 2")
Divider(
dividerSize = DividerSize.FOUR,
width = 200.dp,
color = HandyTheme.colors.bgBasicBlack
)
Text("Section 3")
Divider(dividerSize = DividerSize.EIGHT, color = HandyTheme.colors.bgBasicBlack)
}
}
65 changes: 65 additions & 0 deletions compose/src/main/kotlin/com/yourssu/handy/compose/Divider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.yourssu.handy.compose

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

/**
* Divider의 두께를 정의하는 enum class
*/
enum class DividerSize(
val size: Dp
) {
ONE(1.dp),
TWO(2.dp),
FOUR(4.dp),
EIGHT(8.dp),
}

/**
* width를 지정할 수 있는 Divider
* @param width Divider의 너비
* @param color Divider의 색상
* @param dividerSize Divider의 두께
*/
@Composable
fun Divider(
dividerSize: DividerSize,
modifier: Modifier = Modifier,
width: Dp = 0.dp,
color: Color = HandyTheme.colors.bgBasicStrong,
) {
Box(
modifier = modifier
.width(width)
.height(dividerSize.size)
.background(color)
)
}

/**
* width를 지정할 수 없는 Divider
* 기본적으로 fillMaxWidth를 사용
* @param color Divider의 색상
* @param dividerSize Divider의 두께
*/
@Composable
fun Divider(
dividerSize: DividerSize,
modifier: Modifier = Modifier,
color: Color = HandyTheme.colors.bgBasicStrong,
) {
Box(
modifier = modifier
.fillMaxWidth()
.height(dividerSize.size)
.background(color)
)
}