Skip to content

In design system toolbox app, mutualize enums options of the configuration using pickers #1493

@ludovic35

Description

@ludovic35

Description

Today, when an option of component api is an enum, in the configuration of the demo page of the component , en extension is always created to generate OUDSChipPickerData base on a String description.
Sometime, this Sting is hard coded, sometimes it is a wording key.

  1. Format this string directly form the name of the case of the enum using something like:
var formattedName: String {
        let name = String(describing: self)
        let withSpaces = name.replacingOccurrences(
            of: "([a-z])([A-Z])",
            with: "$1 $2",
            options: .regularExpression
        )
        return withSpaces.prefix(1).uppercased() + withSpaces.dropFirst().lowercased()
    }

This could be an extensions of a protocol:

protocol EnumRepresentable {
}
  1. Create a OUDSChipPickerData builder based on this formatted String of each case
    var chipData: OUDSChipPickerData<Self> {
        OUDSChipPickerData(tag: self, layout: .text(text: self.formattedName))
    }

    static var chips: [OUDSChipPickerData<Self>] {
        allCases.map(\.chipData)
    }

In order to expose this builder to enum option, the flowing protocol can be created

protocol OptionEnumerated: CaseIterable, Hashable, EnumRepresentable { 
}

Metadata

Metadata

Assignees

Labels

No fields configured for Enhancement.

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions