style: for utils

This commit is contained in:
wuji.xwt 2020-09-10 17:44:25 +08:00
parent cdad47fc94
commit bd1921df55
9 changed files with 14 additions and 6 deletions

View File

@ -100,7 +100,11 @@ export class StylePoint {
private placeholder: Element | Text; private placeholder: Element | Text;
constructor(readonly level: number, readonly id?: string) { readonly level: number;
readonly id: string;
constructor(level: number, id?: string) {
let placeholder: any; let placeholder: any;
if (id) { if (id) {
placeholder = document.head.querySelector(`style[data-id="${id}"]`); placeholder = document.head.querySelector(`style[data-id="${id}"]`);

View File

@ -7,7 +7,7 @@ interface LibraryMap {
[key: string]: string; [key: string]: string;
} }
function accessLibrary(library: string | object) { function accessLibrary(library: string | Record<string, unknown>) {
if (typeof library !== 'string') { if (typeof library !== 'string') {
return library; return library;
} }

View File

@ -11,6 +11,7 @@ export function cloneDeep(src: any): any {
} else if (type === 'object' && isPlainObject(src)) { } else if (type === 'object' && isPlainObject(src)) {
data = {}; data = {};
for (const key in src) { for (const key in src) {
// eslint-disable-next-line no-prototype-builtins
if (src.hasOwnProperty(key)) { if (src.hasOwnProperty(key)) {
data[key] = cloneDeep(src[key]); data[key] = cloneDeep(src[key]);
} }

View File

@ -1,7 +1,7 @@
import { ReactNode, ComponentType, isValidElement, cloneElement, createElement } from 'react'; import { ReactNode, ComponentType, isValidElement, cloneElement, createElement } from 'react';
import { isReactComponent } from './is-react'; import { isReactComponent } from './is-react';
export function createContent(content: ReactNode | ComponentType<any>, props?: object): ReactNode { export function createContent(content: ReactNode | ComponentType<any>, props?: Record<string, unknown>): ReactNode {
if (isValidElement(content)) { if (isValidElement(content)) {
return props ? cloneElement(content, props) : content; return props ? cloneElement(content, props) : content;
} }

View File

@ -5,7 +5,7 @@ import { isReactComponent } from './is-react';
const URL_RE = /^(https?:)\/\//i; const URL_RE = /^(https?:)\/\//i;
export function createIcon(icon?: IconType | null, props?: object): ReactNode { export function createIcon(icon?: IconType | null, props?: Record<string, unknown>): ReactNode {
if (!icon) { if (!icon) {
return null; return null;
} }

View File

@ -3,5 +3,6 @@ export function getPrototypeOf(target: any) {
return Object.getPrototypeOf(target); return Object.getPrototypeOf(target);
} }
// eslint-disable-next-line no-proto
return target.__proto__; return target.__proto__;
} }

View File

@ -1,3 +1,3 @@
export function isObject(value: any): value is object { export function isObject(value: any): value is Record<string, unknown> {
return value !== null && typeof value === 'object'; return value !== null && typeof value === 'object';
} }

View File

@ -3,6 +3,7 @@ export function setPrototypeOf(target: any, proto: any) {
if (typeof Object.setPrototypeOf !== 'undefined') { if (typeof Object.setPrototypeOf !== 'undefined') {
Object.setPrototypeOf(target, proto); // tslint:disable-line Object.setPrototypeOf(target, proto); // tslint:disable-line
} else { } else {
// eslint-disable-next-line no-proto
target.__proto__ = proto; target.__proto__ = proto;
} }
} }

View File

@ -13,7 +13,7 @@ export interface IconProps {
fill?: string; fill?: string;
size?: 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | number; size?: 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | number;
children?: ReactNode; children?: ReactNode;
style?: object; style?: Record<string, unknown>;
} }
export function SVGIcon({ export function SVGIcon({
@ -26,6 +26,7 @@ export function SVGIcon({
}: IconProps & { }: IconProps & {
viewBox: string; viewBox: string;
}) { }) {
// eslint-disable-next-line no-prototype-builtins
if (SizePresets.hasOwnProperty(size)) { if (SizePresets.hasOwnProperty(size)) {
size = SizePresets[size]; size = SizePresets[size];
} }