Skip to content

Commit

Permalink
renaming & add accessor visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
dennispost committed Oct 15, 2024
1 parent 34e1240 commit e1c42a0
Show file tree
Hide file tree
Showing 8 changed files with 464 additions and 291 deletions.
95 changes: 48 additions & 47 deletions src/utils/outputs/swiftui/AdaptiveColors+Descripitve.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,75 +14,76 @@
// limitations under the License.
//


import SwiftUI

struct BasicColor {
var text: TextColor
var icon: IconColor
var border: BorderColor
var background: BackgroundColor
public struct BasicColor {
public var text: TextColor
public var icon: IconColor
public var border: BorderColor
public var background: BackgroundColor
}

struct InvertedBackgroundColor {
var contrastMax: StateColor
var contrastHigh: StateColor
var contrastLow: StateColor
public struct InvertedBackgroundColor {
public var contrastMax: StateColor
public var contrastHigh: StateColor
public var contrastLow: StateColor
}

struct InvertedColor {
var background: InvertedBackgroundColor
var onBackground: StateColor
public struct InvertedColor {
public var background: InvertedBackgroundColor
public var onBackground: StateColor
}

struct OriginColor {
var origin: StateColor
var onOrigin: StateColor
public struct OriginColor {
public var origin: StateColor
public var onOrigin: StateColor
}

struct TextColor {
var `default`: StateColor
var emphasis100: StateColor
var emphasis90: StateColor
var emphasis80: StateColor
public struct TextColor {
public var `default`: StateColor
public var emphasis100: StateColor
public var emphasis90: StateColor
public var emphasis80: StateColor
}

struct IconColor {
var `default`: StateColor
var emphasis100: StateColor
var emphasis90: StateColor
var emphasis80: StateColor
var emphasis70: StateColor
public struct IconColor {
public var `default`: StateColor
public var emphasis100: StateColor
public var emphasis90: StateColor
public var emphasis80: StateColor
public var emphasis70: StateColor
}

struct BorderColor {
var `default`: StateColor
var emphasis100: StateColor
var emphasis70: StateColor
var emphasis60: StateColor
var emphasis50: StateColor
public struct BorderColor {
public var `default`: StateColor
public var emphasis100: StateColor
public var emphasis70: StateColor
public var emphasis60: StateColor
public var emphasis50: StateColor
}

struct BackgroundColor {
var transparent: TransparentColor
var level1: StateColor
var level2: StateColor
var level3: StateColor
public struct BackgroundColor {
public var transparent: TransparentColor
public var level1: StateColor
public var level2: StateColor
public var level3: StateColor
}

struct TransparentColor {
var full: Color
var semi: Color
var hovered: Color
var pressed: Color
public struct TransparentColor {
public var full: Color
public var semi: Color
public var hovered: Color
public var pressed: Color
}

struct StateColor {
var `default`: Color
var hovered: Color
var pressed: Color
public struct StateColor {
public var `default`: Color
public var hovered: Color
public var pressed: Color
}

extension AdaptiveColors {
extension DSColorVariant {

public var basic: BasicColor {
.init(
Expand Down
54 changes: 24 additions & 30 deletions src/utils/outputs/swiftui/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ let ${fileName}Colors: [String: Color] = [
return resolvedTokenFile;
};

const generateSwiftUIAdaptiveColorsExtension = (
const generateSwiftUIColorVariantExtension = (
speakingNames: SpeakingName[],
resolvedScheme: string,
darkMode: boolean
Expand Down Expand Up @@ -102,26 +102,27 @@ const generateSwiftUIColorSchemeDarkLight = (
resolvedScheme: string,
darkMode?: boolean,
): string => {
const colorScheme = kebabCase(darkMode ? "dark" : "light");
console.log(fileName)
const colorScheme = kebabCase(darkMode ? "dark" : "light");

resolvedScheme += `\nfunc getColorScheme${colorScheme}(colors: [String: Color]) -> ${designSystemName}ColorScheme {\n`
resolvedScheme += `\n static func getColorScheme${colorScheme}(colors: [String: Color]) -> ${designSystemName}ColorScheme {\n`
for (const name of colorKeys) {
resolvedScheme += `
var ${name.toLowerCase()}Colors${colorScheme}: AdaptiveColors {
.init(.${colorScheme.toLowerCase()}, colorName: "${name.toLowerCase()}", colors: colors)
}\n\n`;
}
var ${name.toLowerCase()}Colors${colorScheme}: DSColorVariant {
.init(.${colorScheme.toLowerCase()}, colorName: "${name.toLowerCase()}", colors: colors)
}\n`;
}
resolvedScheme += `
return .init(\n`;
return .init(\n`;
colorKeys.forEach((name, index) => {
resolvedScheme += ` ${name}: ${name}Colors${colorScheme}`;
resolvedScheme += ` ${name}: ${name}Colors${colorScheme}`;
// if not last element:
if (index < colorKeys.length - 1) {
resolvedScheme += `,\n`
}
});
resolvedScheme += `\n )\n}\n`;
resolvedScheme += `\n )\n }\n`;

return resolvedScheme;
};
Expand Down Expand Up @@ -149,52 +150,43 @@ extension Color {
`;

// 1. Generate generic AdaptiveColors protocol'
// 1. Generate generic DSColorVariant protocol'
const name = colorKeys[0]
const allSpeakingNames = [...speakingNames, ...originAdditionalColors];
resolvedScheme += `struct AdaptiveColors {\n`;
resolvedScheme += `public struct DSColorVariant {\n`;
for (const speakingName of allSpeakingNames) {
const resolvedName = `${kebabCase(speakingName.name, true)}`;
resolvedNames[`${name}${speakingName.name}`] = resolvedName;
resolvedScheme += ` let ${resolvedName}: Color\n\n`;
resolvedScheme += ` public let ${resolvedName}: Color\n`;
}

resolvedScheme += ` init(_ scheme: DBColorScheme, colorName: String, colors: [String: Color]) {
resolvedScheme += `\n init(_ scheme: DSColorScheme, colorName: String, colors: [String: Color]) {
switch scheme {
case .dark:
`;

resolvedScheme = generateSwiftUIAdaptiveColorsExtension(
resolvedScheme = generateSwiftUIColorVariantExtension(
speakingNames,
resolvedScheme,
true
);

resolvedScheme += `
case .light:
`;
resolvedScheme += `\n case .light:\n`;

resolvedScheme = generateSwiftUIAdaptiveColorsExtension(
resolvedScheme = generateSwiftUIColorVariantExtension(
speakingNames,
resolvedScheme,
false
);

resolvedScheme += `
}
}
`

resolvedScheme += `}\n\n`;
resolvedScheme += `\n }\n }\n}\n\n`;

// 2. Generate ColorSchemes for semantic colors
resolvedScheme += `struct ${designSystemName}ColorScheme {\n`;
resolvedScheme += `public struct ${designSystemName}ColorScheme {\n`;
for (const name of colorKeys) {
resolvedScheme += ` let ${name}: AdaptiveColors\n`;
resolvedScheme += ` public let ${name}: DSColorVariant\n`;
}

resolvedScheme += `}\n`;

resolvedScheme = generateSwiftUIColorSchemeDarkLight(
fileName,
colorKeys,
Expand All @@ -209,8 +201,10 @@ extension Color {
false,
);

resolvedScheme += `\n}\n\n`;

resolvedScheme += `
enum DBColorScheme {
enum DSColorScheme {
case light
case dark
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/outputs/swiftui/density.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { densities } from "./shared.ts";

export const generateSwiftUIDensityEnumFile = (): string => {
let resolvedString: string = "enum Density: String {\n";
let resolvedString: string = "enum DSDensity: String {\n";

densities.forEach( density => {
resolvedString += ` case ${density.toLowerCase()} = "${density}"\n`;
Expand Down
Loading

0 comments on commit e1c42a0

Please sign in to comment.