Skip to content
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ coverage
**/Generated
**/build
css
packages/react-docs/static

# package managers
yarn-error.log
Expand Down
9 changes: 8 additions & 1 deletion packages/react-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
},
"homepage": "https://github.com/patternfly/patternfly-react#readme",
"scripts": {
"build": "yarn build:babel && yarn build:types && node ./scripts/copyStyles.js",
"build": "yarn build:babel && yarn build:umd && yarn build:types && node ./scripts/copyStyles.js",
"build:babel": "concurrently \"yarn build:babel:esm && yarn build:babel:umd\" \"yarn build:babel:cjs\"",
"build:babel:cjs": "babel --source-maps --extensions \".js,.ts,.tsx\" src --out-dir dist/js --presets=@babel/env",
"build:babel:esm": "babel --source-maps --extensions \".js,.ts,.tsx\" src --out-dir dist/esm",
"build:babel:umd": "babel --source-maps --extensions \".js\" dist/esm --out-dir dist/umd --plugins=transform-es2015-modules-umd",
"build:types": "tsc -p tsconfig.gen-dts.json",
"build:umd": "rollup -c && rollup -c --environment IS_PRODUCTION",
"clean": "rimraf dist",
"develop": "yarn build:babel:esm --skip-initial-build --watch --verbose",
"gen:tests": "yo tsx-docgen"
Expand Down Expand Up @@ -67,6 +68,12 @@
"generator-tsx-docgen": "^0.1.0",
"glob": "^7.1.2",
"rimraf": "^2.6.2",
"rollup": "^2.2.0",
"@rollup/plugin-node-resolve": "^7.1.1",
"@rollup/plugin-commonjs": "^11.0.2",
"@rollup/plugin-replace": "^2.3.1",
"rollup-plugin-scss": "^2.1.0",
"rollup-plugin-terser": "^5.3.0",
"typescript": "^3.8.3",
"yo": "^3.1.1"
},
Expand Down
31 changes: 31 additions & 0 deletions packages/react-core/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import scss from 'rollup-plugin-scss';
import replace from '@rollup/plugin-replace';
import { terser } from 'rollup-plugin-terser';

const isProduction = process.env.IS_PRODUCTION;

module.exports = {
input: 'dist/esm/index.js',
output: {
file: `dist/umd/react-core${isProduction ? '.min' : ''}.js`,
format: 'umd',
name: 'PatternFlyReact',
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'prop-types': 'PropTypes'
}
},
external: ['react', 'react-dom', 'prop-types'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't you remove prop-types references in another PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but prop-types are still generated from the typescript-to-proptypes plugin. It seemed good to include these in our UMD bundle because there's no type support when using the PatternflyReact object.

plugins: [
replace({
'process.env.NODE_ENV': `'${isProduction ? 'production' : 'development'}'`
}),
resolve(),
commonjs(),
scss(),
isProduction && terser()
]
};
8 changes: 1 addition & 7 deletions packages/react-core/src/components/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import accessibleStyles from '@patternfly/react-styles/css/utilities/Accessibili
import { AlertIcon } from './AlertIcon';
import { capitalize } from '../../helpers/util';
import { InjectedOuiaProps, withOuiaContext } from '../withOuia';
import { AlertContext } from './AlertContext';

export enum AlertVariant {
success = 'success',
Expand Down Expand Up @@ -35,13 +36,6 @@ export interface AlertProps extends Omit<React.HTMLProps<HTMLDivElement>, 'actio
isLiveRegion?: boolean;
}

interface AlertContext {
title: React.ReactNode;
variantLabel?: string;
}

export const AlertContext = React.createContext<AlertContext>(null);

