Skip to content

Commit 5ce543a

Browse files
authored
[macOS] Mark macOS ColorSet and DynamicColor as legacy (microsoft#2136)
* Mark macOS `ColorSet` and `DynamicColor` as legacy * Fix automation
1 parent c7f0c7f commit 5ce543a

File tree

5 files changed

+161
-99
lines changed

5 files changed

+161
-99
lines changed

Demos/FluentUIDemo_macOS/FluentUITestViewControllers/TestBadgeViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class TestBadgeViewController: NSViewController {
2020
containerView.addView(BadgeView(title: "Primary", style: .primary), in: .center)
2121

2222
let customBadge = BadgeView(title: "Custom")
23-
customBadge.backgroundColor = DynamicColor(light: Colors.Palette.blueMagenta20.color, dark: Colors.Palette.gray50.color)
24-
customBadge.textColor = DynamicColor(light: Colors.Palette.gray50.color, dark: Colors.Palette.blueMagenta20.color)
23+
customBadge.backgroundColor = .init(light: Colors.Palette.blueMagenta20.color, dark: Colors.Palette.gray50.color)
24+
customBadge.textColor = .init(light: Colors.Palette.gray50.color, dark: Colors.Palette.blueMagenta20.color)
2525
containerView.addView(customBadge, in: .center)
2626

2727
view = containerView

Sources/FluentUI_macOS/Components/AvatarView/AvatarView.swift

+123-63
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ open class AvatarView: NSView {
402402
/// - returns: the color table entry for the given index
403403
@objc(getColorForIndex:)
404404
@available(*, deprecated, message: "Use getInitialsColorSetFromPrimaryText:secondaryText: instead")
405-
public static func getColor(for index: Int) -> ColorSet {
405+
public static func getColor(for index: Int) -> LegacyColorSet {
406406
let avatarBackgroundColors = AvatarView.avatarColors
407407
return avatarBackgroundColors[index % avatarBackgroundColors.count]
408408
}
@@ -524,7 +524,7 @@ open class AvatarView: NSView {
524524
///
525525
/// - Returns: The calculated `ColorSet` for the provided text values.
526526
@objc(getInitialsColorSetFromPrimaryText:secondaryText:)
527-
public static func getInitialsColorSet(fromPrimaryText primaryText: String?, secondaryText: String?) -> ColorSet {
527+
public static func getInitialsColorSet(fromPrimaryText primaryText: String?, secondaryText: String?) -> LegacyColorSet {
528528
// Set the color based on the primary text and secondary text
529529
let combined = (primaryText ?? "") + (secondaryText ?? "")
530530
let combinedHashable = combined as NSString
@@ -636,67 +636,127 @@ extension AvatarView {
636636
]
637637

638638
/// Table of background and text colors for the AvatarView
639-
static let avatarColors: [ColorSet] = [
640-
ColorSet(background: DynamicColor(light: Colors.Palette.darkRedTint40.color, dark: Colors.Palette.darkRedShade30.color),
641-
foreground: DynamicColor(light: Colors.Palette.darkRedShade30.color, dark: Colors.Palette.darkRedTint40.color)),
642-
ColorSet(background: DynamicColor(light: Colors.Palette.cranberryTint40.color, dark: Colors.Palette.cranberryShade30.color),
643-
foreground: DynamicColor(light: Colors.Palette.cranberryShade30.color, dark: Colors.Palette.cranberryTint40.color)),
644-
ColorSet(background: DynamicColor(light: Colors.Palette.redTint40.color, dark: Colors.Palette.redShade30.color),
645-
foreground: DynamicColor(light: Colors.Palette.redShade30.color, dark: Colors.Palette.redTint40.color)),
646-
ColorSet(background: DynamicColor(light: Colors.Palette.pumpkinTint40.color, dark: Colors.Palette.pumpkinShade30.color),
647-
foreground: DynamicColor(light: Colors.Palette.pumpkinShade30.color, dark: Colors.Palette.pumpkinTint40.color)),
648-
ColorSet(background: DynamicColor(light: Colors.Palette.peachTint40.color, dark: Colors.Palette.peachShade30.color),
649-
foreground: DynamicColor(light: Colors.Palette.peachShade30.color, dark: Colors.Palette.peachTint40.color)),
650-
ColorSet(background: DynamicColor(light: Colors.Palette.marigoldTint40.color, dark: Colors.Palette.marigoldShade30.color),
651-
foreground: DynamicColor(light: Colors.Palette.marigoldShade30.color, dark: Colors.Palette.marigoldTint40.color)),
652-
ColorSet(background: DynamicColor(light: Colors.Palette.goldTint40.color, dark: Colors.Palette.goldShade30.color),
653-
foreground: DynamicColor(light: Colors.Palette.goldShade30.color, dark: Colors.Palette.goldTint40.color)),
654-
ColorSet(background: DynamicColor(light: Colors.Palette.brassTint40.color, dark: Colors.Palette.brassShade30.color),
655-
foreground: DynamicColor(light: Colors.Palette.brassShade30.color, dark: Colors.Palette.brassTint40.color)),
656-
ColorSet(background: DynamicColor(light: Colors.Palette.brownTint40.color, dark: Colors.Palette.brownShade30.color),
657-
foreground: DynamicColor(light: Colors.Palette.brownShade30.color, dark: Colors.Palette.brownTint40.color)),
658-
ColorSet(background: DynamicColor(light: Colors.Palette.forestTint40.color, dark: Colors.Palette.forestShade30.color),
659-
foreground: DynamicColor(light: Colors.Palette.forestShade30.color, dark: Colors.Palette.forestTint40.color)),
660-
ColorSet(background: DynamicColor(light: Colors.Palette.seafoamTint40.color, dark: Colors.Palette.seafoamShade30.color),
661-
foreground: DynamicColor(light: Colors.Palette.seafoamShade30.color, dark: Colors.Palette.seafoamTint40.color)),
662-
ColorSet(background: DynamicColor(light: Colors.Palette.darkGreenTint40.color, dark: Colors.Palette.darkGreenShade30.color),
663-
foreground: DynamicColor(light: Colors.Palette.darkGreenShade30.color, dark: Colors.Palette.darkGreenTint40.color)),
664-
ColorSet(background: DynamicColor(light: Colors.Palette.lightTealTint40.color, dark: Colors.Palette.lightTealShade30.color),
665-
foreground: DynamicColor(light: Colors.Palette.lightTealShade30.color, dark: Colors.Palette.lightTealTint40.color)),
666-
ColorSet(background: DynamicColor(light: Colors.Palette.tealTint40.color, dark: Colors.Palette.tealShade30.color),
667-
foreground: DynamicColor(light: Colors.Palette.tealShade30.color, dark: Colors.Palette.tealTint40.color)),
668-
ColorSet(background: DynamicColor(light: Colors.Palette.steelTint40.color, dark: Colors.Palette.steelShade30.color),
669-
foreground: DynamicColor(light: Colors.Palette.steelShade30.color, dark: Colors.Palette.steelTint40.color)),
670-
ColorSet(background: DynamicColor(light: Colors.Palette.blueTint40.color, dark: Colors.Palette.blueShade30.color),
671-
foreground: DynamicColor(light: Colors.Palette.blueShade30.color, dark: Colors.Palette.blueTint40.color)),
672-
ColorSet(background: DynamicColor(light: Colors.Palette.royalBlueTint40.color, dark: Colors.Palette.royalBlueShade30.color),
673-
foreground: DynamicColor(light: Colors.Palette.royalBlueShade30.color, dark: Colors.Palette.royalBlueTint40.color)),
674-
ColorSet(background: DynamicColor(light: Colors.Palette.cornFlowerTint40.color, dark: Colors.Palette.cornFlowerShade30.color),
675-
foreground: DynamicColor(light: Colors.Palette.cornFlowerShade30.color, dark: Colors.Palette.cornFlowerTint40.color)),
676-
ColorSet(background: DynamicColor(light: Colors.Palette.navyTint40.color, dark: Colors.Palette.navyShade30.color),
677-
foreground: DynamicColor(light: Colors.Palette.navyShade30.color, dark: Colors.Palette.navyTint40.color)),
678-
ColorSet(background: DynamicColor(light: Colors.Palette.lavenderTint40.color, dark: Colors.Palette.lavenderShade30.color),
679-
foreground: DynamicColor(light: Colors.Palette.lavenderShade30.color, dark: Colors.Palette.lavenderTint40.color)),
680-
ColorSet(background: DynamicColor(light: Colors.Palette.purpleTint40.color, dark: Colors.Palette.purpleShade30.color),
681-
foreground: DynamicColor(light: Colors.Palette.purpleShade30.color, dark: Colors.Palette.purpleTint40.color)),
682-
ColorSet(background: DynamicColor(light: Colors.Palette.grapeTint40.color, dark: Colors.Palette.grapeShade30.color),
683-
foreground: DynamicColor(light: Colors.Palette.grapeShade30.color, dark: Colors.Palette.grapeTint40.color)),
684-
ColorSet(background: DynamicColor(light: Colors.Palette.lilacTint40.color, dark: Colors.Palette.lilacShade30.color),
685-
foreground: DynamicColor(light: Colors.Palette.lilacShade30.color, dark: Colors.Palette.lilacTint40.color)),
686-
ColorSet(background: DynamicColor(light: Colors.Palette.pinkTint40.color, dark: Colors.Palette.pinkShade30.color),
687-
foreground: DynamicColor(light: Colors.Palette.pinkShade30.color, dark: Colors.Palette.pinkTint40.color)),
688-
ColorSet(background: DynamicColor(light: Colors.Palette.magentaTint40.color, dark: Colors.Palette.magentaShade30.color),
689-
foreground: DynamicColor(light: Colors.Palette.magentaShade30.color, dark: Colors.Palette.magentaTint40.color)),
690-
ColorSet(background: DynamicColor(light: Colors.Palette.plumTint40.color, dark: Colors.Palette.plumShade30.color),
691-
foreground: DynamicColor(light: Colors.Palette.plumShade30.color, dark: Colors.Palette.plumTint40.color)),
692-
ColorSet(background: DynamicColor(light: Colors.Palette.beigeTint40.color, dark: Colors.Palette.beigeShade30.color),
693-
foreground: DynamicColor(light: Colors.Palette.beigeShade30.color, dark: Colors.Palette.beigeTint40.color)),
694-
ColorSet(background: DynamicColor(light: Colors.Palette.minkTint40.color, dark: Colors.Palette.minkShade30.color),
695-
foreground: DynamicColor(light: Colors.Palette.minkShade30.color, dark: Colors.Palette.minkTint40.color)),
696-
ColorSet(background: DynamicColor(light: Colors.Palette.platinumTint40.color, dark: Colors.Palette.platinumShade30.color),
697-
foreground: DynamicColor(light: Colors.Palette.platinumShade30.color, dark: Colors.Palette.platinumTint40.color)),
698-
ColorSet(background: DynamicColor(light: Colors.Palette.anchorTint40.color, dark: Colors.Palette.anchorShade30.color),
699-
foreground: DynamicColor(light: Colors.Palette.anchorShade30.color, dark: Colors.Palette.anchorTint40.color))
639+
static let avatarColors: [LegacyColorSet] = [
640+
.init(background: .init(light: Colors.Palette.darkRedTint40.color,
641+
dark: Colors.Palette.darkRedShade30.color),
642+
foreground: .init(light: Colors.Palette.darkRedShade30.color,
643+
dark: Colors.Palette.darkRedTint40.color)),
644+
.init(background: .init(light: Colors.Palette.cranberryTint40.color,
645+
dark: Colors.Palette.cranberryShade30.color),
646+
foreground: .init(light: Colors.Palette.cranberryShade30.color,
647+
dark: Colors.Palette.cranberryTint40.color)),
648+
.init(background: .init(light: Colors.Palette.redTint40.color,
649+
dark: Colors.Palette.redShade30.color),
650+
foreground: .init(light: Colors.Palette.redShade30.color,
651+
dark: Colors.Palette.redTint40.color)),
652+
.init(background: .init(light: Colors.Palette.pumpkinTint40.color,
653+
dark: Colors.Palette.pumpkinShade30.color),
654+
foreground: .init(light: Colors.Palette.pumpkinShade30.color,
655+
dark: Colors.Palette.pumpkinTint40.color)),
656+
.init(background: .init(light: Colors.Palette.peachTint40.color,
657+
dark: Colors.Palette.peachShade30.color),
658+
foreground: .init(light: Colors.Palette.peachShade30.color,
659+
dark: Colors.Palette.peachTint40.color)),
660+
.init(background: .init(light: Colors.Palette.marigoldTint40.color,
661+
dark: Colors.Palette.marigoldShade30.color),
662+
foreground: .init(light: Colors.Palette.marigoldShade30.color,
663+
dark: Colors.Palette.marigoldTint40.color)),
664+
.init(background: .init(light: Colors.Palette.goldTint40.color,
665+
dark: Colors.Palette.goldShade30.color),
666+
foreground: .init(light: Colors.Palette.goldShade30.color,
667+
dark: Colors.Palette.goldTint40.color)),
668+
.init(background: .init(light: Colors.Palette.brassTint40.color,
669+
dark: Colors.Palette.brassShade30.color),
670+
foreground: .init(light: Colors.Palette.brassShade30.color,
671+
dark: Colors.Palette.brassTint40.color)),
672+
.init(background: .init(light: Colors.Palette.brownTint40.color,
673+
dark: Colors.Palette.brownShade30.color),
674+
foreground: .init(light: Colors.Palette.brownShade30.color,
675+
dark: Colors.Palette.brownTint40.color)),
676+
.init(background: .init(light: Colors.Palette.forestTint40.color,
677+
dark: Colors.Palette.forestShade30.color),
678+
foreground: .init(light: Colors.Palette.forestShade30.color,
679+
dark: Colors.Palette.forestTint40.color)),
680+
.init(background: .init(light: Colors.Palette.seafoamTint40.color,
681+
dark: Colors.Palette.seafoamShade30.color),
682+
foreground: .init(light: Colors.Palette.seafoamShade30.color,
683+
dark: Colors.Palette.seafoamTint40.color)),
684+
.init(background: .init(light: Colors.Palette.darkGreenTint40.color,
685+
dark: Colors.Palette.darkGreenShade30.color),
686+
foreground: .init(light: Colors.Palette.darkGreenShade30.color,
687+
dark: Colors.Palette.darkGreenTint40.color)),
688+
.init(background: .init(light: Colors.Palette.lightTealTint40.color,
689+
dark: Colors.Palette.lightTealShade30.color),
690+
foreground: .init(light: Colors.Palette.lightTealShade30.color,
691+
dark: Colors.Palette.lightTealTint40.color)),
692+
.init(background: .init(light: Colors.Palette.tealTint40.color,
693+
dark: Colors.Palette.tealShade30.color),
694+
foreground: .init(light: Colors.Palette.tealShade30.color,
695+
dark: Colors.Palette.tealTint40.color)),
696+
.init(background: .init(light: Colors.Palette.steelTint40.color,
697+
dark: Colors.Palette.steelShade30.color),
698+
foreground: .init(light: Colors.Palette.steelShade30.color,
699+
dark: Colors.Palette.steelTint40.color)),
700+
.init(background: .init(light: Colors.Palette.blueTint40.color,
701+
dark: Colors.Palette.blueShade30.color),
702+
foreground: .init(light: Colors.Palette.blueShade30.color,
703+
dark: Colors.Palette.blueTint40.color)),
704+
.init(background: .init(light: Colors.Palette.royalBlueTint40.color,
705+
dark: Colors.Palette.royalBlueShade30.color),
706+
foreground: .init(light: Colors.Palette.royalBlueShade30.color,
707+
dark: Colors.Palette.royalBlueTint40.color)),
708+
.init(background: .init(light: Colors.Palette.cornFlowerTint40.color,
709+
dark: Colors.Palette.cornFlowerShade30.color),
710+
foreground: .init(light: Colors.Palette.cornFlowerShade30.color,
711+
dark: Colors.Palette.cornFlowerTint40.color)),
712+
.init(background: .init(light: Colors.Palette.navyTint40.color,
713+
dark: Colors.Palette.navyShade30.color),
714+
foreground: .init(light: Colors.Palette.navyShade30.color,
715+
dark: Colors.Palette.navyTint40.color)),
716+
.init(background: .init(light: Colors.Palette.lavenderTint40.color,
717+
dark: Colors.Palette.lavenderShade30.color),
718+
foreground: .init(light: Colors.Palette.lavenderShade30.color,
719+
dark: Colors.Palette.lavenderTint40.color)),
720+
.init(background: .init(light: Colors.Palette.purpleTint40.color,
721+
dark: Colors.Palette.purpleShade30.color),
722+
foreground: .init(light: Colors.Palette.purpleShade30.color,
723+
dark: Colors.Palette.purpleTint40.color)),
724+
.init(background: .init(light: Colors.Palette.grapeTint40.color,
725+
dark: Colors.Palette.grapeShade30.color),
726+
foreground: .init(light: Colors.Palette.grapeShade30.color,
727+
dark: Colors.Palette.grapeTint40.color)),
728+
.init(background: .init(light: Colors.Palette.lilacTint40.color,
729+
dark: Colors.Palette.lilacShade30.color),
730+
foreground: .init(light: Colors.Palette.lilacShade30.color,
731+
dark: Colors.Palette.lilacTint40.color)),
732+
.init(background: .init(light: Colors.Palette.pinkTint40.color,
733+
dark: Colors.Palette.pinkShade30.color),
734+
foreground: .init(light: Colors.Palette.pinkShade30.color,
735+
dark: Colors.Palette.pinkTint40.color)),
736+
.init(background: .init(light: Colors.Palette.magentaTint40.color,
737+
dark: Colors.Palette.magentaShade30.color),
738+
foreground: .init(light: Colors.Palette.magentaShade30.color,
739+
dark: Colors.Palette.magentaTint40.color)),
740+
.init(background: .init(light: Colors.Palette.plumTint40.color,
741+
dark: Colors.Palette.plumShade30.color),
742+
foreground: .init(light: Colors.Palette.plumShade30.color,
743+
dark: Colors.Palette.plumTint40.color)),
744+
.init(background: .init(light: Colors.Palette.beigeTint40.color,
745+
dark: Colors.Palette.beigeShade30.color),
746+
foreground: .init(light: Colors.Palette.beigeShade30.color,
747+
dark: Colors.Palette.beigeTint40.color)),
748+
.init(background: .init(light: Colors.Palette.minkTint40.color,
749+
dark: Colors.Palette.minkShade30.color),
750+
foreground: .init(light: Colors.Palette.minkShade30.color,
751+
dark: Colors.Palette.minkTint40.color)),
752+
.init(background: .init(light: Colors.Palette.platinumTint40.color,
753+
dark: Colors.Palette.platinumShade30.color),
754+
foreground: .init(light: Colors.Palette.platinumShade30.color,
755+
dark: Colors.Palette.platinumTint40.color)),
756+
.init(background: .init(light: Colors.Palette.anchorTint40.color,
757+
dark: Colors.Palette.anchorShade30.color),
758+
foreground: .init(light: Colors.Palette.anchorShade30.color,
759+
dark: Colors.Palette.anchorTint40.color))
700760
]
701761
}
702762

Sources/FluentUI_macOS/Components/Badge/BadgeView.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ open class BadgeView: NSView {
7070
updateColors()
7171
}
7272

73-
private var _backgroundColor: DynamicColor
74-
@objc open var backgroundColor: DynamicColor {
73+
private var _backgroundColor: LegacyDynamicColor
74+
@objc open var backgroundColor: LegacyDynamicColor {
7575
get {
7676
return _backgroundColor
7777
}
@@ -83,8 +83,8 @@ open class BadgeView: NSView {
8383
}
8484
}
8585

86-
private var _textColor: DynamicColor
87-
@objc open var textColor: DynamicColor {
86+
private var _textColor: LegacyDynamicColor
87+
@objc open var textColor: LegacyDynamicColor {
8888
get {
8989
return _textColor
9090
}
@@ -144,9 +144,9 @@ open class BadgeView: NSView {
144144
}
145145

146146
private struct Constants {
147-
static let defaultBackgroundColor: DynamicColor = DynamicColor(light: Colors.Palette.communicationBlueTint40.color, dark: Colors.Palette.communicationBlueTint30.color)
148-
static let defaultTextColor: DynamicColor = DynamicColor(light: Colors.Palette.communicationBlue.color, dark: Colors.Palette.communicationBlueShade20.color)
149-
static let primaryBackgroundColor: DynamicColor = DynamicColor(light: Colors.primaryTint40, dark: Colors.primaryTint30)
150-
static let primaryTextColor: DynamicColor = DynamicColor(light: Colors.primary, dark: Colors.primaryShade20)
147+
static let defaultBackgroundColor: LegacyDynamicColor = .init(light: Colors.Palette.communicationBlueTint40.color, dark: Colors.Palette.communicationBlueTint30.color)
148+
static let defaultTextColor: LegacyDynamicColor = .init(light: Colors.Palette.communicationBlue.color, dark: Colors.Palette.communicationBlueShade20.color)
149+
static let primaryBackgroundColor: LegacyDynamicColor = .init(light: Colors.primaryTint40, dark: Colors.primaryTint30)
150+
static let primaryTextColor: LegacyDynamicColor = .init(light: Colors.primary, dark: Colors.primaryShade20)
151151
}
152152
}

Sources/FluentUI_macOS/Components/DynamicColor/DynamicColor.swift

+10-8
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55

66
import AppKit
77

8-
@objc(MSFColorSet)
9-
public class ColorSet: NSObject {
10-
@objc public let background: DynamicColor
11-
@objc public let foreground: DynamicColor
8+
/// Note: this class will be removed once the core iOS color system has been migrated cross-platform.
9+
@objc(MSFLegacyColorSet)
10+
public class LegacyColorSet: NSObject {
11+
@objc public let background: LegacyDynamicColor
12+
@objc public let foreground: LegacyDynamicColor
1213

13-
public init(background: DynamicColor, foreground: DynamicColor) {
14+
public init(background: LegacyDynamicColor, foreground: LegacyDynamicColor) {
1415
self.background = background
1516
self.foreground = foreground
1617
}
1718
}
1819

19-
@objc(MSFDynamicColor)
20-
public class DynamicColor: NSObject {
20+
/// Note: this class will be removed once the core iOS color system has been migrated cross-platform.
21+
@objc(MSFLegacyDynamicColor)
22+
public class LegacyDynamicColor: NSObject {
2123

2224
@objc public let light: NSColor
2325
@objc public let dark: NSColor
@@ -36,7 +38,7 @@ public class DynamicColor: NSObject {
3638
}
3739

3840
public override func isEqual(_ object: Any?) -> Bool {
39-
guard let dynamicColor = object as? DynamicColor else {
41+
guard let dynamicColor = object as? LegacyDynamicColor else {
4042
return false
4143
}
4244
return dynamicColor.light.isEqual(self.light) && dynamicColor.dark.isEqual(self.dark)

0 commit comments

Comments
 (0)