Code
A component to display inline code snippets.
outline
ghost
import { Code, type CodeProps } from '~/components/ui/code'
export const Demo = (props: CodeProps) => {
return <Code {...props}>@park-ui/panda-preset</Code>
}
import { Code, type CodeProps } from '~/components/ui/code'
export const Demo = (props: CodeProps) => {
return <Code {...props}>@park-ui/panda-preset</Code>
}
Usage
import { Code } from '~/components/ui/code'
Installation
npx @park-ui/cli components add code
1
Add Styled Primitive
Copy the code snippet below into ~/components/ui/styled/code.tsx
import { ark } from '@ark-ui/react/factory'
import { styled } from 'styled-system/jsx'
import { code } from 'styled-system/recipes'
import type { ComponentProps } from 'styled-system/types'
export type CodeProps = ComponentProps<typeof Code>
export const Code = styled(ark.code, code)
import { ark } from '@ark-ui/solid'
import type { ComponentProps } from 'solid-js'
import { styled } from 'styled-system/jsx'
import { code } from 'styled-system/recipes'
export type CodeProps = ComponentProps<typeof Code>
export const Code = styled(ark.code, code)
No snippet found
2
Add Re-Export
To improve the developer experience, re-export the styled primitives in~/components/ui/code.tsx
.
export { Code, type CodeProps } from './styled/code'
export { Code, type CodeProps } from './styled/code'
3
Integrate Recipe
If you're not using @park-ui/preset
, add the following recipe to yourpanda.config.ts
:
import { defineRecipe } from '@pandacss/dev'
export const code = defineRecipe({
className: 'code',
base: {
alignItems: 'center',
bg: 'bg.subtle',
borderRadius: 'l2',
color: 'fg.default',
display: 'inline-flex',
fontWeight: 'medium!',
fontFamily: 'var(--fonts-code)',
whiteSpace: 'pre',
},
defaultVariants: {
size: 'md',
variant: 'outline',
},
variants: {
variant: {
outline: {
borderWidth: '1px',
},
ghost: {},
},
size: {
sm: {
minHeight: '5',
px: '0.5',
textStyle: 'xs',
},
md: {
minHeight: '6',
textStyle: 'sm',
px: '1',
py: '1px',
},
lg: {
minHeight: '7',
px: '1.5',
py: '1px',
textStyle: 'md',
},
},
},
})