UserHappyDesign system
Storybook

Platforms

Keep the shared identity while respecting the policy of each surface.

SurfaceGuidance
Customer webUserHappy colors, exact theme bindings, and shared components.
Participant webPreserved Pulse frames and shared controls; use the named flow as context.
Cortex staffSeparate monochrome rules and staff variants.
iOSIts own palette scope and typography exemptions. Do not merge web and iOS allowed lists.

iOS design record

The original Swift design definitions and palette tests are retained. The native app lifecycle is independent of this documentation site.

Read UserHappyDesign.swift
import SwiftUI

enum UserHappyDesign {
    enum Colors {
        // UserHappy Style Guide v3.1 bright palette — canonical values in src/index.css @theme.
        // Fixed light values by design: the app forces light appearance (UIUserInterfaceStyle in
        // project.yml) so the bright design system renders identically on dark-mode devices.
        /// Accessible Orange — NON-TEXT roles only: button fills, borders, focus
        /// rings, symbol glyphs. It was tuned against white (4.59:1) and fails AA
        /// as text on every other canon ground: Page Wash 4.14, Very Light Gray
        /// 3.83, Light Gray 3.43. As a non-text control it only needs 3:1 and
        /// passes everywhere. Web split this role on 2026-08-04 (--color-brand-
        /// orange-accessible vs --color-brand-orange-text, src/index.css).
        static let brandOrange = Color(hex: 0xC75000)
        /// Text Orange — orange that is WORDS: links, button labels, eyebrow
        /// labels. Ratified by Aline on 2026-08-10 (Monday item 12715482042),
        /// superseding the interim value she read as too brown. Orange words sit
        /// on exactly three grounds and it clears 4.5:1 on all three: White
        /// 5.50, Page Wash 4.96, Very Light Gray 4.59. It does NOT clear Light
        /// Gray #e2dedc (4.12) — orange text never appears on Light Gray or
        /// darker. Mirrors web's --color-brand-orange-text.
        static let brandOrangeText = Color(hex: 0xB34700)
        /// Symbol-glyph tint. Same swatch as `brandOrange`; a separate name
        /// because SwiftUI colors an SF Symbol and a run of text with the same
        /// `foregroundStyle` modifier, so — unlike web, where Tailwind's `text-`
        /// prefix states the role — the token is the only place iOS can say
        /// which role is meant. The guard bans bare `brandOrange` in a
        /// foreground position for exactly that reason.
        static let brandOrangeIcon = brandOrange
        static let brandOrangeBright = Color(hex: 0xEA5F00) // brand orange: logo, active states, sentiment
        static let brandOrangeHover = Color(hex: 0xEA5F00) // hover/active = Brand Orange per style guide (ratified 2026-07-22)
        static let brandSoft = Color(hex: 0xEDEAE8)
        static let brandInk = Color(hex: 0xEA5F00) // pressed = active Brand Orange (ratified 2026-07-22)

        static let ink = Color(hex: 0x565352) // dark charcoal: body & UI text
        static let mutedInk = Color(hex: 0x565352)
        /// Third-level label ink. Brand warm gray #b0a49d used to sit here, but it
        /// fails AA on light surfaces (~2.8:1) and Aline hard-banned it as a font
        /// color on 2026-07-23 — web enforces that in paletteCanon.test.ts. Same
        /// resolution as web's --color-text-muted: hierarchy comes from size and
        /// weight, not lighter ink. Warm gray stays canonical for fills and
        /// borders (see `neutralFillStrong`).
        static let tertiaryInk = Color(hex: 0x565352)
        static let inverseInk = Color.white
        static let displayInk = Color(hex: 0x1A1430) // deep navy: display headings

        static let pageBackground = Color(hex: 0xF3F3F3)
        static let accountPageBackground = Color(hex: 0xEDEAE8)
        static let panelBackground = Color.white
        static let panelMutedBackground = Color(hex: 0xEDEAE8)
        static let accountCardBackground = Color.white

        static let border = Color(hex: 0xE2DEDC) // light gray: card borders, light section backgrounds
        static let softBorder = Color(hex: 0xE2DEDC)
        static let fieldBorder = Color(hex: 0xE2DEDC)
        static let focusRing = brandOrange

