项目作者: Stwissel

项目描述 :
Experiments with Aura and LWC Lightning components
高级语言: JavaScript
项目地址: git://github.com/Stwissel/lwcaura.git
创建时间: 2019-03-12T18:08:53Z
项目社区:https://github.com/Stwissel/lwcaura

开源协议:

下载


LWC - Aura experiments

All experiments require that you deploy the components to a Salesforce instance.
Use sfdx force:source:deploy -p experiments/experiment[number] to deploy the one you are interested in

Experiment 1

Compare the modal dialog between Aura and LWC. 2 buttons launch idendical components one Aura, one LWC.
The components use the same backend APEX class. Fetches the record type for a given object and a random
number of colors.

Syntax for AURA component:

  1. <aura:handler name="RecordTypeSelected" event="c:RecordTypeSelected" action="{!c.getRecType}"></aura:handler>
  2. <c:SampleDialogAura objectName="Opportunity" heading="Aura: Pick an Opportunity and Color" ></c:SampleDialogAura>

Syntax for LWC component:

  1. <c:sampleDialogLwc objectName="Opportunity" heading="LWC: Pick an Opportunity and Color" onselectionmade="{!c.lwcselection}" ></c:sampleDialogLwc>

Components

  • SampleDialogController.cls
  • SampleDialogControllerTest.cls
  • aura/RecordTypeSelected
  • aura/SampleDialogAura
  • aura/DemoLWCAuraContainer
  • lwc/sampleDialogLwc

Setup

  • Opportunity object needs to have a record type (or change the call to fetch another object)
  • Create a lightning page and add DemoLWCAuraContainer to it - or add that to any lightning page
  • Deploy with sfdx force:source:deploy -p experiments/experiment1

Experiment 2

Experiment 3

Experiment 4

Experiment 5

Experiment 6

Experiment 7

Creation of 2 lwc components. The slotMachine has an unnamed <slot> element that can be filled with multiple colorEmitter custom elements. bubbleDemo shows an example how it can be uses:

  1. <template>
  2. <div style="background-color: #FFFFFF">
  3. <h1>Slotmachine</h1>
  4. <c-slot-machine>
  5. <c-color-emitter color="red"></c-color-emitter>
  6. <c-color-emitter color="yellow"></c-color-emitter>
  7. <c-color-emitter color="green"></c-color-emitter>
  8. </c-slot-machine>
  9. </div>
  10. </template>

Add the bubbleDemo to a lightning app page. colorEmitter emits a custom event colorSelected that the slotMachine listens to.

Experiment 8

Extending the ability of record-edit-form to use custom input fields. Forms can look this this:

  1. <template>
  2. <lightning-card title="Form Sample">
  3. <div class="slds-p-horizontal_small">
  4. <c-extended-form object-api-name="Account">
  5. <lightning-layout-item size="6" padding="around-medium">
  6. <lightning-input-field
  7. field-name="Name"
  8. ></lightning-input-field>
  9. </lightning-layout-item>
  10. <lightning-layout-item size="6" padding="around-medium"
  11. ><lightning-input-field
  12. field-name="AccountSource"
  13. ></lightning-input-field
  14. ></lightning-layout-item>
  15. <lightning-layout-item size="6" padding="around-medium"
  16. ><lightning-input-field
  17. field-name="AccountNumber"
  18. ></lightning-input-field
  19. ></lightning-layout-item>
  20. <lightning-layout-item size="6" padding="around-medium"
  21. ><c-special-input
  22. field-name="Phone"
  23. data-field
  24. ></c-special-input>
  25. </lightning-layout-item>
  26. </c-extended-form>
  27. </div>
  28. </lightning-card>
  29. </template>