Skip to content

Commit

Permalink
Merge pull request #2 from jadu/feature/xfp-compatibility
Browse files Browse the repository at this point in the history
Changes to ensure library is compatible with XFP
  • Loading branch information
Stanton authored Oct 27, 2020
2 parents f80cc34 + 23a0e2c commit b6ac4c7
Show file tree
Hide file tree
Showing 28 changed files with 12,354 additions and 8,907 deletions.
20,713 changes: 11,874 additions & 8,839 deletions package-lock.json

Large diffs are not rendered by default.

37 changes: 27 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,40 @@
},
"keywords": [],
"author": "",
"browserify": {
"transform": [
[
"babelify",
{
"presets": [
"es2015",
"es2017",
"react",
"stage-0"
]
}
]
]
},
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/preset-env": "^7.9.5",
"@babel/preset-react": "^7.9.4",
"babel-core": "^6.24.0",
"babel-jest": "^26.0.1",
"babel-loader": "^8.1.0",
"babel-loader": "^6.1.0",
"babel-plugin-transform-class-properties": "^6.24.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.0",
"babel-preset-react": "^6.24.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"enzyme-to-json": "^3.4.4",
"html-webpack-plugin": "^4.2.0",
"html-webpack-plugin": "^2.3.0",
"jadu-pulsar": "^10.3.1",
"jest": "^26.0.1",
"react-test-renderer": "^16.13.1",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
"webpack": "^2.0",
"webpack-cli": "^1.0",
"webpack-dev-server": "^2.0"
},
"dependencies": {
"classnames": "^2.2.6",
Expand All @@ -36,7 +52,8 @@
},
"babel": {
"plugins": [
"@babel/plugin-proposal-class-properties"
"babel-plugin-transform-object-rest-spread",
"babel-plugin-transform-class-properties"
]
},
"jest": {
Expand Down
11 changes: 10 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import Button from './components/html/Button';
import Button from './components/html/Button/Button';

import ButtonGroupItem from './components/form/ButtonGroupItem/ButtonGroupItem';
import Checkbox from './components/form/Checkbox/Checkbox';
Expand All @@ -15,6 +15,7 @@ import Fieldset from './components/form/Fieldset/Fieldset';
import FileInput from './components/form/FileInput/FileInput';
import InlineCheckbox from './components/form/InlineCheckbox/InlineCheckbox';
import InlineRadioButton from './components/form/InlineRadioButton/InlineRadioButton';
import InputGroup from './components/form/InputGroup/InputGroup';
import PasswordInput from './components/form/PasswordInput/PasswordInput';
import RangeInput from './components/form/RangeInput/RangeInput';
import RadioButton from './components/form/RadioButton/RadioButton';
Expand Down Expand Up @@ -101,6 +102,14 @@ export default class App extends React.Component {
<TextInput />
</FormGroup>

<FormGroup labelText="Append Button">
<InputGroup>
<Button>Prepended</Button>
<TextInput />
<Button>Appended</Button>
</InputGroup>
</FormGroup>

<FormGroup labelText="Textarea">
<TextArea></TextArea>
</FormGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/components/form/ButtonGroupItem/ButtonGroupItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class ButtonGroupItem extends React.Component {
let inputClassName = classnames(className, type);

return (
<>
<React.Fragment>
<input
className={inputClassName}
id={id ? id : idGuid}
Expand All @@ -37,7 +37,7 @@ export default class ButtonGroupItem extends React.Component {
>
{children}
</FormLabel>
</>
</React.Fragment>
);
}
}
24 changes: 17 additions & 7 deletions src/components/form/FormGroup/FormGroup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default class FormGroup extends React.Component {

static defaultProps = {
className: 'form__group',
guid: shortid.generate(),
required: false
};

Expand All @@ -32,6 +31,7 @@ export default class FormGroup extends React.Component {
error,
flushLabel,
helpText,
hideLabel,
indented,
inline,
inlineCheckbox,
Expand Down Expand Up @@ -69,14 +69,16 @@ export default class FormGroup extends React.Component {
'has-error': error
});

let guid = this.props.guid || shortid.generate();

// GUID to use if no explicit ID has been set
let idGuid = 'id-guid-' + this.props.guid;
let idGuid = 'id-guid-' + guid;

// GUID to use to link the input with any help text
let helpGuid = 'help-guid-' + this.props.guid;
let helpGuid = 'help-guid-' + guid;

// GUID to use to link the input with any errors
let errorGuid = 'error-guid-' + this.props.guid;
let errorGuid = 'error-guid-' + guid;

// Build list of IDs for the input based on the presence of help/error text
let ariaDescribedby = classnames({
Expand All @@ -88,9 +90,13 @@ export default class FormGroup extends React.Component {
let childrenWithGuids = React.Children.map(
children,
(child, i) => {
if (['div', 'p'].indexOf(child.type) !== -1) {
return child;
}

return React.cloneElement(child, {
ariaDescribedby: ariaDescribedby ? ariaDescribedby : null,
idGuid: idGuid
id: idGuid
});
}
);
Expand All @@ -102,7 +108,7 @@ export default class FormGroup extends React.Component {

// Form controls
let inputBlock = (
<>{childrenWithGuids}</>
<React.Fragment>{childrenWithGuids}</React.Fragment>
);

// Wrap with input group if appended/prepended text is present
Expand Down Expand Up @@ -136,13 +142,17 @@ export default class FormGroup extends React.Component {
// Standard group markup strategy for most components
let groupBlock = (
<div className={variantClasses}>
{labelText &&
<FormLabel
required={required}
idGuid={idGuid}
tag={controls ? 'span' : 'label'}
hideLabel={hideLabel}
>
{labelText}
</FormLabel>
}

{controlsBlock}
</div>
);
Expand Down Expand Up @@ -185,7 +195,7 @@ export default class FormGroup extends React.Component {
}

return (
<>{groupBlock}</>
<React.Fragment>{groupBlock}</React.Fragment>
);
}
}
36 changes: 18 additions & 18 deletions src/components/form/FormGroup/FormGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ it('should return null if no children', () => {
it('should render the basic form group', () => {
const tree = render(
<FormGroup>
<>foo</>
<React.Fragment>foo</React.Fragment>
</FormGroup>
);
expect(tree).toMatchSnapshot();
Expand All @@ -24,7 +24,7 @@ it('should render the basic form group', () => {
it('should add the button group classes if using buttonGroup variant', () => {
const tree = shallow(
<FormGroup buttonGroup>
<>foo</>
<React.Fragment>foo</React.Fragment>
</FormGroup>
);
expect(tree).toMatchSnapshot();
Expand All @@ -33,7 +33,7 @@ it('should add the button group classes if using buttonGroup variant', () => {
it('should use fieldset strategy if using choiceGroup variant', () => {
const tree = shallow(
<FormGroup choiceGroup>
<>foo</>
<React.Fragment>foo</React.Fragment>
</FormGroup>
);
expect(tree).toMatchSnapshot();
Expand All @@ -42,7 +42,7 @@ it('should use fieldset strategy if using choiceGroup variant', () => {
it('should add the indented class if using indented variant', () => {
const tree = shallow(
<FormGroup indented>
<>foo</>
<React.Fragment>foo</React.Fragment>
</FormGroup>
);
expect(tree).toMatchSnapshot();
Expand All @@ -51,7 +51,7 @@ it('should add the indented class if using indented variant', () => {
it('should use toggle strategy if using toggle variant', () => {
const tree = shallow(
<FormGroup toggle>
<>foo</>
<React.Fragment>foo</React.Fragment>
</FormGroup>
);
expect(tree).toMatchSnapshot();
Expand All @@ -60,7 +60,7 @@ it('should use toggle strategy if using toggle variant', () => {
it('should add the top label class if using topLabel variant', () => {
const tree = shallow(
<FormGroup topLabel>
<>foo</>
<React.Fragment>foo</React.Fragment>
</FormGroup>
);
expect(tree).toMatchSnapshot();
Expand All @@ -69,7 +69,7 @@ it('should add the top label class if using topLabel variant', () => {
it('should add the flush label class if using flushLabel variant', () => {
const tree = shallow(
<FormGroup flushLabel>
<>foo</>
<React.Fragment>foo</React.Fragment>
</FormGroup>
);
expect(tree).toMatchSnapshot();
Expand All @@ -78,7 +78,7 @@ it('should add the flush label class if using flushLabel variant', () => {
it('should add the checkbox class if using checkbox variant', () => {
const tree = shallow(
<FormGroup checkbox>
<>foo</>
<React.Fragment>foo</React.Fragment>
</FormGroup>
);
expect(tree).toMatchSnapshot();
Expand All @@ -87,7 +87,7 @@ it('should add the checkbox class if using checkbox variant', () => {
it('should use inline strategy if using inlineCheckbox variant', () => {
const tree = shallow(
<FormGroup inlineCheckbox>
<>foo</>
<React.Fragment>foo</React.Fragment>
</FormGroup>
);
expect(tree).toMatchSnapshot();
Expand All @@ -96,7 +96,7 @@ it('should use inline strategy if using inlineCheckbox variant', () => {
it('should use inline strategy if using inlineRadioButton variant', () => {
const tree = shallow(
<FormGroup inlineRadioButton>
<>foo</>
<React.Fragment>foo</React.Fragment>
</FormGroup>
);
expect(tree).toMatchSnapshot();
Expand All @@ -105,7 +105,7 @@ it('should use inline strategy if using inlineRadioButton variant', () => {
it('should add the radio class if using radio variant', () => {
const tree = shallow(
<FormGroup radioButton>
<>foo</>
<React.Fragment>foo</React.Fragment>
</FormGroup>
);
expect(tree).toMatchSnapshot();
Expand All @@ -114,7 +114,7 @@ it('should add the radio class if using radio variant', () => {
it('should add the success class if using success variant', () => {
const tree = shallow(
<FormGroup success>
<>foo</>
<React.Fragment>foo</React.Fragment>
</FormGroup>
);
expect(tree).toMatchSnapshot();
Expand All @@ -123,7 +123,7 @@ it('should add the success class if using success variant', () => {
it('should add the changed class if using changed variant', () => {
const tree = shallow(
<FormGroup changed>
<>foo</>
<React.Fragment>foo</React.Fragment>
</FormGroup>
);
expect(tree).toMatchSnapshot();
Expand All @@ -132,7 +132,7 @@ it('should add the changed class if using changed variant', () => {
it('should add the warning class if using warning variant', () => {
const tree = shallow(
<FormGroup warning>
<>foo</>
<React.Fragment>foo</React.Fragment>
</FormGroup>
);
expect(tree).toMatchSnapshot();
Expand All @@ -141,7 +141,7 @@ it('should add the warning class if using warning variant', () => {
it('should add the error class if using error variant', () => {
const tree = shallow(
<FormGroup error="error message">
<>foo</>
<React.Fragment>foo</React.Fragment>
</FormGroup>
);
expect(tree).toMatchSnapshot();
Expand All @@ -150,7 +150,7 @@ it('should add the error class if using error variant', () => {
it('should prepend text', () => {
const tree = shallow(
<FormGroup prependText="prepended">
<>foo</>
<React.Fragment>foo</React.Fragment>
</FormGroup>
);
expect(tree).toMatchSnapshot();
Expand All @@ -159,7 +159,7 @@ it('should prepend text', () => {
it('should append text', () => {
const tree = shallow(
<FormGroup appendText="appended">
<>foo</>
<React.Fragment>foo</React.Fragment>
</FormGroup>
);
expect(tree).toMatchSnapshot();
Expand All @@ -168,7 +168,7 @@ it('should append text', () => {
it('should append and prepend text', () => {
const tree = shallow(
<FormGroup prependText="prepended" appendText="appended">
<>foo</>
<React.Fragment>foo</React.Fragment>
</FormGroup>
);
expect(tree).toMatchSnapshot();
Expand Down
4 changes: 2 additions & 2 deletions src/components/form/FormLabel/FormLabel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class FormLabel extends React.Component {
);

return (
<>
<React.Fragment>
{children ? (
<LabelTag
htmlFor={htmlFor ? htmlFor : idGuid}
Expand All @@ -44,7 +44,7 @@ export default class FormLabel extends React.Component {
: (
<span className="control__label"></span>
)}
</>
</React.Fragment>
);
}
}
Loading

0 comments on commit b6ac4c7

Please sign in to comment.