Contents

ConditionalComponentTextStyle

The object for defining conditional properties for a component text style, and when the conditional properties are in effect.

Declaration

object ConditionalComponentTextStyle

Properties

NameTypeDescription
conditions Required(Condition | [Condition])

An instance or array of conditions that, when met, cause the conditional component text style properties to take effect.

backgroundColor(Color | string("none"))

The background color for text lines. This value defaults to transparent.

To remove a previously set condition, use none.

dropCapStyle(DropCapStyle | string("none"))

The style of drop cap to apply to the first paragraph of the component.

To remove a previously set condition, use none.

firstLineIndentinteger

The indent, in points, of the first line of each paragraph.

fontFamily(string | string("system"))

The font family to use for text rendering; for example, Gill Sans. Using a combination of fontFamily, fontWeight, and fontStyle, you can define the appearance of the text. Apple News automatically selects the appropriate font variant from the available variants in that family. See Applying Apple News Format Fonts.

You can use the value system to show text in the default font the operating system uses.

fontNamestring

The font name to use to refer to an explicit font variant’s PostScript name, such as GillSans-Bold. Alternatively, you can use a combination of fontFamily, fontWeight, and fontStyle to have Apple News automatically select the appropriate variant depending on the text formatting used.

See Applying Apple News Format Fonts.

fontScalingboolean

A Boolean value that indicates whether scaling of font sizes for various screen sizes is enabled. By default, all font sizes in Apple News Format are scaled down on smaller screen sizes.

fontSizeinteger

The size of the font, in points. By default, the font size is inherited from a parent component or a default style. As a best practice, try not to go below 16 points for body text. Apple News may automatically resize the fontSize for different device sizes or for iOS and iPadOS devices with Larger Accessibility Sizes enabled.

fontStylestring

The font style to apply for the selected font.

Valid values:

  • normal. Selects from the font family a font that Apple News defines as normal.

  • italic. Selects from the font family a font that Apple News defines as italic. If the family doesn’t contain an italic font variant, but contains an oblique variant, Apple news selects oblique instead.

  • oblique. Selects from the font family a font that Apple News defines as oblique. If the family does not contain an oblique font variant, but contains an italic variant, Apple News selects italic instead.

fontWeight(integer | string)

The font weight to apply for the selected font. In addition to explicit weights (named or numerical), lighter and bolder are available, to set text in a lighter or bolder font as compared to the surrounding text.

If Apple News can’t find a font variant with the given specifications in the provided font family, it selects an alternative with the closest match. If Apple News doesn’t find a bold/bolder font, it doesn’t create a faux-bold alternative, and instead uses the closest match. Similarly, if Apple News can’t find an italic or oblique font variant, it won’t slant text or make it appear italicized.

Valid values:

  • thin or 100. Thin or hairline weight.

  • extra-light, ultra-light or 200. Extra-light or ultra-light weight.

  • light or 300. Light weight.

  • regular, normal, book, roman, or 400. Regular weight. This is the default if no weight is defined or inherited.

  • medium or 500. Medium weight.

  • semi-bold, demi-bold, or 600. Semi-bold or demi-bold weight.

  • bold or 700. Bold weight. This is the default when using <strong> or <b> tags in HTML with default fontWeight.

  • extra-bold, ultra-bold, or 800. Extra-bold or ultra-bold weight.

  • black, heavy, or 900. Black or heavy weight.

  • lighter. A weight lighter than its surrounding text. When you make surrounding text bold, a value of lighter makes it medium.

  • bolder. A weight heavier than its surrounding text. When you make surrounding text light, a value of bolder makes it regular.

fontWidthstring

The font width for the selected font (known in CSS as font-stretch). This value defines the width characteristics of a font variant between normal, condensed, and expanded. Some font families are categorized by width (for example, Avenir Next and Avenir Next Condensed), so make sure that the font family you select supports the specified font width.

Valid values:

  • ultra-condensed. The most condensed variant.

  • extra-condensed. A very condensed variant.

  • condensed. A condensed variant.

  • semi-condensed. A semi-condensed variant.

  • normal (default). The font variant classified as normal.

  • semi-expanded. A semi-expanded variant.

  • expanded. An expanded variant.

  • extra-expanded. A very expanded variant.

  • ultra-expanded. The most expanded variant.

hangingPunctuationboolean

A Boolean that defines whether Apple News positions punctuation outside the margins of the body text.

hyphenationboolean

A Boolean that indicates whether Apple News hyphenates text when necessary. By default, only components with the role body or intro have hyphenation enabled. All other components default to false.