const Alert: React.FunctionComponent<AlertProps & InjectedOuiaProps> = ({
variant = AlertVariant.info,
isInline = false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { Button, ButtonVariant, ButtonProps } from '../Button';
import TimesIcon from '@patternfly/react-icons/dist/js/icons/times-icon';
import { AlertContext } from '..';
import { AlertContext } from './AlertContext';

interface AlertActionCloseButtonProps extends ButtonProps {
/** Additional classes added to the AlertActionCloseButton */
Expand Down
8 changes: 8 additions & 0 deletions packages/react-core/src/components/Alert/AlertContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as React from 'react';

interface AlertContext {
title: React.ReactNode;
variantLabel?: string;
}

export const AlertContext = React.createContext<AlertContext>(null);
1 change: 1 addition & 0 deletions packages/react-core/src/components/Alert/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './Alert';
export * from './AlertContext';
export * from './AlertActionCloseButton';
export * from './AlertActionLink';
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DropdownWithContext } from '../Dropdown/DropdownWithContext';
import { ApplicationLauncherGroup } from './ApplicationLauncherGroup';
import { ApplicationLauncherSeparator } from './ApplicationLauncherSeparator';
import { ApplicationLauncherItem } from './ApplicationLauncherItem';
import { ApplicationLauncherContext } from './ApplicationLauncherContext';

export interface ApplicationLauncherProps extends React.HTMLProps<HTMLDivElement> {
/** Additional element css classes */
Expand Down Expand Up @@ -57,11 +58,6 @@ export interface ApplicationLauncherProps extends React.HTMLProps<HTMLDivElement
toggleId?: string;
}

export const ApplicationLauncherContext = React.createContext({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onFavorite: (itemId: string, isFavorite: boolean) => {}
});

export class ApplicationLauncher extends React.Component<ApplicationLauncherProps> {
static defaultProps: ApplicationLauncherProps = {
className: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import accessibleStyles from '@patternfly/react-styles/css/utilities/Accessibili
import { ApplicationLauncherIcon } from './ApplicationLauncherIcon';
import { ApplicationLauncherText } from './ApplicationLauncherText';
import ExternalLinkAltIcon from '@patternfly/react-icons/dist/js/icons/external-link-alt-icon';
import { ApplicationLauncherItemContext } from './ApplicationLauncherItem';
import { ApplicationLauncherItemContext } from './ApplicationLauncherItemContext';

export interface ApplicationLauncherContentProps {
/** Main content to be rendered */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as React from 'react';

export const ApplicationLauncherContext = React.createContext({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onFavorite: (itemId: string, isFavorite: boolean) => {}
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/components/AppLauncher/app-launcher';
import { DropdownItem, DropdownItemProps } from '../Dropdown';
import { ApplicationLauncherContent } from './ApplicationLauncherContent';
import { ApplicationLauncherContext } from './ApplicationLauncher';
import { ApplicationLauncherContext } from './ApplicationLauncherContext';
import { ApplicationLauncherItemContext } from './ApplicationLauncherItemContext';
import StarIcon from '@patternfly/react-icons/dist/js/icons/star-icon';

export const ApplicationLauncherItemContext = React.createContext({ isExternal: false, icon: null });
Copy link
Member

@dlabrecq dlabrecq Mar 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't removing an export be a breaking change?

I believe it's ok to add ApplicationLauncherItemContext.ts , but perhaps remove this in v4?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I've reexported it in the index.ts file so this isn't breaking.


export interface ApplicationLauncherItemProps {
/** Icon rendered before the text */
icon?: React.ReactNode;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as React from 'react';

export const ApplicationLauncherItemContext = React.createContext({ isExternal: false, icon: null });
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export * from './ApplicationLauncher';
export * from './ApplicationLauncherContext';
export * from './ApplicationLauncherItem';
export * from './ApplicationLauncherItemContext';
export * from './ApplicationLauncherContent';
export * from './ApplicationLauncherIcon';
export * from './ApplicationLauncherText';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ class CardViewBasic extends React.Component {
isChecked={selectedItems.includes(product.id)}
defaultChecked={this.state.itemsCheckedByDefault}
aria-label="card checkbox example"
id="check-1"
id={`check-${product.id}`}
/>
</CardActions>
</CardHead>
Expand Down
1 change: 1 addition & 0 deletions packages/react-docs/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
resolve: `gatsby-theme-patternfly-org`,
options: {
context: 'react', // For global items that need sideNav
showGdprBanner: false, // GDPR banner
hiddenPages: ['withOuia', 'Training'], // By title
sideNav: {
react: [
Expand Down
30 changes: 30 additions & 0 deletions packages/react-docs/static/like-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

const e = React.createElement;

class LikeButton extends React.Component {
constructor(props) {
super(props);
this.state = { liked: false };
}

render() {
if (this.state.liked) {
return e(PatternFlyReact.Alert, {
title: ' Great success',
children: 'You liked this',
variant: 'success'
});
}

return e(
PatternFlyReact.Button,
{ onClick: () => this.setState({ liked: true }) },
'Like'
);
}
}


const domContainer = document.querySelector('#react-root');
ReactDOM.render(e(LikeButton), domContainer);
98 changes: 98 additions & 0 deletions packages/react-docs/static/umd.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<!DOCTYPE html>
<html lang="en-us">
<head>
<link rel="stylesheet" href="https://unpkg.com/@patternfly/patternfly@2/patternfly.css" crossorigin />
<meta charset="utf-8"/>
</head>
<body>
<h1 class="pf-c-title pf-m-2xl">PatternFly-React UMD Build</h1>
<p>
UMD build allow for you to quickly get started using <a href="">@patternfly/react-core.</a>
If you care about how this is accomplished, it's highly recommended to read&nbsp;
<a href="https://reactjs.org/docs/add-react-to-a-website.html#add-react-in-one-minute">React's getting started with UMD guide</a> before returning here since.
This guide uses React's guide as a base.
</p>
<h2 class="pf-c-title pf-m-2xl">1. Write HTML</h2>
<p>
Create a container to inject React components into.
<pre>
&lt;div id="react-root">Inject in here&lt;/div>
</pre>
</p>
<h2 class="pf-c-title pf-m-2xl">2. Include JS</h2>
<p>
PatternFly React depends on React and PropTypes. Add these to the bottom of the &lt;body> tag on your page:
<pre>
&lt;script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin>&lt;/script>
&lt;script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin>&lt;/script>
&lt;script src="https://unpkg.com/prop-types@15.6/prop-types.js" crossorigin>&lt;/script>
&lt;script src="https://unpkg.com/@patternfly/react-core@3/dist/umd/react-core.umd.js">&lt;/script>
&lt;script src="like-button.js">&lt;/script>
</pre>

@patternfly/react-core exposes a "PatternFlyReact" object for use in your like-button.js. Populate your like-button.js with something like:
<pre>
'use strict';

const e = React.createElement;

class LikeButton extends React.Component {
constructor(props) {
super(props);
this.state = { liked: false };
}

render() {
if (this.state.liked) {
return e(PatternFlyReact.Alert, {
title: ' Great success',
children: 'You liked this',
variant: 'success'
});
}

return e(
PatternFlyReact.Button,
{ onClick: () => this.setState({ liked: true }) },
'Like'
);
}
}


const domContainer = document.querySelector('#react-root');
ReactDOM.render(e(LikeButton), domContainer);
</pre>
</p>
<h2 class="pf-c-title pf-m-2xl">3. (Optional) Include styles</h2>
<p>
You have to include <b>ALL</b> our PatternFly styles. There's two ways to do this:
<pre>
&lt;link rel="stylesheet" href="https://unpkg.com/@patternfly/patternfly@2/patternfly.css" crossorigin />
</pre>
OR
<pre>
&lt;link rel="stylesheet" href="https://unpkg.com/@patternfly/react-core@3/dist/styles/base.css" crossorigin />
&lt;link rel="stylesheet" href="https://unpkg.com/@patternfly/react-core@3/dist/react-core.umd.css" crossorigin />
</pre>
</p>
<h2 class="pf-c-title pf-m-2xl">4. Don't do this in production</h2>
<p>
This implementation is very bloated.
ALL of React, ReactDOM, PropTypes (which you don't need in production...), and PatternFly (including CSS and fonts) are included which takes 912KB <i>after</i> being gzipped.
Even when minified, they take 520Kb <i>after</i> being gzipped.
Also, you probably want to be able to use JSX.
To enable using JSX, treeshaking, and other modern JS tools PatternFly recommendeds consumption using <a href="https://github.com/patternfly/patternfly-react-seed">Webpack.</a>
It's as simple as cloning <a href="https://github.com/patternfly/patternfly-react-seed">our seed repo</a> and running 2 commands!
</p>
<p>
This page serves as an example of how to do this. Checkout the like button below!
</p>
<div id="react-root">Inject like button here</div>
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/prop-types@15.6/prop-types.js" crossorigin></script>
<script src="https://unpkg.com/@patternfly/react-core@3/dist/umd/react-core.umd.js"></script>
<script src="like-button.js"></script>
</body>
</html>
Loading