Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add text inputs and page layouts

Neeraj Gupta15bc8feefb4e
diff --git a/android/packages/components/src/main/kotlin/io/ente/components/IllustratedPage.kt b/android/packages/components/src/main/kotlin/io/ente/components/IllustratedPage.kt
new file mode 100644
index 0000000000..dc6bde95b7
--- /dev/null
+++ b/android/packages/components/src/main/kotlin/io/ente/components/IllustratedPage.kt
@@ -0,0 +1,80 @@
+package io.ente.components
+
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.BoxWithConstraints
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.heightIn
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.widthIn
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.material3.LocalContentColor
+import androidx.compose.material3.ProvideTextStyle
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.semantics.clearAndSetSemantics
+import androidx.compose.ui.semantics.heading
+import androidx.compose.ui.semantics.semantics
+import androidx.compose.ui.text.style.TextAlign
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+
+@Composable
+public fun IllustratedPage(
+ title: String,
+ message: String,
+ modifier: Modifier = Modifier,
+ illustration: @Composable () -> Unit,
+ actions: @Composable () -> Unit,
+ footer: @Composable () -> Unit,
+) {
+ val palette = LocalEntePalette.current
+ BoxWithConstraints(modifier.fillMaxSize(), contentAlignment = Alignment.TopCenter) {
+ val viewportHeight = maxHeight
+ Column(
+ Modifier.widthIn(max = 480.dp)
+ .fillMaxWidth()
+ .verticalScroll(rememberScrollState())
+ .heightIn(min = viewportHeight)
+ .padding(EnteSpacing.lg),
+ horizontalAlignment = Alignment.CenterHorizontally,
+ verticalArrangement = Arrangement.spacedBy(24.dp, Alignment.CenterVertically),
+ ) {
+ CompositionLocalProvider(LocalContentColor provides palette.text) {
+ Box(
+ Modifier.height(minOf(220.dp, viewportHeight * 0.28f)).clearAndSetSemantics {},
+ contentAlignment = Alignment.Center,
+ ) {
+ illustration()
+ }
+ }
+ Text(
+ title,
+ style = pageTitleStyle,
+ color = palette.text,
+ textAlign = TextAlign.Center,
+ modifier = Modifier.semantics { heading() },
+ )
+ Text(
+ message,
+ style = EnteTypography.body,
+ color = palette.mutedText,
+ textAlign = TextAlign.Center,
+ modifier = Modifier.padding(horizontal = EnteSpacing.lg),
+ )
+ actions()
+ CompositionLocalProvider(LocalContentColor provides palette.mutedText) {
+ ProvideTextStyle(EnteTypography.mini) { footer() }
+ }
+ }
+ }
+}
+
+private val pageTitleStyle = EnteTypography.display2.copy(fontSize = 32.sp, lineHeight = 40.sp)
diff --git a/android/packages/components/src/main/kotlin/io/ente/components/InputField.kt b/android/packages/components/src/main/kotlin/io/ente/components/InputField.kt
new file mode 100644
index 0000000000..0cff7b98c1
--- /dev/null
+++ b/android/packages/components/src/main/kotlin/io/ente/components/InputField.kt
@@ -0,0 +1,138 @@
+package io.ente.components
+
+import androidx.compose.foundation.background
+import androidx.compose.foundation.border
+import androidx.compose.foundation.interaction.MutableInteractionSource
+import androidx.compose.foundation.interaction.collectIsFocusedAsState
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.heightIn
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.foundation.text.BasicTextField
+import androidx.compose.foundation.text.KeyboardActions
+import androidx.compose.foundation.text.KeyboardOptions
+import androidx.compose.material3.LocalContentColor
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.remember
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.graphics.SolidColor
+import androidx.compose.ui.semantics.contentDescription
+import androidx.compose.ui.semantics.error
+import androidx.compose.ui.semantics.semantics
+import androidx.compose.ui.text.input.VisualTransformation
+import androidx.compose.ui.unit.dp
+
+@Composable
+public fun InputField(
+ value: String,
+ onValueChange: (String) -> Unit,
+ modifier: Modifier = Modifier,
+ label: String? = null,
+ required: Boolean = false,
+ placeholder: String? = null,
+ message: String? = null,
+ state: InputState = InputState.Normal,
+ enabled: Boolean = true,
+ readOnly: Boolean = false,
+ singleLine: Boolean = true,
+ minLines: Int = 1,
+ maxLines: Int = Int.MAX_VALUE,
+ keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
+ keyboardActions: KeyboardActions = KeyboardActions.Default,
+ visualTransformation: VisualTransformation = VisualTransformation.None,
+ interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
+ leading: (@Composable () -> Unit)? = null,
+ trailing: (@Composable () -> Unit)? = null,
+) {
+ val palette = LocalEntePalette.current
+ val focused by interactionSource.collectIsFocusedAsState()
+ val statusColor =
+ when (state) {
+ InputState.Normal -> palette.mutedText
+ InputState.Error -> palette.danger
+ InputState.Success -> palette.primary
+ }
+ val border =
+ when {
+ state != InputState.Normal -> statusColor
+ focused -> palette.hintText
+ else -> palette.faintBorder
+ }
+ val textColor = if (enabled) palette.text else palette.disabledText
+ val hintColor = if (enabled) palette.hintText else palette.disabledText
+ val shape = RoundedCornerShape(EnteRadius.large)
+ Column(modifier, verticalArrangement = Arrangement.spacedBy(EnteSpacing.sm)) {
+ if (label != null) {
+ Row(horizontalArrangement = Arrangement.spacedBy(2.dp)) {
+ Text(label, style = EnteTypography.body, color = textColor)
+ if (required) {
+ Text("*", style = EnteTypography.bodyBold, color = palette.danger)
+ }
+ }
+ }
+ BasicTextField(
+ value = value,
+ onValueChange = onValueChange,
+ modifier =
+ Modifier.fillMaxWidth().semantics(mergeDescendants = true) {
+ (label ?: placeholder)?.let { contentDescription = it }
+ if (state == InputState.Error && message != null) error(message)
+ },
+ enabled = enabled,
+ readOnly = readOnly,
+ singleLine = singleLine,
+ minLines = minLines,
+ maxLines = maxLines,
+ keyboardOptions = keyboardOptions,
+ keyboardActions = keyboardActions,
+ visualTransformation = visualTransformation,
+ textStyle = EnteTypography.body.copy(color = textColor),
+ cursorBrush = SolidColor(palette.primary),
+ interactionSource = interactionSource,
+ decorationBox = { innerTextField ->
+ CompositionLocalProvider(LocalContentColor provides hintColor) {
+ Row(
+ modifier =
+ Modifier.fillMaxWidth()
+ .heightIn(min = 52.dp)
+ .clip(shape)
+ .background(if (enabled) palette.surface else palette.fill)
+ .border(1.dp, border, shape)
+ .padding(EnteSpacing.lg),
+ verticalAlignment =
+ if (singleLine) Alignment.CenterVertically else Alignment.Top,
+ ) {
+ leading?.let {
+ it()
+ Spacer(Modifier.width(EnteSpacing.sm))
+ }
+ Box(Modifier.weight(1f)) {
+ if (value.isEmpty() && placeholder != null) {
+ Text(placeholder, style = EnteTypography.body, color = hintColor)
+ }
+ innerTextField()
+ }
+ trailing?.let {
+ Spacer(Modifier.width(EnteSpacing.sm))
+ it()
+ }
+ }
+ }
+ },
+ )
+ if (message != null) {
+ Text(message, style = EnteTypography.mini, color = statusColor)
+ }
+ }
+}
diff --git a/android/packages/components/src/main/kotlin/io/ente/components/InputState.kt b/android/packages/components/src/main/kotlin/io/ente/components/InputState.kt
new file mode 100644
index 0000000000..793e3b126a
--- /dev/null
+++ b/android/packages/components/src/main/kotlin/io/ente/components/InputState.kt
@@ -0,0 +1,7 @@
+package io.ente.components
+
+public enum class InputState {
+ Normal,
+ Error,
+ Success,
+}
diff --git a/android/packages/components/src/main/kotlin/io/ente/components/settings/SettingsFooter.kt b/android/packages/components/src/main/kotlin/io/ente/components/settings/SettingsFooter.kt
new file mode 100644
index 0000000000..7d3f8ba0cc
--- /dev/null
+++ b/android/packages/components/src/main/kotlin/io/ente/components/settings/SettingsFooter.kt
@@ -0,0 +1,35 @@
+package io.ente.components.settings
+
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.text.style.TextAlign
+import io.ente.components.EnteSpacing
+import io.ente.components.EnteTypography
+import io.ente.components.LocalEntePalette
+
+@Composable
+public fun SettingsFooter(
+ version: String,
+ modifier: Modifier = Modifier,
+ links: @Composable () -> Unit,
+) {
+ Column(
+ modifier.fillMaxWidth().padding(vertical = EnteSpacing.xl),
+ horizontalAlignment = Alignment.CenterHorizontally,
+ verticalArrangement = Arrangement.spacedBy(EnteSpacing.lg),
+ ) {
+ links()
+ Text(
+ version,
+ style = EnteTypography.mini,
+ color = LocalEntePalette.current.mutedText,
+ textAlign = TextAlign.Center,
+ )
+ }
+}
diff --git a/android/packages/components/src/main/kotlin/io/ente/components/settings/SettingsSection.kt b/android/packages/components/src/main/kotlin/io/ente/components/settings/SettingsSection.kt
new file mode 100644
index 0000000000..67171a1059
--- /dev/null
+++ b/android/packages/components/src/main/kotlin/io/ente/components/settings/SettingsSection.kt
@@ -0,0 +1,44 @@
+package io.ente.components.settings
+
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.ColumnScope
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.semantics.heading
+import androidx.compose.ui.semantics.semantics
+import io.ente.components.EnteSpacing
+import io.ente.components.EnteTypography
+import io.ente.components.LocalEntePalette
+
+@Composable
+public fun SettingsSection(
+ modifier: Modifier = Modifier,
+ title: String? = null,
+ footer: String? = null,
+ content: @Composable ColumnScope.() -> Unit,
+) {
+ val palette = LocalEntePalette.current
+ Column(modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(EnteSpacing.sm)) {
+ if (title != null) {
+ Text(
+ title,
+ style = EnteTypography.heading2,
+ color = palette.text,
+ modifier = Modifier.padding(vertical = EnteSpacing.sm).semantics { heading() },
+ )
+ }
+ content()
+ if (footer != null) {
+ Text(
+ footer,
+ style = EnteTypography.mini,
+ color = palette.mutedText,
+ modifier = Modifier.padding(EnteSpacing.sm),
+ )
+ }
+ }
+}
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/IllustratedPage.swift b/apple/packages/EnteComponents/Sources/EnteComponents/IllustratedPage.swift
new file mode 100644
index 0000000000..0ebe746cb3
--- /dev/null
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/IllustratedPage.swift
@@ -0,0 +1,55 @@
+import EnteFonts
+import SwiftUI
+
+public struct IllustratedPage<Illustration: View, Actions: View, Footer: View>: View {
+ @Environment(\.entePalette) private var palette
+ private let title: String
+ private let message: String
+ private let illustration: Illustration
+ private let actions: Actions
+ private let footer: Footer
+
+ public init(
+ _ title: String,
+ message: String,
+ @ViewBuilder illustration: () -> Illustration,
+ @ViewBuilder actions: () -> Actions,
+ @ViewBuilder footer: () -> Footer,
+ ) {
+ self.title = title
+ self.message = message
+ self.illustration = illustration()
+ self.actions = actions()
+ self.footer = footer()
+ }
+
+ public var body: some View {
+ GeometryReader { geometry in
+ ScrollView {
+ VStack(spacing: 24) {
+ illustration
+ .frame(height: min(220, geometry.size.height * 0.28))
+ .accessibilityHidden(true)
+ Text(title)
+ .font(EnteFont.outfit(size: 32, relativeTo: .largeTitle))
+ .multilineTextAlignment(.center)
+ .fixedSize(horizontal: false, vertical: true)
+ .accessibilityAddTraits(.isHeader)
+ Text(message)
+ .font(EnteTypography.body)
+ .foregroundStyle(palette.mutedText)
+ .multilineTextAlignment(.center)
+ .fixedSize(horizontal: false, vertical: true)
+ .padding(.horizontal, EnteSpacing.lg)
+ actions
+ footer.font(EnteTypography.mini).foregroundStyle(palette.mutedText)
+ }
+ .padding(EnteSpacing.lg)
+ .frame(maxWidth: 480)
+ .frame(minHeight: geometry.size.height)
+ .frame(maxWidth: .infinity)
+ }
+ }
+ .foregroundStyle(palette.text)
+ }
+}
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/InputField.swift b/apple/packages/EnteComponents/Sources/EnteComponents/InputField.swift
new file mode 100644
index 0000000000..56bb5808b6
--- /dev/null
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/InputField.swift
@@ -0,0 +1,96 @@
+import SwiftUI
+
+public struct InputField: View {
+ @Binding private var text: String
+ @FocusState private var focused: Bool
+ @Environment(\.entePalette) private var palette
+ @Environment(\.isEnabled) private var enabled
+ private let label: String?
+ private let required: Bool
+ private let placeholder: String
+ private let message: String?
+ private let state: InputState
+ private let secure: Bool
+ private let lines: ClosedRange<Int>
+
+ public init(
+ text: Binding<String>,
+ label: String? = nil,
+ required: Bool = false,
+ placeholder: String = "",
+ message: String? = nil,
+ state: InputState = .normal,
+ secure: Bool = false,
+ lines: ClosedRange<Int> = 1...1,
+ ) {
+ _text = text
+ self.label = label
+ self.required = required
+ self.placeholder = placeholder
+ self.message = message
+ self.state = state
+ self.secure = secure
+ self.lines = lines
+ }
+
+ public var body: some View {
+ let prompt = Text(placeholder)
+ .foregroundColor(enabled ? palette.hintText : palette.disabledText)
+ let shape = RoundedRectangle(cornerRadius: EnteRadius.large, style: .continuous)
+ VStack(alignment: .leading, spacing: EnteSpacing.sm) {
+ if let label {
+ HStack(spacing: 2) {
+ Text(label).foregroundStyle(enabled ? palette.text : palette.disabledText)
+ if required {
+ Text("*").font(EnteTypography.bodyBold).foregroundStyle(palette.danger)
+ }
+ }
+ .font(EnteTypography.body)
+ }
+ Group {
+ if secure {
+ SecureField(label ?? placeholder, text: $text, prompt: prompt)
+ } else {
+ TextField(
+ label ?? placeholder, text: $text, prompt: prompt,
+ axis: lines.upperBound == 1 ? .horizontal : .vertical
+ )
+ .lineLimit(lines)
+ }
+ }
+ .textFieldStyle(.plain)
+ .accessibilityLabel(label ?? placeholder)
+ .focused($focused)
+ .font(EnteTypography.body)
+ .foregroundStyle(enabled ? palette.text : palette.disabledText)
+ .tint(palette.primary)
+ .padding(EnteSpacing.lg)
+ .frame(minHeight: 52)
+ .background {
+ shape.fill(enabled ? palette.surface : palette.fill)
+ .onTapGesture { focused = true }
+ }
+ .overlay { shape.strokeBorder(borderColor, lineWidth: 1) }
+ if let message {
+ Text(message)
+ .font(EnteTypography.mini)
+ .foregroundStyle(statusColor)
+ }
+ }
+ }
+
+ private var borderColor: Color {
+ if state != .normal {
+ return statusColor
+ }
+ return focused ? palette.hintText : palette.faintBorder
+ }
+
+ private var statusColor: Color {
+ switch state {
+ case .normal: palette.mutedText
+ case .error: palette.danger
+ case .success: palette.primary
+ }
+ }
+}
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/InputState.swift b/apple/packages/EnteComponents/Sources/EnteComponents/InputState.swift
new file mode 100644
index 0000000000..dd53cfec82
--- /dev/null
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/InputState.swift
@@ -0,0 +1,5 @@
+public enum InputState {
+ case normal
+ case error
+ case success
+}
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/Settings/SettingsFooter.swift b/apple/packages/EnteComponents/Sources/EnteComponents/Settings/SettingsFooter.swift
new file mode 100644
index 0000000000..7499161905
--- /dev/null
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/Settings/SettingsFooter.swift
@@ -0,0 +1,24 @@
+import SwiftUI
+
+public struct SettingsFooter<Links: View>: View {
+ @Environment(\.entePalette) private var palette
+ private let version: String
+ private let links: Links
+
+ public init(version: String, @ViewBuilder links: () -> Links) {
+ self.version = version
+ self.links = links()
+ }
+
+ public var body: some View {
+ VStack(spacing: EnteSpacing.lg) {
+ links
+ Text(version)
+ .font(EnteTypography.mini)
+ .foregroundStyle(palette.mutedText)
+ .multilineTextAlignment(.center)
+ }
+ .frame(maxWidth: .infinity)
+ .padding(.vertical, EnteSpacing.xl)
+ }
+}
diff --git a/apple/packages/EnteComponents/Sources/EnteComponents/Settings/SettingsSection.swift b/apple/packages/EnteComponents/Sources/EnteComponents/Settings/SettingsSection.swift
new file mode 100644
index 0000000000..e874bc98e9
--- /dev/null
+++ b/apple/packages/EnteComponents/Sources/EnteComponents/Settings/SettingsSection.swift
@@ -0,0 +1,38 @@
+import SwiftUI
+
+public struct SettingsSection<Content: View>: View {
+ @Environment(\.entePalette) private var palette
+ private let title: String?
+ private let footer: String?
+ private let content: Content
+
+ public init(
+ _ title: String? = nil,
+ footer: String? = nil,
+ @ViewBuilder content: () -> Content,
+ ) {
+ self.title = title
+ self.footer = footer
+ self.content = content()
+ }
+
+ public var body: some View {
+ VStack(alignment: .leading, spacing: EnteSpacing.sm) {
+ if let title {
+ Text(title)
+ .font(EnteTypography.heading2)
+ .foregroundStyle(palette.text)
+ .padding(.vertical, EnteSpacing.sm)
+ .accessibilityAddTraits(.isHeader)
+ }
+ content
+ if let footer {
+ Text(footer)
+ .font(EnteTypography.mini)
+ .foregroundStyle(palette.mutedText)
+ .padding(EnteSpacing.sm)
+ }
+ }
+ .frame(maxWidth: .infinity, alignment: .leading)
+ }
+}