Giter VIP home page Giter VIP logo

ui5-webcomponents-sample-react's Introduction

UI5 logo CI REUSE status

UI5 Web Components React Sample Application

React sample application to demonstrate the usage of the UI5 Web Components. It shows how to bind properties, to subscribe to events, using nested components and the bootstrapped React build.

This project was bootstrapped with Create React App.

Prerequisites

  • Node.js (version 8.5 or higher โš ๏ธ)
  • Yarn (Optional usage of yarn)

Getting started

  1. Clone this repository using the GitHub Command line tool and navigate into the downloaded directory.

    git clone https://github.com/SAP-samples/ui5-webcomponents-sample-react.git
    cd ui5-webcomponents-sample-react
  2. Install all dependencies

    npm install
  3. Start a local server and run the application. (The running application can be found here: http://localhost:3000)

    npm start

Noteworthy

Consume UI5 Web Components

Import the desired component(s) in your app to define the UI5 Web Component.

For example, to use ui5-button you need to import it:

import "@ui5/webcomponents/dist/Button"; // loads ui5-button

Then, you can use the custom element in an HTML page:

<ui5-button>Hello world!</ui5-button>

Browser support

Currently Chrome, Safari, Firefox and Edge (Chromium-based) support Web Components natively.

Configure React Build

When UI5 Web Components are used they include all of their translation files and CLDR data files in the application bundle. In order to decrease the bundle size of the application a custom Webpack configuration should be provided. (This configuration is already done for this project, so you will NOT be able to run npm run eject, because it is one time operation, which can NOT be reverted.)

  1. Eject the react build with npm run eject
  2. Open config/webpack.config.js file and add the following lines before the last loader:
{
  test: [/cldr\/.*\.json$/, /i18n\/.*\.json$/],
  loader: 'file-loader',
  options: {
    name: 'static/media/[name].[hash:8].[ext]',
  },
  type: 'javascript/auto'
},
// "file" loader makes sure those assets get served by WebpackDevServer.
// When you `import` an asset, you get its (virtual) filename.
// In production, they would get copied to the `build` folder.
// This loader doesn't use a "test" so it will catch all modules
// that fall through the other loaders.

Where is the npm package?

Limitations

No limitations known.

Known Issues

No major bugs known.

Support

We welcome all comments, suggestions, questions, and bug reports. Please follow our Support Guidelines on how to report an issue, or chat with us in the #webcomponents channel of the OpenUI5 Community Slack.

Contribute to UI5 Web Components

Please check our Contribution Guidelines.

ui5-webcomponents-sample-react's People

Contributors

adrian-bobev avatar anselm94 avatar btbernard avatar dependabot[bot] avatar fifoosid avatar hinzzx avatar ilhan007 avatar iobert avatar mapto0 avatar mmoudy49 avatar petermuessig avatar vladitasev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ui5-webcomponents-sample-react's Issues

Internationalization/i18n support

Is there a easy way internationalize SAP UI5 webcomponents for react accordingly with SAP standards? Perhaps using web-components-core?

Thank you.

Sample UI5WC + TypeScript + Tests

Do you have any working examples of a TypeScript React App, using UI5 Web Components, with tests using Jest?

I've tried creating an app with create-react-app --template typescript, then adding UI5 WC, but as soon as I started importing the components in my files, I had several problems when running the pre-configured tests.

Example:

App.tsx

import React from 'react';
import { Button } from "@ui5/webcomponents-react/lib/Button";
import { Title } from "@ui5/webcomponents-react/lib/Title";

function App() {
  return (
    <div className="App">
      <h1>HTML Hello World</h1>
      <Title>UI5 Hello World</Title>
      <Button>UI5 Button</Button>
    </div>
  );
}

export default App;

App.test.tsx

import React from 'react';
import { render } from '@testing-library/react';
import App from './App';

test('renders learn react link', () => {
  const { getByText } = render(<App />);
  const linkElement = getByText(/learn react/i);
  expect(linkElement).toBeInTheDocument();
});

(I know the assertion would fail, but I couldn't even get to this point)

When running yarn test:

image

Does not work with Edge

HI,

on my Windows 10 machine the sample app does not work with Microsoft Edge. It seems that none CSS are applied as the page does only contain texts.

WebComponentsEdge

There are no errors in the log.

BR,
Juri

digital envelope routines::unsupported

Running npm start result in the following error:

Starting the development server...

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:68:19)
    at Object.createHash (node:crypto:138:10)
    at module.exports (/Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/webpack/lib/util/createHash.js:90:53)
    at NormalModule._initBuildHash (/Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/webpack/lib/NormalModule.js:386:16)
    at handleParseError (/Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/webpack/lib/NormalModule.js:434:10)
    at /Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/webpack/lib/NormalModule.js:466:5
    at /Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/webpack/lib/NormalModule.js:327:12
    at /Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/loader-runner/lib/LoaderRunner.js:373:3
    at iterateNormalLoaders (/Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
    at iterateNormalLoaders (/Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
    at /Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/loader-runner/lib/LoaderRunner.js:236:3
    at runSyncOrAsync (/Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/loader-runner/lib/LoaderRunner.js:130:11)
    at iterateNormalLoaders (/Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/loader-runner/lib/LoaderRunner.js:232:2)
    at Array.<anonymous> (/Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
    at Storage.finished (/Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:43:16)
    at /Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:79:9
/Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/scripts/start.js:11
  throw err;
  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:68:19)
    at Object.createHash (node:crypto:138:10)
    at module.exports (/Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/webpack/lib/util/createHash.js:90:53)
    at NormalModule._initBuildHash (/Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/webpack/lib/NormalModule.js:386:16)
    at /Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/webpack/lib/NormalModule.js:418:10
    at /Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/webpack/lib/NormalModule.js:293:13
    at /Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/loader-runner/lib/LoaderRunner.js:367:11
    at /Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/loader-runner/lib/LoaderRunner.js:233:18
    at context.callback (/Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
    at /Users/perage/dev/POC/react1/ui5-webcomponents-sample-react/node_modules/babel-loader/lib/index.js:51:103 {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

use react wrapper

this is the "official" react example, i.e. i got here through the link on the front page of the website. the usecase of webcomponents for me is to use typescript (+ react) while retaining the familiar ui5 look for our customers. i started off writing types for the jsx elements by basically copying the interfaces from the playground, until i realized that there already was a react wrapper. maybe at least reference that wrapper so other developers don't start writing their own type definitions before coming to the same realization.

Set up tests after eject of the standard CRA

Hello Team,

I'm facing the following problem:
Steps to reproduce:

  1. npx create-react-app </app_name>
  2. npm i -S @ui5/webcomponents-react
  3. Follow the instructions for the tests Set up Tests
  4. npm i -D enzyme enzyme-adapter-react-16
  5. setupTest.js looks like this:
import '@testing-library/jest-dom/extend-expect';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

Enzyme.configure({ adapter: new Adapter() });
  1. App.js looks like this:
import React from 'react';

import '@ui5/webcomponents/dist/json-imports/i18n';

import '@ui5/webcomponents/dist/json-imports/Themes';
import '@ui5/webcomponents-fiori/dist/json-imports/Themes';

import './App.css';
import { Button, ShellBar, ThemeProvider } from '@ui5/webcomponents-react';

function App() {
  return (
    <div>
      <ThemeProvider withToastContainer>
        <ShellBar />
        <Button>Click Me!</Button>
      </ThemeProvider>
    </div>
  );
}

export default App;
  1. The test looks like this
import React from 'react';
import App from './App';
import { shallow } from 'enzyme'

test('renders learn react link', () => {
  let shallow1 = shallow(<App />);
});

So far so good the test starts with 100 warnings in the console about the i18n (by the way your app is also starting with them ui5-webcomponents-sample-react ) but the test is loaded and so on.

so you are a suggesting to eject from the standard CRA and to continue on our own and to add in the config/webpack.config.js the following in order to solve the warnings:

 {
              test: [/cldr\/.*\.json$/, /i18n\/.*\.json$/, /assets\/.*\.json$/],
              loader: 'file-loader',
              options: {
                name: 'static/media/[name].[hash:8].[ext]',
              },
              type: 'javascript/auto',
            }

so far so good the warnings are gone from the console and all the assets are now loaded fine.
But the test is not working any mode I am getting the following error:

node_modules/@ui5/webcomponents/dist/json-imports/i18n.js:1
({"Object.":function(module,exports,require,__dirname,__filename,global,jest){import { registerI18nBundle } from "@ui5/webcomponents-base/dist/asset-registries/i18n.js";

Which was solved before with Set up Tests

So please advice what I'm are doing wrong or what I'm missing in the whole configuration.

Thanks & Regards,
Ivan

Is useEffect recommended over onClick events?

Looking through the samples, all click events are being treated using the useEffect hook, adding listeners to the click event:

useEffect(() => {
    saveBtn.current.addEventListener("click", handleSave);
    return () => {
      saveBtn.current.removeEventListener("click", handleSave);
    }
  }, [handleSave]);

I'm new to React, so I'm not really sure about what is the advantage of this approach over using the onClick event already available as default from the components, like this:

<ui5-button design="Emphasized" onClick={handleSave}>Save</ui5-button>

What is the recommendation? useEffect should always be preferred over onClick?

Client-Side navigation not working

I have deployed the react ui5 application in SAP BTP. When I introduce routing using react-router-dom it is saying File Not found

approuter->xs-app.json
{ "welcomeFile": "/salesorderapp" }

public->xs-app.json
{ "welcomeFile": "/index.html", "authenticationMethod": "route", "logout": { "logoutEndpoint": "/do/logout" }, "routes": [ { "source": "^(.*)$", "target": "$1", "service": "html5-apps-repo-rt", "authenticationType": "xsuaa" } ] }

App id is also added to manifest.json
The routing logic
<Routes> <Route path='/' element={<div>Main</div>}/> <Route path='detail' element={<div>Detail</div>}/> </Routes>

Initially the page is loading Main div . But when I hit the detail route, it is saying File not found

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.