fix: call button onPress even without state handler

This commit is contained in:
Aarnav Tale
2024-05-20 14:02:04 -04:00
parent 78698dcbba
commit 0a12cdb3d6
+8 -7
View File
@@ -4,8 +4,8 @@ import { Button as AriaButton } from 'react-aria-components'
import { cn } from '~/utils/cn' import { cn } from '~/utils/cn'
type ButtonProperties = Parameters<typeof AriaButton>[0] & { type ButtonProperties = Parameters<typeof AriaButton>[0] & {
readonly control?: [boolean, Dispatch<SetStateAction<boolean>>]; readonly control?: [boolean, Dispatch<SetStateAction<boolean>>]
readonly variant?: 'heavy' | 'light'; readonly variant?: 'heavy' | 'light'
} }
export default function Button(properties: ButtonProperties) { export default function Button(properties: ButtonProperties) {
@@ -24,13 +24,14 @@ export default function Button(properties: ButtonProperties) {
? 'text-white' ? 'text-white'
: 'text-ui-700 dark:text-ui-300', : 'text-ui-700 dark:text-ui-300',
properties.isDisabled && 'opacity-50 cursor-not-allowed', properties.isDisabled && 'opacity-50 cursor-not-allowed',
properties.className properties.className,
)} )}
// If control is passed, set the state value // If control is passed, set the state value
onPress={properties.control ? () => { onPress={properties.control
properties.control?.[1](true) ? () => {
} : undefined} properties.control?.[1](true)
}
: properties.onPress}
/> />
) )
} }