diff --git a/.templates/new-module/package.json b/.templates/new-module/package.json index c5c87997c..5471a402a 100644 --- a/.templates/new-module/package.json +++ b/.templates/new-module/package.json @@ -31,7 +31,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -52,11 +52,11 @@ "path": "lib/js/module.js" }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-js": "~1", diff --git a/packages/accordion/package.json b/packages/accordion/package.json index cfa11d0a5..b0dcaacdb 100644 --- a/packages/accordion/package.json +++ b/packages/accordion/package.json @@ -31,7 +31,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -52,11 +52,11 @@ "path": "lib/js/module.js" }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-js": "~1", diff --git a/packages/accordion/src/js/jquery.js b/packages/accordion/src/jquery/jquery.js similarity index 100% rename from packages/accordion/src/js/jquery.js rename to packages/accordion/src/jquery/jquery.js diff --git a/packages/accordion/src/js/react.js b/packages/accordion/src/react/accordion.js similarity index 94% rename from packages/accordion/src/js/react.js rename to packages/accordion/src/react/accordion.js index e002c7633..ffd31f9f2 100644 --- a/packages/accordion/src/js/react.js +++ b/packages/accordion/src/react/accordion.js @@ -350,7 +350,7 @@ class AUaccordion extends React.PureComponent { /** * Toggle an accordion on click * - * @param {event object} event - The event object of the click + * @param {object} event - The event object of the click */ toggle( event ) { event.preventDefault(); @@ -391,15 +391,45 @@ class AUaccordion extends React.PureComponent { }; AUaccordion.propTypes = { + /** + * The elements inside. + */ children: PropTypes.node.isRequired, + /** + * The headline of the accordion + */ header: PropTypes.string.isRequired, + /** + * Closed state, optional + */ closed: PropTypes.bool, + /** + * Speed of the animation in ms, optional + */ speed: PropTypes.number, + /** + * A dark variation of the component + */ dark: PropTypes.bool, + /** + * A function executed when the accordion opens, optional + */ onOpen: PropTypes.func, + /** + * A function executed after the accordion opened, optional + */ afterOpen: PropTypes.func, + /** + * A function executed when the accordion closes, optional + */ onClose: PropTypes.func, + /** + * A function executed when the accordion closes, optional + */ afterClose: PropTypes.func, + /** + * The class name for the element, optional. + */ className: PropTypes.string, }; diff --git a/packages/body/package.json b/packages/body/package.json index 846d90ab2..b18156aec 100644 --- a/packages/body/package.json +++ b/packages/body/package.json @@ -33,7 +33,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, diff --git a/packages/breadcrumbs/package.json b/packages/breadcrumbs/package.json index 162cf6dd5..457b8aab9 100644 --- a/packages/breadcrumbs/package.json +++ b/packages/breadcrumbs/package.json @@ -33,7 +33,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -50,11 +50,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/breadcrumbs/src/js/react.js b/packages/breadcrumbs/src/react/breadcrumbs.js similarity index 90% rename from packages/breadcrumbs/src/js/react.js rename to packages/breadcrumbs/src/react/breadcrumbs.js index 9bf5e9ef6..61ffddaf5 100644 --- a/packages/breadcrumbs/src/js/react.js +++ b/packages/breadcrumbs/src/react/breadcrumbs.js @@ -42,14 +42,26 @@ const AUbreadcrumbs = ({ dark, label, items, linkComponent, className = '', ...a ); AUbreadcrumbs.propTypes = { + /** + * A dark variation of the component. + */ dark: PropTypes.bool, + /** + * Provide the aria label + */ label: PropTypes.string.isRequired, + /** + * The link, text and props for each of the breadcrumbs + */ items: PropTypes.arrayOf( PropTypes.shape({ link: PropTypes.string, text: PropTypes.string.isRequired, }) ).isRequired, + /** + * The component used for the link, optional. + */ linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]) }; diff --git a/packages/buttons/package.json b/packages/buttons/package.json index 71f710c84..f7890ebd4 100644 --- a/packages/buttons/package.json +++ b/packages/buttons/package.json @@ -31,7 +31,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -48,11 +48,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/buttons/src/js/react.js b/packages/buttons/src/react/buttons.js similarity index 88% rename from packages/buttons/src/js/react.js rename to packages/buttons/src/react/buttons.js index 7bb8c932e..effc33fb5 100644 --- a/packages/buttons/src/js/react.js +++ b/packages/buttons/src/react/buttons.js @@ -79,13 +79,34 @@ const AUbutton = ({ linkComponent, link, children, as, dark, type, block, classN }; AUbutton.propTypes = { + /** + * If an link is set the button will render as a link. + */ link: PropTypes.string, + /** + * Anything inside. + */ children: PropTypes.node.isRequired, + /** + * The kind of button, secondary or tertiary. + */ as: PropTypes.oneOf([ 'primary', 'secondary', 'tertiary' ]).isRequired, + /** + * A dark variation of the component. + */ dark: PropTypes.bool, type: PropTypes.string, + /** + * The block option to make the button fill the available width. + */ block: PropTypes.bool, + /** + * The class name for the element, optional. + */ className: PropTypes.string, + /** + * The component used for the link, optional. + */ linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]), }; diff --git a/packages/callout/package.json b/packages/callout/package.json index 1d422f208..0b7cd3bdb 100644 --- a/packages/callout/package.json +++ b/packages/callout/package.json @@ -35,7 +35,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -52,11 +52,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/callout/src/react/callout.js b/packages/callout/src/react/callout.js new file mode 100644 index 000000000..339babd12 --- /dev/null +++ b/packages/callout/src/react/callout.js @@ -0,0 +1,83 @@ +/*! [replace-name] v[replace-version] */ +/*************************************************************************************************************************************************************** + * + * Callout function + * + * Use callout to notify and alert users of important snippets of information. + * + **************************************************************************************************************************************************************/ + +import React from 'react'; +import PropTypes from 'prop-types'; + + +// The following line will be replaced automatically with generic imports for the ES5 pipeline. +// You can safely ignore this bit if you use this module with pancake +// +// [replace-imports] + + +/** + * Default callout + * + * @param {string} title - The title of the header + * @param {string} level - The tag level (

etc), default: '1' + * @param {boolean} srOnlyTitle - Title is visible to screen readers only + * @param {boolean} dark - Add the dark variation class, optional + * @param {boolean} alt - Add the alt variation class, optional + * @param {string} children - Anything inside + * @param {string} className - An additional class, optional + * @param {object} attributeOptions - Any other attribute options + */ +export const AUcallout = ({ title, level, srOnlyTitle, dark, alt, description, children, className = '', ...attributeOptions }) => { + const HeadingTag = `h${ level }`; + + return ( +
+ + { children } +
+ ) +}; + +AUcallout.propTypes = { + /** + * Title of the callout. + */ + title: PropTypes.string.isRequired, + /** + * The tag level (

etc), default: '1'. + */ + level: PropTypes.number, + /** + * Make title screen reader visible. + */ + srOnlyTitle: PropTypes.bool, + /** + * A dark variation of the component. + */ + dark: PropTypes.bool, + /** + * A alternate variation of the component. + */ + alt: PropTypes.bool, + /** + * Anything inside. + */ + children: PropTypes.node.isRequired, + /** + * The class name for the element, optional. + */ + className: PropTypes.string, +}; + +AUcallout.defaultProps = { + level: 2, + srOnlyTitle: false, +}; diff --git a/packages/callout/src/js/react.js b/packages/callout/src/react/calloutCalendar.js similarity index 58% rename from packages/callout/src/js/react.js rename to packages/callout/src/react/calloutCalendar.js index ef03d2099..46dfc9a43 100644 --- a/packages/callout/src/js/react.js +++ b/packages/callout/src/react/calloutCalendar.js @@ -1,67 +1,16 @@ -/*! [replace-name] v[replace-version] */ /*************************************************************************************************************************************************************** * - * Callout function + * Callout calendar function * - * Use callout to notify and alert users of important snippets of information. + * Use callout calendar to ... * **************************************************************************************************************************************************************/ + import React from 'react'; import PropTypes from 'prop-types'; -// The following line will be replaced automatically with generic imports for the ES5 pipeline. -// You can safely ignore this bit if you use this module with pancake -// -// [replace-imports] - - -/** - * Default callout - * - * @param {string} title - The title of the header - * @param {string} level - The tag level (

