Icon Button
Icon-only Button with a required label, themed foregrounds, and inherited busy/disabled behavior.
Install
First install? Set up the registry in your app.
npx --yes --package=https://native.uipkge.dev/cli/uipkge-native-0.1.1.tgz uipkge-native add icon-buttonSource files
Expand a file to read the source the installer copies into your app.
components/ui/icon-button/IconButton.tsx
import * as React from 'react'
import { Pressable } from 'react-native'
import type { LucideIcon } from 'lucide-react-native'
import { Button, type ButtonProps } from '@/components/ui/button'
import { Icon } from '@/components/ui/icon'
import { useThemeColors } from '@/lib/theme'
export interface IconButtonProps extends Omit<ButtonProps, 'children' | 'size'> {
icon: LucideIcon
accessibilityLabel: string
iconSize?: number
iconColor?: string
}
export const IconButton = React.forwardRef<React.ComponentRef<typeof Pressable>, IconButtonProps>(
({ icon, iconSize = 20, iconColor, variant = 'ghost', ...props }, ref) => {
const colors = useThemeColors()
const foreground =
variant === 'default'
? colors.primaryForeground
: variant === 'destructive'
? colors.destructiveForeground
: variant === 'secondary'
? colors.secondaryForeground
: variant === 'link'
? colors.primary
: colors.foreground
return (
<Button ref={ref} {...props} size="icon" variant={variant}>
<Icon icon={icon} size={iconSize} color={iconColor ?? foreground} />
</Button>
)
},
)
IconButton.displayName = 'IconButton'
components/ui/icon-button/index.ts
export * from './IconButton'