diff --git a/packages/visualizations-react/stories/Table/options.ts b/packages/visualizations-react/stories/Table/options.ts index 5bd03f29..0a208972 100644 --- a/packages/visualizations-react/stories/Table/options.ts +++ b/packages/visualizations-react/stories/Table/options.ts @@ -75,11 +75,12 @@ export const columns: Column[] = [ { title: 'Image', key: 'image', - dataFormat: 'image', + dataFormat: 'url', options: { accessor: (v: unknown) => (v as FileRecord).url, display: (v: unknown) => (v as FileRecord).filename, alt: (v: unknown) => (v as FileRecord).filename, + tooltip: (v: unknown) => (v as FileRecord).thumbnail && (v as FileRecord).url, }, }, { diff --git a/packages/visualizations/src/components/Format/GeoFormat.svelte b/packages/visualizations/src/components/Format/GeoFormat.svelte index 4ef75b55..054316e8 100644 --- a/packages/visualizations/src/components/Format/GeoFormat.svelte +++ b/packages/visualizations/src/components/Format/GeoFormat.svelte @@ -1,10 +1,8 @@ -
{ - showMap = true; - }, - onHide: () => { - showMap = false; - }, + { + showTooltip = true; + }} + onHide={() => { + showTooltip = false; }} >
{display && display(rawValue)}
- {#if showMap && data && mapOptions} -
+
+ {#if showTooltip && data && mapOptions} -
- {/if} -
+ {/if} +
+ diff --git a/packages/visualizations/src/components/Format/Tooltip.svelte b/packages/visualizations/src/components/Format/Tooltip.svelte new file mode 100644 index 00000000..991bd2d7 --- /dev/null +++ b/packages/visualizations/src/components/Format/Tooltip.svelte @@ -0,0 +1,33 @@ + + +{#if enabled} +
+ +
+ +
+
+{:else} + +{/if} diff --git a/packages/visualizations/src/components/Format/URLFormat.svelte b/packages/visualizations/src/components/Format/URLFormat.svelte index 966d4561..7d31ed48 100644 --- a/packages/visualizations/src/components/Format/URLFormat.svelte +++ b/packages/visualizations/src/components/Format/URLFormat.svelte @@ -2,35 +2,63 @@ import ShortTextFormat from './ShortTextFormat.svelte'; import { isValidUrl, warn } from './utils'; import type { URLFormatProps } from './types'; + import Tooltip from './Tooltip.svelte'; type $$Props = URLFormatProps; export let rawValue: $$Props['rawValue']; export let display: $$Props['display'] = (v: unknown) => v as string; export let accessor: $$Props['accessor'] = (v: unknown) => v as string; + export let tooltip: $$Props['tooltip'] = () => null; export let target: $$Props['target'] = '_blank'; export let rel: $$Props['rel'] = 'nofollow noreferrer noopener'; export let debugWarnings = false; + let showTooltip = false; + $: format = (v: unknown) => { if (isValidUrl(v)) { return { text: display ? display(rawValue) : v, href: v, + src: tooltip && tooltip(rawValue), }; } if (debugWarnings) { warn(v, 'url'); } - return { text: null, href: null }; + return { text: null, href: null, src: null }; }; - $: ({ text, href } = format(accessor ? accessor(rawValue) : rawValue)); + $: ({ text, href, src } = format(accessor ? accessor(rawValue) : rawValue)); {#if text} - {text} + { + showTooltip = true; + }} + onHide={() => { + showTooltip = false; + }} + > + {text} +
+ {#if showTooltip} + {text} + {/if} +
+
{:else} {/if} + + diff --git a/packages/visualizations/src/components/Format/types.ts b/packages/visualizations/src/components/Format/types.ts index ef59aa23..856a3425 100644 --- a/packages/visualizations/src/components/Format/types.ts +++ b/packages/visualizations/src/components/Format/types.ts @@ -47,13 +47,7 @@ export type URLFormatProps = { rawValue: unknown; display?: (v: unknown) => string; accessor?: (v: unknown) => string; + tooltip?: (v: unknown) => string | null; target?: HTMLAnchorElement['target']; rel?: HTMLAnchorElement['rel']; }; - -export type ImageFormatProps = { - rawValue: unknown; - display?: (v: unknown) => string; - accessor?: (v: unknown) => string; - alt?: (v: unknown) => string; -}; diff --git a/packages/visualizations/src/components/Table/Cell/Cell.svelte b/packages/visualizations/src/components/Table/Cell/Cell.svelte index e611c780..4d67098a 100644 --- a/packages/visualizations/src/components/Table/Cell/Cell.svelte +++ b/packages/visualizations/src/components/Table/Cell/Cell.svelte @@ -7,7 +7,6 @@ import LongTextFormat from 'components/Format/LongTextFormat.svelte'; import NumberFormat from 'components/Format/NumberFormat.svelte'; import URLFormat from 'components/Format/URLFormat.svelte'; - import ImageFormat from 'components/Format/ImageFormat.svelte'; import { DATA_FORMAT } from '../constants'; import { locale } from '../store'; import type { Column } from '../types'; @@ -34,8 +33,6 @@ {:else if isColumnOfType(column, DATA_FORMAT.url)} - {:else if isColumnOfType(column, DATA_FORMAT.image)} - {/if} {/if} diff --git a/packages/visualizations/src/components/Table/Row.svelte b/packages/visualizations/src/components/Table/Row.svelte index 16a399a3..12836d7e 100644 --- a/packages/visualizations/src/components/Table/Row.svelte +++ b/packages/visualizations/src/components/Table/Row.svelte @@ -7,7 +7,6 @@ export let rowProps: RowProps | undefined; export let record: Record; - $: console.log(record); let isRowHovered = false; $: ({ onClick, onMouseEnter, onMouseLeave, actionAriaLabel } = rowProps || {}); $: handleMouseEnter = () => { diff --git a/packages/visualizations/src/components/Table/constants.ts b/packages/visualizations/src/components/Table/constants.ts index 04aaa27b..48ff4380 100644 --- a/packages/visualizations/src/components/Table/constants.ts +++ b/packages/visualizations/src/components/Table/constants.ts @@ -7,5 +7,4 @@ export const DATA_FORMAT = { boolean: 'boolean', url: 'url', geo: 'geo', - image: 'image', } as const; diff --git a/packages/visualizations/src/components/Table/types.ts b/packages/visualizations/src/components/Table/types.ts index 53bd5cf2..33ed0d8b 100644 --- a/packages/visualizations/src/components/Table/types.ts +++ b/packages/visualizations/src/components/Table/types.ts @@ -6,7 +6,6 @@ import type { LongTextFormatProps, NumberFormatProps, URLFormatProps, - ImageFormatProps, } from 'components/Format/types'; import type { Async, DataFrame, Source } from 'types'; import type { Pagination } from '../Pagination/types'; @@ -46,7 +45,6 @@ type FormatPropsTypeMap = { [DATA_FORMAT.longText]: ColumnOptions; [DATA_FORMAT.number]: ColumnOptions; [DATA_FORMAT.url]: ColumnOptions; - [DATA_FORMAT.image]: ColumnOptions; }; export type ColumnOfType = BaseColumn & { @@ -63,7 +61,6 @@ export type ShortTextColumn = ColumnOfType; export type LongTextColumn = ColumnOfType; export type NumberColumn = ColumnOfType; export type URLColumn = ColumnOfType; -export type ImageColumn = ColumnOfType; export type RowProps = { onClick?: (record?: Record, index?: number) => void;