|
| 1 | +package com.ninecraft.booket.feature.login.component |
| 2 | + |
| 3 | +import androidx.annotation.StringRes |
| 4 | +import androidx.compose.foundation.background |
| 5 | +import androidx.compose.foundation.layout.Box |
| 6 | +import androidx.compose.foundation.layout.Column |
| 7 | +import androidx.compose.foundation.layout.height |
| 8 | +import androidx.compose.foundation.layout.offset |
| 9 | +import androidx.compose.foundation.layout.padding |
| 10 | +import androidx.compose.foundation.layout.width |
| 11 | +import androidx.compose.foundation.shape.RoundedCornerShape |
| 12 | +import androidx.compose.material3.Text |
| 13 | +import androidx.compose.runtime.Composable |
| 14 | +import androidx.compose.ui.Alignment |
| 15 | +import androidx.compose.ui.Modifier |
| 16 | +import androidx.compose.ui.draw.clip |
| 17 | +import androidx.compose.ui.draw.shadow |
| 18 | +import androidx.compose.ui.geometry.Size |
| 19 | +import androidx.compose.ui.graphics.Outline |
| 20 | +import androidx.compose.ui.graphics.Path |
| 21 | +import androidx.compose.ui.graphics.Shape |
| 22 | +import androidx.compose.ui.graphics.graphicsLayer |
| 23 | +import androidx.compose.ui.res.stringResource |
| 24 | +import androidx.compose.ui.unit.Density |
| 25 | +import androidx.compose.ui.unit.IntOffset |
| 26 | +import androidx.compose.ui.unit.LayoutDirection |
| 27 | +import androidx.compose.ui.unit.dp |
| 28 | +import com.ninecraft.booket.core.designsystem.ComponentPreview |
| 29 | +import com.ninecraft.booket.core.designsystem.theme.ReedTheme |
| 30 | +import com.ninecraft.booket.feature.login.R |
| 31 | + |
| 32 | +private val TriangleShape = object : Shape { |
| 33 | + override fun createOutline( |
| 34 | + size: Size, |
| 35 | + layoutDirection: LayoutDirection, |
| 36 | + density: Density, |
| 37 | + ): Outline { |
| 38 | + val path = Path().apply { |
| 39 | + // 왼쪽 위 |
| 40 | + moveTo(0f, 0f) |
| 41 | + // 오른쪽 위 |
| 42 | + lineTo(size.width, 0f) |
| 43 | + // 중앙 아래 (뾰족한 부분) |
| 44 | + lineTo(size.width / 2, size.height) |
| 45 | + // 닫기 |
| 46 | + close() |
| 47 | + } |
| 48 | + return Outline.Generic(path) |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +@Composable |
| 53 | +internal fun LoginTooltipBox( |
| 54 | + @StringRes messageResId: Int, |
| 55 | +) { |
| 56 | + Column(horizontalAlignment = Alignment.Start) { |
| 57 | + Box( |
| 58 | + Modifier |
| 59 | + .shadow(ReedTheme.radius.xs, RoundedCornerShape(ReedTheme.radius.xs), clip = false) |
| 60 | + .clip(RoundedCornerShape(ReedTheme.radius.xs)) |
| 61 | + .background(ReedTheme.colors.contentBrand) |
| 62 | + .padding( |
| 63 | + horizontal = ReedTheme.spacing.spacing3, |
| 64 | + vertical = ReedTheme.spacing.spacing2, |
| 65 | + ), |
| 66 | + ) { |
| 67 | + Text( |
| 68 | + text = stringResource(messageResId), |
| 69 | + color = ReedTheme.colors.contentInverse, |
| 70 | + style = ReedTheme.typography.label2Regular, |
| 71 | + ) |
| 72 | + } |
| 73 | + Box( |
| 74 | + Modifier |
| 75 | + .width(ReedTheme.spacing.spacing3) |
| 76 | + .height(ReedTheme.spacing.spacing3 / 2) |
| 77 | + .offset { |
| 78 | + IntOffset( |
| 79 | + x = 14.dp.roundToPx(), |
| 80 | + y = 0, |
| 81 | + ) |
| 82 | + } |
| 83 | + .graphicsLayer { |
| 84 | + shadowElevation = 8.dp.toPx() |
| 85 | + shape = TriangleShape |
| 86 | + clip = true |
| 87 | + } |
| 88 | + .background(ReedTheme.colors.contentBrand), |
| 89 | + ) |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +@ComponentPreview |
| 94 | +@Composable |
| 95 | +private fun RecordTooltipBoxPreview() { |
| 96 | + ReedTheme { |
| 97 | + LoginTooltipBox(messageResId = R.string.recent_login) |
| 98 | + } |
| 99 | +} |
0 commit comments