File tree Expand file tree Collapse file tree 5 files changed +64
-2
lines changed
Tests/SlipstreamTests/TailwindCSS/Borders Expand file tree Collapse file tree 5 files changed +64
-2
lines changed Original file line number Diff line number Diff line change @@ -160,8 +160,8 @@ Tailwind utility | Slipstream modifier
160
160
[ Outline Color] ( https://tailwindcss.com/docs/outline-color ) | `` View/outline(_:width:condition:) `` , `` View/outline(_:width:style:condition:) ``
161
161
[ Outline Style] ( https://tailwindcss.com/docs/outline-style ) | `` View/outline(_:width:style:condition:) ``
162
162
[ Outline Offset] ( https://tailwindcss.com/docs/outline-offset ) | [ Not implemented yet] ( https://github.com/jverkoey/slipstream/issues/51 )
163
- [ Ring Width] ( https://tailwindcss.com/docs/ring-width ) | [ Not implemented yet ] ( https://github.com/jverkoey/slipstream/issues/51 )
164
- [ Ring Color] ( https://tailwindcss.com/docs/ring-color ) | [ Not implemented yet ] ( https://github.com/jverkoey/slipstream/issues/51 )
163
+ [ Ring Width] ( https://tailwindcss.com/docs/ring-width ) | `` View/ring(_:width:condition:) ``
164
+ [ Ring Color] ( https://tailwindcss.com/docs/ring-color ) | `` View/ring(_:width:condition:) ``
165
165
[ Ring Offset Width] ( https://tailwindcss.com/docs/ring-offset-width ) | [ Not implemented yet] ( https://github.com/jverkoey/slipstream/issues/51 )
166
166
[ Ring Offset Color] ( https://tailwindcss.com/docs/ring-offset-color ) | [ Not implemented yet] ( https://github.com/jverkoey/slipstream/issues/51 )
167
167
Original file line number Diff line number Diff line change
1
+ # Ring
2
+
3
+ Utilities for creating outline rings with CSS box-shadows.
4
+
5
+ ## Topics
6
+
7
+ ### Modifiers
8
+
9
+ - `` View/ring(_:width:condition:) ``
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ Slipstream implementations of Tailwind CSS's utility classes.
51
51
- < doc:Borders-Border >
52
52
- < doc:Borders-CornerRadius >
53
53
- < doc:Borders-Outline >
54
+ - < doc:Borders-Ring >
54
55
55
56
### Effects
56
57
Original file line number Diff line number Diff line change
1
+ extension View {
2
+ /// Changes the ring of the view using a CSS box-shadow.
3
+ ///
4
+ /// - SeeAlso: Tailwind CSS' [ring width](https://tailwindcss.com/docs/ring-width) documentation.
5
+ /// - SeeAlso: Tailwind CSS' [ring color](https://tailwindcss.com/docs/ring-color) documentation.
6
+ @available ( iOS 17 . 0 , macOS 14 . 0 , * )
7
+ public func ring( _ color: Color ? = nil , width: Int = 1 , condition: Condition ? = nil ) -> some View {
8
+ var classNames : [ String ] = [
9
+ " ring " + closestTailwindRingWidth( width: width)
10
+ ]
11
+ if let color {
12
+ classNames. append ( " ring- " + color. toTailwindColorClass ( ) )
13
+ }
14
+ return modifier ( TailwindClassModifier ( add: Set ( classNames) , condition: condition) )
15
+ }
16
+
17
+ private func closestTailwindRingWidth( width: Int ) -> String {
18
+ let mapping : [ ( classSuffix: String , width: Int ) ] = [
19
+ ( " -0 " , 0 ) ,
20
+ ( " -1 " , 1 ) ,
21
+ ( " -2 " , 2 ) ,
22
+ ( " " , 3 ) ,
23
+ ( " -4 " , 4 ) ,
24
+ ( " -8 " , 8 ) ,
25
+ ]
26
+ let closest = mapping. min { abs ( $0. width - width) < abs ( $1. width - width) }
27
+ return closest? . classSuffix ?? " "
28
+ }
29
+ }
Original file line number Diff line number Diff line change
1
+ import Testing
2
+ import Slipstream
3
+
4
+ struct RingTests {
5
+ @Test func colors( ) throws {
6
+ try #expect( renderHTML ( Div { } . ring ( . black) ) == #"<div class="ring-1 ring-black"></div>"# )
7
+ try #expect( renderHTML ( Div { } . ring ( . white. opacity ( 0.5 ) ) ) == #"<div class="ring-1 ring-white/50"></div>"# )
8
+ }
9
+
10
+ @Test func widths( ) throws {
11
+ try #expect( renderHTML ( Div { } . ring ( width: 0 ) ) == #"<div class="ring-0"></div>"# )
12
+ try #expect( renderHTML ( Div { } . ring ( width: 1 ) ) == #"<div class="ring-1"></div>"# )
13
+ try #expect( renderHTML ( Div { } . ring ( width: 2 ) ) == #"<div class="ring-2"></div>"# )
14
+ try #expect( renderHTML ( Div { } . ring ( width: 3 ) ) == #"<div class="ring"></div>"# )
15
+ try #expect( renderHTML ( Div { } . ring ( width: 4 ) ) == #"<div class="ring-4"></div>"# )
16
+ try #expect( renderHTML ( Div { } . ring ( width: 5 ) ) == #"<div class="ring-4"></div>"# )
17
+ try #expect( renderHTML ( Div { } . ring ( width: 6 ) ) == #"<div class="ring-4"></div>"# )
18
+ try #expect( renderHTML ( Div { } . ring ( width: 7 ) ) == #"<div class="ring-8"></div>"# )
19
+ try #expect( renderHTML ( Div { } . ring ( width: 8 ) ) == #"<div class="ring-8"></div>"# )
20
+ try #expect( renderHTML ( Div { } . ring ( width: 9 ) ) == #"<div class="ring-8"></div>"# )
21
+ try #expect( renderHTML ( Div { } . ring ( width: 100 ) ) == #"<div class="ring-8"></div>"# )
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments