Skip to content

Commit

Permalink
Copy OnClick
Browse files Browse the repository at this point in the history
  • Loading branch information
Shade authored and Shade committed Feb 14, 2025
1 parent 98e7225 commit 97f486d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 35 deletions.
47 changes: 24 additions & 23 deletions src/main/kotlin/ui/components/FormComponents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ fun FormTextField(
onValueChange = onValueChange,
interactionSource = interactionSource,
modifier = Modifier
.fillMaxSize()
.padding(start = 14.dp, bottom = 3.dp),
.fillMaxSize()
.padding(start = 14.dp, bottom = 3.dp),
textStyle = TextStyle(
fontFamily = Font.RussoOne,
color = Color.White,
Expand Down Expand Up @@ -119,8 +119,8 @@ fun FormTextArea(
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 14.dp)
.fillMaxWidth()
.padding(horizontal = 14.dp)
) {
if (label.isNotEmpty()) {
Text(
Expand All @@ -137,8 +137,8 @@ fun FormTextArea(
onValueChange = onValueChange,
interactionSource = interactionSource,
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 8.dp),
.fillMaxWidth()
.padding(bottom = 8.dp),
textStyle = TextStyle(
fontFamily = Font.RussoOne,
color = Color.White,
Expand Down Expand Up @@ -174,17 +174,17 @@ fun <T> FormDropdown(
) {
Box(
modifier = Modifier
.fillMaxSize()
.clickable { expanded = true }
.fillMaxSize()
.clickable { expanded = true }
) {
TextFieldDefaults.DecorationBox(
value = selectedItem?.displayText ?: "",
innerTextField = {
Text(
text = selectedItem?.displayText ?: "",
modifier = Modifier
.fillMaxWidth()
.padding(start = 14.dp, bottom = 3.dp),
.fillMaxWidth()
.padding(start = 14.dp, bottom = 3.dp),
style = TextStyle(
fontFamily = Font.RussoOne,
color = Color.White,
Expand Down Expand Up @@ -232,8 +232,8 @@ fun <T> FormDropdown(
expanded = expanded,
onDismissRequest = { expanded = false },
modifier = Modifier
.background(secondary)
.width(IntrinsicSize.Min)
.background(secondary)
.width(IntrinsicSize.Min)
) {
items.forEach { item ->
DropdownMenuItem(
Expand All @@ -250,11 +250,11 @@ fun <T> FormDropdown(
expanded = false
},
modifier = Modifier
.fillMaxWidth()
.background(
if (item.id == selectedItem?.id) Color.White.copy(alpha = 0.1f)
else Color.Transparent
)
.fillMaxWidth()
.background(
if (item.id == selectedItem?.id) Color.White.copy(alpha = 0.1f)
else Color.Transparent
)
)
}
}
Expand Down Expand Up @@ -284,8 +284,8 @@ fun PasswordTextField(
onValueChange = onValueChange,
interactionSource = interactionSource,
modifier = Modifier
.fillMaxSize()
.padding(start = 14.dp, bottom = 3.dp),
.fillMaxSize()
.padding(start = 14.dp, bottom = 3.dp),
textStyle = TextStyle(
fontFamily = Font.RussoOne,
color = Color.White,
Expand All @@ -312,7 +312,7 @@ fun PasswordTextField(
checked = passwordVisible,
onCheckedChange = { passwordVisible = it },
modifier = Modifier.hoverable(interactionSource)
.pointerHoverIcon(PointerIcon.Hand)
.pointerHoverIcon(PointerIcon.Hand)
)
{
Icon(
Expand Down Expand Up @@ -415,6 +415,7 @@ fun UnderLineTextFiled(
modifier: Modifier = Modifier,
label: String,
field: String,
onIconClick: () -> Unit = { },
onFieldChange: (String) -> Unit,
isPassword: Boolean = false,
singleLine: Boolean = true
Expand Down Expand Up @@ -468,7 +469,7 @@ fun UnderLineTextFiled(
else Icons.Default.Visibility,
contentDescription = "",
modifier = Modifier.size(width = 15.dp, height = 15.dp)
.pointerHoverIcon(PointerIcon.Default),
.pointerHoverIcon(PointerIcon.Default),
tint = Color.Gray
)
}
Expand All @@ -477,14 +478,14 @@ fun UnderLineTextFiled(
Column {
IconButton(
interactionSource = interactionSource,
onClick = {}
onClick = onIconClick
) {
Icon(
imageVector = Icons.Default.ContentCopy,
contentDescription = "",
tint = Color.Gray,
modifier = Modifier.size(width = 15.dp, height = 15.dp)
.pointerHoverIcon(PointerIcon.Default)
.pointerHoverIcon(PointerIcon.Default)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ClipboardManager
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.text.AnnotatedString
import ui.components.UnderLineTextFiled
import viewmodel.SecVaultScreenModel

@Composable
fun PasswordCredentialForm(screenModel: SecVaultScreenModel) {
val selectedCredential by screenModel.selectedCredential.collectAsState()

val clipboardManager: ClipboardManager = LocalClipboardManager.current

var userName by remember(selectedCredential) {
mutableStateOf(selectedCredential.password?.username ?: "")
}
Expand All @@ -38,7 +42,8 @@ fun PasswordCredentialForm(screenModel: SecVaultScreenModel) {
field = userName,
onFieldChange = { userName = it },
label = "Username",
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
onIconClick = { clipboardManager.setText(AnnotatedString(userName)) }
)
}

Expand All @@ -48,7 +53,8 @@ fun PasswordCredentialForm(screenModel: SecVaultScreenModel) {
onFieldChange = { password = it },
label = "Password",
modifier = Modifier.fillMaxWidth(),
isPassword = true
isPassword = true,
onIconClick = { clipboardManager.setText(AnnotatedString(password)) }
)
}

Expand All @@ -57,7 +63,8 @@ fun PasswordCredentialForm(screenModel: SecVaultScreenModel) {
field = email,
onFieldChange = { email = it },
label = "Email",
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
onIconClick = { clipboardManager.setText(AnnotatedString(email)) }
)
}

Expand All @@ -66,7 +73,8 @@ fun PasswordCredentialForm(screenModel: SecVaultScreenModel) {
field = website,
onFieldChange = { website = it },
label = "Website",
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
onIconClick = { clipboardManager.setText(AnnotatedString(website)) }
)
}

Expand All @@ -76,6 +84,7 @@ fun PasswordCredentialForm(screenModel: SecVaultScreenModel) {
@Composable
fun CreditCardCredentialForm(screenModel: SecVaultScreenModel) {
val selectedCredential by screenModel.selectedCredential.collectAsState()
val clipboardManager: ClipboardManager = LocalClipboardManager.current

var bankName by remember(selectedCredential) {
mutableStateOf(selectedCredential.creditCard?.name ?: "")
Expand Down Expand Up @@ -119,7 +128,8 @@ fun CreditCardCredentialForm(screenModel: SecVaultScreenModel) {
field = bankName,
onFieldChange = { bankName = it },
label = "Bank Name",
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
onIconClick = { clipboardManager.setText(AnnotatedString(bankName)) }
)
}

Expand All @@ -128,7 +138,8 @@ fun CreditCardCredentialForm(screenModel: SecVaultScreenModel) {
field = cardOwner,
onFieldChange = { cardOwner = it },
label = "Card Owner",
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
onIconClick = { clipboardManager.setText(AnnotatedString(cardOwner)) }
)
}

Expand All @@ -137,7 +148,8 @@ fun CreditCardCredentialForm(screenModel: SecVaultScreenModel) {
field = cardNumber,
onFieldChange = { cardNumber = it },
label = "Card Number",
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
onIconClick = { clipboardManager.setText(AnnotatedString(cardNumber)) }
)
}

Expand All @@ -147,7 +159,8 @@ fun CreditCardCredentialForm(screenModel: SecVaultScreenModel) {
onFieldChange = { cvc = it },
label = "CVC",
modifier = Modifier.fillMaxWidth(),
isPassword = true
isPassword = true,
onIconClick = { clipboardManager.setText(AnnotatedString(cvc)) }
)
}

Expand All @@ -157,7 +170,8 @@ fun CreditCardCredentialForm(screenModel: SecVaultScreenModel) {
onFieldChange = { pin = it },
label = "Pin",
modifier = Modifier.fillMaxWidth(),
isPassword = true
isPassword = true,
onIconClick = { clipboardManager.setText(AnnotatedString(pin)) }
)
}

Expand All @@ -166,7 +180,8 @@ fun CreditCardCredentialForm(screenModel: SecVaultScreenModel) {
field = expiryDate,
onFieldChange = { expiryDate = it },
label = "Expiry Date",
modifier = Modifier.fillMaxWidth()
modifier = Modifier.fillMaxWidth(),
onIconClick = { clipboardManager.setText(AnnotatedString(expiryDate)) }
)
}

Expand All @@ -176,7 +191,8 @@ fun CreditCardCredentialForm(screenModel: SecVaultScreenModel) {
onFieldChange = { notes = it },
label = "Notes",
modifier = Modifier.fillMaxWidth(),
singleLine = false
singleLine = false,
onIconClick = { clipboardManager.setText(AnnotatedString(notes)) }
)
}
}
Expand Down

0 comments on commit 97f486d

Please sign in to comment.