Skip to content

Commit

Permalink
dynamic padding
Browse files Browse the repository at this point in the history
  • Loading branch information
amirasalah committed Jun 14, 2020
1 parent f054dd9 commit 113e0de
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/components/Date.fixture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default (
includeSubmit={false}
title="Date"
type="number"
topSpacing={0}
name="date"
options={["day", "month", "year"]}
inputProps={{
Expand Down
4 changes: 3 additions & 1 deletion src/components/Date.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface IDate {
type: string;
options: string[];
inputProps: ILimits;
topSpacing?: number;
includeSubmit?: boolean;
}
interface ILimits {
Expand All @@ -28,6 +29,7 @@ export const Date: React.FC<IDate> = ({
name,
options,
inputProps,
topSpacing,
includeSubmit = false
}) => {
const formik = useFormik({
Expand All @@ -37,7 +39,7 @@ export const Date: React.FC<IDate> = ({
}
});
return (
<Box py={4}>
<Box py={topSpacing || 4}>
<FocusWithin>
{({ isFocused, getFocusProps }) => (
<form onSubmit={formik.handleSubmit} {...getFocusProps()}>
Expand Down
1 change: 1 addition & 0 deletions src/components/StreetAddress.fixture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default (
<StreetAddress
title="Street Address"
type="text"
topSpacing={1}
options={["building", "street", "city", "country", "nation", "postcode"]}
includeLookup={false}
/>
Expand Down
6 changes: 4 additions & 2 deletions src/components/StreetAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface IStreetAddress {
type: string;
options: string[];
includeLookup?: boolean;
topSpacing?: number;
}
const nations: string[] = [
"nation1",
Expand All @@ -30,7 +31,8 @@ export const StreetAddress: React.FC<IStreetAddress> = ({
title,
type,
options,
includeLookup = false
includeLookup = false,
topSpacing
}) => {
const [errorMessageVisible, setErrorMessageVisible] = React.useState(false);
const [successMessageVisible, setSuccessMessageVisible] = React.useState(
Expand Down Expand Up @@ -87,7 +89,7 @@ export const StreetAddress: React.FC<IStreetAddress> = ({
<FocusWithin>
{({ isFocused, getFocusProps }) => (
<div {...getFocusProps()}>
<Box py={4} maxWidth={480}>
<Box py={topSpacing || 4} maxWidth={480}>
<form
data-testid="streetAddressForm"
onSubmit={formik.handleSubmit}
Expand Down
4 changes: 4 additions & 0 deletions src/components/Text.fixture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default {
"Short Text": (
<Box bgcolor="background.paper" px={4}>
<Text
topSpacing={1}
title="Short Text Input"
multiline={false}
type="text"
Expand All @@ -21,6 +22,7 @@ export default {
"Long Text": (
<Box bgcolor="background.paper" px={4}>
<Text
topSpacing={1}
title="Long Text Input"
multiline
fullWidth
Expand All @@ -37,6 +39,7 @@ export default {
Email: (
<Box bgcolor="background.paper" px={4}>
<Text
topSpacing={1}
title="Email"
label="Email Address"
placeholder="[email protected]"
Expand All @@ -50,6 +53,7 @@ export default {
Number: (
<Box bgcolor="background.paper" px={4}>
<Text
topSpacing={1}
title="Number"
label="Number"
fullWidth={false}
Expand Down
4 changes: 3 additions & 1 deletion src/components/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ interface IText {
unit?: string;
min?: string;
max?: string;
topSpacing?: number;
maxWords?: number;
inputProps?: IMinMax;
includeSubmit?: boolean;
}

export const Text: React.FC<IText> = ({
title,
topSpacing,
label = false,
fullWidth = true,
placeholder = "",
Expand Down Expand Up @@ -73,7 +75,7 @@ export const Text: React.FC<IText> = ({
<FocusWithin>
{({ isFocused, getFocusProps }) => (
<div {...getFocusProps()}>
<Box py={4} maxWidth={480}>
<Box py={topSpacing || 4} maxWidth={480}>
<form data-testid="textForm" onSubmit={formik.handleSubmit}>
{title && (
<Box mb={1.5}>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/SignIn.fixture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import * as React from "react";

import SignIn from "./SignIn";

export default <SignIn fullPage={false} />;
export default <SignIn topSpacing={1} title="Sign In" fullPage={false} />;
14 changes: 9 additions & 5 deletions src/pages/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ const useStyles = makeStyles({
});
interface ISignIn {
fullPage?: boolean;
topSpacing?: number;
title?: string;
}
const SignIn: React.FC<ISignIn> = ({ fullPage }) => {
const SignIn: React.FC<ISignIn> = ({ fullPage, topSpacing, title }) => {
const [email, setEmail] = React.useState("");
const set = useStore(state => state.set);

Expand All @@ -31,10 +33,12 @@ const SignIn: React.FC<ISignIn> = ({ fullPage }) => {
};
const signInComponent = () => {
return (
<Box maxWidth={400}>
<Typography component="h1" variant="h3" gutterBottom>
<strong>Sign in</strong>
</Typography>
<Box py={topSpacing} maxWidth={400}>
{title && (
<Typography component="h1" variant="h3" gutterBottom>
<strong>{title}</strong>
</Typography>
)}
<Box pb={2}>
Sign in or{" "}
<a href="#" className={classes.link}>
Expand Down

0 comments on commit 113e0de

Please sign in to comment.