Deprecate py-button, py-inputbox, py-box and py-title (#931)

This commit is contained in:
Fábio Rosado
2022-11-14 16:29:28 +00:00
committed by GitHub
parent be9b9f66d3
commit adfa9a9b05
15 changed files with 179 additions and 24 deletions

View File

@@ -1,4 +1,4 @@
import { getAttribute, addClasses } from '../utils';
import { getAttribute, addClasses, createDeprecationWarning } from '../utils';
import { getLogger } from '../logger';
const logger = getLogger('py-box');
@@ -20,6 +20,11 @@ export class PyBox extends HTMLElement {
}
connectedCallback() {
const deprecationMessage = (
'<p>The element &lt;py-box&gt; is deprecated, you should create a ' +
'div with "py-box" class name instead. For example: &lt;div class="py-box"&gt; '
)
createDeprecationWarning(deprecationMessage, "py-box")
const mainDiv = document.createElement('div');
addClasses(mainDiv, ['py-box']);

View File

@@ -1,4 +1,4 @@
import { getAttribute, addClasses, htmlDecode, ensureUniqueId } from '../utils';
import { getAttribute, addClasses, htmlDecode, ensureUniqueId, createDeprecationWarning } from '../utils';
import { getLogger } from '../logger';
import type { Runtime } from '../runtime';
@@ -42,6 +42,12 @@ export function make_PyButton(runtime: Runtime) {
}
async connectedCallback() {
const deprecationMessage = (
'<p>The element &lt;py-button&gt; is deprecated, create a function with your ' +
'inline code and use &lt;button py-click="function()" class="py-button"&gt; instead.</p>'
)
createDeprecationWarning(deprecationMessage, "py-button")
ensureUniqueId(this);
this.code = htmlDecode(this.innerHTML) || '';
this.mount_name = this.id.split('-').join('_');

View File

@@ -1,4 +1,4 @@
import { getAttribute, addClasses, htmlDecode, ensureUniqueId } from '../utils';
import { getAttribute, addClasses, htmlDecode, ensureUniqueId, createDeprecationWarning } from '../utils';
import { getLogger } from '../logger';
import type { Runtime } from '../runtime';
@@ -21,6 +21,11 @@ export function make_PyInputBox(runtime: Runtime) {
}
async connectedCallback() {
const deprecationMessage = (
'<p>The element &lt;py-input&gt; is deprecated, ' +
'use &lt;input class="py-input"&gt; instead.</p>'
)
createDeprecationWarning(deprecationMessage, "py-input")
ensureUniqueId(this);
this.code = htmlDecode(this.innerHTML);
this.mount_name = this.id.split('-').join('_');

View File

@@ -1,4 +1,4 @@
import { addClasses, htmlDecode } from '../utils';
import { addClasses, htmlDecode, createDeprecationWarning } from '../utils';
export class PyTitle extends HTMLElement {
widths: string[];
@@ -9,6 +9,10 @@ export class PyTitle extends HTMLElement {
}
connectedCallback() {
const deprecationMessage = (
'<p>The element &lt;py-title&gt; is deprecated, please use an &lt;h1&gt; tag instead.</p>'
)
createDeprecationWarning(deprecationMessage, "py-title")
this.label = htmlDecode(this.innerHTML);
this.mount_name = this.id.split('-').join('_');
this.innerHTML = '';

View File

@@ -293,6 +293,7 @@ input {
border-color: rgba(37, 99, 235, var(--tw-border-opacity));
border-width: 1px;
border-radius: 0.25rem;
cursor: pointer;
}
.py-li-element p {

View File

@@ -111,3 +111,16 @@ export function joinPaths(parts: string[], separator = '/') {
}
return res;
}
export function createDeprecationWarning(msg: string, elementName: string): void {
const banners = document.getElementsByClassName('alert-banner py-warning');
let bannerCount = 0;
for (const banner of banners) {
if (banner.innerHTML.includes(elementName)) {
bannerCount++;
}
}
if (bannerCount == 0) {
_createAlertBanner(msg, "warning");
}
}