fix: tighten widget preview stage
This commit is contained in:
1 parent
b3a30e0cf6
commit
7fe5f8f81c
2 files changed
+25
-20
No files matched your search
@@ -16,22 +16,19 @@
|
|||||||
max-width: 52rem;
|
max-width: 52rem;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
justify-self: center;
|
justify-self: center;
|
||||||
padding: var(--mantine-spacing-md);
|
|
||||||
border: 1px solid var(--mantine-color-default-border);
|
|
||||||
border-radius: var(--mantine-radius-md);
|
|
||||||
background: light-dark(var(--mantine-color-gray-0), var(--mantine-color-dark-7));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.previewDimensions {
|
.previewDimensions {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
top: calc(var(--mantine-spacing-md) + var(--mantine-spacing-xs));
|
top: var(--mantine-spacing-xs);
|
||||||
right: calc(var(--mantine-spacing-md) + var(--mantine-spacing-xs));
|
right: var(--mantine-spacing-xs);
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.previewCanvas {
|
.previewCanvas {
|
||||||
height: clamp(24rem, calc(100dvh - 17rem), 44rem);
|
position: relative;
|
||||||
|
align-self: center;
|
||||||
padding: var(--mantine-spacing-lg);
|
padding: var(--mantine-spacing-lg);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
border: 1px solid var(--mantine-color-default-border);
|
border: 1px solid var(--mantine-color-default-border);
|
||||||
@@ -154,10 +151,6 @@
|
|||||||
max-width: 44rem;
|
max-width: 44rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.previewCanvas {
|
|
||||||
height: 24rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.settingsPanel {
|
.settingsPanel {
|
||||||
max-height: none;
|
max-height: none;
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
|
|||||||
@@ -83,6 +83,9 @@ interface WidgetEditPreviewProps {
|
|||||||
onChangeOptions: (newOptions: Record<string, unknown>) => void;
|
onChangeOptions: (newOptions: Record<string, unknown>) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PREVIEW_STAGE_INSET = 40;
|
||||||
|
const MAXIMUM_PREVIEW_HEIGHT = 544;
|
||||||
|
|
||||||
const WidgetEditPreview = ({
|
const WidgetEditPreview = ({
|
||||||
kind,
|
kind,
|
||||||
Component,
|
Component,
|
||||||
@@ -95,15 +98,15 @@ const WidgetEditPreview = ({
|
|||||||
onChangeOptions,
|
onChangeOptions,
|
||||||
}: WidgetEditPreviewProps) => {
|
}: WidgetEditPreviewProps) => {
|
||||||
const tItem = useI18n("item.edit");
|
const tItem = useI18n("item.edit");
|
||||||
const { ref, width: availableWidth, height: availableHeight } = useElementSize<HTMLDivElement>();
|
const { ref, width: availableWidth } = useElementSize<HTMLDivElement>();
|
||||||
const sourceWidth = Math.max(dimensions.width, 1);
|
const sourceWidth = Math.max(dimensions.width, 1);
|
||||||
const sourceHeight = Math.max(dimensions.height, 1);
|
const sourceHeight = Math.max(dimensions.height, 1);
|
||||||
let maximumScale = dimensions.scale ?? 0.9;
|
let maximumScale = dimensions.scale ?? 0.9;
|
||||||
if (!Number.isFinite(maximumScale) || maximumScale <= 0) maximumScale = 0.9;
|
if (!Number.isFinite(maximumScale) || maximumScale <= 0) maximumScale = 0.9;
|
||||||
maximumScale = Math.min(maximumScale, 0.9);
|
maximumScale = Math.min(maximumScale, 0.9);
|
||||||
let previewScale = maximumScale;
|
let previewScale = Math.min(MAXIMUM_PREVIEW_HEIGHT / sourceHeight, maximumScale);
|
||||||
if (availableWidth > 0 && availableHeight > 0) {
|
if (availableWidth > PREVIEW_STAGE_INSET) {
|
||||||
previewScale = Math.min(availableWidth / sourceWidth, availableHeight / sourceHeight, maximumScale);
|
previewScale = Math.min((availableWidth - PREVIEW_STAGE_INSET) / sourceWidth, previewScale);
|
||||||
}
|
}
|
||||||
const previewWidth = sourceWidth * previewScale;
|
const previewWidth = sourceWidth * previewScale;
|
||||||
const previewHeight = sourceHeight * previewScale;
|
const previewHeight = sourceHeight * previewScale;
|
||||||
@@ -111,6 +114,12 @@ const WidgetEditPreview = ({
|
|||||||
const hasIntegrationSupport = "supportedIntegrations" in definition;
|
const hasIntegrationSupport = "supportedIntegrations" in definition;
|
||||||
const integrationRequired = hasIntegrationSupport && definition.integrationsRequired !== false;
|
const integrationRequired = hasIntegrationSupport && definition.integrationsRequired !== false;
|
||||||
const isMissingIntegration = integrationRequired && state.integrationIds.length === 0;
|
const isMissingIntegration = integrationRequired && state.integrationIds.length === 0;
|
||||||
|
let previewStageWidth = previewWidth + PREVIEW_STAGE_INSET;
|
||||||
|
let previewStageHeight = previewHeight + PREVIEW_STAGE_INSET;
|
||||||
|
if (isMissingIntegration) {
|
||||||
|
previewStageWidth = Math.max(previewStageWidth, 360);
|
||||||
|
previewStageHeight = Math.max(previewStageHeight, 160);
|
||||||
|
}
|
||||||
const previewIntegrations = integrationData.map((integration) => ({
|
const previewIntegrations = integrationData.map((integration) => ({
|
||||||
id: integration.id,
|
id: integration.id,
|
||||||
permissions: integration.permissions ?? {
|
permissions: integration.permissions ?? {
|
||||||
@@ -121,11 +130,14 @@ const WidgetEditPreview = ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack className={classes.previewPanel} gap="sm">
|
<Stack ref={ref} className={classes.previewPanel} gap={0}>
|
||||||
<Badge className={classes.previewDimensions} size="xs" variant="light" color="gray">
|
<Center
|
||||||
{Math.round(sourceWidth)} × {Math.round(sourceHeight)}
|
className={classes.previewCanvas}
|
||||||
</Badge>
|
style={{ width: previewStageWidth, height: previewStageHeight, maxWidth: "100%" }}
|
||||||
<Center ref={ref} className={classes.previewCanvas}>
|
>
|
||||||
|
<Badge className={classes.previewDimensions} size="xs" variant="light" color="gray">
|
||||||
|
{Math.round(sourceWidth)} × {Math.round(sourceHeight)}
|
||||||
|
</Badge>
|
||||||
{isMissingIntegration ? (
|
{isMissingIntegration ? (
|
||||||
<Alert color="gray" variant="light" icon={<IconEye size={18} />} maw={320}>
|
<Alert color="gray" variant="light" icon={<IconEye size={18} />} maw={320}>
|
||||||
{tItem("preview.integrationRequired")}
|
{tItem("preview.integrationRequired")}
|
||||||
|
|||||||
Reference in new issue
Block a user