ProseCodeGroupe

GitHub à
Regroupez plusieurs exemples de code dans des interfaces à onglets pour une comparaison facile.

Utilisation

Enroulez vos blocs de code autour d'un composant code-group pour les regrouper dans des onglets.

pnpm add @nuxt/ui
::code-group

```bash [pnpm]
pnpm add @ nuxt/ui
```

```bash [yarn]
add @ nuxt/ui
```

```bash [npm]
npm install @ nuxt/ui
```

```bash [bun]
add @ nuxt/ui
```

::
Comme le composant ProsePre, le CodeGroup gère les noms de fichiers, les icônes et le bouton de copie.

api

Props

Prop Default Type
defaultValue
'0'
string

The default tab to select.

sync
string

Sync the selected tab with a local storage key.

modelValue
string
ui
{ root?: SlotClass; list?: SlotClass; indicator?: SlotClass; trigger?: SlotClass; triggerIcon?: SlotClass; triggerLabel?: SlotClass; }

Slots

Slot Type
default
{}

Thème

app.config.ts
export default defineAppConfig({
  ui: {
    prose: {
      codeGroup: {
        slots: {
          root: 'relative group *:not-first:my-0! *:not-first:static! my-5',
          list: 'relative flex items-center gap-1 border border-muted bg-default border-b-0 rounded-t-md overflow-x-auto p-2',
          indicator: 'absolute left-0 inset-y-2 w-(--reka-tabs-indicator-size) translate-x-(--reka-tabs-indicator-position) transition-[translate,width] duration-200 ease-out motion-reduce:transition-none bg-elevated rounded-md shadow-xs',
          trigger: [
            'relative inline-flex items-center gap-1.5 text-default data-[state=active]:text-highlighted hover:bg-elevated/50 px-2 py-1.5 text-sm rounded-md disabled:cursor-not-allowed disabled:opacity-75 outline-primary/25 focus-visible:outline-3',
            'transition-colors'
          ],
          triggerIcon: 'size-4 shrink-0',
          triggerLabel: 'truncate'
        }
      }
    }
  }
})
vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'

export default defineConfig({
  plugins: [
    vue(),
    ui({
      ui: {
        prose: {
          codeGroup: {
            slots: {
              root: 'relative group *:not-first:my-0! *:not-first:static! my-5',
              list: 'relative flex items-center gap-1 border border-muted bg-default border-b-0 rounded-t-md overflow-x-auto p-2',
              indicator: 'absolute left-0 inset-y-2 w-(--reka-tabs-indicator-size) translate-x-(--reka-tabs-indicator-position) transition-[translate,width] duration-200 ease-out motion-reduce:transition-none bg-elevated rounded-md shadow-xs',
              trigger: [
                'relative inline-flex items-center gap-1.5 text-default data-[state=active]:text-highlighted hover:bg-elevated/50 px-2 py-1.5 text-sm rounded-md disabled:cursor-not-allowed disabled:opacity-75 outline-primary/25 focus-visible:outline-3',
                'transition-colors'
              ],
              triggerIcon: 'size-4 shrink-0',
              triggerLabel: 'truncate'
            }
          }
        }
      }
    })
  ]
})

Changelog

No recent changes