Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: react wrappers #1527

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');

Loading