Skip to content

Commit

Permalink
feat: added optional resizable attribute for preview
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderBazukevich authored and Sisha0 committed Dec 20, 2022
1 parent 49d07b1 commit de49cf0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pages/views/examples/example/form.njk
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ title: Example with form
<input type="submit" value="Send">
</form>
</script>
<uip-preview class="centered-content"></uip-preview>
<uip-preview class="centered-content" resizable></uip-preview>
<uip-settings target=".demo-form">
<uip-bool-setting label="Email validation" target="#email" mode="append" attribute="class" value="validation-input"></uip-bool-setting>
</uip-settings>
Expand Down
2 changes: 1 addition & 1 deletion pages/views/examples/example/playground.njk
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ title: Example with playground
<div class="user-card aqua-user">Marina</div>
</div>
</script>
<uip-preview></uip-preview>
<uip-preview resizable></uip-preview>
<uip-settings target=".user-list">
</uip-settings>
<uip-editor></uip-editor>
Expand Down
5 changes: 4 additions & 1 deletion src/core/preview/preview.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
max-width: 100%;
max-height: 100%;
overflow: auto;
resize: both;

&.resizable {
resize: both;
}
}

&.centered-content {
Expand Down
15 changes: 15 additions & 0 deletions src/core/preview/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {UIPPlugin} from '../base/plugin';
*/
export class UIPPreview extends UIPPlugin {
static is = 'uip-preview';
static observedAttributes: string[] = ['resizable'];

@bind
protected _onRootStateChange(): void {
Expand All @@ -19,4 +20,18 @@ export class UIPPreview extends UIPPlugin {
if (this.$inner.parentElement === this) this.removeChild(this.$inner);
super.disconnectedCallback();
}

protected attributeChangedCallback(attrName: string, oldVal: string, newVal: string): void {
if (attrName === 'resizable' && newVal === null) {
this.clearInlineSize();
this.$inner.classList.remove('resizable');
} else {
this.$inner.classList.add('resizable');
}
}

protected clearInlineSize() {
this.$inner.style.removeProperty('height');
this.$inner.style.removeProperty('width');
}
}

0 comments on commit de49cf0

Please sign in to comment.