import QtQuick // A labelled single-line input with an inline error and optional secret echo. Column { id: field property string label: "" property string placeholder: "" property string error: "" property bool secret: false property bool showSecret: false property alias text: input.text property alias inputItem: input property int maxLength: 256 signal edited(string value) signal accepted width: parent ? parent.width : implicitWidth spacing: 6 Text { width: parent.width text: field.label color: Theme.warmWhite font.family: Theme.family font.pixelSize: Theme.fontSmall font.weight: Font.DemiBold visible: field.label.length > 0 } Rectangle { width: parent.width height: 42 radius: Theme.radiusSmall color: Theme.charcoal border.width: input.activeFocus ? 2 : 1 border.color: field.error.length > 0 ? Theme.danger : input.activeFocus ? Theme.focusRing : Theme.border TextInput { id: input anchors.fill: parent anchors.leftMargin: 12 anchors.rightMargin: 44 verticalAlignment: TextInput.AlignVCenter color: Theme.warmWhite font.family: Theme.family font.pixelSize: Theme.fontBody selectionColor: Theme.amberDeep selectedTextColor: Theme.warmWhite echoMode: (field.secret && !field.showSecret) ? TextInput.Password : TextInput.Normal passwordCharacter: "\u2022" selectByMouse: true activeFocusOnTab: true maximumLength: field.maxLength clip: true onTextEdited: field.edited(text) onAccepted: field.accepted() Text { anchors.fill: parent verticalAlignment: Text.AlignVCenter text: field.placeholder color: Theme.muted font.family: Theme.family font.pixelSize: Theme.fontBody visible: input.text.length === 0 && !input.activeFocus } } Text { anchors.right: parent.right anchors.rightMargin: 12 anchors.verticalCenter: parent.verticalCenter visible: field.secret text: field.showSecret ? "hide" : "show" color: Theme.amber font.family: Theme.family font.pixelSize: Theme.fontSmall MouseArea { anchors.fill: parent anchors.margins: -6 cursorShape: Qt.PointingHandCursor onClicked: field.showSecret = !field.showSecret } } } Text { width: parent.width text: field.error color: Theme.danger font.family: Theme.family font.pixelSize: Theme.fontSmall wrapMode: Text.WordWrap visible: field.error.length > 0 } }