import React from
'react'
;
import {
Kbd, Box, Heading, Text, Flex,
Spacer, ChakraProvider, extendTheme
} from
'@chakra-ui/react'
;
import {
defineStyle,
defineStyleConfig
} from
'@chakra-ui/react'
;
const KeyboardShortcut = ({ keys, action }) => (
<Flex my={4}>
<Box>
<Text fontSize=
"lg"
>
Press{
' '
}
{keys.map((key, index) => (
<React.Fragment key={index}>
<Kbd variant={`key${index + 1}`}>
{key}
</Kbd>
{index < keys.length - 1 &&
' + '
}
</React.Fragment>
))}
</Text>
</Box>
<Spacer />
<Box>
<Text>{action}</Text>
</Box>
</Flex>
);
const keyColors = [
'#FF5252'
,
'#FFD740'
,
'#69F0AE'
,
'#448AFF'
];
const customKeyStyle = (color) =>
defineStyle({
background: color,
color:
'white'
,
borderRadius:
'md'
,
fontWeight:
'bold'
,
_hover: { background: `${color}B3` },
_focus: { boxShadow:
'outline'
},
});
const kbdTheme = defineStyleConfig({
defaultProps: {
size:
'md'
,
colorScheme:
'teal'
,
},
variants: {
key1: customKeyStyle(keyColors[0]),
key2: customKeyStyle(keyColors[1]),
key3: customKeyStyle(keyColors[2]),
key4: customKeyStyle(keyColors[3]),
},
});
const theme = extendTheme({
components: {
Kbd: kbdTheme,
},
});
const App = () => {
return
(
<ChakraProvider theme={theme}>
<Box p={8} maxW=
"600px"
mx=
"auto"
>
<Heading mb={4} as=
"h1"
color=
"green.500"
>
GeeksforGeeks
</Heading>
<Text mb={4} as=
"h3"
>
Chakra UI Data Display Keyboard Key
</Text>
<KeyboardShortcut keys={[
'ctrl'
,
'C'
]}
action=
"Copy selected text"
/>
<KeyboardShortcut keys={[
'alt'
,
'then'
,
'F'
]}
action=
"Open File menu"
/>
<KeyboardShortcut keys={[
'cmd'
,
'option'
,
'esc'
]}
action=
"Open Task Manager"
/>
<KeyboardShortcut keys={[
'shift'
,
'R'
]}
action=
"Reload the page"
/>
</Box>
</ChakraProvider>
);
};
export
default
App;