Skip to content

Commit

Permalink
[sGen code generator] Adding first version of the FluentUIStyle.yml f…
Browse files Browse the repository at this point in the history
…ile. (#324)

* Adding first version of the FluentUIStyle.yml file.

* Applying multi-line format to YAML file.
  • Loading branch information
rdeassis committed Nov 25, 2020
1 parent 4c4da77 commit dccf5ee
Show file tree
Hide file tree
Showing 6 changed files with 3,166 additions and 27 deletions.
18 changes: 1 addition & 17 deletions tools/sgen/SGen.xcodeproj/xcshareddata/xcschemes/sgen.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,9 @@
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "config run --config $(PROJECT_DIR)/sgenTests/Configs/configWithInputs.yml"
argument = "config run --config $(PROJECT_DIR)/input/StylesheetsConfig.yml"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "config run --config $(PROJECT_DIR)/sgenTests/Configs/configWithImport.yml"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "config run --config $(PROJECT_DIR)/Playground/StardustPlayground/StardustPlayground/StylesheetsConfig.yml"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "config run --config $(PROJECT_DIR)/../Stardust/Playground/StardustPlayground/StardustPlayground/StylesheetsConfig.yml"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "config run --config $(PROJECT_DIR)/StylesheetsConfig.yml"
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
</LaunchAction>
<ProfileAction
Expand Down
28 changes: 20 additions & 8 deletions tools/sgen/Sources/SGen/Generatable/RhsValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ enum RhsValue {
}
}

static func resolveRedirection(rhs: RhsValue) -> RhsValue? {
if rhs.isRedirect == false {
return rhs
}

var redirection = rhs.redirection!
if !redirection.hasPrefix("mainProxy()") {
redirection = "mainProxy().\(redirection)"
}
return .redirect(redirection: RhsRedirectValue(redirection: redirection, type: "Any"))
}

