import React, { useEffect, useState } from 'react'; import styled from 'styled-components'; import type { IconProps } from '@redocly/theme/icons/types'; import { getCssColorVariable } from '@redocly/theme/core/utils'; export interface AiStarsGradientIconProps extends IconProps { background?: string; borderRadius?: string; padding?: string; margin?: string; } const Icon = (props: AiStarsGradientIconProps) => { const { color = '', background, borderRadius, padding, margin, ...restProps } = props; const [resolvedColor, setResolvedColor] = useState(color); useEffect(() => { const resolvedColor = color.startsWith('var(') ? window .getComputedStyle(document.documentElement) .getPropertyValue(color.slice(4, -1)) .trim() : color; setResolvedColor(resolvedColor); }, [color]); const isColorOverridden = resolvedColor && resolvedColor !== 'none'; const fill = isColorOverridden ? resolvedColor : 'url(#gradient)'; return ( {!isColorOverridden && ( )} ); }; export const AiStarsGradientIcon = styled(Icon).attrs({ 'data-component-name': 'icons/AiStarsGradientIcon/AiStarsGradientIcon', })` height: ${({ size }) => size || '16px'}; width: ${({ size }) => size || '16px'}; ${({ background, borderRadius, margin }) => background && ` display: flex; align-items: center; justify-content: center; background: ${getCssColorVariable(background)}; padding: var(--spacing-xs); margin: ${margin || '0'}; border-radius: ${background && borderRadius ? borderRadius : 'none'}; `} color: ${({ color }) => color && getCssColorVariable(color)}; `;