chakra ui之 Button Icon IconButton

button

import { Button, ButtonGroup } from "@chakra-ui/react"

//usage
<Button colorScheme="blue">Button</Button>
//size  xs, sm, md, lg.
//variant solid, ghost, outline, link.
//with Icon leftIcon={<EmailIcon />}  rightIcon={<ArrowForwardIcon />}

//react-icons
<Button leftIcon={<MdBuild />} colorScheme="pink" variant="solid">
    Settings
</Button>
//isLoading
//spinner spinner={<BeatLoader size={8} color="white" />}

//social button
<HStack>
  <Button colorScheme="facebook" leftIcon={<FaFacebook />}>
    Facebook
  </Button>
  <Button colorScheme="twitter" leftIcon={<FaTwitter />}>
    Twitter
  </Button>
</HStack>

//ButtonGroup 
//isAttached 

// The size prop affects the height of the button
// It can still be overriden by passing a custom height
<Button
  size="md"
  height="48px"
  width="200px"
  border="2px"
  borderColor="green.500"
>
  Button
</Button>

//costom button
// Button from facebook.com
<Box
  as="button"
  height="24px"
  lineHeight="1.2"
  transition="all 0.2s cubic-bezier(.08,.52,.52,1)"
  border="1px"
  px="8px"
  borderRadius="2px"
  fontSize="14px"
  fontWeight="semibold"
  bg="#f5f6f7"
  borderColor="#ccd0d5"
  color="#4b4f56"
  _hover={{ bg: "#ebedf0" }}
  _active={{
    bg: "#dddfe2",
    transform: "scale(0.98)",
    borderColor: "#bec3c9",
  }}
  _focus={{
    boxShadow:
      "0 0 1px 2px rgba(88, 144, 255, .75), 0 1px 1px rgba(0, 0, 0, .15)",
  }}
>
  Join Group
</Box>

Icon

Avoid passing onClick handlers to icon components. If you need a clickable icon, use the IconButton instead.

  • Using Chakra UI icon library
//install
npm i @chakra-ui/icons
# or
yarn add @chakra-ui/icons

import { PhoneIcon, AddIcon, WarningIcon } from '@chakra-ui/icons'

// The default icon size is 1em (16px)
<PhoneIcon />

// Use the `boxSize` prop to change the icon size
<AddIcon w={6} h={6} />

// Use the `color` prop to change the icon color
<WarningIcon w={8} h={8} color="red.500" />
  • Using a third-party icon library
import { Icon } from "@chakra-ui/react"
import { MdSettings } from "react-icons/md"

// Use the `as` prop
function Example() {
  return <Icon as={MdSettings} />
}
  • Creating your own icons
    1.Using the Icon component
    2.Using the createIcon function
import { Icon, createIcon } from "@chakra-ui/react"

Tips for generating your own icons
1.Export icons as svg from Figma, Sketch, etc.
2.Use a tool like SvgOmg to reduce the size and minify the markup.

Fallback Icon
When children is not provided, the Icon component renders a fallback icon.

Icon Button

import { IconButton } from "@chakra-ui/react"
//aria-label needed
<IconButton aria-label="Search database" icon={<SearchIcon />} />
//with react-icon
<IconButton
  variant="outline"
  colorScheme="teal"
  aria-label="Call Sage"
  fontSize="20px"
  icon={<MdPhone />}
/>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值