Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion guide/animation/animatable-modifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
This section is incomplete.
:::

### See also
## See also

- `ElementaryUI.View.opacity(_:)`
- `ElementaryUI.View.offset(x:y:)`
- `ElementaryUI.View.rotationEffect(_:anchor:)`
- `ElementaryUI.View.scaleEffect(_:anchor:)`
- `ElementaryUI.View.blur(radius:)`
- `ElementaryUI.View.saturation(_:)`
- `ElementaryUI.View.brightness(_:)`

<!-- Placeholder: document which modifiers are animatable (colors, borders, blur, etc.) once finalized. -->
4 changes: 2 additions & 2 deletions guide/animation/animate-layout-and-css.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Animate changes to layout and CSS values

ElementaryUI comes with a _**FLIP**_ animation system that enables automatic
ElementaryUI comes with a **FLIP** animation system that enables automatic
animation of essentially any visible change to your view's layout or appearance.

**FLIP** (First, Last, Invert, Play) is a technique that captures the geometry or appearance of an element before and after a change, then animates the difference. A view can opt-in to FLIP handling with modifiers, and any [transaction with an animation](transactions-and-animations.md#transactions) will be animated accordingly.

### Animate layout containers
## Animate layout containers

You can enable layout FLIP-handling on any [HTML element](../dom-interaction/html-elements.md) by applying the `ElementaryUI.View.animateContainerLayout(animateContainerSize:)` modifier.

Expand Down
2 changes: 1 addition & 1 deletion guide/animation/custom-animations.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This section is incomplete.
:::

### See also
## See also

- `ElementaryUI.Animatable`
- `ElementaryUI.CustomAnimation`
Expand Down
2 changes: 1 addition & 1 deletion guide/animation/phase-animator.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ Here, `.phaseAnimator` animates an existing view. Each click adds a heart and ma

## Choosing animations

Use the `animation` closure to choose an `ElementaryUI.Animation` for each phase, including the return to the first phase.
Use the `animation` closure to choose an `ElementaryUI.Animation` for the transition into each phase, including the return to the first phase.

Omit the closure to use the default animation, or return `nil` for a step without animation.
2 changes: 1 addition & 1 deletion guide/animation/transitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This section is incomplete.
:::

### See also
## See also

- `ElementaryUI.Transition`
- `ElementaryUI.View.transition(_:animation:)`
Expand Down
9 changes: 9 additions & 0 deletions guide/dom-interaction/handling-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ ElementaryUI provides on*Event* modifiers to handle DOM events like clicks, key
This section is incomplete.
:::

## Available events

- `ElementaryUI.View.onClick(_:)`
- `ElementaryUI.View.onMouseDown(_:)`
- `ElementaryUI.View.onMouseMove(_:)`
- `ElementaryUI.View.onMouseUp(_:)`
- `ElementaryUI.View.onKeyDown(_:)`
- `ElementaryUI.View.onInput(_:)`

## Example

Use `ElementaryUI.View.onMouseMove(_:)` to track mouse movement:
Expand Down
22 changes: 11 additions & 11 deletions guide/dom-interaction/html-elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Build up your HTML using the provided lower-case types like `div`, `p`, `button`
```swift
@View
struct MyView {
var body: some View {
div {
h1 { "Title" }
p { "Paragraph text" }
button { "Click me" }
var body: some View {
div {
h1 { "Title" }
p { "Paragraph text" }
button { "Click me" }
}
}
}
}
```

Expand All @@ -33,14 +33,14 @@ HTML attributes like `class`, `style`, and `id` are typically set via the elemen

```swift
div(.class("container"), .id("main")) {
p(.style(["color": "crimson"])) {
"Styled text"
}
input(.type(.text), .placeholder("Enter something"))
p(.style(["color": "crimson"])) {
"Styled text"
}
input(.type(.text), .placeholder("Enter something"))
}
```

Attributes can also be altered by using the modifier syntax, this allows for easy handling of conditional attributes.
Attributes can also be altered by using the modifier syntax, which allows for easy handling of conditional attributes.

```swift
div {
Expand Down
4 changes: 2 additions & 2 deletions guide/dom-interaction/input-bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
This section is incomplete.
:::

### See also
## See also

- `ElementaryUI.View.bindValue(_:)`
- `ElementaryUI.View.bindChecked(_:)`
- [Controlling Focus](/guide/dom-interaction/controlling-focus)
- [Controlling Focus](controlling-focus.md)
24 changes: 12 additions & 12 deletions guide/essentials/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ Mounting an application means **attaching its rendered output to the DOM**. Afte
```swift
@main
struct MyApp {
static func main() {
Application(ContentView())
.mount(in: .body)
}
static func main() {
Application(ContentView())
.mount(in: .body)
}
}
```

The `ElementaryUI.Application.mount(in:)` supports arbitrary CSS selectors. You can mount an application into any parent element.
The `ElementaryUI.Application.mount(in:)` method supports arbitrary CSS selectors. You can mount an application into any parent element.

```swift
Application(ContentView())
.mount(in: "#app")
.mount(in: "#app")
```

## Multiple applications
Expand All @@ -30,13 +30,13 @@ You can create and mount multiple applications on the same page. This is useful
```swift
@main
struct IslandsApp {
static func main() {
Application(Navigation())
.mount(in: "#nav-container")
static func main() {
Application(Navigation())
.mount(in: "#nav-container")

Application(CommentsSection())
.mount(in: "#comments-island")
}
Application(CommentsSection())
.mount(in: "#comments-island")
}
}
```

Expand Down
32 changes: 16 additions & 16 deletions guide/essentials/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ This sets up a typed environment key with a default value.

```swift
extension EnvironmentValues {
@Entry var themeColor: String = "blue"
@Entry var themeColor: String = "blue"
}
```

You can then provide a value using the `ElementaryUI.View.environment(_:_:)` modifier. The provided value will be accessible down the hierarchy of this view.

```swift
MyView()
.environment(#Key(\.themeColor), "rebeccapurple")
.environment(#Key(\.themeColor), "rebeccapurple")
```

::: info NOTE
Expand All @@ -26,47 +26,47 @@ Since key paths cannot be used in Embedded Swift, you must wrap them with the `E

## Using environment values in a view

Access environment values in your `ElementaryUI.View` using the `ElementaryUI.Environment` property wrapper.
Access environment values in your `ElementaryUI.View` using the [`Environment`](https://swiftpackageindex.com/elementary-swift/elementary-ui/documentation/elementaryui/environment-swift.struct) property wrapper.

```swift
@View
struct Greeting {
@Environment(#Key(\.themeColor)) var color
@Environment(#Key(\.themeColor)) var color

var body: some View {
p(.style(["color": color])) { "Hello" }
}
var body: some View {
p(.style(["color": color])) { "Hello" }
}
}
```

::: info NOTE
`ElementaryUI.Environment` will only work in types annotated with the `ElementaryUI.@View` macro.
[`Environment`](https://swiftpackageindex.com/elementary-swift/elementary-ui/documentation/elementaryui/environment-swift.struct) will only work in types annotated with the `ElementaryUI.@View` macro.
:::

## Reactive objects

You can also pass [reactive objects](./state-and-reactivity.md#reactive) directly in the environment. The object's type acts as the environment key.
You can also pass [reactive objects](state-and-reactivity.md#reactive) directly in the environment. The object's type acts as the environment key.

```swift
@Reactive
final class UserProfile {
var name: String = "Anonymous"
var name: String = "Anonymous"
}

// Providing the object
let profile = UserProfile()
ContentView()
.environment(profile)
.environment(profile)

// Reading the object in a sub view
@View
struct ProfileHeader {
@Environment(UserProfile.self) var profile
@Environment(UserProfile.self) var profile

var body: some View {
p {
"User: \(profile.name)"
var body: some View {
p {
"User: \(profile.name)"
}
}
}
}
```
66 changes: 33 additions & 33 deletions guide/essentials/lifecycle-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ Use the `ElementaryUI.View.onAppear(_:)` modifier to run an action when a view i
```swift
@View
struct MyView {
var body: some View {
div { "Hello" }
.onAppear {
print("View appeared!")
}
}
var body: some View {
div { "Hello" }
.onAppear {
print("View appeared!")
}
}
}
```

## `onDisappear`

Use the `ElementaryUI.View.onDisappear(_:)` modifier to run an action when a view is removed from hierarchy.
Use the `ElementaryUI.View.onDisappear(_:)` modifier to run an action when a view is removed from the hierarchy.

```swift
@View
struct MyView {
var body: some View {
div { "Goodbye" }
.onDisappear {
print("View disappeared!")
}
}
var body: some View {
div { "Goodbye" }
.onDisappear {
print("View disappeared!")
}
}
}
```

Expand All @@ -41,15 +41,15 @@ The `ElementaryUI.View.onChange(of:initial:_:)` modifier triggers an action when
```swift
@View
struct CounterView {
@State var count = 0
@State var count = 0

var body: some View {
button { "Increment" }
.onClick { count += 1 }
.onChange(of: count) {
print("Count is now \(count)")
}
}
var body: some View {
button { "Increment" }
.onClick { count += 1 }
.onChange(of: count) {
print("Count is now \(count)")
}
}
}
```

Expand All @@ -60,19 +60,19 @@ Use the `ElementaryUI.View.task(_:)` modifier to run an asynchronous operation w
```swift
@View
struct MyView {
@State var data: String?
@State var data: String?

var body: some View {
div {
if let data = data {
data
} else {
"Loading..."
}
}
.task {
data = await fetchData()
var body: some View {
div {
if let data = data {
data
} else {
"Loading..."
}
}
.task {
data = await fetchData()
}
}
}
}
```
2 changes: 1 addition & 1 deletion guide/essentials/list-rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## `ForEach`

Use `ElementaryUI.ForEach` when you need a stable id for your list items (reordering, insertions, animations). You can either use elements that implement `Identifiable`, or the `ElementaryUI.ForEach.init(_:id:content:)` initializer that takes an `id` closure returning any `Hashable` value.
Use `ForEach` when you need a stable id for your list items (reordering, insertions, animations). You can either use elements that implement `Identifiable`, or the `ForEach(_:id:content:)` initializer that takes an `id` closure returning any `Hashable` value.

<<< @/swift/Sources/Snippets/ListStrings.swift#snippet

Expand Down
8 changes: 4 additions & 4 deletions guide/essentials/state-and-reactivity.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ Use the `ElementaryUI.State` property wrapper to declare local, mutable state fo

<elementary-snippet file="TinyCounter" />

The lifetime of the state is tied to the **view’s lifetime**. For example, when this `Counter` view first appears in the view hierachy, a new slice of memory is initialized with `0`. As long as the view remains mounted, the current value of `count` is kept. Once the view is removed from the hierarchy, the memory is released again.
The lifetime of the state is tied to the **view’s lifetime**. For example, when this `TinyCounter` view first appears in the view hierarchy, a new slice of memory is initialized with `1`. As long as the view remains mounted, the current value of `count` is kept. Once the view is removed from the hierarchy, the memory is released again.

## `@Reactive`

Use the `Reactivity.@Reactive` macro to define a reference type that can be used view state.
Use the `Reactivity.@Reactive` macro to define a reference type that can be used as view state.

Any view that accesses one or more properties in its `body` will automatically be re-evaluated when the value of these properties change.
Any view that accesses one or more properties in its `body` will automatically be re-evaluated when the values of these properties change.

::: info Note
::: info NOTE

This is essentially `@Observable`, but with support for Embedded Swift.

Expand Down
Loading
Loading