        static let primaryButtonBackground = brandOrange
        static let primaryButtonPressed = brandOrange
        static let secondaryButtonBackground = panelBackground
        static let secondaryButtonPressed = neutralFillSoft

        static let neutralFill = Color(hex: 0xE2DEDC) // tracks, placeholders, inactive fills
        static let neutralFillSoft = Color(hex: 0xEDEAE8)
        static let neutralFillStrong = Color(hex: 0xB0A49D)
        static let veryLightGray = Color(hex: 0xEDEAE8) // teammate/participant page wash (--color-very-light-gray)

        static let metricTrack = neutralFill
        static let metricPlaceholder = neutralFill
        // Attention/nudge card. Web renders these banners as amber-50 on
        // amber-200 (Layout.tsx, TeamAccessPanel.tsx); iOS had hand-mixed RGB
        // that landed near but not on them.
        static let attentionBackground = Color(hex: 0xFFFBEB) // amber-50
        static let attentionBorder = Color(hex: 0xFDE68A)     // amber-200

        static let warmYellow = Color(hex: 0xFFBC5A) // in-progress badge fill
        static let lightTeal = Color(hex: 0x9FD8D9) // report-in-preparation badge fill
        static let staffNavy = displayInk // Cortex staff-shell accent (navy staff, charcoal customer)

        // Danger / error. The 11-swatch canon has no red, so web canonized the
        // role in three tokens (--color-danger / -surface / -border, index.css).
        // These mirror them exactly; iOS previously used Tailwind red-700/red-50.
        static let danger = Color(hex: 0xC62828)        // text, icons, destructive labels
        static let dangerSurface = Color(hex: 0xFCEBEA) // wash behind error / failed-state banners
        static let dangerBorder = Color(hex: 0xF1C4C1)  // hairline for those banners

        // Success / warning ink. The canon has no green or amber either; web
        // settles these on Tailwind green-700 / amber-700 (HelpStatusBadge.tsx,
        // and the same pair throughout the status badges). Naming them here
        // stops views reaching for SwiftUI's `.green` / `.orange`, which are
        // vivid system colors that match nothing on web.
        static let success = Color(hex: 0x15803D)
        static let successSurface = Color(hex: 0xF0FDF4)
        static let warning = Color(hex: 0xB45309)
        static let warningSurface = Color(hex: 0xFFFBEB)
    }

    enum Radius {
        static let panel: CGFloat = 8
        static let control: CGFloat = 8
        static let badge: CGFloat = 999
        static let metricBar: CGFloat = 3
    }

    enum Spacing {
        static let panelPadding: CGFloat = 12
        static let controlHorizontal: CGFloat = 12
        static let controlVertical: CGFloat = 12
        static let denseControlVertical: CGFloat = 9
        static let metricTight: CGFloat = 4
        static let metricRow: CGFloat = 6
    }

    enum Typography {
        static let title = poppins(28, .bold, relativeTo: .largeTitle)
        static let sectionTitle = poppins(14, .semibold)
        static let body = mulish(13)
        static let caption = mulish(11, relativeTo: .caption)
        static let metricLabel = mulish(10)
        static let metricValue = mulish(10, .medium)
        static let badge = mulish(10, .medium)
        static let button = mulish(14, .semibold)
        static let compactButton = mulish(12, .semibold, relativeTo: .callout)

        /// Weights with a bundled static TTF (see ios/UserHappy/Resources/Fonts).
        /// No variable-font axis is bundled, so `.weight()`/`.fontWeight()` has no
        /// effect on a `Font.custom` face — always request the weight here.
        enum FontWeight {
            case regular, medium, semibold, bold
        }

        /// Style Guide v3.1 display face (headings) — Poppins static weights.
        static func poppins(_ size: CGFloat, _ weight: FontWeight = .regular, relativeTo style: Font.TextStyle = .body) -> Font {
            let suffix: String
            switch weight {
            case .regular:  suffix = "Regular"
            case .medium:   suffix = "Medium"
            case .semibold: suffix = "SemiBold"
            case .bold:     suffix = "Bold"
            }
            return Font.custom("Poppins-\(suffix)", size: size, relativeTo: style)
        }

