Skip to content

Commit

Permalink
[@mantine/tiptap] Add option to configure initial state of external l…
Browse files Browse the repository at this point in the history
…ink control (#4373)
  • Loading branch information
skyt-a committed Jun 18, 2023
1 parent be75cda commit 3001cc4
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/mantine-tiptap/src/controls/LinkControl/LinkControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,23 @@ export interface RichTextEditorLinkControlProps extends Partial<RichTextEditorCo

/** Determines whether external link control tooltip should be disabled */
disableTooltips?: boolean;

/** Initial state for determining if the link should be an external link */
initialExternal?: boolean;
}

const LinkIcon: RichTextEditorControlBaseProps['icon'] = ({ size, ...others }) => (
<IconLink size={size} stroke={1.5} {...others} />
);

const defaultProps: Partial<RichTextEditorLinkControlProps> = {};
const defaultProps: Partial<RichTextEditorLinkControlProps> = {
initialExternal: false,
};

export const LinkControl = forwardRef<HTMLButtonElement, RichTextEditorLinkControlProps>(
(props, ref) => {
const { icon, popoverProps, disableTooltips, ...others } = useComponentDefaultProps(
'RichTextEditorLinkControl',
defaultProps,
props
);
const { icon, popoverProps, disableTooltips, initialExternal, ...others } =
useComponentDefaultProps('RichTextEditorLinkControl', defaultProps, props);

const { editor, labels, classNames, styles, unstyled, variant } = useRichTextEditorContext();
const { classes } = useStyles(null, {
Expand All @@ -50,7 +52,7 @@ export const LinkControl = forwardRef<HTMLButtonElement, RichTextEditorLinkContr
});

const [url, setUrl] = useInputState('');
const [external, setExternal] = useState(false);
const [external, setExternal] = useState(initialExternal);
const [opened, { open, close }] = useDisclosure(false);

const handleOpen = () => {
Expand All @@ -63,7 +65,7 @@ export const LinkControl = forwardRef<HTMLButtonElement, RichTextEditorLinkContr
const handleClose = () => {
close();
setUrl('');
setExternal(false);
setExternal(initialExternal);
};

const setLink = () => {
Expand Down

0 comments on commit 3001cc4

Please sign in to comment.