Jargon - is labelled like this, you don’t have to read it but it will help your understanding if you do.
Important - You need to understand this.
Command - Stuff you need to type is inside the single quotes (not including the single quotes) - that’s type, not copy - you'll learn more if you type it.
Action - Stuff you need to do, separated by >. Example - Start > 'cmd'
Start being an action to press start on the task bar, and then (denoted by > ), type 'cmd'
Action - Install vscode - https://code.visualstudio.com/
Action - Install node.js (the LTS Version recommended for most users) - https://nodejs.org/en/
Jargon - node is an open source server environment, which includes a package manager (npm) which means I can use other (really clever) peoples stuff. All I need to do is install it and then import modules into my application. When I do this my application takes note of the dependency and makes sure it is always packaged together.
Important - node.js RUNS ON THE SERVER. A server can be my local laptop or some kind of server in a datacentre or somewhere in the cloud. Node.js sends the HTML code that I write to your browser, just like any other web server, but you're in complete control, similar to having a super power.
Important - Along with cool modules which I can use for free, some clever people thought it would be a good idea to provide templates, so I don’t get weighed down with the boring stuff. This is called Bootstrapping. I'm going to use a template to bootstrap my new application:
Start > 'cmd'
Or
Start > 'PowerShell'
'cd \;mkdir localDev; cd localDev'
'npx create-react-app meaps'
Jargon - create-react-app is a toolchain. There are various other tools chains for different types of applications here
'cd meaps'
'npm start'
Action - Press 'ctrl c' and type 'y' to Terminate batch job.
'code .'
code then a space and then a period.
This will open vscode in the correct directory. When I refresh my browser I get an error because I cancelled the batch job. To fix this, in vscode:
Action - Pull down menu > Terminal > New Terminal
Action - Left of the trash can > click on the 2 window
'npm start'
Action - MEAPS > src > app.js
Action - replace all the cope with:
import React from 'react';
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
SAPUI5 Components are lightweight, easy to use and super-fast in loading.
</p>
<p>
Some of the components can be containers for other non UI5 components,
</p>
<p>
There is even a whole category of ui5 react charts
</p>
<a
className="App-link"
href="https://sap.github.io/ui5-webcomponents-react/?path=/docs/charts-piechart--render-formated-story"
target="_blank"
rel="noopener noreferrer"
>
Explore React Charts
</a>
</header>
</div>
);
}
export default App;
Cntrl 's'
Jargon - Files and folder structure, I'll be brief; MEAPS is my source (base) folder and holder files that describe (to the package manager NPM) dependencies, and some other run and build parameters. The important file is package.json, more on this later. MEAPS\node-modules folder holds all the good stuff other people have coded. MEAPS\public holds the static files of my application, these files are immutable (cannot change them) acting as resources for node.js to call. MEAPS\src this is where the magic happens, where the code goes that is run by node when I run npm start. You really don't need to know this - I can trace the execution of the npm start command in the package.json > scripts > react-scripts start. React-scripts is a module in the node_modules folder where I will find react-scripts/scripts/start.js, and if I keep following the code I may find a bucket of gold at either end of the rainbow function… ok enough of that…
Jargon - In order for vscode to syntax check and autocomplete (intellicode) I have to tell it I am as using React by using the file extension .jsx. I also get the added benefit of the React syntax extension which I will need. I can also continue to use regular JS components… win win win
Action - right click src folder > select New File > 'Home.jsx'
import React from "react";
import { useHistory } from "react-router-dom";
export function Home() {
const history = useHistory();
return (
<p>
Not much to look at
</p>
);
}
Action - ctrl S
Action - 'npm install react-router-dom'
Action - 'npm install @ui5/webcomponents'
Action - 'npm install @ui5/webcomponents-react'
Action - 'npm install @ui5/webcomponents-fiori'
Action - MEAPS/app.js
import React from 'react';
import { HashRouter } from "react-router-dom";
import { ThemeProvider } from "@ui5/webcomponents-react/lib/ThemeProvider";
import "@ui5/webcomponents/dist/Assets.js";
import { Home } from "./Home"
function App() {
return (
<HashRouter>
<ThemeProvider>
<Home />
</ThemeProvider>
</HashRouter>
);
}
export default App;
Action - ctrl S
Action - right click src folder > select New File > 'Home.jsx'
import React from "react";
import { useHistory } from "react-router-dom";
import { ShellBar, ShellBarItem } from "@ui5/webcomponents-react";
import "@ui5/webcomponents/dist/Assets.js";
export function Home() {
const history = useHistory();
const handleLogoClick = () => {
history.push("./");
};
return <>
<ShellBar
logo={<img src="logo192.png" />}
primaryTitle="MEAPs"
onLogoClick={handleLogoClick} >
<ShellBarItem icon="add" text="Add" />
</ShellBar>
</>;
}
My browser now looks like this:
Action - right click src folder > select New File > 'Page1.jsx'
Then copy and paste the following code:
import React, { Component } from 'react';
import {
Card
FlexBox,
FlexBoxJustifyContent,
FlexBoxWrap,
Icon
} from "@ui5/webcomponents-react";
import { spacing } from "@ui5/webcomponents-react-base";
import "@ui5/webcomponents/dist/Assets.js";
import { useHistory } from "react-router-dom";
class Page1 extends Component {
render() {
return (
<FlexBox
justifyContent={FlexBoxJustifyContent.Center}
wrap={FlexBoxWrap.Wrap}
>
<Card
heading="A UI5 Card"
style={{ width: "300px", ...spacing.sapUiContentPadding }}
avatar={<Icon name="table-view" />}>
</Card>
</FlexBox>
);
};
}
export default Page1;
import Page1 from "./Page1.jsx";
import { useHistory, Switch, Route, Redirect } from "react-router-dom";
return <>
<ShellBar
logo={<img src="logo192.png" />}
primaryTitle="MEAPs"
onLogoClick={handleLogoClick} >
<ShellBarItem icon="add" text="Add" />
</ShellBar>
<Switch>
<Route path="/page1" component={Page1} />
<Redirect from="/" to="/page1" />
</Switch>
</>;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
28 | |
14 | |
12 | |
11 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 |