package dev.inmo.jsuikit.elements import androidx.compose.runtime.Composable import androidx.compose.web.events.SyntheticMouseEvent import dev.inmo.jsuikit.modifiers.* import org.jetbrains.compose.web.attributes.InputType import org.jetbrains.compose.web.attributes.disabled import org.jetbrains.compose.web.dom.* import org.w3c.dom.HTMLButtonElement import org.w3c.dom.HTMLDivElement import org.w3c.dom.events.Event @Composable fun DefaultButton( modifiers: Array = emptyArray(), disabled: Boolean = false, buttonType: UIKitButton.Type = UIKitButton.Type.Default, onClick: ((SyntheticMouseEvent) -> Unit)? = null, attributesCustomizer: AttrBuilderContext = {}, contentAllocator: ContentBuilder ) { Button( { onClick ?.let { onClick(it) } classes("uk-button") include(*modifiers, buttonType) if (disabled) { disabled() } attributesCustomizer() } ) { contentAllocator() } } @Composable fun DefaultButton( text: String, modifiers: Array = emptyArray(), disabled: Boolean = false, buttonType: UIKitButton.Type = UIKitButton.Type.Default, preTextContentAllocator: ContentBuilder? = null, afterTextContentAllocator: ContentBuilder? = null, attributesCustomizer: AttrBuilderContext = {}, onClick: ((SyntheticMouseEvent) -> Unit)? = null ) = DefaultButton(modifiers, disabled = disabled, buttonType = buttonType, onClick = onClick, attributesCustomizer = attributesCustomizer) { preTextContentAllocator ?.apply { preTextContentAllocator() } Text(text) afterTextContentAllocator ?.apply { afterTextContentAllocator() } } @Composable fun UploadButton( text: String, buttonModifiers: Array = emptyArray(), containerModifiers: Array = emptyArray(), disabled: Boolean = false, buttonType: UIKitButton.Type = UIKitButton.Type.Default, attributesCustomizer: AttrBuilderContext = {}, onChange: (Event) -> Unit ) { Div( { classes("js-upload", "uk-form-custom") attr("uk-form-custom", "") include(*containerModifiers) attributesCustomizer() } ) { Input(InputType.File) { onChange { onChange(it.nativeEvent) } } Button( { classes("uk-button") include(*buttonModifiers, buttonType) if (disabled) { disabled() } } ) { Text(text) } } }