Skip to content

Commit

Permalink
Merge pull request #34 from dokar3/v0.4.0-alpha
Browse files Browse the repository at this point in the history
V0.4.0 alpha
  • Loading branch information
dokar3 committed Aug 12, 2022
2 parents 765ee2a + eda4ab3 commit 28b1ae5
Show file tree
Hide file tree
Showing 16 changed files with 673 additions and 283 deletions.
59 changes: 48 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,55 @@ implementation "io.github.dokar3:chiptextfield:latest_version"
**Default (filled style)**

```kotlin
val state = rememberChipTextFieldState<Chip>()
ChipTextField(state = state, onCreateChip = ::Chip)
var value by remember { mutableStateOf("") }
val state = rememberChipTextFieldState<Chip>(
value = value,
onValueChange = { value = it },
)
ChipTextField(
state = state,
onSubmit = {
state.addChip(Chip(value))
value = ""
},
)
```

![](/images/screenshot_filled.jpg)

**Outlined**

```kotlin
val state = rememberChipTextFieldState<Chip>()
OutlinedChipTextField(state = state, onCreateChip = ::Chip)
var value by remember { mutableStateOf("") }
val state = rememberChipTextFieldState<Chip>(
value = value,
onValueChange = { value = it },
)
OutlinedChipTextField(
state = state,
onSubmit = {
state.addChip(Chip(value))
value = ""
},
)
```

![](/images/screenshot_outlined.jpg)

**Need a classic underline style?**

```kotlin
val state = rememberChipTextFieldState<Chip>()
var value by remember { mutableStateOf("") }
val state = rememberChipTextFieldState<Chip>(
value = value,
onValueChange = { value = it },
)
ChipTextField(
state = state,
onCreateChip = ::Chip,
onSubmit = {
state.addChip(Chip(value))
value = ""
},
colors = TextFieldDefaults.textFieldColors(
backgroundColor = Color.Transparent
),
Expand All @@ -51,11 +78,14 @@ class CheckableChip(text: String, isChecked: Boolean = false) : Chip(text) {
var isChecked by mutableStateOf(isChecked)
}

val state = rememberChipTextFieldState<CheckableChip>()
val state = rememberChipTextFieldState(
value = "",
onValueChange = {},
chips = listOf(CheckableChip(""), ...),
)
BasicChipTextField(
state = state,
onCreateChip = ::CheckableChip,
enabled = false, // Disable editing to handle clicks
readOnly = true, // Disable editing
chipLeadingIcon = { chip -> CheckIcon(chip) }, // Show check icon if checked
chipTrailingIcon = {}, // Hide default close button
onChipClick = { chip -> chip.isChecked = !chip.isChecked }
Expand All @@ -72,10 +102,17 @@ fun CheckIcon(chip: CheckableChip, modifier: Modifier = Modifier) { ... }
```kotlin
class AvatarChip(text: String, val avatarUrl: String) : Chip(text)

val state = rememberChipTextFieldState<AvatarChip>()
var value by remember { mutableStateOf("") }
val state = rememberChipTextFieldState<AvatarChip>(
value = value,
onValueChange = { value = it },
)
ChipTextField(
state = state,
onCreateChip = { text -> AvatarChip(text, avatarUrl) },
onSubmit = {
state.addChip(AvatarChip(value, AVATAR_URL))
value = ""
},
chipLeadingIcon = { chip -> Avatar(chip) } // Load and display avatar
)

Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
compose_version = '1.2.0'
compose_compiler_version = '1.2.0'
kotlin_version = '1.7.0'
accompanist_version = '0.25.0'
compose_version = '1.2.1'
compose_compiler_version = '1.3.0'
kotlin_version = '1.7.10'
accompanist_version = '0.25.1'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
classpath 'com.android.tools.build:gradle:7.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ kotlin.code.style=official

GROUP=io.github.dokar3
POM_ARTIFACT_ID=chiptextfield
VERSION_NAME=0.3.0
VERSION_NAME=0.4.0-alpha

POM_NAME=ChipTextField
POM_DESCRIPTION=Editable chip layout in Jetpack Compose.
Expand Down
Loading

0 comments on commit 28b1ae5

Please sign in to comment.