-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13123 from woocommerce/13117-woo-poscash-receipts…
…-implement-receipts-ui [Woo POS][Cash & Receipts] Implement receipts UI
- Loading branch information
Showing
14 changed files
with
614 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,34 @@ | ||
package com.woocommerce.android.ui.woopos.common.composeui.component | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.IntrinsicSize | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.text.BasicTextField | ||
import androidx.compose.foundation.text.KeyboardActions | ||
import androidx.compose.foundation.text.KeyboardOptions | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.TextFieldColors | ||
import androidx.compose.material.TextFieldDefaults | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableIntStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.SolidColor | ||
import androidx.compose.ui.layout.onGloballyPositioned | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.input.VisualTransformation | ||
import androidx.compose.ui.text.style.TextAlign | ||
|
@@ -92,9 +106,62 @@ fun <T> WooPosTypedInputField( | |
} | ||
} | ||
|
||
@Composable | ||
fun WooPosInputField( | ||
value: String, | ||
onValueChange: (String) -> Unit, | ||
label: String = "", | ||
textStyle: TextStyle = MaterialTheme.typography.h6, | ||
textColor: Color = MaterialTheme.colors.onBackground, | ||
keyboardOptions: KeyboardOptions = KeyboardOptions.Default, | ||
keyboardActions: KeyboardActions = KeyboardActions.Default, | ||
contentAlignment: Alignment = Alignment.CenterStart, | ||
modifier: Modifier = Modifier, | ||
) { | ||
var labelWidth by remember { mutableIntStateOf(0) } | ||
|
||
Box( | ||
modifier = modifier | ||
.background(Color.Transparent), | ||
contentAlignment = contentAlignment, | ||
) { | ||
if (value.isEmpty()) { | ||
Text( | ||
text = label, | ||
style = textStyle.copy(color = textColor.copy(alpha = 0.2f)), | ||
maxLines = 1, | ||
softWrap = false, | ||
modifier = Modifier | ||
.onGloballyPositioned { coordinates -> | ||
labelWidth = coordinates.size.width | ||
} | ||
) | ||
} | ||
|
||
val density = LocalDensity.current | ||
|
||
// that's workaround to keep cursor to the left from the label | ||
val textFieldModifier = if (value.isEmpty()) { | ||
Modifier.width(with(density) { labelWidth.toDp() + 4.dp }) | ||
} else { | ||
Modifier.width(IntrinsicSize.Min) | ||
} | ||
BasicTextField( | ||
value = value, | ||
onValueChange = onValueChange, | ||
textStyle = textStyle.copy(color = textColor), | ||
singleLine = true, | ||
keyboardActions = keyboardActions, | ||
keyboardOptions = keyboardOptions, | ||
modifier = textFieldModifier, | ||
cursorBrush = SolidColor(MaterialTheme.colors.onBackground), | ||
) | ||
} | ||
} | ||
|
||
@WooPosPreview | ||
@Composable | ||
fun WooPosInputFieldPreview() { | ||
fun WooPosTypedInputFieldPreview() { | ||
WooPosTheme { | ||
Column(modifier = Modifier.padding(16.dp)) { | ||
WooPosTypedInputField( | ||
|
@@ -125,3 +192,32 @@ fun WooPosInputFieldPreview() { | |
} | ||
} | ||
} | ||
|
||
@WooPosPreview | ||
@Composable | ||
fun WooPosInputFieldPreview() { | ||
WooPosTheme { | ||
Column( | ||
modifier = Modifier | ||
.padding(16.dp) | ||
.fillMaxSize(), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
) { | ||
WooPosInputField( | ||
value = "[email protected]", | ||
onValueChange = {}, | ||
textStyle = MaterialTheme.typography.h3, | ||
contentAlignment = Alignment.Center | ||
) | ||
|
||
Spacer(modifier = Modifier.size(8.dp)) | ||
|
||
WooPosInputField( | ||
value = "", | ||
onValueChange = {}, | ||
textStyle = MaterialTheme.typography.h3, | ||
label = "Label Label", | ||
) | ||
} | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...main/kotlin/com/woocommerce/android/ui/woopos/common/composeui/component/WooPosToolbar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.woocommerce.android.ui.woopos.common.composeui.component | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.IconButton | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.res.vectorResource | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.dp | ||
import androidx.constraintlayout.compose.ConstraintLayout | ||
import com.woocommerce.android.R | ||
import com.woocommerce.android.ui.woopos.common.composeui.WooPosPreview | ||
import com.woocommerce.android.ui.woopos.common.composeui.WooPosTheme | ||
import com.woocommerce.android.ui.woopos.common.composeui.toAdaptivePadding | ||
|
||
@Composable | ||
fun WooPosToolbar( | ||
titleText: String, | ||
onBackClicked: () -> Unit | ||
) { | ||
ConstraintLayout( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(top = 40.dp.toAdaptivePadding()) | ||
.height(40.dp) | ||
) { | ||
val (backButton, title) = createRefs() | ||
IconButton( | ||
onClick = { onBackClicked() }, | ||
modifier = Modifier | ||
.constrainAs(backButton) { | ||
start.linkTo(parent.start) | ||
top.linkTo(parent.top) | ||
centerVerticallyTo(parent) | ||
} | ||
.padding(start = 8.dp.toAdaptivePadding()) | ||
) { | ||
Icon( | ||
imageVector = ImageVector.vectorResource(R.drawable.ic_back_24dp), | ||
contentDescription = stringResource(R.string.woopos_toolbar_icon_content_description), | ||
tint = MaterialTheme.colors.onBackground, | ||
modifier = Modifier.size(28.dp) | ||
) | ||
} | ||
|
||
val iconTitlePadding = 8.dp.toAdaptivePadding() | ||
Text( | ||
text = titleText, | ||
style = MaterialTheme.typography.h4, | ||
color = MaterialTheme.colors.onBackground, | ||
fontWeight = FontWeight.Bold, | ||
maxLines = 1, | ||
modifier = Modifier | ||
.constrainAs(title) { | ||
top.linkTo(backButton.top) | ||
start.linkTo(backButton.end, margin = iconTitlePadding) | ||
centerVerticallyTo(parent) | ||
} | ||
) | ||
} | ||
} | ||
|
||
@WooPosPreview | ||
@Composable | ||
fun WooPosToolbarPreview() { | ||
WooPosTheme { | ||
Column { | ||
WooPosToolbar( | ||
titleText = "Title", | ||
onBackClicked = { } | ||
) | ||
|
||
Spacer(modifier = Modifier.weight(1f)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.