Skip to content

Commit

Permalink
feat: react wrapper components
Browse files Browse the repository at this point in the history
  • Loading branch information
bennypowers committed Apr 18, 2024
1 parent fc63b77 commit b4cee66
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .changeset/spicy-cups-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
"@rhds/elements": minor
---
⚛️ Added React wrapper components

You can now more easily integrate RHDS elements into your React apps by importing our wrapper components

First, make sure that you list `@lit/react` as a dependency in your project

```sh
npm install --save @lit/react
```

Then import the element components you need and treat them like any other react component

```js
import { Tabs } from '@rhds/elements/react/rh-tabs/rh-tabs.js';
import { Tab } from '@rhds/elements/react/rh-tabs/rh-tab.js';
import { TabPanel } from '@rhds/elements/react/rh-tabs/rh-tab-panel.js';

import { useState } from 'react';

const tabs = [
{ heading: 'Hello Red Hat', content: 'Let\'s break down silos' },
{ heading: 'Web components', content: 'They work everywhere' }
];

function App() {
const [index, setExpanded] = useState(-1);
return (
<span>expanded {expanded}</span>
<Tabs>{tabs.map(({ heading, content }, i) => (
<Tab slot="tab" onExpand={() => setExpanded(i)}>{heading}</Tab>
<TabPanel>{content}</TabPanel>))}
</Tabs>
);
}
```
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ docs/assets/playgrounds/
# Build artifacts
elements/*/*.js
elements/*/test/*.js
react
lib/**/*.js
!elements/**/demo/*.css
*.map
Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default tseslint.config(

'**/*.d.ts',
'**/*.(spec|e2e).js',
'react',
'elements/**/*.js',
'lib/**/*.js',

Expand Down
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"exports": {
".": "./rhds.min.js",
"./lib/*": "./lib/*",
"./react/*": "./react/elements/*",
"./*": "./elements/*"
},
"contributors": [
Expand Down Expand Up @@ -109,6 +110,7 @@
"dependencies": [
"patch",
"analyze",
"react-wrappers",
"compile",
"bundle",
"docs"
Expand All @@ -135,6 +137,19 @@
"!elements/*/{demo,test}/**/*.js"
]
},
"react-wrappers": {
"command": "npx tsx scripts/generate-react-wrappers.ts",
"dependencies": [
"analyze"
],
"files": [
"custom-elements.json",
"scripts/generate-react-wrappers.ts"
],
"output": [
"react/**/*"
]
},
"bundle": {
"command": "node scripts/bundle.js"
},
Expand Down
11 changes: 11 additions & 0 deletions scripts/generate-react-wrappers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { generateReactWrappers } from '@patternfly/pfe-tools/react/generate-wrappers.js';

const inURL = new URL('../custom-elements.json', import.meta.url);
const outURL = new URL('../react/', import.meta.url);

await generateReactWrappers(inURL,
outURL,
'@rhds/elements',
'rh',
'Rh');

0 comments on commit b4cee66

Please sign in to comment.