Chip
用于显示紧凑元素的 Jetpack Compose Chip 组件。
For the complete documentation index, see llms.txt. Use this Use this file to discover all available pages.
Expo UI Chips 与官方 Jetpack Compose Chip API 保持一致。每种 chip 类型都是独立组件:AssistChip、FilterChip、InputChip 和 SuggestionChip。
安装
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
用法
Assist chip
Assist chips 帮助用户执行操作或开始任务,例如预订航班或打开地图。它们通常作为对用户输入的响应而出现的临时 UI 元素。
import { Host, AssistChip, Icon, Text } from '@expo/ui/jetpack-compose'; export default function AssistChipExample() { return ( <Host matchContents> <AssistChip onClick={() => console.log('Opening flight booking...')}> <AssistChip.Label> <Text>Book Flight</Text> </AssistChip.Label> <AssistChip.LeadingIcon> <Icon source={require('./assets/flight.xml')} size={18} /> </AssistChip.LeadingIcon> </AssistChip> </Host> ); }
Filter chip
Filter chips 允许用户从一组选项中细化内容。它们支持选中状态,通常用于搜索栏或内容筛选。
import { useState } from 'react'; import { Host, FilterChip, Text } from '@expo/ui/jetpack-compose'; export default function FilterChipExample() { const [selected, setSelected] = useState(false); return ( <Host matchContents> <FilterChip selected={selected} onClick={() => setSelected(!selected)}> <FilterChip.Label> <Text>Images</Text> </FilterChip.Label> </FilterChip> </Host> ); }
Input chip
Input chips 表示用户输入的离散信息片段,例如文本字段中的标签。它们支持头像、尾随图标,并且可以被移除。
import { useState } from 'react'; import { Host, InputChip, Icon, Text, FlowRow } from '@expo/ui/jetpack-compose'; export default function InputChipExample() { const [chips, setChips] = useState(['Work', 'Travel', 'News']); return ( <Host matchContents> <FlowRow horizontalArrangement={{ spacedBy: 8 }}> {chips.map(label => ( <InputChip key={label} selected onClick={() => setChips(prev => prev.filter(c => c !== label))}> <InputChip.Label> <Text>{label}</Text> </InputChip.Label> <InputChip.TrailingIcon> <Icon source={require('./assets/close.xml')} size={18} /> </InputChip.TrailingIcon> </InputChip> ))} </FlowRow> </Host> ); }
Suggestion chip
Suggestion chips 通过展示动态生成的建议来帮助缩小用户意图范围,例如聊天中的快速回复选项或搜索优化建议。
import { Host, SuggestionChip, Text } from '@expo/ui/jetpack-compose'; export default function SuggestionChipExample() { return ( <Host matchContents> <SuggestionChip onClick={() => console.log('Searching nearby...')}> <SuggestionChip.Label> <Text>Nearby</Text> </SuggestionChip.Label> </SuggestionChip> </Host> ); }
API
import { AssistChip, FilterChip, InputChip, SuggestionChip } from '@expo/ui/jetpack-compose';
Components
Type: React.Element<AssistChipProps>
An assist chip that helps users complete actions and primary tasks.
boolean • Default: trueWhether the chip is enabled and can be clicked.
Type: React.Element<FilterChipProps>
A filter chip component for refining content with selection/deselection.
FilterChipColorsColors for the chip's container, label, icon, and selected states.
Type: React.Element<InputChipProps>
An input chip that represents user input and can be dismissed.
InputChipColorsColors for the chip's container, label, icons, and selected states.
boolean • Default: trueWhether the chip is enabled and can be interacted with.
Type: React.Element<SuggestionChipProps>
A suggestion chip that offers contextual suggestions and recommendations.
boolean • Default: trueWhether the chip is enabled and can be clicked.
Types
Colors for AssistChip.
| Property | Type | Description |
|---|---|---|
| containerColor(optional) | ColorValue | - |
| labelColor(optional) | ColorValue | - |
| leadingIconContentColor(optional) | ColorValue | - |
| trailingIconContentColor(optional) | ColorValue | - |
Border configuration for chips.
| Property | Type | Description |
|---|---|---|
| color(optional) | ColorValue | Border color. |
| width(optional) | number | Border width in dp. Default: 1 |
Colors for FilterChip.
| Property | Type | Description |
|---|---|---|
| containerColor(optional) | ColorValue | - |
| iconColor(optional) | ColorValue | - |
| labelColor(optional) | ColorValue | - |
| selectedContainerColor(optional) | ColorValue | - |
| selectedLabelColor(optional) | ColorValue | - |
| selectedLeadingIconColor(optional) | ColorValue | - |
| selectedTrailingIconColor(optional) | ColorValue | - |
Colors for InputChip.
| Property | Type | Description |
|---|---|---|
| containerColor(optional) | ColorValue | - |
| labelColor(optional) | ColorValue | - |
| leadingIconColor(optional) | ColorValue | - |
| selectedContainerColor(optional) | ColorValue | - |
| selectedLabelColor(optional) | ColorValue | - |
| selectedLeadingIconColor(optional) | ColorValue | - |
| selectedTrailingIconColor(optional) | ColorValue | - |
| trailingIconColor(optional) | ColorValue | - |
Colors for SuggestionChip.
| Property | Type | Description |
|---|---|---|
| containerColor(optional) | ColorValue | - |
| iconContentColor(optional) | ColorValue | - |
| labelColor(optional) | ColorValue | - |