Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade the package #119

Merged
merged 29 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
37ff4b3
Make the storage manager public
mattesmohr Jan 10, 2023
6024de2
Add the press modifier to the text component
mattesmohr Jan 14, 2023
38947f6
Add the environment value to the content rendering
mattesmohr Jan 15, 2023
3d5e4b2
Fix the styling of the divider component
mattesmohr Jan 15, 2023
49b2139
Add a dropdown component
mattesmohr Jan 15, 2023
a230ae6
Revise the card component
mattesmohr Jan 23, 2023
ae30808
Remove the css from the grid item
mattesmohr Jan 23, 2023
8b925de
Add a scrollview component
mattesmohr Jan 30, 2023
cacee43
Add a carousel component
mattesmohr Jan 30, 2023
2ab2d83
Extend the carousel component
mattesmohr Feb 4, 2023
c1b2e13
Add more component tests
mattesmohr Feb 4, 2023
efc5b52
Fix test failing
mattesmohr Feb 4, 2023
c1a9f38
Add motion to the carousel by adding javascript
mattesmohr Feb 9, 2023
947a904
Add autoplay to the carousel
mattesmohr Feb 9, 2023
519927a
Fix tests
mattesmohr Feb 9, 2023
50da4a9
Add a test for the symbol component
mattesmohr Feb 12, 2023
1dc382e
Add the possibility to disable views
mattesmohr Feb 14, 2023
884575e
Fix the css classes for the position index
mattesmohr Feb 14, 2023
25d2417
Add a few new symbols
mattesmohr Feb 18, 2023
154d007
Add more symbols
mattesmohr Feb 19, 2023
e3c75ce
Add the possibility to hide views
mattesmohr Feb 19, 2023
3d34635
Revise the input fields to accept a placeholder value
mattesmohr Feb 20, 2023
81a0b8d
Add the submit event to the form component
mattesmohr Feb 23, 2023
4c33834
Add comments
mattesmohr Feb 25, 2023
4fef16a
Refactor code and rearrange files
mattesmohr Feb 25, 2023
4636e9a
Add form validation
mattesmohr Feb 26, 2023
94ddff0
Fix some sort of things
mattesmohr Feb 26, 2023
a65e440
Change the js initialization for the carousel component
mattesmohr Feb 27, 2023
e2f13af
Add a textpad component
mattesmohr Feb 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ let package = Package(
dependencies: [
.product(name: "Lingo", package: "Lingo"),
.product(name: "Collections", package: "swift-collections")
]
],
exclude: ["Abstraction/README.md", "Framework/README.md"]
),
.target(
name: "HTMLKitConverter",
Expand Down
10 changes: 10 additions & 0 deletions Sources/HTMLKit/Abstraction/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Abstraction

This directory contains the HTML abstraction.

### Attributes

### Elements

### Tokens

Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import Foundation

/// A type, that manages the environment storage
internal class Manager {
public class Manager {

/// The storage of the environment
internal var storage: [AnyKeyPath: Any]
private var storage: [AnyKeyPath: Any]

/// Initiates a manager
internal init() {
public init() {

self.storage = [:]
}

/// Retrieves an item from storage by its path
internal func retrieve(for path: AnyKeyPath) -> Any? {
public func retrieve(for path: AnyKeyPath) -> Any? {

if let value = self.storage[path] {
return value
Expand All @@ -23,7 +23,7 @@ internal class Manager {
}

/// Adds und updates an item to the storage
internal func upsert<T>(_ value: T, for path: AnyKeyPath) {
public func upsert<T>(_ value: T, for path: AnyKeyPath) {
self.storage[path] = value
}
}
17 changes: 17 additions & 0 deletions Sources/HTMLKit/Framework/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Framework

This directory contains sources for

### Builders

### Environment

### Extensions

### Helpers

### Localization

### Primitives

### Rendering
12 changes: 10 additions & 2 deletions Sources/HTMLKit/Framework/Rendering/Renderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ public class Renderer {
self.lingo = lingo
}

public func add<T>(model: T) where T: Encodable {
manager.upsert(model, for: \T.self)
/// Initiates the renderer.
public init(lingo: Lingo? = nil, manager: Manager) {

self.environment = Environment()
self.manager = manager
self.lingo = lingo
}

/// Renders a view
Expand Down Expand Up @@ -112,6 +116,10 @@ public class Renderer {
result += try render(modifier: modifier)
}

if let value = content as? EnvironmentValue {
result += try render(value: value)
}

if let element = content as? String {
result += element
}
Expand Down
49 changes: 48 additions & 1 deletion Sources/HTMLKitComponents/Actions.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
/*
Abstract:
The file contains the actions for the components.
The file contains the action stencils for the components.
*/

import Foundation

/// A collection of actions, that can be triggered by events.
public enum Actions {

/// Shows the target.
case show(_ target: String)

/// Hides the target.
case hide(_ target: String)

/// Animates the target.
case animate(_ target: String)

/// Opens the target.
case open(_ target: String)

/// Closes the target.
case close(_ target: String)

/// Validates the form.
case valdiate(_ target: String, _ rules: [Validator])

public var description: String {

switch self {
case .valdiate(_, _):
return "validate"
default:
return "default"
}
}

/// The script for the action.
public var script: String {

switch self {
Expand All @@ -28,26 +54,47 @@ public enum Actions {

case .close(let target):
return close(target)

case .valdiate(let target, let rules):
return validate(target, rules)
}
}

/// Returns a show action stencil.
private func show(_ target: String) -> String {
return "$('#\(target)').show();"
}

/// Returns a hide action stencil.
private func hide(_ target: String) -> String {
return "$('#\(target)').hide();"
}

/// Returns a animate action stencil.
private func animate(_ target: String) -> String {
return "$('#\(target)').animate();"
}

/// Returns a open action stencil.
private func open(_ target: String) -> String {
return "$('#\(target)').open();"
}

/// Returns a close action stencil.
private func close(_ target: String) -> String {
return "$('#\(target)').close();"
}

/// Returns a close action stencil.
private func validate(_ target: String, _ validators: [Validator]) -> String {

if let data = try? JSONEncoder().encode(validators) {

if let result = String(data: data, encoding: .utf8) {
return "$('#\(target)').validate('\(result)');"
}
}

return "$('#\(target)').validate('[]');"
}
}
18 changes: 18 additions & 0 deletions Sources/HTMLKitComponents/Components/Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ extension Button: ButtonModifier {
public func backgroundColor(_ color: Tokens.BackgroundColor) -> Button {
return self.mutate(backgroundcolor: color.rawValue)
}

public func disabled(_ condition: Bool) -> Button {

if condition {
return self.mutate(state: Tokens.ViewState.disabled.rawValue)
}

return self
}
}

extension Button: PressModifier {
Expand Down Expand Up @@ -153,4 +162,13 @@ extension LinkButton: ButtonModifier {
public func backgroundColor(_ color: Tokens.BackgroundColor) -> LinkButton {
return self.mutate(backgroundcolor: color.rawValue)
}

public func disabled(_ condition: Bool) -> LinkButton {

if condition {
return self.mutate(state: Tokens.ViewState.disabled.rawValue)
}

return self
}
}
44 changes: 40 additions & 4 deletions Sources/HTMLKitComponents/Components/Card.swift
Original file line number Diff line number Diff line change
@@ -1,21 +1,57 @@
/*
Abstract:
The file contains a card component.
*/

import HTMLKit

public struct Card: View, Modifiable {
/// A component that distinguish content.
public class Card: View {

/// The header of the card.
public var header: [Content]?

internal var content: [Content]
/// The content of the card.
public var content: [Content]

/// The classes of the content.
internal var classes: [String]

/// Creates a card.
public init(@ContentBuilder<Content> content: () -> [Content]) {

self.content = content()
self.classes = ["card"]
}

/// Creates a card.
public init(@ContentBuilder<Content> content: () -> [Content],
@ContentBuilder<Content> header: () -> [Content]) {

self.content = content()
self.header = header()
self.classes = ["card"]
}

/// Creates a card.
internal init(header: [Content]?, content: [Content], classes: [String]) {

self.header = header
self.content = content
self.classes = classes
}

public var body: Content {
Division {
content
Division {
header
}
.class("card-header")
Division {
content
}
.class("card-body")
}
.class(self.classes.joined(separator: " "))
.class(classes.joined(separator: " "))
}
}
114 changes: 114 additions & 0 deletions Sources/HTMLKitComponents/Components/Carousel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
Abstract:
The file contains a carousel component.
*/

import HTMLKit

/// A compnonent that cycles through an amount of views.
public struct Carousel: View {

/// The indication for the carousel.
internal var indication: [Content]

/// The content of the carousel.
internal var content: [Content]

/// The classes of the carousel.
internal var classes: [String]

/// Creates a carousel.
public init(@ContentBuilder<Content> content: () -> [Content],
@ContentBuilder<Content> indication: () -> [Content]) {

self.content = content()
self.indication = indication()
self.classes = ["carousel"]
}

/// Creates a carousel.
internal init(indication: [Content], content: [Content], classes: [String]) {

self.indication = indication
self.content = content
self.classes = classes
}

public var body: Content {
Division {
Division {
content
}
.class("carousel-content")
Division {
indication
}
.class("carousel-indication")
}
.class(classes.joined(separator: " "))
}
}

public struct Slide: View, Identifiable, Modifiable {

internal var id: String?

internal var source: String

internal var classes: [String]

internal var caption: [Content]

public init(source: String, @ContentBuilder<Content> caption: () -> [Content]) {

self.source = source
self.caption = caption()
self.classes = ["slide"]
}

internal init(id: String?, source: String, caption: [Content], classes: [String]) {

self.id = id
self.source = source
self.caption = caption
self.classes = classes
}

public var body: Content {
Division {
Division {
HTMLKit.Image()
.source(source)
}
.class("slide-thumbnail")
Division {
caption
}
.class("slide-caption")
}
.class(classes.joined(separator: " "))
.modify(unwrap: id) {
$0.id($1)
}
}

public func tag(_ value: String) -> Slide {
return self.mutate(id: value)
}
}

public struct Indicator: View {

internal var tag: String

public init(for tag: String) {
self.tag = "#" + tag
}

public var body: Content {
Anchor {
}
.class("indicator")
.reference(tag)
}
}
Loading