• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# PasteButton
2
3
4The **\<PasteButton>** security component allows you to obtain temporary pasteboard permission from the user by their touching the button, eliminating the need for a permission request dialog box.
5
6
7> **NOTE**
8>
9> This component is supported since API version 10. Updates will be marked with a superscript to indicate their earliest API version.
10
11
12## Child Components
13
14Not supported
15
16
17## APIs
18### PasteButton
19PasteButton()
20
21Creates a Paste button with an icon, text, and background.
22
23### PasteButton
24PasteButton(option:{icon?: PasteIconStyle, text?: PasteDescription, buttonType?: ButtonType})
25
26Creates a Paste button that contains the specified elements.
27
28**Parameters**
29
30| Name| Type| Mandatory| Description|
31| -------- | -------- | -------- | -------- |
32| icon | [PasteIconStyle](#pasteiconstyle) | No| Icon style of the Paste button.<br>If this parameter is not specified, no icon is contained. Either **icon** or **text**, or both, must be set.|
33| text | [PasteDescription](#pastedescription) | No| Text on the Paste button.<br>If this parameter is not specified, no text is contained. Either **icon** or **text**, or both, must be set.|
34| buttonType | [ButtonType](ts-basic-components-button.md#buttontype) | No| Background style of the Paste button.<br>If this parameter is not specified, there is no background.|
35
36
37## Attributes
38
39This component can only inherit the [universal attributes of security components](ts-securitycomponent-attributes.md#attributes)
40
41
42## PasteIconStyle
43
44| Name| Value| Description|
45| -------- | -------- | -------- |
46| LINES | 0 | Line style icon.|
47
48
49## PasteDescription
50
51| Name| Value| Description|
52| -------- | -------- | -------- |
53| PASTE | 0 | The text on the Paste button is **Paste**.|
54
55
56## PasteButtonOnClickResult
57
58| Name| Value| Description|
59| -------- | -------- | -------- |
60| SUCCESS | 0 | The Paste button is touched successfully.|
61| TEMPORARY_AUTHORIZATION_FAILED | 1 | Temporary authorization fails after the Paste button is touched.|
62
63
64## Events
65
66Only the following events are supported.
67
68| Name| Description|
69| -------- | -------- |
70| onClick(event: (event: [ClickEvent](ts-universal-events-click.md#clickevent), result: [PasteButtonOnClickResult](#pastebuttononclickresult)) =&gt; void) | Triggered when the component is touched.<br>**result**: authorization result. After the authorization, the pasteboard content can be read.<br>**event**: For details, see **ClickEvent**.|
71
72
73## Example
74
75```
76// xxx.ets
77@Entry
78@Component
79struct Index {
80  build() {
81    Row() {
82      Column({space:10}) {
83        // Create a default Paste button with an icon, text, and background.
84        PasteButton().onClick((event: ClickEvent, result: PasteButtonOnClickResult)=>{
85          console.info("result " + result)
86        })
87        // Whether an element is contained depends on whether the parameter corresponding to the element is specified.
88        PasteButton({icon:PasteIconStyle.LINES})
89        // Create a Paste button with only an icon and background.
90        PasteButton({icon:PasteIconStyle.LINES, buttonType:ButtonType.Capsule})
91        // Create a Paste button with an icon, text, and background.
92        PasteButton({icon:PasteIconStyle.LINES, text:PasteDescription.PASTE, buttonType:ButtonType.Capsule})
93      }.width('100%')
94    }.height('100%')
95  }
96}
97```
98
99![en-us_image_0000001593677984](figures/en-us_image_0000001593677984.png)
100