Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

FieldDetailMetaBadges.tsx

42 lines1.3 KB

1import { For, Show, createMemo } from 'solid-js'
2import { FieldMetaBadge } from '../FieldMetaBadge'
3import type { FieldMetaBadgeKind } from '../FieldMetaBadge'
4import type { FieldId } from '@/types/branded'
5import { useFormDevtoolsStore } from '@/stores/formDevtoolsStore'
6import { CardDescription } from '@/components/ui/card'
7​
8interface FieldDetailMetaBadgesProps {
9 fieldId: FieldId
10 isMounted: boolean | undefined
12export function FieldDetailMetaBadges(props: FieldDetailMetaBadgesProps) {
13 const { getFieldSummary } = useFormDevtoolsStore().fieldMeta
14​
15 const meta = () => getFieldSummary(props.fieldId)
16​
17 const badges = createMemo(() => {
18 const m = meta()
19 const output: Array<FieldMetaBadgeKind> = []
20​
21 if (props.isMounted === false) output.push('unmounted')
22​
23 output.push(
24 m.isDirty ? 'dirty' : 'pristine',
25 m.isTouched ? 'touched' : 'untouched',
26 m.isDefaultValue ? 'defaultValue' : 'nonDefaultValue',
27 )
28​
29 if (m.isBlurred) output.push('blurred')
30 if (m.isLongValidating) output.push('validating')
31​
32 return output
33 })
34​
35 return (
36 <Show when={badges().length > 0}>
37 <CardDescription class="flex flex-wrap gap-2">
38 <For each={badges()}>{(badge) => <FieldMetaBadge kind={badge} />}</For>
39 </CardDescription>
40 </Show>
41 )