• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# TS Component Reference Template
2
3## General Writing Instructions
4
5>  **NOTE**
6>
7> Delete all writing instructions after you finish the writing.
8
9|      | Item        | Writing Instruction                                      |
10| ---- | ----------- | ---------------------------------------- |
11| 1    | Customer-oriented mindset  | **Stand in the shoes of developers and provide the use cases, parameter selection principles, recommendations/tips, sample code, and anything else that a developer will need to develop the component.**|
12| 2   | Upload path       | Upload markdown files to `docs/en/application-dev/reference/arkui-ts`.<br>Upload images to `docs/en/application-dev/reference/arkui-ts/figures`. In addition, reference the image path in the markdown file as follows: `![](figures/exampleImage.jpg)`, `![](figures/exampleImage.png)`, or `![](figures/exampleImage.gif)`.|
13| 3    | File name       | Provide one TS component reference document for each .d.ts file. Name the file in the format of `ts-componentClassName-componentName.md`.<br>Examples:<br>For the basic component **\<text>**, the reference file name is `ts-basic-component-text.md`.<br>For the container component **\<list>**, the reference file name is `js-container-component-list.md`. |
14| 4    | Directory update       | After uploading a TS component reference document, update the `Readme-EN.md` file in `docs/en/application-dev/reference/arkui-ts`. |
15| 5    | Document structure       | - Component description<br>- Initial version description<br>- Modules to import/Usage description<br>- Permission description<br>- APIs, attributes, events, objects, enums, and custom types<br>The order in which APIs are described in the document must be consistent with that in which they appear in the code. If some APIs have a logical sequence, pay attention to their sequence in the document. |
16| 6    | Initial version description     | 1. Use the greater-than sign (`>`) followed by a space to indent the description about the initial version of the component. Unless otherwise marked, all APIs in the component have the same initial version.<br>2. When introducing an API to an existing component, use the `<sup>` tag to mark its initial version. The format is `<sup>versionNumber+</sup>`, for example, `<sup>7+</sup>`.<br>When introducing an attribute to an existing API, use the `<sup>` tag to mark its initial version. The format is `newAttribute<sup>versionNumber+</sup>`, for example, `newAttribute<sup>7+</sup>`. |
17| 7    | Deprecated API description     | Do not delete the deprecated content from the document. Instead, suffix `deprecated` as a superscript to the content, and use the greater-than sign (`>`) to introduce the substitute API plus a link to the API description.<br>Example: abandonmentMethod<sup>(deprecated)</sup><br>> This API is no longer maintained since API version 7. You are advised to use [newMethod]\(#newmethod) instead.|
18| 8    | Permission description       | Use "Required Permissions" as a level-2 heading.<br>1. If a specific permission required for using the component can be requested only by system applications, provide the description in the following format:<br>ohos.permission.examplePermission (available only to system applications)<br>2. If a specific permission required for using the component can be requested by all applications, provide the description in the following format:<br>ohos.permission.examplePermission<br>3. If multiple permissions are required for using the component, provide the permissions with `and` or `or` in the following format:<br>ohos.permission.examplePermissionA and ohos.permission.examplePermissionB<br>ohos.permission.examplePermissionA or ohos.permission.examplePermissionB |
19| 9   | @system api | 1. If all APIs of the component are system APIs, add the following sentence to the next line of the initial version description:<br>The APIs provided by this component are system APIs.<br>2. If an API is a system API that can be used only by original equipment manufacturers (OEMs), add the following sentence to the API description:<br>**System API**: This is a system API. |
20| 10   | Sample code programming language     | Use code blocks to provide sample code, and mark the programming language ts by adding `// xxx.ets` at the beginning of every sample code block.|
21| 11   | Link       | Link format: [Link text]\(Link content)<br>Cross-folder link format: [markdown file name]\(\.\./../xxx/xxx.md). One `./` indicates one upper-level folder.<br>Intra-topic link format: [Interface A<sup>7+</sup>]\(#xxxa7). The text in the intra-topic link must be the same as the title to be linked. In the link, all letters must be in lowercase, and no special character (except the hyphen) or tag is included.|
22
23The following describes the instructions for writing a specific component reference document.
24
25***
26
27# Document Title
28
29> *Writing Instructions:*
30>
31> 1. **Document title**: Use phrases that summarize the component functionalities. Examples: `Button` and `Slider`.
32> 2. **Heading levels**: Use the document title as the level-1 heading, which is prefixed with `#` followed by a space. Use the functions, classes, interfaces, enums, and types as level-2 headings, which are prefixed with `##` followed by a space. Use the attributes and functions under classes as level-3 headings, which are prefixed with `###` followed by a space.
33> 3. **Initial version description**: Use the greater-than symbol (`>`) to indent the description about the initial version of the component. Use a line break after **NOTE**. <br>Place the version description after the component description. A component has only one initial version. <br>Use the following sentence: "This component is supported since API version *x*. Newly added APIs will be marked with a superscript to indicate their earliest API version." Change ***x*** to the actual version number.
34
35Describe the component from its functionalities, use cases, and recommendations in this section.
36
37**Example 1**: \<Marquee>
38
39The **\<Marquee>** component is used to display a scrolling piece of text. The text is scrolled only when its width exceeds the width of the **\<Marquee>** component.
40
41**Example 2**: \<SideBarContainer>
42
43The **\<SideBarContainer>** component contains a sidebar and content area as its child components. The sidebar is the first child component and can be shown or hidden as needed. The content area is the second child component.
44
45> **NOTE**
46>
47> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
48
49## Modules to Import
50
51> *Writing Instructions:*
52>
53> 1. This section is optional. Delete it if the document is about a component or universal method.
54> 2. This section is mandatory if the document is about an API to be imported.
55> 3. Write the modules to import based on the actual conditions. Provide the **import** statement in the form of a code block.<br>**Example:**
56>
57
58```js
59import Curves from '@ohos.curves'
60```
61
62## Required Permissions
63
64> *Writing Instructions:*
65>
66> 1. This section is optional. Delete it if you do not need to apply for any permission to use the component.
67> 2. If a specific permission required for using the component can be requested only by system applications, provide the description in the following format:
68>    ohos.permission.examplePermission (available only to system applications)
69> 3. If a specific permission required for using the component can be requested by all applications, provide the description in the following format:
70>   ohos.permission.examplePermission
71> 4. If multiple permissions are required for using the component, provide the permissions with `and` or `or` in the following format:<br>
72>   ohos.permission.examplePermissionA and ohos.permission.examplePermissionB<br>
73>   ohos.permission.examplePermissionA or ohos.permission.examplePermissionB
74
75Example: ohos.permission.INTERNET<br>For details about how to apply for a permission, see [Permission Application Statement](../../application-dev/security/accesstoken-guidelines.md).
76
77## Child Components
78
79> *Writing Instructions:*
80>
81> 1. This section is mandatory if the document is about a built-in component that contains child components.
82> 2. Delete this section if the document is about a non-built-in component or a built-in component that does not contain child components.
83
84Example: Supported
85
86## APIs
87
88>*Writing Instructions:*
89>
90>1. This section is mandatory if the document is about a built-in component and the component has APIs.
91>2. The description of the API calling mode must be the same as that in the .d.ts file and include the parameter type and parameter name.
92>3. Add a question mark (?) after the parameter name to mark an optional parameter.
93>4. Use English symbols in the complete method name, and add a space after each colon (:).
94>5. Do not use a semicolon (;) at the end of the complete method name.
95>6. If a custom parameter type (such as object and enum) appears for the first time, describe the parameter type in an unordered list. If this type has been described in other places, use a relative link to reference it.
96>7. Note: The angle bracket (<>) may be identified as a label and not displayed. To ensure normal display, you can either add a backslash (\\) (in the format of "\\<>") or use escape characters \&lt; and \&gt;.
97>8. Note: The method in the component interface has no return value and is not presented in the form of level-2 or level-3 headings. It must also meet requirements described in [Methods](#methods).
98>9. Note: The default value must be described in a separate line in the description.
99
100If an API has two or more constructors, describe their differences.
101
102Provide the method name in the following format: methodName (parameterName1: parameterType1, parameterName2: parameterType2, ...) <br>If an API involves multiple methods, describe the methods in sequence and add a sequence number before the methods, for example, **method 1:**.
103
104Example: **Method 1**: Button(options?: { type?: ButtonType, stateEffect?: boolean })
105
106Describe the function of the method. If there are usage restrictions, describe them in detail.
107
108**options Parameters** (This part is optional. Delete it if there is no parameter.)
109
110| Name        | Type      | Mandatory  | Description                                      |
111| ----------- | ---------- | ---- | ---------------------------------------- |
112| type        | ButtonType | No   | Button type.<br>Default value: ButtonType.Capsule         |
113| stateEffect | boolean    | No   | Whether to enable the state switchover effect when a button is pressed. When the state is set to **false**, the state switchover effect is disabled.<br>Default value: true|
114
115## Attributes
116
117> *Writing Instructions:*
118>
119> 1. This section is optional. Delete it if there is no attribute.
120> 2. Create a link for a custom type (such as object and enum) to the corresponding interface or enum.
121> 3. Note: The default value must be described in a separate line in the description.
122
123If the document is about a built-in component, specify whether the component supports universal attributes.
124
125Example:
126
127In addition to the [universal attributes]\(a relative link to the Universal Attributes topic), the following attributes are supported.
128
129| Name        | Type             | Description                                      |
130| ---------- | --------------- | ---------------------------------------- |
131| alignItems | HorizontalAlign | Alignment mode of child components in the horizontal direction.<br>Default value: HorizontalAlign.Center|
132
133## Events
134
135> *Writing Instructions:*
136>
137> 1. This section is optional. Delete it if there is no event.
138> 2. Create a link for a custom type (such as object and enum) to the corresponding interface or enum. If this type appears for the first time, describe it under the event in the form of a level-2 heading. If this type has been described in other places, use a relative link to reference it.
139
140If the document is about a built-in component, specify whether the component supports universal events.
141
142Example:
143
144In addition to the [universal events]\(a relative link to the Universal Events topic), the following events are supported.
145
146Provide the invoking mode of each event. The requirements are the same as those in [Methods](#methods).
147
148### onSubmit
149
150onSubmit(callback: (value: string) => void)
151
152Triggered when users click the search icon or the search button, or touch the search button on a soft keyboard.
153
154**Parameters**
155
156| Name  | Type  | Mandatory| Description         |
157| ----- | ------ | ---- | ----------- |
158| value | string | Yes   | Current text input.|
159
160## Methods
161
162> *Writing Instructions:*
163>
164> 1. This section is optional. Delete it if there is no method. If there are multiple methods, describe them in separate level-2 headings, prefixed with `##` followed by a space.
165>
166> 2. Use the method name in the format of importedClassName.methodName as the level-2 heading.
167>
168>    Example: mediaquery.matchMediaSync
169>
170> 3. **Method calling mode**: The description must be the same as that in the .d.ts file and include the parameter type, parameter name, and return value type.
171>
172>    Example: matchMediaSync(condition: string): MediaQueryListener
173>
174> 4. The angle bracket (<>) may be identified as a label and not displayed. To ensure normal display, you can either add a backslash (\\) (in the format of "\\<>") or use escape characters \&lt; and \&gt;.
175>
176> 5. **Method description**: Describe the features implemented by the method and include the prerequisites for using the method, the impact of the method, and the permissions and system capabilities required to use the method. (*Example of prerequisites: This method can be called only after the xx method is called; you must ensure that the connection to the Internet is normal. Example of impact: xx does not take effect after this method is called.*)
177>
178> 6. **Line feed in a table**: Use \<br> for line feed.<br>
179
180Provide the method name in the following format: (**static** if it is a static method) methodName (parameterName1: parameterType1, parameterName2: parameterType2, ...): returnValueType
181
182Describe the method.
183
184**Parameters** (This part is optional. Delete it if there is no parameter.)
185
186| Name      | Type  | Mandatory  | Description        |
187| --------- | ------ | ---- | ---------- |
188| condition | string | Yes   | Matching condition of a media event.|
189
190**Return value** (This part is optional. Delete it if there is no return value.)
191
192| Type                | Description                    |
193| ------------------ | ---------------------- |
194| MediaQueryListener | Listening handle to a media event, which is used to register or deregister the listening callback.|
195
196**Example**
197
198```js
199// This part is mandatory.
200
201// Check all sample code provided in the example.
202// Minor errors such as missing symbols and variable inconsistency are unacceptable.
203// Declare all variables that are used.
204
205// Write an actual case that can be easily used, rather than the parameter names themselves. Use comments to describe the content that are not user-defined.
206// Example: var result = xxx.createExample(parameterOne); // parameterOne is automatically obtained by scanning.
207
208// Provide clear and concise comments in the following typical scenarios:
209// 1. The meaning of a variable name or the code logic is not clearly stated in the code.
210// 2. A complex algorithm or special syntax is involved.
211```
212
213## Classes
214
215> *Writing Instructions:*
216>
217> 1. This section is optional. Delete it if there is no class. If there are multiple classes, describe them in multiple level-2 headings, prefixed with `##` followed by a space.
218> 2. Use the actual class name as the level-2 heading.
219> 3. If the class contains both attributes and methods, write the attributes above the methods. Write their actual names in separate level-3 headings.
220> 4. If the class contains only attributes, you do not need to create a level-3 heading. Instead, use a table to display the attributes.
221
222Describe the functions, use cases, and restrictions of this class.
223
224### Objects to Import
225
226> *Writing Instructions:*
227>
228> This section is mandatory. Describes the class creation mode in the form of code segments.
229
230Example:
231
232```
233patternLockController: PatternLockController = new PatternLockController()
234```
235
236### Attributes
237
238> *Writing Instructions:*
239>
240> This section is optional. Except that a level-3 heading is used for attributes in classes/interfaces, other instructions are the same as those provided under [Attributes](#attributes).
241
242### Methods in Classes
243
244> *Writing Instructions:*
245>
246> 1. This section is optional. Use the actual method name as the level-3 heading. **Do not add a prefix.** Example: scrollTo
247> 2. You do not need to provide the sample code and sample diagram. Other requirements are the same as those in [Methods](#methods).
248
249## Enums
250
251> *Writing Instructions:*
252>
253> This section is optional. Describe the enums in the form of level-2 headings.
254
255### FlexDirection enums
256
257| Name           | Description              |
258| ------------- | ---------------- |
259| Row           | The child components are arranged in the same direction as the main axis runs along the rows. |
260| RowReverse    | Center aligned. This is the default alignment mode.    |
261| Column        | The child components are arranged in the same direction as the main axis runs down the columns. |
262| ColumnReverse | The child components are arranged opposite to the `Column` direction.|
263
264## Objects
265
266> *Writing Instructions:*
267>
268> 1. This section is optional. Describe the objects in the form of level-2 headings.
269
270### MouseEvent
271
272| Field     | Type  | Description                |
273| --------- | ------ | ------------------ |
274| timestamp | number | Timestamp when the event is triggered.        |
275| screenX   | number | X-coordinate of the clicked point relative to the upper left corner of the screen.|
276| screenY   | number | Y-coordinate of the clicked point relative to the upper left corner of the screen.|
277
278## Example
279
280Provide the display effect of the example.
281
282> *Writing Instructions:*
283>
284> 1. This section is mandatory. Use a level-2 or level-3 heading, and provide sample codes and figures under the heading.
285> 2. Use multiple level-3 headings to present the function of a component or module one by one, if the functions are complex.
286>
287> ```tsx
288> // This part is mandatory.
289>
290> // Check all sample code provided in the example.
291> // Minor errors such as missing symbols and variable inconsistency are unacceptable.
292> // Declare all variables that are used.
293> // Mark the programming language of the sample code.
294>
295> // Write an actual case that can be easily used, rather than the parameter names themselves. Use comments to describe the content that are not user-defined.
296> // Example: var result = xxx.createExample(parameterOne); // parameterOne is automatically obtained by scanning.
297>
298> // The layout of the image must be clear, the color must be simple and elegant, and the image must be copyrighted.
299>
300> // Provide clear and concise comments in the following typical scenarios:
301> // 1. The meaning of a variable name or the code logic is not self-explanatory.
302> // 2. A complex algorithm or special syntax is involved.
303> ```
304
305Example:
306
307```ts
308// xxx.ets
309@Entry
310@Component
311struct CheckboxExample {
312  build() {
313    Row() {
314      // Generate a check box that is selected by default and can be clicked to display its status.
315      Checkbox({name: 'checkbox1',  group: 'checkboxGroup'})
316        .select(true)
317        .selectedColor(0xed6f21)
318        .onChange((value: boolean) => {
319          console.info('Checkbox1 change is'+ value)
320        })
321      // Generate a check box that is not selected by default and can be clicked to display its status.
322      Checkbox({name: 'checkbox2',  group: 'checkboxGroup'})
323        .select(false)
324        .selectedColor(0x39a2db)
325        .onChange((value: boolean) => {
326          console.info('Checkbox2 change is'+ value)
327        })
328    }
329  }
330}
331```
332<!--no_check-->
333