Skip to content

Commit

Permalink
refactors styles and replaces MUI with react select
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmckenna committed May 5, 2019
1 parent c63657f commit b3b63da
Show file tree
Hide file tree
Showing 30 changed files with 374 additions and 109 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@reach/router": "^1.2.1",
"axios": "^0.18.0",
"classnames": "^2.2.6",
"notistack": "^0.8.2",
"querystring": "^0.2.0",
"ramda": "^0.26.1",
"react": "^16.8.6",
Expand Down
Binary file added public/fonts/LibreBaskerville-Bold.ttf
Binary file not shown.
Binary file added public/fonts/LibreBaskerville-Regular.ttf
Binary file not shown.
Binary file added public/fonts/Raleway-Bold.ttf
Binary file not shown.
Binary file added public/fonts/Raleway-Regular.ttf
Binary file not shown.
27 changes: 27 additions & 0 deletions public/fonts/fonts.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@font-face {
font-family: 'Libre Baskerville';
font-weight: normal;
font-style: normal;
src: url('./LibreBaskerville-Regular.ttf')
}

@font-face {
font-family: 'Raleway';
font-weight: normal;
font-style: normal;
src: url('./Raleway-Regular.ttf')
}

@font-face {
font-family: 'Libre Baskerville';
font-weight: 700;
font-style: bold;
src: url('./LibreBaskerville-Bold.ttf')
}

@font-face {
font-family: 'Raleway';
font-weight: 700;
font-style: bold;
src: url('./Raleway-Bold.ttf')
}
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/>
<meta name="theme-color" content="#000000" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link rel="stylesheet" href="%PUBLIC_URL%/fonts/fonts.css">
<title>Barcart - Find your next Cocktail!</title>
</head>
<body>
Expand Down
35 changes: 22 additions & 13 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,37 @@ import theme from './theme';
import store from 'src/store';

import Admin from 'src/features/AdminLanding';
import CocktailDetail from 'src/features/CocktailDetail';
import Footer from 'src/features/Footer';
import Login from 'src/features/Login';
import Header from './features/Header';
import Home from './features/Home';
import SearchLanding from './features/SearchLanding';

import SnackbarProvider from 'src/components/SnackbarProvider';

class App extends Component {
render() {
return (
<Provider store={store}>
<MuiThemeProvider theme={theme}>
<CssBaseline />
<Header />
<Router>
<Home path="/" />
<SearchLanding path="search" />
<Login path="login" />
<Admin path="admin/*" />
</Router>
<Footer />
</MuiThemeProvider>
</Provider>
<SnackbarProvider
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
autoHideDuration={2000}
>
<Provider store={store}>
<MuiThemeProvider theme={theme}>
<CssBaseline />
<Header />
<Router>
<Home path="/" />
<SearchLanding path="search" />
<Login path="login" />
<Admin path="admin/*" />
<CocktailDetail path="cocktails/*" />
</Router>
<Footer />
</MuiThemeProvider>
</Provider>
</SnackbarProvider>
);
}
}
Expand Down
29 changes: 23 additions & 6 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,40 @@ import {
import React from 'react';
import { compose } from 'recompose';

import _Button, { ButtonProps } from '@material-ui/core/Button';
import _Button, { ButtonBaseProps } from '@material-ui/core/ButtonBase';

type ClassNames = 'root';
type ClassNames = 'root' | 'secondary';

const styles: StyleRulesCallback<ClassNames> = theme => ({
root: {}
root: {
color: '#000'
},
secondary: {
color: '#fff'
}
});

interface Props extends ButtonProps {
interface Props extends ButtonBaseProps {
isLoading?: boolean;
variant?: 'primary' | 'secondary';
}

type CombinedProps = Props & WithStyles<ClassNames>;

const Button: React.SFC<CombinedProps> = props => {
const { isLoading, children, ...rest } = props;
return <_Button {...rest}>{isLoading ? 'Loading...' : children}</_Button>;
const { isLoading, children, classes, ...rest } = props;

const className = props.variant
? props.variant === 'primary'
? classes.root
: classes.secondary
: classes.root;

return (
<_Button className={className} disableRipple={true} {...rest}>
{isLoading ? 'Loading...' : children}
</_Button>
);
};

const styled = withStyles(styles);
Expand Down
1 change: 1 addition & 0 deletions src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const Checkbox: React.SFC<CombinedProps> = props => {
control={
<_Checkbox
{...rest}
disableRipple={true}
classes={{
root: classes.root
}}
Expand Down
2 changes: 1 addition & 1 deletion src/components/LandingError/LandingError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const LandingError: React.SFC<CombinedProps> = props => {
return (
<div className={props.classes.root}>
<ThumbDown style={{ width: '75px', height: '75px' }} />
<Typography>{props.message}</Typography>
<Typography variant="h6">{props.message}</Typography>
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/LandingLoading/LandingLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const LandingLoading: React.FC<CombinedProps> = props => {
return isVisible ? (
<div className={props.classes.root}>
<CircularProgress style={{ width: '75px', height: '75px' }} />
{props.message && <Typography>{props.message}</Typography>}
{props.message && <Typography variant="h6">{props.message}</Typography>}
</div>
) : (
<React.Fragment />
Expand Down
24 changes: 21 additions & 3 deletions src/components/Searchbar/Searchbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import {
WithStyles
} from '@material-ui/core/styles';
import React from 'react';
import Select from 'react-select';
import Select, { components } from 'react-select';
import { Props as SelectProps } from 'react-select/lib/Select';
import { compose, StateHandlerMap, withStateHandlers } from 'recompose';

import Button from 'src/components/Button';

type ClassNames = 'root';

const styles: StyleRulesCallback<ClassNames> = theme => ({
Expand Down Expand Up @@ -49,8 +51,6 @@ const Searchbar: React.SFC<CombinedProps> = props => {
loading,
handleSelect,
handleSubmit,
classes,
query,
setQuery
} = props;

Expand Down Expand Up @@ -105,11 +105,29 @@ const Searchbar: React.SFC<CombinedProps> = props => {
isLoading={loading}
isClearable={true}
onChange={handleSelect}
components={{
MenuList: componentProps =>
_Menu({ ...componentProps, handleSubmit: props.handleSubmit })
}}
{...props}
/>
);
};

const _Menu: React.FC<any> = props => {
return (
<React.Fragment>
<components.MenuList {...props}>{props.children}</components.MenuList>
<Button
style={{ width: '100%', padding: '1em' }}
onClick={props.handleSubmit}
>
Search
</Button>
</React.Fragment>
);
};

interface SearchState {
query: string;
}
Expand Down
61 changes: 36 additions & 25 deletions src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
import React from 'react';
import { compose } from 'recompose';

import TextField, { TextFieldProps } from '@material-ui/core/TextField';
import Select from 'react-select';
import { Props as SelectProps } from 'react-select/lib/Select';

type ClassNames = 'root';

Expand All @@ -17,42 +18,52 @@ const styles: StyleRulesCallback<ClassNames> = theme => ({
export interface Option<V = string | number, L = string | number> {
value: V;
label: L;
disabled?: boolean;
}

interface Props {
interface Props extends Omit<SelectProps, 'options' | 'onChange'> {
options: Option[];
defaultText?: string;
defaultOption?: string;
handleSelect: (value: any, actionMeta: any) => void;
}

type CombinedProps = Props & TextFieldProps & WithStyles<ClassNames>;
type CombinedProps = Props & WithStyles<ClassNames>;

const _Select: React.SFC<CombinedProps> = props => {
const { classes, options, defaultOption, handleSelect, ...rest } = props;

const interceptedOptions: Option[] = defaultOption
? [
{
label: defaultOption,
value: defaultOption,
disabled: true
},
...options
]
: options;

const Select: React.SFC<CombinedProps> = props => {
const { options, SelectProps, defaultText, ...rest } = props;
return (
<TextField
select
defaultValue={defaultText || 'Select One'}
SelectProps={{
...SelectProps,
native: true
}}
<Select
{...rest}
>
<option disabled key={0} value={defaultText || 'Select One'}>
{defaultText || 'Select One'}
</option>
{options.map(option => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</TextField>
classNamePrefix="react-select"
options={interceptedOptions as any}
placeholder={
defaultOption
? `${interceptedOptions[0].label}`
: props.placeholder
? props.placeholder
: 'Select an Option'
}
onChange={handleSelect}
isOptionDisabled={(option: Option) => option.disabled || false}
/>
);
};

const styled = withStyles(styles);

export default compose<CombinedProps, TextFieldProps & Props>(
export default compose<CombinedProps, SelectProps & Props>(
styled,
React.memo
)(Select);
)(_Select);
46 changes: 46 additions & 0 deletions src/components/SnackbarProvider/SnackbarProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {
StyleRulesCallback,
withStyles,
WithStyles
} from '@material-ui/core/styles';
import { SnackbarProvider, SnackbarProviderProps } from 'notistack';
import React from 'react';
import { compose } from 'recompose';

type ClassNames = 'root' | 'success' | 'error';

const styles: StyleRulesCallback<ClassNames> = theme => ({
root: {},
success: {
backgroundColor: 'rgba(0,107,224,.98)'
},
error: {
backgroundColor: 'rgba(171,4,87,.86)'
}
});

type CombinedProps = SnackbarProviderProps & WithStyles<ClassNames>;

const _SnackbarProvider: React.FC<CombinedProps> = props => {
const { classes, ...rest } = props;

return (
<SnackbarProvider
{...rest}
maxSnack={3}
classes={{
variantError: classes.error,
variantSuccess: classes.success
}}
>
{props.children}
</SnackbarProvider>
);
};

const styled = withStyles(styles);

export default compose<CombinedProps, SnackbarProviderProps>(
styled,
React.memo
)(_SnackbarProvider);
1 change: 1 addition & 0 deletions src/components/SnackbarProvider/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './SnackbarProvider';
6 changes: 3 additions & 3 deletions src/components/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {
import React from 'react';
import { compose } from 'recompose';

import _TextField, { TextFieldProps } from '@material-ui/core/TextField';
import _TextField, { InputBaseProps } from '@material-ui/core/InputBase';

type ClassNames = 'root';

const styles: StyleRulesCallback<ClassNames> = theme => ({
root: {}
});

type CombinedProps = TextFieldProps & WithStyles<ClassNames>;
type CombinedProps = InputBaseProps & WithStyles<ClassNames>;

const TextField: React.SFC<CombinedProps> = props => {
const { ...rest } = props;
Expand All @@ -23,7 +23,7 @@ const TextField: React.SFC<CombinedProps> = props => {

const styled = withStyles(styles);

export default compose<CombinedProps, TextFieldProps>(
export default compose<CombinedProps, InputBaseProps>(
styled,
React.memo
)(TextField);
2 changes: 1 addition & 1 deletion src/features/AdminLanding/AdminLanding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { RouteComponentProps, Router } from '@reach/router';
import React from 'react';
import { compose } from 'recompose';

import Button from '@material-ui/core/Button';
import Button from 'src/components/Button';
import CreateCocktailForm from './CreateForms/CreateCocktail';
import CreateIngredientForm from './CreateForms/CreateIngredient';

Expand Down
Loading

0 comments on commit b3b63da

Please sign in to comment.