etc), default: '1' - * @param {boolean} srOnlyTitle - Title is visible to screen readers only - * @param {boolean} dark - Add the dark variation class, optional - * @param {boolean} alt - Add the alt variation class, optional - * @param {string} children - Anything inside - * @param {string} className - An additional class, optional - * @param {object} attributeOptions - Any other attribute options - */ -export const AUcallout = ({ title, level, srOnlyTitle, dark, alt, description, children, className = '', ...attributeOptions }) => { - const HeadingTag = `h${ level }`; - - return ( -
- - { children } -
- ) -}; - -AUcallout.propTypes = { - title: PropTypes.string.isRequired, - level: PropTypes.number, - srOnlyTitle: PropTypes.bool, - dark: PropTypes.bool, - alt: PropTypes.bool, - children: PropTypes.node.isRequired, - className: PropTypes.string, -}; - -AUcallout.defaultProps = { - level: 2, - srOnlyTitle: false, -}; - - /** * Calendar callout * @@ -97,19 +46,52 @@ export const AUcalloutCalendar = ({ title, level, srOnlyTitle, dark, alt, sublin } AUcalloutCalendar.propTypes = { + /** + * Title of the callout. + */ title: PropTypes.string.isRequired, + /** + * The tag level (

etc), default: '1'. + */ level: PropTypes.number, + /** + * Make title screen reader visible. + */ srOnlyTitle: PropTypes.bool, + /** + * A dark variation of the component. + */ dark: PropTypes.bool, + /** + * A alternate variation of the component. + */ alt: PropTypes.bool, + /** + * The subline of the event, optional. + */ subline: PropTypes.string, + /** + * The date time string. + */ datetime: PropTypes.string.isRequired, + /** + * The same date but human readable. + */ time: PropTypes.string.isRequired, + /** + * The name of the event, optional. + */ name: PropTypes.string, + /** + * The class name for the element, optional. + */ className: PropTypes.string, }; AUcalloutCalendar.defaultProps = { + title: 'Title of the calendar callout', + datetime: '2017-01-01T00:00:00+00:00', + time: 'Sunday 32 Jun', level: 2, srOnlyTitle: true, }; diff --git a/packages/control-input/package.json b/packages/control-input/package.json index c168a31ea..eb5b8d008 100644 --- a/packages/control-input/package.json +++ b/packages/control-input/package.json @@ -31,7 +31,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -48,11 +48,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/control-input/src/js/react.js b/packages/control-input/src/react/control-input.js similarity index 58% rename from packages/control-input/src/js/react.js rename to packages/control-input/src/react/control-input.js index dc25070b5..5121f4614 100644 --- a/packages/control-input/src/js/react.js +++ b/packages/control-input/src/react/control-input.js @@ -1,7 +1,7 @@ /*! [replace-name] v[replace-version] */ /*************************************************************************************************************************************************************** * - * control-input function + * control-input checkbox function * * Control inputs include radio buttons and checkboxes. They allow users to select one or more options. * @@ -49,55 +49,36 @@ export const AUcheckbox = ({ dark, alt, small, block, label, status, id, classNa }; AUcheckbox.propTypes = { + /** + * A dark variation of the component + */ dark: PropTypes.bool, + /** + * An alternate variation of the component + */ alt: PropTypes.bool, + /** + * The small variation of the component + */ small: PropTypes.bool, + /** + * + */ block: PropTypes.bool, + /** + * The label of the radio button + */ label: PropTypes.string.isRequired, - id: PropTypes.string.isRequired, - status: PropTypes.oneOf([ 'valid', 'invalid' ]), - className: PropTypes.string, -}; - - -/** - * The radio component - * - * @param {boolean} dark - Add the dark variation class, optional - * @param {boolean} alt - Add the alt variation class, optional - * @param {boolean} small - Add the small variation class - * @param {boolean} block - Add the block variation class - * @param {string} label - The label text - * @param {string} status - Mark this field as either 'valid' or 'invalid', optional - * @param {string} id - The id of the radio input - * @param {string} className - An additional class, optional - * @param {object} attributeOptions - Any other attribute options - */ -export const AUradio = ({ dark, alt, small, block, label, status, id, className = '', ...attributeOptions }) => { - - return ( -
- - -
- ); -}; - -AUradio.propTypes = { - dark: PropTypes.bool, - alt: PropTypes.bool, - small: PropTypes.bool, - block: PropTypes.bool, - label: PropTypes.string.isRequired, + /** + * + */ id: PropTypes.string.isRequired, + /** + * + */ status: PropTypes.oneOf([ 'valid', 'invalid' ]), + /** + * The class name for the element, optional. + */ className: PropTypes.string, }; diff --git a/packages/control-input/src/react/control-inputRadio.js b/packages/control-input/src/react/control-inputRadio.js new file mode 100644 index 000000000..fe62eaca0 --- /dev/null +++ b/packages/control-input/src/react/control-inputRadio.js @@ -0,0 +1,77 @@ +/*************************************************************************************************************************************************************** + * + * control-input radio function + * + * Control inputs include radio buttons and checkboxes. They allow users to select one or more options. + * + **************************************************************************************************************************************************************/ + +import React from 'react'; +import PropTypes from 'prop-types'; + + +/** + * The radio component + * + * @param {boolean} dark - Add the dark variation class, optional + * @param {boolean} alt - Add the alt variation class, optional + * @param {boolean} small - Add the small variation class + * @param {boolean} block - Add the block variation class + * @param {string} label - The label text + * @param {string} status - Mark this field as either 'valid' or 'invalid', optional + * @param {string} id - The id of the radio input + * @param {string} className - An additional class, optional + * @param {object} attributeOptions - Any other attribute options + */ +export const AUradio = ({ dark, alt, small, block, label, status, id, className = '', ...attributeOptions }) => { + + return ( +
+ + +
+ ); +}; + +AUradio.propTypes = { + /** + * A dark variation of the component + */ + dark: PropTypes.bool, + /** + * An alternate variation of the component + */ + alt: PropTypes.bool, + /** + * The small variation of the component + */ + small: PropTypes.bool, + /** + * + */ + block: PropTypes.bool, + /** + * The label of the radio button + */ + label: PropTypes.string.isRequired, + /** + * The label of the checkbox button + */ + id: PropTypes.string.isRequired, + /** + * + */ + status: PropTypes.oneOf([ 'valid', 'invalid' ]), + /** + * The class name for the element, optional. + */ + className: PropTypes.string, +}; diff --git a/packages/core/package.json b/packages/core/package.json index db8815f39..9fece00ba 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -31,7 +31,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, diff --git a/packages/cta-link/package.json b/packages/cta-link/package.json index f239a02dc..a6b9ba908 100644 --- a/packages/cta-link/package.json +++ b/packages/cta-link/package.json @@ -34,7 +34,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -51,11 +51,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/cta-link/src/js/react.js b/packages/cta-link/src/react/cta-link.js similarity index 89% rename from packages/cta-link/src/js/react.js rename to packages/cta-link/src/react/cta-link.js index e77e8d0c2..b8642c8dd 100644 --- a/packages/cta-link/src/js/react.js +++ b/packages/cta-link/src/react/cta-link.js @@ -53,10 +53,25 @@ const AUctaLink = ({ linkComponent, dark, link, text, className = '', ...attribu } AUctaLink.propTypes = { + /** + * A dark variation of the component. + */ dark: PropTypes.bool, + /** + * The link to the location of the cta-link. + */ link: PropTypes.string, + /** + * Provide the aria label. + */ text: PropTypes.string.isRequired, + /** + * The class name for the element, optional. + */ className: PropTypes.string, + /** + * The component used for the link, optional. + */ linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]) }; diff --git a/packages/direction-links/package.json b/packages/direction-links/package.json index 29d76df3b..56afd27d8 100644 --- a/packages/direction-links/package.json +++ b/packages/direction-links/package.json @@ -37,7 +37,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -54,11 +54,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/direction-links/src/js/react.js b/packages/direction-links/src/react/direction-links.js similarity index 90% rename from packages/direction-links/src/js/react.js rename to packages/direction-links/src/react/direction-links.js index 81b7356e8..1ce1ae465 100644 --- a/packages/direction-links/src/js/react.js +++ b/packages/direction-links/src/react/direction-links.js @@ -67,11 +67,29 @@ const AUdirectionLink = ({ linkComponent, dark, link, text, direction, className }; AUdirectionLink.propTypes = { + /** + * A dark variation of the component. + */ dark: PropTypes.bool, + /** + * The href link, optional. + */ link: PropTypes.string, + /** + * The text of the link. + */ text: PropTypes.string.isRequired, + /** + * The direction the link goes. + */ direction: PropTypes.oneOf([ 'up', 'right', 'down', 'left' ]).isRequired, + /** + * The class name for the element, optional. + */ className: PropTypes.string, + /** + * The component used for the link, optional. + */ linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]) }; diff --git a/packages/footer/package.json b/packages/footer/package.json index 48b79c7af..8de4e2cd4 100644 --- a/packages/footer/package.json +++ b/packages/footer/package.json @@ -34,7 +34,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -51,11 +51,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/footer/src/js/react.js b/packages/footer/src/react/footer.js similarity index 54% rename from packages/footer/src/js/react.js rename to packages/footer/src/react/footer.js index e124f0917..0e3f25174 100644 --- a/packages/footer/src/js/react.js +++ b/packages/footer/src/react/footer.js @@ -17,51 +17,6 @@ import PropTypes from 'prop-types'; // [replace-imports] - -/** - * A section for the footer that contains navigational elements - * - * @param {node} children - The inside of this section - * @param {string} className - An additional class, optional - * @param {string} ariaLabel - The aria-label attribute, optional - * @param {object} attributeOptions - Any other attribute options - */ -export const AUfooterNav = ({ children, className = '', ariaLabel, ...attributeOptions }) => ( - -); - -AUfooterNav.propTypes = { - children: PropTypes.node.isRequired, - className: PropTypes.string, - ariaLabel: PropTypes.string, -}; - -AUfooterNav.defaultProps = { - ariaLabel: 'footer', -} - - -/** - * A section for the footer that sits at the end - * - * @param {node} children - The inside of this section - * @param {string} className - An additional class, optional - * @param {object} attributeOptions - Any other attribute options - */ -export const AUfooterEnd = ({ children, className = '', ...attributeOptions }) => ( -
- { children } -
-); - -AUfooterEnd.propTypes = { - children: PropTypes.node.isRequired, - className: PropTypes.string, -}; - - /** * DEFAULT * The footer component @@ -83,9 +38,21 @@ const AUfooter = ({ dark, alt, children, className = '', ...attributeOptions }) ); AUfooter.propTypes = { + /** + * A dark variation of the component + */ dark: PropTypes.bool, + /** + * A alternate variation of the component + */ alt: PropTypes.bool, + /** + * The elements inside. + */ children: PropTypes.node.isRequired, + /** + * The class name for the element, optional. + */ className: PropTypes.string, }; diff --git a/packages/footer/src/react/footerEnd.js b/packages/footer/src/react/footerEnd.js new file mode 100644 index 000000000..fdb7b7d4c --- /dev/null +++ b/packages/footer/src/react/footerEnd.js @@ -0,0 +1,36 @@ +/*************************************************************************************************************************************************************** + * + * footer end function + * + * Footers help users who reach the bottom of a page without finding what they want. + * + **************************************************************************************************************************************************************/ + + +import React from 'react'; +import PropTypes from 'prop-types'; + + +/** + * A section for the footer that sits at the end + * + * @param {node} children - The inside of this section + * @param {string} className - An additional class, optional + * @param {object} attributeOptions - Any other attribute options + */ +export const AUfooterEnd = ({ children, className = '', ...attributeOptions }) => ( +
+ { children } +
+); + +AUfooterEnd.propTypes = { + /** + * The elements inside. + */ + children: PropTypes.node.isRequired, + /** + * The class name for the element, optional. + */ + className: PropTypes.string, +}; diff --git a/packages/footer/src/react/footerNav.js b/packages/footer/src/react/footerNav.js new file mode 100644 index 000000000..ad604a6da --- /dev/null +++ b/packages/footer/src/react/footerNav.js @@ -0,0 +1,45 @@ +/*************************************************************************************************************************************************************** + * + * footer nav function + * + * Footers help users who reach the bottom of a page without finding what they want. + * + **************************************************************************************************************************************************************/ + + +import React from 'react'; +import PropTypes from 'prop-types'; + + +/** + * A section for the footer that contains navigational elements + * + * @param {node} children - The inside of this section + * @param {string} className - An additional class, optional + * @param {string} ariaLabel - The aria-label attribute, optional + * @param {object} attributeOptions - Any other attribute options + */ +export const AUfooterNav = ({ children, className = '', ariaLabel, ...attributeOptions }) => ( + +); + +AUfooterNav.propTypes = { + /** + * The elements inside. + */ + children: PropTypes.node.isRequired, + /** + * The class name for the element, optional. + */ + className: PropTypes.string, + /** + * The aria-label attribute, defaults to "footer navigation" + */ + ariaLabel: PropTypes.string, +}; + +AUfooterNav.defaultProps = { + ariaLabel: 'footer', +} diff --git a/packages/form/package.json b/packages/form/package.json index ef891bbdf..aa3f4ca9a 100644 --- a/packages/form/package.json +++ b/packages/form/package.json @@ -23,10 +23,10 @@ "build:pre": "node ../../scripts/helper.js precompile publish", "build:js": "npm run build:pre && node ../../scripts/helper.js compile", "build:react": "cd tests/react/ && webpack", - "build": "npm run build:js && npm run build:react", + "build": "npm run build:js", "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build:react", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -43,11 +43,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/form/src/js/react.js b/packages/form/src/js/react.js deleted file mode 100644 index 125fecbe1..000000000 --- a/packages/form/src/js/react.js +++ /dev/null @@ -1,230 +0,0 @@ -/*! [replace-name] v[replace-version] */ -/*************************************************************************************************************************************************************** - * - * form function - * - * The form component contains layout, labelling and inline validations for form fields - * - **************************************************************************************************************************************************************/ - -import React from 'react'; -import PropTypes from 'prop-types'; - - -// The following line will be replaced automatically with generic imports for the ES5 pipeline. -// You can safely ignore this bit if you use this module with pancake -// -// [replace-imports] - - -/** - * The label component - * - * @param {string} text - Text of the label, required - * @param {boolean} dark - Add the dark variation class, optional - * @param {boolean} inline - Display the label inline, optional - * @param {string} className - An additional class, optional - * @param {object} attributeOptions - Any other attribute options - */ -export const AUlabel = ( { text, dark, inline, className, ...attributeOptions } ) => ( - -); - -AUlabel.propTypes = { - /** - * Text of the label, required - */ - text: PropTypes.string.isRequired, - /** - * Add the dark variation class, optional - */ - dark: PropTypes.bool, - /** - * Display the label inline, optional - */ - inline: PropTypes.bool, - /** - * An additional class, optional - */ - className: PropTypes.string, -}; - - -AUlabel.defaultProps = { - className: '' -} - - -/** - * The hint text component - * - * @param {string} text - Text of the label, required - * @param {boolean} dark - Add the dark variation class, optional - * @param {boolean} alt - Add the alt variation class, optional - * @param {string} className - An additional class, optional - * @param {object} attributeOptions - Any other attribute options - */ -export const AUhintText = ( { text, dark, alt, className, ...attributeOptions } ) => ( - - { text } - -); - - -AUhintText.propTypes = { - /** - * Text of the label, required - */ - text: PropTypes.string.isRequired, - /** - * Add the dark variation class, optional - */ - alt: PropTypes.bool, - /** - * Add the alt variation class, optional - */ - dark: PropTypes.bool, - /** - * An additional class, optional - */ - className: PropTypes.string, -}; - - -AUhintText.defaultProps = { - className: '' -} - - -/** - * The error text component - * - * @param {string} text - Text of the label, required - * @param {boolean} dark - Add the dark variation class, optional - * @param {boolean} inline - Display the error text inline, optional - * @param {string} className - An additional class, optional - * @param {object} attributeOptions - Any other attribute options - */ -export const AUerrorText = ( { text, dark, inline, className, ...attributeOptions } ) => ( - - { text } - -); - - -AUerrorText.propTypes = { - /** - * Text of the label, required - */ - dark: PropTypes.bool, - /** - * Add the dark variation class, optional - */ - text: PropTypes.string.isRequired, - /** - * Display the error text inline, optional - */ - inline: PropTypes.bool, - /** - * An additional class, optional - */ - className: PropTypes.string, -}; - - -AUerrorText.defaultProps = { - className: '' -} - -/** - * The form group component - * - * @param {string} status - Adds invalid state to form group - * @param {string} className - An additional class, optional - * @param {object} attributeOptions - Any other attribute options - */ -export const AUformGroup = ( { status, dark, className, ...attributeOptions } ) => ( -
-); - - -AUformGroup.propTypes = { - /** - * Adds invalid state to form group - */ - status: PropTypes.oneOf(['valid', 'invalid']), - /** - * An additional class, optional - */ - className: PropTypes.string, -}; - -AUformGroup.defaultProps = { - status: "valid", - className: '' -} - - -/** - * The fieldset component - * - * @param {string} className - An additional class, optional - * @param {object} attributeOptions - Any other attribute options - */ -export const AUfieldset = ( { dark, className, ...attributeOptions } ) => ( -
-
-); - - -AUfieldset.propTypes = { - /** - * An additional class, optional - */ - className: PropTypes.string, -}; - - -AUfieldset.defaultProps = { - className: '' -} - - -/** - * The legend component - * - * @param {object} attributeOptions - Any other attribute options - */ -export const AUlegend = ( {...attributeOptions} ) => ( - -); diff --git a/packages/form/src/react/form.js b/packages/form/src/react/form.js new file mode 100644 index 000000000..09e5f1bcb --- /dev/null +++ b/packages/form/src/react/form.js @@ -0,0 +1,47 @@ +/*! [replace-name] v[replace-version] */ +/*************************************************************************************************************************************************************** + * + * form fieldset function + * + * The form component contains layout, labelling and inline validations for form fields + * +**************************************************************************************************************************************************************/ + +import React from 'react'; +import PropTypes from 'prop-types'; + + +// The following line will be replaced automatically with generic imports for the ES5 pipeline. +// You can safely ignore this bit if you use this module with pancake +// +// [replace-imports] + + +/** + * The fieldset component + * + * @param {string} className - An additional class, optional + * @param {object} attributeOptions - Any other attribute options + */ +export const AUfieldset = ( { dark, className, ...attributeOptions } ) => ( +
+
+); + + +AUfieldset.propTypes = { + /** + * An additional class, optional + */ + className: PropTypes.string, +}; + + +AUfieldset.defaultProps = { + className: '' +} diff --git a/packages/form/src/react/formErrorText.js b/packages/form/src/react/formErrorText.js new file mode 100644 index 000000000..034a02563 --- /dev/null +++ b/packages/form/src/react/formErrorText.js @@ -0,0 +1,58 @@ +/*************************************************************************************************************************************************************** + * + * form error text function + * + * The form component contains layout, labelling and inline validations for form fields + * +**************************************************************************************************************************************************************/ + + +import React from 'react'; +import PropTypes from 'prop-types'; + + +/** + * The error text component + * + * @param {string} text - Text of the label, required + * @param {boolean} dark - Add the dark variation class, optional + * @param {boolean} inline - Display the error text inline, optional + * @param {string} className - An additional class, optional + * @param {object} attributeOptions - Any other attribute options + */ +export const AUerrorText = ( { text, dark, inline, className, ...attributeOptions } ) => ( + + { text } + +); + + +AUerrorText.propTypes = { + /** + * Text of the label, required + */ + dark: PropTypes.bool, + /** + * Add the dark variation class, optional + */ + text: PropTypes.string.isRequired, + /** + * Display the error text inline, optional + */ + inline: PropTypes.bool, + /** + * An additional class, optional + */ + className: PropTypes.string, +}; + + +AUerrorText.defaultProps = { + className: '' +} diff --git a/packages/form/src/react/formGroup.js b/packages/form/src/react/formGroup.js new file mode 100644 index 000000000..527792bb5 --- /dev/null +++ b/packages/form/src/react/formGroup.js @@ -0,0 +1,50 @@ +/*************************************************************************************************************************************************************** + * + * form group function + * + * The form component contains layout, labelling and inline validations for form fields + * +**************************************************************************************************************************************************************/ + +import React from 'react'; +import PropTypes from 'prop-types'; + + +// The following line will be replaced automatically with generic imports for the ES5 pipeline. +// You can safely ignore this bit if you use this module with pancake +// +// [replace-imports] + + +/** + * The form group component + * + * @param {string} status - Adds invalid state to form group + * @param {string} className - An additional class, optional + * @param {object} attributeOptions - Any other attribute options + */ +export const AUformGroup = ( { status, dark, className, ...attributeOptions } ) => ( +
+); + + +AUformGroup.propTypes = { + /** + * Adds invalid state to form group + */ + status: PropTypes.oneOf(['valid', 'invalid']), + /** + * An additional class, optional + */ + className: PropTypes.string, +}; + +AUformGroup.defaultProps = { + status: "valid", + className: '' +} diff --git a/packages/form/src/react/formHintText.js b/packages/form/src/react/formHintText.js new file mode 100644 index 000000000..131eec2cb --- /dev/null +++ b/packages/form/src/react/formHintText.js @@ -0,0 +1,58 @@ +/*************************************************************************************************************************************************************** + * + * form hint text function + * + * The form component contains layout, labelling and inline validations for form fields + * +**************************************************************************************************************************************************************/ + + +import React from 'react'; +import PropTypes from 'prop-types'; + + +/** + * The hint text component + * + * @param {string} text - Text of the label, required + * @param {boolean} dark - Add the dark variation class, optional + * @param {boolean} alt - Add the alt variation class, optional + * @param {string} className - An additional class, optional + * @param {object} attributeOptions - Any other attribute options + */ +export const AUhintText = ( { text, dark, alt, className, ...attributeOptions } ) => ( + + { text } + +); + + +AUhintText.propTypes = { + /** + * Text of the label, required + */ + text: PropTypes.string.isRequired, + /** + * Add the dark variation class, optional + */ + alt: PropTypes.bool, + /** + * Add the alt variation class, optional + */ + dark: PropTypes.bool, + /** + * An additional class, optional + */ + className: PropTypes.string, +}; + + +AUhintText.defaultProps = { + className: '' +} diff --git a/packages/form/src/react/formLabel.js b/packages/form/src/react/formLabel.js new file mode 100644 index 000000000..a2b55195b --- /dev/null +++ b/packages/form/src/react/formLabel.js @@ -0,0 +1,57 @@ +/*************************************************************************************************************************************************************** + * + * form label function + * + * The form component contains layout, labelling and inline validations for form fields + * +**************************************************************************************************************************************************************/ + + +import React from 'react'; +import PropTypes from 'prop-types'; + + +/** + * The label component + * + * @param {string} text - Text of the label, required + * @param {boolean} dark - Add the dark variation class, optional + * @param {boolean} inline - Display the label inline, optional + * @param {string} className - An additional class, optional + * @param {object} attributeOptions - Any other attribute options + */ +export const AUlabel = ( { text, dark, inline, className, ...attributeOptions } ) => ( + +); + +AUlabel.propTypes = { + /** + * Text of the label, required + */ + text: PropTypes.string.isRequired, + /** + * Add the dark variation class, optional + */ + dark: PropTypes.bool, + /** + * Display the label inline, optional + */ + inline: PropTypes.bool, + /** + * An additional class, optional + */ + className: PropTypes.string, +}; + + +AUlabel.defaultProps = { + className: '' +} diff --git a/packages/form/src/react/formLegend.js b/packages/form/src/react/formLegend.js new file mode 100644 index 000000000..132bc06b3 --- /dev/null +++ b/packages/form/src/react/formLegend.js @@ -0,0 +1,21 @@ +/*************************************************************************************************************************************************************** + * + * form legend function + * + * The form component contains layout, labelling and inline validations for form fields + * +**************************************************************************************************************************************************************/ + + +import React from 'react'; +import PropTypes from 'prop-types'; + + +/** + * The legend component + * + * @param {object} attributeOptions - Any other attribute options + */ +export const AUlegend = ( {...attributeOptions} ) => ( + +); diff --git a/packages/form/tests/react/index.js b/packages/form/tests/react/index.js index d682e813e..976423e3b 100644 --- a/packages/form/tests/react/index.js +++ b/packages/form/tests/react/index.js @@ -1,11 +1,11 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import { AUlabel, AUhintText, AUerrorText, AUformGroup, AUfieldset, AUForm, AUlegend } from './form.js'; -import AUtextInput from '../../../text-inputs/src/js/react'; -import AUheading from '../../../headings/src/js/react'; -import AUselect from '../../../select/src/js/react'; -import { AUcheckbox } from '../../../control-input/src/js/react'; +import { AUlabel, AUhintText, AUerrorText, AUformGroup, AUfieldset, AUlegend } from './form.js'; +import AUtextInput from '../../../text-inputs'; +import AUheading from '../../../headings'; +import AUselect from '../../../select'; +import { AUcheckbox } from '../../../control-input'; class App extends React.Component { diff --git a/packages/grid-12/package.json b/packages/grid-12/package.json index 23b6a67b4..e1e8d28aa 100644 --- a/packages/grid-12/package.json +++ b/packages/grid-12/package.json @@ -33,7 +33,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, diff --git a/packages/header/package.json b/packages/header/package.json index 0521d3e51..45cbb361d 100644 --- a/packages/header/package.json +++ b/packages/header/package.json @@ -33,7 +33,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -50,11 +50,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/header/src/react/header.js b/packages/header/src/react/header.js new file mode 100644 index 000000000..f96e6bf10 --- /dev/null +++ b/packages/header/src/react/header.js @@ -0,0 +1,47 @@ +/*! [replace-name] v[replace-version] */ +/*************************************************************************************************************************************************************** + * + * header function + * + * Headers provide a consistent start to pages. + * + **************************************************************************************************************************************************************/ + +import React from 'react'; +import PropTypes from 'prop-types'; + + +// The following line will be replaced automatically with generic imports for the ES5 pipeline. +// You can safely ignore this bit if you use this module with pancake +// +// [replace-imports] + + +/** + * DEFAULT + * The header component + * + * @param {boolean} hero - The hero option, optional + * @param {boolean} dark - Add the dark variation class, optional + * @param {boolean} alt - Add the alt variation class, optional + * @param {node} children - The inside of this section + * @param {string} className - An additional class, optional + * @param {object} attributeOptions - Any other attribute options + */ +const AUheader = ({ hero, dark, alt, children, className = '', ...attributeOptions }) => ( +
+ { children } +
+); + +AUheader.propTypes = { + hero: PropTypes.bool, + dark: PropTypes.bool, + alt: PropTypes.bool, + children: PropTypes.node, + className: PropTypes.string, +}; + +export default AUheader; diff --git a/packages/header/src/js/react.js b/packages/header/src/react/headerBrand.js similarity index 67% rename from packages/header/src/js/react.js rename to packages/header/src/react/headerBrand.js index a1b7faccb..7b705a8d6 100644 --- a/packages/header/src/js/react.js +++ b/packages/header/src/react/headerBrand.js @@ -1,22 +1,16 @@ -/*! [replace-name] v[replace-version] */ /*************************************************************************************************************************************************************** * * header function * * Headers provide a consistent start to pages. * - **************************************************************************************************************************************************************/ +**************************************************************************************************************************************************************/ + import React from 'react'; import PropTypes from 'prop-types'; -// The following line will be replaced automatically with generic imports for the ES5 pipeline. -// You can safely ignore this bit if you use this module with pancake -// -// [replace-imports] - - /** * The header brand component * @@ -89,14 +83,41 @@ export const AUheaderBrand = ({ } AUheaderBrand.propTypes = { + /** + * + */ title: PropTypes.node, + /** + * + */ level: PropTypes.oneOf([ '1', '2', '3', '4', '5', '6' ]), + /** + * + */ subline: PropTypes.node, + /** + * + */ link: PropTypes.string, + /** + * + */ brandImage: PropTypes.string, + /** + * + */ brandImageAlt: PropTypes.string, + /** + * + */ children: PropTypes.node, + /** + * The class name for the element, optional. + */ className: PropTypes.string, + /** + * + */ linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]), } @@ -105,33 +126,3 @@ AUheaderBrand.defaultProps = { brandImageAlt: 'Australian Government Crest', linkComponent: 'a', }; - - -/** - * DEFAULT - * The header component - * - * @param {boolean} hero - The hero option, optional - * @param {boolean} dark - Add the dark variation class, optional - * @param {boolean} alt - Add the alt variation class, optional - * @param {node} children - The inside of this section - * @param {string} className - An additional class, optional - * @param {object} attributeOptions - Any other attribute options - */ -const AUheader = ({ hero, dark, alt, children, className = '', ...attributeOptions }) => ( -
- { children } -
-); - -AUheader.propTypes = { - hero: PropTypes.bool, - dark: PropTypes.bool, - alt: PropTypes.bool, - children: PropTypes.node, - className: PropTypes.string, -}; - -export default AUheader; diff --git a/packages/headings/package.json b/packages/headings/package.json index 19ffa9950..a0c9027bb 100644 --- a/packages/headings/package.json +++ b/packages/headings/package.json @@ -35,7 +35,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -52,11 +52,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/headings/src/js/react.js b/packages/headings/src/react/headings.js similarity index 90% rename from packages/headings/src/js/react.js rename to packages/headings/src/react/headings.js index 4af8d15aa..847ebf347 100644 --- a/packages/headings/src/js/react.js +++ b/packages/headings/src/react/headings.js @@ -51,9 +51,18 @@ const AUheading = ({ level, size, children, className = '', ...attributeOptions }; AUheading.propTypes = { + /** + * The semantic headline tag level, h1-h6. + */ level: PropTypes.oneOf([ '1', '2', '3', '4', '5', '6' ]).isRequired, + /** + * The display size, 'xs', 'sm', 'md', 'lg', 'xl', 'xxl', 'xxxl'. + */ size: PropTypes.oneOf([ 'xs', 'sm', 'md', 'lg', 'xl', 'xxl', 'xxxl' ]).isRequired, children: PropTypes.node.isRequired, + /** + * The class name for the element, optional. + */ className: PropTypes.string, }; diff --git a/packages/inpage-nav/package.json b/packages/inpage-nav/package.json index fbd311c1c..3852ced15 100644 --- a/packages/inpage-nav/package.json +++ b/packages/inpage-nav/package.json @@ -35,7 +35,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -52,11 +52,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/inpage-nav/src/js/react.js b/packages/inpage-nav/src/react/inpage-nav.js similarity index 52% rename from packages/inpage-nav/src/js/react.js rename to packages/inpage-nav/src/react/inpage-nav.js index c01ae4ce7..e63427ee7 100644 --- a/packages/inpage-nav/src/js/react.js +++ b/packages/inpage-nav/src/react/inpage-nav.js @@ -17,66 +17,6 @@ import PropTypes from 'prop-types'; // [replace-imports] -/** - * The section component for the AUinpageNavLinks component - * - * @param {object} link - The link of this section - * @param {object} title - The title of the section - * @param {object} li - An additional object to be spread into the wrapping element, optional - * @param {object} attributeOptions - Any other attribute options - */ -export const AUinpageNavLinksItem = ({ link, title, li = {}, ...attributeOptions }) => ( -
  • - { title } -
  • -); - -AUinpageNavLinksItem.propTypes = { - link: PropTypes.string.isRequired, - title: PropTypes.string.isRequired, - li: PropTypes.object, -}; - - -/** - * The inpage-nav component - * - * @param {boolean} dark - Add the dark variation class, optional - * @param {string} title - The title of the content link block, default: Contents - * @param {array} sections - An array of objects of all sections, sample: { link: '', title: '', onClick: () } - * @param {string} className - An additional class, optional - * @param {string} ariaLabel - The aria-label attribute, optional - * @param {object} attributeOptions - Any other attribute options - */ -export const AUinpageNavLinks = ({ dark, title, sections, ariaLabel, className = '', ...attributeOptions }) => ( - -); - -AUinpageNavLinks.propTypes = { - dark: PropTypes.bool, - title: PropTypes.string.isRequired, - sections: PropTypes.arrayOf( - PropTypes.shape({ - link: PropTypes.string.isRequired, - title: PropTypes.string.isRequired, - li: PropTypes.object, - }) - ).isRequired, - className: PropTypes.string, -}; - -AUinpageNavLinks.defaultProps = { - title: 'Contents', - ariaLabel: 'in page navigation', -}; - - /** * The inpage-nav component * @@ -107,12 +47,33 @@ export const AUinpageNavSection = ({ title, link, children, level, headingClass, }; AUinpageNavSection.propTypes = { + /** + * + */ title: PropTypes.string.isRequired, + /** + * + */ link: PropTypes.string.isRequired, + /** + * The elements inside. + */ children: PropTypes.node.isRequired, + /** + * + */ level: PropTypes.oneOf([ '1', '2', '3', '4', '5', '6' ]).isRequired, + /** + * + */ headingClass: PropTypes.string, + /** + * + */ sectionLink: PropTypes.string, + /** + * The class name for the element, optional. + */ className: PropTypes.string, }; diff --git a/packages/inpage-nav/src/react/inpage-navLinks.js b/packages/inpage-nav/src/react/inpage-navLinks.js new file mode 100644 index 000000000..0915b6c78 --- /dev/null +++ b/packages/inpage-nav/src/react/inpage-navLinks.js @@ -0,0 +1,62 @@ +/*************************************************************************************************************************************************************** + * + * inpage-nav links function + * + * Use inpage-nav links to help users scan and jump to content of a page. + * +**************************************************************************************************************************************************************/ + + +import React from 'react'; +import PropTypes from 'prop-types'; + + +/** + * The inpage-nav component + * + * @param {boolean} dark - Add the dark variation class, optional + * @param {string} title - The title of the content link block, default: Contents + * @param {array} sections - An array of objects of all sections, sample: { link: '', title: '', onClick: () } + * @param {string} className - An additional class, optional + * @param {string} ariaLabel - The aria-label attribute, optional + * @param {object} attributeOptions - Any other attribute options + */ +export const AUinpageNavLinks = ({ dark, title, sections, ariaLabel, className = '', ...attributeOptions }) => ( + +); + +AUinpageNavLinks.propTypes = { + /** + * A dark variation of the component + */ + dark: PropTypes.bool, + /** + * + */ + title: PropTypes.string.isRequired, + /** + * + */ + sections: PropTypes.arrayOf( + PropTypes.shape({ + link: PropTypes.string.isRequired, + title: PropTypes.string.isRequired, + li: PropTypes.object, + }) + ).isRequired, + /** + * The class name for the element, optional. + */ + className: PropTypes.string, +}; + +AUinpageNavLinks.defaultProps = { + title: 'Contents', + ariaLabel: 'in page navigation', +}; diff --git a/packages/inpage-nav/src/react/inpage-navLinksItem.js b/packages/inpage-nav/src/react/inpage-navLinksItem.js new file mode 100644 index 000000000..a3c3f3cbd --- /dev/null +++ b/packages/inpage-nav/src/react/inpage-navLinksItem.js @@ -0,0 +1,41 @@ +/*************************************************************************************************************************************************************** + * + * inpage-nav links item function + * + * Use inpage-nav links to help users scan and jump to content of a page. + * +**************************************************************************************************************************************************************/ + + +import React from 'react'; +import PropTypes from 'prop-types'; + + +/** + * The section component for the AUinpageNavLinks component + * + * @param {object} link - The link of this section + * @param {object} title - The title of the section + * @param {object} li - An additional object to be spread into the wrapping element, optional + * @param {object} attributeOptions - Any other attribute options + */ +export const AUinpageNavLinksItem = ({ link, title, li = {}, ...attributeOptions }) => ( +
  • + { title } +
  • +); + +AUinpageNavLinksItem.propTypes = { + /** + * + */ + link: PropTypes.string.isRequired, + /** + * The title of the link + */ + title: PropTypes.string.isRequired, + /** + * + */ + li: PropTypes.object, +}; diff --git a/packages/keyword-list/package.json b/packages/keyword-list/package.json index 6426bb147..2111f5f9f 100644 --- a/packages/keyword-list/package.json +++ b/packages/keyword-list/package.json @@ -35,7 +35,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -52,11 +52,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/keyword-list/src/react/keyword-list.js b/packages/keyword-list/src/react/keyword-list.js new file mode 100644 index 000000000..1432fc302 --- /dev/null +++ b/packages/keyword-list/src/react/keyword-list.js @@ -0,0 +1,76 @@ +/*! [replace-name] v[replace-version] */ +/*************************************************************************************************************************************************************** + * + * keyword-list function + * + * Headers provide a consistent start to pages. + * +**************************************************************************************************************************************************************/ + +import React from 'react'; +import PropTypes from 'prop-types'; + + +// The following line will be replaced automatically with generic imports for the ES5 pipeline. +// You can safely ignore this bit if you use this module with pancake +// +// [replace-imports] + + +/** + * DEFAULT + * The keyword-list component + * + * @param {string} repeatedName - The repeated bit in each item + * @param {array} items - All items in this list, format: { link: '', name: '', onClick: () } + * @param {boolean} dark - Add the dark variation class, optional + * @param {string} className - An additional class, optional + * @param {string} linkComponent - The component used for the link + * @param {object} attributeOptions - Any other attribute options + */ +const AUkeywordList = ({ repeatedName, linkComponent, items, dark, className = '', ...attributeOptions }) => ( + +); + +AUkeywordList.propTypes = { + /** + * + */ + repeatedName: PropTypes.string.isRequired, + /** + * A dark variation of the component + */ + dark: PropTypes.bool, + /** + * + */ + items: PropTypes.arrayOf( + PropTypes.shape({ + link: PropTypes.string, + name: PropTypes.string.isRequired, + li: PropTypes.object, + }) + ).isRequired, + /** + * The class name for the element, optional. + */ + className: PropTypes.string, + /** + * + */ + linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]), +}; + + +AUkeywordList.defaultProps = { + linkComponent: 'a', +}; + + +export default AUkeywordList; diff --git a/packages/keyword-list/src/js/react.js b/packages/keyword-list/src/react/keyword-listItem.js similarity index 54% rename from packages/keyword-list/src/js/react.js rename to packages/keyword-list/src/react/keyword-listItem.js index cc7c791b5..c58c5e3bc 100644 --- a/packages/keyword-list/src/js/react.js +++ b/packages/keyword-list/src/react/keyword-listItem.js @@ -1,21 +1,16 @@ -/*! [replace-name] v[replace-version] */ /*************************************************************************************************************************************************************** * - * keyword-list function + * keyword-list item function * * Headers provide a consistent start to pages. * - **************************************************************************************************************************************************************/ +**************************************************************************************************************************************************************/ + import React from 'react'; import PropTypes from 'prop-types'; -// The following line will be replaced automatically with generic imports for the ES5 pipeline. -// You can safely ignore this bit if you use this module with pancake -// -// [replace-imports] - /** * An item inside the AUkeywordList component * @@ -61,10 +56,25 @@ export const AUkeywordListItem = ({ linkComponent, repeatedName, link, name, li }; AUkeywordListItem.propTypes = { + /** + * + */ repeatedName: PropTypes.string.isRequired, + /** + * + */ link: PropTypes.string, + /** + * + */ name: PropTypes.string.isRequired, + /** + * + */ li: PropTypes.object, + /** + * + */ linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]), }; @@ -72,47 +82,3 @@ AUkeywordListItem.propTypes = { AUkeywordListItem.defaultProps = { linkComponent: 'a', }; - - -/** - * DEFAULT - * The keyword-list component - * - * @param {string} repeatedName - The repeated bit in each item - * @param {array} items - All items in this list, format: { link: '', name: '', onClick: () } - * @param {boolean} dark - Add the dark variation class, optional - * @param {string} className - An additional class, optional - * @param {string} linkComponent - The component used for the link - * @param {object} attributeOptions - Any other attribute options - */ -const AUkeywordList = ({ repeatedName, linkComponent, items, dark, className = '', ...attributeOptions }) => ( - -); - -AUkeywordList.propTypes = { - repeatedName: PropTypes.string.isRequired, - dark: PropTypes.bool, - items: PropTypes.arrayOf( - PropTypes.shape({ - link: PropTypes.string, - name: PropTypes.string.isRequired, - li: PropTypes.object, - }) - ).isRequired, - className: PropTypes.string, - linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]), -}; - - -AUkeywordList.defaultProps = { - linkComponent: 'a', -}; - - -export default AUkeywordList; diff --git a/packages/link-list/package.json b/packages/link-list/package.json index 6d691ba2b..09f496b63 100644 --- a/packages/link-list/package.json +++ b/packages/link-list/package.json @@ -34,7 +34,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -51,11 +51,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/link-list/src/react/link-list.js b/packages/link-list/src/react/link-list.js new file mode 100644 index 000000000..7b49f1e32 --- /dev/null +++ b/packages/link-list/src/react/link-list.js @@ -0,0 +1,65 @@ +/*! [replace-name] v[replace-version] */ +/*************************************************************************************************************************************************************** + * + * link-lists function + * + * A simple list of inline links. + * + **************************************************************************************************************************************************************/ + +import React from 'react'; +import PropTypes from 'prop-types'; + + +// The following line will be replaced automatically with generic imports for the ES5 pipeline. +// You can safely ignore this bit if you use this module with pancake +// +// [replace-imports] + + +/** + * DEFAULT + * The Link List component + * + * @param {array} items - All items inside the link list to be passed to AUlinkListItem, format: { link: '', text: '', onClick: () } + * @param {string} className - An additional class, optional + * @param {string} linkComponent - The component used for the link + * @param {object} attributeOptions - Any other attribute options, optional + */ +const AUlinkList = ({ inline, items, linkComponent, className = '', ...attributeOptions }) => ( + +); + +AUlinkList.propTypes = { + /** + * + */ + inline: PropTypes.bool, + /** + * + */ + items: PropTypes.arrayOf( + PropTypes.shape({ + link: PropTypes.string, + text: PropTypes.node.isRequired, + li: PropTypes.object, + }) + ).isRequired, + /** + * + */ + linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]) +}; + +AUlinkList.defaultProps = { + linkComponent: "a", +}; + + +export default AUlinkList; diff --git a/packages/link-list/src/js/react.js b/packages/link-list/src/react/link-listItem.js similarity index 60% rename from packages/link-list/src/js/react.js rename to packages/link-list/src/react/link-listItem.js index 571b88bf8..abf9776fa 100644 --- a/packages/link-list/src/js/react.js +++ b/packages/link-list/src/react/link-listItem.js @@ -1,21 +1,16 @@ -/*! [replace-name] v[replace-version] */ /*************************************************************************************************************************************************************** * - * link-lists function + * link-lists item function * * A simple list of inline links. * **************************************************************************************************************************************************************/ + import React from 'react'; import PropTypes from 'prop-types'; -// The following line will be replaced automatically with generic imports for the ES5 pipeline. -// You can safely ignore this bit if you use this module with pancake -// -// [replace-imports] - /** * An item inside the AUlinkList component * @@ -61,52 +56,28 @@ export const AUlinkListItem = ({ text, link, linkComponent, li = {}, children, o }; AUlinkListItem.propTypes = { + /** + * + */ text: PropTypes.node.isRequired, + /** + * + */ link: PropTypes.string, + /** + * + */ li: PropTypes.object, + /** + * + */ onClick: PropTypes.object, + /** + * + */ linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]) }; AUlinkListItem.defaultProps = { linkComponent: "a", }; - - -/** - * DEFAULT - * The Link List component - * - * @param {array} items - All items inside the link list to be passed to AUlinkListItem, format: { link: '', text: '', onClick: () } - * @param {string} className - An additional class, optional - * @param {string} linkComponent - The component used for the link - * @param {object} attributeOptions - Any other attribute options, optional - */ -const AUlinkList = ({ inline, items, linkComponent, className = '', ...attributeOptions }) => ( - -); - -AUlinkList.propTypes = { - inline: PropTypes.bool, - items: PropTypes.arrayOf( - PropTypes.shape({ - link: PropTypes.string, - text: PropTypes.node.isRequired, - li: PropTypes.object, - }) - ).isRequired, - linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]) -}; - -AUlinkList.defaultProps = { - linkComponent: "a", -}; - - -export default AUlinkList; diff --git a/packages/main-nav/package.json b/packages/main-nav/package.json index c2356719b..81b0b1ced 100644 --- a/packages/main-nav/package.json +++ b/packages/main-nav/package.json @@ -31,7 +31,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -52,11 +52,11 @@ "path": "lib/js/module.js" }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-js": "~1", diff --git a/packages/main-nav/src/js/jquery.js b/packages/main-nav/src/jquery/jquery.js similarity index 100% rename from packages/main-nav/src/js/jquery.js rename to packages/main-nav/src/jquery/jquery.js diff --git a/packages/main-nav/src/react/main-nav.js b/packages/main-nav/src/react/main-nav.js new file mode 100644 index 000000000..6b4c9d333 --- /dev/null +++ b/packages/main-nav/src/react/main-nav.js @@ -0,0 +1,58 @@ +/*! [replace-name] v[replace-version] */ +/*************************************************************************************************************************************************************** + * + * mainNav function + * + * Horizontal list of links to key areas on the website. Usually located in the header. + * + **************************************************************************************************************************************************************/ + +import React from 'react'; +import PropTypes from 'prop-types'; + + +// The following line will be replaced automatically with generic imports for the ES5 pipeline. +// You can safely ignore this bit if you use this module with pancake +// +// [replace-imports] + + +const AUmainNav = ({ dark, alt, className, ariaLabel, children, ...attributeOptions }) => ( + +); + +AUmainNav.propTypes = { + /** + * A dark variation of the component + */ + dark: PropTypes.bool, + /** + * An alternate variation of the component + */ + alt: PropTypes.bool, + /** + * + */ + ariaLabel: PropTypes.string, + /** + * The elements inside. + */ + children: PropTypes.node.isRequired, +}; + +AUmainNav.defaultProps = { + ariaLabel: 'main', +}; + +export default AUmainNav; diff --git a/packages/main-nav/src/js/react.js b/packages/main-nav/src/react/main-navContent.js similarity index 83% rename from packages/main-nav/src/js/react.js rename to packages/main-nav/src/react/main-navContent.js index 685a5e1eb..7b3799b54 100644 --- a/packages/main-nav/src/js/react.js +++ b/packages/main-nav/src/react/main-navContent.js @@ -1,80 +1,17 @@ -/*! [replace-name] v[replace-version] */ /*************************************************************************************************************************************************************** * - * mainNav function + * mainNav content function * * Horizontal list of links to key areas on the website. Usually located in the header. * **************************************************************************************************************************************************************/ + import React from 'react'; import PropTypes from 'prop-types'; -import AU from '@gov.au/animate'; // interdependency with our animate lib - - -// ES5 dependency: import AUlinkList from '@gov.au/link-list'; -// ES6 dependency: import AUlinkList from './link-list'; - - -// The following line will be replaced automatically with generic imports for the ES5 pipeline. -// You can safely ignore this bit if you use this module with pancake -// -// [replace-imports] - - -/** - * A menu inside the AUmainNav - * - * @param {array} items - The links in an array containing text, location and active status - * @param {string} linkComponent - The component used for the link - */ -const AUmainNavMenu = ({ items, linkComponent }) => { - // Generate the menu - const GenerateMenu = ( items ) => { - const menu = items.map( item => { - const link = item.active ? { - link: item.link, - text: item.text, - 'aria-current': 'page', - li: { - className: 'active', - }, - } : - { - link: item.link, - text: item.text, - }; - - // return the link, maybe with children - return link; - }); - - return menu; - } - - // Create the menu with children - return ( - - ); -} - - -AUmainNavMenu.propTypes = { - items: PropTypes.arrayOf( - PropTypes.shape({ - link: PropTypes.string, - text: PropTypes.node.isRequired, - children: PropTypes.array, - }) - ).isRequired, - linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]), -}; - -AUmainNavMenu.defaultProps = { - linkComponent: 'a', -}; - +// ES5 dependency: import AU from '@gov.au/animate'; +// ES6 dependency: import AU from './animate'; // This value gets increased for each navigation component let IDvalue = 0; @@ -444,42 +381,40 @@ export class AUmainNavContent extends React.PureComponent { }; AUmainNavContent.propTypes = { + /** + * A dark variation of the component + */ dark: PropTypes.bool, + /** + * An alternate variation of the component + */ alt: PropTypes.bool, + /** + * + */ children: PropTypes.node, + /** + * + */ speed: PropTypes.number, + /** + * + */ onOpen: PropTypes.func, + /** + * + */ afterOpen: PropTypes.func, + /** + * + */ onClose: PropTypes.func, + /** + * + */ afterClose: PropTypes.func, + /** + * The class name for the element, optional. + */ className: PropTypes.string, }; - - -const AUmainNav = ({ dark, alt, className, ariaLabel, children, ...attributeOptions }) => ( - -); - -AUmainNav.propTypes = { - dark: PropTypes.bool, - alt: PropTypes.bool, - ariaLabel: PropTypes.string, - children: PropTypes.node.isRequired, -}; - -AUmainNav.defaultProps = { - ariaLabel: 'main', -}; - -export default AUmainNav; diff --git a/packages/main-nav/src/react/main-navMenu.js b/packages/main-nav/src/react/main-navMenu.js new file mode 100644 index 000000000..c765d31b1 --- /dev/null +++ b/packages/main-nav/src/react/main-navMenu.js @@ -0,0 +1,73 @@ +/*************************************************************************************************************************************************************** + * + * mainNav menu function + * + * Horizontal list of links to key areas on the website. Usually located in the header. + * + **************************************************************************************************************************************************************/ + + +import React from 'react'; +import PropTypes from 'prop-types'; + +// ES5 dependency: import AUaccordion from '@gov.au/link-list'; +// ES6 dependency: import AUlinkList from './link-list'; + + +/** + * A menu inside the AUmainNav + * + * @param {array} items - The links in an array containing text, location and active status + * @param {string} linkComponent - The component used for the link + */ +const AUmainNavMenu = ({ items, linkComponent }) => { + // Generate the menu + const GenerateMenu = ( items ) => { + const menu = items.map( item => { + const link = item.active ? { + link: item.link, + text: item.text, + 'aria-current': 'page', + li: { + className: 'active', + }, + } : + { + link: item.link, + text: item.text, + }; + + // return the link, maybe with children + return link; + }); + + return menu; + } + + // Create the menu with children + return ( + + ); +} + + +AUmainNavMenu.propTypes = { + /** + * + */ + items: PropTypes.arrayOf( + PropTypes.shape({ + link: PropTypes.string, + text: PropTypes.node.isRequired, + children: PropTypes.array, + }) + ).isRequired, + /** + * + */ + linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]), +}; + +AUmainNavMenu.defaultProps = { + linkComponent: 'a', +}; diff --git a/packages/page-alerts/package.json b/packages/page-alerts/package.json index 742f8a0fb..3a55460ef 100644 --- a/packages/page-alerts/package.json +++ b/packages/page-alerts/package.json @@ -38,7 +38,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -55,11 +55,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/page-alerts/src/js/react.js b/packages/page-alerts/src/react/page-alerts.js similarity index 88% rename from packages/page-alerts/src/js/react.js rename to packages/page-alerts/src/react/page-alerts.js index efb092d8e..8d7b0a1dc 100644 --- a/packages/page-alerts/src/js/react.js +++ b/packages/page-alerts/src/react/page-alerts.js @@ -57,10 +57,25 @@ const AUpageAlert = ({ as, alt, dark, children, className = '', ...attributeOpti ); AUpageAlert.propTypes = { + /** + * One of four kinds: 'info', 'success', 'warning', 'error'. + */ as: PropTypes.oneOf([ 'info', 'warning', 'error', 'success' ]).isRequired, + /** + * An alternate variation of the component. + */ alt: PropTypes.bool, + /** + * A dark variation of the component. + */ dark: PropTypes.bool, + /** + * Anything inside. + */ children: PropTypes.node.isRequired, + /** + * The class name for the element, optional. + */ className: PropTypes.string, }; diff --git a/packages/progress-indicator/package.json b/packages/progress-indicator/package.json index fb60e9a76..e74e3f59f 100644 --- a/packages/progress-indicator/package.json +++ b/packages/progress-indicator/package.json @@ -31,7 +31,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -48,11 +48,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/progress-indicator/src/react/progress-indicator.js b/packages/progress-indicator/src/react/progress-indicator.js new file mode 100644 index 000000000..b13224c5e --- /dev/null +++ b/packages/progress-indicator/src/react/progress-indicator.js @@ -0,0 +1,58 @@ +/*! [replace-name] v[replace-version] */ +/*************************************************************************************************************************************************************** + * + * progress-indicator function + * + * Indicator of progress through a multitude of pages mostly used for forms. + * + **************************************************************************************************************************************************************/ + +import React from 'react'; +import PropTypes from 'prop-types'; + + +// The following line will be replaced automatically with generic imports for the ES5 pipeline. +// You can safely ignore this bit if you use this module with pancake +// +// [replace-imports] + + +/** + * DEFAULT + * The progress-indicator component + * + * @param {boolean} dark - Add the dark variation class, optional + * @param {array} items - All items for this progress indicator + * @param {string} className - An additional class, optional + * @param {string} linkComponent - The component used for the link + * @param {object} attributeOptions - Any other attribute options + */ +const AUprogressIndicator = ({ dark, linkComponent, items, className = '', ...attributeOptions }) => ( +
      + { + items.map( + ( item, i ) => + ) + } +
    +); + +AUprogressIndicator.propTypes = { + dark: PropTypes.bool, + items: PropTypes.arrayOf( + PropTypes.shape({ + link: PropTypes.string, + text: PropTypes.string.isRequired, + status: PropTypes.PropTypes.oneOf([ 'doing', 'todo', 'done' ]).isRequired, + statusText: PropTypes.string, + li: PropTypes.object, + }) + ).isRequired, + linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]), +}; + +AUprogressIndicator.defaultProps = { + linkComponent: 'a', +}; + +export default AUprogressIndicator; diff --git a/packages/progress-indicator/src/js/react.js b/packages/progress-indicator/src/react/progress-indicatorItem.js similarity index 64% rename from packages/progress-indicator/src/js/react.js rename to packages/progress-indicator/src/react/progress-indicatorItem.js index 7af9bea16..d9f6d2742 100644 --- a/packages/progress-indicator/src/js/react.js +++ b/packages/progress-indicator/src/react/progress-indicatorItem.js @@ -1,21 +1,16 @@ -/*! [replace-name] v[replace-version] */ /*************************************************************************************************************************************************************** * - * progress-indicator function + * progress-indicator item function * * Indicator of progress through a multitude of pages mostly used for forms. * **************************************************************************************************************************************************************/ + import React from 'react'; import PropTypes from 'prop-types'; -// The following line will be replaced automatically with generic imports for the ES5 pipeline. -// You can safely ignore this bit if you use this module with pancake -// -// [replace-imports] - /** * All status options, can be overwritten * @@ -86,44 +81,3 @@ AUprogressIndicatorItem.propTypes = { AUprogressIndicatorItem.defaultProps = { linkComponent: 'a', }; - - -/** - * DEFAULT - * The progress-indicator component - * - * @param {boolean} dark - Add the dark variation class, optional - * @param {array} items - All items for this progress indicator - * @param {string} className - An additional class, optional - * @param {string} linkComponent - The component used for the link - * @param {object} attributeOptions - Any other attribute options - */ -const AUprogressIndicator = ({ dark, linkComponent, items, className = '', ...attributeOptions }) => ( -
      - { - items.map( - ( item, i ) => - ) - } -
    -); - -AUprogressIndicator.propTypes = { - dark: PropTypes.bool, - items: PropTypes.arrayOf( - PropTypes.shape({ - link: PropTypes.string, - text: PropTypes.string.isRequired, - status: PropTypes.PropTypes.oneOf([ 'doing', 'todo', 'done' ]).isRequired, - statusText: PropTypes.string, - li: PropTypes.object, - }) - ).isRequired, - linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]), -}; - -AUprogressIndicator.defaultProps = { - linkComponent: 'a', -}; - -export default AUprogressIndicator; diff --git a/packages/responsive-media/package.json b/packages/responsive-media/package.json index 228fe4eee..0ead8fd5e 100644 --- a/packages/responsive-media/package.json +++ b/packages/responsive-media/package.json @@ -37,7 +37,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, diff --git a/packages/select/package.json b/packages/select/package.json index c89c0952d..0f7e7e72c 100644 --- a/packages/select/package.json +++ b/packages/select/package.json @@ -33,7 +33,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -50,11 +50,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/select/src/js/react.js b/packages/select/src/react/select.js similarity index 79% rename from packages/select/src/js/react.js rename to packages/select/src/react/select.js index f31261cde..0fd4dd45b 100644 --- a/packages/select/src/js/react.js +++ b/packages/select/src/react/select.js @@ -17,24 +17,6 @@ import PropTypes from 'prop-types'; // [replace-imports] -/** - * An item inside the Select component - * - * @param {string} text - The text of this option - * @param {string} value - The value of this option - * @param {object} attributeOptions - Any other attribute options - */ -export const AUselectItem = ({ text, value, ...attributeOptions }) => ( - -); - -AUselectItem.propTypes = { - text: PropTypes.string.isRequired, - value: PropTypes.string.isRequired, - className: PropTypes.string, -}; - - /** * DEFAULT * The select component @@ -66,15 +48,30 @@ const AUselect = ({ dark, options, block, status, className = '', ...attributeOp }; AUselect.propTypes = { + /** + * A dark variation of the component + */ dark: PropTypes.bool, + /** + * + */ options: PropTypes.arrayOf( PropTypes.shape({ value: PropTypes.string.isRequired, text: PropTypes.string.isRequired, }) ).isRequired, + /** + * + */ block: PropTypes.bool, + /** + * + */ status: PropTypes.oneOf([ 'valid', 'invalid' ]), + /** + * The class name for the element, optional. + */ className: PropTypes.string, }; diff --git a/packages/select/src/react/selectItem.js b/packages/select/src/react/selectItem.js new file mode 100644 index 000000000..c52da1efd --- /dev/null +++ b/packages/select/src/react/selectItem.js @@ -0,0 +1,38 @@ +/*************************************************************************************************************************************************************** + * + * select item function + * + * The form select element for multiple options + * + **************************************************************************************************************************************************************/ + + +import React from 'react'; +import PropTypes from 'prop-types'; + + +/** + * An item inside the Select component + * + * @param {string} text - The text of this option + * @param {string} value - The value of this option + * @param {object} attributeOptions - Any other attribute options + */ +export const AUselectItem = ({ text, value, ...attributeOptions }) => ( + +); + +AUselectItem.propTypes = { + /** + * + */ + text: PropTypes.string.isRequired, + /** + * + */ + value: PropTypes.string.isRequired, + /** + * The class name for the element, optional. + */ + className: PropTypes.string, +}; diff --git a/packages/side-nav/package.json b/packages/side-nav/package.json index fce03221d..600155c15 100644 --- a/packages/side-nav/package.json +++ b/packages/side-nav/package.json @@ -31,7 +31,7 @@ "serve": "browser-sync tests --files 'tests/**/*.html, tests/**/*.css, tests/**/*.js'", "watch:js": "onchange 'src/js/*.js' -- npm run build:js", - "watch:jsx": "onchange 'src/js/react.js' 'tests/react/index.js' -- npm run build", + "watch:jsx": "onchange 'src/react/*.js' 'tests/react/index.js' -- npm run build", "watch:sass": "onchange 'src/sass/*.scss' 'tests/site/test.scss' -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -52,11 +52,11 @@ "path": "lib/js/module.js" }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-js": "~1", diff --git a/packages/side-nav/src/js/jquery.js b/packages/side-nav/src/jquery/jquery.js similarity index 100% rename from packages/side-nav/src/js/jquery.js rename to packages/side-nav/src/jquery/jquery.js diff --git a/packages/side-nav/src/js/react.js b/packages/side-nav/src/react/side-nav.js similarity index 76% rename from packages/side-nav/src/js/react.js rename to packages/side-nav/src/react/side-nav.js index 11f1bd96b..f67be3948 100644 --- a/packages/side-nav/src/js/react.js +++ b/packages/side-nav/src/react/side-nav.js @@ -10,8 +10,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -// ES5 dependency: import AUlinkList from '@gov.au/link-list'; -// ES6 dependency: import AUlinkList from './link-list'; // ES5 dependency: import AUaccordion from '@gov.au/accordion'; // ES6 dependency: import AUaccordion from './accordion'; @@ -22,43 +20,6 @@ import PropTypes from 'prop-types'; // [replace-imports] -/** - * A menu inside the AUsideNav - * - * @param {array} items - The links in an array containing text, location and active status - * @param {string} linkComponent - The component used for the link - */ -const AUsideNavMenu = ({ items, linkComponent }) => { - // Recursively re generate the menu with children as necessary - const GenerateMenu = ( items ) => { - const menu = items.map( item => { - const link = { - link: item.active ? '' : item.link, - text: item.active ? { item.text } : item.text, - li: { - className: item.active ? 'active' : '', - }, - }; - - // If it has children create a menu again - if( item.children ){ - link.children = - } - - // return the link, maybe with children - return link; - }); - - return menu; - } - - // Create the menu with children - return ( - - ); -} - - /** * DEFAULT * The side navigation component @@ -124,18 +85,57 @@ const AUsideNav = ({ ); AUsideNav.propTypes = { + /** + * A dark variation of the component. + */ dark: PropTypes.bool, + /** + * An alternate variation of the component. + */ alt: PropTypes.bool, + /** + * The headline of the accordion. + */ accordionHeader: PropTypes.string.isRequired, + /** + * A function executed when the accordion opens, optional. + */ onOpen: PropTypes.func, + /** + * A function executed after the accordion opens, optional. + */ afterOpen: PropTypes.func, + /** + * A function executed when the accordion closes, optional. + */ onClose: PropTypes.func, + /** + * A function executed after the accordion closes, optional. + */ afterClose: PropTypes.func, + /** + * The headline of the menu. + */ menuHeader: PropTypes.string, + /** + * The menu headers link. + */ menuHeaderLink: PropTypes.string, + /** + * Closed state, optional. + */ closed: PropTypes.bool, + /** + * Speed of the animation in ms, optional. + */ speed: PropTypes.number, + /** + * The component used for the child links, optional. + */ linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]), + /** + * The menu items. + */ items: PropTypes.arrayOf( PropTypes.shape({ link: PropTypes.string, @@ -143,7 +143,13 @@ AUsideNav.propTypes = { children: PropTypes.array, }) ).isRequired, + /** + * The class name for the element, optional. + */ className: PropTypes.string, + /** + * The aria-label attribute, defaults to "side navigation". + */ ariaLabel: PropTypes.string, }; diff --git a/packages/side-nav/src/react/side-navMenu.js b/packages/side-nav/src/react/side-navMenu.js new file mode 100644 index 000000000..e18783011 --- /dev/null +++ b/packages/side-nav/src/react/side-navMenu.js @@ -0,0 +1,50 @@ +/*************************************************************************************************************************************************************** + * + * sideNav menu function + * + * A vertical list of links for site navigation typically placed next to the body content. + * + **************************************************************************************************************************************************************/ + + +import React from 'react'; +import PropTypes from 'prop-types'; + +// ES5 dependency: import AUlinkList from '@gov.au/link-list'; +// ES6 dependency: import AUlinkList from './link-list'; + +/** + * A menu inside the AUsideNav + * + * @param {array} items - The links in an array containing text, location and active status + * @param {string} linkComponent - The component used for the link + */ +const AUsideNavMenu = ({ items, linkComponent }) => { + // Recursively re generate the menu with children as necessary + const GenerateMenu = ( items ) => { + const menu = items.map( item => { + const link = { + link: item.active ? '' : item.link, + text: item.active ? { item.text } : item.text, + li: { + className: item.active ? 'active' : '', + }, + }; + + // If it has children create a menu again + if( item.children ){ + link.children = + } + + // return the link, maybe with children + return link; + }); + + return menu; + } + + // Create the menu with children + return ( + + ); +} \ No newline at end of file diff --git a/packages/skip-link/package.json b/packages/skip-link/package.json index aed9a227d..32399a7cd 100644 --- a/packages/skip-link/package.json +++ b/packages/skip-link/package.json @@ -35,7 +35,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -52,11 +52,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/skip-link/src/js/react.js b/packages/skip-link/src/react/skip-link.js similarity index 94% rename from packages/skip-link/src/js/react.js rename to packages/skip-link/src/react/skip-link.js index c3bf965bb..df9c49167 100644 --- a/packages/skip-link/src/js/react.js +++ b/packages/skip-link/src/react/skip-link.js @@ -24,8 +24,17 @@ export const AUskipLinkItem = ({ link, text, className = '', ...attributeOptions ); AUskipLinkItem.propTypes = { + /** + * + */ link: PropTypes.string.isRequired, + /** + * + */ text: PropTypes.string.isRequired, + /** + * The class name for the element, optional. + */ className: PropTypes.string, }; @@ -50,12 +59,18 @@ const AUskipLink = ({ links, className = '', ariaLabel, ...attributeOptions }) = ); AUskipLink.propTypes = { + /** + * + */ links: PropTypes.arrayOf( PropTypes.shape({ link: PropTypes.string.isRequired, text: PropTypes.string.isRequired, }) ).isRequired, + /** + * + */ ariaLabel: PropTypes.string, }; diff --git a/packages/tags/package.json b/packages/tags/package.json index 5c3669664..b574d2f10 100644 --- a/packages/tags/package.json +++ b/packages/tags/package.json @@ -33,7 +33,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -50,11 +50,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/tags/src/js/react.js b/packages/tags/src/react/tags.js similarity index 90% rename from packages/tags/src/js/react.js rename to packages/tags/src/react/tags.js index cca0dae27..10adf4b99 100644 --- a/packages/tags/src/js/react.js +++ b/packages/tags/src/react/tags.js @@ -46,9 +46,21 @@ const AUtagItem = ({ link, linkComponent, text, li = {}, ...attributeOptions }) AUtagItem.propTypes = { + /** + * + */ link: PropTypes.string, + /** + * + */ text: PropTypes.string.isRequired, + /** + * + */ li: PropTypes.object, + /** + * + */ linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]), }; @@ -77,7 +89,13 @@ const AUtags = ({ dark, linkComponent, tags, className = '', ...attributeOptions ); AUtags.propTypes = { + /** + * A dark variation of the component. + */ dark: PropTypes.bool, + /** + * All tags inside a neat array. + */ tags: PropTypes.arrayOf( PropTypes.shape({ link: PropTypes.string, @@ -85,7 +103,13 @@ AUtags.propTypes = { li: PropTypes.object, }) ).isRequired, + /** + * The class name for the element, optional. + */ className: PropTypes.string, + /** + * The component used for the child links, optional. + */ linkComponent: PropTypes.oneOfType([ PropTypes.string, PropTypes.func ]), }; diff --git a/packages/text-inputs/package.json b/packages/text-inputs/package.json index a2190382d..fadd439ed 100644 --- a/packages/text-inputs/package.json +++ b/packages/text-inputs/package.json @@ -39,7 +39,7 @@ "serve": "browser-sync tests --files \"tests/**/*.html, tests/**/*.css, tests/**/*.js\"", "watch:js": "onchange \"src/js/*.js\" -- npm run build:js", - "watch:jsx": "onchange \"src/js/react.js\" \"tests/react/index.js\" -- npm run build", + "watch:jsx": "onchange \"src/react/*.js\" \"tests/react/index.js\" -- npm run build", "watch:sass": "onchange \"src/sass/*.scss\" \"tests/site/test.scss\" -- npm run build", "watch": "npm run build && npm-run-all --parallel serve watch:*" }, @@ -56,11 +56,11 @@ "sass-versioning": true }, "react": { - "path": "lib/js/react.js" + "path": "lib/react/react.js" } } }, - "main": "lib/js/react.es5.js", + "main": "lib/react/react.es5.js", "dependencies": { "@gov.au/pancake": "~1", "@gov.au/pancake-sass": "~2", diff --git a/packages/text-inputs/src/js/react.js b/packages/text-inputs/src/react/text-inputs.js similarity index 89% rename from packages/text-inputs/src/js/react.js rename to packages/text-inputs/src/react/text-inputs.js index bad27ccb0..e1888dd3a 100644 --- a/packages/text-inputs/src/js/react.js +++ b/packages/text-inputs/src/react/text-inputs.js @@ -55,11 +55,29 @@ const AUtextInput = ({ as, dark, block, status, width, type = 'text', className ); AUtextInput.propTypes = { + /** + * The kind of input, can be either 'input' or 'textarea', default: 'input'. + */ as: PropTypes.oneOf([ 'input', 'textarea' ]), + /** + * A dark variation of the component. + */ dark: PropTypes.bool, + /** + * Add the block variation class. + */ block: PropTypes.bool, + /** + * Mark this field as either 'valid' or 'invalid'. + */ status: PropTypes.oneOf([ 'valid', 'invalid' ]), + /** + * The class name for the element, optional. + */ className: PropTypes.string, + /** + * + */ width: PropTypes.oneOf([ 'xs', 'sm', 'md', 'lg', 'xl' ]) }; diff --git a/scripts/helper.js b/scripts/helper.js index d265935e1..a2da448a9 100644 --- a/scripts/helper.js +++ b/scripts/helper.js @@ -223,6 +223,7 @@ const HELPER = (() => { // constructor factory // Settings //-------------------------------------------------------------------------------------------------------------------------------------------------------------- NAME: PKG.name, + SHORTNAME: PKG.name.substring( 8 ), VERSION: PKG.version, DEPENDENCIES: PKG.peerDependencies, TEMPLATES: Path.normalize(`${ __dirname }/../.templates`), @@ -325,7 +326,7 @@ HELPER.precompile = (() => { */ readme: () => { const depTree = GetDepTree( HELPER.NAME ); - const prettyTree = `${ HELPER.NAME.substring( 8 ) }\n${ Treeify.asTree( depTree ) }`; + const prettyTree = `${ HELPER.SHORTNAME }\n${ Treeify.asTree( depTree ) }`; let readme = Fs.readFileSync( `./README.md`, `utf-8`); readme = readme.replace(/## Dependency graph\n\n```shell[\s\S]*?```/, `## Dependency graph\n\n\`\`\`shell\n${ prettyTree }\`\`\``); @@ -336,26 +337,43 @@ HELPER.precompile = (() => { js: () => { const _hasJS = Fs.existsSync( `${ process.cwd() }/src/js/module.js` ); - const _hasJquery = Fs.existsSync( `${ process.cwd() }/src/js/jquery.js` ); - const _hasReact = Fs.existsSync( `${ process.cwd() }/src/js/react.js` ); - - // 1. create path - if( _hasJS || _hasJquery || _hasReact ) { - CreateDir(`./lib/js/`); - } - + const _hasJquery = Fs.existsSync( `${ process.cwd() }/src/jquery/jquery.js` ); + const _hasReact = Fs.existsSync( `${ process.cwd() }/src/react/${ HELPER.SHORTNAME }.js` ); + // 2. copy files if( _hasJS ) { + CreateDir(`./lib/js/`); + CopyFile(`./src/js/module.js`, `./lib/js/module.js`); } if( _hasJquery ) { - CopyFile(`./src/js/jquery.js`, `./lib/js/jquery.js`); + CreateDir(`./lib/jquery/`); + + CopyFile(`./src/jquery/jquery.js`, `./lib/jquery/jquery.js`); } if( _hasReact ) { - CopyFile(`./src/js/react.js`, `./lib/js/react.js`); - CopyFile(`./src/js/react.js`, `./tests/react/${ HELPER.NAME.substring( 8 ) }.js`); + CreateDir( `./lib/react/` ); + + CopyFile( `./src/react/${ HELPER.SHORTNAME }.js`, `./lib/react/react.js` ); + + // Inject seperate react files into main component file + let reactFiles = Fs.readdirSync( `${ process.cwd() }/src/react/`, `utf-8` ) + // Remove the main component file from our list + .filter( item => item !== `${ HELPER.SHORTNAME }.js` ); + + reactFiles.forEach( item => { + let reactFile = `${ process.cwd() }/src/react/${ item }`; + let reactFileData = Fs.readFileSync( reactFile, `utf-8` ); + + reactFileData = reactFileData.replace( /^import React from (\'|\")react(\'|\");/gm, ''); + reactFileData = reactFileData.replace( /^import PropTypes from (\'|\")prop-types(\'|\");/gm, ''); + + Fs.appendFileSync( `${ process.cwd() }/lib/react/react.js`, reactFileData ); + }) + + CopyFile( `./lib/react/react.js`, `./tests/react/${ HELPER.SHORTNAME }.js` ); } // 3.replace strings inside new files in lib @@ -370,12 +388,12 @@ HELPER.precompile = (() => { } if( _hasJquery ) { - ReplaceFileContent( searches, `./lib/js/jquery.js` ); + ReplaceFileContent( searches, `./lib/jquery/jquery.js` ); } if( _hasReact ) { - ReplaceFileContent( searches, `./lib/js/react.js` ); - ReplaceFileContent( searches, `./tests/react/${ HELPER.NAME.substring( 8 ) }.js` ); + ReplaceFileContent( searches, `./lib/react/react.js` ); + ReplaceFileContent( searches, `./tests/react/${ HELPER.SHORTNAME }.js` ); } }, @@ -389,7 +407,7 @@ HELPER.precompile = (() => { * Compile and autoprefix Sass */ reactSass: () => { - if( Fs.existsSync(`${ process.cwd() }/lib/js/react.js`) ) { + if( Fs.existsSync(`${ process.cwd() }/lib/react/react.js`) ) { // 1. create directory CreateDir('./lib/css/'); @@ -406,11 +424,11 @@ HELPER.precompile = (() => { * Transpile react to es5, compile css file and include it into our react component */ react: () => { - if( Fs.existsSync(`${ process.cwd() }/lib/js/react.js`) ) { + if( Fs.existsSync(`${ process.cwd() }/lib/react/react.js`) ) { const reactOptions = { ast: false, - compact: true, minified: true, + comments: false, presets: [ `@babel/preset-env`, `@babel/preset-react` @@ -426,20 +444,20 @@ HELPER.precompile = (() => { }; // 1. Copy files - CopyFile('./src/js/react.js', './lib/js/react.es5.js'); + CopyFile('./lib/react/react.js', './lib/react/react.es5.js'); // 2. Replace the comment with an import statement - ReplaceFileContent( searches, `${ process.cwd() }/lib/js/react.es5.js` ); + ReplaceFileContent( searches, `${ process.cwd() }/lib/react/react.es5.js` ); // 3. Compile /lib/react.js to react.es5.js - Babel.transformFile( `./lib/js/react.es5.js`, reactOptions, ( error, result ) => { + Babel.transformFile( `./lib/react/react.js`, reactOptions, ( error, result ) => { if( error ) { - HELPER.log.error(`We encountered an error when transpiling the react file in ${ Chalk.yellow( `${ process.cwd() }/lib/js/react.es5.js` ) }`); + HELPER.log.error(`We encountered an error when transpiling the react file in ${ Chalk.yellow( `${ process.cwd() }/lib/react/react.es5.js` ) }`); HELPER.log.error( error ); } else { - Fs.writeFileSync( `./lib/js/react.es5.js`, result.code ); - Fs.writeFileSync( `./lib/js/react.es5.js.map`, JSON.stringify( result.map, null, 2 ) ); + Fs.writeFileSync( `./lib/react/react.es5.js`, result.code ); + Fs.writeFileSync( `./lib/react/react.es5.js.map`, JSON.stringify( result.map, null, 2 ) ); } }); } @@ -528,13 +546,18 @@ HELPER.compile = (() => { let code = ''; dependencies.forEach( dependency => { - if( Fs.existsSync( Path.normalize(`${ process.cwd() }/../${ dependency }${ from }`) ) ) { - const fileLocation = Path.normalize(`${ to }/${ dependency }.js`); + const fileLocation = Path.normalize(`${ to }/${ dependency }.js`); + if( Fs.existsSync( Path.normalize(`${ process.cwd() }/../${ dependency }${ from }`) ) ) { CopyFile( Path.normalize(`${ process.cwd() }/../${ dependency }${ from }`), `.${ fileLocation }` ); HELPER.log.success(`Written file ${ Chalk.yellow( `.${ fileLocation }` ) }`); } + else if( dependency == 'animate' ) { + CopyFile( Path.normalize(`${ process.cwd() }/../${ dependency }/lib/js/module.js`), `.${ fileLocation }` ); + + HELPER.log.success(`WARNING: Writing custom JS file 'animate' ${ Chalk.yellow( `.${ fileLocation }` ) } `); + } }); } @@ -579,11 +602,11 @@ HELPER.compile = (() => { getAllJs( '/lib/js/module.js', '/tests/site/script.js' ); // get all js for jquery.js - getAllJs( '/lib/js/jquery.js', '/tests/jquery/jquery.js' ); + getAllJs( '/lib/jquery/jquery.js', '/tests/jquery/jquery.js' ); getAllJs( '/lib/js/module.js', '/tests/jquery/script.js' ); // get all react scripts - getAllReact( '/lib/js/react.js', '/tests/react/' ); + getAllReact( `/lib/react/react.js`, '/tests/react/' ); }, img: () => { @@ -948,8 +971,8 @@ HELPER.test = (() => { const packagesPKG = require( Path.normalize(`${ __dirname }/../packages/${ module }/package.json`) ); const hasSass = Fs.existsSync( Path.normalize(`${ __dirname }/../packages/${ module }/src/sass/_module.scss`) ); const hasJS = Fs.existsSync( Path.normalize(`${ __dirname }/../packages/${ module }/src/js/module.js`) ); - const hasReact = Fs.existsSync( Path.normalize(`${ __dirname }/../packages/${ module }/src/js/react.js`) ); - // const hasJQuery = Fs.existsSync( Path.normalize(`${ __dirname }/../packages/${ module }/src/js/jquery.js`) ); + const hasReact = Fs.existsSync( Path.normalize( `${ __dirname }/../packages/${ module }/src/react/${ HELPER.SHORTNAME }.js` ) ); + // const hasJQuery = Fs.existsSync( Path.normalize(`${ __dirname }/../packages/${ module }/src/jquery/jquery.js`) ); // testing lifecycle script if( packagesPKG.scripts.postinstall !== 'pancake' ) { @@ -970,7 +993,8 @@ HELPER.test = (() => { error += `The module ${ module } is missing the "build:react" script.\n`; } - if( hasReact && !packagesPKG.scripts['build'].includes('npm run build:react') ) { + // If we isolate a component like this again we need to refactor. + if( hasReact && module !== 'form' && !packagesPKG.scripts['build'].includes('npm run build:react' ) ) { error += `The module ${ module } is missing the "build:react" task inside the build script.\n`; } @@ -1184,7 +1208,7 @@ HELPER.init = () => { if( process.argv.indexOf( 'precompile' ) !== -1 ) { - CFonts.say( `Precompile ${ PKG.name.substring( 8 ) }`, { + CFonts.say( `Precompile ${ HELPER.SHORTNAME }`, { font: 'chrome', space: false, colors: ['red', 'magenta', 'blue'], @@ -1201,7 +1225,7 @@ HELPER.init = () => { if( process.argv.indexOf( 'compile' ) !== -1 ) { - CFonts.say( `Compiling ${ PKG.name.substring( 8 ) }`, { + CFonts.say( `Compiling ${ HELPER.SHORTNAME }`, { font: 'chrome', space: false, colors: ['red', 'magenta', 'blue'],