Skip to content

Commit

Permalink
feat: add chips
Browse files Browse the repository at this point in the history
  • Loading branch information
vighnesh153 committed Nov 5, 2023
1 parent 6bebe7d commit 73ca641
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package com.google.jetcatalog

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.Clear
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material.icons.filled.Favorite
import androidx.compose.material.icons.filled.Settings
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.unit.dp
import androidx.tv.material3.AssistChip
import androidx.tv.material3.Button
import androidx.tv.material3.ButtonDefaults
import androidx.tv.material3.ExperimentalTvMaterial3Api
import androidx.tv.material3.FilterChip
import androidx.tv.material3.Icon
import androidx.tv.material3.IconButton
import androidx.tv.material3.IconButtonDefaults
import androidx.tv.material3.InputChip
import androidx.tv.material3.OutlinedButton
import androidx.tv.material3.OutlinedButtonDefaults
import androidx.tv.material3.OutlinedIconButton
import androidx.tv.material3.OutlinedIconButtonDefaults
import androidx.tv.material3.SuggestionChip
import androidx.tv.material3.Text
import androidx.tv.material3.WideButton

@OptIn(ExperimentalTvMaterial3Api::class)
@Composable
fun ChipsScreen() {
val actions = listOf(
ExampleAction(
title = "Assist Chip",
content = {
Row(
horizontalArrangement = Arrangement.spacedBy(20.dp),
verticalAlignment = Alignment.CenterVertically,
) {
AssistChip(onClick = { }) {
Text(text = "Label")
}

AssistChip(
onClick = { },
leadingIcon = editIcon
) {
Text(text = "Label")
}
}
}
),
ExampleAction(
title = "Filter Chip",
content = {
Row(
horizontalArrangement = Arrangement.spacedBy(20.dp),
verticalAlignment = Alignment.CenterVertically,
) {
var isSelected1 by remember { mutableStateOf(false) }
FilterChip(
selected = isSelected1,
onClick = { isSelected1 = !isSelected1 }
) {
Text(text = "Label")
}

var isSelected2 by remember { mutableStateOf(false) }
FilterChip(
selected = isSelected2,
onClick = { isSelected2 = !isSelected2 },
leadingIcon = checkIcon
) {
Text(text = "Label")
}
}
}
),
ExampleAction(
title = "Input Chip",
content = {
Row(
horizontalArrangement = Arrangement.spacedBy(20.dp),
verticalAlignment = Alignment.CenterVertically,
) {
var isSelected1 by remember { mutableStateOf(false) }
InputChip(
selected = isSelected1,
onClick = { isSelected1 = !isSelected1 }
) {
Text(text = "Label")
}

var isSelected2 by remember { mutableStateOf(false) }
InputChip(
selected = isSelected2,
onClick = { isSelected2 = !isSelected2 },
leadingIcon = editIcon,
trailingIcon = clearIcon
) {
Text(text = "Label")
}
}
}
),
ExampleAction(
title = "Suggestion Chip",
content = {
SuggestionChip(onClick = { }) {
Text(text = "Label")
}
}
),
)

ExamplesScreenWithDottedBackground(actions)
}

@OptIn(ExperimentalTvMaterial3Api::class)
private val editIcon = @Composable {
Icon(
imageVector = Icons.Default.Edit,
contentDescription = "Edit icon",
)
}

@OptIn(ExperimentalTvMaterial3Api::class)
private val checkIcon = @Composable {
Icon(
imageVector = Icons.Default.Check,
contentDescription = "Check icon",
)
}

@OptIn(ExperimentalTvMaterial3Api::class)
private val clearIcon = @Composable {
Icon(
imageVector = Icons.Default.Clear,
contentDescription = "Clear icon",
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ enum class NavGraph(
routeName = "chips",
composable = { appBar ->
appBar()
WorkInProgressScreen()
ChipsScreen()
}
),
Lists(
Expand Down

0 comments on commit 73ca641

Please sign in to comment.