Pressable is a lower level primitive if you need more flexibility than a button and access to hover, pressed and focus events.
function Example() {
return <Pressable>
{({
isHovered,
isFocused,
isPressed
}) => {
return <Box maxW="96" borderWidth="1" borderColor="coolGray.300" shadow="3" bg={isPressed ? 'coolGray.200' : isHovered ? 'coolGray.200' : 'coolGray.100'} p="5" rounded="8" style={{
transform: [{
scale: isPressed ? 0.96 : 1
}]
}}>
<HStack alignItems="center">
<Badge colorScheme="darkBlue" _text={{
color: 'white'
}} variant="solid" rounded="4">
Business
</Badge>
<Spacer />
<Text fontSize={10} color="coolGray.800">
1 month ago
</Text>
</HStack>
<Text color="coolGray.800" mt="3" fontWeight="medium" fontSize="xl">
Marketing License
</Text>
<Text mt="2" fontSize="sm" color="coolGray.700">
Unlock powerfull time-saving tools for creating email delivery and
collecting marketing data
</Text>
<Flex>
{isFocused ? <Text mt="2" fontSize={12} fontWeight="medium" textDecorationLine="underline" color="darkBlue.600" alignSelf="flex-start">
Read More
</Text> : <Text mt="2" fontSize={12} fontWeight="medium" color="darkBlue.600">
Read More
</Text>}
</Flex>
</Box>;
}}
</Pressable>;
}
Pressable accepts most of the utility style system props.
function Example() {
return <Box alignItems="center">
<Pressable onPress={() => console.log("I'm Pressed")} rounded="8" overflow="hidden" borderWidth="1" borderColor="coolGray.300" maxW="96" shadow="3" bg="coolGray.100" p="5">
<Box>
<HStack alignItems="center">
<Badge colorScheme="darkBlue" _text={{
color: "white"
}} variant="solid" rounded="4">
Business
</Badge>
<Spacer />
<Text fontSize={10} color="coolGray.800">
1 month ago
</Text>
</HStack>
<Text color="coolGray.800" mt="3" fontWeight="medium" fontSize="xl">
Marketing License
</Text>
<Text mt="2" fontSize="sm" color="coolGray.700">
Unlock powerfull time-saving tools for creating email delivery and
collecting marketing data
</Text>
<Flex>
<Text mt="2" fontSize={12} fontWeight="medium" color="darkBlue.600">
Read More
</Text>
</Flex>
</Box>
</Pressable>
</Box>;
}
Accessing events (hover, focus and pressed)
Pressable accepts a render prop children, which receives isHovered, isFocused and isPressed props.
function Example() {
return <Box alignItems="center">
<Pressable maxW="96">
{({
isHovered,
isFocused,
isPressed
}) => {
return <Box bg={isPressed ? "coolGray.200" : isHovered ? "coolGray.200" : "coolGray.100"} style={{
transform: [{
scale: isPressed ? 0.96 : 1
}]
}} p="5" rounded="8" shadow={3} borderWidth="1" borderColor="coolGray.300">
<HStack alignItems="center">
<Badge colorScheme="darkBlue" _text={{
color: "white"
}} variant="solid" rounded="4">
Business
</Badge>
<Spacer />
<Text fontSize={10} color="coolGray.800">
1 month ago
</Text>
</HStack>
<Text color="coolGray.800" mt="3" fontWeight="medium" fontSize="xl">
Marketing License
</Text>
<Text mt="2" fontSize="sm" color="coolGray.700">
Unlock powerfull time-saving tools for creating email delivery
and collecting marketing data
</Text>
<Flex>
{isFocused ? <Text mt="2" fontSize={12} fontWeight="medium" textDecorationLine="underline" color="darkBlue.600" alignSelf="flex-start">
Read More
</Text> : <Text mt="2" fontSize={12} fontWeight="medium" color="darkBlue.600">
Read More
</Text>}
</Flex>
</Box>;
}}
</Pressable>
</Box>;
}
Pressable implements
,
,
,
,
,
,
,
,
,
,
Called when a mouse enters the Pressable
Called when a mouse leaves the Pressable
Called when Pressable receives focus
Called when Pressable loses focus
Style props to be applied when hovered
Type: Omit<Partial<IPressableProps>, "_hover">
Style props to be applied when pressed
Type: Omit<Partial<IPressableProps>, "_pressed">
Style props to be applied when focus
Type: Omit<Partial<IPressableProps>, "_focus">
Style props to be applied when disabled
Type: Omit<Partial<IPressableProps>, "_disabled">
If true, the p will be disabled.
If true, the p will be hovered.
If true, the p will be pressed.
If true, the p will be focused.
If true, the focus ring will be visible .
Style props to be applied when focus visible. These styles will be only applied when user is interacting the app using a keyboard. (Web only)
Type: Omit<Partial<IPressableProps>, "_focusVisible">
Either children or a render prop that receives a boolean reflecting whether the component is currently pressed.
Type: ReactNode | (({ isPressed, isHovered, isFocused, }: { isPressed: boolean; isHovered: boolean; isFocused: boolean; }) => any)