MCPcopy Create free account
hub / github.com/SyntaxUI/syntaxui / Heading

Function Heading

src/components/Heading.tsx:69–117  ·  view source on GitHub ↗
({
  children,
  tag,
  label,
  level,
  anchor = true,
  ...props
}: React.ComponentPropsWithoutRef<`h${Level}`> & {
  id: string
  tag?: string
  label?: string
  level?: Level
  anchor?: boolean
})

Source from the content-addressed store, hash-verified

67}
68
69export function Heading<Level extends 2 | 3>({
70 children,
71 tag,
72 label,
73 level,
74 anchor = true,
75 ...props
76}: React.ComponentPropsWithoutRef<`h${Level}`> & {
77 id: string
78 tag?: string
79 label?: string
80 level?: Level
81 anchor?: boolean
82}) {
83 level = level ?? (2 as Level)
84 let Component = `h${level}` as 'h2' | 'h3'
85 let ref = useRef<HTMLHeadingElement>(null)
86 let registerHeading = useSectionStore((s) => s.registerHeading)
87
88 let inView = useInView(ref, {
89 margin: `${remToPx(-3.5)}px 0px 0px 0px`,
90 amount: 'all',
91 })
92
93 useEffect(() => {
94 if (level === 2) {
95 registerHeading({ id: props.id, ref, offsetRem: tag || label ? 8 : 6 })
96 }
97 })
98
99 return (
100 <>
101 <Eyebrow tag={tag} label={label} />
102 <Component
103 ref={ref}
104 className={tag || label ? 'mt-2 scroll-mt-32' : 'scroll-mt-24'}
105 {...props}
106 >
107 {anchor ? (
108 <Anchor id={props.id} inView={inView}>
109 {children}
110 </Anchor>
111 ) : (
112 children
113 )}
114 </Component>
115 </>
116 )
117}

Callers

nothing calls this directly

Calls 2

useSectionStoreFunction · 0.90
remToPxFunction · 0.90

Tested by

no test coverage detected