@elastic/eui-docusaurus-theme 2.0.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.
- package/LICENSE.txt +6 -0
- package/README.md +292 -0
- package/lib/.tsbuildinfo-client +1 -0
- package/lib/components/badge/index.d.ts +1 -0
- package/lib/components/badge/index.js +9 -0
- package/lib/components/codesandbox_icon/codesandbox_icon.d.ts +4 -0
- package/lib/components/codesandbox_icon/codesandbox_icon.js +2 -0
- package/lib/components/codesandbox_icon/index.d.ts +1 -0
- package/lib/components/codesandbox_icon/index.js +8 -0
- package/lib/components/demo/actions_bar/actions_bar.d.ts +10 -0
- package/lib/components/demo/actions_bar/actions_bar.js +34 -0
- package/lib/components/demo/actions_bar/index.d.ts +1 -0
- package/lib/components/demo/actions_bar/index.js +8 -0
- package/lib/components/demo/code_transformer.d.ts +18 -0
- package/lib/components/demo/code_transformer.js +39 -0
- package/lib/components/demo/codesandbox/find_external_dependencies.d.ts +5 -0
- package/lib/components/demo/codesandbox/find_external_dependencies.js +30 -0
- package/lib/components/demo/codesandbox/index.d.ts +1 -0
- package/lib/components/demo/codesandbox/index.js +8 -0
- package/lib/components/demo/codesandbox/open_action.d.ts +16 -0
- package/lib/components/demo/codesandbox/open_action.js +91 -0
- package/lib/components/demo/context.d.ts +14 -0
- package/lib/components/demo/context.js +13 -0
- package/lib/components/demo/create_demo.d.ts +5 -0
- package/lib/components/demo/create_demo.js +13 -0
- package/lib/components/demo/demo.d.ts +23 -0
- package/lib/components/demo/demo.js +61 -0
- package/lib/components/demo/editor/editor.d.ts +1 -0
- package/lib/components/demo/editor/editor.js +39 -0
- package/lib/components/demo/editor/index.d.ts +1 -0
- package/lib/components/demo/editor/index.js +8 -0
- package/lib/components/demo/index.d.ts +3 -0
- package/lib/components/demo/index.js +10 -0
- package/lib/components/demo/preview/index.d.ts +1 -0
- package/lib/components/demo/preview/index.js +8 -0
- package/lib/components/demo/preview/preview.d.ts +7 -0
- package/lib/components/demo/preview/preview.js +36 -0
- package/lib/components/demo/scope.d.ts +1 -0
- package/lib/components/demo/scope.js +12 -0
- package/lib/components/demo/source/get_source_from_children.d.ts +11 -0
- package/lib/components/demo/source/get_source_from_children.js +42 -0
- package/lib/components/demo/source/index.d.ts +1 -0
- package/lib/components/demo/source/index.js +8 -0
- package/lib/components/demo/source/source.d.ts +6 -0
- package/lib/components/demo/source/source.js +25 -0
- package/lib/components/figma_embed/index.d.ts +5 -0
- package/lib/components/figma_embed/index.js +36 -0
- package/lib/components/guideline/guideline.d.ts +10 -0
- package/lib/components/guideline/guideline.js +68 -0
- package/lib/components/guideline/guideline_text.d.ts +6 -0
- package/lib/components/guideline/guideline_text.js +28 -0
- package/lib/components/guideline/index.d.ts +2 -0
- package/lib/components/guideline/index.js +9 -0
- package/lib/components/guideline/types.d.ts +1 -0
- package/lib/components/guideline/types.js +8 -0
- package/lib/components/high_contrast_mode_toggle/index.d.ts +1 -0
- package/lib/components/high_contrast_mode_toggle/index.js +15 -0
- package/lib/components/icon/index.d.ts +1 -0
- package/lib/components/icon/index.js +9 -0
- package/lib/components/index.d.ts +7 -0
- package/lib/components/index.js +14 -0
- package/lib/components/navbar_item/index.d.ts +19 -0
- package/lib/components/navbar_item/index.js +84 -0
- package/lib/components/prop_table/definition_types.d.ts +43 -0
- package/lib/components/prop_table/definition_types.js +8 -0
- package/lib/components/prop_table/extended_types.d.ts +5 -0
- package/lib/components/prop_table/extended_types.js +27 -0
- package/lib/components/prop_table/extended_types_info.d.ts +26 -0
- package/lib/components/prop_table/extended_types_info.js +34 -0
- package/lib/components/prop_table/index.d.ts +1 -0
- package/lib/components/prop_table/index.js +8 -0
- package/lib/components/prop_table/prop_table.d.ts +8 -0
- package/lib/components/prop_table/prop_table.js +115 -0
- package/lib/components/theme_context/index.d.ts +16 -0
- package/lib/components/theme_context/index.js +103 -0
- package/lib/components/theme_context/theme_overrides.d.ts +2 -0
- package/lib/components/theme_context/theme_overrides.js +12 -0
- package/lib/components/version_switcher/index.d.ts +23 -0
- package/lib/components/version_switcher/index.js +51 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +19 -0
- package/lib/index.js.map +1 -0
- package/lib/theme/Admonition/Types.d.ts +3 -0
- package/lib/theme/Admonition/Types.js +51 -0
- package/lib/theme/CodeBlock/index.d.ts +3 -0
- package/lib/theme/CodeBlock/index.js +35 -0
- package/lib/theme/ColorModeToggle/index.d.ts +10 -0
- package/lib/theme/ColorModeToggle/index.js +51 -0
- package/lib/theme/Demo/actions.d.ts +8 -0
- package/lib/theme/Demo/actions.js +8 -0
- package/lib/theme/Demo/default_scope.d.ts +3 -0
- package/lib/theme/Demo/default_scope.js +17 -0
- package/lib/theme/DocBreadcrumbs/Items/Home/index.d.ts +2 -0
- package/lib/theme/DocBreadcrumbs/Items/Home/index.js +15 -0
- package/lib/theme/DocBreadcrumbs/Items/item.styles.d.ts +5 -0
- package/lib/theme/DocBreadcrumbs/Items/item.styles.js +40 -0
- package/lib/theme/DocBreadcrumbs/index.d.ts +2 -0
- package/lib/theme/DocBreadcrumbs/index.js +63 -0
- package/lib/theme/DocItem/Content/index.d.ts +3 -0
- package/lib/theme/DocItem/Content/index.js +44 -0
- package/lib/theme/DocItem/Footer/index.d.ts +2 -0
- package/lib/theme/DocItem/Footer/index.js +17 -0
- package/lib/theme/DocItem/Layout/index.d.ts +3 -0
- package/lib/theme/DocItem/Layout/index.js +71 -0
- package/lib/theme/DocItem/Metadata/index.d.ts +2 -0
- package/lib/theme/DocItem/Metadata/index.js +7 -0
- package/lib/theme/DocItem/Paginator/index.d.ts +6 -0
- package/lib/theme/DocItem/Paginator/index.js +11 -0
- package/lib/theme/DocItem/TOC/Desktop/index.d.ts +2 -0
- package/lib/theme/DocItem/TOC/Desktop/index.js +8 -0
- package/lib/theme/DocItem/TOC/Mobile/index.d.ts +2 -0
- package/lib/theme/DocItem/TOC/Mobile/index.js +17 -0
- package/lib/theme/DocItem/index.d.ts +3 -0
- package/lib/theme/DocItem/index.js +10 -0
- package/lib/theme/DocPaginator/index.d.ts +3 -0
- package/lib/theme/DocPaginator/index.js +19 -0
- package/lib/theme/DocRoot/Layout/Main/index.d.ts +3 -0
- package/lib/theme/DocRoot/Layout/Main/index.js +35 -0
- package/lib/theme/DocRoot/Layout/Sidebar/index.d.ts +3 -0
- package/lib/theme/DocRoot/Layout/Sidebar/index.js +81 -0
- package/lib/theme/DocRoot/Layout/index.d.ts +3 -0
- package/lib/theme/DocRoot/Layout/index.js +47 -0
- package/lib/theme/DocSidebarItem/Category/index.d.ts +3 -0
- package/lib/theme/DocSidebarItem/Category/index.js +146 -0
- package/lib/theme/DocSidebarItem/Link/index.d.ts +3 -0
- package/lib/theme/DocSidebarItem/Link/index.js +39 -0
- package/lib/theme/DocSidebarItem/index.d.ts +3 -0
- package/lib/theme/DocSidebarItem/index.js +15 -0
- package/lib/theme/DocSidebarItems/index.d.ts +5 -0
- package/lib/theme/DocSidebarItems/index.js +17 -0
- package/lib/theme/EditThisPage/index.d.ts +3 -0
- package/lib/theme/EditThisPage/index.js +17 -0
- package/lib/theme/Footer/index.d.ts +2 -0
- package/lib/theme/Footer/index.js +43 -0
- package/lib/theme/Heading/index.d.ts +3 -0
- package/lib/theme/Heading/index.js +49 -0
- package/lib/theme/Logo/index.d.ts +3 -0
- package/lib/theme/Logo/index.js +80 -0
- package/lib/theme/MDXComponents/A.d.ts +6 -0
- package/lib/theme/MDXComponents/A.js +17 -0
- package/lib/theme/MDXComponents/Blockquote.d.ts +2 -0
- package/lib/theme/MDXComponents/Blockquote.js +18 -0
- package/lib/theme/MDXComponents/Code.d.ts +6 -0
- package/lib/theme/MDXComponents/Code.js +35 -0
- package/lib/theme/MDXComponents/Heading.d.ts +4 -0
- package/lib/theme/MDXComponents/Heading.js +4 -0
- package/lib/theme/MDXComponents/ListItem.d.ts +2 -0
- package/lib/theme/MDXComponents/ListItem.js +5 -0
- package/lib/theme/MDXComponents/OrderedList.d.ts +2 -0
- package/lib/theme/MDXComponents/OrderedList.js +11 -0
- package/lib/theme/MDXComponents/Paragraph.d.ts +2 -0
- package/lib/theme/MDXComponents/Paragraph.js +18 -0
- package/lib/theme/MDXComponents/Table.d.ts +2 -0
- package/lib/theme/MDXComponents/Table.js +3 -0
- package/lib/theme/MDXComponents/TableBody.d.ts +2 -0
- package/lib/theme/MDXComponents/TableBody.js +3 -0
- package/lib/theme/MDXComponents/TableDataCell.d.ts +2 -0
- package/lib/theme/MDXComponents/TableDataCell.js +3 -0
- package/lib/theme/MDXComponents/TableHeader.d.ts +2 -0
- package/lib/theme/MDXComponents/TableHeader.js +3 -0
- package/lib/theme/MDXComponents/TableHeaderCell.d.ts +2 -0
- package/lib/theme/MDXComponents/TableHeaderCell.js +3 -0
- package/lib/theme/MDXComponents/TableRow.d.ts +2 -0
- package/lib/theme/MDXComponents/TableRow.js +3 -0
- package/lib/theme/MDXComponents/UnorderedList.d.ts +2 -0
- package/lib/theme/MDXComponents/UnorderedList.js +11 -0
- package/lib/theme/MDXComponents/index.d.ts +2 -0
- package/lib/theme/MDXComponents/index.js +46 -0
- package/lib/theme/MDXContent/index.d.ts +6 -0
- package/lib/theme/MDXContent/index.js +4 -0
- package/lib/theme/Navbar/Content/index.d.ts +7 -0
- package/lib/theme/Navbar/Content/index.js +149 -0
- package/lib/theme/Navbar/Layout/index.d.ts +6 -0
- package/lib/theme/Navbar/Layout/index.js +59 -0
- package/lib/theme/Navbar/MobileSidebar/Header/index.d.ts +7 -0
- package/lib/theme/Navbar/MobileSidebar/Header/index.js +46 -0
- package/lib/theme/Navbar/MobileSidebar/Layout/index.d.ts +6 -0
- package/lib/theme/Navbar/MobileSidebar/Layout/index.js +26 -0
- package/lib/theme/Navbar/MobileSidebar/index.d.ts +7 -0
- package/lib/theme/Navbar/MobileSidebar/index.js +14 -0
- package/lib/theme/NavbarItem/DropdownNavbarItem/index.d.ts +3 -0
- package/lib/theme/NavbarItem/DropdownNavbarItem/index.js +94 -0
- package/lib/theme/NavbarItem/NavbarNavLink.d.ts +7 -0
- package/lib/theme/NavbarItem/NavbarNavLink.js +48 -0
- package/lib/theme/PaginatorNavLink/index.d.ts +3 -0
- package/lib/theme/PaginatorNavLink/index.js +43 -0
- package/lib/theme/Root.d.ts +3 -0
- package/lib/theme/Root.js +66 -0
- package/lib/theme/Root.styles.d.ts +2 -0
- package/lib/theme/Root.styles.js +111 -0
- package/lib/theme/TOCCollapsible/CollapseButton/index.d.ts +3 -0
- package/lib/theme/TOCCollapsible/CollapseButton/index.js +23 -0
- package/lib/theme/TOCItems/Tree.d.ts +5 -0
- package/lib/theme/TOCItems/Tree.js +80 -0
- package/lib/theme/infima.styles.d.ts +1 -0
- package/lib/theme/infima.styles.js +1456 -0
- package/lib/theme/reset.styles.d.ts +2 -0
- package/lib/theme/reset.styles.js +79 -0
- package/package.json +61 -0
- package/src/components/badge/index.ts +11 -0
- package/src/components/codesandbox_icon/codesandbox_icon.tsx +24 -0
- package/src/components/codesandbox_icon/index.ts +9 -0
- package/src/components/demo/actions_bar/actions_bar.tsx +95 -0
- package/src/components/demo/actions_bar/index.ts +9 -0
- package/src/components/demo/code_transformer.ts +44 -0
- package/src/components/demo/codesandbox/find_external_dependencies.ts +34 -0
- package/src/components/demo/codesandbox/index.ts +9 -0
- package/src/components/demo/codesandbox/open_action.tsx +132 -0
- package/src/components/demo/context.ts +30 -0
- package/src/components/demo/create_demo.tsx +17 -0
- package/src/components/demo/demo.tsx +143 -0
- package/src/components/demo/editor/editor.tsx +51 -0
- package/src/components/demo/editor/index.ts +9 -0
- package/src/components/demo/index.ts +11 -0
- package/src/components/demo/preview/index.ts +9 -0
- package/src/components/demo/preview/preview.tsx +77 -0
- package/src/components/demo/scope.ts +14 -0
- package/src/components/demo/source/get_source_from_children.ts +59 -0
- package/src/components/demo/source/index.ts +9 -0
- package/src/components/demo/source/source.tsx +36 -0
- package/src/components/figma_embed/index.tsx +57 -0
- package/src/components/guideline/guideline.tsx +121 -0
- package/src/components/guideline/guideline_text.tsx +51 -0
- package/src/components/guideline/index.ts +10 -0
- package/src/components/guideline/types.ts +9 -0
- package/src/components/high_contrast_mode_toggle/index.tsx +28 -0
- package/src/components/icon/index.ts +11 -0
- package/src/components/index.ts +15 -0
- package/src/components/navbar_item/index.tsx +164 -0
- package/src/components/prop_table/definition_types.ts +53 -0
- package/src/components/prop_table/extended_types.tsx +66 -0
- package/src/components/prop_table/extended_types_info.ts +35 -0
- package/src/components/prop_table/index.ts +9 -0
- package/src/components/prop_table/prop_table.tsx +235 -0
- package/src/components/theme_context/index.tsx +156 -0
- package/src/components/theme_context/theme_overrides.ts +15 -0
- package/src/components/version_switcher/index.tsx +144 -0
- package/src/index.ts +21 -0
- package/src/theme/Admonition/Types.tsx +85 -0
- package/src/theme/CodeBlock/index.tsx +57 -0
- package/src/theme/ColorModeToggle/index.tsx +93 -0
- package/src/theme/Demo/actions.tsx +20 -0
- package/src/theme/Demo/default_scope.ts +19 -0
- package/src/theme/DocBreadcrumbs/Items/Home/index.tsx +38 -0
- package/src/theme/DocBreadcrumbs/Items/item.styles.ts +43 -0
- package/src/theme/DocBreadcrumbs/index.tsx +144 -0
- package/src/theme/DocItem/Content/index.tsx +75 -0
- package/src/theme/DocItem/Footer/index.tsx +59 -0
- package/src/theme/DocItem/Layout/index.tsx +112 -0
- package/src/theme/DocItem/Metadata/index.tsx +23 -0
- package/src/theme/DocItem/Paginator/index.tsx +20 -0
- package/src/theme/DocItem/TOC/Desktop/index.tsx +24 -0
- package/src/theme/DocItem/TOC/Mobile/index.tsx +35 -0
- package/src/theme/DocItem/index.tsx +30 -0
- package/src/theme/DocPaginator/index.tsx +64 -0
- package/src/theme/DocRoot/Layout/Main/index.tsx +61 -0
- package/src/theme/DocRoot/Layout/Sidebar/index.tsx +124 -0
- package/src/theme/DocRoot/Layout/index.tsx +72 -0
- package/src/theme/DocSidebarItem/Category/index.tsx +266 -0
- package/src/theme/DocSidebarItem/Link/index.tsx +86 -0
- package/src/theme/DocSidebarItem/index.tsx +29 -0
- package/src/theme/DocSidebarItems/index.tsx +30 -0
- package/src/theme/EditThisPage/index.tsx +50 -0
- package/src/theme/Footer/index.tsx +67 -0
- package/src/theme/Heading/index.tsx +94 -0
- package/src/theme/Logo/index.tsx +146 -0
- package/src/theme/MDXComponents/A.tsx +33 -0
- package/src/theme/MDXComponents/Blockquote.tsx +35 -0
- package/src/theme/MDXComponents/Code.tsx +60 -0
- package/src/theme/MDXComponents/Heading.tsx +16 -0
- package/src/theme/MDXComponents/ListItem.tsx +20 -0
- package/src/theme/MDXComponents/OrderedList.tsx +26 -0
- package/src/theme/MDXComponents/Paragraph.tsx +33 -0
- package/src/theme/MDXComponents/Table.tsx +16 -0
- package/src/theme/MDXComponents/TableBody.tsx +16 -0
- package/src/theme/MDXComponents/TableDataCell.tsx +20 -0
- package/src/theme/MDXComponents/TableHeader.tsx +16 -0
- package/src/theme/MDXComponents/TableHeaderCell.tsx +20 -0
- package/src/theme/MDXComponents/TableRow.tsx +16 -0
- package/src/theme/MDXComponents/UnorderedList.tsx +26 -0
- package/src/theme/MDXComponents/index.ts +61 -0
- package/src/theme/MDXContent/index.tsx +22 -0
- package/src/theme/Navbar/Content/index.tsx +262 -0
- package/src/theme/Navbar/Layout/index.tsx +100 -0
- package/src/theme/Navbar/MobileSidebar/Header/index.tsx +89 -0
- package/src/theme/Navbar/MobileSidebar/Layout/index.tsx +44 -0
- package/src/theme/Navbar/MobileSidebar/index.tsx +46 -0
- package/src/theme/NavbarItem/DropdownNavbarItem/index.tsx +200 -0
- package/src/theme/NavbarItem/NavbarNavLink.tsx +141 -0
- package/src/theme/PaginatorNavLink/index.tsx +72 -0
- package/src/theme/Root.styles.ts +122 -0
- package/src/theme/Root.tsx +106 -0
- package/src/theme/TOCCollapsible/CollapseButton/index.tsx +53 -0
- package/src/theme/TOCItems/Tree.tsx +114 -0
- package/src/theme/infima.styles.ts +1458 -0
- package/src/theme/reset.styles.ts +82 -0
- package/src/theme/theme.d.ts +598 -0
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
Children,
|
|
11
|
+
PropsWithChildren,
|
|
12
|
+
useCallback,
|
|
13
|
+
useMemo,
|
|
14
|
+
useState,
|
|
15
|
+
} from 'react';
|
|
16
|
+
import { isElement } from 'react-is';
|
|
17
|
+
import { LiveProvider } from 'react-live';
|
|
18
|
+
import { themes as prismThemes } from 'prism-react-renderer';
|
|
19
|
+
import {
|
|
20
|
+
useEuiMemoizedStyles,
|
|
21
|
+
copyToClipboard,
|
|
22
|
+
UseEuiTheme,
|
|
23
|
+
} from '@elastic/eui';
|
|
24
|
+
import { css } from '@emotion/react';
|
|
25
|
+
import { demoDefaultScope } from '@theme/Demo/default_scope';
|
|
26
|
+
import { DemoContext, DemoContextObject } from './context';
|
|
27
|
+
import { DemoEditor } from './editor';
|
|
28
|
+
import { DemoPreview } from './preview';
|
|
29
|
+
import { DemoSource } from './source';
|
|
30
|
+
import { originalScope } from './scope';
|
|
31
|
+
import { DemoActionsBar } from './actions_bar';
|
|
32
|
+
import { demoCodeTransformer } from './code_transformer';
|
|
33
|
+
import { DemoPreviewProps } from './preview/preview';
|
|
34
|
+
|
|
35
|
+
export interface DemoSourceMeta {
|
|
36
|
+
code: string;
|
|
37
|
+
isActive: boolean;
|
|
38
|
+
filename?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface DemoProps extends PropsWithChildren {
|
|
42
|
+
/**
|
|
43
|
+
* Whether the source code editor is open by default
|
|
44
|
+
*/
|
|
45
|
+
isSourceOpen?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Allows to extend the default scope of the rendered demo and pass additional
|
|
48
|
+
* properties available within the demo.
|
|
49
|
+
*
|
|
50
|
+
* The default scope exposes all React and EUI exports.
|
|
51
|
+
*/
|
|
52
|
+
scope?: Record<string, unknown>;
|
|
53
|
+
previewPadding?: DemoPreviewProps['padding'];
|
|
54
|
+
previewWrapper?: DemoPreviewProps['wrapperComponent'];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const getDemoStyles = (euiTheme: UseEuiTheme) => ({
|
|
58
|
+
demo: css`
|
|
59
|
+
--docs-demo-border-color: ${euiTheme.euiTheme.border.color};
|
|
60
|
+
--docs-demo-border-radius: ${euiTheme.euiTheme.size.s};
|
|
61
|
+
|
|
62
|
+
border: 1px solid var(--docs-demo-border-color);
|
|
63
|
+
border-radius: var(--docs-demo-border-radius);
|
|
64
|
+
margin-block: ${euiTheme.euiTheme.size.xl};
|
|
65
|
+
word-break: break-word;
|
|
66
|
+
`,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export const Demo = ({
|
|
70
|
+
children,
|
|
71
|
+
scope,
|
|
72
|
+
isSourceOpen: _isSourceOpen = false,
|
|
73
|
+
previewPadding,
|
|
74
|
+
previewWrapper,
|
|
75
|
+
}: DemoProps) => {
|
|
76
|
+
const styles = useEuiMemoizedStyles(getDemoStyles);
|
|
77
|
+
const [sources, setSources] = useState<DemoSourceMeta[]>([]);
|
|
78
|
+
const [isSourceOpen, setIsSourceOpen] = useState<boolean>(_isSourceOpen);
|
|
79
|
+
const activeSource = sources[0] || null;
|
|
80
|
+
|
|
81
|
+
// liveProviderKey restarts the demo to its initial state
|
|
82
|
+
const [liveProviderKey, setLiveProviderKey] = useState<number>(0);
|
|
83
|
+
|
|
84
|
+
const finalScope = useMemo(
|
|
85
|
+
() => ({
|
|
86
|
+
...originalScope,
|
|
87
|
+
...demoDefaultScope,
|
|
88
|
+
...scope,
|
|
89
|
+
}),
|
|
90
|
+
[scope]
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
const addSource = useCallback<DemoContextObject['addSource']>(
|
|
94
|
+
(source: DemoSourceMeta) => {
|
|
95
|
+
setSources((sources) => [...sources, source]);
|
|
96
|
+
},
|
|
97
|
+
[]
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const onClickCopyToClipboard = useCallback(() => {
|
|
101
|
+
copyToClipboard(activeSource?.code || '');
|
|
102
|
+
}, [activeSource]);
|
|
103
|
+
|
|
104
|
+
const onClickReloadExample = useCallback(() => {
|
|
105
|
+
setLiveProviderKey((liveProviderKey) => liveProviderKey + 1);
|
|
106
|
+
}, []);
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<div css={styles.demo}>
|
|
110
|
+
<DemoContext.Provider value={{ sources, addSource }}>
|
|
111
|
+
<LiveProvider
|
|
112
|
+
key={liveProviderKey}
|
|
113
|
+
code={activeSource?.code || ''}
|
|
114
|
+
transformCode={demoCodeTransformer}
|
|
115
|
+
theme={prismThemes.dracula}
|
|
116
|
+
scope={finalScope}
|
|
117
|
+
>
|
|
118
|
+
<DemoPreview
|
|
119
|
+
padding={previewPadding}
|
|
120
|
+
wrapperComponent={previewWrapper}
|
|
121
|
+
/>
|
|
122
|
+
<DemoActionsBar
|
|
123
|
+
isSourceOpen={isSourceOpen}
|
|
124
|
+
setSourceOpen={setIsSourceOpen}
|
|
125
|
+
activeSource={activeSource}
|
|
126
|
+
sources={sources}
|
|
127
|
+
onClickCopyToClipboard={onClickCopyToClipboard}
|
|
128
|
+
onClickReloadExample={onClickReloadExample}
|
|
129
|
+
/>
|
|
130
|
+
{isSourceOpen && <DemoEditor />}
|
|
131
|
+
</LiveProvider>
|
|
132
|
+
|
|
133
|
+
{Children.map(children, (child, index) => {
|
|
134
|
+
if (isElement(child) && child.type === DemoSource) {
|
|
135
|
+
return child;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return <DemoSource isActive={index === 0}>{child}</DemoSource>;
|
|
139
|
+
})}
|
|
140
|
+
</DemoContext.Provider>
|
|
141
|
+
</div>
|
|
142
|
+
);
|
|
143
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { LiveEditor, LiveError } from 'react-live';
|
|
10
|
+
import { css } from '@emotion/react';
|
|
11
|
+
import { useEuiMemoizedStyles } from '@elastic/eui';
|
|
12
|
+
|
|
13
|
+
const getEditorStyles = () => ({
|
|
14
|
+
editor: css`
|
|
15
|
+
font-family: var(--ifm-font-family-monospace);
|
|
16
|
+
border-radius: 0 0 var(--docs-demo-border-radius) var(--docs-demo-border-radius);
|
|
17
|
+
|
|
18
|
+
& .prism-code {
|
|
19
|
+
border-radius: 0 0 calc(var(--docs-demo-border-radius) - 1px) calc(var(--docs-demo-border-radius) - 1px);
|
|
20
|
+
max-height: 450px;
|
|
21
|
+
overflow: auto;
|
|
22
|
+
}
|
|
23
|
+
`,
|
|
24
|
+
error: css`
|
|
25
|
+
// docusaurus overrides the default pre styles
|
|
26
|
+
// forcing us to use higher specificity here
|
|
27
|
+
&& > pre {
|
|
28
|
+
font-size: var(--eui-font-size-s);
|
|
29
|
+
background: var(--eui-background-color-danger);
|
|
30
|
+
color: var(--eui-color-danger-text);
|
|
31
|
+
padding: var(--eui-size-xs) var(--eui-size-s);
|
|
32
|
+
margin: 0;
|
|
33
|
+
border-radius: 0;
|
|
34
|
+
}
|
|
35
|
+
`,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export const DemoEditor = () => {
|
|
39
|
+
const styles = useEuiMemoizedStyles(getEditorStyles);
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div css={styles.editor}>
|
|
43
|
+
<div css={styles.error}>
|
|
44
|
+
<LiveError />
|
|
45
|
+
</div>
|
|
46
|
+
<div>
|
|
47
|
+
<LiveEditor tabMode="focus" />
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
export { DemoEditor } from './editor';
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
export { Demo, type DemoProps } from './demo';
|
|
10
|
+
export { DemoSource } from './source';
|
|
11
|
+
export { createDemo } from './create_demo';
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
export { DemoPreview } from './preview';
|
|
@@ -0,0 +1,77 @@
|
|
|
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 { css } from '@emotion/react';
|
|
10
|
+
import { LivePreview } from 'react-live';
|
|
11
|
+
import {
|
|
12
|
+
ComponentType,
|
|
13
|
+
CSSProperties,
|
|
14
|
+
Fragment,
|
|
15
|
+
PropsWithChildren,
|
|
16
|
+
} from 'react';
|
|
17
|
+
import BrowserOnly from '@docusaurus/BrowserOnly';
|
|
18
|
+
import ErrorBoundary from '@docusaurus/ErrorBoundary';
|
|
19
|
+
import { ErrorBoundaryErrorMessageFallback } from '@docusaurus/theme-common';
|
|
20
|
+
import {
|
|
21
|
+
UseEuiTheme,
|
|
22
|
+
useEuiTheme,
|
|
23
|
+
EuiPaddingSize,
|
|
24
|
+
euiPaddingSize,
|
|
25
|
+
} from '@elastic/eui';
|
|
26
|
+
|
|
27
|
+
export interface DemoPreviewProps {
|
|
28
|
+
padding?: EuiPaddingSize;
|
|
29
|
+
wrapperComponent?: ComponentType<PropsWithChildren>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const getPreviewStyles = (euiTheme: UseEuiTheme) => ({
|
|
33
|
+
previewWrapper: css`
|
|
34
|
+
padding: var(--docs-demo-preview-padding);
|
|
35
|
+
border-radius: var(--docs-demo-border-radius);
|
|
36
|
+
`,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* PreviewLoader provides a fallback content for the server-side render
|
|
41
|
+
* of the live component preview component.
|
|
42
|
+
* Due to the limitations of react-live the demo is only rendered client-side.
|
|
43
|
+
*/
|
|
44
|
+
const PreviewLoader = () => <div>Loading...</div>;
|
|
45
|
+
|
|
46
|
+
export const DemoPreview = ({
|
|
47
|
+
padding = 'l',
|
|
48
|
+
wrapperComponent: WrapperComponent = Fragment,
|
|
49
|
+
}: DemoPreviewProps) => {
|
|
50
|
+
const euiTheme = useEuiTheme();
|
|
51
|
+
const styles = getPreviewStyles(euiTheme);
|
|
52
|
+
const paddingSize = euiPaddingSize(euiTheme, padding);
|
|
53
|
+
|
|
54
|
+
const style = {
|
|
55
|
+
'--docs-demo-preview-padding': paddingSize,
|
|
56
|
+
} as CSSProperties;
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<BrowserOnly fallback={<PreviewLoader />}>
|
|
60
|
+
{() => (
|
|
61
|
+
<>
|
|
62
|
+
<ErrorBoundary
|
|
63
|
+
fallback={(params: any) => (
|
|
64
|
+
<ErrorBoundaryErrorMessageFallback {...params} />
|
|
65
|
+
)}
|
|
66
|
+
>
|
|
67
|
+
<div css={styles.previewWrapper} style={style}>
|
|
68
|
+
<WrapperComponent>
|
|
69
|
+
<LivePreview />
|
|
70
|
+
</WrapperComponent>
|
|
71
|
+
</div>
|
|
72
|
+
</ErrorBoundary>
|
|
73
|
+
</>
|
|
74
|
+
)}
|
|
75
|
+
</BrowserOnly>
|
|
76
|
+
);
|
|
77
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
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 React from 'react';
|
|
10
|
+
|
|
11
|
+
export const originalScope: Record<string, unknown> = {
|
|
12
|
+
React,
|
|
13
|
+
...React,
|
|
14
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
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 { Children, ReactElement, ReactNode } from 'react';
|
|
10
|
+
import { isElement } from 'react-is';
|
|
11
|
+
|
|
12
|
+
export interface SourceMeta {
|
|
13
|
+
/**
|
|
14
|
+
* The source code
|
|
15
|
+
*/
|
|
16
|
+
code: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get source string from given children.
|
|
21
|
+
*/
|
|
22
|
+
export const getSourceFromChildren = (children: ReactNode): string | null => {
|
|
23
|
+
// Direct (non-MDX) usage almost always passes a string
|
|
24
|
+
if (typeof children === 'string') {
|
|
25
|
+
return children;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (Children.count(children) !== 1 || !isElement(children)) {
|
|
29
|
+
// This should never happen
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const element = children as ReactElement;
|
|
34
|
+
const functionName = (element.type as Function).name;
|
|
35
|
+
// The code block content could render in either MDXPre (development builds)
|
|
36
|
+
// or pre (optimized production builds)
|
|
37
|
+
if (
|
|
38
|
+
typeof element.type !== 'function' ||
|
|
39
|
+
(functionName !== 'MDXPre' && functionName !== 'pre')
|
|
40
|
+
) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!isElement(element.props.children)) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const codeElement = element.props.children as ReactElement;
|
|
49
|
+
if (!codeElement || !codeElement.props.children) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const code = codeElement.props.children;
|
|
54
|
+
if (typeof code !== 'string') {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return code;
|
|
59
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
export { DemoSource, type DemoSourceProps } from './source';
|
|
@@ -0,0 +1,36 @@
|
|
|
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 { PropsWithChildren, useEffect } from 'react';
|
|
10
|
+
import { useDemoContext } from '../context';
|
|
11
|
+
import { getSourceFromChildren } from './get_source_from_children';
|
|
12
|
+
|
|
13
|
+
export interface DemoSourceProps extends PropsWithChildren {
|
|
14
|
+
filename?: string;
|
|
15
|
+
isActive?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const DemoSource = ({ children, filename, isActive = false }: DemoSourceProps) => {
|
|
19
|
+
const demoContext = useDemoContext();
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
const source = getSourceFromChildren(children);
|
|
23
|
+
|
|
24
|
+
if (source) {
|
|
25
|
+
const transformedSource = source.replace(/\n$/, '');
|
|
26
|
+
|
|
27
|
+
demoContext.addSource({
|
|
28
|
+
code: transformedSource,
|
|
29
|
+
isActive,
|
|
30
|
+
filename,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}, [children]);
|
|
34
|
+
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
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 { PropsWithChildren, ReactNode, useMemo } from 'react';
|
|
10
|
+
import {
|
|
11
|
+
EuiFlexItem,
|
|
12
|
+
EuiSplitPanel,
|
|
13
|
+
EuiPanelProps,
|
|
14
|
+
useEuiMemoizedStyles,
|
|
15
|
+
UseEuiTheme,
|
|
16
|
+
highContrastModeStyles,
|
|
17
|
+
} from '@elastic/eui';
|
|
18
|
+
import { css } from '@emotion/react';
|
|
19
|
+
|
|
20
|
+
import { GuidelineType } from './types';
|
|
21
|
+
import { GuidelineText } from './guideline_text';
|
|
22
|
+
|
|
23
|
+
export interface GuidelineProps extends PropsWithChildren {
|
|
24
|
+
type: GuidelineType;
|
|
25
|
+
text: string | ReactNode;
|
|
26
|
+
panelPadding?: EuiPanelProps['paddingSize'];
|
|
27
|
+
panelStyle?: EuiPanelProps['style'];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const getGuidelineStyles = (euiThemeContext: UseEuiTheme) => {
|
|
31
|
+
const { euiTheme } = euiThemeContext;
|
|
32
|
+
return {
|
|
33
|
+
root: css`
|
|
34
|
+
margin-block: var(--eui-theme-content-vertical-spacing);
|
|
35
|
+
`,
|
|
36
|
+
wrapper: css`
|
|
37
|
+
border-block-end: ${euiTheme.border.thick};
|
|
38
|
+
border-start-start-radius: ${euiTheme.border.radius.medium};
|
|
39
|
+
border-start-end-radius: ${euiTheme.border.radius.medium};
|
|
40
|
+
overflow: hidden;
|
|
41
|
+
|
|
42
|
+
${highContrastModeStyles(euiThemeContext, {
|
|
43
|
+
// Code block is used within a panel which already has a border - skip doubling up
|
|
44
|
+
preferred: `
|
|
45
|
+
& > .euiCodeBlock {
|
|
46
|
+
border: none;
|
|
47
|
+
}
|
|
48
|
+
`,
|
|
49
|
+
})}
|
|
50
|
+
`,
|
|
51
|
+
wrapperDo: css`
|
|
52
|
+
border-color: ${euiTheme.colors.success};
|
|
53
|
+
`,
|
|
54
|
+
wrapperDont: css`
|
|
55
|
+
border-color: ${euiTheme.colors.danger};
|
|
56
|
+
`,
|
|
57
|
+
textWrapper: css`
|
|
58
|
+
margin-block-start: var(--eui-size-xs);
|
|
59
|
+
`,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const Guideline = ({
|
|
64
|
+
children,
|
|
65
|
+
text,
|
|
66
|
+
type = 'default',
|
|
67
|
+
panelPadding = 'm',
|
|
68
|
+
panelStyle,
|
|
69
|
+
}: GuidelineProps) => {
|
|
70
|
+
const styles = useEuiMemoizedStyles(getGuidelineStyles);
|
|
71
|
+
|
|
72
|
+
const panelColor = useMemo((): EuiPanelProps['color'] => {
|
|
73
|
+
if (type === 'do') {
|
|
74
|
+
return 'success';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (type === 'dont') {
|
|
78
|
+
return 'danger';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return 'subdued';
|
|
82
|
+
}, [type]);
|
|
83
|
+
|
|
84
|
+
const textElement = useMemo(() => {
|
|
85
|
+
if (typeof text === 'string') {
|
|
86
|
+
return <GuidelineText type={type}>{text}</GuidelineText>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return text;
|
|
90
|
+
}, [text]);
|
|
91
|
+
|
|
92
|
+
const wrapperStyles = [
|
|
93
|
+
styles.wrapper,
|
|
94
|
+
type === 'do' && styles.wrapperDo,
|
|
95
|
+
type === 'dont' && styles.wrapperDont,
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<EuiFlexItem css={styles.root} style={{ flexBasis: 300 }}>
|
|
100
|
+
<EuiSplitPanel.Outer
|
|
101
|
+
color="transparent"
|
|
102
|
+
hasBorder={false}
|
|
103
|
+
hasShadow={false}
|
|
104
|
+
>
|
|
105
|
+
<figure>
|
|
106
|
+
<EuiSplitPanel.Inner
|
|
107
|
+
css={wrapperStyles}
|
|
108
|
+
color={panelColor}
|
|
109
|
+
paddingSize={panelPadding}
|
|
110
|
+
style={panelStyle}
|
|
111
|
+
>
|
|
112
|
+
{children}
|
|
113
|
+
</EuiSplitPanel.Inner>
|
|
114
|
+
<EuiSplitPanel.Inner paddingSize="none" css={styles.textWrapper}>
|
|
115
|
+
{textElement}
|
|
116
|
+
</EuiSplitPanel.Inner>
|
|
117
|
+
</figure>
|
|
118
|
+
</EuiSplitPanel.Outer>
|
|
119
|
+
</EuiFlexItem>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
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 { PropsWithChildren, useMemo } from 'react';
|
|
10
|
+
import { EuiText, EuiTextProps } from '@elastic/eui';
|
|
11
|
+
|
|
12
|
+
import { GuidelineType } from './types';
|
|
13
|
+
|
|
14
|
+
export interface GuidelineTextProps extends PropsWithChildren {
|
|
15
|
+
type: GuidelineType;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const GuidelineText = ({ type, children }: GuidelineTextProps) => {
|
|
19
|
+
const textPrefix = useMemo(() => {
|
|
20
|
+
if (type === 'default') {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<>
|
|
26
|
+
<strong>{type === 'do' ? 'Do:' : `Don't:`}</strong>
|
|
27
|
+
</>
|
|
28
|
+
);
|
|
29
|
+
}, [type]);
|
|
30
|
+
|
|
31
|
+
const textColor = useMemo((): EuiTextProps['color'] => {
|
|
32
|
+
if (type === 'do') {
|
|
33
|
+
return 'success';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (type === 'dont') {
|
|
37
|
+
return 'danger';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return 'text';
|
|
41
|
+
}, [type]);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<EuiText size="s" color={textColor}>
|
|
45
|
+
<p>
|
|
46
|
+
{textPrefix}
|
|
47
|
+
{children}
|
|
48
|
+
</p>
|
|
49
|
+
</EuiText>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
export { Guideline, type GuidelineProps } from './guideline';
|
|
10
|
+
export { GuidelineText, type GuidelineTextProps } from './guideline_text';
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
export type GuidelineType = 'do' | 'dont' | 'default';
|