mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-15 09:21:24 +08:00
29e3ce3583
* fix(module:interop): reorganization into classes * comments clean-up * Add typescript test project * fix: sync with pull request #1765: support drag * github test action fix attempt * tests: jsinterop test mock fix * codecov added to ts tests * add generated split js to gitignore * fix: coverage github action Co-authored-by: James Yeung <shunjiey@hotmail.com>
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import { infoHelper as domInfoHelper } from './dom/infoHelper';
|
|
|
|
export class styleHelper {
|
|
static addCls(selector: Element | string, className: string | Array<string>) {
|
|
let element = domInfoHelper.get(selector);
|
|
if (element) {
|
|
if (typeof className === "string") {
|
|
element.classList.add(className);
|
|
} else {
|
|
element.classList.add(...className);
|
|
}
|
|
}
|
|
}
|
|
|
|
static removeCls(selector: Element | string, clsName: string | Array<string>) {
|
|
let element = domInfoHelper.get(selector);
|
|
if (element) {
|
|
if (typeof clsName === "string") {
|
|
element.classList.remove(clsName);
|
|
} else {
|
|
element.classList.remove(...clsName);
|
|
}
|
|
}
|
|
}
|
|
|
|
static addClsToFirstChild(element: Element | string, className: string): void {
|
|
var domElement = domInfoHelper.get(element);
|
|
if (domElement && domElement.firstElementChild) {
|
|
domElement.firstElementChild.classList.add(className);
|
|
}
|
|
}
|
|
|
|
static removeClsFromFirstChild(element: Element | string, className): void {
|
|
var domElement = domInfoHelper.get(element);
|
|
if (domElement && domElement.firstElementChild) {
|
|
domElement.firstElementChild.classList.remove(className);
|
|
}
|
|
}
|
|
|
|
static matchMedia(query: string): boolean {
|
|
return window.matchMedia(query).matches;
|
|
}
|
|
|
|
static getStyle(element, styleProp: string) {
|
|
if (element.currentStyle)
|
|
return element.currentStyle[styleProp];
|
|
else if (window.getComputedStyle)
|
|
return document.defaultView.getComputedStyle(element, null).getPropertyValue(styleProp);
|
|
}
|
|
|
|
//Referenced in Caret, class Mirror
|
|
static css(element: HTMLElement, name: string | object, value: string | null = null) {
|
|
if (typeof name === 'string') {
|
|
element.style[name] = value;
|
|
} else {
|
|
for (let key in name) {
|
|
if (name.hasOwnProperty(key)) {
|
|
element.style[key] = name[key];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} |