### SwiftUI Select Component Examples Source: https://context7.com/sunghyun-k/legendui-swift/llms.txt Demonstrates the usage of the LegendUI Select component in SwiftUI, illustrating different styles like Radio, Card, Dropdown, and Segmented. It covers basic selection, adding descriptions, handling placeholders, and disabling options. This example requires the LegendUI framework. ```swift import SwiftUI import LegendUI struct SelectExample: View { enum Fruit: String, CaseIterable { case apple = "Apple" case banana = "Banana" case orange = "Orange" } @State private var radioSelection: Fruit = .apple @State private var cardSelection: Fruit = .apple @State private var dropdownSelection: Fruit = .apple @State private var segmentedSelection: Fruit = .apple var body: some View { ScrollView { VStack(alignment: .leading, spacing: 32) { // Radio style (default) VStack(alignment: .leading, spacing: 8) { Text("Radio Style").font(.headline) Select( selection: $radioSelection, items: [ SelectItem("Apple", value: .apple), SelectItem("Banana", value: .banana), SelectItem("Orange", value: .orange) ] ) } // Card style with descriptions VStack(alignment: .leading, spacing: 8) { Text("Card Style").font(.headline) Select( selection: $cardSelection, items: [ SelectItem( "Apple", description: "A sweet red fruit", value: .apple ), SelectItem( "Banana", description: "A yellow tropical fruit", value: .banana ) ], style: .card ) } // Dropdown style VStack(alignment: .leading, spacing: 8) { Text("Dropdown Style").font(.headline) Select( selection: $dropdownSelection, items: Fruit.allCases.map { SelectItem($0.rawValue, value: $0) }, style: .dropdown(placeholder: "Choose a fruit") ) } // Segmented style (horizontal) VStack(alignment: .leading, spacing: 8) { Text("Segmented Style").font(.headline) Select( selection: $segmentedSelection, items: Fruit.allCases.map { SelectItem($0.rawValue, value: $0) }, axis: .horizontal, style: .segmented ) } // With disabled option Select( selection: $radioSelection, items: [ SelectItem("Available", value: .apple), SelectItem("Disabled", value: .banana, isDisabled: true) ] ) } .padding() } } } ``` -------------------------------- ### Install LegendUI via Swift Package Manager Source: https://github.com/sunghyun-k/legendui-swift/blob/main/README.md Instructions for adding the LegendUI library to your Xcode project or Package.swift file. This is the standard method for integrating Swift packages. ```bash https://github.com/sunghyun-k/legendui-swift ``` ```swift dependencies: [ .package(url: "https://github.com/sunghyun-k/legendui-swift", from: "0.1.0") ] ``` -------------------------------- ### SwiftUI Chip Component Example Source: https://context7.com/sunghyun-k/legendui-swift/llms.txt Illustrates the use of the LegendUI Chip component for displaying tags, filters, and selections. It covers basic chip configurations, interactive chips with close buttons, avatar support, different sizes, custom content, and various corner radius styles. The component is built using SwiftUI. ```swift import SwiftUI import LegendUI struct ChipExample: View { @State private var selectedTags: Set = [] var body: some View { VStack(spacing: 16) { // Basic chips HStack(spacing: 8) { Chip("SwiftUI", variant: .solid, color: .primary) Chip("iOS 17", variant: .bordered, color: .secondary) Chip("Beta", variant: .dot, color: .warning) } // Interactive chip with close button Chip( "Removable Tag", variant: .flat, color: .success, onTap: { print("Tapped") }, onClose: { print("Removed") } ) // Chip with avatar Chip( "John Doe", avatarSystemImage: "person.fill", variant: .solid, color: .primary ) // Different sizes HStack(spacing: 8) { Chip("Small", size: .sm) Chip("Medium", size: .md) Chip("Large", size: .lg) } // Custom content chip Chip(variant: .bordered, color: .warning) { Text("Custom") } startContent: { Image(systemName: "star.fill") } endContent: { Text("!") } // Different corner radius styles HStack(spacing: 8) { Chip("Sharp", radius: .none) Chip("Rounded", radius: .md) Chip("Pill", radius: .full) } } .padding() } } ``` -------------------------------- ### SwiftUI Button Component Example Source: https://context7.com/sunghyun-k/legendui-swift/llms.txt Demonstrates the usage of the customizable Button component from LegendUI. It showcases various variants, sizes, icon-only buttons, buttons with labels, and custom styling options. This component uses SwiftUI's ButtonStyle protocol for integration. ```swift import SwiftUI import LegendUI struct ButtonExample: View { @State private var isLoading = false var body: some View { VStack(spacing: 16) { // Basic button with primary variant Button("Sign In") { print("Tapped!") } .buttonStyle(.legend(variant: .primary)) // Button with different variants Button("Secondary Action") {} .buttonStyle(.legend(variant: .secondary)) Button("Delete") {} .buttonStyle(.legend(variant: .danger, size: .sm)) // Icon-only button Button { // Action } label: { Image(systemName: "heart.fill") } .buttonStyle(.legend( variant: .secondary, size: .md, isIconOnly: true )) // Button with icon and text Button { // Action } label: { Label("Download", systemImage: "arrow.down.circle") } .buttonStyle(.legend(variant: .primary, size: .lg)) // Custom variant button let customVariant = ButtonVariant( foregroundColor: .white, backgroundColor: .purple, pressedBackgroundColor: .purple.opacity(0.8), disabledForegroundColor: .gray, disabledBackgroundColor: .gray.opacity(0.3) ) Button("Custom Style") {} .buttonStyle(.legend(customVariant: customVariant)) } .padding() } } ``` -------------------------------- ### Display a Toast Notification with LegendUI Source: https://github.com/sunghyun-k/legendui-swift/blob/main/README.md Example demonstrating how to use the LegendUI library to display a toast notification. It shows the necessary imports and how to manage toast states and display them. ```swift import SwiftUI import LegendUI struct ContentView: View { @State private var toasts: [ToastValue] = [] var body: some View { VStack(spacing: 16) { Button("Show Toast") { toasts.append( ToastValue( title: "Success", message: "Operation completed", type: .success ) ) } .buttonStyle(.legend(variant: .primary)) } .toasts($toasts) } } ``` -------------------------------- ### SwiftUI Surface Component Examples Source: https://context7.com/sunghyun-k/legendui-swift/llms.txt Demonstrates various ways to use the surface styling modifiers in LegendUI Swift. It showcases direct ShapeStyle usage and the .surfaceStyle() modifier with different configurations for padding and corner radius. This snippet is intended for SwiftUI developers using the LegendUI framework. ```swift import SwiftUI import LegendUI struct SurfaceExample: View { var body: some View { ScrollView { VStack(spacing: 16) { // Using ShapeStyles RoundedRectangle(cornerRadius: 16) .fill(.surface) .frame(height: 100) .overlay { Text("Primary Surface") .foregroundStyle(.surfaceForeground) } RoundedRectangle(cornerRadius: 16) .fill(.surfaceSecondary) .frame(height: 100) .overlay { Text("Secondary Surface") .foregroundStyle(.surfaceForeground) } // Using surface modifier Text("Default Surface Card") .surfaceStyle() Text("Secondary Surface") .surfaceStyle(.secondary) Text("Tertiary Surface") .surfaceStyle(.tertiary) // Custom padding and corner radius VStack(alignment: .leading, spacing: 8) { Text("Card Title") .font(.headline) Text("This card has custom padding and corner radius") .foregroundStyle(.secondary) } .surfaceStyle(.default, padding: 24, cornerRadius: 16) // Nested surfaces VStack(spacing: 12) { Text("Outer Container") .font(.headline) VStack(spacing: 8) { Text("Nested Card") .font(.subheadline) Text("Uses secondary surface") .font(.caption) } .surfaceStyle(.secondary, padding: 16) } .surfaceStyle(.default, padding: 20) // Transparent surface Text("Transparent") .surfaceStyle(.transparent, padding: 16) .border(Color.gray.opacity(0.3)) } .padding() } } } ``` -------------------------------- ### SwiftUI Skeleton Placeholder with Animations Source: https://context7.com/sunghyun-k/legendui-swift/llms.txt Demonstrates how to use the Legend UI Skeleton modifier in SwiftUI to create loading placeholders. It supports custom animations like shimmer and pulse, and can be applied to various view elements. The example shows how to toggle the loading state and apply the modifier to different UI components such as cards, lists, and simple shapes. ```swift import SwiftUI import LegendUI struct SkeletonExample: View { @State private var isLoading = true @State private var userData: UserData? // Note: UserData is not used in the provided snippet but is part of the original context. var body: some View { VStack(spacing: 24) { // Card skeleton VStack(alignment: .leading, spacing: 12) { HStack(spacing: 12) { Circle() .fill(Color.gray.opacity(0.2)) .frame(width: 48, height: 48) .skeleton(isLoading: isLoading) VStack(alignment: .leading, spacing: 8) { RoundedRectangle(cornerRadius: 4) .fill(Color.gray.opacity(0.2)) .frame(width: 120, height: 14) .skeleton(isLoading: isLoading) RoundedRectangle(cornerRadius: 4) .fill(Color.gray.opacity(0.2)) .frame(width: 80, height: 12) .skeleton(isLoading: isLoading) } } RoundedRectangle(cornerRadius: 8) .fill(Color.gray.opacity(0.2)) .frame(height: 160) .skeleton(isLoading: isLoading) } .padding() // List skeleton VStack(spacing: 16) { ForEach(0..<3, id: \.self) { HStack(spacing: 12) { RoundedRectangle(cornerRadius: 8) .fill(Color.gray.opacity(0.2)) .frame(width: 48, height: 48) .skeleton(isLoading: isLoading) VStack(alignment: .leading, spacing: 8) { RoundedRectangle(cornerRadius: 4) .fill(Color.gray.opacity(0.2)) .frame(height: 14) .skeleton(isLoading: isLoading) RoundedRectangle(cornerRadius: 4) .fill(Color.gray.opacity(0.2)) .frame(width: 150, height: 12) .skeleton(isLoading: isLoading) } } } } .padding() // Pulse animation RoundedRectangle(cornerRadius: 8) .fill(Color.gray.opacity(0.2)) .frame(height: 60) .skeleton( isLoading: isLoading, animation: .pulse(duration: 1.5) ) .padding() // Toggle loading state Button(isLoading ? "Stop Loading" : "Start Loading") { isLoading.toggle() } .buttonStyle(.legend(variant: .primary)) } } } struct UserData { let name: String let avatar: String } ``` -------------------------------- ### LegendUI Theming System (SwiftUI) Source: https://context7.com/sunghyun-k/legendui-swift/llms.txt Explains LegendUI's theming system for global UI customization of colors, layout, and typography, including automatic light/dark mode adaptation and applying custom themes. Requires importing SwiftUI and LegendUI. ```swift import SwiftUI import LegendUI struct ThemeExample: View { var body: some View { // Using default theme (automatic) ContentView() // Or apply custom theme ContentView() .legendTheme(customTheme) } // Create custom theme private var customTheme: LegendTheme { LegendTheme( colors: .default, // Use default colors layout: .default, // Use default layout typography: .default // Use default typography ) } } // Access theme in components struct CustomComponent: View { @Environment(\.legendTheme) private var theme var body: some View { Text("Themed Text") .foregroundStyle(theme.colors.surface.foreground) .padding(theme.layout.spacing.medium) .background(theme.colors.surface.primary) .cornerRadius(theme.layout.radius.large) } } ``` -------------------------------- ### Apply Custom Theme with LegendUI Source: https://github.com/sunghyun-k/legendui-swift/blob/main/README.md Illustrates how to apply a custom theme to components using the LegendUI library's theming modifier. It shows both default theme usage and custom theme application. ```swift // Use default theme (automatic) ContentView() // Or apply custom theme ContentView() .legendTheme(customTheme) ``` -------------------------------- ### SwiftUI Dialog Implementation with Legend UI Source: https://context7.com/sunghyun-k/legendui-swift/llms.txt Demonstrates how to use Legend UI's dialog components in a SwiftUI view. This snippet shows the creation of both confirmation and form dialogs, including state management for user inputs and dialog visibility. It utilizes custom buttons and input elements provided by the Legend UI framework. ```swift import SwiftUI import LegendUI struct DialogExample: View { @State private var showConfirm = false @State private var showForm = false @State private var email = "" @State private var agreeToTerms = false @Environment(\.dismissDialog) private var dismissDialog var body: some View { VStack(spacing: 16) { Button("Show Confirmation") { showConfirm = true } .buttonStyle(.legend(variant: .primary)) Button("Show Form Dialog") { showForm = true } .buttonStyle(.legend(variant: .secondary)) } .padding() .dialog(isPresented: $showConfirm) { DialogContent { DialogHeader( title: "Confirm Action", showCloseButton: true ) DialogBody { Text("Are you sure you want to proceed? This cannot be undone.") } DialogFooter { DialogCloseButton("Cancel", variant: .ghost) Button("Confirm") { // Handle confirmation showConfirm = false } .buttonStyle(.legend( variant: .primary, size: .sm, isFullWidth: false )) } } } .dialog( isPresented: $showForm, isDismissable: false, hasBackgroundBlur: true ) { DialogContent { DialogHeader( title: "Subscribe", showCloseButton: true ) DialogBody { VStack(alignment: .leading, spacing: 16) { Text("Enter your email to subscribe.") TextInput( "Email", text: $email, prompt: "your@email.com", size: .sm ) Toggle("I agree to terms", isOn: $agreeToTerms) .toggleStyle(.legendCheckbox(size: .sm)) } } DialogFooter { DialogCloseButton("Cancel") Button("Subscribe") { showForm = false } .buttonStyle(.legend( variant: .primary, size: .sm, isFullWidth: false )) .disabled(!agreeToTerms || email.isEmpty) } } } } } ``` -------------------------------- ### Custom Toggle Styles with LegendUI (SwiftUI) Source: https://context7.com/sunghyun-k/legendui-swift/llms.txt Demonstrates how to apply custom checkbox and switch styles using LegendUI's toggle modifiers. Supports various sizes, invalid states, and disabled states. Requires importing SwiftUI and LegendUI. ```swift import SwiftUI import LegendUI struct ToggleExample: View { @State private var acceptTerms = false @State private var enableNotifications = true @State private var newsletter = false @State private var darkMode = false @State private var airplaneMode = false @State private var invalidOption = false var body: some View { VStack(alignment: .leading, spacing: 24) { // Checkbox styles VStack(alignment: .leading, spacing: 16) { Text("Checkboxes").font(.headline) Toggle("Accept terms and conditions", isOn: $acceptTerms) .toggleStyle(.legendCheckbox) Toggle("Subscribe to newsletter", isOn: $newsletter) .toggleStyle(.legendCheckbox(size: .sm)) Toggle("Enable notifications", isOn: $enableNotifications) .toggleStyle(.legendCheckbox(size: .lg)) Toggle("Invalid option", isOn: $invalidOption) .toggleStyle(.legendCheckbox(isInvalid: true)) Toggle("Disabled", isOn: .constant(false)) .toggleStyle(.legendCheckbox) .disabled(true) } Separator() // Switch styles VStack(alignment: .leading, spacing: 16) { Text("Switches").font(.headline) Toggle("Dark Mode", isOn: $darkMode) .toggleStyle(.legendSwitch) Toggle("Airplane Mode", isOn: $airplaneMode) .toggleStyle(.legendSwitch(size: .sm)) Toggle("Wi-Fi", isOn: .constant(true)) .toggleStyle(.legendSwitch(size: .lg)) Toggle("Invalid setting", isOn: .constant(true)) .toggleStyle(.legendSwitch(isInvalid: true)) Toggle("Disabled", isOn: .constant(false)) .toggleStyle(.legendSwitch) .disabled(true) } Separator() // Without labels HStack(spacing: 24) { VStack(spacing: 12) { Text("Checkbox").font(.caption) Toggle(isOn: .constant(true)) { EmptyView() } .toggleStyle(.legendCheckbox) } VStack(spacing: 12) { Text("Switch").font(.caption) Toggle(isOn: .constant(true)) { EmptyView() } .toggleStyle(.legendSwitch) } } } .padding() } } ``` -------------------------------- ### SwiftUI Toast Notification Implementation Source: https://context7.com/sunghyun-k/legendui-swift/llms.txt Demonstrates how to implement a stackable toast notification system using SwiftUI and LegendUI. It showcases how to manage an array of `ToastValue` objects to display different types of toasts (success, warning, danger, default) with options for duration, icons, and close buttons. The toasts can be displayed at the top or bottom of the screen. ```swift import SwiftUI import LegendUI struct ToastExample: View { @State private var toasts: [ToastValue] = [] var body: some View { VStack(spacing: 16) { Button("Show Success") { toasts.append(ToastValue( title: "Success", message: "Your changes have been saved", type: .success, duration: 3.0 )) } .buttonStyle(.legend(variant: .primary)) Button("Show Warning") { toasts.append(ToastValue( title: "Warning", message: "Your storage is almost full", type: .warning )) } .buttonStyle(.legend(variant: .secondary)) Button("Show Error") { toasts.append(ToastValue( title: "Connection Lost", message: "Unable to reach the server", type: .danger, icon: "wifi.slash" )) } .buttonStyle(.legend(variant: .danger)) // Persistent toast (no auto-dismiss) Button("Show Persistent") { toasts.append(ToastValue( title: "Important", message: "This won't auto-dismiss", type: .default, duration: nil, showCloseButton: true )) } .buttonStyle(.legend(variant: .ghost)) Button("Clear All") { toasts.removeAll() } .buttonStyle(.legend(variant: .tertiary, size: .sm)) Text("Active: \(toasts.count)") .font(.caption) } .padding() // Display toasts at top of screen .toasts($toasts, alignment: .top) // Or at bottom // .toasts($toasts, alignment: .bottom) } } ``` -------------------------------- ### Implement Spinner in SwiftUI Source: https://context7.com/sunghyun-k/legendui-swift/llms.txt The Spinner component displays a loading indicator. It supports customization of size, color, and can be conditionally shown or integrated into buttons. Its primary use is to provide visual feedback during asynchronous operations. ```swift import SwiftUI import LegendUI struct SpinnerExample: View { @State private var isLoading = false var body: some View { VStack(spacing: 32) { // Basic spinner Spinner() // Different sizes HStack(spacing: 24) { Spinner(size: .sm) Spinner(size: .md) Spinner(size: .lg) } // Different colors HStack(spacing: 24) { Spinner(color: .default) Spinner(color: .success) Spinner(color: .warning) Spinner(color: .danger) } // Custom color Spinner(color: .custom(.purple)) // Conditional spinner Spinner(isLoading: isLoading) // In a button Button { isLoading = true // Simulate async work DispatchQueue.main.asyncAfter(deadline: .now() + 2) { isLoading = false } } label: { HStack { if isLoading { Spinner(size: .sm, color: .custom(.white)) } Text(isLoading ? "Loading..." : "Submit") } } .buttonStyle(.legend(variant: .primary)) // Loading state overlay VStack(spacing: 16) { Spinner(size: .lg, color: .success) Text("Loading your content...") .foregroundStyle(.secondary) } .frame(maxWidth: .infinity) .padding(40) .background(Color.gray.opacity(0.05)) .cornerRadius(16) } .padding() } } ``` -------------------------------- ### SwiftUI TextInput Component with Validation and Features Source: https://context7.com/sunghyun-k/legendui-swift/llms.txt Demonstrates the usage of the LegendUI TextInput component in SwiftUI. It showcases various configurations including basic input, email validation, secure password entry with visibility toggle, multiline bio input, search functionality with clear button, and different size variations. This snippet requires the SwiftUI and LegendUI frameworks. ```swift import SwiftUI import LegendUI struct TextInputExample: View { @State private var username = "" @State private var email = "" @State private var password = "" @State private var isSecure = true @State private var bio = "" @State private var searchQuery = "" var isEmailValid: Bool { email.contains("@") && email.contains(".") } var body: some View { ScrollView { VStack(spacing: 24) { // Basic input TextInput( "Username", text: $username, prompt: "Enter your username", isRequired: true ) // Input with validation TextInput( "Email", text: $email, prompt: "your@email.com", description: "We'll never share your email", errorMessage: "Please enter a valid email address", isRequired: true, isInvalid: !email.isEmpty && !isEmailValid ) // Password input with toggle visibility TextInput( text: $password, prompt: "Enter password", isRequired: true, isSecure: isSecure ) { Text("Password") } startContent: { Image(systemName: "lock.fill") .font(.system(size: 14)) } endContent: { Button { isSecure.toggle() } label: { Image(systemName: isSecure ? "eye.slash.fill" : "eye.fill") .font(.system(size: 14)) } } // Multiline text input TextInput( "Bio", text: $bio, prompt: "Tell us about yourself...", description: "Maximum 500 characters", errorMessage: "Bio is too long", isMultiline: true, isInvalid: bio.count > 500 ) // Search input with icon TextInput( text: $searchQuery, prompt: "Search...", size: .sm ) { Text("Search") } startContent: { Image(systemName: "magnifyingglass") .font(.system(size: 14)) } endContent: { if !searchQuery.isEmpty { Button { searchQuery = "" } label: { Image(systemName: "xmark.circle.fill") .font(.system(size: 14)) } } } // Different sizes VStack(spacing: 16) { TextInput("Small", text: .constant(""), size: .sm) TextInput("Medium", text: .constant(""), size: .md) TextInput("Large", text: .constant(""), size: .lg) } } .padding() } } } ``` -------------------------------- ### Implement Separator in SwiftUI Source: https://context7.com/sunghyun-k/legendui-swift/llms.txt The Separator component acts as a visual divider between content sections. It can be configured for horizontal or vertical orientation, thickness, and color, allowing for flexible layout designs. It is useful for structuring UI elements. ```swift import SwiftUI import LegendUI struct SeparatorExample: View { var body: some View { VStack(spacing: 32) { // Basic horizontal separator VStack(spacing: 8) { Text("Section 1") Separator() Text("Section 2") } // Thick separator VStack(spacing: 8) { Text("Above") Separator(variant: .thick) Text("Below") } // Vertical separator HStack { Text("Left") Separator(orientation: .vertical) .frame(height: 40) Text("Right") } // Custom thickness and color VStack(spacing: 12) { Text("Custom Separators") Separator(thickness: 2, color: .blue) Separator(thickness: 3, color: .green) Separator(thickness: 5, color: .red) } // In navigation-like layout VStack(spacing: 0) { HStack { Text("Components") Separator(orientation: .vertical) .frame(height: 20) .padding(.horizontal, 12) Text("Themes") Separator(orientation: .vertical) .frame(height: 20) .padding(.horizontal, 12) Text("Examples") } .padding() Separator() Text("Content area") .frame(maxWidth: .infinity) .padding() } .background(Color.gray.opacity(0.1)) .cornerRadius(12) } .padding() } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.