ProComponents, templates & AI tooling
2.3k

CloseButton 关闭按钮

用于关闭对话框、模态框或收起内容的按钮组件。

导入

import { CloseButton } from 'heroui-native';

用法

基础用法

CloseButton 渲染带默认样式的关闭图标按钮。

<CloseButton />

自定义图标颜色

通过 iconProps 自定义图标颜色。

<CloseButton iconProps={{ color: themeColorDanger }} />
<CloseButton iconProps={{ color: themeColorAccent }} />

自定义图标尺寸

通过 iconProps 调整图标大小。

<CloseButton iconProps={{ size: 24 }} />

自定义子节点

用自定义内容替换默认关闭图标。

<CloseButton>
  <CustomIcon />
</CloseButton>

禁用态

禁用按钮以禁止交互。

<CloseButton isDisabled />

示例

import { CloseButton, useThemeColor } from 'heroui-native';
import { Ionicons } from '@expo/vector-icons';
import { View } from 'react-native';
import { withUniwind } from 'uniwind';

const StyledIonicons = withUniwind(Ionicons);

export default function CloseButtonExample() {
  const themeColorForeground = useThemeColor('foreground');
  const themeColorDanger = useThemeColor('danger');

  return (
    <View className="flex-1 px-5 items-center justify-center">
      <View className="flex-row items-center gap-4">
        <CloseButton />
        <CloseButton iconProps={{ color: themeColorDanger }} />
        <CloseButton>
          <StyledIonicons
            name="close-circle"
            size={28}
            color={themeColorForeground}
          />
        </CloseButton>
        <CloseButton isDisabled />
      </View>
    </View>
  );
}

更多示例见 GitHub 仓库

API 参考

CloseButton

CloseButton 继承 Button 的全部属性。默认 variant='tertiary'size='sm'isIconOnly=true

proptypedefaultdescription
iconPropsCloseButtonIconProps-自定义关闭图标属性
childrenReact.ReactNode-自定义内容,替换默认关闭图标

isDisabledclassNameanimationfeedbackVariant 以及所有 Pressable 相关继承属性见 Button API 参考

CloseButtonIconProps

proptypedefaultdescription
sizenumber20图标尺寸
colorstringUses theme muted color图标颜色

本页目录