        /// Style Guide v3.1 body face (copy, labels, buttons) — Mulish static
        /// weights. Only Regular/SemiBold/Bold are bundled (no Medium static
        /// file exists in the source repo); `.medium` maps to SemiBold rather
        /// than thinning small UI text down to Regular.
        static func mulish(_ size: CGFloat, _ weight: FontWeight = .regular, relativeTo style: Font.TextStyle = .body) -> Font {
            let suffix: String
            switch weight {
            case .regular:           suffix = "Regular"
            case .medium, .semibold: suffix = "SemiBold"
            case .bold:              suffix = "Bold"
            }
            return Font.custom("Mulish-\(suffix)", size: size, relativeTo: style)
        }
    }

    enum Metrics {
        static let sentimentLabelWidth: CGFloat = 72
        static let sentimentValueWidth: CGFloat = 28
        static let sentimentBarHeight: CGFloat = 8
        static let responseRateBarHeight: CGFloat = 4
    }
}

enum UserHappyBadgeTone {
    case brand
    case owner
    case admin
    case member
    case neutral
    case success
    case warning
    case danger

    var foreground: Color {
        switch self {
        case .brand, .admin:
            UserHappyDesign.Colors.brandInk
        case .owner:
            Color(hex: 0x7E22CE) // purple-700, matching web's Badge.tsx pair
        case .member, .neutral:
            UserHappyDesign.Colors.mutedInk
        case .success:
            UserHappyDesign.Colors.success
        case .warning:
            UserHappyDesign.Colors.warning
        case .danger:
            UserHappyDesign.Colors.danger
        }
    }

    var background: Color {
        switch self {
        case .brand, .admin:
            UserHappyDesign.Colors.brandSoft
        case .owner:
            Color(hex: 0xFAF5FF) // purple-50
        case .member, .neutral:
            UserHappyDesign.Colors.panelMutedBackground
        case .success:
            UserHappyDesign.Colors.successSurface
        case .warning:
            UserHappyDesign.Colors.warningSurface
        case .danger:
            UserHappyDesign.Colors.dangerSurface
        }
    }

    var border: Color? {
        switch self {
        case .member, .neutral:
            UserHappyDesign.Colors.fieldBorder
        case .danger:
            UserHappyDesign.Colors.dangerBorder
        default:
            nil
        }
    }
}

struct UserHappyRoleBadge: View {
    enum Role {
        case owner
        case admin
        case member

        var title: String {
            switch self {
            case .owner: "Owner"
            case .admin: "Admin"
            case .member: "Member"
            }
        }

        var tone: UserHappyBadgeTone {
            switch self {
            case .owner: .owner
            case .admin: .admin
            case .member: .member
            }
        }
    }

    let role: Role

    var body: some View {
        Text(role.title)
            .userHappyBadge(role.tone)
    }
}

/// Surface changes presentation only; permissions remain in PermissionService.
enum UserHappyButtonSurface: Equatable {
    case customer, staff
}

private struct UserHappyButtonSurfaceKey: EnvironmentKey {
    static let defaultValue: UserHappyButtonSurface = .customer
}

extension EnvironmentValues {
    var userHappyButtonSurface: UserHappyButtonSurface {
        get { self[UserHappyButtonSurfaceKey.self] }
        set { self[UserHappyButtonSurfaceKey.self] = newValue }
    }
}

struct UserHappyButtonStyle: ButtonStyle {
    enum Variant: Equatable { case primary, outline, secondary, quiet }
    enum Size: Equatable { case regular, compact }
    enum Width: Equatable { case intrinsic, full }

    @Environment(\.isEnabled) private var isEnabled
    @Environment(\.userHappyButtonSurface) private var inheritedSurface
    private let variant: Variant
    private let size: Size
    private let width: Width
    private let surface: UserHappyButtonSurface?

    init(_ variant: Variant = .primary, size: Size = .regular, width: Width = .intrinsic,
         surface: UserHappyButtonSurface? = nil) {
        self.variant = variant
        self.size = size
        self.width = width
        self.surface = surface
    }

