Skip to content

Commit

Permalink
feat: add code samples to show how to use token in tokens pages of de…
Browse files Browse the repository at this point in the history
…mo app (#283) (#297)

Signed-off-by: Pierre-Yves Lapersonne <[email protected]>
Co-authored-by: Ludovic PINEL <[email protected]>
  • Loading branch information
Tayebsed93 and ludovic35 authored Nov 29, 2024
1 parent 4baef6c commit dcd69ea
Show file tree
Hide file tree
Showing 21 changed files with 260 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- [DemoApp] Add code sample for tokens usages in token pages ([#283](https://github.com/Orange-OpenSource/ouds-ios/issues/283))
- [Library] Color some new semantic tokens `colorContentStatus*`, `colorContentOnBrand*`, `colorContentOnStatus*`, `colorGradient*`, `colorBorder*`, `colorContentOnAction*`
- [Tool] Add UI tests in CI/CD pipelines ([#298](https://github.com/Orange-OpenSource/ouds-ios/issues/298))
- [DemoApp] Add more UI tests on demo app ([#154](https://github.com/Orange-OpenSource/ouds-ios/issues/154))
Expand Down
3 changes: 3 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Any use or displaying shall constitute an infringement under intellectual proper
./Showcase/Showcase/Resources/Assets.xcassets/Illustrations/il_tokens_grid_max_width.imageset/il_tokens_grid_max_width_dark.png
./Showcase/Showcase/Resources/Assets.xcassets/Illustrations/il_tokens_grid_min_width.imageset/il_tokens_grid_min_width.png
./Showcase/Showcase/Resources/Assets.xcassets/Illustrations/il_tokens_grid_min_width.imageset/il_tokens_grid_min_width_dark.png
./Showcase/Showcase/Resources/Assets.xcassets/Tokens/ic_chevron-down.imageset/ic_chevron-down.png
./Showcase/Showcase/Resources/Assets.xcassets/Tokens/ic_chevron-up.imageset/ic_chevron-up.png
./Showcase/Showcase/Resources/Assets.xcassets/Tokens/ic_copy.imageset/ic_copy.png
./Showcase/Showcase/Resources/Assets.xcassets/Tokens/ic_border.imageset/ic_border.svg
./Showcase/Showcase/Resources/Assets.xcassets/Tokens/ic_dimension.imageset/ic_dimension.svg
./Showcase/Showcase/Resources/Assets.xcassets/Tokens/ic_filter_effects.imageset/ic_filter_effects.svg
Expand Down
30 changes: 30 additions & 0 deletions Showcase/Showcase.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
6D24658E2CBEAC750023E359 /* BorderTokenPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07CF42822CA45DA9000BD03E /* BorderTokenPage.swift */; };
6D2465902CBEAEE40023E359 /* ShowcaseTokenIllustration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 075114E72CB81F0E00B8B759 /* ShowcaseTokenIllustration.swift */; };
6D3E872C2CCBE0A300AEB105 /* OUDSTokenBorderUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D3E872B2CCBE0A300AEB105 /* OUDSTokenBorderUITests.swift */; };
6D43136D2CEF400D004E6886 /* ShowcaseTokenCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DCC57E12CEB984D000F35F8 /* ShowcaseTokenCode.swift */; };
6D8F9C4E2CBFDC380078A10E /* ComponentsPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51BD760D2C466FCF0033365D /* ComponentsPage.swift */; };
6D8F9C4F2CBFDC8B0078A10E /* EmptyState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 074794792CAE882A0033C2D8 /* EmptyState.swift */; };
6D8F9C502CC14EBF0078A10E /* OpacityTokenPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07CF427E2CA41325000BD03E /* OpacityTokenPage.swift */; };
Expand All @@ -154,6 +155,7 @@
6DB260E42CD0F0520091F72E /* NameSpace+GapStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07F75A402CC653EB0004F1AD /* NameSpace+GapStack.swift */; };
6DB260E52CD0F0520091F72E /* NameSpace+PaddingInlineWithArrow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07F0FA8B2CC9408C000F166F /* NameSpace+PaddingInlineWithArrow.swift */; };
6DB260E62CD0F07D0091F72E /* NamedTypography+Illustration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0784B2772CCBDD8900299C10 /* NamedTypography+Illustration.swift */; };
6DCC57E22CEB984D000F35F8 /* ShowcaseTokenCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DCC57E12CEB984D000F35F8 /* ShowcaseTokenCode.swift */; };
6DE5F47D2CC696120008E774 /* ThemeSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07CF42882CA55BC8000BD03E /* ThemeSelection.swift */; };
6DED17E92CD1143500584BC9 /* OUDSTokensSizeUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DED17E82CD1143500584BC9 /* OUDSTokensSizeUITests.swift */; };
6DED17EB2CD114AD00584BC9 /* OUDSTokensSpaceUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DED17EA2CD114AD00584BC9 /* OUDSTokensSpaceUITests.swift */; };
Expand Down Expand Up @@ -292,6 +294,9 @@
6D3E872B2CCBE0A300AEB105 /* OUDSTokenBorderUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = OUDSTokenBorderUITests.swift; path = ShowcaseTests/__Snapshots__/OUDSTokensBorderUITests/OUDSTokenBorderUITests.swift; sourceTree = SOURCE_ROOT; };
6DED17E82CD1143500584BC9 /* OUDSTokensSizeUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = OUDSTokensSizeUITests.swift; path = ShowcaseTests/__Snapshots__/OUDSTokensDimensionUITests/Size/OUDSTokensSizeUITests.swift; sourceTree = SOURCE_ROOT; };
6DED17EA2CD114AD00584BC9 /* OUDSTokensSpaceUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = OUDSTokensSpaceUITests.swift; path = ShowcaseTests/__Snapshots__/OUDSTokensDimensionUITests/Space/OUDSTokensSpaceUITests.swift; sourceTree = SOURCE_ROOT; };
6DCC57E12CEB984D000F35F8 /* ShowcaseTokenCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShowcaseTokenCode.swift; sourceTree = "<group>"; };
6DED17E82CD1143500584BC9 /* OUDSTokensSizeUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = OUDSTokensSizeUITests.swift; path = ShowcaseTests/__Snapshots__/OUDSTokensDimensionUITests/Size/OUDSTokensSizeUITests.swift; sourceTree = SOURCE_ROOT; };
6DED17EA2CD114AD00584BC9 /* OUDSTokensSpaceUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = OUDSTokensSpaceUITests.swift; path = ShowcaseTests/__Snapshots__/OUDSTokensDimensionUITests/Space/OUDSTokensSpaceUITests.swift; sourceTree = SOURCE_ROOT; };
6DFC208A2CDE669500F2EC33 /* AccessibilityStatementPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccessibilityStatementPage.swift; sourceTree = "<group>"; };
6DFC20B02CE3AF1500F2EC33 /* boosted-grid.min.css */ = {isa = PBXFileReference; lastKnownFileType = text.css; path = "boosted-grid.min.css"; sourceTree = "<group>"; };
6DFC20B12CE3AF1500F2EC33 /* favicon.ico */ = {isa = PBXFileReference; lastKnownFileType = image.ico; path = favicon.ico; sourceTree = "<group>"; };
Expand Down Expand Up @@ -364,6 +369,7 @@
077CCE5B2CB431C50059CC28 /* ShowcaseVariantElement.swift */,
075114E72CB81F0E00B8B759 /* ShowcaseTokenIllustration.swift */,
075C71342CEB9BD200B93FC3 /* ShowcaseTokkenIllustrationBackground.swift */,
6DCC57E12CEB984D000F35F8 /* ShowcaseTokenCode.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -769,6 +775,28 @@
path = accessibilityStatement;
sourceTree = "<group>";
};
6DFC20892CDE664400F2EC33 /* AccessibilityStatement */ = {
isa = PBXGroup;
children = (
6DFC208A2CDE669500F2EC33 /* AccessibilityStatementPage.swift */,
);
path = AccessibilityStatement;
sourceTree = "<group>";
};
6DFC209B2CDF92D500F2EC33 /* accessibilityStatement */ = {
isa = PBXGroup;
children = (
6DFC20BF2CE3D39D00F2EC33 /* accessibility_detail.html */,
6DFC20C02CE3D39D00F2EC33 /* accessibility_result.xml */,
6DFC20B02CE3AF1500F2EC33 /* boosted-grid.min.css */,
6DFC20B12CE3AF1500F2EC33 /* favicon.ico */,
6DFC20B22CE3AF1500F2EC33 /* orange-logo.svg */,
6DFC20B32CE3AF1500F2EC33 /* pie.css */,
6DFC20B42CE3AF1500F2EC33 /* style.css */,
);
path = accessibilityStatement;
sourceTree = "<group>";
};
6E90D400B72B50FE406E8DFC /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -988,6 +1016,7 @@
buildActionMask = 2147483647;
files = (
51ED41052CF8AF2C007AB814 /* NamedColor+Gradient.swift in Sources */,
6D43136D2CEF400D004E6886 /* ShowcaseTokenCode.swift in Sources */,
6DED17F12CD2641800584BC9 /* OpacityTokenElement.swift in Sources */,
6DED17F02CD25CB000584BC9 /* TokenElement.swift in Sources */,
6DED17EF2CD25B2200584BC9 /* SizeTokenElement.swift in Sources */,
Expand Down Expand Up @@ -1087,6 +1116,7 @@
51BD76232C466FCF0033365D /* ShowcaseElementsPage.swift in Sources */,
0765B49C2CC15B2E00E69359 /* NamedColor+Elevation.swift in Sources */,
6DFC208B2CDE669500F2EC33 /* AccessibilityStatementPage.swift in Sources */,
6DCC57E22CEB984D000F35F8 /* ShowcaseTokenCode.swift in Sources */,
51E3FF0B2CAFD9AE00F1BC59 /* ShowcaseElementPage.swift in Sources */,
0765B4942CC1597C00E69359 /* NamedColor+Background.swift in Sources */,
075C71372CECC3D800B93FC3 /* SpacePaddingTokenIllustrations.swift in Sources */,
Expand Down
6 changes: 5 additions & 1 deletion Showcase/Showcase/Pages/Tokens/Border/BorderTokenPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ struct BorderTokenPage: View {
}

// MARK: Body

var body: some View {
VStack(alignment: .leading, spacing: activeTheme.spaceFixedMedium) {
Section {
VStack(alignment: .leading, spacing: activeTheme.spaceFixedNone) {
ShowcaseTokenCode(code: "theme.borderWidthDefault")
}
}
Section {
VStack(alignment: .leading, spacing: activeTheme.spaceFixedNone) {
ForEach(NamedBorderWidth.allCases, id: \.rawValue) { namedWidth in
Expand Down
3 changes: 3 additions & 0 deletions Showcase/Showcase/Pages/Tokens/Color/ColorTokenPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ struct ColorTokenPage: View {

var body: some View {
Group {
Section {
ShowcaseTokenCode(code: "theme.colorBgPrimary.color(for: colorScheme)")
}
Section { illustrationForBackground() } header: { header("Background") }
Section { illustrationForAction() } header: { header("Action") }
Section { illustrationForAlways() } header: { header("Always") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ struct SizeTokenPage: View {

var body: some View {
Group {
Section {
ShowcaseTokenCode(code: "theme.sizeIconWithHeadingXLargeShort.dimension(for: horizontalSizeClass ?? .regular)")
}
Section { illustrationForIconDecorative() } header: {
header("app_tokens_dimension_size_iconDecorative_label")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ struct SpaceTokenPage: View {

var body: some View {
Group {
Section {
ShowcaseTokenCode(code: "theme.spaceScaledMedium.dimension(for: horizontalSizeClass ?? .regular)")
}
// Basic Space Tokens
Section { ScaledSpacesCategory() } header: {
header("app_tokens_dimension_space_scaled_label")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ struct ElevationTokenPage: View {

var body: some View {
VStack(alignment: .leading, spacing: activeTheme.spaceFixedNone) {
Section {
ShowcaseTokenCode(code: "theme.elevationNone.elevation(for: colorScheme)")
}
Spacer()
.frame(height: activeTheme.spaceFixedMedium)
ForEach(NamedElevation.allCases, id: \.rawValue) { elevationName in
illustration(for: elevationName)
}
Expand Down
4 changes: 4 additions & 0 deletions Showcase/Showcase/Pages/Tokens/Grid/GrisTokenPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ struct GridTokenPage: View {
.background(theme.colorBgEmphasized.color(for: colorScheme))
}

Section {
ShowcaseTokenCode(code: "theme.gridColumnCount(for: horizontalSizeClass)")
}

Section { illustrationForGridTokens() } header: {
Text(horizontalSizeClass.rawValue)
.showcaseSectionHeaderStyle()
Expand Down
5 changes: 5 additions & 0 deletions Showcase/Showcase/Pages/Tokens/Opacity/OpacityTokenPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ struct OpacityTokenPage: View {

var body: some View {
VStack(alignment: .leading, spacing: activeTheme.spaceFixedNone) {
Section {
ShowcaseTokenCode(code: "theme.opacityTransparent")
}
Spacer()
.frame(height: activeTheme.spaceFixedMedium)
ForEach(NamedOpacity.allCases, id: \.rawValue) { opmacityName in
illustration(for: opmacityName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ struct TypographyTokenPage: View {

var body: some View {
VStack(alignment: .leading, spacing: activeTheme.spaceFixedNone) {
Section {
ShowcaseTokenCode(code: "theme.typeBodyStrongLarge(theme)")
}
Spacer()
ForEach(NamedTypography.allCases, id: \.rawValue) { typographyName in
illustration(from: typographyName)
}
Expand Down
2 changes: 1 addition & 1 deletion Showcase/Showcase/Pages/Utils/ShowcaseElementPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct ShowcaseElementPage: View {
// MARK: Body

var body: some View {
List {
ScrollView {
VStack(alignment: .leading, spacing: theme.spaceFixedMedium) {
CardIllustration(icon: Image(element.imageName))
.accessibilityHidden(true)
Expand Down
114 changes: 114 additions & 0 deletions Showcase/Showcase/Pages/Utils/ShowcaseTokenCode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
//
// Software Name: OUDS iOS
// SPDX-FileCopyrightText: Copyright (c) Orange SA
// SPDX-License-Identifier: MIT
//
// This software is distributed under the MIT license,
// the text of which is available at https://opensource.org/license/MIT/
// or see the "LICENSE" file for more details.
//
// Authors: See CONTRIBUTORS.txt
// Software description: A SwiftUI components library with code examples for Orange Unified Design System
//

import OUDS
import OUDSTokensSemantic
import SwiftUI

struct ShowcaseTokenCode: View {

// MARK: Environment properties

@Environment(\.theme) private var theme
@Environment(\.colorScheme) private var colorScheme

// MARK: Stored properties

@State private var isCodeVisible = false
var code: String

// MARK: Body

var body: some View {
VStack(spacing: theme.spaceFixedNone) {
toggleButtonSection()
if isCodeVisible {
codeTokenDisplayCodeSection()
}
}
}

// MARK: Private helpers

private func toggleButtonSection() -> some View {
VStack(alignment: .leading, spacing: theme.spaceFixedNone) {
Button(action: toggle) {
HStack {
Text("app_tokens_code_title_label")
.typeBodyStrongLarge(theme)
.foregroundStyle(theme.colorContentDefault.color(for: colorScheme))
.padding(.vertical, theme.spacePaddingInlineShort)
Image("ic_chevron-up")
.resizable()
.renderingMode(.template)
.rotationEffect(Angle.degrees(isCodeVisible ? 0 : 180))
.foregroundColor(theme.colorBgBrandPrimary.color(for: colorScheme))
.frame(width: 20, height: 20)
.padding(.trailing, theme.spacePaddingInlineMedium)
.accessibilityLabel("app_tokens_code_visibility_button_a11y")
}
}
.buttonStyle(PlainButtonStyle())
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.bottom, theme.spacePaddingBlockShort)
}

private func codeTokenDisplayCodeSection() -> some View {
HStack(alignment: .firstTextBaseline, spacing: theme.spacePaddingBlockMedium) {
Text(code)
.font(.system(.body, design: .monospaced))
.foregroundStyle(theme.colorContentDefault.color(for: colorScheme))
.padding(.vertical, theme.spacePaddingInlineShort)

Button(action: {
UIPasteboard.general.string = code
}, label: {
ZStack {
Color.clear
.frame(width: 44, height: 44)

Image("ic_copy")
.resizable()
.renderingMode(.template)
.foregroundColor(theme.colorBgStatusPositiveMuted.color(for: colorScheme))
.frame(width: 24, height: 24)
.padding(.trailing, theme.spacePaddingInlineMedium)
.alignmentGuide(.firstTextBaseline) { $0[.bottom] * 0.7 }
.accessibilityLabel("app_tokens_code_copy_button_a11y")
}
})
}
.frame(minWidth: 72, maxWidth: .infinity, alignment: .leading)
.padding(.vertical, theme.spacePaddingInlineShort)
.padding(.leading, theme.spacePaddingInlineMedium)
.background(theme.colorBgSecondary.color(for: colorScheme))
.accessibilityElement(children: .combine)
.accessibilityHint("app_tokens_code_copy_button_a11y")
.overlay(
Rectangle()
.opacity(theme.opacityTransparent)
.frame(minWidth: 40, maxWidth: .infinity, alignment: .leading)
.oudsBorder(style: theme.borderStyleDefault,
width: theme.borderWidthThin,
radius: theme.borderRadiusDefault,
color: theme.colorBorderDefault)
)
}

private func toggle() {
withAnimation {
isCodeVisible.toggle()
}
}
}
17 changes: 12 additions & 5 deletions Showcase/Showcase/Pages/Utils/ShowcaseVariantElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@ struct ShowcaseVariantElement: View {
NavigationLink {
ShowcaseElementPage(element: element)
} label: {
Text(LocalizedStringKey(element.name))
.typeHeadingMedium(theme)
.foregroundStyle(theme.colorContentDefault.color(for: colorScheme))
.padding(.vertical, theme.spaceFixedShorter)
HStack {
Text(LocalizedStringKey(element.name))
.typeHeadingMedium(theme)
.foregroundStyle(theme.colorContentDefault.color(for: colorScheme))
.padding(.vertical, theme.spaceFixedShorter)
.padding(.leading, theme.spaceFixedMedium)
Spacer()
Image(systemName: "chevron.right")
.foregroundColor(theme.colorContentDefault.color(for: colorScheme))
.padding(.trailing, theme.spaceFixedMedium)
.accessibilityHidden(true)
}
}
}
.padding(.horizontal, theme.spaceFixedMedium)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "ic_chevron-down.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "ic_chevron-up.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit dcd69ea

Please sign in to comment.