23
loading...
This website collects cookies to deliver better user experience
*** 50% complete ***
on the screen wasn’t all that exciting.“Focus your time on delivering features/functionality which extends the value of your intellectual property. Leverage frameworks, products, and services for everything else.”
J. Vester
having-fun-with-the-lightning-design-system
by executing v2 of the Create React App CLI using the following command:npx create-react-app having-fun-with-the-lightning-design-system
react-app-rewired dependency
in to the React applicationdesign-system
and design-system-react
Salesforce dependencies into the React application../public
folder of the React application.index.html
of the React application to include the salesforce-lightning-design-system.min.css
stylesheet file.index.js
of the React application to wrap the <App />
element inside an <Icon Settings>
element.npm ci
command to make sure all the necessary dependencies were installed and ready.setTimeout()
timer to make the spinner act as if something is being loaded from a remote service. For simplicity, I made all my code changes in the App.js
file already created by the Create React App CLI.render()
function:{this.state.showAlert &&
<div>
<AlertContainer>
<Alert
icon={<Icon category="utility" name="user"></Alert>}
labels={{
heading: 'This is an Informational Alert',
headingLink: 'Close this Alert',
}}
onClickHeadingLink={() => this.closeAlert()}
/>
</AlertContainer>
</div>
}
state = {
showAlert: true,
...
closeAlert()
function in the JavaScript portion of the App.js
file to cause the alert to no longer display:closeAlert() {
this.setState({showAlert: false});
}
showSpinner
to the App.js
file and included the following timer code to simulate waiting for a service request to finish:state = {
...
showSpinner: true,
...
componentDidMount() {
this.timer = setTimeout(
() => {
this.setState({showSpinner: false});
},
3000,
);
}
showSpinner
property to false
, which causes the spinner to no longer display. Adding the spinner to the application was quite simple:{this.state.showSpinner &&
<div style={{marginTop: 10, position: 'relative', height: '5rem'}}>
<Spinner
size="small"
variant="base"
assistiveText={{label: 'Getting Data, Please Wait ...'}}
></Spinner>
</div>
}
showSpinner
boolean was set to false
. This would emulate typical functionality where the spinner displays while data is being retrieved. Once retrieved, the spinner disappears and the application content—presented using a badge, data table, and trial bar—becomes available.<div style={{marginTop: 10}}>
<Badge
id="badge-base-example-success"
color="success"
content="2,112.00 Purchase Credits Available"
icon={
<Icon
category="utility"
name="moneybag"
size="xx-small"
colorVariant="base"
></Badge>
}
/>
</div>
render()
function in the App.js
included the data table code shown below:<div style={{marginTop: 25, overflow: 'auto'}}>
<DataTable
items={this.state.items}
id="DataTableExample-music"
striped
>
<DataTableColumn key="album" label="Album Name" property="albumName"></DataTableColumn>
<DataTableColumn key="release-date" label="Release Date" property="releaseDate"></DataTableColumn>
<DataTableColumn key="sales" label="Original Copies Sold" property="sales"></DataTableColumn>
<DataTableColumn key="label" label="Label" property="label"></DataTableColumn>
<DataTableColumn key="credits" label="Credits" property="credits" right="right"></DataTableColumn>
<DataTableRowActions
options={[
{
id: 0,
label: 'Buy this Song',
value: '1',
},
{
id: 1,
label: 'Save for Later',
value: '2',
},
{
id: 2,
label: 'Preview this Song',
value: '3',
}
]}
onAction={this.handleRowAction}
dropdown={<Dropdown length="3"></DataTableRowActions>}
/>
</DataTable>
</div>
[
{
id: '0',
albumName: 'Grace Under Pressure',
releaseDate: '7/1/1984',
sales: '1,000,000 (Platinum)',
label: 'Mercury',
credits: 13.06
},
...
handleRowAction = (item, action) => {
console.log(item, action);
};
render()
function using the following code:<div style={{marginTop: 25}}>
<TrialBar
labels={{timeLeft: '15', timeLeftUnit: 'days'}}
onRenderActions={() => (
<Button variant="success" label="Subscribe Now"></Button>
)}
>
<div style={{marginTop: 15}}>Never miss another deal again, press the <strong>Subscribe Now</strong> button to get started today.
</div>
</TrialBar>
</div>
npm start