Skip to content

Commit d43dccf

Browse files
committed
Add ui-components
1 parent 29c7dda commit d43dccf

File tree

13 files changed

+176
-1
lines changed

13 files changed

+176
-1
lines changed

android/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/.idea/navEditor.xml
99
/.idea/assetWizardSettings.xml
1010
.DS_Store
11-
/build
11+
build
1212
/app/release/*
1313
/captures
1414
.externalNativeBuild
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
plugins {
2+
id("com.android.library")
3+
alias(libs.plugins.kotlin.android)
4+
alias(libs.plugins.compose.compiler)
5+
alias(libs.plugins.paparazzi)
6+
id("com.emergetools.paparazzi.preview-scanner")
7+
}
8+
9+
android {
10+
namespace = "com.emergetools.hackernews.ui.components"
11+
compileSdk = 36
12+
13+
defaultConfig {
14+
minSdk = 30
15+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
16+
}
17+
18+
buildFeatures {
19+
compose = true
20+
}
21+
22+
compileOptions {
23+
sourceCompatibility = JavaVersion.VERSION_17
24+
targetCompatibility = JavaVersion.VERSION_17
25+
}
26+
27+
kotlinOptions {
28+
jvmTarget = JavaVersion.VERSION_17.toString()
29+
}
30+
}
31+
32+
paparazziPreviewScanner {
33+
scanPackages.addAll("com.emergetools.hackernews.ui.components")
34+
}
35+
36+
dependencies {
37+
implementation(libs.androidx.core.ktx)
38+
implementation(platform(libs.androidx.compose.bom))
39+
implementation(libs.androidx.ui)
40+
implementation(libs.androidx.ui.graphics)
41+
implementation(libs.androidx.ui.tooling.preview)
42+
implementation(libs.androidx.material3)
43+
44+
debugImplementation(libs.androidx.ui.tooling)
45+
debugImplementation(libs.androidx.ui.test.manifest)
46+
47+
testImplementation(libs.junit)
48+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
</manifest>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.emergetools.hackernews.ui.components
2+
3+
import androidx.compose.foundation.layout.padding
4+
import androidx.compose.material3.Button
5+
import androidx.compose.material3.MaterialTheme
6+
import androidx.compose.material3.Surface
7+
import androidx.compose.material3.Text
8+
import androidx.compose.runtime.Composable
9+
import androidx.compose.ui.Modifier
10+
import androidx.compose.ui.tooling.preview.PreviewLightDark
11+
import androidx.compose.ui.unit.dp
12+
13+
@Composable
14+
fun PrimaryButton(
15+
text: String,
16+
onClick: () -> Unit,
17+
modifier: Modifier = Modifier,
18+
enabled: Boolean = true
19+
) {
20+
Button(
21+
onClick = onClick,
22+
modifier = modifier,
23+
enabled = enabled
24+
) {
25+
Text(text = text)
26+
}
27+
}
28+
29+
@PreviewLightDark
30+
@Composable
31+
fun PrimaryButtonPreview() {
32+
MaterialTheme {
33+
Surface {
34+
PrimaryButton(
35+
text = "Click Me",
36+
onClick = {},
37+
modifier = Modifier.padding(16.dp)
38+
)
39+
}
40+
}
41+
}
42+
43+
@PreviewLightDark
44+
@Composable
45+
fun PrimaryButtonDisabledPreview() {
46+
MaterialTheme {
47+
Surface {
48+
PrimaryButton(
49+
text = "Disabled Button",
50+
onClick = {},
51+
enabled = false,
52+
modifier = Modifier.padding(16.dp)
53+
)
54+
}
55+
}
56+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.emergetools.hackernews.ui.components
2+
3+
import androidx.compose.foundation.layout.Column
4+
import androidx.compose.foundation.layout.fillMaxWidth
5+
import androidx.compose.foundation.layout.padding
6+
import androidx.compose.material3.Card
7+
import androidx.compose.material3.CardDefaults
8+
import androidx.compose.material3.MaterialTheme
9+
import androidx.compose.material3.Surface
10+
import androidx.compose.material3.Text
11+
import androidx.compose.runtime.Composable
12+
import androidx.compose.ui.Modifier
13+
import androidx.compose.ui.tooling.preview.PreviewLightDark
14+
import androidx.compose.ui.unit.dp
15+
16+
@Composable
17+
fun InfoCard(
18+
title: String,
19+
content: String,
20+
modifier: Modifier = Modifier
21+
) {
22+
Card(
23+
modifier = modifier.fillMaxWidth(),
24+
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp)
25+
) {
26+
Column(
27+
modifier = Modifier.padding(16.dp)
28+
) {
29+
Text(
30+
text = title,
31+
style = MaterialTheme.typography.titleMedium
32+
)
33+
Text(
34+
text = content,
35+
style = MaterialTheme.typography.bodyMedium,
36+
modifier = Modifier.padding(top = 8.dp)
37+
)
38+
}
39+
}
40+
}
41+
42+
@PreviewLightDark
43+
@Composable
44+
fun InfoCardPreview() {
45+
MaterialTheme {
46+
Surface {
47+
InfoCard(
48+
title = "Sample Title",
49+
content = "This is some sample content for the card component.",
50+
modifier = Modifier.padding(16.dp)
51+
)
52+
}
53+
}
54+
}
55+
56+
@PreviewLightDark
57+
@Composable
58+
fun InfoCardLongContentPreview() {
59+
MaterialTheme {
60+
Surface {
61+
InfoCard(
62+
title = "Long Content Example",
63+
content = "This is a much longer piece of content that demonstrates how the card component handles multiple lines of text. It should wrap properly and maintain good readability.",
64+
modifier = Modifier.padding(16.dp)
65+
)
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)