Skip to content

Commit

Permalink
Allow EmbeddedDisplay resize prop to be string or number
Browse files Browse the repository at this point in the history
  • Loading branch information
abigailalexander committed Mar 18, 2024
1 parent eadc572 commit a43dc56
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ui/widgets/EmbeddedDisplay/bobParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function bobParseResizing(jsonProp: ElementCompact): string {
case 4:
return "crop-content";
default:
return "scroll-widget";
return "scroll-content";
}
}

Expand Down
14 changes: 12 additions & 2 deletions src/ui/widgets/EmbeddedDisplay/embeddedDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ import { useOpiFile } from "./useOpiFile";
import { useId } from "react-id-generator";
import { getOptionalValue, trimFromString } from "../utils";

const RESIZE_STRINGS = [
"scroll-widget",
"size-content",
"crop-widget",
"stretch-content",
"crop-content"
];

const EmbeddedDisplayProps = {
...WidgetPropType,
file: FilePropType,
Expand All @@ -34,15 +42,17 @@ const EmbeddedDisplayProps = {
scroll: BoolPropOpt,
scalingOrigin: StringPropOpt,
overrideAutoZoomToFitValue: BoolPropOpt,
resize: StringPropOpt
resize: StringOrNumPropOpt
};

export const EmbeddedDisplay = (
props: InferWidgetProps<typeof EmbeddedDisplayProps>
): JSX.Element => {
const description = useOpiFile(props.file);
const id = useId();
const resize = props.resize || "scroll-content";
let resize = props.resize || "scroll-content";
// If number, convert back to string
if (typeof resize === "number") resize = RESIZE_STRINGS[resize];

log.debug(description);

Expand Down
2 changes: 1 addition & 1 deletion src/ui/widgets/EmbeddedDisplay/opiParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ function opiParseResizing(jsonProp: ElementCompact): string {
case 2:
return "crop-content";
case 3:
return "scroll-widget";
return "scroll-content";
default:
return "size-widget";
}
Expand Down

0 comments on commit a43dc56

Please sign in to comment.