Skip to content

Commit

Permalink
feat(Input): Floating Label Fields
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenfitzpatrick committed Feb 27, 2018
1 parent 1370417 commit 3c0a168
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 15 deletions.
32 changes: 23 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"transpile": "npm-run-all transpile:main transpile:esm transpile:cjs",
"smart-release": "npm run build && npm run test && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish",
"test": "jest",
"test:watch": "npm run test -- --watch",
"test:coverage": "npm test -- --coverage",
"test:ci": "jest --coverage && ./node_modules/coveralls/bin/coveralls.js < ./coverage/lcov.info",
"test:size": "bundlesize",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Button.propTypes = {
/**
* onClick Handler handling button click
*/
onClick: PropTypes.func.isRequired,
onClick: PropTypes.func,
/**
* Value to display in button
*/
Expand Down
2 changes: 1 addition & 1 deletion src/components/Button/Button.styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const FitzyButton = styled.button`
color: white;
cursor: pointer;
appearance: none;
font-size: 14px;
font-size: inherit;
width: ${({ fullWidth }) => (fullWidth ? '100%' : 'auto')};
&:disabled {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class Input extends PureComponent {

return (
<FormField role="presentation" className={className}>
{this.renderLabel(inputId)}
{this.renderInput(inputId)}
{this.renderLabel(inputId)}
{this.renderHint()}
{this.renderWarning()}
</FormField>
Expand Down
16 changes: 14 additions & 2 deletions src/components/Input/Input.styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ const FormField = styled.label`
position: relative;
display: block;
margin-bottom: 1.5rem;
&:focus-within {
label {
top: -24px;
}
}
`;

const FormError = styled.span`
Expand All @@ -25,13 +31,19 @@ const FitzyInput = styled.input`
background-color: #fff;
transition: border 0.3s ease-in-out;
margin: 0 0 5px 0;
~ label {
top: ${({ value }) => (value ? '-24px' : '12px')};
}
`;

const FitzyLabel = styled.label`
display: inline-block;
margin-bottom: 5px;
font-weight: bold;
max-width: 100%;
position: absolute;
left: 12px;
z-index: 1;
transition: all 0.3s ease;
`;

/** @component */
Expand Down
1 change: 0 additions & 1 deletion src/components/Input/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ initialState = { value: '' };

<Input
label="Name"
placeholder="Enter your name"
value={state.value}
onChange={(_, v) => setState({ value: v })}
warning={<span>Some Warning</span>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ exports[`Input should match snapshot 1`] = `
margin-bottom: 1.5rem;
}
.c0:focus-within label {
top: -24px;
}
.c1 {
display: block;
position: relative;
Expand All @@ -24,6 +28,10 @@ exports[`Input should match snapshot 1`] = `
margin: 0 0 5px 0;
}
.c1 ~ label {
top: -24px;
}
<label
className="c0"
role="presentation"
Expand Down

0 comments on commit 3c0a168

Please sign in to comment.