Skip to content

Commit

Permalink
experiment: conditional fit-height containers
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-kot committed Jul 20, 2023
1 parent c305a5a commit 0008314
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 52 deletions.
42 changes: 31 additions & 11 deletions src/internal/components/cartesian-chart/chart-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,43 @@ export const CartesianChartContainer = forwardRef(
}: CartesianChartContainerProps,
ref: React.Ref<HTMLDivElement>
) => {
const withFitHeight = (className: string) => clsx(className, fitHeight && styles['fit-height']);
if (fitHeight) {
return (
<div className={clsx(styles['chart-container'], styles['fit-height'])} ref={ref}>
{leftAxisLabel}

<div className={clsx(styles['chart-container-outer'], styles['fit-height'])}>
{leftAxisLabelMeasure}

<div className={styles['chart-container-inner']}>
<div
className={clsx(styles['chart-container-plot-wrapper'], styles['fit-height'])}
style={{ minHeight: Math.max(minHeight, CONTENT_MIN_HEIGHT_BOUNDARY) }}
>
<div className={clsx(styles['chart-container-plot'], styles['fit-height'])}>{chartPlot}</div>
</div>

<div className={clsx(styles['chart-container-bottom-labels'], styles['fit-height'])}>
{bottomAxisLabel}
</div>
</div>

{popover}
</div>
</div>
);
}

return (
<div className={withFitHeight(styles['chart-container'])} ref={ref}>
<div className={styles['chart-container']} ref={ref}>
{leftAxisLabel}

<div className={withFitHeight(styles['chart-container-outer'])}>
<div className={styles['chart-container-outer']}>
{leftAxisLabelMeasure}

<div className={styles['chart-container-inner']}>
<div
className={withFitHeight(styles['chart-container-plot-wrapper'])}
style={{ minHeight: Math.max(minHeight, CONTENT_MIN_HEIGHT_BOUNDARY) }}
>
<div className={withFitHeight(styles['chart-container-plot'])}>{chartPlot}</div>
</div>

<div className={withFitHeight(styles['chart-container-bottom-labels'])}>{bottomAxisLabel}</div>
{chartPlot}
{bottomAxisLabel}
</div>

{popover}
Expand Down
6 changes: 0 additions & 6 deletions src/internal/components/cartesian-chart/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@
}

.chart-container-plot-wrapper {
display: contents;

&.fit-height {
display: block;
position: relative;
Expand All @@ -147,8 +145,6 @@
}

.chart-container-plot {
display: contents;

&.fit-height {
display: block;
position: absolute;
Expand All @@ -160,8 +156,6 @@
}

.chart-container-bottom-labels {
display: contents;

&.fit-height {
display: block;
}
Expand Down
89 changes: 56 additions & 33 deletions src/internal/components/chart-wrapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,66 @@ export const ChartWrapper = forwardRef(
ref: React.Ref<HTMLDivElement>
) => {
const baseProps = getBaseProps(props);
return (
<div
ref={ref}
{...baseProps}
className={clsx(baseProps.className, styles.wrapper, fitHeight && styles['wrapper--fit-height'])}
onBlur={onBlur}
>
<div className={clsx(styles['inner-wrapper'], fitHeight && styles['inner-wrapper--fit-height'])}>
{(defaultFilter || additionalFilters) && (
<InternalBox className={styles['filter-container']} margin={{ bottom: 'l' }}>
<InternalSpaceBetween
size="l"
direction="horizontal"
className={clsx({ [styles['has-default-filter']]: !!defaultFilter })}
>
{defaultFilter}
{additionalFilters}
</InternalSpaceBetween>
</InternalBox>
)}

<div
className={clsx(styles.content, contentClassName, {
[styles['content--reserve-filter']]: reserveFilterSpace,
[styles['content--reserve-legend']]: reserveLegendSpace,
[styles['content--fit-height']]: fitHeight,
})}
style={{
minHeight: !fitHeight ? contentMinHeight : undefined,
}}
>
{chartStatus}
{chart}
const filtersNode = (defaultFilter || additionalFilters) && (
<InternalBox className={styles['filter-container']} margin={{ bottom: 'l' }}>
<InternalSpaceBetween
size="l"
direction="horizontal"
className={clsx({ [styles['has-default-filter']]: !!defaultFilter })}
>
{defaultFilter}
{additionalFilters}
</InternalSpaceBetween>
</InternalBox>
);

const legendNode = legend && <InternalBox margin={{ top: 'm' }}>{legend}</InternalBox>;

if (fitHeight) {
return (
<div
ref={ref}
{...baseProps}
className={clsx(baseProps.className, styles.wrapper, styles['wrapper--fit-height'])}
onBlur={onBlur}
>
<div className={clsx(styles['inner-wrapper'], styles['inner-wrapper--fit-height'])}>
{filtersNode}

<div
className={clsx(styles.content, contentClassName, {
[styles['content--reserve-filter']]: reserveFilterSpace,
[styles['content--reserve-legend']]: reserveLegendSpace,
[styles['content--fit-height']]: true,
})}
>
{chartStatus}
{chart}
</div>

{legendNode}
</div>
</div>
);
}

{legend && <InternalBox margin={{ top: 'm' }}>{legend}</InternalBox>}
return (
<div ref={ref} {...baseProps} className={clsx(baseProps.className, styles.wrapper)} onBlur={onBlur}>
{filtersNode}

<div
className={clsx(styles.content, contentClassName, {
[styles['content--reserve-filter']]: reserveFilterSpace,
[styles['content--reserve-legend']]: reserveLegendSpace,
})}
style={{ minHeight: contentMinHeight }}
>
{chartStatus}
{chart}
</div>

{legendNode}
</div>
);
}
Expand Down
2 changes: 0 additions & 2 deletions src/internal/components/chart-wrapper/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
}

.inner-wrapper {
display: contents;

&--fit-height {
display: flex;
flex-direction: column;
Expand Down

0 comments on commit 0008314

Please sign in to comment.