data/primitives/docs/overview/getting-started.mdx
In this quick tutorial, we will install and style the Popover component.
Install Radix Primitives from your command line.
npm install radix-ui@latest
Import and structure the parts.
// index.jsx
import * as React from "react";
import { Popover } from "radix-ui";
const PopoverDemo = () => (
<Popover.Root>
<Popover.Trigger>More info</Popover.Trigger>
<Popover.Portal>
<Popover.Content>
Some more info…
<Popover.Arrow />
</Popover.Content>
</Popover.Portal>
</Popover.Root>
);
export default PopoverDemo;
Add styles where desired.
// index.jsx
import * as React from "react";
import { Popover } from "radix-ui";
import "./styles.css";
const PopoverDemo = () => (
<Popover.Root>
<Popover.Trigger __className__="PopoverTrigger">Show info</Popover.Trigger>
<Popover.Portal>
<Popover.Content __className__="PopoverContent">
Some content
<Popover.Arrow __className__="PopoverArrow" />
</Popover.Content>
</Popover.Portal>
</Popover.Root>
);
export default PopoverDemo;
/* styles.css */
.PopoverTrigger {
background-color: white;
border-radius: 4px;
}
.PopoverContent {
border-radius: 4px;
padding: 20px;
width: 260px;
background-color: white;
}
.PopoverArrow {
fill: white;
}
Here's a complete demo.
<HeroContainer> <GettingStartedDemo /> </HeroContainer> <HeroCodeBlock folder="GettingStarted" cssLib="css" />The steps above outline briefly what's involved in using a Radix Primitive in your application.
These components are low-level enough to give you control over how you want to wrap them. You're free to introduce your own high-level API to better suit the needs of your team and product.
In a few simple steps, we've implemented a fully accessible Popover component, without having to worry about many of its complexities.