1# Content Modifier 2 3You can apply a content modifier to a component to customize its content area using a style builder. 4 5> **NOTE** 6> 7> This feature is supported since API version 12. Updates will be marked with a superscript to indicate their earliest API version. 8 9## contentModifier 10 11contentModifier(modifier:ContentModifier\<T>) 12 13Creates a content modifier. 14 15**System capability**: SystemCapability.ArkUI.ArkUI.Full 16 17**Parameters** 18 19| Name | Type | Mandatory | Description | 20| -------- | ------------------ | ---- | ------------------------------------------------------------ | 21| modifier | ContentModifier\<T> | Yes | Content modifier to apply to the current component.<br>**modifier**: content modifier. You need a custom class to implement the **ContentModifier** API. | 22 23## ContentModifier\<T> 24 25You need a custom class to implement the **ContentModifier** API. 26 27### applyContent 28 29applyContent() : WrappedBuilder<[T]> 30 31Builder of the custom content area. 32 33**Atomic service API**: This API can be used in atomic services since API version 12. 34 35**System capability**: SystemCapability.ArkUI.ArkUI.Full 36 37**Parameters** 38 39| Name | Description | 40| ---- | ------------------------------------------------------------ | 41| T | Component attribute class, which is used to distinguish different information required by different components after content areas are customized, for example, **ButtonConfiguration** for the **Button** component and **CheckBoxConfiguration** of the **Checkbox** component. | 42 43**Value range of the T parameter:** 44 45ButtonConfiguration, CheckBoxConfiguration, DataPanelConfiguration, TextClockConfiguration, ToggleConfiguration, GaugeConfiguration, LoadingProgressConfiguration, RadioConfiguration, ProgressConfiguration, RatingConfiguration, SliderConfiguration 46 47**Supported attributes** 48 49The universal attribute **enabled** and **contentModifier** are supported. 50## CommonConfiguration\<T><sup>12+</sup> 51 52You need a custom class to implement the **ContentModifier** API. 53 54**Atomic service API**: This API can be used in atomic services since API version 12. 55 56**System capability**: SystemCapability.ArkUI.ArkUI.Full 57 58| Name | Type | Description | 59| ------ | ------ | ---------------- | 60| enabled | boolean | Whether to enable the content modifier and respond to operations such as **triggerChange**. The value **true** means to enable the content modifier and respond to operations such as **triggerChange**, and **false** means the opposite.| 61| contentModifier | ContentModifier\<T> | Content modifier that sends the component information required by users to the custom content area.| 62 63 64## Example 65 66This example demonstrates how to create a custom check box using **ContentModifier**. This check box comes in the custom pentagon style instead of the original check box style. When selected, the check box shows a red triangle pattern inside, and the title displays the word "Selected;" when deselected, the check box hides the red triangle pattern inside, and the title displays the word "Unselected." 67 68```ts 69// xxx.ets 70class MyCheckboxStyle implements ContentModifier<CheckBoxConfiguration> { 71 selectedColor: Color = Color.White 72 73 constructor(selectedColor: Color) { 74 this.selectedColor = selectedColor; 75 } 76 77 applyContent(): WrappedBuilder<[CheckBoxConfiguration]> { 78 return wrapBuilder(buildCheckbox) 79 } 80} 81 82@Builder 83function buildCheckbox(config: CheckBoxConfiguration) { 84 Column({ space: 10 }) { 85 Text(config.name + (config.selected ? "(Selected)" : "(Not selected)")) 86 Shape() { 87 // Pentagon check box style 88 Path() 89 .width(200) 90 .height(60) 91 .commands('M100 0 L0 100 L50 200 L150 200 L200 100 Z') 92 .fillOpacity(0) 93 .strokeWidth(3) 94 // Red triangle pattern style 95 Path() 96 .width(10) 97 .height(10) 98 .commands('M50 0 L100 100 L0 100 Z') 99 .visibility(config.selected ? Visibility.Visible : Visibility.Hidden) 100 .fill(config.selected ? (config.contentModifier as MyCheckboxStyle).selectedColor : Color.Black) 101 .stroke((config.contentModifier as MyCheckboxStyle).selectedColor) 102 .margin({ left: 11, top: 10 }) 103 } 104 .width(300) 105 .height(200) 106 .viewPort({ 107 x: 0, 108 y: 0, 109 width: 310, 110 height: 310 111 }) 112 .strokeLineJoin(LineJoinStyle.Miter) 113 .strokeMiterLimit(5) 114 .onClick(() => { 115 // Trigger the check box state change upon click. 116 if (config.selected) { 117 config.triggerChange(false) 118 } else { 119 config.triggerChange(true) 120 } 121 }) 122 .margin({ left: 150 }) 123 } 124} 125 126@Entry 127@Component 128struct Index { 129 build() { 130 Row() { 131 Column() { 132 Checkbox({ name: 'Check box status', group: 'checkboxGroup' }) 133 .select(true) 134 .contentModifier(new MyCheckboxStyle(Color.Red)) 135 .onChange((value: boolean) => { 136 console.info('Checkbox change is' + value) 137 }) 138 } 139 .width('100%') 140 } 141 .height('100%') 142 } 143} 144``` 145 146 147