Skip to content

Commit

Permalink
Refactor IconButton and clean up imports in TextField
Browse files Browse the repository at this point in the history
Removed unnecessary imports from the TextField component and refactored IconButton usage. This includes removing the IconButton import in TextField and defining a new PMCIconButton function in the Button component. This improvement aids in reducing clutter and enhancing code readability.
  • Loading branch information
mdsadiqueinam committed Apr 9, 2024
1 parent 5aa8a2d commit 2841b52
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
20 changes: 20 additions & 0 deletions commonCompose/src/commonMain/kotlin/ui/components/Button.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package ui.components

import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.RowScope
import androidx.compose.material3.Button
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.IconButton
import androidx.compose.material3.IconButtonColors
import androidx.compose.material3.IconButtonDefaults
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon
Expand Down Expand Up @@ -53,4 +58,19 @@ fun PMCTextButton(
content()
}
}
}

@Composable
fun PMCIconButton(
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
content: @Composable () -> Unit
) {
IconButton(
onClick = onClick,
modifier = modifier.pointerHoverIcon(icon = PointerIcon.Hand),
enabled = enabled,
content = content
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.compose.material.icons.filled.Error
import androidx.compose.material.icons.outlined.Visibility
import androidx.compose.material.icons.outlined.VisibilityOff
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
Expand All @@ -25,15 +24,12 @@ import androidx.compose.ui.input.key.KeyEventType
import androidx.compose.ui.input.key.key
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.input.key.type
import androidx.compose.ui.input.pointer.PointerIcon
import androidx.compose.ui.input.pointer.pointerHoverIcon
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
import org.jetbrains.compose.resources.stringResource
import pdnsmanager.commoncompose.generated.resources.Res
import pdnsmanager.commoncompose.generated.resources.error
import pdnsmanager.commoncompose.generated.resources.hide_password
import pdnsmanager.commoncompose.generated.resources.show_password

Expand All @@ -58,7 +54,7 @@ fun PMCOutlinedTextField(
val focusManager = LocalFocusManager.current
OutlinedTextField(
modifier = modifier.onPreviewKeyEvent {
if (it.key == Key.Tab && it.type == KeyEventType.KeyDown){
if (it.key == Key.Tab && it.type == KeyEventType.KeyDown) {
focusManager.moveFocus(FocusDirection.Down)
true
} else {
Expand Down Expand Up @@ -145,15 +141,14 @@ fun PMCPasswordTextField(
isError = isError,
error = error,
trailingIcon = {
IconButton(
PMCIconButton(
onClick = {
if (visibility.value == FieldVisibility.Hidden) {
visibility.value = FieldVisibility.Visible
} else {
visibility.value = FieldVisibility.Hidden
}
},
modifier = Modifier.pointerHoverIcon(PointerIcon.Hand)
) {
visibility.value.icon()
}
Expand Down

0 comments on commit 2841b52

Please sign in to comment.