From 4263f6b8764bb147e301c3dbba0ac4986959aad8 Mon Sep 17 00:00:00 2001 From: Sandile Date: Tue, 7 Sep 2021 11:43:11 +0200 Subject: [PATCH 1/2] feat(blocksAntd): Card block now has an onClick event. --- packages/blocks/blocksAntd/demo/examples/Card.yaml | 10 ++++++++++ packages/blocks/blocksAntd/src/blocks/Card/Card.js | 7 ++++++- packages/blocks/blocksAntd/src/blocks/Card/Card.json | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/blocks/blocksAntd/demo/examples/Card.yaml b/packages/blocks/blocksAntd/demo/examples/Card.yaml index 4ef789a22..63f1df886 100644 --- a/packages/blocks/blocksAntd/demo/examples/Card.yaml +++ b/packages/blocks/blocksAntd/demo/examples/Card.yaml @@ -49,3 +49,13 @@ type: Card properties: title:
Card Title
+- id: 'with onClick event' + type: Card + properties: + title: Card block + events: + onClick: + - id: message + type: message + params: + content: Success diff --git a/packages/blocks/blocksAntd/src/blocks/Card/Card.js b/packages/blocks/blocksAntd/src/blocks/Card/Card.js index 67dceca5d..f8a1e97f6 100644 --- a/packages/blocks/blocksAntd/src/blocks/Card/Card.js +++ b/packages/blocks/blocksAntd/src/blocks/Card/Card.js @@ -18,7 +18,7 @@ import React from 'react'; import { Card } from 'antd'; import { blockDefaultProps, RenderHtml } from '@lowdefy/block-tools'; -const CardBlock = ({ blockId, content, properties, methods }) => ( +const CardBlock = ({ blockId, content, properties, methods, events }) => ( ( hoverable={properties.hoverable} size={properties.size} type={properties.inner ? 'inner' : null} + onClick={() => methods.triggerEvent({ name: 'onClick' })} + className={methods.makeCssClass([ + { outline: 'none', cursor: events.onClick && 'pointer' }, + properties.style, + ])} > {content.content && content.content()} diff --git a/packages/blocks/blocksAntd/src/blocks/Card/Card.json b/packages/blocks/blocksAntd/src/blocks/Card/Card.json index 0f41c5964..db4785cd3 100644 --- a/packages/blocks/blocksAntd/src/blocks/Card/Card.json +++ b/packages/blocks/blocksAntd/src/blocks/Card/Card.json @@ -51,6 +51,16 @@ "description": "Title to show in the title area - supports html. Overwritten by blocks in the title content area." } } + }, + "events": { + "type": "object", + "additionalProperties": false, + "properties": { + "onClick": { + "type": "array", + "description": "Trigger actions when the Card is clicked." + } + } } } } From 5fd636db37a957f7ac569ebe14ebfce5b4ddbe98 Mon Sep 17 00:00:00 2001 From: Sandile Date: Tue, 7 Sep 2021 15:01:43 +0200 Subject: [PATCH 2/2] chore(blocksAntd): Updated Card tests. --- .../__snapshots__/Card.mock.test.js.snap | 216 ++++++++++++++++++ .../tests/__snapshots__/Card.test.js.snap | 74 +++++- 2 files changed, 280 insertions(+), 10 deletions(-) diff --git a/packages/blocks/blocksAntd/tests/__snapshots__/Card.mock.test.js.snap b/packages/blocks/blocksAntd/tests/__snapshots__/Card.mock.test.js.snap index 9aadbb027..2c311a265 100644 --- a/packages/blocks/blocksAntd/tests/__snapshots__/Card.mock.test.js.snap +++ b/packages/blocks/blocksAntd/tests/__snapshots__/Card.mock.test.js.snap @@ -16,6 +16,7 @@ Array [ > content , + "className": "{\\"style\\":[{\\"outline\\":\\"none\\"},null]}", "extra":
content
, + "className": "{\\"style\\":[{\\"outline\\":\\"none\\"},null]}", "extra": undefined, "headStyle": "{\\"options\\":{\\"styleObjectOnly\\":true}}", "hoverable": undefined, "id": "default", + "onClick": [Function], "size": undefined, "title": undefined, "type": null, @@ -118,10 +135,12 @@ Array [ > content , + "className": "{\\"style\\":[{\\"outline\\":\\"none\\"},null]}", "extra": undefined, "headStyle": "{\\"options\\":{\\"styleObjectOnly\\":true}}", "hoverable": undefined, "id": "properties.bodyStyle: border: 5px solid blue", + "onClick": [Function], "size": undefined, "title": content , + "className": "{\\"style\\":[{\\"outline\\":\\"none\\"},null]}", "extra": undefined, "headStyle": "{\\"options\\":{\\"styleObjectOnly\\":true}}", "hoverable": undefined, "id": "properties.bordered: false", + "onClick": [Function], "size": undefined, "title": content , + "className": "{\\"style\\":[{\\"outline\\":\\"none\\"},null]}", "extra": undefined, "headStyle": "{\\"style\\":{\\"border\\":\\"5px solid blue\\"},\\"options\\":{\\"styleObjectOnly\\":true}}", "hoverable": undefined, "id": "properties.headerStyle: border: 5px solid blue", + "onClick": [Function], "size": undefined, "title": content , + "className": "{\\"style\\":[{\\"outline\\":\\"none\\"},null]}", "extra": undefined, "headStyle": "{\\"options\\":{\\"styleObjectOnly\\":true}}", "hoverable": true, "id": "properties.hoverable: true", + "onClick": [Function], "size": undefined, "title": content , + "className": "{\\"style\\":[{\\"outline\\":\\"none\\"},null]}", "extra": undefined, "headStyle": "{\\"options\\":{\\"styleObjectOnly\\":true}}", "hoverable": undefined, "id": "properties.inner: true", + "onClick": [Function], "size": undefined, "title": content , + "className": "{\\"style\\":[{\\"outline\\":\\"none\\"},null]}", "extra": undefined, "headStyle": "{\\"options\\":{\\"styleObjectOnly\\":true}}", "hoverable": undefined, "id": "properties.size: small", + "onClick": [Function], "size": "small", "title": content , + "className": "{\\"style\\":[{\\"outline\\":\\"none\\"},null]}", "extra": undefined, "headStyle": "{\\"options\\":{\\"styleObjectOnly\\":true}}", "hoverable": undefined, "id": "properties.title", + "onClick": [Function], "size": undefined, "title": content , + "className": "{\\"style\\":[{\\"outline\\":\\"none\\"},null]}", "extra": undefined, "headStyle": "{\\"options\\":{\\"styleObjectOnly\\":true}}", "hoverable": undefined, "id": "with html in title", + "onClick": [Function], "size": undefined, "title": @@ -595,6 +719,15 @@ Array [ "styleObjectOnly": true, }, ], + Array [ + Array [ + Object { + "cursor": undefined, + "outline": "none", + }, + undefined, + ], + ], ], "results": Array [ Object { @@ -605,6 +738,89 @@ Array [ "type": "return", "value": "{\\"options\\":{\\"styleObjectOnly\\":true}}", }, + Object { + "type": "return", + "value": "{\\"style\\":[{\\"outline\\":\\"none\\"},null]}", + }, + ], + }, + "registerEvent": [Function], + "registerMethod": [Function], + "triggerEvent": [Function], + } + } + />, + "type": null, + }, + Object {}, + ], +] +`; + +exports[`Mock render - with onClick event - value[0] - default 1`] = ` +Array [ + Array [ + Object { + "bodyStyle": "{\\"options\\":{\\"styleObjectOnly\\":true}}", + "bordered": undefined, + "children":
+ content +
, + "className": "{\\"style\\":[{\\"outline\\":\\"none\\",\\"cursor\\":\\"pointer\\"},null]}", + "extra": undefined, + "headStyle": "{\\"options\\":{\\"styleObjectOnly\\":true}}", + "hoverable": undefined, + "id": "with onClick event", + "onClick": [Function], + "size": undefined, + "title":
+
+
+
+ +
+
+
+
+
+ content +
+
+
+`; + +exports[`Render with onClick event - value[0] 1`] = ` +