Getting Started with the KendoReact ScrollView
This guide provides the information you need to start using the KendoReact ScrollView — it includes instructions about the available installation approaches, the required dependencies, the code for running the project, and links to additional resources.
Start Free TrialAfter the completion of this guide, you will be able to achieve an end result as demonstrated in the following example.
Setting Up Your React Project
Before you install the KendoReact ScrollView, make sure that you have a running React project. The easiest way to set up a React project is to use the Create React App approach that is described in the Get Started with KendoReact article.
Installing the ScrollView Package
All KendoReact packages are distributed through npm and offer a similar installation experience. To use the ScrollView component, start with the installation of the ScrollView npm package and its dependencies. Use Node.js v5.0.0 or later.
npm install --save @progress/kendo-react-scrollview @progress/kendo-react-intl @progress/kendo-licensing @progress/kendo-svg-icons
Importing the Component
After installing the package, import the ScrollView component in the React App. In the src/App.js
file of your React project, import the ScrollView
component from the ScrollView package.
// ES2015 module syntax
import { ScrollView } from "@progress/kendo-react-scrollview";
// CommonJS format
const { ScrollView } = require('@progress/kendo-react-scrollview');
Using the Component
- Map the array of objects by adding the following code in the
src/App.js
file.
const items = [
{ position: 1, url: 'https://demos.telerik.com/kendo-ui/content/shared/images/photos/1.jpg' },
{ position: 2, url: 'https://demos.telerik.com/kendo-ui/content/shared/images/photos/2.jpg' },
{ position: 3, url: 'https://demos.telerik.com/kendo-ui/content/shared/images/photos/3.jpg' },
{ position: 4, url: 'https://demos.telerik.com/kendo-ui/content/shared/images/photos/4.jpg' }
];
- Add the component's markup to the
src/App.js
file in your project.
import 'style.css';
const App = () => {
return (
<div>
<ScrollView style={{ width: 512, height: 384 }}>
{items.map((item, index) => {
return (
<div className="image-with-text" key={index}>
<p>
Showing image {item.position} of {items.length}.
</p>
<img
src={item.url}
alt={'KendoReact ScrollView Photo'}
style={{ width: 512, height: 384 }}
draggable={false}
/>
</div>
);
})}
</ScrollView>
</div>
);
};
export default App;
- Add the component's styles to the
src/style.css
file in your project.
/* center the ScrollView horizontally */
/* k-scrollview is the default component class */
.k-scrollview {
margin: 0 auto;
}
/* enable absolute positioning inside the ScrollView template */
.image-with-text {
position: relative;
}
/* style the overlay text inside the ScrollView */
.image-with-text > p {
position: absolute;
top: 1rem;
left: 1.6rem;
color: rgba(255, 255, 255, 0.8);
margin: 0;
font-style: italic;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}
-
To style the ScrollView, install and import the Default theme, which is one of the three beautiful themes for KendoReact.
2.1. Install the Default theme package.
shnpm install --save @progress/kendo-theme-default
2.2. Import the CSS file from the package in
src/App.js
. Add this import before your existingApp.css
import.jsximport '@progress/kendo-theme-default/dist/all.css';
-
Build and run the application by typing the following command in the root folder of your project:
shnpm start
-
Navigate to http://localhost:3000 to see the KendoReact ScrollView component on the page.
Activating Your License Key
Using any of the UI components in the KendoReact library requires either a commercial license key or an active trial license key.
Follow the instructions on the KendoReact My License page to activate your trial or commercial license. You can skip this step if your application already contains a KendoReact license file.
Dependencies
The ScrollView package requires you to install the following peer dependencies in your application:
Package Name | Description |
---|---|
react 16.8.2* | Contains the functionality necessary to define React components. |
react-dom | Contains the React renderer for the web. |
@progress/kendo-licensing | Contains the internal infrastructure related to licensing. |
@progress/kendo-react-intl | Contains the KendoReact Internationalization package that applies the desired cultures by providing services and pipes for the parsing and formatting of dates and numbers. |
@progress/kendo-svg-icons | Contains the KendoReact SVG icons. |