Skip to content

Commit

Permalink
Merge pull request #603 from iruizmar/auth_ui_experimental_annotation
Browse files Browse the repository at this point in the history
Add AuthUiExperimental annotation
  • Loading branch information
jan-tennert authored May 20, 2024
2 parents 10957f9 + 6209ecd commit f57f9cc
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.saveable.mapSaver
import androidx.compose.runtime.saveable.rememberSaveable
import io.github.jan.supabase.annotations.SupabaseExperimental
import io.github.jan.supabase.annotations.SupabaseInternal
import io.github.jan.supabase.compose.auth.ui.annotations.AuthUiExperimental

/**
* Represents the state of auth forms.
*/
@SupabaseExperimental
@AuthUiExperimental
class AuthState(
states: Map<String, Boolean> = emptyMap()
) {
Expand Down Expand Up @@ -65,6 +65,7 @@ class AuthState(
/**
* Local composition for [AuthState]. Use [AuthForm] for automatic saving and restoring.
*/
@AuthUiExperimental
val LocalAuthState = compositionLocalOf {
AuthState() //possibly to throw an error here
}
Expand All @@ -74,6 +75,7 @@ val LocalAuthState = compositionLocalOf {
* @param state The [AuthState] to provide.
* @param content The content to provide the [AuthState] to.
*/
@AuthUiExperimental
@Composable
fun AuthForm(
state: AuthState = rememberSaveable(saver = AuthState.SAVER) { AuthState() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import io.github.jan.supabase.annotations.SupabaseExperimental
import io.github.jan.supabase.compose.auth.ui.annotations.AuthUiExperimental

/**
* A component that represents a form field.
Expand All @@ -14,7 +14,7 @@ import io.github.jan.supabase.annotations.SupabaseExperimental
* @param mandatory Whether the form field is mandatory or not. If false, will not affect the [AuthState.validForm] value. Default is true.
* @param content The composable function that defines the content of the form field and receives a mutable state object as a parameter.
*/
@SupabaseExperimental
@AuthUiExperimental
@Composable
fun FormComponent(key: String, mandatory: Boolean = true, content: @Composable (valid: MutableState<Boolean>) -> Unit) {
val state = LocalAuthState.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp
import io.github.jan.supabase.annotations.SupabaseExperimental
import io.github.jan.supabase.compose.auth.ui.annotations.AuthUiExperimental
import io.github.jan.supabase.gotrue.providers.OAuthProvider

internal val DEFAULT_ICON_SIZE = 24.dp //from Material3
Expand All @@ -23,7 +23,7 @@ internal val DEFAULT_ICON_SIZE = 24.dp //from Material3
* @param contentDescription The content description for the icon.
* @param modifier The modifier to be applied to the icon. Note that the size of the icon is not fixed.
*/
@SupabaseExperimental
@AuthUiExperimental
@Composable
fun ProviderIcon(provider: OAuthProvider, contentDescription: String?, modifier: Modifier = Modifier) {
providerPainter(provider, LocalDensity.current)?.let {
Expand All @@ -42,7 +42,7 @@ fun ProviderIcon(provider: OAuthProvider, contentDescription: String?, modifier:
* @param provider The OAuth provider to authenticate with.
* @param text The text to display in the button. Default value is "Login in with" followed by the capitalized provider name.
*/
@SupabaseExperimental
@AuthUiExperimental
@Composable
fun RowScope.ProviderButtonContent(provider: OAuthProvider, text: String = "Login with ${provider.name.capitalize()}") {
ProviderIcon(provider, "Login with ${provider.name}", Modifier.size(DEFAULT_ICON_SIZE))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.github.jan.supabase.compose.auth.ui.annotations

/**
* Used to mark experimental Compose Auth Ui APIs
*/
@RequiresOptIn(level = RequiresOptIn.Level.ERROR, message = "This API is experimental and may not be stable yet")
annotation class AuthUiExperimental
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.TextFieldValue
import io.github.jan.supabase.annotations.SupabaseExperimental
import io.github.jan.supabase.compose.auth.ui.AuthIcons
import io.github.jan.supabase.compose.auth.ui.FormComponent
import io.github.jan.supabase.compose.auth.ui.FormValidator
import io.github.jan.supabase.compose.auth.ui.annotations.AuthUiExperimental
import io.github.jan.supabase.compose.auth.ui.rememberMailIcon

/**
Expand All @@ -50,7 +50,7 @@ import io.github.jan.supabase.compose.auth.ui.rememberMailIcon
* @param mandatory Whether the form field is mandatory or not. If false, will not affect the [AuthState.validForm] value. You can also make this value dynamic and only make the field mandatory, if e.g. the [value] is not empty. Default is true.
*/
@ExperimentalMaterial3Api
@SupabaseExperimental
@AuthUiExperimental
@Composable
fun EmailField(
value: String,
Expand Down Expand Up @@ -130,7 +130,7 @@ fun EmailField(
* @param formKey The key to store the validity of the email field in the AuthState. Defaults to "EMAIL".
* @param mandatory Whether the form field is mandatory or not. If false, will not affect the [AuthState.validForm] value. You can also make this value dynamic and only make the field mandatory, if e.g. the [value] is not empty. Default is true.
*/
@SupabaseExperimental
@AuthUiExperimental
@ExperimentalMaterial3Api
@Composable
fun EmailField(
Expand Down Expand Up @@ -211,7 +211,7 @@ fun EmailField(
* @param formKey The key to store the validity of the email field in the AuthState. Defaults to "EMAIL".
* @param mandatory Whether the form field is mandatory or not. If false, will not affect the [AuthState.validForm] value. You can also make this value dynamic and only make the field mandatory, if e.g. the [value] is not empty. Default is true.
*/
@SupabaseExperimental
@AuthUiExperimental
@ExperimentalMaterial3Api
@Composable
fun OutlinedEmailField(
Expand Down Expand Up @@ -292,7 +292,7 @@ fun OutlinedEmailField(
* @param formKey The key to store the validity of the email field in the AuthState. Defaults to "EMAIL".
* @param mandatory Whether the form field is mandatory or not. If false, will not affect the [AuthState.validForm] value. You can also make this value dynamic and only make the field mandatory, if e.g. the [value] is not empty. Default is true.
*/
@SupabaseExperimental
@AuthUiExperimental
@ExperimentalMaterial3Api
@Composable
fun OutlinedEmailField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.VisualTransformation
import io.github.jan.supabase.annotations.SupabaseExperimental
import io.github.jan.supabase.compose.auth.ui.AuthIcons
import io.github.jan.supabase.compose.auth.ui.FormComponent
import io.github.jan.supabase.compose.auth.ui.annotations.AuthUiExperimental
import io.github.jan.supabase.compose.auth.ui.rememberLockIcon
import io.github.jan.supabase.compose.auth.ui.rememberVisibilityIcon
import io.github.jan.supabase.compose.auth.ui.rememberVisibilityOffIcon
Expand Down Expand Up @@ -55,7 +55,7 @@ import io.github.jan.supabase.compose.auth.ui.rememberVisibilityOffIcon
* @param formKey The key to store the validity of the password field in the AuthState. Defaults to "EMAIL".
* @param mandatory Whether the form field is mandatory or not. If false, will not affect the [AuthState.validForm] value. You can also make this value dynamic and only make the field mandatory, if e.g. the [value] is not empty. Default is true.
*/
@SupabaseExperimental
@AuthUiExperimental
@ExperimentalMaterial3Api
@Composable
fun PasswordField(
Expand Down Expand Up @@ -141,7 +141,7 @@ fun PasswordField(
* @param formKey The key to store the validity of the password field in the AuthState. Defaults to "EMAIL".
* @param mandatory Whether the form field is mandatory or not. If false, will not affect the [AuthState.validForm] value. You can also make this value dynamic and only make the field mandatory, if e.g. the [value] is not empty. Default is true.
*/
@SupabaseExperimental
@AuthUiExperimental
@ExperimentalMaterial3Api
@Composable
fun PasswordField(
Expand Down Expand Up @@ -228,7 +228,7 @@ fun PasswordField(
* @param formKey The key to store the validity of the password field in the AuthState. Defaults to "EMAIL".
* @param mandatory Whether the form field is mandatory or not. If false, will not affect the [AuthState.validForm] value. You can also make this value dynamic and only make the field mandatory, if e.g. the [value] is not empty. Default is true.
*/
@SupabaseExperimental
@AuthUiExperimental
@ExperimentalMaterial3Api
@Composable
fun OutlinedPasswordField(
Expand Down Expand Up @@ -314,7 +314,7 @@ fun OutlinedPasswordField(
* @param formKey The key to store the validity of the password field in the AuthState. Defaults to "EMAIL".
* @param mandatory Whether the form field is mandatory or not. If false, will not affect the [AuthState.validForm] value. You can also make this value dynamic and only make the field mandatory, if e.g. the [value] is not empty. Default is true.
*/
@SupabaseExperimental
@AuthUiExperimental
@ExperimentalMaterial3Api
@Composable
fun OutlinedPasswordField(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.VisualTransformation
import io.github.jan.supabase.annotations.SupabaseExperimental
import io.github.jan.supabase.compose.auth.ui.AuthIcons
import io.github.jan.supabase.compose.auth.ui.FormComponent
import io.github.jan.supabase.compose.auth.ui.FormValidator
import io.github.jan.supabase.compose.auth.ui.annotations.AuthUiExperimental
import io.github.jan.supabase.compose.auth.ui.rememberCallIcon

private const val DEFAULT_MASK = "+## ### #########"
Expand Down Expand Up @@ -54,7 +54,7 @@ private const val DEFAULT_MASK_CHAR = '#'
* @param formKey The key to store the validity of the phone field in the AuthState. Defaults to "EMAIL".
* @param mandatory Whether the form field is mandatory or not. If false, will not affect the [AuthState.validForm] value. You can also make this value dynamic and only make the field mandatory, if e.g. the [value] is not empty. Default is true.
*/
@SupabaseExperimental
@AuthUiExperimental
@Composable
fun PhoneField(
value: String,
Expand Down Expand Up @@ -143,7 +143,7 @@ fun PhoneField(
* @param formKey The key to store the validity of the phone field in the AuthState. Defaults to "EMAIL".
* @param mandatory Whether the form field is mandatory or not. If false, will not affect the [AuthState.validForm] value. You can also make this value dynamic and only make the field mandatory, if e.g. the [value] is not empty. Default is true.
*/
@SupabaseExperimental
@AuthUiExperimental
@Composable
fun PhoneField(
value: TextFieldValue,
Expand Down Expand Up @@ -232,7 +232,7 @@ fun PhoneField(
* @param formKey The key to store the validity of the phone field in the AuthState. Defaults to "EMAIL".
* @param mandatory Whether the form field is mandatory or not. If false, will not affect the [AuthState.validForm] value. You can also make this value dynamic and only make the field mandatory, if e.g. the [value] is not empty. Default is true.
*/
@SupabaseExperimental
@AuthUiExperimental
@Composable
fun OutlinedPhoneField(
value: TextFieldValue,
Expand Down Expand Up @@ -321,7 +321,7 @@ fun OutlinedPhoneField(
* @param formKey The key to store the validity of the phone field in the AuthState. Defaults to "EMAIL".
* @param mandatory Whether the form field is mandatory or not. If false, will not affect the [AuthState.validForm] value. You can also make this value dynamic and only make the field mandatory, if e.g. the [value] is not empty. Default is true.
*/
@SupabaseExperimental
@AuthUiExperimental
@Composable
fun OutlinedPhoneField(
value: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.input.OffsetMapping
import androidx.compose.ui.text.input.TransformedText
import androidx.compose.ui.text.input.VisualTransformation
import io.github.jan.supabase.annotations.SupabaseExperimental
import io.github.jan.supabase.compose.auth.ui.annotations.AuthUiExperimental

/**
* Represents a phone number visual transformation.
Expand All @@ -14,7 +14,7 @@ import io.github.jan.supabase.annotations.SupabaseExperimental
* @param maskNumber The character used in the mask to represent a digit.
*
*/
@SupabaseExperimental
@AuthUiExperimental
class PhoneVisualTransformation(val mask: String, val maskNumber: Char) : VisualTransformation {

private val maxLength = mask.count { it == maskNumber }
Expand Down

0 comments on commit f57f9cc

Please sign in to comment.