mirror of
https://github.com/pyscript/pyscript.git
synced 2026-04-05 05:00:30 -04:00
Deprecate py-button, py-inputbox, py-box and py-title (#931)
This commit is contained in:
@@ -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 <py-box> is deprecated, you should create a ' +
|
||||
'div with "py-box" class name instead. For example: <div class="py-box"> '
|
||||
)
|
||||
createDeprecationWarning(deprecationMessage, "py-box")
|
||||
const mainDiv = document.createElement('div');
|
||||
addClasses(mainDiv, ['py-box']);
|
||||
|
||||
|
||||
@@ -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 <py-button> is deprecated, create a function with your ' +
|
||||
'inline code and use <button py-click="function()" class="py-button"> instead.</p>'
|
||||
)
|
||||
createDeprecationWarning(deprecationMessage, "py-button")
|
||||
|
||||
ensureUniqueId(this);
|
||||
this.code = htmlDecode(this.innerHTML) || '';
|
||||
this.mount_name = this.id.split('-').join('_');
|
||||
|
||||
@@ -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 <py-input> is deprecated, ' +
|
||||
'use <input class="py-input"> instead.</p>'
|
||||
)
|
||||
createDeprecationWarning(deprecationMessage, "py-input")
|
||||
ensureUniqueId(this);
|
||||
this.code = htmlDecode(this.innerHTML);
|
||||
this.mount_name = this.id.split('-').join('_');
|
||||
|
||||
@@ -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 <py-title> is deprecated, please use an <h1> tag instead.</p>'
|
||||
)
|
||||
createDeprecationWarning(deprecationMessage, "py-title")
|
||||
this.label = htmlDecode(this.innerHTML);
|
||||
this.mount_name = this.id.split('-').join('_');
|
||||
this.innerHTML = '';
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user