Skip to content

Commit

Permalink
feat(cxl-ui): Added paddin property to handle parent contaner sizes w…
Browse files Browse the repository at this point in the history
…hen scaling
  • Loading branch information
freudFlintstone committed Jul 3, 2023
1 parent 071a86f commit c9f6f9e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/cxl-ui/scss/cxl-credential.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
:host {
display: flex;
margin: auto;
}

.container {
Expand Down Expand Up @@ -57,7 +58,7 @@
font-size: 20px;
font-weight: 200;
text-transform: lowercase;
letter-spacing: 0.09em;
letter-spacing: 2px;
}

#header {
Expand Down
12 changes: 7 additions & 5 deletions packages/cxl-ui/src/components/cxl-credential.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export class CXLCredentialElement extends LitElement {
@property({ type: Number }) scale = 0.5;
@property({ type: Number }) maxWidth;
@property({ type: Number, attribute: 'max-width' }) maxWidth;
@property({ type: Number, attribute: 'parent-padding' }) parentPadding = 0;
@query('#qr-code') qrCodeCanvas = null;
Expand Down Expand Up @@ -97,7 +99,7 @@ export class CXLCredentialElement extends LitElement {
* device orientation. But it will adjust, if the page is reloaded after.
*/
_handleScaling() {
const width = this.maxWidth || window.innerWidth;
const width = this.maxWidth || window.innerWidth - this.parentPadding;
const finalW = 1464 * this.scale;
this.correctionFactor = width < finalW || this.maxWidth ? width / finalW : 1;
this.style.height = `${1120 * this.scale * this.correctionFactor}px`;
Expand Down Expand Up @@ -128,8 +130,8 @@ export class CXLCredentialElement extends LitElement {
this.setAttribute('theme', this.type === 'minidegree' ? 'dark' : 'light');
}

if (changes.has('scale')) {
this._handleScaling();
if (changes.has('scale') || changes.has('correctionFactor')) {
requestAnimationFrame(() => this._handleScaling());
}
}

Expand Down Expand Up @@ -158,7 +160,7 @@ export class CXLCredentialElement extends LitElement {
<div class="code">
<div>
<canvas id="qr-code"></canvas>
<div id="qr-code-text" class="thin">certificate/${this.credentialId}</div>
<div id="qr-code-text" class="thin">certificate : ${this.credentialId}</div>
</div>
</div>
</section>
Expand Down

0 comments on commit c9f6f9e

Please sign in to comment.