diff --git a/webview/src/experiments/components/Experiments.tsx b/webview/src/experiments/components/Experiments.tsx index d540e9d8c4..601b07a444 100644 --- a/webview/src/experiments/components/Experiments.tsx +++ b/webview/src/experiments/components/Experiments.tsx @@ -23,7 +23,7 @@ import styles from './table/styles.module.scss' import { AddColumns, Welcome } from './GetStarted' import buildDynamicColumns from '../util/buildDynamicColumns' import { sendMessage } from '../../shared/vscode' -import { useThemeVariables } from '../../shared/components/theme/Theme' +import { WebviewWrapper } from '../../shared/components/webviewWrapper/WebviewWrapper' import { GetStarted } from '../../shared/components/getStarted/GetStarted' import { DragDropProvider } from '../../shared/components/dragDrop/DragDropContext' import { EmptyState } from '../../shared/components/emptyState/EmptyState' @@ -224,21 +224,14 @@ export const ExperimentsTable: React.FC<{ const Experiments: React.FC<{ tableData?: TableData | null }> = ({ tableData }) => { - const variables = useThemeVariables() return ( -
{ - e.preventDefault() - }} - > + {tableData ? ( ) : ( Loading Experiments... )} -
+ ) } diff --git a/webview/src/plots/components/Plots.tsx b/webview/src/plots/components/Plots.tsx index bac5b9ed28..db96be8223 100644 --- a/webview/src/plots/components/Plots.tsx +++ b/webview/src/plots/components/Plots.tsx @@ -12,7 +12,7 @@ import { ComparisonTableWrapper } from './comparisonTable/ComparisonTableWrapper import { PlotsWebviewState } from '../hooks/useAppReducer' import { EmptyState } from '../../shared/components/emptyState/EmptyState' import { Modal } from '../../shared/components/modal/Modal' -import { useThemeVariables } from '../../shared/components/theme/Theme' +import { WebviewWrapper } from '../../shared/components/webviewWrapper/WebviewWrapper' import { DragDropProvider } from '../../shared/components/dragDrop/DragDropContext' import { sendMessage } from '../../shared/vscode' import { getThemeValue, ThemeProperty } from '../../util/styles' @@ -170,18 +170,8 @@ const PlotsContent = ({ state }: PlotsProps) => { ) } -export const Plots = ({ state }: PlotsProps) => { - const variables = useThemeVariables() - - return ( -
{ - e.preventDefault() - }} - > - -
- ) -} +export const Plots = ({ state }: PlotsProps) => ( + + + +) diff --git a/webview/src/shared/components/theme/Theme.test.tsx b/webview/src/shared/components/webviewWrapper/WebviewWrapper.test.tsx similarity index 88% rename from webview/src/shared/components/theme/Theme.test.tsx rename to webview/src/shared/components/webviewWrapper/WebviewWrapper.test.tsx index 0d279e17d5..e7a4b442a5 100644 --- a/webview/src/shared/components/theme/Theme.test.tsx +++ b/webview/src/shared/components/webviewWrapper/WebviewWrapper.test.tsx @@ -3,17 +3,17 @@ */ import React from 'react' import { render, cleanup, screen } from '@testing-library/react' -import { Theme } from './Theme' +import { WebviewWrapper } from './WebviewWrapper' -describe('Theme', () => { +describe('Wrapper', () => { afterEach(() => { cleanup() }) it('should add some css variables to the markup', () => { - render() + render(Test) - const theme = screen.getByTestId('theme-wrapper') + const theme = screen.getByText('Test') const expectedVariables = [ '--editor-background-transparency-1', '--editor-background-transparency-2', diff --git a/webview/src/shared/components/webviewWrapper/WebviewWrapper.tsx b/webview/src/shared/components/webviewWrapper/WebviewWrapper.tsx new file mode 100644 index 0000000000..64197cf737 --- /dev/null +++ b/webview/src/shared/components/webviewWrapper/WebviewWrapper.tsx @@ -0,0 +1,26 @@ +import React, { ReactNode } from 'react' +import cx from 'classnames' +import { useThemeVariables } from './useThemeVariables' +import styles from './styles.module.scss' + +export const WebviewWrapper = ({ + children, + className +}: { + children: ReactNode + className?: string +}) => { + const themeVariables = useThemeVariables() + + return ( +
{ + e.preventDefault() + }} + > + {children} +
+ ) +} diff --git a/webview/src/shared/components/webviewWrapper/styles.module.scss b/webview/src/shared/components/webviewWrapper/styles.module.scss new file mode 100644 index 0000000000..289632f4b7 --- /dev/null +++ b/webview/src/shared/components/webviewWrapper/styles.module.scss @@ -0,0 +1,4 @@ +.webviewWrapper { + width: 100%; + height: 100%; +} diff --git a/webview/src/shared/components/theme/Theme.tsx b/webview/src/shared/components/webviewWrapper/useThemeVariables.ts similarity index 73% rename from webview/src/shared/components/theme/Theme.tsx rename to webview/src/shared/components/webviewWrapper/useThemeVariables.ts index b918c47749..1e2b717b47 100644 --- a/webview/src/shared/components/theme/Theme.tsx +++ b/webview/src/shared/components/webviewWrapper/useThemeVariables.ts @@ -1,19 +1,8 @@ -import React, { - DetailedHTMLProps, - HTMLAttributes, - useState, - useLayoutEffect, - useCallback -} from 'react' +import { useState, useLayoutEffect, useCallback } from 'react' import { alphaToHex, getThemeValue, ThemeProperty } from '../../../util/styles' -type CSSVariables = DetailedHTMLProps< - HTMLAttributes, - HTMLDivElement -> - export const useThemeVariables = () => { - const [variables, setVariables] = useState({}) + const [variables, setVariables] = useState>({}) const createCSSVariables = useCallback(() => { const ColorsWithOpacity = { @@ -57,12 +46,3 @@ export const useThemeVariables = () => { return variables } - -export const Theme: React.FC = ({ children }) => { - const variables = useThemeVariables() - return ( -
- {children} -
- ) -} diff --git a/webview/src/stories/ComparisonTable.stories.tsx b/webview/src/stories/ComparisonTable.stories.tsx index b3c0b1d78f..b4a63b75c7 100644 --- a/webview/src/stories/ComparisonTable.stories.tsx +++ b/webview/src/stories/ComparisonTable.stories.tsx @@ -7,7 +7,7 @@ import { ComparisonTable, ComparisonTableProps } from '../plots/components/comparisonTable/ComparisonTable' -import { Theme } from '../shared/components/theme/Theme' +import { WebviewWrapper } from '../shared/components/webviewWrapper/WebviewWrapper' import { DragDropProvider } from '../shared/components/dragDrop/DragDropContext' export default { @@ -18,11 +18,11 @@ export default { const Template: Story = ({ plots, revisions }) => { return ( - + - + ) } diff --git a/webview/src/stories/ComparisonTableHeader.stories.tsx b/webview/src/stories/ComparisonTableHeader.stories.tsx index 5f41e48c42..1d1a750c37 100644 --- a/webview/src/stories/ComparisonTableHeader.stories.tsx +++ b/webview/src/stories/ComparisonTableHeader.stories.tsx @@ -1,7 +1,7 @@ import { Meta, Story } from '@storybook/react/types-6-0' import React from 'react' import { ComparisonTableHeader } from '../plots/components/comparisonTable/ComparisonTableHeader' -import { Theme } from '../shared/components/theme/Theme' +import { WebviewWrapper } from '../shared/components/webviewWrapper/WebviewWrapper' const basicArgs = { displayColor: '#945DD6', @@ -24,7 +24,7 @@ const Template: Story<{ index: number isPinned: boolean }> = ({ name, displayColor, onClicked, isPinned }) => ( - + {name} - + ) export const Basic = Template.bind({}) diff --git a/webview/src/stories/ContextMenu.stories.tsx b/webview/src/stories/ContextMenu.stories.tsx index 76310a49c0..b2a1014c05 100644 --- a/webview/src/stories/ContextMenu.stories.tsx +++ b/webview/src/stories/ContextMenu.stories.tsx @@ -3,7 +3,7 @@ import React from 'react' import '../shared/style.scss' import './test-vscode-styles.scss' import { MessageFromWebviewType } from 'dvc/src/webview/contract' -import { Theme } from '../shared/components/theme/Theme' +import { WebviewWrapper } from '../shared/components/webviewWrapper/WebviewWrapper' import { ContextMenu, ContextMenuProps @@ -19,7 +19,7 @@ export default { const Template: Story = () => { return ( - + = () => { - + ) } diff --git a/webview/src/stories/IconMenu.stories.tsx b/webview/src/stories/IconMenu.stories.tsx index 43275b5e0a..80d5d4d08e 100644 --- a/webview/src/stories/IconMenu.stories.tsx +++ b/webview/src/stories/IconMenu.stories.tsx @@ -7,7 +7,7 @@ import { SelectMenu } from '../shared/components/selectMenu/SelectMenu' import { IconMenu } from '../shared/components/iconMenu/IconMenu' import { IconMenuItemProps } from '../shared/components/iconMenu/IconMenuItem' import { AllIcons } from '../shared/components/Icon' -import { Theme } from '../shared/components/theme/Theme' +import { WebviewWrapper } from '../shared/components/webviewWrapper/WebviewWrapper' const items: IconMenuItemProps[] = [ { @@ -90,9 +90,9 @@ export default { const Template: Story<{ items: IconMenuItemProps[] }> = ({ items }) => ( - + - + ) export const MenuWithIcons = Template.bind({})