Skip to main content
Glama
deleonio
by deleonio
getRenderStates.ts1.37 kB
import type { MsgPropType, Stringified, TouchedPropType } from '../../schema'; /** * Berechnet in Abhängigkeit des Component-State, wie die * aria-describedby-Attributs gesetzt werden sollen. * * @param state State der Component * @returns Render-States */ export const getRenderStates = (state: { _msg?: Stringified<MsgPropType>; _hint?: string; _id: string; _touched?: TouchedPropType; _hideMsg?: boolean; _hasCounter?: boolean; }): { hasError: boolean; hasHint: boolean; ariaDescribedBy: string[]; } => { const msg = state._msg; const description = typeof msg === 'string' ? msg : msg?._description; const type = typeof msg === 'string' ? 'error' : (msg?._type ?? 'error'); const hasMessage = Boolean(description && description.length > 0); const isMessageValidError = type === 'error' && hasMessage; const hasError = isMessageValidError && state._touched === true; const hasHint = typeof state._hint === 'string' && state._hint.length > 0; const ariaDescribedBy: string[] = []; if (hasMessage && !state._hideMsg) { ariaDescribedBy.push(`${state._id}-msg`); } if (hasHint === true) { ariaDescribedBy.push(`${state._id}-hint`); } if (state._hasCounter) { ariaDescribedBy.push(`${state._id}-counter`); } if (hasError === true) { ariaDescribedBy.push(`${state._id}-error`); } return { hasError, hasHint, ariaDescribedBy }; };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/deleonio/public-ui-kolibri'

If you have feedback or need assistance with the MCP directory API, please join our Discord server