import { ActionIcon, BoxProps, MantinePolymorphicComponent, polymorphicFactory, PolymorphicFactory, StylesApiProps, Tooltip, useProps, } from '@mantine/core'; import { useCodeHighlightContext } from '../CodeHighlight.context'; export interface CodeHighlightControlProps extends BoxProps, StylesApiProps { /** Control icon */ children?: React.ReactNode; /** Label displayed in the tooltip when the control is hovered */ tooltipLabel?: string; } export type CodeHighlightControlFactory = PolymorphicFactory<{ props: CodeHighlightControlProps; defaultRef: HTMLButtonElement; defaultComponent: 'button'; }>; export const CodeHighlightControl: MantinePolymorphicComponent = polymorphicFactory((_props) => { const props = useProps('CodeHighlightControl', null, _props); const { children, vars, tooltipLabel, ...others } = props; const ctx = useCodeHighlightContext(); const tooltipStyles = ctx.getStyles('controlTooltip'); const control = ( {children} ); if (tooltipLabel) { return ( {control} ); } return control; }); CodeHighlightControl.displayName = '@mantine/code-highlight/CodeHighlightControl';