    func makeBody(configuration: Configuration) -> some View {
        makeBody(configuration: configuration, surface: surface ?? inheritedSurface, isEnabled: isEnabled)
    }

    // Wrappers pass their own resolved environment instead of reading an uninstalled style.
    func makeBody(configuration: Configuration, surface: UserHappyButtonSurface, isEnabled: Bool) -> some View {
        let destructive = configuration.role == .destructive
        let accent = surface == .staff ? UserHappyDesign.Colors.ink
            : (destructive ? UserHappyDesign.Colors.danger : UserHappyDesign.Colors.brandOrange)
        let filled = variant == .primary
        let foreground = !isEnabled ? UserHappyDesign.Colors.mutedInk
            : (filled ? UserHappyDesign.Colors.inverseInk
               : (destructive ? accent
                  : (variant == .outline && surface == .customer
                     ? UserHappyDesign.Colors.brandOrangeText : UserHappyDesign.Colors.ink)))
        let background = !isEnabled ? UserHappyDesign.Colors.neutralFill
            : (filled ? accent : (configuration.isPressed ? UserHappyDesign.Colors.neutralFillSoft
                                   : UserHappyDesign.Colors.panelBackground))
        return configuration.label
            .font(size == .regular ? UserHappyDesign.Typography.button : UserHappyDesign.Typography.compactButton)
            .multilineTextAlignment(.center)
            .fixedSize(horizontal: false, vertical: true)
            .padding(.horizontal, size == .regular ? 16 : 12)
            .padding(.vertical, 10)
            .frame(minWidth: 44, maxWidth: width == .full ? .infinity : nil,
                   minHeight: size == .regular ? 48 : 44)
            .foregroundStyle(foreground)
            .background(background)
            .clipShape(RoundedRectangle(cornerRadius: UserHappyDesign.Radius.control))
            .overlay {
                RoundedRectangle(cornerRadius: UserHappyDesign.Radius.control)
                    .strokeBorder(variant == .outline ? accent : UserHappyDesign.Colors.border,
                                  lineWidth: variant == .outline ? 2 : (variant == .secondary ? 1 : 0))
                // Inset feedback keeps inverse label contrast intact while pressed.
                if configuration.isPressed && isEnabled {
                    RoundedRectangle(cornerRadius: UserHappyDesign.Radius.control - 2)
                        .strokeBorder(foreground, lineWidth: 2)
                        .padding(3)
                }
            }
            .contentShape(RoundedRectangle(cornerRadius: UserHappyDesign.Radius.control))
    }
}

/// Keep the command visible while work is in flight; callers disable repeated actions.
struct UserHappyButtonLabel: View {
    let title: String
    var isLoading = false

    var body: some View {
        HStack(spacing: 8) {
            if isLoading { ProgressView() }
            Text(title)
        }
        .accessibilityElement(children: .ignore)
        .accessibilityLabel(title)
        .accessibilityValue(isLoading ? "In progress" : "")
    }
}

struct UserHappyMetricRow<Content: View>: View {
    let label: String
    let value: String
    var labelWidth = UserHappyDesign.Metrics.sentimentLabelWidth
    var valueWidth = UserHappyDesign.Metrics.sentimentValueWidth
    private let content: () -> Content

    init(
        label: String,
        value: String,
        labelWidth: CGFloat = UserHappyDesign.Metrics.sentimentLabelWidth,
        valueWidth: CGFloat = UserHappyDesign.Metrics.sentimentValueWidth,
        @ViewBuilder content: @escaping () -> Content
    ) {
        self.label = label
        self.value = value
        self.labelWidth = labelWidth
        self.valueWidth = valueWidth
        self.content = content
    }

    var body: some View {
        HStack(spacing: UserHappyDesign.Spacing.metricRow) {
            Text(label)
                .font(UserHappyDesign.Typography.metricLabel)
                .foregroundStyle(UserHappyDesign.Colors.mutedInk)
                .frame(width: labelWidth, alignment: .leading)
            content()
            Text(value)
                .font(UserHappyDesign.Typography.metricValue)
                .foregroundStyle(UserHappyDesign.Colors.mutedInk)
                .frame(width: valueWidth, alignment: .trailing)
        }
    }
}

