This repo contains React Virtual assistant implementation.
To play with virtual-assistant in your project, run
npm install @patternfly/virtual-assistant --save
Make sure to add the CSS imports as the last import in your index file. The extension is intended to override certain PatternFly component styles. However, if it's not the last import, you may not see these.
import '@patternfly/virtual-assistant/dist/css/main.css';
src/
matching its name (for example src/MyComponent
).tsx
file named after the component (for example src/MyComponent/MyComponent.tsx
)index.ts
which will export the component as a default and then all necessary interfacesimport * as React from 'react';
import { Text } from '@patternfly/react-core';
// do not forget to export your component's interface
// always place the component's interface above the component itself in the code
export interface MyComponentProps {
text: String;
// do not use the named export of your component, just a default one
const MyComponent: React.FunctionComponent<MyComponentProps> = () => {
return (
<Text>
This is my new component
</Text>
);
};
export default MyComponent;
export { default } from './MyComponent';
export * from './MyComponent';
src
|- MyComponent
|- index.ts
|- MyComponent.tsx
variant
, onClick
, position
, etc.)/packages/module/patternfly-docs/content/extensions/virtual-assistant/examples/MyComponent/MyComponent.md
) with examples of all possible use cases (packages/module/patternfly-docs/content/extensions/virtual-assistant/examples/MyComponent/MyComponent[...]Example.tsx
)// when possible, extend available PatternFly types
export interface MyComponentProps extends ButtonProps {
customLabel: Boolean
};
export const MyComponent: React.FunctionComponent<MyComponentProps> = ({ customLabel, ...props }) => ( ... );
---
section: extensions
subsection: Virtual assistant
id: MyComponent
propComponents: ['MyComponent']
---
import MyComponent from "@patternfly/virtual-assistant/dist/dynamic/MyComponent";
## Component usage
MyComponent has been created to demo contributing to this repository.
### MyComponent component example label
```js file="./MyComponentExample.tsx"```
MyComponentExample.tsx
)import React from 'react';
const MyComponentExample: React.FunctionComponent = () => (
<MyComponent customLabel="My label">
);
export default BatteryLowExample;
When adding a component for which it is advantageous to divide it into several sub-components make sure:
src/
folderThe aim is to enable the user of our "complex" component to use either complete or take advantage of its sub-components and manage their composition independently.
When adding/making changes to a component, always make sure your code is tested:
[ComponentName].test.tsx
file to your component's directorycypress/component/[ComponentName].cy.tsx
file and E2E tests to cypress/e2e/[ComponentName].spec.cy.ts
ouiaId
to component props definition with a default value of the component name (for subcomponents, let's use ComponentName-element-specification
naming convention e.g. ouiaId="VirtualAssistant-send-button"
)actionMenu
, actionMenuDropdown
, actionMenuDropdownToggle
, etc.)pf-v6-u-XXX
classes, use CSS variables in a custom class instead (styles for the utility classes are not bundled with the standard patternfly.css - it would require the consumer to import also addons.css)From root folder:
npm install
npm run build
cd packages/module
npm run docs:build
npm run docs:serve
Open a new terminal tab while serving; make sure you are in package/module folder:
npm run docs:screenshots
These files will not be picked up by git; you'll have to look for them and add them manually.