Components
Code

Code

A component to display inline code snippets.

Usage

@park-ui/panda-preset
import { Code, type CodeProps } from '~/components/ui/code'

export const Demo = (props: CodeProps) => {
  return <Code {...props}>@park-ui/panda-preset</Code>
}

Installation

1

Add Component

Insert code snippet into your project. Update import paths as needed.

import { ark } from '@ark-ui/react/factory'
import type { ComponentProps } from 'react'
import { styled } from 'styled-system/jsx'
import { code } from 'styled-system/recipes'

export const Code = styled(ark.code, code)
export interface CodeProps extends ComponentProps<typeof Code> {}
2

Add Recipe

This step is necessary only if you do not use any of the Park UI plugins.

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)',
  },
  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',
      },
    },
  },
})

On this page