Skip to content

Commit

Permalink
WIP: panel
Browse files Browse the repository at this point in the history
  • Loading branch information
vio committed Jan 6, 2023
1 parent f4c479a commit a7d8c2f
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 1 deletion.
10 changes: 10 additions & 0 deletions packages/ui/src/app/app.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useContext, useEffect, useMemo } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import { HashRouter, NavLink, Route, Switch, useLocation } from 'react-router-dom';
import { COMPONENT } from '@bundle-stats/utils';

Expand Down Expand Up @@ -27,6 +28,7 @@ import { QueryStateProvider, useComponentQueryState } from '../query-state';
import I18N from '../i18n';
import { Header } from './header';
import css from './app.module.css';
import { Panel } from './panel';

const ScrollToTop = () => {
const { pathname } = useLocation();
Expand Down Expand Up @@ -159,6 +161,8 @@ const PackagesContent = () => {
};

const AppComponent = ({ version, jobs }) => {
const [panel, setPanel] = useComponentQueryState('p');

if (jobs?.length === 0) {
return (
<Layout version={version}>
Expand Down Expand Up @@ -207,6 +211,12 @@ const AppComponent = ({ version, jobs }) => {
</Switch>
</div>
</Layout>

<button onClick={() => setPanel({ p: 'some' })} type="button">
open
</button>

<Panel state={panel} setState={setPanel} />
</JobsProvider>
);
};
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/app/panel/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './panel';
31 changes: 31 additions & 0 deletions packages/ui/src/app/panel/panel.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.root {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: hidden;
pointer-events: none;
z-index: var(--layer-high);
}

.inner {
padding: var(--space-small);
position: absolute;
right: -100%;
top: 0;
bottom: 0;
width: 100%;
max-width: 60rem;
box-shadow: 0 0 var(--space-medium) var(--color-shadow);

background: white;
pointer-events: auto;
transition: var(--transition-in);
overflow-y: auto;
}

.open .inner {
right: 0;
transition: var(--transition-out);
}
28 changes: 28 additions & 0 deletions packages/ui/src/app/panel/panel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { useCallback } from 'react';
import cx from 'classnames';

import * as css from './panel.module.css';

interface PanelState {
p: string;
}

interface PanelProps extends React.ComponentProps<'div'> {
state?: PanelState;
setState: (newState: PanelState) => void;
}

export const Panel = ({ className = '', state = { p: '' }, setState }: PanelProps) => {
const handleClose = useCallback(() => setState({ p: '' }), [setState]);
return (
<div className={cx(css.root, state?.p && css.open, className)}>
<div className={css.inner}>
Panel
<button onClick={handleClose} type="button">close</button>
<div id="portal-panel-content">
NONE
</div>
</div>
</div>
);
}
25 changes: 24 additions & 1 deletion packages/ui/src/components/bundle-modules/bundle-modules.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
MODULE_FILTERS,
MODULE_FILE_TYPE,
} from '@bundle-stats/utils';
import { Portal } from 'ariakit/portal';

import config from '../../config.json';
import I18N from '../../i18n';
Expand Down Expand Up @@ -102,10 +103,32 @@ const RowHeader = ({ row, chunks, labels, CustomComponentLink }) => {
[row],
);

const getPortalElement = useCallback(() => {
const portalRoot = document.getElementById('portal-panel-content');
portalRoot.innerText = '';
return portalRoot;
}, []);

if (!showHoverCard) {
return <div onMouseEnter={handleOnMouseEnter}>{content}</div>;
return <div onClick={handleOnMouseEnter}>{content}</div>;
}

return (
<>
<div>{content}</div>
<Portal portalElement={getPortalElement}>
<ModuleInfo
item={row}
chunks={chunks}
chunkIds={chunkIds}
labels={labels}
customComponentLink={CustomComponentLink}
onClick={close}
/>
</Portal>
</>
)

return (
<HoverCard label={content} hoverCardClassName={css.nameHoverCard}>
{({ close }) => (
Expand Down

0 comments on commit a7d8c2f

Please sign in to comment.