Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

1.4 KB
Raw Blame
import type { PolymorphicProps } from "@kobalte/core/polymorphic";
import { Polymorphic } from "@kobalte/core/polymorphic";
import { cx } from "cva";
import { splitProps, type ValidComponent } from "solid-js";
import IconCapChevronDown from "~icons/cap/chevron-down";

type TargetDropdownButtonProps<T extends ValidComponent> = PolymorphicProps<
	T,
	{
		class?: string;
		disabled?: boolean;
		expanded?: boolean;
	}
>;

export default function TargetDropdownButton<
	T extends ValidComponent = "button",
>(props: TargetDropdownButtonProps<T>) {
	const [local, rest] = splitProps(props, ["class", "expanded", "disabled"]);

	return (
		<Polymorphic
			as="button"
			type="button"
			{...rest}
			disabled={local.disabled}
			aria-expanded={local.expanded ? "true" : "false"}
			data-expanded={local.expanded ? "true" : "false"}
			class={cx(
				"flex w-7 shrink-0 items-center justify-center rounded-lg bg-gray-4 text-gray-12 transition-colors duration-150 hover:bg-gray-6 active:bg-gray-7 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-blue-9 focus-visible:ring-offset-2 focus-visible:ring-offset-gray-1",
				local.expanded && "bg-blue-4 text-blue-11",
				local.disabled && "pointer-events-none opacity-60",
				local.class,
			)}
		>
			<IconCapChevronDown
				class={cx(
					"size-4 text-gray-11 transition-transform duration-150",
					local.expanded && "rotate-180 text-gray-12",
				)}
			/>
		</Polymorphic>
	);
}