forked from microsoft/fluentui-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
V2BasicChipActivity.kt
234 lines (224 loc) · 9.96 KB
/
V2BasicChipActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package com.microsoft.fluentuidemo.demos
import android.os.Bundle
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Arrangement.Absolute.spacedBy
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Add
import androidx.compose.material.icons.outlined.ShoppingCart
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.saveable.listSaver
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.toMutableStateList
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.unit.dp
import com.microsoft.fluentui.theme.FluentTheme
import com.microsoft.fluentui.theme.token.FluentAliasTokens
import com.microsoft.fluentui.theme.token.FluentIcon
import com.microsoft.fluentui.theme.token.Icon
import com.microsoft.fluentui.theme.token.StateBrush
import com.microsoft.fluentui.theme.token.StateColor
import com.microsoft.fluentui.theme.token.controlTokens.BasicChipInfo
import com.microsoft.fluentui.theme.token.controlTokens.BasicChipTokens
import com.microsoft.fluentui.tokenized.controls.BasicChip
import com.microsoft.fluentui.tokenized.controls.Label
import com.microsoft.fluentuidemo.V2DemoActivity
class V2BasicChipActivity : V2DemoActivity() {
init {
setupActivity(this)
}
override val paramsUrl = "https://github.com/microsoft/fluentui-android/wiki/Controls#params-13"
override val controlTokensUrl =
"https://github.com/microsoft/fluentui-android/wiki/Controls#control-tokens-13"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setActivityContent {
CreateBasicChipActivityUI()
}
}
@Composable
private fun CreateBasicChipActivityUI() {
var selectedList = rememberSaveable(
saver = listSaver(
save = { stateList ->
if (stateList.isNotEmpty()) {
val first = stateList.first()
if (!canBeSaved(first)) {
throw IllegalStateException("${first::class} cannot be saved. By default only types which can be stored in the Bundle class can be saved.")
}
}
stateList.toList()
},
restore = { it.toMutableStateList() }
)) {
mutableStateListOf(
false,
false,
false,
false,
false,
false,
false,
false,
false,
false
)
}
class CustomChipToken1 : BasicChipTokens() {
@Composable
override fun backgroundBrush(basicChipInfo: BasicChipInfo): StateBrush {
return StateBrush(
rest = SolidColor(
FluentTheme.aliasTokens.neutralBackgroundColor[FluentAliasTokens.NeutralBackgroundColorTokens.Background5].value(
themeMode = FluentTheme.themeMode
)
),
selected = SolidColor(
FluentTheme.aliasTokens.brandBackgroundColor[FluentAliasTokens.BrandBackgroundColorTokens.BrandBackgroundTint].value(
themeMode = FluentTheme.themeMode
)
)
)
}
@Composable
override fun textColor(basicChipInfo: BasicChipInfo): StateColor {
return StateColor(
rest = FluentTheme.aliasTokens.neutralForegroundColor[FluentAliasTokens.NeutralForegroundColorTokens.Foreground2].value(
themeMode = FluentTheme.themeMode
),
selected = FluentTheme.aliasTokens.brandBackgroundColor[FluentAliasTokens.BrandBackgroundColorTokens.BrandBackground1Selected].value(
themeMode = FluentTheme.themeMode
)
)
}
}
class CustomChipToken2 : BasicChipTokens() {
@Composable
override fun backgroundBrush(basicChipInfo: BasicChipInfo): StateBrush {
return StateBrush(
rest = SolidColor(
FluentTheme.aliasTokens.brandBackgroundColor[FluentAliasTokens.BrandBackgroundColorTokens.BrandBackgroundTint].value(
themeMode = FluentTheme.themeMode
)
),
selected = SolidColor(
FluentTheme.aliasTokens.brandBackgroundColor[FluentAliasTokens.BrandBackgroundColorTokens.BrandBackground1].value(
themeMode = FluentTheme.themeMode
)
),
disabled = SolidColor(
FluentTheme.aliasTokens.neutralBackgroundColor[FluentAliasTokens.NeutralBackgroundColorTokens.Background5].value(
themeMode = FluentTheme.themeMode
)
)
)
}
@Composable
override fun textColor(basicChipInfo: BasicChipInfo): StateColor {
return StateColor(
rest = FluentTheme.aliasTokens.brandForegroundColor[FluentAliasTokens.BrandForegroundColorTokens.BrandForegroundTint].value(
themeMode = FluentTheme.themeMode
),
selected = FluentTheme.aliasTokens.neutralForegroundColor[FluentAliasTokens.NeutralForegroundColorTokens.ForegroundOnColor].value(
themeMode = FluentTheme.themeMode
),
disabled = FluentTheme.aliasTokens.neutralForegroundColor[FluentAliasTokens.NeutralForegroundColorTokens.ForegroundDisable1].value(
themeMode = FluentTheme.themeMode
)
)
}
}
Column(
modifier = Modifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Label(text = "Basic Chip", textStyle = FluentAliasTokens.TypographyTokens.Body1Strong)
Row(horizontalArrangement = spacedBy(8.dp)) {
BasicChip(
label = "Word",
selected = selectedList[0],
onClick = { selectedList[0] = !selectedList[0] })
BasicChip(
label = "Excel",
selected = selectedList[1],
onClick = { selectedList[1] = !selectedList[1] })
BasicChip(
label = "PowerPoint",
selected = selectedList[2],
onClick = { selectedList[2] = !selectedList[2] })
BasicChip(
label = "PDF",
selected = selectedList[3],
onClick = { selectedList[3] = !selectedList[3] })
}
Label(text = "Chip States", textStyle = FluentAliasTokens.TypographyTokens.Body1Strong)
Row(horizontalArrangement = spacedBy(8.dp)) {
BasicChip(
label = "Enabled", onClick = {})
BasicChip(
label = "Selected",
selected = true, onClick = {})
BasicChip(
label = "Disabled",
enabled = false
)
BasicChip(
label = "Static"
)
}
Label(
text = "Time (Custom Color)",
textStyle = FluentAliasTokens.TypographyTokens.Body1Strong
)
Row(horizontalArrangement = spacedBy(8.dp)) {
BasicChip(
basicChipTokens = CustomChipToken2(),
label = "Today",
selected = selectedList[4],
onClick = { selectedList[4] = !selectedList[4] })
BasicChip(
basicChipTokens = CustomChipToken2(),
label = "Yesterday",
selected = selectedList[5],
onClick = { selectedList[5] = !selectedList[5] })
BasicChip(
basicChipTokens = CustomChipToken2(),
label = "Last Week",
selected = selectedList[6],
onClick = { selectedList[6] = !selectedList[6] })
}
Label(
text = "Custom UI Chips",
textStyle = FluentAliasTokens.TypographyTokens.Body1Strong
)
Row(horizontalArrangement = spacedBy(8.dp)) {
BasicChip(
label = "Label",
leadingAccessory = { Icon(FluentIcon(Icons.Outlined.ShoppingCart)) },
selected = selectedList[7],
onClick = { selectedList[7] = !selectedList[7] })
BasicChip(
label = "Label",
trailingAccessory = { Icon(FluentIcon(Icons.Outlined.Add)) },
selected = selectedList[8],
onClick = { selectedList[8] = !selectedList[8] })
}
Label(
text = "Custom Color Chips",
textStyle = FluentAliasTokens.TypographyTokens.Body1Strong
)
Row(horizontalArrangement = spacedBy(8.dp)) {
BasicChip(
label = "Label",
selected = selectedList[9],
onClick = { selectedList[9] = !selectedList[9] },
basicChipTokens = CustomChipToken1()
)
}
}
}
}