Veil UI
Components

Box

A generic layout primitive with padding and asChild composition.

Installation

$ npx veil-ui@latest add box

Usage

import { Box } from "@/components/ui/box";

<Box padding="md" className="rounded-lg border">
  Content
</Box>;

Examples

Basic

A generic layout primitive.

Padding

padding="sm"
padding="md"
padding="lg"

Composition

asChild forwards the styles and props to a single child element, so you can render a link or a custom component without an extra wrapper.

API reference

PropTypeDefaultDescription
asChildbooleanfalseRender the styles onto a single child element.
padding"none" | "xs" | "sm" | "md" | "lg" | "xl""none"Padding scale: 0, 4, 8, 16, 24 or 32px.
...propsReact.ComponentProps<"div">—All native div attributes.

Accessibility

  • Presentational primitive; it adds no roles.
  • When asChild renders a link or button, that element keeps its own semantics and keyboard behaviour.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add box --framework vue or switch the framework in components.json.

<script setup lang="ts">
import { Primitive } from "reka-ui";
import { computed } from "vue";

import { cn } from "@/lib/utils";

const paddings = {
  none: "p-0",
  xs: "p-1",
  sm: "p-2",
  md: "p-4",
  lg: "p-6",
  xl: "p-8",
} as const;

defineOptions({ inheritAttrs: false });

const props = withDefaults(
  defineProps<{
    asChild?: boolean;
    padding?: keyof typeof paddings;
    class?: string;
  }>(),
  { asChild: false, padding: "none" },
);

const classes = computed(() => cn(paddings[props.padding], props.class));
</script>

<template>
  <Primitive
    :as="asChild ? undefined : 'div'"
    :as-child="asChild"
    data-slot="box"
    :data-padding="padding"
    :class="classes"
    v-bind="$attrs"
  >
    <slot />
  </Primitive>
</template>

On this page