diff --git a/packages/docusaurus-theme/src/components/figma_embed/index.tsx b/packages/docusaurus-theme/src/components/figma_embed/index.tsx new file mode 100644 index 00000000000..9522b55ac77 --- /dev/null +++ b/packages/docusaurus-theme/src/components/figma_embed/index.tsx @@ -0,0 +1,57 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { IframeHTMLAttributes, useMemo } from 'react'; +import { useEuiMemoizedStyles, UseEuiTheme } from '@elastic/eui'; +import { css } from '@emotion/react'; +import useBaseUrl from '@docusaurus/useBaseUrl'; + +export interface FigmaEmbedProps + extends IframeHTMLAttributes { + url: string; +} + +const getFigmaEmbedStyles = (euiTheme: UseEuiTheme) => ({ + wrapper: css` + border: 1px solid ${euiTheme.euiTheme.colors.lightShade}; + border-radius: ${euiTheme.euiTheme.size.s}; + margin: ${euiTheme.euiTheme.size.xl} 0; + `, + iframe: css` + border-radius: ${euiTheme.euiTheme.size.s}; + display: block; + `, +}); + +export const FigmaEmbed = ({ url, ...rest }: FigmaEmbedProps) => { + const baseUrl = useBaseUrl('/', { absolute: true }); + const styles = useEuiMemoizedStyles(getFigmaEmbedStyles); + + const src = useMemo(() => { + const params = new URLSearchParams({ + embed_host: 'eui.elastic.co', + embed_origin: baseUrl, + url, + }); + + return `https://www.figma.com/embed?${params.toString()}`; + }, [url, baseUrl]); + + return ( +
+