UNPKG

@senka-ai/ui

Version:

A modern, type-safe Svelte 5 UI component library with full theme support, accessibility standards, and robust state management patterns

98 lines (97 loc) 2.47 kB
/** * Unified icon rendering utilities * Provides consistent patterns for icon handling across components */ /** * Determines if an icon should be rendered */ export function shouldRenderIcon(icon, showIcon = true) { return showIcon && icon !== undefined && icon !== null && icon !== ''; } /** * Gets the appropriate icon size */ export function getIconSize(size, defaultSize = 16) { return size ?? defaultSize; } /** * Gets standard icon container classes */ export function getIconContainerClasses(position = 'center') { const base = 'flex items-center justify-center'; const positions = { left: 'text-neutral-500', right: 'text-neutral-500', center: 'text-neutral-500', }; return `${base} ${positions[position]}`; } /** * Gets positioning classes for icons within inputs */ export function getInputIconClasses(position) { const base = 'absolute top-1/2 -translate-y-1/2 transform text-neutral-500'; const positions = { left: 'left-3.25', right: 'right-3.25', }; return `${base} ${positions[position]}`; } /** * Gets padding classes for inputs with icons */ export function getInputPadding(hasLeftIcon, hasRightIcon) { let padding = ''; if (hasLeftIcon) { padding += 'pl-10 '; } if (hasRightIcon) { padding += 'pr-10 '; } return padding.trim(); } /** * Standard icon sizes used across the application */ export const ICON_SIZES = { xs: 12, small: 14, medium: 16, large: 18, xl: 20, '2xl': 24, '3xl': 32, }; /** * Gets icon size from size key */ export function getIconSizeValue(size) { return ICON_SIZES[size]; } /** * Type guard to check if an icon is a string (emoji or text) */ export function isStringIcon(icon) { return typeof icon === 'string'; } /** * Type guard to check if an icon is a component/snippet */ export function isComponentIcon(icon) { return typeof icon === 'function' || (typeof icon === 'object' && icon !== null); } /** * Creates consistent icon rendering logic */ export function createIconRenderer(icon, options = {}) { const { size = 16, className = '', defaultSize = 16 } = options; const iconSize = getIconSize(size, defaultSize); return { shouldRender: shouldRenderIcon(icon, true), isString: isStringIcon(icon), isComponent: isComponentIcon(icon), size: iconSize, className, icon, }; }