Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

956 B
Raw Blame
import type { TextProps } from '@chakra-ui/react';

import { Link, Text } from '@chakra-ui/react';
import { useMemo } from 'react';

import { splitTextIntoLinkSegments } from './linkify';

/** Prose with its `http(s)` URLs rendered as links that open in a new tab; the text itself is left as written. */
export const LinkifiedText = ({ children, ...textProps }: { children: string } & Omit<TextProps, 'children'>) => {
  const segments = useMemo(() => splitTextIntoLinkSegments(children), [children]);

  return (
    <Text {...textProps}>
      {segments.map((segment, index) =>
        segment.kind === 'link' ? (
          <Link
            key={index}
            color="accent.fg"
            href={segment.value}
            overflowWrap="anywhere"
            rel="noopener noreferrer"
            target="_blank"
          >
            {segment.value}
          </Link>
        ) : (
          segment.value
        )
      )}
    </Text>
  );
};