mirror of
https://github.com/penpot/penpot-plugins.git
synced 2025-01-08 07:50:44 -05:00
feat: min modal size
This commit is contained in:
parent
b65e66535a
commit
d17c08332c
2 changed files with 22 additions and 2 deletions
|
@ -95,4 +95,19 @@ describe('createModal', () => {
|
||||||
String(expectedHeight)
|
String(expectedHeight)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should apply minimum dimensions to the modal', () => {
|
||||||
|
const theme: PenpotTheme = 'light';
|
||||||
|
const options: OpenUIOptions = { width: 100, height: 100 };
|
||||||
|
|
||||||
|
const modal = createModal(
|
||||||
|
'Test Modal',
|
||||||
|
'https://example.com',
|
||||||
|
theme,
|
||||||
|
options
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(modal.setAttribute).toHaveBeenCalledWith('width', '200');
|
||||||
|
expect(modal.setAttribute).toHaveBeenCalledWith('height', '200');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,6 +11,8 @@ export function createModal(
|
||||||
const modal = document.createElement('plugin-modal') as PluginModalElement;
|
const modal = document.createElement('plugin-modal') as PluginModalElement;
|
||||||
|
|
||||||
modal.setTheme(theme);
|
modal.setTheme(theme);
|
||||||
|
const minPluginWidth = 200;
|
||||||
|
const minPluginHeight = 200;
|
||||||
|
|
||||||
const defaultWidth = 335;
|
const defaultWidth = 335;
|
||||||
const defaultHeight = 590;
|
const defaultHeight = 590;
|
||||||
|
@ -31,8 +33,11 @@ export function createModal(
|
||||||
|
|
||||||
const maxWidth = window.innerWidth - initialPosition.inlineEnd;
|
const maxWidth = window.innerWidth - initialPosition.inlineEnd;
|
||||||
const maxHeight = window.innerHeight - initialPosition.blockStart;
|
const maxHeight = window.innerHeight - initialPosition.blockStart;
|
||||||
const width = Math.min(options?.width || defaultWidth, maxWidth);
|
let width = Math.min(options?.width || defaultWidth, maxWidth);
|
||||||
const height = Math.min(options?.height || defaultHeight, maxHeight);
|
let height = Math.min(options?.height || defaultHeight, maxHeight);
|
||||||
|
|
||||||
|
width = Math.max(width, minPluginWidth);
|
||||||
|
height = Math.max(height, minPluginHeight);
|
||||||
|
|
||||||
modal.setAttribute('title', name);
|
modal.setAttribute('title', name);
|
||||||
modal.setAttribute('iframe-src', url);
|
modal.setAttribute('iframe-src', url);
|
||||||
|
|
Loading…
Reference in a new issue