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

[MOB-1901] 토글 이모지 버튼 그룹 추가 #69

Merged
merged 3 commits into from
Sep 13, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package io.channel.bezier.compose.component.toggle_emoji_button_group

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.channel.bezier.BezierTheme
import io.channel.bezier.compose.component.toggle_emoji_button_group.property.BezierToggleEmojiButtonGroupFillDirectionType
import io.channel.bezier.compose.component.toggle_emoji_button_group.source.toggle_emoji_button.BezierToggleEmojiButton
import io.channel.bezier.compose.component.toggle_emoji_button_group.source.toggle_emoji_button.properties.BezierToggleEmojiButtonVariant
import io.channel.bezier.extension.thenIf

@Composable
fun BezierToggleEmojiButtonGroup(
emojis: List<String>,
type: BezierToggleEmojiButtonGroupFillDirectionType,
onEmojiClick: (index: Int) -> Unit,
modifier: Modifier = Modifier,
selectedIndex: Int? = null,
) {
val horizontalArrangement = when (type) {
BezierToggleEmojiButtonGroupFillDirectionType.Undefined -> Arrangement.spacedBy(
space = 6.dp,
alignment = Alignment.CenterHorizontally,
)

BezierToggleEmojiButtonGroupFillDirectionType.Horizontal -> Arrangement.spacedBy(6.dp)
BezierToggleEmojiButtonGroupFillDirectionType.All -> Arrangement.spacedBy(6.dp)
}

Row(
modifier = modifier,
horizontalArrangement = horizontalArrangement,
) {
emojis.forEachIndexed { index, emoji ->
BezierToggleEmojiButton(
selected = index == selectedIndex,
name = emoji,
variant = BezierToggleEmojiButtonVariant.Primary,
onClick = { onEmojiClick.invoke(index) },
modifier = Modifier
.thenIf(type == BezierToggleEmojiButtonGroupFillDirectionType.All) {
aspectRatio(1f).weight(1f)
}
.thenIf(type == BezierToggleEmojiButtonGroupFillDirectionType.Horizontal) {
weight(1f)
},
)
}
}
}

@Preview(showBackground = true)
@Composable
private fun BezierToggleEmojiButtonGroupPreview() {
BezierTheme {
Column(
modifier = Modifier.padding(10.dp),
verticalArrangement = Arrangement.spacedBy(10.dp),
) {
val emojis = remember { listOf("1", "2", "3", "4") }
var selectedIndex by remember { mutableStateOf<Int?>(null) }

BezierToggleEmojiButtonGroup(
emojis = emojis,
type = BezierToggleEmojiButtonGroupFillDirectionType.Undefined,
onEmojiClick = { selectedIndex = it },
selectedIndex = selectedIndex,
modifier = Modifier.fillMaxWidth(),
)

BezierToggleEmojiButtonGroup(
emojis = emojis,
type = BezierToggleEmojiButtonGroupFillDirectionType.Horizontal,
onEmojiClick = { selectedIndex = it },
selectedIndex = selectedIndex,
modifier = Modifier.fillMaxWidth(),
)

BezierToggleEmojiButtonGroup(
emojis = emojis,
type = BezierToggleEmojiButtonGroupFillDirectionType.All,
onEmojiClick = { selectedIndex = it },
selectedIndex = selectedIndex,
modifier = Modifier.fillMaxWidth(),
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.channel.bezier.compose.component.toggle_emoji_button_group.property

enum class BezierToggleEmojiButtonGroupFillDirectionType {
Undefined,
Horizontal,
All,
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.channel.bezier.compose.component.toggle_emoji_button
package io.channel.bezier.compose.component.toggle_emoji_button_group.source.toggle_emoji_button

import androidx.compose.foundation.background
import androidx.compose.foundation.border
Expand All @@ -24,7 +24,7 @@ import androidx.compose.ui.unit.dp
import io.channel.bezier.BezierTheme
import io.channel.bezier.compose.component.emoji.BezierEmoji
import io.channel.bezier.compose.component.emoji.properties.BezierEmojiSize
import io.channel.bezier.compose.component.toggle_emoji_button.properties.BezierToggleEmojiButtonVariant
import io.channel.bezier.compose.component.toggle_emoji_button_group.source.toggle_emoji_button.properties.BezierToggleEmojiButtonVariant

@Composable
fun BezierToggleEmojiButton(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.channel.bezier.compose.component.toggle_emoji_button.properties
package io.channel.bezier.compose.component.toggle_emoji_button_group.source.toggle_emoji_button.properties

import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.Dp
Expand Down