Skip to content

Commit 4a98615

Browse files
authored
Merge pull request #4 from lukepistrol/docs
added DocC docs; enhanced readme
2 parents 91c6cec + 96c2fe5 commit 4a98615

File tree

6 files changed

+114
-3
lines changed

6 files changed

+114
-3
lines changed

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ To create a new asset, follow the guide on [Apple's developer website](https://d
3434

3535
Add the `.svg` you exported from `SF Symbols.app` to the `Symbols.xcassets` catalog.
3636

37+
Also add a static property to the `Image` and `NSImage` extension like so:
38+
39+
```swift
40+
// Image Extension
41+
static let your_symbol_name: Image = .init(symbol: "your_symbol_name")
42+
43+
// NSImage Extension
44+
static let your_symbol_name: NSImage = .symbol(named: "your_symbol_name")
45+
```
46+
3747
> **Important:** Make sure your symbol looks great in every font weight.
3848
3949
## Tests
@@ -46,9 +56,10 @@ Also include snapshot tests for each symbol for `Image` as well as `NSImage`:
4656
// MARK: YOUR_SYMBOL_NAME
4757

4858
func testCreateNSImageYourSymbolName() {
49-
let image = NSImage.symbol(named: "your_symbol_name")
59+
let image = NSImage.your_symbol_name
5060
let view = NSImageView(image: image)
51-
assertSnapshot(matching: view, as: .image)
61+
view.appearance = .init(named: .aqua)
62+
assertSnapshot(matching: view, as: .image, record: record)
5263
}
5364
```
5465

@@ -58,8 +69,9 @@ func testCreateNSImageYourSymbolName() {
5869
// MARK: YOUR_SYMBOL_NAME
5970

6071
func testCreateImageYourSymbolName() {
61-
let image = Image(symbol: "your_symbol_name")
72+
let image = Image.your_symbol_name
6273
let view: NSView = NSHostingController(rootView: image).view
74+
view.appearance = .init(named: .aqua)
6375
assertSnapshot(matching: view, as: .image(size: view.intrinsicContentSize))
6476
}
6577
```

Sources/CodeEditSymbols/CodeEditSymbols.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public extension Image {
2121
static let commit: Image = .init(symbol: "commit")
2222
static let checkout: Image = .init(symbol: "checkout")
2323

24+
// add static properties for your symbols above this line
25+
2426
}
2527

2628

@@ -40,4 +42,6 @@ public extension NSImage {
4042
static let commit: NSImage = .symbol(named: "commit")
4143
static let checkout: NSImage = .symbol(named: "checkout")
4244

45+
// add static properties for your symbols above this line
46+
4347
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Add Custom Symbols
2+
3+
To create a new asset, follow the guide on [Apple's developer website](https://developer.apple.com/documentation/uikit/uiimage/creating_custom_symbol_images_for_your_app).
4+
5+
## Overview
6+
7+
Add the `.svg` you exported from `SF Symbols.app` to the `Symbols.xcassets` catalog.
8+
9+
Also add a static property to the `Image` and `NSImage` extension like so:
10+
11+
```swift
12+
// Image Extension
13+
static let your_symbol_name: Image = .init(symbol: "your_symbol_name")
14+
15+
// NSImage Extension
16+
static let your_symbol_name: NSImage = .symbol(named: "your_symbol_name")
17+
```
18+
19+
> **Important:** Make sure your symbol looks great in every font weight.
20+
21+
22+
## Tests
23+
24+
Also include snapshot tests for each symbol for `Image` as well as `NSImage`:
25+
26+
### NSImage:
27+
28+
```swift
29+
// MARK: YOUR_SYMBOL_NAME
30+
31+
func testCreateNSImageYourSymbolName() {
32+
let image = NSImage.your_symbol_name
33+
let view = NSImageView(image: image)
34+
view.appearance = .init(named: .aqua)
35+
assertSnapshot(matching: view, as: .image, record: record)
36+
}
37+
```
38+
39+
### Image:
40+
41+
```swift
42+
// MARK: YOUR_SYMBOL_NAME
43+
44+
func testCreateImageYourSymbolName() {
45+
let image = Image.your_symbol_name
46+
let view: NSView = NSHostingController(rootView: image).view
47+
view.appearance = .init(named: .aqua)
48+
assertSnapshot(matching: view, as: .image(size: view.intrinsicContentSize))
49+
}
50+
```
51+
52+
## Variants
53+
54+
Keep different variants of a symbol in the same parent folder and name them appropriately (see Apple's own symbols for reference).
55+
56+
You might have a symbol called `lock` and one where the symbol is inside a square where you would call that file `lock.square`. Also keep in mind to also provide a `.fill` variant if appropriate (`lock.fill`, `lock.square.fill`)
57+
58+
### Example of a `.fill` Variant
59+
60+
![Fill Variant](fill_variant.png)
61+
62+
## Annotate the Symbol
63+
64+
As of version 3 of `SF Symbols` it is possible to create `multi-color`, `hierarchical` and `palette` annotations inside the `SF Symbols.app`. Be sure to annotate it accordingly if appropriate.
65+
66+
![Annotating](annotating.png)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# ``CodeEditSymbols``
2+
3+
A package containing all custom assets for CodeEdit. These are mostly custom [SF Symbols](https://developer.apple.com/design/human-interface-guidelines/sf-symbols/overview/#creating-custom-symbols).
4+
5+
## How to use
6+
7+
### NSImage:
8+
9+
```swift
10+
import CodeEditSymbols
11+
12+
let nsImage = NSImage.symbol(named: "name_of_the_symbol")
13+
14+
// or using the static property:
15+
16+
let nsImage1 = NSImage.name_of_the_symbol
17+
```
18+
19+
### Image:
20+
21+
```swift
22+
import CodeEditSymbols
23+
24+
let image = Image(symbol: "name_of_the_symbol")
25+
26+
// or using the static property:
27+
28+
let image1 = Image.name_of_the_symbol
29+
```
51.5 KB
Loading
12.9 KB
Loading

0 commit comments

Comments
 (0)