Skip to content

Commit

Permalink
feat(actions-core): Add CopyToClipboard action.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yianni99 committed Aug 4, 2023
1 parent 7ca5772 commit 964cd8f
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 0 deletions.
47 changes: 47 additions & 0 deletions packages/docs/actions/CopyToClipboard.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2020-2023 Lowdefy, Inc

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

_ref:
path: templates/actions.yaml.njk
vars:
pageId: CopyToClipboard
pageTitle: CopyToClipboard
filePath: actions/CopyToClipboard.yaml
types: |
```
(params: {
copy: string,
}): void
```
description: |
The `CopyToClipboard` action is used to copy content to the clipboard, based on [`Clipboard`](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText).
params: |
###### object
- `copy: string`: __Required__ - Text to be copied to the clipboard.
examples: |
###### Copy text button:
```yaml
- id: copy_button
type: Button
properties:
title: Copy Text
events:
onClick:
- id: copy
type: CopyToClipboard
params:
copy: Lorem ipsum dolor sit amet
messages:
success: Copied!
```
3 changes: 3 additions & 0 deletions packages/docs/menus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,9 @@
- id: CallMethod
type: MenuLink
pageId: CallMethod
- id: CopyToClipboard
type: MenuLink
pageId: CopyToClipboard
- id: DisplayMessage
type: MenuLink
pageId: DisplayMessage
Expand Down
1 change: 1 addition & 0 deletions packages/docs/pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
- _ref: connections/Stripe.yaml

- _ref: actions/CallMethod.yaml
- _ref: actions/CopyToClipboard.yaml
- _ref: actions/DisplayMessage.yaml
- _ref: actions/DownloadCsv.yaml
- _ref: actions/Fetch.yaml
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/actions/actions-core/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

export { default as CallMethod } from './actions/CallMethod.js';
export { default as CopyToClipboard } from './actions/CopyToClipboard.js';
export { default as Link } from './actions/Link.js';
export { default as Login } from './actions/Login.js';
export { default as Logout } from './actions/Logout.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright 2020-2023 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

async function CopyToClipboard({ globals, params }) {
const { window } = globals;
const { copy } = params;
window.navigator.clipboard.writeText(copy);
}

export default CopyToClipboard;
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2020-2023 Lowdefy, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { jest } from '@jest/globals';
import CopyToClipboard from './CopyToClipboard.js';

const mockWriteText = jest.fn();

const window = {
navigator: {
clipboard: { writeText: mockWriteText },
},
};

const globals = { window };

test('CopyToClipboard mock test', async () => {
CopyToClipboard({
globals,
params: { copy: 'Copy content.' },
});
expect(mockWriteText.mock.calls).toEqual([['Copy content.']]);
});

0 comments on commit 964cd8f

Please sign in to comment.