|
| 1 | +import type { Key } from "react-aria-components"; |
| 2 | + |
| 3 | +import Button from "components/base/Button/Button"; |
| 4 | +import { |
| 5 | + ToggleButton, |
| 6 | + ToggleButtonGroup, |
| 7 | +} from "components/base/ToggleButton/ToggleButton"; |
| 8 | + |
| 9 | +import FamilyIcon from "assets/icons/family.svg?react"; |
| 10 | +import TransitIcon from "assets/icons/transit.svg?react"; |
| 11 | +import CarIcon from "assets/icons/car.svg?react"; |
| 12 | +import ArrowFullRightIcon from "assets/icons/arrow-full-right.svg?react"; |
| 13 | +import { useEffect, useState } from "react"; |
| 14 | + |
| 15 | +export const Places = { |
| 16 | + Work: "Work", |
| 17 | + School: "School", |
| 18 | + Daycare: "Daycare", |
| 19 | + FriendsFamily: "Friends/Family", |
| 20 | + Doctor: "Doctor", |
| 21 | + Other: "Other", |
| 22 | +}; |
| 23 | + |
| 24 | +type PlaceKeys = (typeof Places)[keyof typeof Places]; |
| 25 | + |
| 26 | +type Mode = "transit" | "car"; |
| 27 | +type Size = "small" | "medium" | "large"; |
| 28 | + |
| 29 | +interface Props { |
| 30 | + size?: Size; |
| 31 | + mode: Mode; |
| 32 | + place: PlaceKeys; |
| 33 | +} |
| 34 | + |
| 35 | +interface MobileProps extends Props { |
| 36 | + display: "map" | "list"; |
| 37 | +} |
| 38 | + |
| 39 | +const getModeIcon = (mode: Mode, size: Size) => |
| 40 | + mode === "transit" ? ( |
| 41 | + <TransitIcon className={getIconStyle(size)} /> |
| 42 | + ) : ( |
| 43 | + <CarIcon className={getIconStyle(size)} /> |
| 44 | + ); |
| 45 | + |
| 46 | +const getIconStyle = (size: Size) => |
| 47 | + size === "small" |
| 48 | + ? "font-normal text-gray-500 w-[13px]" |
| 49 | + : "font-normal text-gray-500 w-[17px]"; |
| 50 | + |
| 51 | +export const UserProfileSubheaderMobile = ({ |
| 52 | + mode, |
| 53 | + place, |
| 54 | + size = "medium", |
| 55 | + display = "map", |
| 56 | +}: MobileProps) => { |
| 57 | + const [displayOption, setDisplayOption] = useState(new Set<Key>([display])); |
| 58 | + |
| 59 | + useEffect(() => { |
| 60 | + setDisplayOption(new Set<Key>([display])); |
| 61 | + }, [display]); |
| 62 | + |
| 63 | + const onChangeDisplayOption = (keys: Set<Key>) => { |
| 64 | + if (keys.size === 0) { |
| 65 | + setDisplayOption(displayOption); |
| 66 | + return; |
| 67 | + } |
| 68 | + setDisplayOption(keys); |
| 69 | + }; |
| 70 | + |
| 71 | + return ( |
| 72 | + <div className="flex flex-column items-center gap-3"> |
| 73 | + <Button |
| 74 | + variant="outline" |
| 75 | + size={size} |
| 76 | + label="You" |
| 77 | + leftIcon={<FamilyIcon className={getIconStyle(size)} />} |
| 78 | + /> |
| 79 | + <Button |
| 80 | + variant="outline" |
| 81 | + size={size} |
| 82 | + label={place} |
| 83 | + leftIcon={ |
| 84 | + <div className="flex items-center gap-3"> |
| 85 | + {getModeIcon(mode, size)} |
| 86 | + <ArrowFullRightIcon className="font-normal fill-gray-400 w-[10px] -ml-1" /> |
| 87 | + </div> |
| 88 | + } |
| 89 | + /> |
| 90 | + <ToggleButtonGroup |
| 91 | + selectionMode="single" |
| 92 | + selectedKeys={displayOption} |
| 93 | + onSelectionChange={onChangeDisplayOption} |
| 94 | + > |
| 95 | + <ToggleButton id="map" size={size}> |
| 96 | + Map |
| 97 | + </ToggleButton> |
| 98 | + <ToggleButton id="list" size={size}> |
| 99 | + List |
| 100 | + </ToggleButton> |
| 101 | + </ToggleButtonGroup> |
| 102 | + </div> |
| 103 | + ); |
| 104 | +}; |
| 105 | + |
| 106 | +export const UserProfileSubheader = ({ |
| 107 | + mode, |
| 108 | + place, |
| 109 | + size = "medium", |
| 110 | +}: Props) => { |
| 111 | + return ( |
| 112 | + <div className="flex flex-col gap-3 w-[360px]"> |
| 113 | + <Button |
| 114 | + variant="outline" |
| 115 | + size={size} |
| 116 | + label="Your Profile" |
| 117 | + leftIcon={<FamilyIcon className={getIconStyle(size)} />} |
| 118 | + info="2br・public transit" |
| 119 | + /> |
| 120 | + <Button |
| 121 | + variant="outline" |
| 122 | + size={size} |
| 123 | + label={place} |
| 124 | + leftIcon={getModeIcon(mode, size)} |
| 125 | + info="122 Address St, Cambridge" |
| 126 | + /> |
| 127 | + </div> |
| 128 | + ); |
| 129 | +}; |
0 commit comments