hyphenationMinimumCharactersAfterinteger

The minimum number of characters required after the hyphen to enable hyphenation.

hyphenationMinimumCharactersBeforeinteger

The minimum number of characters required before the hyphen to enable hyphenation for a word.

hyphenationMinimumWordLengthinteger

The minimum number of characters required to enable hyphenation for a word.

hyphenationZoneinteger

The area in points from the right edge of the text component before which a word needs to start to enable hyphenation.

By default, the value is set to 18 points.

A larger value reduces the allowable hyphenation area of a word, which can result in a more ragged appearance of the text along the right margin.

lineBalancingboolean

A Boolean value that defines whether the system enables line balancing for the text component.

lineHeightinteger

The default line height, in points. Apple News recalculates the line height as necessary, relative to the font size. For example, when Apple News automatically resizes the font to fit a smaller screen, it also adjusts the line height accordingly.

linkStyle(TextStyle | string("none"))

Text styling for all links within a text component.

To remove a previously set condition, use none.

orderedListItems(ListItemStyle | string("none"))

An object for use with text components with HTML markup. You can create text styles containing an orderedListItems definition to configure how to display list items inside <ol> tags.

To remove a previously set condition, use none.

paragraphSpacingAfterinteger

An object that defines the spacing, in points, after each paragraph, relative to the line height.

paragraphSpacingBeforeinteger

An object that defines the spacing, in points, before each paragraph, relative to the line height.

strikethrough(TextDecoration | boolean)

The text strikethrough. Set strikethrough to true to use the text color inherited from the textColor property as the strikethrough color, or provide a text decoration definition with a different color. By default, Apple News omits strikethrough (false).

stroke(TextStrokeStyle | string("none"))

The stroke style for the text outline. By default, Apple News omits stroke.

To remove a previously set condition, use none.

textAlignmentstring

The justification for all text within the component.

If Apple News omits textAlignment or sets it to none, the justification is determined by the text direction (left-to-right text is aligned to the left, and right-to-left text is aligned to the right).

textColorColor

The text color to apply to the selected text.

textShadow(TextShadow | string("none"))

The text shadow for this style.

To remove a previously set condition, use none.

textTransformstring

The transform to apply to the text.

Valid values:

  • uppercase

  • lowercase

  • capitalize. Capitalizes the first letter of all words in the string.

  • smallcaps. Capitalizes the lowercase letters as short capital letters.

  • none (default)

trackingnumber

The amount of tracking (spacing between characters) in text, as a percentage of the font size. The actual spacing between letters is determined by combining information from the font and font size.

Example: Set tracking to 0.5 to make the distance between characters increase by 50% of the fontSize. With a font size of 10, the additional space between characters is 5 points.

underline(TextDecoration | boolean)

The text underlining. You can use this style for links. Set underline to true to use the text color as the underline color, or provide a text decoration with a different color. By default, Apple News omits underline (false).

unorderedListItems(ListItemStyle | string("none"))

An object for use with text components with HTML markup. You can create text styles containing an unorderedListItems definition to configure how to display list items inside <ul> tags.

To remove a previously set condition, use none.

verticalAlignmentstring

The vertical alignment of the text. You can use this property for superscript and subscript.

To override values specified in parent text styles, use baseline.

Defaults to baseline when unspecified, and inherits the value specified in a TextStyle applied to the same range.

The values superscript and subscript also adjust the font size to 2/3 of the size defined for that character range.

Mentioned in

Discussion

Use the ConditionalComponentTextStyle object to define an array of conditional component text style properties and the conditions under which to apply them. When a condition is met, the value of a property in ConditionalComponentTextStyle overrides the value of the same property if you define it in the parent ComponentTextStyle object. See ComponentTextStyle.

Example

{
  "components": [
    {
      "role": "title",
      "text": "Lorem Ipsum Dolor Sit Amet",
      "textStyle": "exampleTextStyle"
    }
  ],
  "componentTextStyles": {
    "exampleTextStyle": {
      "fontSize": 24,
      "conditional": [
        {
          "fontSize": 24,
          "conditions": [
            {
              "minViewportWidth": 0
            }
          ]
        },
        {
          "fontSize": 48,
          "conditions": [
            {
              "minViewportWidth": 415
            }
          ]
        },
        {
          "fontSize": 64,
          "conditions": [
            {
              "minViewportWidth": 769
            }
          ]
        }
      ]
    }
  }
}

See Also

Conditional Design Elements