18
18
19
19
package com.neoutils.neoregex.core.sharedui.component
20
20
21
- import androidx.compose.foundation.BorderStroke
22
- import androidx.compose.foundation.background
23
21
import androidx.compose.foundation.border
24
- import androidx.compose.foundation.layout.*
22
+ import androidx.compose.foundation.layout.PaddingValues
23
+ import androidx.compose.foundation.layout.fillMaxWidth
25
24
import androidx.compose.foundation.shape.RoundedCornerShape
26
25
import androidx.compose.foundation.text.KeyboardActions
27
- import androidx.compose.material3.*
26
+ import androidx.compose.material3.LocalTextStyle
28
27
import androidx.compose.material3.MaterialTheme.colorScheme
29
28
import androidx.compose.material3.MaterialTheme.typography
29
+ import androidx.compose.material3.Text
30
30
import androidx.compose.runtime.*
31
- import androidx.compose.ui.Alignment
32
31
import androidx.compose.ui.Modifier
33
32
import androidx.compose.ui.focus.FocusRequester
34
33
import androidx.compose.ui.focus.focusRequester
@@ -38,137 +37,68 @@ import androidx.compose.ui.unit.dp
38
37
import com.neoutils.neoregex.core.designsystem.textfield.NeoTextField
39
38
import com.neoutils.neoregex.core.designsystem.theme.NeoTheme.dimensions
40
39
41
- @OptIn(ExperimentalMaterial3Api ::class )
42
40
@Composable
43
41
fun PatternNameDialog (
44
42
onDismissRequest : () -> Unit ,
45
43
onConfirm : (String ) -> Unit ,
46
44
modifier : Modifier = Modifier ,
47
- name : MutableState <String > = remember { mutableStateOf("") },
48
- hint : @Composable () -> Unit = {
49
- Text (
50
- text = "Pattern name",
51
- style = LocalTextStyle .current.let {
52
- it.copy(
53
- color = it.color.copy(
54
- alpha = 0.5f
55
- )
56
- )
57
- },
58
- overflow = TextOverflow .Ellipsis ,
59
- maxLines = 1
60
- )
61
- },
62
- title : @Composable () -> Unit = {
63
- Text (
64
- text = "Save pattern",
65
- color = colorScheme.onSurfaceVariant,
66
- style = typography.titleSmall.copy(
67
- fontFamily = null,
68
- )
69
- )
70
- },
71
- cancelLabel : @Composable () -> Unit = {
72
- Text (text = "Cancel ")
73
- },
74
- confirmLabel : @Composable () -> Unit = {
75
- Text (text = "Save ")
76
- }
77
- ) = BasicAlertDialog (
45
+ name : MutableState <String > = remember { mutableStateOf("") },
46
+ title : @Composable () -> Unit ,
47
+ confirmLabel : @Composable () -> Unit
48
+ ) = NeoRegexDialog (
78
49
onDismissRequest = onDismissRequest,
50
+ title = title,
51
+ confirmLabel = confirmLabel,
52
+ onConfirm = {
53
+ onConfirm(name.value)
54
+ },
55
+ enableConfirm = name.value.isNotBlank(),
79
56
modifier = modifier
80
57
) {
81
- Surface (
82
- color = colorScheme.background,
83
- contentColor = colorScheme.onBackground,
84
- border = BorderStroke (width = 1 .dp, colorScheme.outline)
85
- ) {
86
- Column {
87
- Box (
88
- modifier = Modifier
89
- .background(colorScheme.surfaceVariant)
90
- .padding(horizontal = 16 .dp)
91
- .fillMaxWidth()
92
- .height(40 .dp),
93
- contentAlignment = Alignment .Center
94
- ) {
95
- title()
96
- }
97
-
98
- HorizontalDivider (color = colorScheme.outlineVariant)
99
-
100
- Column (
101
- modifier = Modifier .padding(16 .dp),
102
- horizontalAlignment = Alignment .CenterHorizontally
103
- ) {
104
-
105
- var focused by remember { mutableStateOf(false ) }
58
+ var focused by remember { mutableStateOf(false ) }
106
59
107
- val focusRequester = remember { FocusRequester () }
60
+ val focusRequester = remember { FocusRequester () }
108
61
109
- LaunchedEffect (Unit ) { focusRequester.requestFocus() }
62
+ LaunchedEffect (Unit ) { focusRequester.requestFocus() }
110
63
111
- NeoTextField (
112
- hint = hint,
113
- value = name.value,
114
- onValueChange = { name.value = it },
115
- keyboardActions = KeyboardActions (
116
- onDone = {
117
- onConfirm(name.value)
118
- onDismissRequest()
119
- }
120
- ),
121
- singleLine = true ,
122
- textStyle = typography.bodyMedium.copy(
123
- color = colorScheme.onBackground
124
- ),
125
- contentPadding = PaddingValues (dimensions.wide),
126
- modifier = Modifier
127
- .fillMaxWidth()
128
- .focusRequester(focusRequester)
129
- .onFocusChanged { focused = it.isFocused }
130
- .border(
131
- width = 1 .dp,
132
- color = colorScheme.outline.copy(
133
- alpha = if (focused) 1f else 0.5f
134
- ),
135
- shape = RoundedCornerShape (4 .dp)
136
- )
137
- )
138
-
139
- Spacer (Modifier .height(16 .dp))
140
-
141
- Row (
142
- modifier = Modifier .fillMaxWidth(),
143
- horizontalArrangement = Arrangement .SpaceAround
144
- ) {
145
- OutlinedButton (
146
- onClick = {
147
- onDismissRequest()
148
- },
149
- shape = RoundedCornerShape (8 .dp),
150
- colors = ButtonDefaults .outlinedButtonColors(
151
- contentColor = colorScheme.onBackground
152
- )
153
- ) {
154
- cancelLabel()
155
- }
156
-
157
- OutlinedButton (
158
- onClick = {
159
- onConfirm(name.value)
160
- onDismissRequest()
161
- },
162
- enabled = name.value.isNotBlank(),
163
- shape = RoundedCornerShape (8 .dp),
164
- colors = ButtonDefaults .outlinedButtonColors(
165
- contentColor = colorScheme.onBackground
166
- )
167
- ) {
168
- confirmLabel()
169
- }
170
- }
64
+ NeoTextField (
65
+ value = name.value,
66
+ onValueChange = { name.value = it },
67
+ keyboardActions = KeyboardActions (
68
+ onDone = {
69
+ onConfirm(name.value)
70
+ onDismissRequest()
171
71
}
72
+ ),
73
+ singleLine = true ,
74
+ textStyle = typography.bodyMedium.copy(
75
+ color = colorScheme.onBackground
76
+ ),
77
+ contentPadding = PaddingValues (dimensions.wide),
78
+ modifier = Modifier
79
+ .fillMaxWidth()
80
+ .focusRequester(focusRequester)
81
+ .onFocusChanged { focused = it.isFocused }
82
+ .border(
83
+ width = 1 .dp,
84
+ color = colorScheme.outline.copy(
85
+ alpha = if (focused) 1f else 0.5f
86
+ ),
87
+ shape = RoundedCornerShape (4 .dp)
88
+ ),
89
+ hint = {
90
+ Text (
91
+ text = " Pattern name" ,
92
+ style = LocalTextStyle .current.let {
93
+ it.copy(
94
+ color = it.color.copy(
95
+ alpha = 0.5f
96
+ )
97
+ )
98
+ },
99
+ overflow = TextOverflow .Ellipsis ,
100
+ maxLines = 1
101
+ )
172
102
}
173
- }
103
+ )
174
104
}
0 commit comments