@elastic/eui-docusaurus-theme 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ import { IframeHTMLAttributes, ImgHTMLAttributes } from 'react';
2
+ type FigmaAssetBase = {
3
+ /** Figma file/node URL (used for embed mode; kept as source reference for images). */
4
+ url: string;
5
+ /** Required accessible text: iframe `title` / image `alt`. */
6
+ title: string;
7
+ };
8
+ export type FigmaAssetImageProps = FigmaAssetBase & Omit<ImgHTMLAttributes<HTMLImageElement>, 'src' | 'title' | 'alt'> & {
9
+ /**
10
+ * Renders a static image (default). Pass any image URL string (SVG preferred;
11
+ * WebP/PNG also work). Prefer a colocated URL import, e.g.
12
+ * `import asset from '!url-loader!./assets/….svg'` then `src={asset}`.
13
+ * (Plain `.svg` imports become React components via SVGR and are not valid `img` URLs.)
14
+ */
15
+ type?: 'image';
16
+ src: string;
17
+ };
18
+ export type FigmaAssetEmbedProps = FigmaAssetBase & Omit<IframeHTMLAttributes<HTMLIFrameElement>, 'src' | 'title'> & {
19
+ /** Renders an interactive Figma iframe from `url`. */
20
+ type: 'embed';
21
+ src?: never;
22
+ };
23
+ export type FigmaAssetProps = FigmaAssetImageProps | FigmaAssetEmbedProps;
24
+ export declare const FigmaAsset: (props: FigmaAssetProps) => import("@emotion/react/jsx-runtime").JSX.Element;
25
+ export {};
@@ -0,0 +1,60 @@
1
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
2
+ /*
3
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4
+ * or more contributor license agreements. Licensed under the Elastic License
5
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
6
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
7
+ * Side Public License, v 1.
8
+ */
9
+ import { useMemo, } from 'react';
10
+ import { useEuiMemoizedStyles } from '@elastic/eui';
11
+ import { css } from '@emotion/react';
12
+ import useBaseUrl from '@docusaurus/useBaseUrl';
13
+ const getFigmaAssetStyles = (euiTheme) => ({
14
+ wrapper: css `
15
+ border: 1px solid ${euiTheme.euiTheme.colors.borderBasePlain};
16
+ border-radius: ${euiTheme.euiTheme.size.s};
17
+ margin: ${euiTheme.euiTheme.size.xl} 0;
18
+ overflow: hidden;
19
+ background-color: ${euiTheme.euiTheme.colors.backgroundLightText};
20
+ `,
21
+ iframe: css `
22
+ border-radius: ${euiTheme.euiTheme.size.s};
23
+ display: block;
24
+ `,
25
+ image: css `
26
+ display: block;
27
+ width: 100%;
28
+ max-width: 100%;
29
+ height: auto;
30
+ `,
31
+ });
32
+ export const FigmaAsset = (props) => {
33
+ const { url, title } = props;
34
+ const baseUrl = useBaseUrl('/', { absolute: true });
35
+ const imageSrcProp = props.type === 'embed' ? undefined : props.src;
36
+ const imageSrcString = typeof imageSrcProp === 'string' ? imageSrcProp : undefined;
37
+ const baseImageSrc = useBaseUrl(imageSrcString?.startsWith('/') ? imageSrcString : '/');
38
+ // Imported assets are already resolved URLs; only site-root paths need useBaseUrl.
39
+ const imageSrc = imageSrcString?.startsWith('/')
40
+ ? baseImageSrc
41
+ : (imageSrcString ?? '');
42
+ const styles = useEuiMemoizedStyles(getFigmaAssetStyles);
43
+ const embedSrc = useMemo(() => {
44
+ const params = new URLSearchParams({
45
+ embed_host: 'eui.elastic.co',
46
+ embed_origin: baseUrl,
47
+ url,
48
+ });
49
+ return `https://www.figma.com/embed?${params.toString()}`;
50
+ }, [url, baseUrl]);
51
+ if (props.type === 'embed') {
52
+ const { url: _url, title: _title, type: _type, ...iframeRest } = props;
53
+ return (_jsx("div", { css: styles.wrapper, children: _jsx("iframe", { ...iframeRest, css: styles.iframe, title: title, height: "450", width: "100%", src: embedSrc, allowFullScreen: true }) }));
54
+ }
55
+ const { url: _url, title: _title, type: _type, src: _src, ...imgRest } = props;
56
+ if (typeof props.src !== 'string') {
57
+ throw new Error('FigmaAsset: `src` must be a URL string. Import SVGs with `!url-loader!` (e.g. `import asset from \'!url-loader!./assets/foo.svg\'`), not as a bare `.svg` module (SVGR returns a React component).');
58
+ }
59
+ return (_jsx("div", { css: styles.wrapper, children: _jsx("img", { ...imgRest, css: styles.image, src: imageSrc, alt: title }) }));
60
+ };
@@ -1,6 +1,7 @@
1
1
  export { AppThemeContext, useAppTheme } from './theme_context';
