Skip to content

Commit ecfa78b

Browse files
committed
First release
First release sirio-kit-iOS
1 parent c5abb7c commit ecfa78b

File tree

3,112 files changed

+45936
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,112 files changed

+45936
-1
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/
6+
DerivedData/
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2022, INPS
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Package.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// swift-tools-version:5.6
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "SirioKitIOS",
8+
platforms: [.iOS(.v15)],
9+
products: [
10+
// Products define the executables and libraries a package produces, and make them visible to other packages.
11+
.library(
12+
name: "SirioKitIOS",
13+
targets: ["SirioKitIOS"]),
14+
],
15+
dependencies: [
16+
// Dependencies declare other packages that this package depends on.
17+
// .package(url: /* package url */, from: "1.0.0"),
18+
],
19+
targets: [
20+
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
21+
// Targets can depend on other targets in this package, and on products in packages this package depends on.
22+
.target(
23+
name: "SirioKitIOS",
24+
dependencies: [],
25+
resources: [.process("Fonts"), .process("Resources")]
26+
),
27+
.testTarget(
28+
name: "SirioKitIOSTests",
29+
dependencies: ["SirioKitIOS"]),
30+
]
31+
)

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
1-
# sirio-kit-iOS
1+
# Sirio-kit-iOS
2+
3+
Sirio-kit-iOS is a library containing the iOS implementation of Sirio design system to be used for INPS mobile apps UI.
4+
5+
## Requirements
6+
7+
- iOS 15.0+
8+
- Xcode 14+
9+
- Swift 4+
10+
11+
12+
## Usage
13+
1. Add the following to your Package.swift:
14+
```swift
15+
.package(url: "https://github.com/INPS-it/sirio-kit-iOS", .upToNextMajor(from: "4.0.0"))
16+
```
17+
2. Declare `import SirioKitIOS` to use the components where you want use it.
18+
19+
3. Register the font provided by the library in the app scene. (This example can be found in the demo project.)
20+
21+
```swift
22+
@main
23+
struct iOS_ExampleApp: App {
24+
25+
init() {
26+
// Register fonts from library
27+
Fonts.registerFonts()
28+
}
29+
}
30+
```
31+
4. Use components as in the example app.
32+
33+
## License
34+
35+
SirioKitIOS is released under the BSD 3-Clause License [See LICENSE](https://github.com/INPS-it/SirioKitIOS/blob/main/LICENSE) for details.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// AccordionData.swift
3+
//
4+
// SPDX-FileCopyrightText: 2022 Istituto Nazionale Previdenza Sociale
5+
//
6+
// SPDX-License-Identifier: BSD-3-Clause
7+
//
8+
9+
import SwiftUI
10+
import UIKit
11+
12+
/// A representation of an accordion
13+
/// - Parameters:
14+
/// - data: The structure of the component
15+
/// - content: The content inside accordion
16+
/// - isDisabled: Whether the accordion is disabled
17+
/// - isOpen: Whether the accordion is open
18+
/// - onTapAccordion: Callback that is executed when the accordion is tapped
19+
public class AccordionData: Identifiable, ObservableObject {
20+
21+
public var id = UUID()
22+
private(set) var text: String
23+
private(set) var content: AnyView
24+
@Published public var isDisabled: Bool
25+
@Published public var isOpen: Bool
26+
private(set) var onTapAccordion: ((Bool) -> Void)?
27+
28+
public init<Content>(text: String,
29+
@ViewBuilder content: @escaping () -> Content,
30+
isDisabled: Bool = false,
31+
isOpen: Bool = false,
32+
onTapAccordion: ((Bool) -> Void)? = nil) where Content: View {
33+
self.text = text
34+
self.content = AnyView(content())
35+
self.isDisabled = isDisabled
36+
self.isOpen = isOpen
37+
self.onTapAccordion = onTapAccordion
38+
}
39+
40+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//
2+
// AccordionStyle.swift
3+
//
4+
// SPDX-FileCopyrightText: 2022 Istituto Nazionale Previdenza Sociale
5+
//
6+
// SPDX-License-Identifier: BSD-3-Clause
7+
//
8+
9+
import SwiftUI
10+
11+
// A struct to manage the Accordion style
12+
struct AccordionStyle: ButtonStyle {
13+
@Environment(\.colorScheme) var colorScheme
14+
var text: String
15+
var isOpen: Bool
16+
@Binding var isDisabled: Bool
17+
var withBorder: Bool = true
18+
@State var isHover = false
19+
20+
func makeBody(configuration: Self.Configuration) -> some View {
21+
VStack {
22+
HStack {
23+
SirioText(text: text, typography: Typography.Accordion.style)
24+
.foregroundColor(textColor)
25+
.lineLimit(1)
26+
27+
Spacer()
28+
29+
SirioIcon(icon: isOpen ? .angleUp : .angleDown)
30+
.frame(width: Size.Accordion.Icon.frame,
31+
height: Size.Accordion.Icon.frame)
32+
.foregroundColor(iconColor)
33+
}
34+
.frame(height: Size.Accordion.sectionHeight)
35+
.padding(.horizontal, Size.Accordion.paddingHorizontal)
36+
.border(borderColor, width: Size.Accordion.borderWidth)
37+
}
38+
.background(backgroundColor)
39+
.onHover { isHover in
40+
self.isHover = isHover
41+
}
42+
}
43+
44+
private var borderColor: Color {
45+
if withBorder {
46+
return colorScheme == .dark ? Color.Accordion.Border.dark : Color.Accordion.Border.light
47+
}
48+
return Color.clear
49+
}
50+
51+
private var backgroundColor: Color {
52+
let hoverColor: Color = colorScheme == .dark ? Color.Accordion.Background.Hover.dark : Color.Accordion.Background.Hover.light
53+
let defaultColor: Color = colorScheme == .dark ? Color.Accordion.Background.Default.dark : Color.Accordion.Background.Default.light
54+
let activeColor: Color = colorScheme == .dark ? Color.Accordion.Background.Active.dark : Color.Accordion.Background.Active.light
55+
56+
if isDisabled {
57+
return Color.Accordion.Background.disabled
58+
} else if isOpen {
59+
return isHover ? hoverColor : activeColor
60+
} else {
61+
return isHover ? hoverColor : defaultColor
62+
}
63+
}
64+
65+
private var textColor: Color {
66+
if isDisabled {
67+
return Color.Accordion.Text.disabled
68+
} else {
69+
return colorScheme == .dark ? Color.Accordion.Text.dark : Color.Accordion.Text.light
70+
}
71+
72+
}
73+
74+
private var iconColor: Color {
75+
if isDisabled {
76+
return Color.Accordion.Icon.disabled
77+
} else {
78+
return colorScheme == .dark ? Color.Accordion.Icon.dark : Color.Accordion.Icon.light
79+
}
80+
}
81+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// Accordion.swift
3+
//
4+
// SPDX-FileCopyrightText: 2022 Istituto Nazionale Previdenza Sociale
5+
//
6+
// SPDX-License-Identifier: BSD-3-Clause
7+
//
8+
9+
import SwiftUI
10+
11+
/// Displays collapsible content panels for presenting information in a limited amount of space
12+
/// - Parameters:
13+
/// - data: The content of the component
14+
public struct Accordion: View {
15+
private var data: AccordionData
16+
17+
public init(data: AccordionData) {
18+
self.data = data
19+
}
20+
21+
public var body: some View {
22+
BaseAccordion(data: data)
23+
}
24+
}
25+
26+
struct Accordion_Previews: PreviewProvider {
27+
static var previews: some View {
28+
Accordion(data: .init(text: "Accordion Item #1", content: {
29+
SirioText(text: .loremIpsum, typography: .label_md_700)
30+
.foregroundColor(.black)
31+
}))
32+
.colorScheme(.dark)
33+
}
34+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//
2+
// AccordionGroup.swift
3+
//
4+
// SPDX-FileCopyrightText: 2022 Istituto Nazionale Previdenza Sociale
5+
//
6+
// SPDX-License-Identifier: BSD-3-Clause
7+
//
8+
9+
import SwiftUI
10+
11+
/// A group of accordions in column
12+
/// - Parameters:
13+
/// - data: A list of [AccordionData] each with the content of one accordion
14+
public struct AccordionGroup: View {
15+
@Environment(\.colorScheme) var colorScheme
16+
17+
let data: [AccordionData]
18+
19+
public init(data: [AccordionData]){
20+
self.data = data
21+
}
22+
23+
public var body: some View {
24+
VStack(spacing: 0) {
25+
ForEach(data.indices, id: \.self) { i in
26+
VStack(spacing: 0) {
27+
BaseAccordion(data: data[i], withBorder: false)
28+
29+
if i < data.count - 1 { // The separator is shown only if it isn't the last item
30+
Rectangle()
31+
.fill(borderColor)
32+
.frame(height: Size.Accordion.borderWidth)
33+
}
34+
}
35+
}
36+
}
37+
.border(borderColor, width: Size.Accordion.borderWidth)
38+
}
39+
}
40+
41+
extension AccordionGroup {
42+
var borderColor: Color {
43+
colorScheme == .dark ? Color.clear : Color.Accordion.Border.light
44+
}
45+
}
46+
47+
struct AccordionGroup_Previews: PreviewProvider {
48+
49+
static var previews: some View {
50+
VStack {
51+
AccordionGroup(data: [
52+
.init(text: "Accordion #1", content: {
53+
SirioText(text: .loremIpsum, typography: .label_md_700)
54+
.foregroundColor(.black)
55+
}),
56+
.init(text: "Accordion #2", content: {
57+
SirioText(text: .loremIpsum, typography: .label_md_700)
58+
.foregroundColor(.black)
59+
}),
60+
.init(text: "Accordion #3", content: {
61+
SirioText(text: .loremIpsum, typography: .label_md_700)
62+
.foregroundColor(.black)
63+
}, isDisabled: true)
64+
])
65+
Spacer()
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)