You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorials/ui5-webcomponents-react-card/ui5-webcomponents-react-card.md
+22-24Lines changed: 22 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -23,23 +23,23 @@ There you can try out the different components and also take a look at the codin
23
23
24
24
---
25
25
26
-
### Add components to MyApp.jsx
26
+
### Add components to MyApp.tsx
27
27
28
28
First you need to import the components you want to use.
29
29
30
30
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.
31
31
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.
33
33
34
-
```JavaScript / JSX
34
+
```TypeScript / TSX
35
35
import { Card } from"@ui5/webcomponents-react";
36
36
```
37
37
38
38
2.So, youimportedthe`Card`component. Nowit's time to use it. Replace the content of your `<div>` with a `<Card>`.
39
39
40
40
Inthe [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`.
41
41
42
-
```JavaScript / JSX
42
+
```TypeScript / TSX
43
43
<div>
44
44
<Card>This is the content area of the Card</Card>
45
45
</div>
@@ -51,7 +51,7 @@ Your webpage should now look like this.
51
51
52
52
Andthefilelikethis:
53
53
54
-
```JavaScript / JSX
54
+
```TypeScript / TSX
55
55
import { Card } from "@ui5/webcomponents-react";
56
56
57
57
export function MyApp() {
@@ -71,13 +71,13 @@ The heading area of the `Card` component is empty, this is because it didn't rec
71
71
72
72
1.Importthe`CardHeader`.
73
73
74
-
```JavaScript / JSX
74
+
```TypeScript / TSX
75
75
import { Card, CardHeader } from "@ui5/webcomponents-react";
@@ -87,15 +87,15 @@ The heading area of the `Card` component is empty, this is because it didn't rec
87
87
88
88
2.Nowthe`Card`hasaheaderarea, butthe`font-family`ofthecontentareadiffersfromthe`Card`header. AllUI5WebComponentsforReactcomponentsusethesamestyling, thisincludes`font-family`, `color`, etc.
89
89
90
-
Add the `Text`import to your `MyApp.jsx` file.
90
+
Addthe`Text`importtoyour`MyApp.tsx`file.
91
91
92
-
```JavaScript / JSX
92
+
```TypeScript / TSX
93
93
import { Card, CardHeader, Text } from "@ui5/webcomponents-react";
94
94
```
95
95
96
96
Andwrapthetextwithinthe`Text`component.
97
97
98
-
```JavaScript / JSX
98
+
```TypeScript / TSX
99
99
<div>
100
100
<Card header={<CardHeader titleText="Card" />}>
101
101
<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
109
109
110
110
### Styleyourcomponent
111
111
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
+
Inthisstep, wewillonlyapply [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.
Copy file name to clipboardExpand all lines: tutorials/ui5-webcomponents-react-charts/ui5-webcomponents-react-charts.md
+27-27Lines changed: 27 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -29,9 +29,9 @@ UI5 Web Components for React also comes with a chart library. In this tutorial,
29
29
npm install @ui5/webcomponents-react-charts
30
30
```
31
31
32
-
2. Then, import `LineChart` and `BarChart` into `MyApp.jsx`.
32
+
2. Then, import `LineChart` and `BarChart` into `MyApp.tsx`.
33
33
34
-
```JavaScript / JSX
34
+
```TypeScript / TSX
35
35
import { BarChart, LineChart } from "@ui5/webcomponents-react-charts";
36
36
```
37
37
@@ -40,7 +40,7 @@ UI5 Web Components for React also comes with a chart library. In this tutorial,
40
40
41
41
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.
42
42
43
-
```JavaScript / JSX
43
+
```TypeScript / TSX
44
44
<Text style={spacing.sapUiContentPadding}>
45
45
This is the content area of the Card
46
46
</Text>
@@ -51,7 +51,7 @@ UI5 Web Components for React also comes with a chart library. In this tutorial,
51
51
52
52
2. Add data to your component, since `data` is static you can define it outside of the component, right above your `MyApp` component.
53
53
54
-
```JavaScript / JSX
54
+
```TypeScript / TSX
55
55
const dataset = [
56
56
{
57
57
month: "January",
@@ -86,7 +86,7 @@ UI5 Web Components for React also comes with a chart library. In this tutorial,
86
86
87
87
3. Now add the `dataset` to your `LineChart` and configure the `dimensions` and `measures` props.
@@ -112,9 +112,9 @@ UI5 Web Components for React also comes with a chart library. In this tutorial,
112
112
113
113
Two charts are rendered now with equal datasets but different representation.
114
114
115
-
Your `MyApp.jsx` component should look like this:
115
+
Your `MyApp.tsx` component should look like this:
116
116
117
-
```JavaScript / JSX
117
+
```TypeScript / TSX
118
118
import React from "react";
119
119
import { Card, CardHeader, Text } from "@ui5/webcomponents-react";
120
120
import { spacing } from "@ui5/webcomponents-react-base";
@@ -192,20 +192,20 @@ export function MyApp() {
192
192
193
193
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!
194
194
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";
199
199
```
200
200
- Use the `useState` function in the right after you start to define the `MyApp` function (before the click handler).
2. By clicking on the `CardHeader` the state should be set corresponding to the chart which should be displayed.
206
206
207
207
Rewrite your `onClick` function so it will handle this logic.
208
-
```JavaScript / JSX
208
+
```TypeScript / TSX
209
209
const handleHeaderClick = () => {
210
210
if (toggleCharts === "lineChart") {
211
211
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
215
215
};
216
216
```
217
217
3. To only render the current chart, add the following lines to the render of the component:
218
-
```JavaScript / JSX
218
+
```TypeScript / TSX
219
219
<Card
220
220
header={
221
221
<CardHeader
@@ -250,13 +250,13 @@ Two charts in one `Card` is a bit too much, don't you think? It would be nicer i
250
250
4. You can further improve your `CardHeader` component by using the `avatar` `prop` and adding an `Icon` to it.
251
251
252
252
Add the following import to your component:
253
-
```JavaScript / JSX
253
+
```TypeScript / TSX
254
254
import { Card, CardHeader, Text, Icon } from "@ui5/webcomponents-react";
255
255
```
256
256
257
257
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:
258
258
259
-
```JavaScript / JSX
259
+
```TypeScript / TSX
260
260
import lineChartIcon from '@ui5/webcomponents-icons/dist/line-chart.js';
261
261
import barChartIcon from '@ui5/webcomponents-icons/dist/horizontal-bar-chart.js';
262
262
```
@@ -265,15 +265,15 @@ Two charts in one `Card` is a bit too much, don't you think? It would be nicer i
265
265
266
266
Add the `avatar` prop to the `CardHeader`, which receives an `Icon` as value:
267
267
268
-
```JavaScript / JSX
268
+
```TypeScript / TSX
269
269
<CardHeader
270
270
...
271
271
avatar={<Icon name={lineChartIcon} />}
272
272
/>
273
273
```
274
274
275
275
Then, change the `name` prop of the `Icon` to the following:
@@ -442,7 +442,7 @@ To make your `Card` look cleaner and to give the user the information that the h
442
442
443
443
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):
0 commit comments