amzn / style-dictionary

A build system for creating cross-platform styles.
https://styledictionary.com
Apache License 2.0
3.94k stars 560 forks source link

Android support for fonts & textCase via textAllCaps #1331

Open niggeulimann opened 2 months ago

niggeulimann commented 2 months ago

As discussed earlier in the this PR includes two things:

  1. it resolves a token of type fontFamily to an android-ressource entry like <item name="typography_body_font_family" type="font">@font/comic_sans_regular</item>

❗️to fully support this, i also use the following transform, which is not included yet

export const androidFontFamilyTransform = {
    type: "value",
    name: "android/androidFontFamilyTransform",
    transitive: true,
    filter: (token) =>
      token.attributes.item === "fontFamily" ||
      token.attributes.subitem === "fontFamily",
    transform: (token) => {
      return "@font/"+token.value;
    }
  };

Usage: the value can be used with https://developer.android.com/reference/android/widget/TextView#attr_android:fontFamily - please ensure that the font-file has the same name

  1. it resolves a token of type textCase to a bool android ressource like this: <bool name="typography_body_text_case">false</bool> ❗️this also needs a transform:
    export const androidTextCaseTransform = {
    type: "value",
    name: "android/textCaseAsBool",
    transitive: true,
    filter: (token) => {
      return token.type === "textCase";
    },
    transform: (token) => {
       return token.value === "uppercase" ? "true" : "false";
    }
    };

    Usage: the generated resource can be used with https://developer.android.com/reference/android/widget/TextView#attr_android:textAllCaps

From our point of view, this would be a big improvement.

aws-amplify-us-west-1[bot] commented 2 months ago

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-1331.d16eby4ekpss5y.amplifyapp.com

jorenbroekema commented 2 months ago

Thanks for contributing this, I think it makes sense to add both transforms you mentioned and then also have them added to the android transformGroup. The "true" and "false" values can be just true andfalseand the filter can check for the$type/typeinstead of theattributes.item/attributes.subitem`.

I think we need to discuss with @dbanksdesign whether we want to create a new format/transformGroup for these improvements or whether we consider this bugfixes that should be added in a minor patch. Technically speaking changing the format / token value transforms within a transformGroup are breaking changes.