2
2
  export { Badge } from './badge';
3
- export { FigmaEmbed } from './figma_embed';
3
+ export { FigmaAsset } from './figma_asset';
4
+ export type { FigmaAssetProps, FigmaAssetImageProps, FigmaAssetEmbedProps, } from './figma_asset';
4
5
  export { Guideline, GuidelineText } from './guideline';
5
6
  export { Icon } from './icon';
6
7
  export { PropTable } from './prop_table';
@@ -7,7 +7,7 @@
7
7
  */
8
8
  export { AppThemeContext, useAppTheme } from './theme_context';
9
9
  export { Badge } from './badge';
10
- export { FigmaEmbed } from './figma_embed';
10
+ export { FigmaAsset } from './figma_asset';
11
11
  export { Guideline, GuidelineText } from './guideline';
12
12
  export { Icon } from './icon';
13
13
  export { PropTable } from './prop_table';
@@ -6,7 +6,7 @@
6
6
  * Side Public License, v 1.
7
7
  */
8
8
  import OriginalMDXComponents from '@theme-init/MDXComponents';
9
- import { Badge, Demo, DemoSource, FigmaEmbed, Guideline, GuidelineText, Icon, PropTable, } from '../../components';
9
+ import { Badge, Demo, DemoSource, FigmaAsset, Guideline, GuidelineText, Icon, PropTable, } from '../../components';
10
10
  import { ListItem } from './ListItem';
11
11
  import { Blockquote } from './Blockquote';
12
12
  import { Paragraph } from './Paragraph';
@@ -37,7 +37,7 @@ const MDXComponents = {
37
37
  Badge,
38
38
  Demo,
39
39
  DemoSource,
40
- FigmaEmbed,
40
+ FigmaAsset,
41
41
  Guideline,
42
42
  GuidelineText,
43
43
  Icon,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elastic/eui-docusaurus-theme",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "EUI theme for Docusaurus",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "scripts": {
@@ -40,7 +40,7 @@
40
40
  "@docusaurus/theme-common": "^3.7.0",
41
41
  "@docusaurus/utils-validation": "^3.7.0",
42
42
  "@elastic/datemath": "^5.0.3",
43
- "@elastic/eui": "^117.1.0",
43
+ "@elastic/eui": "^118.0.0",
44
44
  "@elastic/eui-theme-borealis": "^8.0.0",
45
45
  "@emotion/css": "^11.11.2",
46
46
  "@emotion/react": "^11.11.4",
@@ -0,0 +1,123 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
5
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
6
+ * Side Public License, v 1.
7
+ */
8
+
9
+ import {
10
+ IframeHTMLAttributes,
11
+ ImgHTMLAttributes,
12
+ useMemo,
13
+ } from 'react';
14
+ import { useEuiMemoizedStyles, UseEuiTheme } from '@elastic/eui';
15
+ import { css } from '@emotion/react';
16
+ import useBaseUrl from '@docusaurus/useBaseUrl';
17
+
18
+ type FigmaAssetBase = {
19
+ /** Figma file/node URL (used for embed mode; kept as source reference for images). */
20
+ url: string;
21
+ /** Required accessible text: iframe `title` / image `alt`. */
22
+ title: string;
23
+ };
24
+
25
+ export type FigmaAssetImageProps = FigmaAssetBase &
26
+ Omit<ImgHTMLAttributes<HTMLImageElement>, 'src' | 'title' | 'alt'> & {
27
+ /**
28
+ * Renders a static image (default). Pass any image URL string (SVG preferred;
29
+ * WebP/PNG also work). Prefer a colocated URL import, e.g.
30
+ * `import asset from '!url-loader!./assets/….svg'` then `src={asset}`.
31
+ * (Plain `.svg` imports become React components via SVGR and are not valid `img` URLs.)
32
+ */
33
+ type?: 'image';
34
+ src: string;
35
+ };
36
+
37
+ export type FigmaAssetEmbedProps = FigmaAssetBase &
38
+ Omit<IframeHTMLAttributes<HTMLIFrameElement>, 'src' | 'title'> & {
39
+ /** Renders an interactive Figma iframe from `url`. */
40
+ type: 'embed';
41
+ src?: never;
42
+ };
43
+
44
+ export type FigmaAssetProps = FigmaAssetImageProps | FigmaAssetEmbedProps;
45
+
46
+ const getFigmaAssetStyles = (euiTheme: UseEuiTheme) => ({
47
+ wrapper: css`
48
+ border: 1px solid ${euiTheme.euiTheme.colors.borderBasePlain};
49
+ border-radius: ${euiTheme.euiTheme.size.s};
50
+ margin: ${euiTheme.euiTheme.size.xl} 0;
51
+ overflow: hidden;
52
+ background-color: ${euiTheme.euiTheme.colors.backgroundLightText};
53
+ `,
54
+ iframe: css`
55
+ border-radius: ${euiTheme.euiTheme.size.s};
56
+ display: block;
57
+ `,
58
+ image: css`
59
+ display: block;
60
+ width: 100%;
61
+ max-width: 100%;
62
+ height: auto;
63
+ `,
64
+ });
65
+
66
+ export const FigmaAsset = (props: FigmaAssetProps) => {
67
+ const { url, title } = props;
68
+ const baseUrl = useBaseUrl('/', { absolute: true });
69
+ const imageSrcProp = props.type === 'embed' ? undefined : props.src;
70
+ const imageSrcString =
71
+ typeof imageSrcProp === 'string' ? imageSrcProp : undefined;
72
+ const baseImageSrc = useBaseUrl(
73
+ imageSrcString?.startsWith('/') ? imageSrcString : '/'
74
+ );
75
+ // Imported assets are already resolved URLs; only site-root paths need useBaseUrl.
76
+ const imageSrc = imageSrcString?.startsWith('/')
77
+ ? baseImageSrc
78
+ : (imageSrcString ?? '');
79
+ const styles = useEuiMemoizedStyles(getFigmaAssetStyles);
80
+
81
+ const embedSrc = useMemo(() => {
82
+ const params = new URLSearchParams({
83
+ embed_host: 'eui.elastic.co',
84
+ embed_origin: baseUrl,
85
+ url,
86
+ });
87
+
88
+ return `https://www.figma.com/embed?${params.toString()}`;
89
+ }, [url, baseUrl]);
90
+
91
+ if (props.type === 'embed') {
92
+ const { url: _url, title: _title, type: _type, ...iframeRest } = props;
93
+
94
+ return (
95
+ <div css={styles.wrapper}>
96
+ <iframe
97
+ {...iframeRest}
98
+ css={styles.iframe}
99
+ title={title}
100
+ height="450"
101
+ width="100%"
102
+ src={embedSrc}
103
+ allowFullScreen
104
+ />
105
+ </div>
106
+ );
107
+ }
108
+
109
+ const { url: _url, title: _title, type: _type, src: _src, ...imgRest } =
110
+ props;
111
+
112
+ if (typeof props.src !== 'string') {
113
+ throw new Error(
114
+ 'FigmaAsset: `src` must be a URL string. Import SVGs with `!url-loader!` (e.g. `import asset from \'!url-loader!./assets/foo.svg\'`), not as a bare `.svg` module (SVGR returns a React component).'
115
+ );
116
+ }
117
+
118
+ return (
119
+ <div css={styles.wrapper}>
120
+ <img {...imgRest} css={styles.image} src={imageSrc} alt={title} />
121
+ </div>
122
+ );
123
+ };
@@ -8,7 +8,12 @@
8
8
 
9
9
  export { AppThemeContext, useAppTheme } from './theme_context';
10
10
  export { Badge } from './badge';
11
- export { FigmaEmbed } from './figma_embed';
11
+ export { FigmaAsset } from './figma_asset';
12
+ export type {
13
+ FigmaAssetProps,
14
+ FigmaAssetImageProps,
15
+ FigmaAssetEmbedProps,
16
+ } from './figma_asset';
12
17
  export { Guideline, GuidelineText } from './guideline';
13
18
  export { Icon } from './icon';
14
19
  export { PropTable } from './prop_table';
@@ -11,7 +11,7 @@ import {
11
11
  Badge,
12
12
  Demo,
13
13
  DemoSource,
14
- FigmaEmbed,
14
+ FigmaAsset,
15
15
  Guideline,
16
16
  GuidelineText,
17
17
  Icon,
@@ -51,7 +51,7 @@ const MDXComponents = {
51
51
  Badge,
52
52
  Demo,
53
53
  DemoSource,
54
- FigmaEmbed,
54
+ FigmaAsset,
55
55
  Guideline,
56
56
  GuidelineText,
57
57
  Icon,
@@ -1,5 +0,0 @@
1
- import { IframeHTMLAttributes } from 'react';
2
- export interface FigmaEmbedProps extends IframeHTMLAttributes<HTMLIFrameElement> {
3
- url: string;
4
- }
5
- export declare const FigmaEmbed: ({ url, ...rest }: FigmaEmbedProps) => import("@emotion/react/jsx-runtime").JSX.Element;
@@ -1,36 +0,0 @@
1
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
2
- /*
3
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4
- * or more contributor license agreements. Licensed under the Elastic License
5
- * 2.0 and the Server Side Public License, v 1; you may not use this file except
6
- * in compliance with, at your election, the Elastic License 2.0 or the Server
7
- * Side Public License, v 1.
8
- */
9
- import { useMemo } from 'react';
10
- import { useEuiMemoizedStyles } from '@elastic/eui';
11
- import { css } from '@emotion/react';
12
- import useBaseUrl from '@docusaurus/useBaseUrl';
13
- const getFigmaEmbedStyles = (euiTheme) => ({
14
- wrapper: css `
15
- border: 1px solid ${euiTheme.euiTheme.colors.lightShade};
16
- border-radius: ${euiTheme.euiTheme.size.s};
17
- margin: ${euiTheme.euiTheme.size.xl} 0;
18
- `,
19
- iframe: css `
20
- border-radius: ${euiTheme.euiTheme.size.s};
21
- display: block;
22
- `,
23
- });
24
- export const FigmaEmbed = ({ url, ...rest }) => {
25
- const baseUrl = useBaseUrl('/', { absolute: true });
26
- const styles = useEuiMemoizedStyles(getFigmaEmbedStyles);
27
- const src = useMemo(() => {
28
- const params = new URLSearchParams({
29
- embed_host: 'eui.elastic.co',
30
- embed_origin: baseUrl,
31
- url,
32
- });
33
- return `https://www.figma.com/embed?${params.toString()}`;
34
- }, [url, baseUrl]);
35
- return (_jsx("div", { css: styles.wrapper, children: _jsx("iframe", { ...rest, css: styles.iframe, height: "450", width: "100%", src: src, allowFullScreen: true }) }));
36
- };
@@ -1,57 +0,0 @@
1
- /*
2
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
- * or more contributor license agreements. Licensed under the Elastic License
4
- * 2.0 and the Server Side Public License, v 1; you may not use this file except
5
- * in compliance with, at your election, the Elastic License 2.0 or the Server
6
- * Side Public License, v 1.
7
- */
8
-
9
- import { IframeHTMLAttributes, useMemo } from 'react';
10
- import { useEuiMemoizedStyles, UseEuiTheme } from '@elastic/eui';
11
- import { css } from '@emotion/react';
12
- import useBaseUrl from '@docusaurus/useBaseUrl';
13
-
14
- export interface FigmaEmbedProps
15
- extends IframeHTMLAttributes<HTMLIFrameElement> {
16
- url: string;
17
- }
18
-
19
- const getFigmaEmbedStyles = (euiTheme: UseEuiTheme) => ({
20
- wrapper: css`
21
- border: 1px solid ${euiTheme.euiTheme.colors.lightShade};
22
- border-radius: ${euiTheme.euiTheme.size.s};
23
- margin: ${euiTheme.euiTheme.size.xl} 0;
24
- `,
25
- iframe: css`
26
- border-radius: ${euiTheme.euiTheme.size.s};
27
- display: block;
28
- `,
29
- });
30
-
31
- export const FigmaEmbed = ({ url, ...rest }: FigmaEmbedProps) => {
32
- const baseUrl = useBaseUrl('/', { absolute: true });
33
- const styles = useEuiMemoizedStyles(getFigmaEmbedStyles);
34
-
35
- const src = useMemo(() => {
36
- const params = new URLSearchParams({
37
- embed_host: 'eui.elastic.co',
38
- embed_origin: baseUrl,
39
- url,
40
- });
41
-
42
- return `https://www.figma.com/embed?${params.toString()}`;
43
- }, [url, baseUrl]);
44
-
45
- return (
46
- <div css={styles.wrapper}>
47
- <iframe
48
- {...rest}
49
- css={styles.iframe}
50
- height="450"
51
- width="100%"
52
- src={src}
53
- allowFullScreen
54
- />
55
- </div>
56
- );
57
- };