-
Notifications
You must be signed in to change notification settings - Fork 115
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
Add support for color mode defined by color name prefix #218 #235
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,29 +37,39 @@ final class ColorsLoader { | |
lightHC: [Color]?, | ||
darkHC: [Color]?) { | ||
let colors = try loadColors(fileId: figmaParams.lightFileId, filter: filter) | ||
|
||
let darkSuffix = colorParams?.darkModeSuffix ?? "_dark" | ||
|
||
let lightPrefix = colorParams?.lightModePrefix | ||
let darkPrefix = colorParams?.darkModePrefix | ||
let lightSuffix = colorParams?.lightModeSuffix | ||
let darkSuffix = colorParams?.darkModeSuffix | ||
let lightHCPrefix = colorParams?.lightHCModePrefix ?? "lightHC_" | ||
let darkHCPrefix = colorParams?.darkHCModePrefix ?? "darkHC_" | ||
let lightHCSuffix = colorParams?.lightHCModeSuffix ?? "_lightHC" | ||
let darkHCSuffix = colorParams?.darkHCModeSuffix ?? "_darkHC" | ||
|
||
let lightColors = colors | ||
.filter { | ||
!$0.name.hasSuffix(darkSuffix) && | ||
!$0.name.hasSuffix(lightHCSuffix) && | ||
!$0.name.hasSuffix(darkHCSuffix) | ||
} | ||
Comment on lines
-45
to
-50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You must not delete this code. A color style list can contains colors which names doesn't contain prefixes and suffixes for light mode but contain "dark" suffix/prefix for dark mode. Example: "background", "foreground", "dark_background", "dark_foreground". |
||
let darkColors = filteredColors(colors, suffix: darkSuffix) | ||
let lightHCColors = filteredColors(colors, suffix: lightHCSuffix) | ||
let darkHCColors = filteredColors(colors, suffix: darkHCSuffix) | ||
let lightColors = filteredColors(colors, prefix: lightPrefix, suffix: lightSuffix) | ||
let darkColors = filteredColors(colors, prefix: darkPrefix, suffix: darkSuffix) | ||
let lightHCColors = filteredColors(colors, prefix: lightHCPrefix, suffix: lightHCSuffix) | ||
let darkHCColors = filteredColors(colors, prefix: darkHCPrefix, suffix: darkHCSuffix) | ||
return (lightColors, darkColors, lightHCColors, darkHCColors) | ||
} | ||
|
||
private func filteredColors(_ colors: [Color], suffix: String) -> [Color] { | ||
private func filteredColors(_ colors: [Color], prefix: String?, suffix: String?) -> [Color] { | ||
let filteredColors = colors | ||
.filter { $0.name.hasSuffix(suffix) } | ||
.filter { | ||
if let prefix, let suffix { | ||
return $0.name.hasPrefix(prefix) && $0.name.hasSuffix(suffix) | ||
} else if let prefix { | ||
return $0.name.hasPrefix(prefix) | ||
} else if let suffix { | ||
return $0.name.hasSuffix(suffix) | ||
} else { | ||
return true | ||
} | ||
} | ||
.map { color -> Color in | ||
var newColor = color | ||
newColor.name = String(color.name.dropLast(suffix.count)) | ||
newColor.name = String(color.name.dropFirst(prefix?.count ?? 0).dropLast(suffix?.count ?? 0)) | ||
return newColor | ||
} | ||
return filteredColors | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To maintain backward compatibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes no sense for me. Someone can use suffix, someone can use prefix, but not both. So if I only have suffixes in my Figma, how would I configure my figma-export with such default values?