This repo contains a set of opinionated react component groups used to standardize functionality and look and feel across products. The components are based on PatternFly with some additional functionality.
Please see the migration guide
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 { Content } from '@patternfly/react-core';
import { createUseStyles } from 'react-jss';
// 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;
}
const useStyles = createUseStyles({
myText: {
fontFamily: 'monospace',
fontSize: 'var(--pf-v6-global--icon--FontSize--md)',
},
})
// do not use the named export of your component, just a default one
const MyComponent: React.FunctionComponent<MyComponentProps> = () => {
const classes = useStyles();
return (
<Content className={classes.myText}>
This is my new reusable component
</Content>
);
};
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/component-groups/examples/MyComponent/MyComponent.md
) with examples of all possible use cases (packages/module/patternfly-docs/content/extensions/component-groups/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: Component groups
subsection: My component's category
id: MyComponent
propComponents: ['MyComponent']
---
import MyComponent from "@patternfly/react-component-groups/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 MyComponentExample;
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 the component props definition with a default value of the component name (for subcomponents, let's use ComponentName-element-specification
naming convention e.g. ouiaId="WarningModal-confirm-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)npm install
npm run build
npm install
npm run start
to build and start the development servernpm run test
to run the unit testsnpm run cypress:run:cp
to run Cypress component testsnpm run cypress:run:e2e
to run Cypress E2E testsnpm run lint
to run the linternpm run build:docs
followed by npm run serve:docs
, then run npm run test:a11y
in a new terminal window to run our accessibility tests for the components. Once the accessibility tests have finished running you can run npm run serve:a11y
to locally view the generated report.