Skip to content

Commit 70ad47f

Browse files
committed
Added a new component+documentation.
1 parent fee2ca9 commit 70ad47f

File tree

3 files changed

+175
-23
lines changed

3 files changed

+175
-23
lines changed

DOCUMENTATION.md

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<details>
88
<summary>Date Picker</summary>
99

10-
# MUIDatePicker
10+
## `MUIDatePicker`
1111

1212
The `MUIDatePicker` SwiftUI component provides a Material Design-style date picker with customizable appearance and behavior.
1313

@@ -47,7 +47,7 @@ The date picker includes a formatted representation of the selected date. The `f
4747
<details>
4848
<summary>Time Picker</summary>
4949

50-
# MUITimePicker
50+
## `MUITimePicker`
5151

5252
The `MUITimePicker` SwiftUI component provides a Material Design-style time picker with customizable appearance and behavior.
5353

@@ -84,7 +84,7 @@ This example demonstrates how to use the `MUITimePicker` in a SwiftUI view. The
8484
<details>
8585
<summary> TextField </summary>
8686

87-
# MUITextField
87+
## `MUITextField`
8888

8989
The `MUITextField` SwiftUI component provides a Material Design-style text field with customizable appearance and behavior.
9090

@@ -137,7 +137,7 @@ struct ContentView: View {
137137
<details>
138138
<summary> SecureField </summary>
139139

140-
# MUISecureField
140+
## `MUISecureField`
141141

142142
The `MUISecureField` SwiftUI component provides a Material Design-style secure field with customizable appearance and behavior.
143143

@@ -191,7 +191,7 @@ struct ContentView: View {
191191
<details>
192192
<summary> Button </summary>
193193

194-
# MUIButton
194+
## `MUIButton`
195195

196196
The `MUIButton` SwiftUI component provides a versatile button with various styles to suit different design needs.
197197

@@ -235,7 +235,7 @@ MUIButton("Title", style: .elevated, action: {
235235
<details>
236236
<summary> Card </summary>
237237

238-
# MUICardView
238+
## `MUICardView`
239239

240240
The `MUICardView` SwiftUI component represents a MaterialUI style card.
241241

@@ -300,7 +300,7 @@ MUICardView(
300300
<details>
301301
<summary> Checkbox </summary>
302302

303-
# MUICheckbox
303+
## `MUICheckbox`
304304

305305
`MUICheckbox` provides a checkbox with a clean and modern MaterialUI design. It allows users to toggle between the checked and unchecked states by tapping the checkbox.
306306

@@ -327,7 +327,7 @@ MUICheckbox("Enable Feature", isOn: $isChecked)
327327
<details>
328328
<summary> Floating Button </summary>
329329

330-
# MUIFloatingButton
330+
## `MUIFloatingButton`
331331

332332
A SwiftUI button designed for floating action button (FAB) functionality with various initialization options. MUIIconButton provides the flexibility to create circular icon buttons with different styles, allowing you to choose from elevated, filled, tonal, or secondary background styles.
333333

@@ -357,7 +357,7 @@ MUIFloatingButton(image: "customIcon", title: "Custom") {
357357
<details>
358358
<summary> Icon Button </summary>
359359

360-
# MUIIconButton
360+
## `MUIIconButton`
361361

362362
`MUIIconButton` provides the flexibility to create circular icon buttons with different styles, allowing you to choose from elevated, filled, tonal, or secondary background styles.
363363

@@ -390,7 +390,7 @@ MUIIconButton("customImage", style: .filled) {
390390
<details>
391391
<summary> Switch </summary>
392392

393-
# MUISwitch
393+
## `MUISwitch`
394394

395395
`MUISwitch` is a SwiftUI view representing a MaterialUI style switch.it provides a custom-styled switch with a MaterialUI design, offering a unique appearance for toggling between states.
396396

@@ -418,8 +418,7 @@ MUISwitch("Enable Feature", isOn: $isEnabled)
418418
<details>
419419
<summary> Alerts </summary>
420420

421-
422-
# MUIAlert
421+
## `MUIAlert`
423422

424423
`MUIAlert` provides a convenient way to present a MaterialUI style alert over the current view.
425424

@@ -473,10 +472,53 @@ struct ContentView: View {
473472

474473
</details>
475474

475+
<details>
476+
<summary> Dialog Sheet </summary>
477+
478+
## `MUIDialogSheet`
479+
480+
`MUIAlert` provides a convenient way to present a MaterialUI style dialog sheet over the current view.
481+
482+
`.mUIDialogSheet()` is an extension to the `View` protocol in SwiftUI, offering a modifier that can be applied to any view. This modifier presents a MaterialUI style dialog sheet.
483+
484+
## Usage
485+
486+
To use `MUIDialogSheet`, apply the `mUIDialogSheet` modifier to a SwiftUI view and provide the necessary parameters:
487+
488+
## Parameters
489+
490+
- `isPresented: Binding<Bool>`: Binding to control the presentation state of the dialog sheet.
491+
- `content: View`: A view content to be displayed in the dialog sheet.
492+
493+
## Example
494+
495+
```swift
496+
struct ContentView: View {
497+
@State private var showDialogSheet = false
498+
499+
var body: some View {
500+
VStack {
501+
Button("Show Alert") {
502+
showDialogSheet.toggle()
503+
}
504+
}
505+
506+
// MUIDialogSheet
507+
.mUIDialogSheet(isPresented: $showDialogSheet) {
508+
Text("Dialog sheet content")
509+
}
510+
}
511+
}
512+
}
513+
```
514+
515+
</details>
516+
517+
476518
<details>
477519
<summary> Snackbar </summary>
478520

479-
# MUISnackbar
521+
## `MUISnackbar`
480522
`MUISnackbar` provides a customizable MaterialUI style snackbar that can be displayed at the bottom of the screen.
481523

482524
`.mUISnackbar()` is an extension to the `View` protocol in SwiftUI, offering a modifier that can be applied to any view. This modifier presents a MaterialUI style snackbar with customizable parameters such as message, duration, and an optional primary action button.
@@ -526,7 +568,7 @@ struct ContentView: View {
526568
<details>
527569
<summary> List </summary>
528570

529-
# MUIList
571+
## `MUIList`
530572
`MUIList` is a SwiftUI view that provides a MaterialUI-styled list with various visual styles. The `MUIList` view is designed to display a collection of elements with different visual styles such as plain, inset, or insetGrouped.
531573

532574
## Usage
@@ -558,7 +600,7 @@ struct ContentView: View {
558600
<details>
559601
<summary> Navigation View </summary>
560602

561-
# MUINavigationView
603+
## `MUINavigationView`
562604

563605
`MUINavigationView` is a custom navigation view that provides a MaterialUI-styled navigation bar.
564606

@@ -610,7 +652,7 @@ MUINavigationLink(destination: {
610652
})
611653
```
612654

