From 11272ce41ad787e2235bf3957eb7c8f20922fa84 Mon Sep 17 00:00:00 2001 From: Michael Fatemi Date: Tue, 8 Jun 2021 08:48:08 -0400 Subject: [PATCH] Add some UI components --- src/components/NewUI/App.tsx | 14 +- src/components/NewUI/Event.tsx | 190 ++++-------------- src/components/NewUI/UIPlacesAutocomplete.tsx | 100 +++++++++ src/components/NewUI/UIPrimaryTitle.tsx | 15 ++ src/components/NewUI/UISecondaryHeader.tsx | 17 ++ src/components/NewUI/UITimeInput.tsx | 21 ++ 6 files changed, 196 insertions(+), 161 deletions(-) create mode 100644 src/components/NewUI/UIPlacesAutocomplete.tsx create mode 100644 src/components/NewUI/UIPrimaryTitle.tsx create mode 100644 src/components/NewUI/UISecondaryHeader.tsx create mode 100644 src/components/NewUI/UITimeInput.tsx diff --git a/src/components/NewUI/App.tsx b/src/components/NewUI/App.tsx index f5bebd5..1f5cb60 100644 --- a/src/components/NewUI/App.tsx +++ b/src/components/NewUI/App.tsx @@ -1,4 +1,5 @@ import Event from './Event'; +import UIPrimaryTitle from './UIPrimaryTitle'; export default function App() { return ( @@ -7,20 +8,13 @@ export default function App() { display: 'flex', flexDirection: 'column', alignItems: 'center', - maxWidth: '50rem', + width: '30rem', + maxWidth: '30rem', marginLeft: 'auto', marginRight: 'auto', }} > -

- WheelShare -

+ WheelShare { + console.log({ rideTherePickupPlaceID, rideBackDropoffPlaceID }); + }, [rideTherePickupPlaceID, rideBackDropoffPlaceID]); return (
-

- {title} -

+ {title} {needRideThere && ( <> - setRideThereLocation(address)} - value={rideThereLocation} - > - {({ - getInputProps, - getSuggestionItemProps, - suggestions, - loading, - }) => ( -
- - {loading - ? 'Loading' - : suggestions.length > 0 && ( -
- {suggestions.map((suggestion) => ( -
- {suggestion.description} -
- ))} -
- )} -
- )} -
- + Ride There +
+ + setRideTherePickupPlaceID(placeID) + } /> + )} {needRideBack && ( <> - setRideBackLocation(address)} - value={rideBackLocation} - > - {({ - getInputProps, - getSuggestionItemProps, - suggestions, - loading, - }) => ( -
- - {loading - ? 'Loading' - : suggestions.length > 0 && ( -
- {suggestions.map((suggestion) => ( -
- {suggestion.description} -
- ))} -
- )} -
- )} -
- + Ride Back + + + setRideBackDropoffPlaceID(placeID) + } /> + )}
diff --git a/src/components/NewUI/UIPlacesAutocomplete.tsx b/src/components/NewUI/UIPlacesAutocomplete.tsx new file mode 100644 index 0000000..548428a --- /dev/null +++ b/src/components/NewUI/UIPlacesAutocomplete.tsx @@ -0,0 +1,100 @@ +import { useRef, useState } from 'react'; +import PlacesAutocomplete, { Suggestion } from 'react-places-autocomplete'; + +type Opts = Parameters['0']; + +function SuggestionsList({ + suggestions, + getSuggestionItemProps, +}: { + suggestions: readonly Suggestion[]; + getSuggestionItemProps: Opts['getSuggestionItemProps']; +}) { + return ( +
+ {suggestions.map((suggestion) => ( +
+ {suggestion.description} +
+ ))} +
+ ); +} + +export default function UIPlacesAutocomplete({ + onSelected, + placeholder = 'Enter a location', +}: { + onSelected?: (address: string, placeID: string) => void; + placeholder?: string; +}) { + const [location, setLocation] = useState(''); + const suggestionsRef = useRef([]); + return ( + { + setLocation(address); + if (onSelected) { + onSelected(address, placeID); + } + }} + value={location} + > + {({ getInputProps, getSuggestionItemProps, suggestions, loading }) => { + if (!loading) { + suggestionsRef.current = suggestions; + console.log(suggestions); + } + return ( +
+ + {suggestionsRef.current.length > 0 && ( + + )} +
+ ); + }} +
+ ); +} diff --git a/src/components/NewUI/UIPrimaryTitle.tsx b/src/components/NewUI/UIPrimaryTitle.tsx new file mode 100644 index 0000000..bcb5715 --- /dev/null +++ b/src/components/NewUI/UIPrimaryTitle.tsx @@ -0,0 +1,15 @@ +import { ReactNode } from 'react'; + +export default function UIPrimaryTitle({ children }: { children: ReactNode }) { + return ( +

+ {children} +

+ ); +} diff --git a/src/components/NewUI/UISecondaryHeader.tsx b/src/components/NewUI/UISecondaryHeader.tsx new file mode 100644 index 0000000..3768a9c --- /dev/null +++ b/src/components/NewUI/UISecondaryHeader.tsx @@ -0,0 +1,17 @@ +const baseStyle = { + marginTop: '0rem', + marginBottom: '0.25em', + textAlign: 'center', +} as const; + +export default function UISecondaryHeader({ + style, + children, + ...props +}: JSX.IntrinsicElements['h2']) { + return ( +

+ {children} +

+ ); +} diff --git a/src/components/NewUI/UITimeInput.tsx b/src/components/NewUI/UITimeInput.tsx new file mode 100644 index 0000000..b2d441e --- /dev/null +++ b/src/components/NewUI/UITimeInput.tsx @@ -0,0 +1,21 @@ +const baseStyle = { + marginTop: '0.5em', + padding: '0.5em', + fontFamily: 'Inter', + fontSize: '1.25rem', + borderRadius: '0.5em', + border: '0px', +}; + +export default function UITimeInput({ + style, + ...props +}: JSX.IntrinsicElements['input']) { + return ( + + ); +}