import { createEffect, on, type Accessor, type JSX, type Setter } from 'solid-js' import { useState } from '../state' import { expand } from '../utils' export function capitalizeFirstLetter(str: string): string { return str.charAt(0).toUpperCase() + str.slice(1) } export function GalleryNav(props: { children?: JSX.Element closeText: string isAnimating: Accessor setIsOpen: Setter }): JSX.Element { // variables const indexNums: HTMLSpanElement[] = Array(8) // states const [state] = useState() const stateLength = state().length // helper functions const updateIndexText: () => void = () => { const indexValue: string = expand(state().index + 1) const indexLength: string = expand(stateLength) indexNums.forEach((e: HTMLSpanElement, i: number) => { if (i < 4) { e.innerText = indexValue[i] } else { e.innerText = indexLength[i - 4] } }) } const onClick: () => void = () => { if (props.isAnimating()) return props.setIsOpen(false) } // effects createEffect( on( () => { state() }, () => { updateIndexText() }, { defer: true } ) ) return ( <> ) }