File tree 7 files changed +211
-91
lines changed
scripts/generators/patternfly-3-component
7 files changed +211
-91
lines changed Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change 1
1
const { setActionTypes } = require ( './scripts/generators/actionTypes' ) ;
2
2
const { setHelpers } = require ( './scripts/generators/helpers' ) ;
3
3
const setPF4Generators = require ( './scripts/generators/patternfly-4-component' ) ;
4
+ const setPF3Generators = require ( './scripts/generators/patternfly-3-component' ) ;
4
5
const setPackageGenerators = require ( './scripts/generators/package' ) ;
5
6
6
7
module . exports = plop => {
7
8
setHelpers ( plop ) ;
8
9
setActionTypes ( plop ) ;
9
10
10
11
setPF4Generators ( plop ) ;
12
+ setPF3Generators ( plop ) ;
11
13
setPackageGenerators ( plop ) ;
12
14
} ;
Original file line number Diff line number Diff line change
1
+ const { join, resolve } = require ( 'path' ) ;
2
+ const { pascalCase } = require ( 'change-case' ) ;
3
+ const { ADD_TO_BARREL_FILE } = require ( '../actionTypes' ) ;
4
+
5
+ const templatesDir = resolve ( __dirname , './templates' ) ;
6
+ const patternflyReactRoot = resolve (
7
+ __dirname ,
8
+ '../../../packages/patternfly-react'
9
+ ) ;
10
+
11
+ function setPF3Generators ( plop ) {
12
+ plop . setGenerator ( 'PatternFly 3 Component' , {
13
+ description : 'Component for PatternFly 3 patternfly-react package' ,
14
+ prompts : [
15
+ {
16
+ type : 'input' ,
17
+ name : 'name' ,
18
+ message : 'What name should the component have?'
19
+ }
20
+ ] ,
21
+ actions : ( { name } ) => {
22
+ const base = join ( templatesDir , './component' ) ;
23
+ const data = {
24
+ componentName : pascalCase ( name )
25
+ } ;
26
+ return [
27
+ {
28
+ base,
29
+ data,
30
+ type : 'addMany' ,
31
+ destination : join (
32
+ patternflyReactRoot ,
33
+ './src/components/{{componentName}}/'
34
+ ) ,
35
+ templateFiles : join ( base , '*.js' )
36
+ } ,
37
+ {
38
+ data,
39
+ type : ADD_TO_BARREL_FILE ,
40
+ template : `export * from './components/{{componentName}}';` ,
41
+ path : join ( patternflyReactRoot , './src/index.js' )
42
+ }
43
+ ] . filter ( Boolean ) ;
44
+ }
45
+ } ) ;
46
+ }
47
+
48
+ module . exports = setPF3Generators ;
Original file line number Diff line number Diff line change
1
+ export { default as { { componentName } } } from './{{componentName}}' ;
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import PropTypes from 'prop-types' ;
3
+
4
+ /**
5
+ * {{componentName}} Component for PatternFly React
6
+ */
7
+ const { { componentName} } = ( { children, ...props } ) => < div { ...props } > { children } </ div > ;
8
+
9
+ { { componentName } } . propTypes = {
10
+ children : PropTypes . node
11
+ } ;
12
+
13
+ { { componentName } } . defaultProps = {
14
+ children : null
15
+ } ;
16
+
17
+ export default { { componentName} } ;
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import { storiesOf } from '@storybook/react' ;
3
+ import { withKnobs , text } from '@storybook/addon-knobs' ;
4
+ import { withInfo } from '@storybook/addon-info' ;
5
+ import { defaultTemplate } from 'storybook/decorators/storyTemplates' ;
6
+ import {
7
+ storybookPackageName ,
8
+ DOCUMENTATION_URL ,
9
+ STORYBOOK_CATEGORY
10
+ } from 'storybook/constants/siteConstants' ;
11
+ import { { { componentName } } } from './index' ;
12
+ import { name } from '../../../package.json' ;
13
+
14
+ const stories = storiesOf (
15
+ `${ storybookPackageName ( name ) } /${ STORYBOOK_CATEGORY . SOME_CATEGORY } /{{componentName}}` ,
16
+ module
17
+ ) ;
18
+ stories . addDecorator ( withKnobs ) ;
19
+ stories . addDecorator (
20
+ defaultTemplate ( {
21
+ title : '{{componentName}}' ,
22
+ documentationLink : `${
23
+ DOCUMENTATION_URL . SOME_PATTERNFLY_ORG_CATEGORY
24
+ } some-valid-component-url-here/`
25
+ } )
26
+ ) ;
27
+
28
+ stories . add (
29
+ '{{componentName}} story' ,
30
+ withInfo ( `This is the {{componentName}} component.` ) ( ( ) => (
31
+ < { { componentName} } >
32
+ < span >
33
+ { text (
34
+ 'Label' ,
35
+ 'Well done! You generated a PatternFly React component.'
36
+ ) }
37
+ </ span >
38
+ </{ { componentName} } >
39
+ ) )
40
+ ) ;
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import { shallow } from 'enzyme' ;
3
+ import { { componentName } } from './{{componentName}}' ;
4
+
5
+ const props = { } ;
6
+
7
+ test ( 'replace with useful test name' , ( ) => {
8
+ const view = shallow ( < { { componentName} } { ...props } /> ) ;
9
+ // Add a useful assertion here.
10
+ expect ( view ) . toBe ( false ) ;
11
+ } ) ;
You can’t perform that action at this time.
0 commit comments