613-
## MUINavigationHeaderStyle
655+
## `MUINavigationHeaderStyle`
614656

615657
`MUINavigationHeaderStyle` is an enumeration representing different styles for navigation bar headers.
616658

@@ -622,7 +664,7 @@ MUINavigationLink(destination: {
622664
<details>
623665
<summary> Tab View</summary>
624666

625-
# MUITabView
667+
## `MUITabView`
626668

627669
The `MUITabView` SwiftUI component combines main content with a MaterialUI-style tab bar for easy navigation.
628670

@@ -655,7 +697,7 @@ MUITabBarView(selection: $selection) {
655697
<details>
656698
<summary> Segmented Control </summary>
657699

658-
# MUISegmentedControl
700+
## `MUISegmentedControl`
659701

660702
The `MUISegmentedControl` SwiftUI component provides a segmented control with customizable appearance and behavior.
661703

@@ -699,7 +741,7 @@ struct ContentView: View {
699741
<details>
700742
<summary> Divider </summary>
701743

702-
# MUIDivider
744+
## `MUIDivider`
703745

704746
The `MUIDivider` SwiftUI component represents a MaterialUI-style divider with customizable orientation.
705747

@@ -738,7 +780,7 @@ struct ContentView: View {
738780
<details>
739781
<summary> Progress View </summary>
740782

741-
# MUIProgressView
783+
## `MUIProgressView`
742784

743785
The `MUIProgressView` SwiftUI component represents a MaterialUI-style progress view with customizable line width.
744786

@@ -777,7 +819,7 @@ struct ContentView: View {
777819
<details>
778820
<summary> SearchBar </summary>
779821

780-
# MUISearchBar
822+
## `MUISearchBar`
781823

782824
The `MUISearchBar` SwiftUI component represents a MaterialUI-style search bar with a customizable placeholder and search text binding.
783825

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ MaterialUIKit is a SwiftUI package offering a set of user interface components i
3232
### Date Picker
3333
![DatePicker](https://github.com/aumChauhan/MaterialUIKit/assets/83302656/ce23247f-4fa4-4c75-9841-8c062902adbc)
3434

35+
### Dialog Sheet
36+
![Dialog Sheet](https://github.com/aumChauhan/MaterialUIKit/assets/83302656/9d65a7ff-1afc-4d55-bd30-d30491525020)
37+
3538
### Floating Button
3639
![FAB](https://github.com/aumChauhan/MaterialUIKit/assets/83302656/fca45946-4c95-4d65-b834-054763e456ba)
3740

@@ -75,7 +78,7 @@ MaterialUIKit is a SwiftUI package offering a set of user interface components i
7578
To integrate MaterialUIKit into your project, you can use `CocoaPods` or `Swift Package Manager`.
7679

7780
<details>
78-
<summary> CocoaPods </summary>
81+
<summary> <strong> CocoaPods </strong> </summary>
7982
8083
Add the following line to your Podfile:
8184

@@ -88,7 +91,7 @@ Then run `pod install` to install the framework.
8891
</details>
8992

9093
<details>
91-
<summary> Swift Package Manager </summary>
94+
<summary> <strong> Swift Package Manager </strong> </summary>
9295

9396
In Xcode, go to File -> Swift Packages -> Add Package Dependency and enter the repository URL:
9497

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//
2+
// MUIDialogSheet.swift
3+
// MaterialUIKit: https://github.com/aumChauhan/MaterialUIKit.git
4+
//
5+
// Author: Aum Chauhan
6+
// Created On: 24/01/24
7+
//
8+
9+
import SwiftUI
10+
11+
// MARK: - Extension View
12+
13+
@available(iOS 15.0, *)
14+
extension View {
15+
16+
/// Presents a MaterialUI style dialog sheet over the current view.
17+
///
18+
/// - Parameters:
19+
/// - isPresented: Binding to control the presentation state of the dialog sheet.
20+
/// - content: A view content to be displayed in the dialog sheet.
21+
public func mUIDialogSheet<Content: View>(isPresented: Binding<Bool>, _ content: () -> Content) -> some View {
22+
self.modifier(
23+
MUIDialogSheetModifer(isPresented: isPresented, dialogSheetContent: AnyView(content()))
24+
)
25+
}
26+
}
27+
28+
// MARK: - MUIDialogSheetModifer
29+
30+
/// A view modifier that adds the MaterialUI style dialog sheet behavior to any view.
31+
@available(iOS 15.0, *)
32+
private struct MUIDialogSheetModifer: ViewModifier {
33+
34+
// MARK: - Properties
35+
36+
@Binding public var isPresented: Bool
37+
public let dialogSheetContent: AnyView
38+
39+
// MARK: - Body
40+
41+
func body(content: Content) -> some View {
42+
content.overlay(
43+
MUIDialogSheetView(isPresented: $isPresented, content: dialogSheetContent)
44+
)
45+
}
46+
}
47+
48+
// MARK: - MUIDialogSheetView
49+
50+
/// A custom Material UI style dialog sheet that can be presented over other views.
51+
@available(iOS 15.0, *)
52+
private struct MUIDialogSheetView: View {
53+
54+
// MARK: - Properties
55+
56+
@Binding public var isPresented: Bool
57+
@State private var animationFlag: Bool = false
58+
59+
public let content: any View
60+
61+
// MARK: Initializers
62+
63+
public init(isPresented: Binding<Bool>, content: any View) {
64+
self._isPresented = isPresented
65+
self.content = content
66+
}
67+
68+
// MARK: - View Body
69+
70+
var body: some View {
71+
ZStack {
72+
// Backgorund
73+
Color.gray.opacity(0.0)
74+
.frame(maxWidth: .infinity, maxHeight: .infinity)
75+
.edgesIgnoringSafeArea(.all)
76+
77+
VStack(alignment: .leading, spacing: 10) {
78+
// Sheet dismiss button
79+
HStack {
80+
Button {
81+
isPresented.toggle()
82+
} label: {
83+
Image(systemName: "xmark")
84+
.foregroundColor(MaterialUI.tint.secondaryTitle())
85+
}
86+
87+
Spacer()
88+
}
89+
90+
AnyView(content)
91+
}
92+
.frame(width: UIScreen.main.bounds.width/1.3)
93+
.padding(20)
94+
.background(MaterialUI.tint.iconColor())
95+
.cornerRadius(25)
96+
.shadow(color: .black.opacity(0.1), radius: 10, x: 0, y: 1)
97+
}
98+
// In-Out animation
99+
.scaleEffect(animationFlag ? 1 : 0)
100+
.opacity(animationFlag ? 1 : 0)
101+
.onChangeWithFallback(of: isPresented) { oldValue, newValue in
102+
withAnimation(.bouncy) {
103+
animationFlag = isPresented
104+
}
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)