|
| 1 | +import { useState } from "react"; |
| 2 | +import { defaultTheme, Provider } from "@adobe/react-spectrum"; |
| 3 | +import { Label, Radio, RadioGroup } from "react-aria-components"; |
| 4 | +import User from "@spectrum-icons/workflow/User"; |
| 5 | +import UserGroup from "@spectrum-icons/workflow/UserGroup"; |
| 6 | +import Building from "@spectrum-icons/workflow/Building"; |
| 7 | +import CheckmarkCircle from "@spectrum-icons/workflow/CheckmarkCircle"; |
| 8 | +import ThemeSwitcher from "./ThemeSwitcher"; |
| 9 | + |
| 10 | +export function App() { |
| 11 | + let [colorScheme, setColorScheme] = useState(undefined); |
| 12 | + |
| 13 | + return ( |
| 14 | + <Provider theme={defaultTheme} colorScheme={colorScheme}> |
| 15 | + <ThemeSwitcher setColorScheme={setColorScheme} /> |
| 16 | + <div className="grid justify-center grid-cols-1 gap-160 auto-rows-fr"> |
| 17 | + <SelectBoxExample /> |
| 18 | + <SentimentRatingGroup /> |
| 19 | + </div> |
| 20 | + </Provider> |
| 21 | + ); |
| 22 | +} |
| 23 | + |
| 24 | +function SelectBoxExample() { |
| 25 | + return ( |
| 26 | + <RadioGroup |
| 27 | + className="flex flex-col space-y-2 text-center" |
| 28 | + defaultValue="Team" |
| 29 | + > |
| 30 | + <Label className="text-xl font-semibold">Select Boxes</Label> |
| 31 | + <div className="flex justify-center"> |
| 32 | + <SelectBox |
| 33 | + name="Individual" |
| 34 | + icon={<User size="XL" />} |
| 35 | + description="For 1 person" |
| 36 | + /> |
| 37 | + <SelectBox |
| 38 | + name="Team" |
| 39 | + icon={<UserGroup size="XL" />} |
| 40 | + description="For teams of 9 or less" |
| 41 | + /> |
| 42 | + <SelectBox |
| 43 | + name="Enterprise" |
| 44 | + icon={<Building size="XL" />} |
| 45 | + description="For of 10 or more" |
| 46 | + /> |
| 47 | + </div> |
| 48 | + </RadioGroup> |
| 49 | + ); |
| 50 | +} |
| 51 | + |
| 52 | +function SelectBox({ name, icon, description }) { |
| 53 | + return ( |
| 54 | + <Radio |
| 55 | + value={name} |
| 56 | + className={({ isFocusVisible, isSelected, isPressed }) => ` |
| 57 | + flex justify-center p-160 m-160 h-2000 w-2000 focus:outline-none border rounded |
| 58 | + ${isFocusVisible ? "ring-half ring-offset-0" : ""} |
| 59 | + ${isSelected ? "bg-accent-100 border-accent-700" : ""} |
| 60 | + ${isPressed && !isSelected ? "bg-gray-200" : ""} |
| 61 | + ${!isSelected && !isPressed ? "bg-white dark:bg-black" : ""} |
| 62 | + `} |
| 63 | + > |
| 64 | + {({ isSelected }) => ( |
| 65 | + <div className="relative flex flex-col items-center justify-center w-full h-full gap-150"> |
| 66 | + {isSelected && ( |
| 67 | + <div className="absolute top-0 left-0 text-accent-800 -mt-125 -ml-75"> |
| 68 | + <CheckmarkCircle size="S" /> |
| 69 | + </div> |
| 70 | + )} |
| 71 | + {icon && <div className="text-gray-500">{icon}</div>} |
| 72 | + <div> |
| 73 | + <div className={`font-semibold`}>{name}</div> |
| 74 | + {description && <div className="text-sm">{description}</div>} |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + )} |
| 78 | + </Radio> |
| 79 | + ); |
| 80 | +} |
| 81 | + |
| 82 | +function SentimentRatingGroup() { |
| 83 | + let ratings = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; |
| 84 | + return ( |
| 85 | + <RadioGroup className="flex flex-col m-auto space-y-10 text-center"> |
| 86 | + <Label className="text-xl font-semibold">Sentiment Rating</Label> |
| 87 | + <div className="flex justify-between"> |
| 88 | + <span>Least Likely</span> |
| 89 | + <span>Most Likely</span> |
| 90 | + </div> |
| 91 | + <div className="flex justify-evenly"> |
| 92 | + {ratings.map((rating) => ( |
| 93 | + <SentimentRating key={rating} rating={rating} /> |
| 94 | + ))} |
| 95 | + </div> |
| 96 | + </RadioGroup> |
| 97 | + ); |
| 98 | +} |
| 99 | + |
| 100 | +function SentimentRating({ rating }) { |
| 101 | + return ( |
| 102 | + <Radio |
| 103 | + value={rating} |
| 104 | + className="flex items-center justify-center bg-white border rounded-full p-160 m-75 h-200 w-200 focus:outline-none focus-visible:ring dark:bg-black selected:bg-accent-800 dark:selected:bg-accent-800 selected:border-accent-800 selected:text-white pressed:bg-gray-200 dark:pressed:bg-gray-200 hovered:border-gray-300" |
| 105 | + > |
| 106 | + {rating} |
| 107 | + </Radio> |
| 108 | + ); |
| 109 | +} |
0 commit comments