struct UserHappyMetricBar: View {
    let value: Double
    var tint = UserHappyDesign.Colors.brandOrangeBright
    var track = UserHappyDesign.Colors.metricTrack
    var height = UserHappyDesign.Metrics.sentimentBarHeight

    private var clampedValue: Double {
        min(max(value, 0), 1)
    }

    var body: some View {
        GeometryReader { geometry in
            ZStack(alignment: .leading) {
                RoundedRectangle(cornerRadius: UserHappyDesign.Radius.metricBar)
                    .fill(track)
                    .frame(height: height)
                RoundedRectangle(cornerRadius: UserHappyDesign.Radius.metricBar)
                    .fill(tint)
                    .frame(width: geometry.size.width * CGFloat(clampedValue), height: height)
            }
        }
        .frame(height: height)
    }
}

private struct UserHappyInputFieldModifier: ViewModifier {
    var dense: Bool

    func body(content: Content) -> some View {
        content
            .padding(.horizontal, UserHappyDesign.Spacing.controlHorizontal)
            .padding(.vertical, dense ? UserHappyDesign.Spacing.denseControlVertical : UserHappyDesign.Spacing.controlVertical)
            .background(UserHappyDesign.Colors.panelBackground)
            .clipShape(RoundedRectangle(cornerRadius: UserHappyDesign.Radius.control))
            .overlay(
                RoundedRectangle(cornerRadius: UserHappyDesign.Radius.control)
                    .stroke(UserHappyDesign.Colors.fieldBorder, lineWidth: 1)
            )
            .tint(UserHappyDesign.Colors.focusRing)
    }
}

private struct UserHappyAccountCardModifier: ViewModifier {
    var padding: CGFloat
    var highlighted: Bool

    func body(content: Content) -> some View {
        content
            .padding(padding)
            .background(highlighted ? UserHappyDesign.Colors.attentionBackground : UserHappyDesign.Colors.accountCardBackground)
            .clipShape(RoundedRectangle(cornerRadius: UserHappyDesign.Radius.panel))
            .overlay(
                RoundedRectangle(cornerRadius: UserHappyDesign.Radius.panel)
                    .stroke(highlighted ? UserHappyDesign.Colors.attentionBorder : UserHappyDesign.Colors.softBorder, lineWidth: highlighted ? 1.5 : 1)
            )
    }
}

private struct UserHappyBadgeModifier: ViewModifier {
    let foreground: Color
    let background: Color
    let border: Color?

    func body(content: Content) -> some View {
        content
            .font(UserHappyDesign.Typography.badge)
            .padding(.horizontal, 6)
            .padding(.vertical, 2)
            .background(background)
            .foregroundStyle(foreground)
            .clipShape(Capsule())
            .overlay {
                if let border {
                    Capsule().stroke(border, lineWidth: 1)
                }
            }
    }
}

extension Color {
    init(hex: UInt32) {
        self.init(
            red: Double((hex >> 16) & 0xFF) / 255.0,
            green: Double((hex >> 8) & 0xFF) / 255.0,
            blue: Double(hex & 0xFF) / 255.0
        )
    }
}

extension View {
    func userHappyInputField(dense: Bool = false) -> some View {
        modifier(UserHappyInputFieldModifier(dense: dense))
    }

    func userHappyAccountCard(padding: CGFloat = UserHappyDesign.Spacing.panelPadding, highlighted: Bool = false) -> some View {
        modifier(UserHappyAccountCardModifier(padding: padding, highlighted: highlighted))
    }

    func userHappyBadge(_ tone: UserHappyBadgeTone) -> some View {
        modifier(UserHappyBadgeModifier(foreground: tone.foreground, background: tone.background, border: tone.border))
    }

    func userHappyBadge(foreground: Color, background: Color, border: Color? = nil) -> some View {
        modifier(UserHappyBadgeModifier(foreground: foreground, background: background, border: border))
    }
}

Source: ios/UserHappy/Core/Design/UserHappyDesign.swift · design/canon.json