Skip to content

Commit 412e056

Browse files
authored
Merge pull request #23373 from Lukas742/master
ui5-webcomponents-react: use vite template
2 parents ffec0e2 + 3c7872e commit 412e056

File tree

19 files changed

+179
-171
lines changed

19 files changed

+179
-171
lines changed
Loading
Loading
Loading

tutorials/ui5-webcomponents-react-card/ui5-webcomponents-react-card.md

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ There you can try out the different components and also take a look at the codin
2323

2424
---
2525

26-
### Add components to MyApp.jsx
26+
### Add components to MyApp.tsx
2727

2828
First you need to import the components you want to use.
2929

3030
You can check out all available components in the [Storybook](https://sap.github.io/ui5-webcomponents-react). Take your time to play around a little, change some `props` and take a look at the coding.
3131

32-
1. Start with importing a `Card` component into your `MyApp.jsx` file (right below the existing import statement).
32+
1. Start with importing a `Card` component into your `MyApp.tsx` file.
3333

34-
```JavaScript / JSX
34+
```TypeScript / TSX
3535
import { Card } from "@ui5/webcomponents-react";
3636
```
3737

3838
2. So, you imported the `Card` component. Now it's time to use it. Replace the content of your `<div>` with a `<Card>`.
3939

4040
In the [Storybook](https://sap.github.io/ui5-webcomponents-react/?path=/story/4-ui5-web-components-card--default-story), you can see that Cards can receive different props. For now only add some text as `children`.
4141

42-
```JavaScript / JSX
42+
```TypeScript / TSX
4343
<div>
4444
<Card>This is the content area of the Card</Card>
4545
</div>
@@ -51,7 +51,7 @@ Your webpage should now look like this.
5151

5252
And the file like this:
5353

54-
```JavaScript / JSX
54+
```TypeScript / TSX
5555
import { Card } from "@ui5/webcomponents-react";
5656
5757
export function MyApp() {
@@ -71,13 +71,13 @@ The heading area of the `Card` component is empty, this is because it didn't rec
7171

7272
1. Import the `CardHeader`.
7373

74-
```JavaScript / JSX
74+
```TypeScript / TSX
7575
import { Card, CardHeader } from "@ui5/webcomponents-react";
7676
```
7777

7878
2. Add the `CardHeader` component to your `Card` and give it a title by setting the `titleText` prop:
7979

80-
```JavaScript / JSX
80+
```TypeScript / TSX
8181
<div>
8282
<Card header={<CardHeader titleText="Card" />}>
8383
This is the content area of the Card
@@ -87,15 +87,15 @@ The heading area of the `Card` component is empty, this is because it didn't rec
8787

8888
2. Now the `Card` has a header area, but the `font-family` of the content area differs from the `Card` header. All UI5 Web Components for React components use the same styling, this includes `font-family`, `color`, etc.
8989

90-
Add the `Text` import to your `MyApp.jsx` file.
90+
Add the `Text` import to your `MyApp.tsx` file.
9191

92-
```JavaScript / JSX
92+
```TypeScript / TSX
9393
import { Card, CardHeader, Text } from "@ui5/webcomponents-react";
9494
```
9595

9696
And wrap the text within the `Text` component.
9797

98-
```JavaScript / JSX
98+
```TypeScript / TSX
9999
<div>
100100
<Card header={<CardHeader titleText="Card" />}>
101101
<Text>This is the content area of the Card</Text>
@@ -109,13 +109,13 @@ The `font-family` of the content now corresponds to the `font-family` of the hea
109109

110110
### Style your component
111111

112-
In this step, we will only apply [inline-styling](https://reactjs.org/docs/dom-elements.html#style). You can also style your component using normal CSS or even authoring tools like [JSS](https://cssinjs.org/?v=v10.0.0), but this will be covered in [Tutorial 6](ui5-webcomponents-react-styling) of the tutorial series.
112+
In this step, we will only apply [inline-styling](https://reactjs.org/docs/dom-elements.html#style). You can also style your component using normal CSS or even authoring tools like [JSS](https://cssinjs.org), but this will be covered in [Tutorial 6](ui5-webcomponents-react-styling) of the tutorial series.
113113

114114
The Card now spreads across the whole screen, this behavior is intended so it takes up the whole space of its container.
115115

116116
1. To restrict the `width` of the `Card`, add the `style` prop.
117117

118-
```JavaScript / JSX
118+
```TypeScript / TSX
119119
<Card header={<CardHeader titleText="Card" />} style={{ width: "300px" }}>
120120
<Text>This is the content area of the Card</Text>
121121
</Card>
@@ -128,28 +128,27 @@ The Card now spreads across the whole screen, this behavior is intended so it ta
128128
Execute this in your terminal:
129129

130130
```Shell
131-
npm install @ui5/webcomponents-react-base --save
131+
npm install @ui5/webcomponents-react-base
132132
```
133133

134134
Then import:
135135

136-
```JavaScript / JSX
136+
```TypeScript / TSX
137137
import { spacing } from "@ui5/webcomponents-react-base";
138138
```
139139

140140
And finally add this to your `Text` component:
141141

142-
```JavaScript / JSX
142+
```TypeScript / TSX
143143
<Text style={spacing.sapUiContentPadding}>
144144
This is the content area of the Card
145145
</Text>
146146
```
147147
Hereby you get a standardized content-padding. `spacing` comes with many more properties, feel free to test them and see what they do.
148148

149-
After this step `MyApp.jsx` should look like this:
150-
```JavaScript / JSX
151-
import React from "react";
152-
import { Card, Text, CardHeader } from "@ui5/webcomponents-react";
149+
After this step `MyApp.tsx` should look like this:
150+
```TypeScript / TSX
151+
import { Card, CardHeader, Text } from "@ui5/webcomponents-react";
153152
import { spacing } from "@ui5/webcomponents-react-base";
154153
155154
export function MyApp() {
@@ -174,7 +173,7 @@ And your application like this:
174173

175174
1. The Card header can also be clickable. For this you need to set its `interactive` prop to true.
176175

177-
```JavaScript / JSX
176+
```TypeScript / TSX
178177
<Card
179178
header={<CardHeader titleText="Card" interactive />}
180179
...
@@ -185,7 +184,7 @@ And your application like this:
185184

186185
2. To make the header react to a click, add a function as value to the `onClick` prop.
187186

188-
```JavaScript / JSX
187+
```TypeScript / TSX
189188
<Card
190189
header={
191190
<CardHeader
@@ -199,7 +198,7 @@ And your application like this:
199198
```
200199
201200
3. Now, add the callback function right in the beginning of the component (definition function):
202-
```JavaScript / JSX
201+
```TypeScript / TSX
203202
export function MyApp() {
204203
const handleHeaderClick = () => {
205204
alert("Header clicked");
@@ -208,8 +207,7 @@ And your application like this:
208207
```
209208
210209
The file now looks like this:
211-
```JavaScript / JSX
212-
import React from "react";
210+
```TypeScript / TSX
213211
import { Card, Text, CardHeader } from "@ui5/webcomponents-react";
214212
import { spacing } from "@ui5/webcomponents-react-base";
215213

Loading
Loading

tutorials/ui5-webcomponents-react-charts/ui5-webcomponents-react-charts.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ UI5 Web Components for React also comes with a chart library. In this tutorial,
2929
npm install @ui5/webcomponents-react-charts
3030
```
3131

32-
2. Then, import `LineChart` and `BarChart` into `MyApp.jsx`.
32+
2. Then, import `LineChart` and `BarChart` into `MyApp.tsx`.
3333

34-
```JavaScript / JSX
34+
```TypeScript / TSX
3535
import { BarChart, LineChart } from "@ui5/webcomponents-react-charts";
3636
```
3737
@@ -40,7 +40,7 @@ UI5 Web Components for React also comes with a chart library. In this tutorial,
4040
4141
1. Start with the `LineChart`. You can add it underneath the `Text` component. Then pass the `dimensions` and `measures` prop with an empty array as value.
4242
43-
```JavaScript / JSX
43+
```TypeScript / TSX
4444
<Text style={spacing.sapUiContentPadding}>
4545
This is the content area of the Card
4646
</Text>
@@ -51,7 +51,7 @@ UI5 Web Components for React also comes with a chart library. In this tutorial,
5151
5252
2. Add data to your component, since `data` is static you can define it outside of the component, right above your `MyApp` component.
5353
54-
```JavaScript / JSX
54+
```TypeScript / TSX
5555
const dataset = [
5656
{
5757
month: "January",
@@ -86,7 +86,7 @@ UI5 Web Components for React also comes with a chart library. In this tutorial,
8686
8787
3. Now add the `dataset` to your `LineChart` and configure the `dimensions` and `measures` props.
8888
89-
```JavaScript / JSX
89+
```TypeScript / TSX
9090
<LineChart
9191
dimensions={[{ accessor: "month" }]}
9292
measures={[{ accessor: "data", label: "Stock Price" }]}
@@ -102,7 +102,7 @@ UI5 Web Components for React also comes with a chart library. In this tutorial,
102102
103103
We want the same data just with a different representation, therefore you can use the same props as you did with the `LineChart`.
104104
105-
```JavaScript / JSX
105+
```TypeScript / TSX
106106
<BarChart
107107
dimensions={[{ accessor: "month" }]}
108108
measures={[{ accessor: "data", label: "Stock Price" }]}
@@ -112,9 +112,9 @@ UI5 Web Components for React also comes with a chart library. In this tutorial,
112112
113113
Two charts are rendered now with equal datasets but different representation.
114114
115-
Your `MyApp.jsx` component should look like this:
115+
Your `MyApp.tsx` component should look like this:
116116
117-
```JavaScript / JSX
117+
```TypeScript / TSX
118118
import React from "react";
119119
import { Card, CardHeader, Text } from "@ui5/webcomponents-react";
120120
import { spacing } from "@ui5/webcomponents-react-base";
@@ -192,20 +192,20 @@ export function MyApp() {
192192
193193
Two charts in one `Card` is a bit too much, don't you think? It would be nicer if the charts could be toggled by clicking on the header. Let's implement that!
194194
195-
1. First add a state. It should control, which chart is going to be rendered. Use the [State Hook logic](https://reactjs.org/docs/hooks-state.html) to implement the state and set `"lineChart"` as default value. Don't forget to import `useState` from React, otherwise you will get an error.
196-
- Import the `useState` function in the header of the `MyApp.jsx` file (replace the current import of React).
197-
```JavaScript / JSX
198-
import React, { useState } from "react";
195+
1. First add a state. It should control, which chart is going to be rendered. Use the [State Hook logic](https://react.dev/reference/react/useState) to implement the state and set `"lineChart"` as default value. Don't forget to import `useState` from React, otherwise you will get an error.
196+
- Import the `useState` function in the header of the `MyApp.tsx` file.
197+
```TypeScript / TSX
198+
import { useState } from "react";
199199
```
200200
- Use the `useState` function in the right after you start to define the `MyApp` function (before the click handler).
201-
```JavaScript / JSX
201+
```TypeScript / TSX
202202
const [toggleCharts, setToggleCharts] = useState("lineChart");
203203
```
204204
205205
2. By clicking on the `CardHeader` the state should be set corresponding to the chart which should be displayed.
206206
207207
Rewrite your `onClick` function so it will handle this logic.
208-
```JavaScript / JSX
208+
```TypeScript / TSX
209209
const handleHeaderClick = () => {
210210
if (toggleCharts === "lineChart") {
211211
setToggleCharts("barChart");
@@ -215,7 +215,7 @@ Two charts in one `Card` is a bit too much, don't you think? It would be nicer i
215215
};
216216
```
217217
3. To only render the current chart, add the following lines to the render of the component:
218-
```JavaScript / JSX
218+
```TypeScript / TSX
219219
<Card
220220
header={
221221
<CardHeader
@@ -250,13 +250,13 @@ Two charts in one `Card` is a bit too much, don't you think? It would be nicer i
250250
4. You can further improve your `CardHeader` component by using the `avatar` `prop` and adding an `Icon` to it.
251251
252252
Add the following import to your component:
253-
```JavaScript / JSX
253+
```TypeScript / TSX
254254
import { Card, CardHeader, Text, Icon } from "@ui5/webcomponents-react";
255255
```
256256
257257
Icons can be imported altogether (`import '@ui5/webcomponents-icons/dist/AllIcons.js';`), but to reduce bundle size and for better maintainability, it's recommended importing each icon on its own:
258258
259-
```JavaScript / JSX
259+
```TypeScript / TSX
260260
import lineChartIcon from '@ui5/webcomponents-icons/dist/line-chart.js';
261261
import barChartIcon from '@ui5/webcomponents-icons/dist/horizontal-bar-chart.js';
262262
```
@@ -265,15 +265,15 @@ Two charts in one `Card` is a bit too much, don't you think? It would be nicer i
265265
266266
Add the `avatar` prop to the `CardHeader`, which receives an `Icon` as value:
267267
268-
```JavaScript / JSX
268+
```TypeScript / TSX
269269
<CardHeader
270270
...
271271
avatar={<Icon name={lineChartIcon} />}
272272
/>
273273
```
274274
275275
Then, change the `name` prop of the `Icon` to the following:
276-
```JavaScript / JSX
276+
```TypeScript / TSX
277277
<CardHeader
278278
avatar={ <Icon name={ toggleCharts === "lineChart" ? lineChartIcon : barChartIcon } /> }
279279
...
@@ -287,8 +287,8 @@ Two charts in one `Card` is a bit too much, don't you think? It would be nicer i
287287
288288
289289
If something went wrong you can compare your component to this code snippet:
290-
```JavaScript / JSX
291-
import React, { useState } from "react";
290+
```TypeScript / TSX
291+
import { useState } from "react";
292292
import { Card, CardHeader, Text, Icon } from "@ui5/webcomponents-react";
293293
import { spacing } from "@ui5/webcomponents-react-base";
294294
import { BarChart, LineChart } from "@ui5/webcomponents-react-charts";
@@ -384,13 +384,13 @@ One of the main advantages of React is how UI updates are handled. React will on
384384
385385
1. In order to demonstrate this behavior, add a new `state` (right after the definition of the previous state).
386386
387-
```JavaScript / JSX
387+
```TypeScript / TSX
388388
const [loading, setLoading] = useState(false);
389389
```
390390
391391
2. Then edit your `handleHeaderClick` function like this:
392392
393-
```JavaScript / JSX
393+
```TypeScript / TSX
394394
const handleHeaderClick = () => {
395395
if (toggleCharts === "lineChart") {
396396
setLoading(true);
@@ -410,7 +410,7 @@ One of the main advantages of React is how UI updates are handled. React will on
410410
411411
3. Add `loading` to both of your charts.
412412
413-
```JavaScript / JSX
413+
```TypeScript / TSX
414414
<LineChart
415415
dimensions={[{ accessor: "month" }]}
416416
measures={[{ accessor: "data", label: "Stock Price" }]}
@@ -419,7 +419,7 @@ One of the main advantages of React is how UI updates are handled. React will on
419419
/>
420420
```
421421
422-
```JavaScript / JSX
422+
```TypeScript / TSX
423423
<BarChart
424424
dimensions={[{ accessor: "month" }]}
425425
measures={[{ accessor: "data", label: "Stock Price" }]}
@@ -442,7 +442,7 @@ To make your `Card` look cleaner and to give the user the information that the h
442442
443443
The content text is not really informative. Let's change that and display the type of the chart. Add the following constants to your component (after the event handler):
444444
445-
```JavaScript / JSX
445+
```TypeScript / TSX
446446
const contentTitle = toggleCharts === 'lineChart' ? 'Line Chart' : 'Bar Chart';
447447
const switchToChart = toggleCharts === 'lineChart' ? 'Bar Chart' : 'Line Chart';
448448
```
@@ -452,7 +452,7 @@ To make your `Card` look cleaner and to give the user the information that the h
452452
First change the value of `titleText` to something that explains the content of the `Card` (e.g., `"Stock Price"`).
453453
Then add a `subtitleText` prop. Here you can give the users the information that they can switch between charts by clicking the header.
454454
455-
```JavaScript / JSX
455+
```TypeScript / TSX
456456
<Card
457457
header={
458458
<CardHeader
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)