import React, { HTMLAttributes, forwardRef } from "react";
import { Slot } from "../../utils/components/slot/Slot";
import { cl } from "../../utils/helpers";
import { BreakpointsAlias } from "../utilities/types";
export interface ResponsiveProps extends HTMLAttributes {
children: React.ReactNode;
/**
* Will show/hide element above breakpoint (inclusive)
*/
above?: Exclude;
/**
* Will show/hide element below breakpoint (inclusive)
*/
below?: Exclude;
/**
* Overrides html-tag
* @default "div"
*/
as?: "div" | "span";
/**
* When true, will render element as its child. This merges classes, styles and event handlers.
*/
asChild?: boolean;
}
const Responsive = forwardRef<
HTMLDivElement,
ResponsiveProps & { variant: "show" | "hide" }
>(
(
{
as: Component = "div",
className,
above,
below,
variant,
asChild,
...rest
},
ref,
) => {
const aboveProp = variant === "show" ? above : below;
const belowProp = variant === "show" ? below : above;
const Comp = asChild ? Slot : Component;
return (
);
},
);
/**
* Responsive view Primitive to show/hide elements based on breakpoints
*
* @see [📝 Documentation](https://aksel.nav.no/komponenter/primitives/hide)
* @see 🏷️ {@link ResponsiveProps}
*
* @example
*
*
*
* // Only visible above "md"
*
*
* @example
*
*
*
* // Only visible below "md"
*
*
*/
export const Hide = forwardRef(
(props, ref) => ,
);
/**
* Responsive view Primitive to show/hide elements based on breakpoints
*
* @see [📝 Documentation](https://aksel.nav.no/komponenter/primitives/show)
* @see 🏷️ {@link ResponsiveProps}
*
* @example
*
*
*
* // Only visible below "md"
*
*
* @example
*
*
*
* // Only visible above "md"
*
*
*/
export const Show = forwardRef(
(props, ref) => ,
);