Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(playground): replace antd overlay #7645

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions packages/cubejs-playground/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
/* eslint-disable no-undef,react/jsx-no-target-blank */
import { Component, useEffect } from 'react';
import '@ant-design/compatible/assets/index.css';
import { Layout, Alert } from 'antd';
import { Alert, Layout } from 'antd';
import { Component, useEffect } from 'react';
import { RouteComponentProps, withRouter } from 'react-router-dom';
import styled from 'styled-components';

import Header from './components/Header/Header';
import GlobalStyles from './components/GlobalStyles';
import { CubeLoader } from './atoms';
import { AppContextConsumer, PlaygroundContext } from './components/AppContext';
import GlobalStyles from './components/GlobalStyles';
import Header from './components/Header/Header';
import { LivePreviewContextProvider } from './components/LivePreviewContext/LivePreviewContextProvider';
import {
event,
setAnonymousId,
setTracker,
setTelemetry,
setTracker,
trackImpl,
} from './events';
import { AppContextConsumer, PlaygroundContext } from './components/AppContext';
import { useAppContext } from './hooks';
import { LivePreviewContextProvider } from './components/LivePreviewContext/LivePreviewContextProvider';

const StyledLayoutContent = styled(Layout.Content)`
height: 100%;
`;
Expand Down
21 changes: 10 additions & 11 deletions packages/cubejs-playground/src/ChartContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import { Component, FunctionComponent, Suspense } from 'react';
import {
CodeOutlined,
CodeSandboxOutlined,
CopyOutlined,
DownOutlined,
PlusOutlined,
ThunderboltOutlined,
QuestionCircleOutlined,
ThunderboltOutlined
} from '@ant-design/icons';
import { Dropdown, Menu, Modal } from 'antd';
import { ChartType, Meta, Query, ResultSet } from '@cubejs-client/core';
import { Dropdown, Menu } from 'antd';
import { getParameters } from 'codesandbox-import-utils/lib/api/define';
import styled from 'styled-components';
import { Component, FunctionComponent, Suspense } from 'react';
import { Redirect, RouteComponentProps, withRouter } from 'react-router-dom';
import { ChartType, Meta, Query, ResultSet } from '@cubejs-client/core';
import styled from 'styled-components';

import { FatalError } from './components/Error/FatalError';
import { SectionRow } from './components';
import { Button, Card, CubeLoader } from './atoms';
import PrismCode from './PrismCode';
import { Button, Card, CubeLoader } from './atoms';
import { SectionRow } from './components';
import { FatalError } from './components/Error/FatalError';
import { playgroundAction } from './events';
import { codeSandboxDefinition, copyToClipboard } from './utils';
import { GraphQLIcon } from './shared/icons/GraphQLIcon';
import { loadable } from './loadable';
import { GraphQLIcon } from './shared/icons/GraphQLIcon';
import { codeSandboxDefinition, copyToClipboard } from './utils';

const GraphiQLSandbox = loadable(
() => import('./components/GraphQL/GraphiQLSandbox')
Expand Down
96 changes: 77 additions & 19 deletions packages/cubejs-playground/src/QueryBuilder/ButtonDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,90 @@
import { Dropdown, DropDownProps, ButtonProps } from 'antd';
import { ButtonProps } from 'antd';
import { useEffect, useRef } from 'react';
import styled from 'styled-components';

import { Button } from '../atoms';

const TooltipTriggerWrapper = styled.div`
position: relative;
`;

const TooltipContent = styled.div`
position: absolute;
left: 16px;
top: 40px;
z-index: 9999;
left: 0;
overflow: hidden;
box-shadow: 0 3px 6px -4px rgba(0, 0, 0, 0.12),
0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 9px 28px 8px rgba(0, 0, 0, 0.05);
`;

function TooltipTrigger({ children, shown, onClose, ...overlayStyles }) {
const ref = useRef<any>(null);

useEffect(() => {
document.addEventListener('mousedown', (event: any) => {
if (!ref?.current) {
return;
}

if (!ref.current.contains(event.target)) {
onClose();
}
});
}, []);

return (
<TooltipTriggerWrapper>
{children[0]}
{shown ? (
<TooltipContent
ref={ref}
className="ant-dropdown ant-dropdown-placement-bottomLeft "
style={{ ...overlayStyles }}
>
{children[1]}
</TooltipContent>
) : null}
</TooltipTriggerWrapper>
);
}

type ButtonDropdownProps = {
onOverlayClose?: () => void;
} & DropDownProps & ButtonProps
show: boolean;
overlay: React.ReactNode;
overlayStyles?: any;
onOverlayClose: () => void;
onOverlayOpen: () => void;
onItemClick?: () => void;
} & ButtonProps;

const ButtonDropdown = ({
export function ButtonDropdown({
show,
overlay,
disabled = false,
overlayStyles,
onOverlayClose,
onOverlayOpen,
onItemClick,
...buttonProps
}: ButtonDropdownProps) => {
}: ButtonDropdownProps) {
return (
<Dropdown
disabled={disabled}
overlay={overlay}
placement="bottomLeft"
trigger={['click']}
onVisibleChange={(visible) => {
if (!visible) {
onOverlayClose?.();
}
<TooltipTrigger
shown={show}
{...overlayStyles}
onClose={() => {
onOverlayClose();
}}
>
<Button {...buttonProps} disabled={disabled} />
</Dropdown>
<Button
{...buttonProps}
onClick={() => {
onOverlayOpen();
}}
disabled={disabled}
/>
<div onClick={onItemClick}>{overlay}</div>
</TooltipTrigger>
);
};

export default ButtonDropdown;
}
Loading
Loading