Fade
Fade is a native div overlay that draws an edge gradient from a Density background depth to transparent. Use it inside a positioned parent to soften the edge of charts, panes, and scrolled content.
import { Fade } from "density-base-ui";
export default function FadeExample() {
return (
<div
style={{
alignContent: "start",
display: "grid",
gap: "0.75rem",
height: "10rem",
overflow: "hidden",
position: "relative",
}}
>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.
</p>
<Fade style={{ "--dn-fade-size": "4rem" }} />
</div>
);
}Props
| Prop | Attribute | Values | Default |
|---|---|---|---|
depth |
data-dn-depth |
1, 2, 3, 4, 5, 6, 7 |
1 |
direction |
None | fade-out-top, fade-out-right, fade-out-bottom, fade-out-left |
fade-out-bottom |
children |
None | ReactNode |
None |
| Other native div props | Mixed | HTMLAttributes<HTMLDivElement> |
None |
Set --dn-fade-size in style to override the default fade depth.
Direction
import type * as React from "react";
import { Fade } from "density-base-ui";
import { ExampleStack } from "../ExampleLayout";
const fadeStyle = { "--dn-fade-size": "2rem" } as const;
function FadePreview({
children,
direction,
}: {
children: string;
direction: React.ComponentProps<typeof Fade>["direction"];
}) {
return (
<div
style={{
alignItems: "center",
display: "flex",
justifyContent: "center",
minHeight: "6rem",
overflow: "hidden",
position: "relative",
}}
>
{children}
<Fade direction={direction} style={fadeStyle} />
</div>
);
}
export default function FadeDirectionExample() {
return (
<ExampleStack>
<FadePreview direction="fade-out-top">Fade out top</FadePreview>
<FadePreview direction="fade-out-right">Fade out right</FadePreview>
<FadePreview direction="fade-out-bottom">Fade out bottom</FadePreview>
<FadePreview direction="fade-out-left">Fade out left</FadePreview>
</ExampleStack>
);
}Depth
import type * as React from "react";
import { Fade } from "density-base-ui";
import { ExampleStack } from "../ExampleLayout";
const fadeStyle = { "--dn-fade-size": "2rem" } as const;
function FadePreview({
children,
depth,
}: {
children: string;
depth: React.ComponentProps<typeof Fade>["depth"];
}) {
return (
<div
style={{
alignItems: "center",
display: "flex",
justifyContent: "center",
minHeight: "4rem",
overflow: "hidden",
position: "relative",
}}
>
{children}
<Fade depth={depth} style={fadeStyle} />
</div>
);
}
export default function FadeDepthExample() {
return (
<ExampleStack>
<FadePreview depth="1">Depth 1</FadePreview>
<FadePreview depth="2">Depth 2</FadePreview>
<FadePreview depth="3">Depth 3</FadePreview>
<FadePreview depth="4">Depth 4</FadePreview>
<FadePreview depth="5">Depth 5</FadePreview>
<FadePreview depth="6">Depth 6</FadePreview>
<FadePreview depth="7">Depth 7</FadePreview>
</ExampleStack>
);
}