3.0.8 • Published 4 days ago

@catena-x/portal-shared-components v3.0.8

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 days ago

Catena-X Portal Shared UI Components

Contains the Shared UI Components that are used to build the Portal Frontend and other applications in the Catena-X ecosystem.

User documentation

To use components in your own project follow this guide. First create a new react app and add dependencies for the library and Material UI. We are using yarn and TypeScript, if you prefer a different setup like npm/npx or JavaScript there are other templates available.

yarn create vite sample-shared-components --template react-ts
cd sample-shared-components
yarn add @catena-x/portal-shared-components @mui/icons-material @mui/material

Then start the development server and open the browser

yarn dev
# press o + enter

Check the default Vite React App in your browser which shows a button counting the number of times it has been clicked. Now let's modify this App so it's using the Shared Components instead of default HTML elements.

Edit src/main.tsx to import and wrap the App with the Catena-X SharedThemeProvider context.

+ import { SharedThemeProvider } from '@catena-x/portal-shared-components'

ReactDOM.createRoot(document.getElementById('root')!).render(
  <React.StrictMode>
+   <SharedThemeProvider>
      <App />
+   </SharedThemeProvider>
  </React.StrictMode>,
)

Open src/App.tsx to import the Button component and replace the default button with it.

+ import { Button } from '@catena-x/portal-shared-components'
...
-   <button ...>
+   <Button ...>
...
-   </button>
+   </Button>

Then check in your browser how the appearance of the button has changed from a dark more rectangle shaped to a larger blue more rounded one. However the behavior of the button hasn't changed.

Now let's have a look at a more complex example. In a first step we remove the stylings because the components are coming with Catena-X UI styling presets.

Remove the css import from src/main.tsx

+ import './index.css'

Add two more libraries

yarn add amount-to-words @javascript-packages/roman-numerals

Then open src/App.tsx again and overwrite the content with this example.

import { useState } from 'react'
import { Button, Cards, ViewSelector } from '@catena-x/portal-shared-components'
import { numberToWords } from 'amount-to-words'
import { toRoman } from '@javascript-packages/roman-numerals'

const isPrime = (num: number) => {
    for (let i = 2, s = Math.sqrt(num); i <= s; i++)
        if (num % i === 0)
            return false
    return num > 1
}

enum ViewType {
    ALL = 'ALL',
    ODD = 'ODD',
    EVEN = 'EVEN',
    PRIME = 'PRIME',
}

const viewFilter: Record<ViewType, (n: number) => boolean> = {
    ALL: () => true,
    ODD: (n) => n % 2 === 1,
    EVEN: (n) => n % 2 === 0,
    PRIME: isPrime,
}

const svgtext = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" style="background-color:green"><style>text{font:36px bold;stroke-linejoin:round;stroke:#ffa600;fill:#b3cb2d;text-anchor:middle;dominant-baseline:middle;stroke-width:4px;paint-order:stroke;}</style><text x="32" y="36">N</text></svg>'

const generateImage = (n: number) => `data:image/svg+xml,${encodeURIComponent(svgtext.replace('N', n.toString()))}`

const generateCard = (n: number) => ({
    title: numberToWords(n),
    subtitle: n === 0 ? '0' : toRoman(n),
    subscriptionStatus: isPrime(n) ? 'Prime' : undefined,
    description: 'This is a description of the card',
    image: {
        src: generateImage(n),
    }
})

const cardsArgs = {
    variant: 'compact',
    expandOnHover: true,
    imageSize: 'medium',
    imageShape: 'round',
    buttonText: 'View',
}

function App() {
    const [count, setCount] = useState<number>(1)
    const [view, setView] = useState<ViewType>(ViewType.ALL)

    return (
        <>
            <Button onClick={() => { setCount(() => count + 1) }}> count is {count} </Button>
            <ViewSelector views={
                Object.keys(ViewType)
                    .map(
                        (buttonText) => ({
                            buttonText,
                            buttonValue: buttonText,
                            onButtonClick: (e: React.MouseEvent) => { setView(e.target.value as ViewType) },
                        })
                    )
            }
                activeView={view}
            />
            <Cards {...cardsArgs} items={
                new Array(count)
                    .fill(0)
                    .map((_, i) => i)
                    .filter(viewFilter[view])
                    .map(generateCard)
            } />
        </>
    )
}

export default App

This example shows several components working together. Every button click adds a new card for that number and you can filter the cards by various criteria.

Developer documentation

Steps to run local storybook

yarn
yarn start

License

Distributed under the Apache 2.0 License. See LICENSE for more information.

3.0.8

4 days ago

3.0.7

11 days ago

3.0.6

11 days ago

3.0.5

17 days ago

3.0.4

30 days ago

3.0.3

30 days ago

3.0.2

1 month ago

3.0.1

1 month ago

2.1.45

1 month ago

3.0.0

1 month ago

2.1.44

1 month ago

2.1.42

2 months ago

2.1.41

2 months ago

2.1.40

2 months ago

2.1.38

2 months ago

2.1.39

2 months ago

2.1.37

2 months ago

2.1.36

2 months ago

2.1.35

2 months ago

2.1.34

2 months ago

2.1.33

2 months ago

2.1.32

2 months ago

2.1.31

3 months ago

2.1.28

3 months ago

2.1.29

3 months ago

2.1.30

3 months ago

2.1.27

3 months ago

2.1.26

3 months ago

2.1.25

3 months ago

2.1.24

3 months ago

2.1.23

3 months ago

2.1.22

3 months ago

2.1.21

4 months ago

2.1.20

4 months ago

2.1.18

4 months ago

2.1.19

4 months ago

2.1.16

4 months ago

2.1.17

4 months ago

2.1.15

4 months ago

2.1.12

4 months ago

2.0.28

8 months ago

2.0.29

8 months ago

2.0.5

11 months ago

2.0.33

8 months ago

2.0.7

10 months ago

2.0.34

8 months ago

2.0.6

11 months ago

2.0.31

8 months ago

2.0.9

10 months ago

2.0.32

8 months ago

2.0.8

10 months ago

2.0.30

8 months ago

2.1.9

7 months ago

2.1.10

6 months ago

2.1.11

6 months ago

2.1.2

8 months ago

2.0.15

9 months ago

2.1.1

8 months ago

2.0.16

9 months ago

2.1.4

7 months ago

2.0.13

10 months ago

2.1.3

7 months ago

2.0.14

9 months ago

2.1.6

7 months ago

2.0.11

10 months ago

2.1.5

7 months ago

2.0.12

10 months ago

2.1.8

7 months ago

2.1.7

7 months ago

2.0.10

10 months ago

2.1.0

8 months ago

2.0.19

9 months ago

2.0.17

9 months ago

2.0.18

9 months ago

2.0.26

8 months ago

2.0.27

8 months ago

2.0.24

9 months ago

2.0.25

8 months ago

2.0.22

9 months ago

2.0.23

9 months ago

2.0.20

9 months ago

2.0.21

9 months ago

2.0.3

11 months ago

2.0.4

11 months ago

2.0.2

11 months ago

2.0.1

11 months ago

2.0.0

11 months ago