Skip to content

Chaintech-Network/CMP-autocomplete-search-box

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧩 CMPAutocompleteSearchBox

A clean, customizable Jetpack Compose Multiplatform search box with auto-complete suggestions.

Maven Central Kotlin Compose Multiplatform License

badge-android badge-ios

ComposeAutocompleteSearchBox


✨ Features

βœ… Customizable design (colors, icons, fonts, and sizes)
βœ… Smart auto-suggestion logic (startsWith)
βœ… Integrated clear and search icons
βœ… Keyboard β€œDone” handling included
βœ… Compose Multiplatform support (Android, Desktop, Web coming soon)


πŸ“¦ Installation

Add the dependency to your Gradle module:

dependencies {
    implementation("network.chaintech:cmp-autocomplete-search-box:1.0.0")
}

πŸš€ Quick Start

@Composable
fun MyScreen() {
    val searchText =  remember { mutableStateOf(TextFieldValue("")) }
    val suggestions = listOf("Kotlin", "Compose", "Android")

    SearchBox(
        searchText = searchText,
        suggestions = suggestions,
        onSearchTextChanged = {
            // Optional: trigger filtering logic here
        },
        onItemSelected = {
            // Handle selection (e.g., search or filter results)
        }
    )
}

🎨 Customization

🎨 Colors

Use SearchBoxColors to customize all color properties:

val customColors = SearchBoxColors(
    textColor = Color.Black,
    placeholderColor = Color.Gray,
    cursorColor = Color.DarkGray,
    backgroundColor = Color.White,
    borderColor = Color.LightGray,
    suggestionBoxBGColor = Color(0xFFEFEFEF)
)

πŸ“ Sizes

Control the height, border, and spacing via SearchBoxSizes:

val customSizes = SearchBoxSizes(
    height = 56.dp,
    borderWidth = 1.5.dp,
    cornerRadius = 20.dp,
    horizontalPadding = 16.dp
)

πŸ–ΌοΈ Icons

Provide your own composables for the icons using SearchBoxIcons:

val customIcons = SearchBoxIcons(
    searchIcon = { modifier ->
        Icon(Icons.Default.Search, contentDescription = "Search", modifier = modifier)
    },
    clearIcon = { modifier ->
        Icon(Icons.Default.Close, contentDescription = "Clear", modifier = modifier)
    }
)

Usage:

SearchBox(
    searchText = searchText,
    suggestions = suggestions,
    colors = customColors,
    sizes = customSizes,
    icons = customIcons
)

βš™οΈ Parameters Reference

Name Type Description
searchText MutableState<String> Current text entered in the box
suggestions List<String> Suggestion list used for autocomplete
onSearchTextChanged () -> Unit Triggered whenever text changes
onItemSelected () -> Unit Called when a suggestion is selected
placeholder String Placeholder text for the field
suggestionPlaceholder String Placeholder text shown beside suggestion
fontFamily FontFamily Font for text and placeholders
colors SearchBoxColors Defines all UI colors
sizes SearchBoxSizes Controls layout spacing and dimensions
icons SearchBoxIcons Provides composables for search/clear icons

🧠 Preview Example

@Preview
@Composable
fun SearchBoxPreview() {
    val searchState =  remember { mutableStateOf(TextFieldValue("")) }
    val sampleSuggestions = listOf("Kotlin", "Compose", "Android")

    SearchBox(
        searchText = searchState,
        suggestions = sampleSuggestions,
        placeholder = "Search topics..."
    )
}

Expected Output

SearchBox Screenshot

🧩 Components Overview

Component Description
SearchBox Main composable function
SearchBoxColors Color customization class
SearchBoxSizes Size customization class
SearchBoxIcons Icon customization class

πŸ“– Detailed Explanation

For an in-depth guide and detailed explanation, check out our comprehensive Medium Blog Post.

Medium

πŸ§‘β€πŸ’» Author

Chaintech Network

Stay connected and keep up with our latest innovations! πŸ’Ό Let's innovate together!

GitHub
LinkedIn Medium


🌟 Support

If you find this library useful:
⭐ Star the repo β†’ it helps others discover it!
πŸ’¬ Open an issue or PR if you’d like to contribute.

πŸ“„ License

Copyright 2025 Mobile Innovation Network

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published