console.log("Hello, world!")
import { Code } from "@chakra-ui/react"
const Demo = () => {
return <Code>{`console.log("Hello, world!")`}</Code>
}
Usage
import { Code } from "@chakra-ui/react"
<Code>Hello world</Code>
Examples
Sizes
Use the size
prop to change the size of the code component.
console.log()
console.log()
console.log()
console.log()
import { Code, Stack } from "@chakra-ui/react"
const Demo = () => {
return (
<Stack gap="2" align="flex-start">
<Code size="xs">console.log()</Code>
<Code size="sm">console.log()</Code>
<Code size="md">console.log()</Code>
<Code size="lg">console.log()</Code>
</Stack>
)
}
Variants
Use the variant
prop to change the appearance of the code component.
console.log()
console.log()
console.log()
console.log()
import { Code, Stack } from "@chakra-ui/react"
const Demo = () => {
return (
<Stack gap="2" align="flex-start">
<Code variant="solid">console.log()</Code>
<Code variant="outline">console.log()</Code>
<Code variant="subtle">console.log()</Code>
<Code variant="surface">console.log()</Code>
</Stack>
)
}
Colors
Use the colorPalette
prop to change the color scheme of the component.
gray
console.log()
console.log()
console.log()
console.log()
red
console.log()
console.log()
console.log()
console.log()
green
console.log()
console.log()
console.log()
console.log()
blue
console.log()
console.log()
console.log()
console.log()
teal
console.log()
console.log()
console.log()
console.log()
pink
console.log()
console.log()
console.log()
console.log()
purple
console.log()
console.log()
console.log()
console.log()
cyan
console.log()
console.log()
console.log()
console.log()
orange
console.log()
console.log()
console.log()
console.log()
yellow
console.log()
console.log()
console.log()
console.log()
import { Code, Stack, Text } from "@chakra-ui/react"
import { colorPalettes } from "compositions/lib/color-palettes"
const Demo = () => {
return (
<Stack gap="2" align="flex-start">
{colorPalettes.map((colorPalette) => (
<Stack
align="center"
key={colorPalette}
direction="row"
gap="10"
px="4"
width="full"
>
<Text minW="8ch" textStyle="sm">
{colorPalette}
</Text>
<Code colorPalette={colorPalette} variant="solid">
{`console.log()`}
</Code>
<Code colorPalette={colorPalette} variant="outline">
{`console.log()`}
</Code>
<Code colorPalette={colorPalette} variant="subtle">
{`console.log()`}
</Code>
<Code colorPalette={colorPalette} variant="surface">
{`console.log()`}
</Code>
</Stack>
))}
</Stack>
)
}
Props
Prop | Default | Type |
---|---|---|
colorPalette | 'gray' | 'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent' The color palette of the component |
variant | 'subtle' | 'solid' | 'subtle' | 'outline' | 'surface' | 'plain' The variant of the component |
size | 'sm' | 'xs' | 'sm' | 'md' | 'lg' The size of the component |