-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Table): support inline editing in PF4 (#1227)
- Loading branch information
Showing
76 changed files
with
13,815 additions
and
333 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/patternfly-4/react-inline-edit-extension/.babelrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"presets": [ | ||
"../.babelrc.js" | ||
], | ||
"env": { | ||
"production:esm": { | ||
"plugins": [ | ||
[ | ||
"@patternfly/react-styles/babel", | ||
{ | ||
"srcDir": "./src", | ||
"outDir": "./dist/esm", | ||
"useModules": true | ||
} | ||
] | ||
] | ||
}, | ||
"production:cjs": { | ||
"plugins": [ | ||
[ | ||
"@patternfly/react-styles/babel", | ||
{ | ||
"srcDir": "./src", | ||
"outDir": "./dist/js", | ||
"useModules": false | ||
} | ||
] | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# @patternfly/react-inline-edit-extension | ||
|
||
Inline Edit extension provides inline editing support for PatternFly 4 React table. | ||
|
||
This package is currently an extension. Extension components do not undergo the same rigorous design or coding review process as core PatternFly components. If enough members of the community find them useful, we will work to move them into our core PatternFly system by starting the design process for the idea. |
42 changes: 42 additions & 0 deletions
42
packages/patternfly-4/react-inline-edit-extension/build/copyStyles.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* eslint-disable no-case-declarations */ | ||
const { copySync, readFileSync, writeFileSync } = require('fs-extra'); | ||
const { resolve, dirname, join } = require('path'); | ||
const { parse: parseCSS, stringify: stringifyCSS } = require('css'); | ||
|
||
const baseCSSFilename = 'patternfly-base.css'; | ||
const stylesDir = resolve(__dirname, '../dist/styles'); | ||
const pfDir = dirname(require.resolve(`@patternfly/patternfly/${baseCSSFilename}`)); | ||
|
||
const css = readFileSync(join(pfDir, baseCSSFilename), 'utf8'); | ||
const ast = parseCSS(css); | ||
|
||
const unusedSelectorRegEx = /(\.fas?|\.sr-only)/; | ||
const unusedKeyFramesRegEx = /fa-/; | ||
const unusedFontFamilyRegEx = /Font Awesome 5 Free/; | ||
const ununsedFontFilesRegExt = /(fa-|\.html$|\.css$)/; | ||
|
||
// Core provides font awesome fonts and utlities. React does not use these | ||
ast.stylesheet.rules = ast.stylesheet.rules.filter(rule => { | ||
switch (rule.type) { | ||
case 'rule': | ||
return !rule.selectors.some(sel => unusedSelectorRegEx.test(sel)); | ||
case 'keyframes': | ||
return !unusedKeyFramesRegEx.test(rule.name); | ||
case 'charset': | ||
case 'comment': | ||
return false; | ||
case 'font-face': | ||
const fontFamilyDecl = rule.declarations.find(decl => decl.property === 'font-family'); | ||
return !unusedFontFamilyRegEx.test(fontFamilyDecl.value); | ||
default: | ||
return true; | ||
} | ||
}); | ||
|
||
copySync(join(pfDir, 'assets/images'), join(stylesDir, 'assets/images')); | ||
copySync(join(pfDir, 'assets/fonts'), join(stylesDir, 'assets/fonts'), { | ||
filter(src) { | ||
return !ununsedFontFilesRegExt.test(src); | ||
} | ||
}); | ||
writeFileSync(join(stylesDir, 'base.css'), stringifyCSS(ast)); |
8 changes: 8 additions & 0 deletions
8
packages/patternfly-4/react-inline-edit-extension/build/snapshot-serializer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const fs = require('fs'); | ||
const { createSerializer } = require('@patternfly/react-styles/snapshot-serializer'); | ||
|
||
const pf4CSS = fs.readFileSync(require.resolve('@patternfly/patternfly/patternfly-base.css'), 'utf8'); | ||
|
||
module.exports = createSerializer({ | ||
globalCSS: pf4CSS.match(/:root\W?\{(.|\n)*?\}/)[0] | ||
}); |
61 changes: 61 additions & 0 deletions
61
packages/patternfly-4/react-inline-edit-extension/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
{ | ||
"name": "@patternfly/react-inline-edit-extension", | ||
"version": "1.0.0", | ||
"description": "This library provides inline editing support for PatternFly 4 React table", | ||
"main": "dist/js/index.js", | ||
"module": "dist/esm/index.js", | ||
"types": "dist/js/index.d.ts", | ||
"sideEffects": false, | ||
"publishConfig": { | ||
"access": "public", | ||
"tag": "prerelease" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/patternfly/patternfly-react.git" | ||
}, | ||
"keywords": [ | ||
"react", | ||
"patternfly", | ||
"table", | ||
"reacttabular" | ||
], | ||
"author": "Red Hat", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/patternfly/patternfly-react/issues" | ||
}, | ||
"homepage": "https://github.com/patternfly/patternfly-react/tree/master/packages/patternfly-4/", | ||
"dependencies": { | ||
"@patternfly/patternfly": "1.0.244", | ||
"@patternfly/react-core": "^2.9.2", | ||
"@patternfly/react-table": "^1.3.4", | ||
"@patternfly/react-icons": "^3.6.1", | ||
"@patternfly/react-styles": "^2.4.0", | ||
"classnames": "^2.2.5", | ||
"exenv": "^1.2.2", | ||
"reactabular-table": "^8.14.0" | ||
}, | ||
"peerDependencies": { | ||
"prop-types": "^15.6.1", | ||
"react": "^16.4.0", | ||
"react-dom": "^15.6.2 || ^16.4.0" | ||
}, | ||
"scripts": { | ||
"build": "yarn build:babel && yarn build:ts", | ||
"build:babel": "concurrently \"yarn build:babel:cjs\" \"yarn build:babel:esm\"", | ||
"build:babel:cjs": "cross-env BABEL_ENV=production:cjs babel src --out-dir dist/js", | ||
"build:babel:esm": "cross-env BABEL_ENV=production:esm babel src --out-dir dist/esm", | ||
"build:ts": "node ./scripts/copyTS.js", | ||
"postbuild": "node ./build/copyStyles.js" | ||
}, | ||
"optionalDependencies": { | ||
"@patternfly/react-tokens": "^2.0.2" | ||
}, | ||
"devDependencies": { | ||
"css": "^2.2.3", | ||
"fs-extra": "^6.0.1", | ||
"glob": "^7.1.2", | ||
"npmlog": "^4.1.2" | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/patternfly-4/react-inline-edit-extension/scripts/copyTS.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const path = require('path'); | ||
const glob = require('glob'); | ||
const fse = require('fs-extra'); | ||
const log = require('npmlog'); | ||
|
||
const srcDir = path.join('./src'); | ||
const distDir = path.join('./dist/js'); | ||
|
||
const files = glob.sync('**/*.d.ts', { | ||
cwd: srcDir | ||
}); | ||
files.forEach(file => { | ||
const from = path.join(srcDir, file); | ||
const to = path.join(distDir, file); | ||
log.info('copyTS', `${from} --> ${to}`); | ||
fse.copySync(from, to); | ||
}); |
20 changes: 20 additions & 0 deletions
20
...ages/patternfly-4/react-inline-edit-extension/src/components/CancelButton/CancelButton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import { CloseIcon } from '@patternfly/react-icons'; | ||
import { Button } from '@patternfly/react-core'; | ||
|
||
const CancelButton = props => ( | ||
<Button {...props}> | ||
<CloseIcon /> | ||
</Button> | ||
); | ||
|
||
CancelButton.propTypes = { | ||
...Button.propTypes | ||
}; | ||
|
||
CancelButton.defaultProps = { | ||
...Button.defaultProps, | ||
variant: 'plain' | ||
}; | ||
|
||
export default CancelButton; |
9 changes: 9 additions & 0 deletions
9
...patternfly-4/react-inline-edit-extension/src/components/CancelButton/CancelButton.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { CancelButton } from './index'; | ||
|
||
test('it renders properly', () => { | ||
const component = shallow(<CancelButton />); | ||
|
||
expect(component).toMatchSnapshot(); | ||
}); |
22 changes: 22 additions & 0 deletions
22
...inline-edit-extension/src/components/CancelButton/__snapshots__/CancelButton.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`it renders properly 1`] = ` | ||
<Button | ||
aria-label={null} | ||
className="" | ||
component="button" | ||
isActive={false} | ||
isBlock={false} | ||
isDisabled={false} | ||
isFocus={false} | ||
isHover={false} | ||
type="button" | ||
variant="plain" | ||
> | ||
<CloseIcon | ||
color="currentColor" | ||
size="sm" | ||
title={null} | ||
/> | ||
</Button> | ||
`; |
1 change: 1 addition & 0 deletions
1
packages/patternfly-4/react-inline-edit-extension/src/components/CancelButton/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as CancelButton } from './CancelButton'; |
20 changes: 20 additions & 0 deletions
20
...es/patternfly-4/react-inline-edit-extension/src/components/ConfirmButton/ConfirmButton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import { CheckIcon } from '@patternfly/react-icons'; | ||
import { Button } from '@patternfly/react-core'; | ||
|
||
const ConfirmButton = props => ( | ||
<Button {...props}> | ||
<CheckIcon /> | ||
</Button> | ||
); | ||
|
||
ConfirmButton.propTypes = { | ||
...Button.propTypes | ||
}; | ||
|
||
ConfirmButton.defaultProps = { | ||
...Button.defaultProps, | ||
variant: 'primary' | ||
}; | ||
|
||
export default ConfirmButton; |
9 changes: 9 additions & 0 deletions
9
...tternfly-4/react-inline-edit-extension/src/components/ConfirmButton/ConfirmButton.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { ConfirmButton } from './index'; | ||
|
||
test('it renders properly', () => { | ||
const component = shallow(<ConfirmButton />); | ||
|
||
expect(component).toMatchSnapshot(); | ||
}); |
22 changes: 22 additions & 0 deletions
22
...line-edit-extension/src/components/ConfirmButton/__snapshots__/ConfirmButton.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`it renders properly 1`] = ` | ||
<Button | ||
aria-label={null} | ||
className="" | ||
component="button" | ||
isActive={false} | ||
isBlock={false} | ||
isDisabled={false} | ||
isFocus={false} | ||
isHover={false} | ||
type="button" | ||
variant="primary" | ||
> | ||
<CheckIcon | ||
color="currentColor" | ||
size="sm" | ||
title={null} | ||
/> | ||
</Button> | ||
`; |
1 change: 1 addition & 0 deletions
1
packages/patternfly-4/react-inline-edit-extension/src/components/ConfirmButton/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as ConfirmButton } from './ConfirmButton'; |
Oops, something went wrong.