@gluestack-ui/select
选择提供了一种动态和方便用户的方式,在封闭视图中呈现一个选项列表,能够从下放列表中扩展和选择项目.
安装
要安装组件,请在终端中运行以下命令。 这将添加到您的项目的依赖性中, 并允许您在您的项目中使用它 .
npx install @gluestack-ui/select
使用量
所有这些组件的默认样式可以在组件/选择文件中找到. 作为参考,你可以查看 源代码 选择组件.
// import animation configured styled function
import { styled } from '../styled';
// import the styles
import {
Root as StyledSelectRoot,
Trigger as StyledSelectTrigger,
Input as StyledSelectInput,
Icon as StyledSelectIcon,
} from '../components/core/select/styled-components';
import {
Root,
Content,
Item,
ItemText,
DragIndicator,
IndicatorWrapper,
Backdrop,
Icon,
FlatList,
ScrollView,
SectionHeaderText,
SectionList,
VirtualizedList,
} from '../components/core/actionsheet/styled-components';
// import the createSelect and createActionsheet function
import { createSelect } from '@gluestack-ui/select';
import { createActionsheet } from '@gluestack-ui/actionsheet';
// Understanding the API
const Actionsheet = createActionsheet({
Root,
Backdrop,
Content,
DragIndicator,
IndicatorWrapper,
Item,
ItemText,
Icon,
ScrollView,
VirtualizedList,
FlatList,
SectionList,
SectionHeaderText,
AnimatePresence: styled.Component,
});
const Select = createSelect(
{
Root: StyledSelectRoot,
Trigger: StyledSelectTrigger,
Input: StyledSelectInput,
Icon: StyledSelectIcon,
},
{
Portal: Actionsheet,
Backdrop: Actionsheet.Backdrop,
Content: Actionsheet.Content,
DragIndicator: Actionsheet.DragIndicator,
DragIndicatorWrapper: Actionsheet.DragIndicatorWrapper,
Item: Actionsheet.Item,
ItemText: Actionsheet.ItemText,
ScrollView: Actionsheet.ScrollView,
VirtualizedList: Actionsheet.VirtualizedList,
FlatList: Actionsheet.FlatList,
SectionList: Actionsheet.SectionList,
SectionHeaderText: Actionsheet.SectionHeaderText,
}
);
// Using the select component
export default () => (
<Select isDisabled={isDisabled} isInvalid={isInvalid}>
<SelectTrigger>
<SelectInput placeholder="Select option" />
<SelectIcon mr="$3">
<Icon as={ChevronDownIcon} />
</SelectIcon>
</SelectTrigger>
<SelectPortal>
<SelectBackdrop />
<SelectContent>
<SelectDragIndicatorWrapper>
<SelectDragIndicator />
</SelectDragIndicatorWrapper>
<SelectItem label="UX Research" value="UX Research" />
<SelectItem label="Web Development" value="Web Development" />
</SelectContent>
</SelectPortal>
</Select>
);
更多关于如何启动的指南 这里。 。 。 .