Skip to content

Commit

Permalink
Whitespace / marginBottom hoc (#185)
Browse files Browse the repository at this point in the history
new spacing HOC

- changed name to `withWhiteSpace`
- uses a range of 0-9  margin values (for each small and large screen) based on GDS spacing values
- updated components to be allow recomposing via glamorous

also fixed
- position: duabs (don't know how this got back in there again?)
- widths on unordered/ordered lists
- changed icon colours to black in storybook
- removed floats on radio/checkbox
  • Loading branch information
marksy authored and penx committed Apr 5, 2018
1 parent a078751 commit 139b600
Show file tree
Hide file tree
Showing 45 changed files with 365 additions and 95 deletions.
6 changes: 4 additions & 2 deletions components/back-link/src/index.js
Expand Up @@ -45,8 +45,8 @@ const Anchor = glamorous.button({
},
});

const BackLink = ({ children, goBack }) => (
<Anchor onClick={goBack}>{children}</Anchor>
const BackLink = ({ children, className, goBack }) => (
<Anchor className={className} onClick={goBack}>{children}</Anchor>
);

BackLink.propTypes = {
Expand All @@ -58,10 +58,12 @@ BackLink.propTypes = {
* A function that is called on click
*/
goBack: PropTypes.func, // TODO: rename onClick
className: PropTypes.string,
};

BackLink.defaultProps = {
goBack: undefined,
className: undefined,
};

export default BackLink;
9 changes: 7 additions & 2 deletions components/breadcrumb/src/index.js
Expand Up @@ -66,8 +66,8 @@ const BreadcrumbListItem = glamorous.li({
});

// TODO use Context API https://github.com/reactjs/rfcs/blob/master/text/0002-new-version-of-context.md
const Breadcrumb = ({ children, ...props }) => (
<BreadcrumbContainer {...props}>
const Breadcrumb = ({ children, className, ...props }) => (
<BreadcrumbContainer className={className} {...props}>
<BreadcrumbList>
{children.length && children.map ? (
children.map((child, i) => (
Expand All @@ -82,11 +82,16 @@ const Breadcrumb = ({ children, ...props }) => (
</BreadcrumbContainer>
);

Breadcrumb.defaultProps = {
className: undefined,
};

Breadcrumb.propTypes = {
/**
* Generally a series of anchors or Link components
*/
children: PropTypes.node.isRequired,
className: PropTypes.string,
};

export default Breadcrumb;
1 change: 0 additions & 1 deletion components/button/src/__snapshots__/test.js.snap
Expand Up @@ -16,7 +16,6 @@ exports[`button matches wrapper snapshot: wrapper mount 1`] = `
outline-offset: -1px;
outline: 1px solid transparent;
padding: .526315em .789473em .263157em;
position: duabs;
text-decoration: none;
-webkit-appearance: none;
-webkit-font-smoothing: antialiased;
Expand Down
10 changes: 8 additions & 2 deletions components/button/src/index.js
Expand Up @@ -6,6 +6,7 @@
// https://github.com/alphagov/govuk_elements/blob/master/packages/govuk-elements-sass/public/sass/elements/_buttons.scss

import glamorous from 'glamorous';
import PropTypes from 'prop-types';
import React from 'react';

import {
Expand All @@ -30,7 +31,6 @@ const GButton = glamorous.button(
outlineOffset: '-1px',
outline: '1px solid transparent',
padding: '.526315em .789473em .263157em',
position: 'duabs',
textDecoration: 'none',
WebkitAppearance: 'none',
WebkitFontSmoothing: 'antialiased',
Expand All @@ -57,9 +57,15 @@ const GButton = glamorous.button(
);

// TODO: start and iconUrl props
const Button = props => <GButton {...props} />;
const Button = ({ className, ...props }) => <GButton className={className} {...props} />;

Button.propTypes = {
className: PropTypes.string,
children: PropTypes.node,
};

Button.defaultProps = {
className: undefined,
children: 'Button',
};

Expand Down
3 changes: 0 additions & 3 deletions components/checkbox/src/__snapshots__/test.js.snap
Expand Up @@ -4,11 +4,8 @@ exports[`Checkbox matches wrapper snapshot: wrapper mount 1`] = `
.glamor-2,
[data-glamor-2] {
display: block;
float: left;
clear: left;
position: relative;
padding: 0 0 0 38px;
margin-bottom: 10px;
}
.glamor-0,
Expand Down
14 changes: 9 additions & 5 deletions components/checkbox/src/index.js
Expand Up @@ -8,11 +8,8 @@ import { YELLOW, BLACK } from 'govuk-colours';

const CheckboxWrapper = glamorous.label({
display: 'block',
float: 'left',
clear: 'left',
position: 'relative',
padding: '0 0 0 38px',
marginBottom: '10px',
});

const Input = glamorous.input({
Expand Down Expand Up @@ -80,19 +77,26 @@ const Label = glamorous.span({
},
});

const Checkbox = ({ children, inline, ...input }) => (
<CheckboxWrapper inline={inline}>
const Checkbox = ({
children,
className,
inline,
...input
}) => (
<CheckboxWrapper className={className} inline={inline}>
<Input type="checkbox" {...input} />
<Label>{children}</Label>
</CheckboxWrapper>
);

Checkbox.defaultProps = {
className: undefined,
inline: undefined,
};

Checkbox.propTypes = {
children: PropTypes.node.isRequired,
className: PropTypes.string,
inline: PropTypes.bool,
};

Expand Down
1 change: 0 additions & 1 deletion components/date-input/src/__snapshots__/test.js.snap
Expand Up @@ -144,7 +144,6 @@ exports[`DateInput matches wrappersnapshot: wrapper mount 1`] = `
<DateInput
errorText="example"
hintText={null}
>
<glamorous(div)
errorText="example"
Expand Down
10 changes: 6 additions & 4 deletions components/date-input/src/index.js
Expand Up @@ -71,8 +71,8 @@ const ListParent = glamorous.div({
},
});

const DateInput = ({ children, ...props }) => (
<LabelWrapper errorText={props.errorText}>
const DateInput = ({ children, className, ...props }) => (
<LabelWrapper className={className} errorText={props.errorText}>
<LabelText errorText={props.errorText}>{children}</LabelText>
{props.hintText ? <HintText>{props.hintText}</HintText> : <span />}
{props.errorText ? (
Expand All @@ -98,12 +98,14 @@ const DateInput = ({ children, ...props }) => (
);

DateInput.defaultProps = {
hintText: null,
errorText: null,
className: undefined,
hintText: undefined,
errorText: undefined,
};

DateInput.propTypes = {
children: PropTypes.node.isRequired,
className: PropTypes.string,
hintText: PropTypes.string,
errorText: PropTypes.string,
};
Expand Down
Expand Up @@ -16,7 +16,6 @@ exports[`DocumentFooterMetadata matches snapshot: enzyme.mount 1`] = `
text-transform: none;
font-size: 14px;
line-height: 1.1428571429;
width: 100%;
list-style-type: none;
margin-left: 0;
}
Expand Down
4 changes: 0 additions & 4 deletions components/file-upload/src/__snapshots__/test.js.snap
Expand Up @@ -73,8 +73,6 @@ exports[`FileUpload matches snapshot: enzyme.mount 1`] = `
}
<FileUpload
acceptedFormats={null}
hint={null}
meta={Object {}}
>
<Label>
Expand All @@ -92,11 +90,9 @@ exports[`FileUpload matches snapshot: enzyme.mount 1`] = `
</glamorous(span)>
</LabelText>
<glamorous(input)
accept={null}
type="file"
>
<input
accept={null}
className="glamor-1"
type="file"
/>
Expand Down
10 changes: 6 additions & 4 deletions components/file-upload/src/index.js
Expand Up @@ -30,9 +30,9 @@ const Input = glamorous.input({
});

const FileUpload = ({
meta, children, hint, acceptedFormats,
meta, children, hint, acceptedFormats, className,
}) => (
<Label error={meta.error}>
<Label className={className} error={meta.error}>
<LabelText error={meta.error}>{children}</LabelText>
{hint && <HintText>{hint}</HintText>}
{meta.touched && meta.error && <ErrorText>{meta.error}</ErrorText>}
Expand All @@ -41,9 +41,10 @@ const FileUpload = ({
);

FileUpload.defaultProps = {
hint: null,
hint: undefined,
meta: {},
acceptedFormats: null,
acceptedFormats: undefined,
className: undefined,
};

FileUpload.propTypes = {
Expand All @@ -65,6 +66,7 @@ FileUpload.propTypes = {
}),
children: PropTypes.node.isRequired,
acceptedFormats: PropTypes.string,
className: PropTypes.string,
};

export default FileUpload;
6 changes: 4 additions & 2 deletions components/input-field/src/index.js
Expand Up @@ -11,9 +11,9 @@ import HintText from '@govuk-react/hint-text';
import Input from '@govuk-react/input';

const InputField = ({
meta, children, hint, input,
meta, children, hint, input, className,
}) => (
<Label error={meta.touched && meta.error}>
<Label className={className} error={meta.touched && meta.error}>
<LabelText>{children}</LabelText>
{hint && <HintText>{hint}</HintText>}
{meta.touched && meta.error && <ErrorText>{meta.error}</ErrorText>}
Expand All @@ -25,6 +25,7 @@ InputField.defaultProps = {
hint: null,
input: {},
meta: {},
className: undefined,
};

InputField.propTypes = {
Expand Down Expand Up @@ -52,6 +53,7 @@ InputField.propTypes = {
visited: PropTypes.bool,
}),
children: PropTypes.node.isRequired,
className: PropTypes.string,
};

export default InputField;
11 changes: 10 additions & 1 deletion components/label/src/index.js
Expand Up @@ -2,6 +2,7 @@

import glamorous from 'glamorous';
import React from 'react';
import PropTypes from 'prop-types';

import { ERROR_COLOUR } from 'govuk-colours';
import { MEDIA_QUERIES, SITE_WIDTH, SPACING } from '@govuk-react/constants';
Expand All @@ -28,6 +29,14 @@ const GLabel = glamorous.label(
}),
);

const Label = props => <GLabel {...props} />;
const Label = ({ className, ...props }) => (<GLabel className={className} {...props} />);

Label.defaultProps = {
className: undefined,
};

Label.propTypes = {
className: PropTypes.string,
};

export default Label;
9 changes: 8 additions & 1 deletion components/list-item/src/index.js
Expand Up @@ -23,10 +23,17 @@ const GListItem = glamorous.li({
},
});

const ListItem = ({ children }) => <GListItem>{children}</GListItem>;
const ListItem = ({ children, className }) => (
<GListItem className={className}>{children}</GListItem>
);

ListItem.defaultProps = {
className: undefined,
};

ListItem.propTypes = {
children: PropTypes.node.isRequired,
className: PropTypes.string,
};

export default ListItem;
1 change: 0 additions & 1 deletion components/list-navigation/src/__snapshots__/test.js.snap
Expand Up @@ -21,7 +21,6 @@ exports[`ListNavigation matches wrapper snapshot: wrapper mount 1`] = `
text-transform: none;
font-size: 14px;
line-height: 1.1428571429;
width: 100%;
list-style-type: square;
}
Expand Down
6 changes: 4 additions & 2 deletions components/list-navigation/src/index.js
Expand Up @@ -7,8 +7,8 @@ import UnorderedList from '@govuk-react/unordered-list';
import ListItem from '@govuk-react/list-item';

// TODO use Context API https://github.com/reactjs/rfcs/blob/master/text/0002-new-version-of-context.md
const ListNavigation = ({ children, listStyleType }) => (
<UnorderedList listStyleType={listStyleType}>
const ListNavigation = ({ children, className, listStyleType }) => (
<UnorderedList className={className} listStyleType={listStyleType}>
{children.length && children.map ? (
children.map((child, i) => (
<ListItem key={child.key || i}>{child}</ListItem>
Expand All @@ -21,11 +21,13 @@ const ListNavigation = ({ children, listStyleType }) => (

ListNavigation.defaultProps = {
listStyleType: undefined,
className: undefined,
};

ListNavigation.propTypes = {
children: PropTypes.node.isRequired,
listStyleType: PropTypes.string,
className: PropTypes.string,
};

export default ListNavigation;
6 changes: 4 additions & 2 deletions components/multi-choice/src/index.js
Expand Up @@ -52,9 +52,9 @@ const FieldSet = glamorous.div(
);

const MultiChoice = ({
meta, label, children, hint,
meta, label, children, hint, className,
}) => (
<FieldSet error={meta.touched && meta.error}>
<FieldSet className={className} error={meta.touched && meta.error}>
<LabelText>{label}</LabelText>
{hint && <HintText>{hint}</HintText>}
{meta.touched && meta.error && <ErrorText>{meta.error}</ErrorText>}
Expand All @@ -64,6 +64,7 @@ const MultiChoice = ({

MultiChoice.defaultProps = {
hint: undefined,
className: undefined,
meta: {},
};

Expand All @@ -86,6 +87,7 @@ MultiChoice.propTypes = {
label: PropTypes.node.isRequired,
children: PropTypes.node.isRequired,
hint: PropTypes.string,
className: PropTypes.string,
};

export default MultiChoice;
1 change: 0 additions & 1 deletion components/ordered-list/src/__snapshots__/test.js.snap
Expand Up @@ -11,7 +11,6 @@ exports[`OrderedList matches wrapper snapshot: wrapper mount 1`] = `
text-transform: none;
font-size: 14px;
line-height: 1.1428571429;
width: 100%;
}
.glamor-2,
Expand Down

0 comments on commit 139b600

Please sign in to comment.