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: tooltip styles #2009

Merged
merged 1 commit into from
Nov 13, 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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ export function getCustomTooltipEntries({
dataColumn: rec.__source.__malloyDataRecord.cell(f.name),
resultMetadata: metadata,
tag: f.tagParse().tag,
customProps: {
table: {
shouldFillWidth: true,
disableVirtualization: true,
rowLimit: 20,
},
},
}).renderValue,
highlight: false,
color: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@

import {For, Match, Show, Switch, createEffect, createSignal} from 'solid-js';
import {ChartTooltipEntry} from '../types';
// TODO: This is a hacky way to get table CSS applied at global level so it affects tables in tooltips
// Need a better strategy here for how we render things inside of tooltips. Is it possible to keep
// tooltips and modals inside of the <malloy-render> component? Or can we render <malloy-render> with
// subsets of the Result set?
import '../table/table.css';

export function DefaultChartTooltip(props: {data: ChartTooltipEntry}) {
const [render, setRender] = createSignal(false);
Expand Down
1 change: 1 addition & 0 deletions packages/malloy-render/src/component/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export function MalloyRender(
{
disableVirtualization: false,
rowLimit: Infinity,
shouldFillWidth: false,
},
props.tableConfig
);
Expand Down
16 changes: 12 additions & 4 deletions packages/malloy-render/src/component/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,16 @@ const MalloyTableRoot = (_props: {
rowLimit?: number;
scrollEl?: HTMLElement;
disableVirtualization?: boolean;
shouldFillWidth?: boolean;
}) => {
const props = mergeProps({rowLimit: Infinity}, _props);
const tableCtx = useTableContext()!;
const resultMetadata = useResultContext();
const shouldFillWidth =
tableCtx.root &&
props.data.field.tagParse().tag.tag('table')?.text('size') === 'fill';
typeof props.shouldFillWidth === 'boolean'
? props.shouldFillWidth
: tableCtx.root &&
props.data.field.tagParse().tag.tag('table')?.text('size') === 'fill';

const pinnedFields = createMemo(() => {
const fields = Object.entries(tableCtx.layout.fieldHeaderRangeMap)
Expand Down Expand Up @@ -618,6 +621,7 @@ const MalloyTable: Component<{
rowLimit?: number;
scrollEl?: HTMLElement;
disableVirtualization?: boolean;
shouldFillWidth?: boolean;
}> = props => {
const metadata = useResultContext();
const hasTableCtx = !!useTableContext();
Expand Down Expand Up @@ -651,13 +655,17 @@ const MalloyTable: Component<{
const tableProps = () =>
mergeProps(props, {
disableVirtualization:
typeof props.disableVirtualization !== 'undefined'
typeof props.disableVirtualization === 'boolean'
? props.disableVirtualization
: tableConfig().disableVirtualization,
rowLimit:
typeof props.rowLimit !== 'undefined'
typeof props.rowLimit === 'number'
? props.rowLimit
: tableConfig().rowLimit,
shouldFillWidth:
typeof props.shouldFillWidth === 'boolean'
? props.shouldFillWidth
: tableConfig().shouldFillWidth,
});

return (
Expand Down
29 changes: 10 additions & 19 deletions packages/malloy-render/src/component/tooltip/tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {createSignal, JSXElement, onCleanup, onMount, Show} from 'solid-js';
import {Portal} from 'solid-js/web';
import {createSignal, JSXElement, onCleanup, Show} from 'solid-js';
import tooltipCss from './tooltip.css?raw';
import {useConfig} from '../render';

const TOOLTIP_STYLE_ID = 'malloy-tooltip-style';

export function Tooltip(props: {show: boolean; children: JSXElement}) {
const [pos, setPos] = createSignal([0, 0]);
const handler = evt => {
Expand All @@ -18,24 +15,18 @@ export function Tooltip(props: {show: boolean; children: JSXElement}) {
document.removeEventListener('mousemove', handler);
});

// Tooltips are rendered in the body outside of the malloy-render component,
// so we need to append the styles to the head of the document, rather than scoped inside malloy-render.
onMount(() => {
const config = useConfig();
config.addCSSToDocument(TOOLTIP_STYLE_ID, tooltipCss);
});
const config = useConfig();
config.addCSSToShadowRoot(tooltipCss);

return (
<Show when={props.show}>
<Portal>
<div
style={`position: fixed; top: ${pos()[1]}px; left: ${
pos()[0]
}px; width: 0px; height: 0px; pointer-events: none; z-index: 1000`}
>
<div class="malloy-tooltip">{props.children}</div>
</div>
</Portal>
<div
style={`position: fixed; top: ${pos()[1]}px; left: ${
pos()[0]
}px; width: 0px; height: 0px; pointer-events: none; z-index: 1000`}
>
<div class="malloy-tooltip">{props.children}</div>
</div>
</Show>
);
}
1 change: 1 addition & 0 deletions packages/malloy-render/src/component/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export type Channel = {
export type TableConfig = {
disableVirtualization: boolean;
rowLimit: number;
shouldFillWidth: boolean;
};
export type DashboardConfig = {
disableVirtualization: boolean;
Expand Down