static func valueFrom(_ int: Int) -> RhsValue {
return .int(int: Int(int))
}
Expand Down Expand Up @@ -244,21 +256,21 @@ enum RhsValue {
for component in components {
let parameter = component.trimmingCharacters(in: .whitespacesAndNewlines)
if parameter.hasPrefix("\(Rhs.FluentUIColor.Props.lightKey):") {
light = try? valueFrom(escape(Rhs.FluentUIColor.Props.lightKey, string: parameter))
light = try? resolveRedirection(rhs: valueFrom(escape(Rhs.FluentUIColor.Props.lightKey, string: parameter)))
} else if parameter.hasPrefix("\(Rhs.FluentUIColor.Props.lightHighContrastKey):") {
lightHighContrast = try? valueFrom(escape(Rhs.FluentUIColor.Props.lightHighContrastKey, string: parameter))
lightHighContrast = try? resolveRedirection(rhs: valueFrom(escape(Rhs.FluentUIColor.Props.lightHighContrastKey, string: parameter)))
} else if parameter.hasPrefix("\(Rhs.FluentUIColor.Props.lightElevatedKey):") {
lightElevated = try? valueFrom(escape(Rhs.FluentUIColor.Props.lightElevatedKey, string: parameter))
lightElevated = try? resolveRedirection(rhs: valueFrom(escape(Rhs.FluentUIColor.Props.lightElevatedKey, string: parameter)))
} else if parameter.hasPrefix("\(Rhs.FluentUIColor.Props.lightElevatedHighContrastKey):") {
lightElevatedHighContrast = try? valueFrom(escape(Rhs.FluentUIColor.Props.lightElevatedHighContrastKey, string: parameter))
lightElevatedHighContrast = try? resolveRedirection(rhs: valueFrom(escape(Rhs.FluentUIColor.Props.lightElevatedHighContrastKey, string: parameter)))
} else if parameter.hasPrefix("\(Rhs.FluentUIColor.Props.darkKey):") {
dark = try? valueFrom(escape(Rhs.FluentUIColor.Props.darkKey, string: parameter))
dark = try? resolveRedirection(rhs: valueFrom(escape(Rhs.FluentUIColor.Props.darkKey, string: parameter)))
} else if parameter.hasPrefix("\(Rhs.FluentUIColor.Props.darkHighContrastKey):") {
darkHighContrast = try? valueFrom(escape(Rhs.FluentUIColor.Props.darkHighContrastKey, string: parameter))
darkHighContrast = try? resolveRedirection(rhs: valueFrom(escape(Rhs.FluentUIColor.Props.darkHighContrastKey, string: parameter)))
} else if parameter.hasPrefix("\(Rhs.FluentUIColor.Props.darkElevatedKey):") {
darkElevated = try? valueFrom(escape(Rhs.FluentUIColor.Props.darkElevatedKey, string: parameter))
darkElevated = try? resolveRedirection(rhs: valueFrom(escape(Rhs.FluentUIColor.Props.darkElevatedKey, string: parameter)))
} else if parameter.hasPrefix("\(Rhs.FluentUIColor.Props.darkElevatedHighContrastKey):") {
darkElevatedHighContrast = try? valueFrom(escape(Rhs.FluentUIColor.Props.darkElevatedHighContrastKey, string: parameter))
darkElevatedHighContrast = try? resolveRedirection(rhs: valueFrom(escape(Rhs.FluentUIColor.Props.darkElevatedHighContrastKey, string: parameter)))
} else {
fatalError("Invalid FluentUIColor parameter: \(parameter)")
}
Expand Down
6 changes: 4 additions & 2 deletions tools/sgen/Sources/SGen/Generatable/Stylesheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ private extension \(textStyleType) {
var defaultPointSize: CGFloat? {
switch self {
"""

var needsDefaultCase: Bool = false
Expand All @@ -927,7 +928,7 @@ private extension \(textStyleType) {
if needsDefaultCase {
header += """
default:
return nil"
return nil
"""
}

Expand All @@ -938,6 +939,7 @@ private extension \(textStyleType) {
var maximumPointSize: CGFloat? {
switch self {
"""

needsDefaultCase = false
Expand All @@ -957,7 +959,7 @@ private extension \(textStyleType) {
if needsDefaultCase {
header += """
default:
return nil"
return nil
"""
}

Expand Down
163 changes: 163 additions & 0 deletions tools/sgen/input/FluentUIStyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
Colors:
Brand:
- primary: "FluentUIColor(light: #0078D4, dark: #0086F0)"
- shade10: "FluentUIColor(light: #106EBE, dark: #1890F1)"
- shade20: "FluentUIColor(light: #005A9E, dark: #3AA0F3)"
- shade30: "FluentUIColor(light: #004578, dark: #6CB8F6)"
- tint10: "FluentUIColor(light: #2B88D8, dark: #0078D4)"
- tint20: "FluentUIColor(light: #C7E0F4, dark: #004C87)"
- tint30: "FluentUIColor(light: #DEECF9, dark: #043862)"
- tint40: "FluentUIColor(light: #EFF6FC, dark: #092C47)"

Neutral:
- clear: "#00000000"
- black: "#000000"
- grey2: "#050505"
- grey4: "#0A0A0A"
- grey6: "#0F0F0F"
- grey8: "#141414"
- grey10: "#1A1A1A"
- grey12: "#1F1F1F"
- grey14: "#242424"
- grey16: "#292929"
- grey18: "#2E2E2E"
- grey20: "#333333"
- grey22: "#383838"
- grey24: "#3D3D3D"
- grey26: "#424242"
- grey28: "#474747"
- grey30: "#4D4D4D"
- grey32: "#525252"
- grey34: "#575757"
- grey36: "#5C5C5C"
- grey38: "#616161"
- grey40: "#666666"
- grey42: "#6B6B6B"
- grey44: "#707070"
- grey46: "#757575"
- grey48: "#7A7A7A"
- grey50: "#808080"
- grey52: "#858585"
- grey54: "#8A8A8A"
- grey56: "#8F8F8F"
- grey58: "#949494"
- grey60: "#999999"
- grey62: "#9E9E9E"
- grey64: "#A3A3A3"
- grey66: "#A8A8A8"
- grey68: "#ADADAD"
- grey70: "#B2B2B2"
- grey72: "#B8B8B8"
- grey74: "#BDBDBD"
- grey76: "#C2C2C2"
- grey78: "#C7C7C7"
- grey80: "#CCCCCC"
- grey82: "#D1D1D1"
- grey84: "#D6D6D6"
- grey86: "#DBDBDB"
- grey88: "#E0E0E0"
- grey90: "#E5E5E5"
- grey92: "#EBEBEB"
- grey94: "#F0F0F0"
- grey96: "#F5F5F5"
- grey98: "#FAFAFA"
- white: "#FFFFFF"

Background:
- neutral1: "FluentUIColor(light: $Colors.Neutral.white, dark: $Colors.Neutral.black, darkElevated: $Colors.Neutral.grey4)"
- neutral2: "FluentUIColor(light: $Colors.Neutral.grey98, dark: $Colors.Neutral.grey4, darkElevated: $Colors.Neutral.grey8)"
- neutral3: "FluentUIColor(light: $Colors.Neutral.grey96, dark: $Colors.Neutral.grey8, darkElevated: $Colors.Neutral.grey16)"
- neutral4: "FluentUIColor(light: $Colors.Neutral.grey94, dark: $Colors.Neutral.grey16, darkElevated: $Colors.Neutral.grey24)"
- neutral5: "FluentUIColor(light: $Colors.Neutral.grey92, dark: $Colors.Neutral.grey36)"
- neutralDisabled: "FluentUIColor(light: $Colors.Neutral.grey88, dark: $Colors.Neutral.grey84)"
- brandRest: "FluentUIColor(light: $Colors.Brand.primary, dark: $Colors.Brand.primary)"
- brandHover: "FluentUIColor(light: $Colors.Brand.shade10, dark: $Colors.Brand.shade10)"
- brandPressed: "FluentUIColor(light: $Colors.Brand.shade30, dark: $Colors.Brand.shade30)"
- brandSelected: "FluentUIColor(light: $Colors.Brand.shade20, dark: $Colors.Brand.shade20)"
- brandDisabled: "FluentUIColor(light: $Colors.Neutral.grey88, dark: $Colors.Neutral.grey84)"

Foreground:
- neutral1: "FluentUIColor(light: $Colors.Neutral.grey14, lightHighContrast: $Colors.Neutral.black, dark: $Colors.Neutral.white)"
- neutral2: "FluentUIColor(light: $Colors.Neutral.grey26, lightHighContrast: $Colors.Neutral.black, dark: $Colors.Neutral.grey84, darkHighContrast: $Colors.Neutral.white)"
- neutral3: "FluentUIColor(light: $Colors.Neutral.grey38, lightHighContrast: $Colors.Neutral.grey14, dark: $Colors.Neutral.grey68, darkHighContrast: $Colors.Neutral.grey84)"
- neutral4: "FluentUIColor(light: $Colors.Neutral.grey50, lightHighContrast: $Colors.Neutral.grey26, dark: $Colors.Neutral.grey52, darkHighContrast: $Colors.Neutral.grey84)"
- neutralDisabled: "FluentUIColor(light: $Colors.Neutral.grey74, lightHighContrast: $Colors.Neutral.grey38, dark: $Colors.Neutral.grey36, darkHighContrast: $Colors.Neutral.grey62)"
- neutralInverted: "FluentUIColor(light: $Colors.Neutral.white, dark: $Colors.Neutral.black)"
- brandRest: "FluentUIColor(light: $Colors.Brand.primary, lightHighContrast: $Colors.Brand.shade20, dark: $Colors.Brand.primary, darkHighContrast: $Colors.Brand.tint20)"
- brandHover: "FluentUIColor(light: $Colors.Brand.shade10, dark: $Colors.Brand.shade10)"
- brandPressed: "FluentUIColor(light: $Colors.Brand.shade30, dark: $Colors.Brand.shade30)"
- brandSelected: "FluentUIColor(light: $Colors.Brand.shade20, dark: $Colors.Brand.shade20)"
- brandDisabled: "FluentUIColor(light: $Colors.Neutral.grey74, dark: $Colors.Neutral.grey36)"

Stroke:
- neutral1: "FluentUIColor(light: $Colors.Neutral.grey94, lightHighContrast: $Colors.Neutral.grey38, dark: $Colors.Neutral.grey24, darkHighContrast: $Colors.Neutral.grey68, darkElevated: $Colors.Neutral.grey32)"
- neutral2: "FluentUIColor(light: $Colors.Neutral.grey88, lightHighContrast: $Colors.Neutral.grey38, dark: $Colors.Neutral.grey32, darkHighContrast: $Colors.Neutral.grey68, darkElevated: $Colors.Neutral.grey36)"
- neutral3: "FluentUIColor(light: $Colors.Neutral.grey82, lightHighContrast: $Colors.Neutral.grey38, dark: $Colors.Neutral.grey40, darkHighContrast: $Colors.Neutral.grey68, darkElevated: $Colors.Neutral.grey52)"
- neutralDisabled: "FluentUIColor(light: $Colors.Neutral.grey88, dark: $Colors.Neutral.grey32)"
- neutralAccessible: "FluentUIColor(light: $Colors.Neutral.grey38, lightHighContrast: $Colors.Neutral.grey14, dark: $Colors.Neutral.grey68, darkHighContrast: $Colors.Neutral.grey84, darkElevated: $Colors.Neutral.grey68)"
- brandRest: "FluentUIColor(light: $Colors.Brand.primary, dark: $Colors.Brand.primary)"
- brandHover: "FluentUIColor(light: $Colors.Brand.shade10, dark: $Colors.Brand.shade10)"
- brandPressed: "FluentUIColor(light: $Colors.Brand.shade30, dark: $Colors.Brand.shade30)"
- brandSelected: "FluentUIColor(light: $Colors.Brand.shade20, dark: $Colors.Brand.shade20)"
- brandDisabled: "FluentUIColor(light: $Colors.Neutral.grey88, dark: $Colors.Neutral.grey84)"

Typography:
subheadline: "Font(subheadline)"
footnote: "Font(footnote)"

Border:
radius: [ none: 0pt, small: 2pt, medium: 4pt, large: 8pt, xlarge: 12pt ]
size: [ none: 0pt, thin: 1pt, thick: 2pt, thicker: 4pt, thickest: 6pt ]

Icon:
style: EnumDef(regular, filled)
size: [ xxxSmall: 10pt, xxSmall: 12pt, xSmall: 16pt, small: 20pt, medium: 24pt, large: 28pt, xlarge: 36pt, xxlarge: 40pt, xxxlarge: 48pt ]

Spacing:
none: 0pt
xxxSmall: 2pt
xxSmall: 4pt
xSmall: 8pt
small: 12pt
medium: 16pt
large: 20pt
xlarge: 24pt
xxlarge: 36pt
xxxlarge: 48pt
xxxxlarge: 72pt

Opacity:
opacity8: 0.8f
opacity16: 0.16f
opacity24: 0.24f
opacity32: 0.32f
opacity64: 0.64f
opacity72: 0.72f
opacity88: 0.88f
opacity96: 0.96f
none: 1f

AP_MSFButton:
backgroundColor: [ rest: $Colors.Neutral.clear, hover: $Colors.Neutral.clear, pressed: $Colors.Neutral.clear, selected: $Colors.Neutral.clear, disabled: $Colors.Neutral.clear ]
borderColor: [ rest: $Colors.Background.brandRest, hover: $Colors.Background.brandHover, pressed: $Colors.Background.brandPressed, selected: $Colors.Background.brandSelected, disabled: $Colors.Background.brandDisabled ]
borderRadius: [ small: $Border.radius.medium, medium: $Border.radius.large, large: $Border.radius.xlarge ]
borderSize: [ small: $Border.size.none, medium: $Border.size.none, large: $Border.size.none ]
iconColor: [ rest: $Colors.Foreground.brandRest, hover: $Colors.Foreground.brandHover, pressed: $Colors.Foreground.brandPressed, selected: $Colors.Foreground.brandSelected, disabled: $Colors.Foreground.brandDisabled ]
iconSize: [ small: $Icon.size.xSmall, medium: $Icon.size.small, large: $Icon.size.small ]
interspace: [ small: $Spacing.xxSmall, medium: $Spacing.xSmall, large: $Spacing.xSmall ]
padding: [ small: $Spacing.xSmall, medium: $Spacing.small, large: $Spacing.large ]
textColor: [ rest: $Colors.Foreground.brandRest, hover: $Colors.Foreground.brandHover, pressed: $Colors.Foreground.brandPressed, selected: $Colors.Foreground.brandSelected, disabled: $Colors.Foreground.brandDisabled ]
textFont: [ small: $Typography.footnote, medium: $Typography.subheadline, large: $Typography.subheadline ]

PrimaryButton extends MSFButton:
backgroundColor: [ rest: $Colors.Background.brandRest, hover: $Colors.Background.brandHover, pressed: $Colors.Background.brandPressed, selected: $Colors.Background.brandSelected, disabled: $Colors.Background.brandDisabled ]
iconColor: [ rest: $Colors.Foreground.neutralInverted, hover: $Colors.Foreground.neutralInverted, pressed: $Colors.Foreground.neutralInverted, selected: $Colors.Foreground.neutralInverted, disabled: $Colors.Foreground.neutralInverted ]
textColor: [ rest: $Colors.Foreground.neutralInverted, hover: $Colors.Foreground.neutralInverted, pressed: $Colors.Foreground.neutralInverted, selected: $Colors.Foreground.neutralInverted, disabled: $Colors.Foreground.neutralInverted ]

SecondaryButton extends MSFButton:
borderColor: [ rest: $Colors.Stroke.brandRest, hover: $Colors.Stroke.brandHover, pressed: $Colors.Stroke.brandPressed, selected: $Colors.Stroke.brandSelected, disabled: $Colors.Stroke.brandDisabled ]
borderSize: [ small: $Border.size.thin, medium: $Border.size.thin, large: $Border.size.thin ]

GhostButton extends MSFButton:
borderColor: [ rest: $Colors.Neutral.clear, hover: $Colors.Neutral.clear, pressed: $Colors.Neutral.clear, selected: $Colors.Brand.shade10, disabled: $Colors.Neutral.clear ]

20 changes: 20 additions & 0 deletions tools/sgen/input/StylesheetsConfig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
objc: true
generateBaseStyle: true
inputDir: ./
inputs:
- FluentUIStyle.yml
typography:
styles:
- largeTitle: { mapsTo: largeTitle }
- title1: { mapsTo: title1 }
- title2: { mapsTo: title2 }
- title3: { mapsTo: title3 }
- headline: { mapsTo: headline }
- body: { mapsTo: body }
- callout: { mapsTo: callout }
- subheadline: { mapsTo: subheadline }
- footnote: { mapsTo: footnote }
- caption1: { mapsTo: caption1 }
- caption2: { mapsTo: caption2 }
output:
path: ../output/
Loading

0 comments on commit dccf5ee

Please sign in to comment.