Слияние кода завершено, страница обновится автоматически
import React, { useEffect, ReactElement } from 'react';
import { insertCss } from 'insert-css';
import warn from '../_util/warning';
import generateColor from './generate';
import { AbstractNode, IconDefinition } from './interface';
import { CustomIconComponentProps } from './Icon';
export function warning(valid: boolean, message: string): void {
warn(valid, `[@c7n/icons] ${message}`);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isIconDefinition(target: any): target is IconDefinition {
return (
typeof target === 'object' &&
typeof target.name === 'string' &&
typeof target.theme === 'string' &&
(typeof target.icon === 'object' || typeof target.icon === 'function')
);
}
export function normalizeAttrs(attrs: Attrs = {}): Attrs {
return Object.keys(attrs).reduce((acc: Attrs, key) => {
const val = attrs[key];
switch (key) {
case 'class':
acc.className = val;
delete acc.class;
break;
default:
acc[key] = val;
}
return acc;
}, {});
}
export interface Attrs {
[key: string]: string;
}
export function generate(
node: AbstractNode,
key: string,
rootProps?: { [key: string]: unknown } | false,
): ReactElement {
if (!rootProps) {
return React.createElement(
node.tag,
{ key, ...normalizeAttrs(node.attrs) },
(node.children || []).map((child, index) => generate(child, `${key}-${node.tag}-${index}`)),
);
}
return React.createElement(
node.tag,
{
key,
...normalizeAttrs(node.attrs),
...rootProps,
},
(node.children || []).map((child, index) => generate(child, `${key}-${node.tag}-${index}`)),
);
}
export function getSecondaryColor(primaryColor: string): string {
// choose the second color
return generateColor(primaryColor)[0];
}
export function normalizeTwoToneColors(
twoToneColor: string | [string, string] | undefined,
): string[] {
if (!twoToneColor) {
return [];
}
return Array.isArray(twoToneColor) ? twoToneColor : [twoToneColor];
}
// These props make sure that the SVG behaviours like general text.
// Reference: https://blog.prototypr.io/align-svg-icons-to-text-and-say-goodbye-to-font-icons-d44b3d7b26b4
export const svgBaseProps: CustomIconComponentProps & {
'aria-hidden': boolean | 'false' | 'true';
focusable: boolean | 'auto' | 'false' | 'true';
} = {
width: '1em',
height: '1em',
fill: 'currentColor',
'aria-hidden': 'true',
focusable: 'false',
};
export const iconStyles = `
.c7nicon {
display: inline-block;
color: inherit;
font-style: normal;
line-height: 0;
text-align: center;
text-transform: none;
vertical-align: -0.125em;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.c7nicon > * {
line-height: 1;
}
.c7nicon svg {
display: inline-block;
}
.c7nicon::before {
display: none;
}
.c7nicon .c7nicon-icon {
display: block;
}
.c7nicon[tabindex] {
cursor: pointer;
}
.c7nicon-spin::before,
.c7nicon-spin {
display: inline-block;
-webkit-animation: loadingCircle 1s infinite linear;
animation: loadingCircle 1s infinite linear;
}
@-webkit-keyframes loadingCircle {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes loadingCircle {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
`;
let cssInjectedFlag = false;
export const useInsertStyles = (styleStr: string = iconStyles): void => {
useEffect(() => {
if (!cssInjectedFlag) {
insertCss(styleStr, {
prepend: true,
});
cssInjectedFlag = true;
}
}, []);
};
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )