Skip to content
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

feat: add output scripts for swiftui #957

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions src/utils/outputs/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ import {
} from "./index.ts";
import { generateCustomColorClass } from "./web/custom-color-class.ts";
import { generateAndroidReadmeFile } from "./compose/readme.ts";
import { generateSwiftUIColorFile, generateSwiftUIColorScheme } from "./swiftui/colors.ts";
import { generateSwiftUIReadmeFile } from "./swiftui/readme.ts";
import { generateSwiftUIDimensionsFile, generateSwiftUIDimensionsSchemeFile } from "./swiftui/dimensions.ts";
import { generateSwiftUIDensityEnumFile } from "./swiftui/density.ts";
import { generateSwiftUIDesignSystemThemeFile, generateSwiftUIThemeFile } from "./swiftui/theme.ts";
import { designSystemName, generateStaticSwiftUIFiles } from "./swiftui/shared.ts";
import { generateSwiftUIElevationsFile } from "./swiftui/elevation.ts";
import { generateSwiftUIFontFamilyFile, generateSwiftUITypographyFile, generateSwiftUITypographySchemeFile } from "./swiftui/typography.ts";

const download = (fileName: string, file: Blob) => {
const element = document.createElement("a");
Expand Down Expand Up @@ -107,6 +115,64 @@ export const downloadTheme = async (
);
zip.file(`${androidDataFolder}/Density.kt`, generateDensityEnumFile());

// SwiftUI (iOS)
const iOSFileName = kebabCase(fileName);

const iOSFolder: string = "swiftui";
const iOSThemeBrandingName: string = kebabCase(theme.branding.name)
const iOSCoreFolder: string = `${iOSFolder}/core`;
const iOSThemeFolder: string = `${iOSFolder}/${iOSThemeBrandingName}`;
const iOSDataFolder: string = `${iOSThemeFolder}/data`;
zip.file(
`${iOSFolder}/README.md`,
generateSwiftUIReadmeFile(),
);
zip.file(
`${iOSFolder}/${designSystemName}ColorScheme.swift`,
generateSwiftUIColorScheme(iOSFileName, speakingNames, allColors),
);
zip.file(
`${iOSFolder}/${designSystemName}Dimensions.swift`,
generateSwiftUIDimensionsSchemeFile(iOSFileName),
);
zip.file(
`${iOSFolder}/${designSystemName}Typography.swift`,
generateSwiftUITypographySchemeFile(iOSFileName),
);
zip.file(
`${iOSFolder}/${designSystemName}Theme.swift`,
generateSwiftUIDesignSystemThemeFile(iOSThemeBrandingName),
);
// iOS - Theme
zip.file(
`${iOSThemeFolder}/${iOSFileName}.swift`,
generateSwiftUIThemeFile(iOSThemeBrandingName),
);
// iOS - Theme - Date
zip.file(
`${iOSDataFolder}/${iOSThemeBrandingName}Dimensions.swift`,
generateSwiftUIDimensionsFile(iOSThemeBrandingName, theme),
);
zip.file(
`${iOSDataFolder}/${iOSThemeBrandingName}Typography.swift`,
generateSwiftUITypographyFile(iOSThemeBrandingName, theme),
);
zip.file(
`${iOSDataFolder}/${iOSThemeBrandingName}Colors.swift`,
generateSwiftUIColorFile(iOSThemeBrandingName, allColors, luminanceSteps),
);
// iOS - Core
zip.file(
`${iOSCoreFolder}/AdaptiveColors+Descriptive.swift`,
generateStaticSwiftUIFiles()
);
zip.file(`${iOSCoreFolder}/Fonts.swift`, generateSwiftUIFontFamilyFile());
zip.file(
`${iOSCoreFolder}/Elevations.swift`,
generateSwiftUIElevationsFile(theme.elevation),
);
zip.file(`${iOSCoreFolder}/Density.swift`, generateSwiftUIDensityEnumFile());

// Utils
const utilsFolder: string = "Utils";
zip.file(
Expand Down
233 changes: 233 additions & 0 deletions src/utils/outputs/swiftui/AdaptiveColors+Descripitve.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
//
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have any Licence information in other files. Should we remove it here @dennispost?

// Copyright 2024 by DB Systel GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//


import SwiftUI

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

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

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

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

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

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

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

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

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

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

extension DSColorVariant {

public var basic: BasicColor {
.init(
text: .init(
default: .init(
default: onBgBasicEmphasis100Default,
hovered: onBgBasicEmphasis100Hovered,
pressed: onBgBasicEmphasis100Pressed
),
emphasis100: .init(
default: onBgBasicEmphasis100Default,
hovered: onBgBasicEmphasis100Hovered,
pressed: onBgBasicEmphasis100Pressed
),
emphasis90: .init(
default: onBgBasicEmphasis80Default,
hovered: onBgBasicEmphasis80Hovered,
pressed: onBgBasicEmphasis80Pressed
),
emphasis80: .init(
default: onBgBasicEmphasis80Default,
hovered: onBgBasicEmphasis80Hovered,
pressed: onBgBasicEmphasis80Pressed
)
),
icon: .init(
default: .init(
default: onBgBasicEmphasis70Default,
hovered: onBgBasicEmphasis70Hovered,
pressed: onBgBasicEmphasis70Pressed
),
emphasis100: .init(
default: onBgBasicEmphasis100Default,
hovered: onBgBasicEmphasis100Hovered,
pressed: onBgBasicEmphasis100Pressed
),
emphasis90: .init(
default: onBgBasicEmphasis90Default,
hovered: onBgBasicEmphasis90Hovered,
pressed: onBgBasicEmphasis90Pressed
),
emphasis80: .init(
default: onBgBasicEmphasis80Default,
hovered: onBgBasicEmphasis80Hovered,
pressed: onBgBasicEmphasis80Pressed
),
emphasis70: .init(
default: onBgBasicEmphasis70Default,
hovered: onBgBasicEmphasis70Hovered,
pressed: onBgBasicEmphasis70Pressed
)
),
border: .init(
default: .init(
default: onBgBasicEmphasis60Default,
hovered: onBgBasicEmphasis60Hovered,
pressed: onBgBasicEmphasis60Pressed
),
emphasis100: .init(
default: onBgBasicEmphasis100Default,
hovered: onBgBasicEmphasis100Hovered,
pressed: onBgBasicEmphasis100Pressed
),
emphasis70: .init(
default: onBgBasicEmphasis70Default,
hovered: onBgBasicEmphasis70Hovered,
pressed: onBgBasicEmphasis70Pressed
),
emphasis60: .init(
default: onBgBasicEmphasis60Default,
hovered: onBgBasicEmphasis60Hovered,
pressed: onBgBasicEmphasis60Pressed
),
emphasis50: .init(
default: onBgBasicEmphasis50Default,
hovered: onBgBasicEmphasis50Hovered,
pressed: onBgBasicEmphasis50Pressed
)
),
background: .init(
transparent: .init(
full: bgBasicTransparentFullDefault,
semi: bgBasicTransparentSemiDefault,
hovered: bgBasicTransparentHovered,
pressed: bgBasicTransparentPressed
),
level1: .init(
default: bgBasicLevel1Default,
hovered: bgBasicLevel1Hovered,
pressed: bgBasicLevel1Pressed
),
level2: .init(
default: bgBasicLevel2Default,
hovered: bgBasicLevel2Hovered,
pressed: bgBasicLevel2Pressed
),
level3: .init(
default: bgBasicLevel3Default,
hovered: bgBasicLevel3Hovered,
pressed: bgBasicLevel3Pressed
)
)
)
}

public var inverted: InvertedColor {
.init(
background: .init(
contrastMax: .init(
default: bgInvertedContrastMaxDefault,
hovered: bgInvertedContrastMaxHovered,
pressed: bgInvertedContrastMaxPressed
),
contrastHigh: .init(
default: bgInvertedContrastHighDefault,
hovered: bgInvertedContrastHighHovered,
pressed: bgInvertedContrastHighPressed
),
contrastLow: .init(
default: bgInvertedContrastLowDefault,
hovered: bgInvertedContrastLowHovered,
pressed: bgInvertedContrastLowPressed
)
),
onBackground: .init(
default: onBgInvertedDefault,
hovered: onBgInvertedHovered,
pressed: onBgInvertedPressed
)
)
}

public var origin: OriginColor {
.init(
origin: .init(
default: originDefault,
hovered: originHovered,
pressed: originPressed
),
onOrigin: .init(
default: onOriginDefault,
hovered: onOriginHovered,
pressed: onOriginPressed
)
)
}
}
Loading
Loading