├── .gitignore ├── .postcssrc ├── LICENSE ├── README.md ├── components.json ├── docs └── instructions-gif-connections.gif ├── jsconfig.json ├── package-lock.json ├── package.json ├── public └── favicon.png ├── src ├── components │ ├── App │ │ ├── App.js │ │ └── index.js │ ├── CountdownToNextPuzzle │ │ ├── CountdownToNextPuzzle.js │ │ └── index.js │ ├── Game │ │ ├── Game.js │ │ └── index.js │ ├── GameControlButtonsPanel │ │ ├── GameControlButtonsPanel.js │ │ └── index.js │ ├── GameGrid │ │ ├── GameGrid.js │ │ ├── GameGrid.module.css │ │ └── index.js │ ├── Header │ │ ├── Header.js │ │ └── index.js │ ├── NumberOfMistakesDisplay │ │ ├── NumberOfMistakesDisplay.js │ │ └── index.js │ ├── ShareScoreButton │ │ ├── ShareScoreButton.js │ │ └── index.js │ ├── Sparkles │ │ ├── Sparkles.js │ │ └── index.js │ ├── WordButton │ │ ├── WordButton.js │ │ ├── WordButton.module.css │ │ └── index.js │ ├── modals │ │ ├── BaseModal │ │ │ ├── BaseModal.js │ │ │ └── index.js │ │ ├── GameLostModal │ │ │ ├── GameLostModal.js │ │ │ └── index.js │ │ ├── GameWonModal │ │ │ ├── GameWonModal.js │ │ │ └── index.js │ │ ├── InfoModal │ │ │ ├── InfoModal.js │ │ │ └── index.js │ │ └── ViewResultsModal │ │ │ ├── ViewResultsModal.js │ │ │ └── index.js │ └── ui │ │ ├── accordion.jsx │ │ ├── alert-dialog.jsx │ │ ├── badge.jsx │ │ ├── button.jsx │ │ ├── popover.jsx │ │ ├── separator.jsx │ │ ├── tabs.jsx │ │ ├── toast.jsx │ │ ├── toaster.jsx │ │ ├── toggle.jsx │ │ └── use-toast.js ├── hooks │ ├── use-prefers-reduced-motion.hook.js │ └── use-random-interval.hook.js ├── index.css ├── index.html ├── index.js ├── lib │ ├── constants.js │ ├── data.js │ ├── game-helpers.js │ ├── local-storage.js │ ├── share-game.js │ ├── time-utils.js │ └── utils.js ├── providers │ ├── GameStatusProvider │ │ ├── GameStatusProvider.js │ │ └── index.js │ └── PuzzleDataProvider │ │ ├── PuzzleDataProvider.js │ │ └── index.js ├── reset.css └── styles.css └── tailwind.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .parcel-cache/* 3 | 4 | .idea/ 5 | .vscode/ 6 | node_modules/ 7 | build/ 8 | dist/ 9 | .DS_Store 10 | *.tgz 11 | my-app* 12 | template/src/__tests__/__snapshots__/ 13 | lerna-debug.log 14 | npm-debug.log* 15 | yarn-debug.log* 16 | yarn-error.log* 17 | /.changelog 18 | .npm/ 19 | 20 | *.swp 21 | -------------------------------------------------------------------------------- /.postcssrc: -------------------------------------------------------------------------------- 1 | { 2 | "plugins": { 3 | "tailwindcss": {} 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Connections (React, Tailwind, Shadcn/ui) 2 | 3 | This is a clone of the [NYT Connections Game](https://www.nytimes.com/games/connections). Which itself seems to be an unacknowledged clone of the British game [`Only Connect`](https://kotaku.com/new-york-times-connections-only-connect-puzzle-wordle-1850553072). 4 | 5 | Anyways.. 6 | 7 | ### [Click Here To Try Out The Demo](https://blackconnections.andcomputers.io/) 8 | 9 | ![Gif of Connections Gameplay](/docs/instructions-gif-connections.gif) 10 | 11 | ## To Run Locally: 12 | 13 | ``` 14 | cd react-connections-game 15 | npm install 16 | npm run dev 17 | ``` 18 | 19 | ### Technology 20 | 21 | - [React 18](https://react.dev/) 22 | - [Tailwind CSS](https://tailwindcss.com/) 23 | - [React Spring](https://www.react-spring.dev/) for a few animations 24 | - [Shadcn/ui](https://ui.shadcn.com/) for primitive components 25 | - Copied a number of utility functions from a [React Wordle Clone - cwackerfuss/react-wordle](https://github.com/cwackerfuss/react-wordle) 26 | - Built with [Parcel](https://parceljs.org/) 27 | 28 | ### Code Organization 29 | 30 | - Global state (game status, guesses, etc.) is handled using React's Context API. The provider components are in `src/providers` 31 | - Components are in `src/components` 32 | - Primitive components imported from `shadcn/ui` library and lightly edited are in `src/components/ui` 33 | - The `Sparkles` component is taken from [Josh Comeau's article on creating animated sparkles in React.](https://www.joshwcomeau.com/react/animated-sparkles-in-react/). 34 | - Helper functions for local storage, game statistics, and constants are in `src/lib` 35 | - The actual puzzle data for changing the content of each puzzle is in `src/lib/data.js` 36 | - Custom hooks are in `src/hooks` 37 | - Both of these are code snippets taken from [Josh Comeau's Blog](https://www.joshwcomeau.com/snippets/) 38 | 39 | #### Similar Projects 40 | 41 | - [PuzzGrid](https://puzzgrid.com/about) which allows you to create your own games/puzzles, no code required. 42 | - [Connections Generator by swellgarfo](https://www.reddit.com/r/NYTSpellingBee/comments/152i5cx/for_those_playing_nyt_connections_i_created_a/) which also allows you to create your own games/puzzles, no code required. 43 | 44 | ### Contributing 45 | 46 | - Please fork and submit a PR if you'd like! 47 | 48 | ### Projects Built Using This Repo: 49 | 50 | - _your fork here!_ 51 | 52 | _Want to add one to the list? Please make a pull request._ 53 | 54 | #### If you found this helpful or entertaining feel free to check out our other work! 55 | 56 | - [Writings & Thoughts](https://andcomputers.io) 57 | - [Black Wordle](https://blackwords.andcomputers.io) 58 | 59 | ##### If you'd like to support financially 60 | 61 | - [One-Time Contribution via Stripe](https://buy.stripe.com/7sIg1Udac6xZegodQR) 62 | -------------------------------------------------------------------------------- /components.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://ui.shadcn.com/schema.json", 3 | "style": "default", 4 | "rsc": false, 5 | "tsx": false, 6 | "tailwind": { 7 | "config": "tailwind.config.js", 8 | "css": "src/index.css", 9 | "baseColor": "slate", 10 | "cssVariables": true 11 | }, 12 | "aliases": { 13 | "components": "src/components", 14 | "utils": "src/utils" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /docs/instructions-gif-connections.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/and-computers/react-connections-game/e5428ffc972963d3dbe95291e62cc22bfc3e8d20/docs/instructions-gif-connections.gif -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "paths": { 4 | "@/*": ["./*"] 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "@radix-ui/react-accordion": "^1.1.2", 4 | "@radix-ui/react-alert-dialog": "^1.0.5", 5 | "@radix-ui/react-popover": "^1.0.7", 6 | "@radix-ui/react-separator": "^1.0.3", 7 | "@radix-ui/react-slot": "^1.0.2", 8 | "@radix-ui/react-tabs": "^1.0.4", 9 | "@radix-ui/react-toast": "^1.1.5", 10 | "@radix-ui/react-toggle": "^1.0.3", 11 | "class-variance-authority": "^0.7.0", 12 | "clsx": "^2.0.0", 13 | "date-fns": "^2.30.0", 14 | "eslint": "8.49.0", 15 | "eslint-config-react-app": "7.0.1", 16 | "lucide-react": "^0.288.0", 17 | "new-component": "5.0.2", 18 | "parcel": "2.9.2", 19 | "prettier": "2.6.2", 20 | "process": "0.11.10", 21 | "query-string": "^8.1.0", 22 | "react": "18.2.0", 23 | "react-confetti-explosion": "^2.1.2", 24 | "react-countdown": "^2.3.5", 25 | "react-dom": "18.2.0", 26 | "react-spring": "^9.7.3", 27 | "rimraf": "5.0.1", 28 | "styled-components": "^6.1.0", 29 | "tailwind-merge": "^1.14.0", 30 | "tailwindcss-animate": "^1.0.7", 31 | "ua-parser-js": "^1.0.36" 32 | }, 33 | "scripts": { 34 | "predev": "rimraf .parcel-cache dist", 35 | "dev": "parcel src/index.html", 36 | "build": "parcel build src/index.html", 37 | "nc": "new-component" 38 | }, 39 | "browserslist": "> 0.5%, last 2 versions, not dead", 40 | "devDependencies": { 41 | "postcss": "^8.4.31", 42 | "tailwindcss": "^3.3.3" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /public/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/and-computers/react-connections-game/e5428ffc972963d3dbe95291e62cc22bfc3e8d20/public/favicon.png -------------------------------------------------------------------------------- /src/components/App/App.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import Header from "../Header"; 3 | import Game from "../Game"; 4 | 5 | import { Toaster } from "../ui/toaster"; 6 | import PuzzleDataProvider from "../../providers/PuzzleDataProvider"; 7 | import GameStatusProvider from "../../providers/GameStatusProvider"; 8 | 9 | function App() { 10 | return ( 11 | 12 | 13 |
14 | 15 |
16 | 17 |
18 |
19 |
20 | ); 21 | } 22 | 23 | export default App; 24 | -------------------------------------------------------------------------------- /src/components/App/index.js: -------------------------------------------------------------------------------- 1 | export * from './App'; 2 | export { default } from './App'; 3 | -------------------------------------------------------------------------------- /src/components/CountdownToNextPuzzle/CountdownToNextPuzzle.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import Countdown from "react-countdown"; 3 | import { dateOfNextPuzzle } from "../../lib/time-utils"; 4 | 5 | // Renderer callback with condition 6 | const renderer = ({ days, hours, minutes, seconds, completed }) => { 7 | //ChatGPT Assisted 8 | // Render a countdown 9 | if (completed) { 10 | return ( 11 | 12 | New Game Available! Refresh Your Browser. 13 | 14 | ); 15 | } 16 | const timeParts = []; 17 | 18 | if (days > 0) { 19 | timeParts.push(`${days} Day${days > 1 ? "s" : ""}`); 20 | } 21 | if (hours > 0) { 22 | timeParts.push(`${hours} Hour${hours > 1 ? "s" : ""}`); 23 | } 24 | if (minutes > 0) { 25 | timeParts.push(`${minutes} Minute${minutes > 1 ? "s" : ""}`); 26 | } 27 | 28 | // Create a sentence based on the time parts 29 | let timeLeftString = "Next Puzzle Released in "; 30 | if (timeParts.length > 2) { 31 | timeLeftString += timeParts.slice(0, -1).join(", "); 32 | timeLeftString += `, and ${timeParts.slice(-1)}`; 33 | } else if (timeParts.length == 2) { 34 | timeLeftString += `${timeParts[0]} and ${timeParts[1]}`; 35 | } else { 36 | timeLeftString += timeParts[0]; 37 | } 38 | // Create a sentence based on the time parts 39 | 40 | return
{timeLeftString}
; 41 | }; 42 | 43 | function CountdownToNextPuzzle() { 44 | return ( 45 |
46 | 52 |
53 | ); 54 | } 55 | 56 | export default CountdownToNextPuzzle; 57 | -------------------------------------------------------------------------------- /src/components/CountdownToNextPuzzle/index.js: -------------------------------------------------------------------------------- 1 | export * from './CountdownToNextPuzzle'; 2 | export { default } from './CountdownToNextPuzzle'; 3 | -------------------------------------------------------------------------------- /src/components/Game/Game.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { shuffleGameData } from "../../lib/game-helpers"; 3 | import GameGrid from "../GameGrid"; 4 | import NumberOfMistakesDisplay from "../NumberOfMistakesDisplay"; 5 | import GameLostModal from "../modals/GameLostModal"; 6 | import GameWonModal from "../modals/GameWonModal"; 7 | 8 | import { Separator } from "../ui/separator"; 9 | import ConfettiExplosion from "react-confetti-explosion"; 10 | 11 | import { PuzzleDataContext } from "../../providers/PuzzleDataProvider"; 12 | import { GameStatusContext } from "../../providers/GameStatusProvider"; 13 | import GameControlButtonsPanel from "../GameControlButtonsPanel"; 14 | 15 | import ViewResultsModal from "../modals/ViewResultsModal"; 16 | 17 | function Game() { 18 | const { gameData, categorySize, numCategories } = 19 | React.useContext(PuzzleDataContext); 20 | const { submittedGuesses, solvedGameData, isGameOver, isGameWon } = 21 | React.useContext(GameStatusContext); 22 | 23 | const [shuffledRows, setShuffledRows] = React.useState( 24 | shuffleGameData({ gameData }) 25 | ); 26 | const [isEndGameModalOpen, setisEndGameModalOpen] = React.useState(false); 27 | const [gridShake, setGridShake] = React.useState(false); 28 | const [showConfetti, setShowConfetti] = React.useState(false); 29 | 30 | // use effect to update Game Grid after a row has been correctly solved 31 | React.useEffect(() => { 32 | const categoriesToRemoveFromRows = solvedGameData.map( 33 | (data) => data.category 34 | ); 35 | const dataLeftForRows = gameData.filter((data) => { 36 | return !categoriesToRemoveFromRows.includes(data.category); 37 | }); 38 | if (dataLeftForRows.length > 0) { 39 | setShuffledRows(shuffleGameData({ gameData: dataLeftForRows })); 40 | } 41 | }, [solvedGameData]); 42 | 43 | // Handle End Game! 44 | React.useEffect(() => { 45 | if (!isGameOver) { 46 | return; 47 | } 48 | // extra delay for game won to allow confetti to show 49 | const modalDelay = isGameWon ? 2000 : 250; 50 | const delayModalOpen = window.setTimeout(() => { 51 | setisEndGameModalOpen(true); 52 | //unmount confetti after modal opens 53 | setShowConfetti(false); 54 | }, modalDelay); 55 | 56 | if (isGameWon) { 57 | setShowConfetti(true); 58 | } 59 | 60 | return () => window.clearTimeout(delayModalOpen); 61 | }, [isGameOver]); 62 | 63 | return ( 64 | <> 65 |

66 | Create {numCategories} groups of {categorySize} 67 |

68 | 69 |
70 | {isGameOver && isGameWon ? ( 71 | 75 | ) : ( 76 | 80 | )} 81 | 86 | {showConfetti && isGameOver && ( 87 |
88 | 93 |
94 | )} 95 | 96 | 97 | {!isGameOver ? ( 98 | <> 99 | 100 | 105 | 106 | ) : ( 107 | 108 | )} 109 |
110 | 111 | ); 112 | } 113 | 114 | export default Game; 115 | -------------------------------------------------------------------------------- /src/components/Game/index.js: -------------------------------------------------------------------------------- 1 | export * from './Game'; 2 | export { default } from './Game'; 3 | -------------------------------------------------------------------------------- /src/components/GameControlButtonsPanel/GameControlButtonsPanel.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { Button } from "../ui/button"; 3 | import { useToast } from "../ui/use-toast"; 4 | import { Shuffle, Undo, SendHorizontal } from "lucide-react"; 5 | import { 6 | isGuessCorrect, 7 | isGuessRepeated, 8 | shuffleGameData, 9 | } from "../../lib/game-helpers"; 10 | 11 | import { GameStatusContext } from "../../providers/GameStatusProvider"; 12 | import { PuzzleDataContext } from "../../providers/PuzzleDataProvider"; 13 | 14 | function GameControlButtonsPanel({ 15 | shuffledRows, 16 | setShuffledRows, 17 | setGridShake, 18 | }) { 19 | const { 20 | isGameOver, 21 | guessCandidate, 22 | setGuessCandidate, 23 | submittedGuesses, 24 | setSubmittedGuesses, 25 | solvedGameData, 26 | setSolvedGameData, 27 | } = React.useContext(GameStatusContext); 28 | const { gameData, categorySize } = React.useContext(PuzzleDataContext); 29 | const { toast } = useToast(); 30 | 31 | function deselectAll() { 32 | setGuessCandidate([]); 33 | } 34 | 35 | function submitCandidateGuess() { 36 | // check that its a valid guess by size 37 | if (guessCandidate.length !== categorySize) { 38 | return; 39 | } 40 | // check that the guess hasnt already been submitted previously 41 | if (isGuessRepeated({ submittedGuesses, guessCandidate })) { 42 | toast({ 43 | label: "Notification", 44 | title: "Repeated Guess", 45 | description: "You previously made this guess!", 46 | }); 47 | 48 | return; 49 | } 50 | // add guess to state 51 | setSubmittedGuesses([...submittedGuesses, guessCandidate]); 52 | // check if the guess is correct 53 | const { 54 | isCorrect, 55 | correctWords, 56 | correctCategory, 57 | isGuessOneAway, 58 | correctDifficulty, 59 | correctImageSrc, 60 | } = isGuessCorrect({ 61 | guessCandidate, 62 | gameData, 63 | }); 64 | 65 | // if the guess is correct: 66 | // set it as solved in game data 67 | if (isCorrect) { 68 | setSolvedGameData([ 69 | ...solvedGameData, 70 | { 71 | category: correctCategory, 72 | words: correctWords, 73 | difficulty: correctDifficulty, 74 | imageSrc: correctImageSrc, 75 | }, 76 | ]); 77 | setGuessCandidate([]); 78 | } else { 79 | // Shake the grid to give feedback that they were wrong 80 | setGridShake(true); 81 | if (isGuessOneAway) { 82 | toast({ 83 | label: "Notification", 84 | title: "Close Guess", 85 | description: 86 | "You were one guess away from correctly guessing a category!", 87 | }); 88 | } 89 | } 90 | } 91 | 92 | return ( 93 |
94 | 104 | 113 | 121 |
122 | ); 123 | } 124 | 125 | export default GameControlButtonsPanel; 126 | -------------------------------------------------------------------------------- /src/components/GameControlButtonsPanel/index.js: -------------------------------------------------------------------------------- 1 | export * from './GameControlButtonsPanel'; 2 | export { default } from './GameControlButtonsPanel'; 3 | -------------------------------------------------------------------------------- /src/components/GameGrid/GameGrid.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | import WordButton from "../WordButton"; 4 | 5 | import * as styles from "./GameGrid.module.css"; 6 | 7 | import { useSpring, animated } from "react-spring"; 8 | import { PuzzleDataContext } from "../../providers/PuzzleDataProvider"; 9 | import { GameStatusContext } from "../../providers/GameStatusProvider"; 10 | 11 | import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover"; 12 | import { Badge } from "../ui/badge"; 13 | 14 | function WordRow({ words }) { 15 | return ( 16 |
17 | {words.map((word) => ( 18 | 19 | ))} 20 |
21 | ); 22 | } 23 | 24 | export function SolvedWordRow({ ...props }) { 25 | const DIFFICULTY_COLOR_MAP = { 26 | 1: "rgb(74 222 128)", // green 27 | 2: "rgb(251 191 36)", // amber 28 | 3: "rgb(129 140 248)", //indigo 29 | 4: "rgb(34 211 238)", //cyan 30 | }; 31 | 32 | const color = `${DIFFICULTY_COLOR_MAP[props.difficulty]}`; 33 | 34 | const [hasBeenClicked, setHasBeenClicked] = React.useState(false); 35 | 36 | const springProps = useSpring({ 37 | from: { 38 | opacity: 0, 39 | transform: "translateY(100%)", 40 | }, 41 | to: { 42 | opacity: 1, 43 | transform: "translateY(0%)", 44 | }, 45 | delay: 250, 46 | }); 47 | // if there is an image available render it as a popover 48 | const isImageAvailable = props.imageSrc != null; 49 | return ( 50 | 51 | {!isImageAvailable ? ( 52 |
53 |

{props.category}

54 |

{props.words.join(", ")}

55 |
56 | ) : ( 57 | 58 | 59 |
setHasBeenClicked(true)} 63 | > 64 | {!hasBeenClicked && ( 65 | 66 | View More 67 | 68 | )} 69 |

{props.category}

70 |

{props.words.join(", ")}

71 |
72 |
73 | 74 |
75 | 76 |
77 |
78 |
79 | )} 80 |
81 | ); 82 | } 83 | 84 | function GameGrid({ gameRows, shouldGridShake, setShouldGridShake }) { 85 | const { submittedGuesses, isGameOver, isGameWon, solvedGameData } = 86 | React.useContext(GameStatusContext); 87 | 88 | const { gameData } = React.useContext(PuzzleDataContext); 89 | 90 | React.useEffect(() => { 91 | const shakeEffect = window.setTimeout(() => { 92 | setShouldGridShake(false); 93 | // this timeout should probably be calculated since it depends on animation values for the grid shake 94 | }, 2000); 95 | 96 | // cleanup timeout 97 | return () => window.clearTimeout(shakeEffect); 98 | }, [submittedGuesses]); 99 | 100 | const isGameOverAndLost = isGameOver && !isGameWon; 101 | const isGameOverAndWon = isGameOver && isGameWon; 102 | const isGameActive = !isGameOver; 103 | const isGameActiveWithAnySolvedRows = 104 | isGameActive && solvedGameData.length > 0; 105 | 106 | return ( 107 |
108 | {(isGameOverAndWon || isGameActiveWithAnySolvedRows) && ( 109 |
110 | {solvedGameData.map((solvedRowObj) => ( 111 | 112 | ))} 113 |
114 | )} 115 | {isGameActive && ( 116 |
117 | {gameRows.map((row, idx) => ( 118 | 119 | ))} 120 |
121 | )} 122 | {/* Show correct answers here after the game is over if they lost */} 123 | {isGameOverAndLost && ( 124 |
125 |

The answer categories are below.

126 | {gameData.map((obj) => ( 127 | 128 | ))} 129 |
130 | )} 131 |
132 | ); 133 | } 134 | 135 | export default GameGrid; 136 | -------------------------------------------------------------------------------- /src/components/GameGrid/GameGrid.module.css: -------------------------------------------------------------------------------- 1 | .shake { 2 | animation-name: tilt-shaking; 3 | animation-duration: 0.1s; 4 | animation-delay: 0.2s; 5 | animation-iteration-count: 5; 6 | } 7 | 8 | @keyframes shake-horizontal { 9 | 0% { 10 | transform: translateX(0%); 11 | } 12 | 13 | 25% { 14 | transform: translateX(-1%); 15 | } 16 | 17 | 50% { 18 | transform: translateX(1%); 19 | } 20 | 21 | 75% { 22 | transform: translateX(-1%); 23 | } 24 | 25 | 100% { 26 | transform: translateX(0%); 27 | } 28 | } 29 | 30 | @keyframes tilt-shaking { 31 | 0% { 32 | transform: rotate(0deg); 33 | } 34 | 25% { 35 | transform: rotate(1deg); 36 | } 37 | 50% { 38 | transform: rotate(0deg); 39 | } 40 | 75% { 41 | transform: rotate(-1deg); 42 | } 43 | 100% { 44 | transform: rotate(0deg); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/components/GameGrid/index.js: -------------------------------------------------------------------------------- 1 | export * from './GameGrid'; 2 | export { default } from './GameGrid'; 3 | -------------------------------------------------------------------------------- /src/components/Header/Header.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | import InfoModal from "../modals/InfoModal"; 4 | 5 | function Header() { 6 | return ( 7 |
8 |

Black Connections

9 | 10 |
11 | ); 12 | } 13 | 14 | export default Header; 15 | -------------------------------------------------------------------------------- /src/components/Header/index.js: -------------------------------------------------------------------------------- 1 | export * from './Header'; 2 | export { default } from './Header'; 3 | -------------------------------------------------------------------------------- /src/components/NumberOfMistakesDisplay/NumberOfMistakesDisplay.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { range } from "../../lib/utils"; 3 | import { Circle, CircleSlash } from "lucide-react"; 4 | import { MAX_MISTAKES } from "../../lib/constants"; 5 | import { GameStatusContext } from "../../providers/GameStatusProvider"; 6 | 7 | function SingleMistakeDisplay({ isUsed }) { 8 | return ( 9 |
10 | {isUsed ? ( 11 | 12 | ) : ( 13 | 14 | )} 15 |
16 | ); 17 | } 18 | 19 | function NumberOfMistakesDisplay() { 20 | const { numMistakesUsed } = React.useContext(GameStatusContext); 21 | // array size of number of guess. [1, 2, 3, 4] 22 | const mistakeRange = range(MAX_MISTAKES); 23 | return ( 24 |
25 |

Mistakes Remaining:

26 | {mistakeRange.map((el) => ( 27 | 28 | ))} 29 |
30 | ); 31 | } 32 | 33 | export default NumberOfMistakesDisplay; 34 | -------------------------------------------------------------------------------- /src/components/NumberOfMistakesDisplay/index.js: -------------------------------------------------------------------------------- 1 | export * from "./NumberOfMistakesDisplay"; 2 | export { default } from "./NumberOfMistakesDisplay"; 3 | -------------------------------------------------------------------------------- /src/components/ShareScoreButton/ShareScoreButton.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { cn } from "../../lib/utils"; 3 | import Sparkles from "../Sparkles"; 4 | import { Button } from "../ui/button"; 5 | import { useToast } from "../ui/use-toast"; 6 | import { shareStatus } from "../../lib/share-game"; 7 | import { GameStatusContext } from "../../providers/GameStatusProvider"; 8 | import { PuzzleDataContext } from "../../providers/PuzzleDataProvider"; 9 | 10 | function ShareScoreButton({ buttonText = "Share", className = "" }) { 11 | const { gameData } = React.useContext(PuzzleDataContext); 12 | const { submittedGuesses } = React.useContext(GameStatusContext); 13 | const { toast } = useToast(); 14 | function handleShareToClipboard() { 15 | toast({ 16 | label: "Notification", 17 | title: "", 18 | description: "Copied to clipboard!", 19 | }); 20 | } 21 | function handleShareFailure() { 22 | toast({ 23 | label: "Notification", 24 | title: "", 25 | description: "Was unable to copy to clipboard / share.", 26 | }); 27 | } 28 | return ( 29 | 30 | 45 | 46 | ); 47 | } 48 | 49 | export default ShareScoreButton; 50 | -------------------------------------------------------------------------------- /src/components/ShareScoreButton/index.js: -------------------------------------------------------------------------------- 1 | export * from './ShareScoreButton'; 2 | export { default } from './ShareScoreButton'; 3 | -------------------------------------------------------------------------------- /src/components/Sparkles/Sparkles.js: -------------------------------------------------------------------------------- 1 | // https://www.joshwcomeau.com/react/animated-sparkles-in-react/ 2 | 3 | import React from "react"; 4 | import styled, { keyframes } from "styled-components"; 5 | 6 | import { range, random } from "../../lib/utils"; 7 | import usePrefersReducedMotion from "../../hooks/use-prefers-reduced-motion.hook"; 8 | import useRandomInterval from "../../hooks/use-random-interval.hook"; 9 | 10 | const DEFAULT_COLOR = "#FFC700"; 11 | const generateSparkle = (color) => { 12 | const sparkle = { 13 | id: String(random(10000, 99999)), 14 | createdAt: Date.now(), 15 | color, 16 | size: random(10, 20), 17 | style: { 18 | top: random(0, 100) + "%", 19 | left: random(0, 100) + "%", 20 | zIndex: 3, 21 | }, 22 | }; 23 | return sparkle; 24 | }; 25 | const Sparkles = ({ color = DEFAULT_COLOR, children, ...delegated }) => { 26 | const [sparkles, setSparkles] = React.useState(() => { 27 | return range(3).map(() => generateSparkle(color)); 28 | }); 29 | const prefersReducedMotion = usePrefersReducedMotion(); 30 | useRandomInterval( 31 | () => { 32 | const sparkle = generateSparkle(color); 33 | const now = Date.now(); 34 | const nextSparkles = sparkles.filter((sp) => { 35 | const delta = now - sp.createdAt; 36 | return delta < 750; 37 | }); 38 | nextSparkles.push(sparkle); 39 | setSparkles(nextSparkles); 40 | }, 41 | prefersReducedMotion ? null : 50, 42 | prefersReducedMotion ? null : 450 43 | ); 44 | return ( 45 | 46 | {sparkles.map((sparkle) => ( 47 | 53 | ))} 54 | {children} 55 | 56 | ); 57 | }; 58 | const Sparkle = ({ size, color, style }) => { 59 | const path = 60 | "M26.5 25.5C19.0043 33.3697 0 34 0 34C0 34 19.1013 35.3684 26.5 43.5C33.234 50.901 34 68 34 68C34 68 36.9884 50.7065 44.5 43.5C51.6431 36.647 68 34 68 34C68 34 51.6947 32.0939 44.5 25.5C36.5605 18.2235 34 0 34 0C34 0 33.6591 17.9837 26.5 25.5Z"; 61 | return ( 62 | 63 | 64 | 65 | 66 | 67 | ); 68 | }; 69 | const comeInOut = keyframes` 70 | 0% { 71 | transform: scale(0); 72 | } 73 | 50% { 74 | transform: scale(1); 75 | } 76 | 100% { 77 | transform: scale(0); 78 | } 79 | `; 80 | const spin = keyframes` 81 | 0% { 82 | transform: rotate(0deg); 83 | } 84 | 100% { 85 | transform: rotate(180deg); 86 | } 87 | `; 88 | const Wrapper = styled.span` 89 | display: inline-block; 90 | position: relative; 91 | `; 92 | const SparkleWrapper = styled.span` 93 | position: absolute; 94 | display: block; 95 | pointer-events: none; 96 | @media (prefers-reduced-motion: no-preference) { 97 | animation: ${comeInOut} 700ms forwards; 98 | } 99 | `; 100 | const SparkleSvg = styled.svg` 101 | display: block; 102 | @media (prefers-reduced-motion: no-preference) { 103 | animation: ${spin} 1000ms linear; 104 | } 105 | `; 106 | const ChildWrapper = styled.strong` 107 | position: relative; 108 | z-index: 1; 109 | font-weight: bold; 110 | `; 111 | 112 | export default Sparkles; 113 | -------------------------------------------------------------------------------- /src/components/Sparkles/index.js: -------------------------------------------------------------------------------- 1 | export * from './Sparkles'; 2 | export { default } from './Sparkles'; 3 | -------------------------------------------------------------------------------- /src/components/WordButton/WordButton.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import * as styles from "./WordButton.module.css"; 3 | import { Toggle } from "../ui/toggle"; 4 | 5 | import { GameStatusContext } from "../../providers/GameStatusProvider"; 6 | 7 | function WordButton({ word, fullCandidateSize }) { 8 | const { guessCandidate, setGuessCandidate } = 9 | React.useContext(GameStatusContext); 10 | const [isSelected, setIsSelected] = React.useState( 11 | !!guessCandidate.includes(word) 12 | ); 13 | 14 | const isCandidateListFull = guessCandidate.length == fullCandidateSize; 15 | 16 | React.useEffect(() => { 17 | setIsSelected(!!guessCandidate.includes(word)); 18 | }, [guessCandidate]); 19 | 20 | function flipSelection() { 21 | if (isSelected) { 22 | // remove from candidateGuess 23 | const updatedGuessCandidate = guessCandidate.filter((w) => { 24 | return w !== word; 25 | }); 26 | setGuessCandidate(updatedGuessCandidate); 27 | // set state to *not* selected 28 | setIsSelected(false); 29 | } else { 30 | // check if the candidate array is full 31 | if (!isCandidateListFull) { 32 | // add to candidateGuess array 33 | setGuessCandidate([...guessCandidate, word]); 34 | // set state to *selected* 35 | setIsSelected(true); 36 | } 37 | } 38 | } 39 | 40 | //const fontSizeByWordLength = 9characters works with 0.6rem 41 | 42 | function getFontSize(word) { 43 | const baseLength = 7; 44 | const wordLength = word.length; 45 | let fontSize = 1; 46 | if (wordLength > baseLength) { 47 | const numExtraChars = wordLength - baseLength; 48 | fontSize = fontSize - numExtraChars * 0.1; 49 | fontSize = Math.max(0.5, fontSize); 50 | return `${fontSize}em`; 51 | } else { 52 | return null; 53 | } 54 | } 55 | // word = "washingtonian"; 56 | return ( 57 | 63 |

67 | {word} 68 |

69 |
70 | ); 71 | } 72 | 73 | export default WordButton; 74 | -------------------------------------------------------------------------------- /src/components/WordButton/WordButton.module.css: -------------------------------------------------------------------------------- 1 | .selected { 2 | border: 2px solid black; 3 | } 4 | 5 | .growShrink { 6 | /*Tell this element which properties to animate if something changes 7 | We are saying all properties will animate when changed seconds*/ 8 | transition: all 0.4s; 9 | } 10 | 11 | .growShrink[data-state="on"] { 12 | transform: scale(1.05); 13 | } 14 | 15 | /* .button { 16 | padding: 8px 8px; 17 | gap: 4px; 18 | border: none; 19 | border-radius: 4px; 20 | background: gray; 21 | color: white; 22 | font-weight: 600; 23 | font-size: 1.25rem; 24 | cursor: pointer; 25 | outline-offset: 4px; 26 | } 27 | 28 | .item:hover { 29 | cursor: pointer; 30 | } 31 | 32 | .item { 33 | width: 24px; 34 | max-width: 48px; 35 | min-width: 20px; 36 | min-height: 70px; 37 | height: 22.5vw; 38 | max-height: 22.5vw; 39 | font-size: 15px; 40 | background-color: grey; 41 | color: black; 42 | outline: none; 43 | text-align: center; 44 | font-family: "NYT-Franklin"; 45 | font-weight: bold; 46 | border-radius: 6px; 47 | z-index: 0; 48 | position: absolute; 49 | transition: opacity 0.4s ease; 50 | } */ 51 | -------------------------------------------------------------------------------- /src/components/WordButton/index.js: -------------------------------------------------------------------------------- 1 | export * from './WordButton'; 2 | export { default } from './WordButton'; 3 | -------------------------------------------------------------------------------- /src/components/modals/BaseModal/BaseModal.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | import { 4 | AlertDialog, 5 | AlertDialogAction, 6 | AlertDialogCancel, 7 | AlertDialogContent, 8 | AlertDialogDescription, 9 | AlertDialogFooter, 10 | AlertDialogHeader, 11 | AlertDialogTitle, 12 | AlertDialogTrigger, 13 | } from "../../ui/alert-dialog"; 14 | 15 | function BaseModal({ 16 | title = "title", 17 | trigger = undefined, 18 | initiallyOpen = true, 19 | footerElements, 20 | children, 21 | actionButtonText = "Continue", 22 | showActionButton = true, 23 | }) { 24 | const [isOpen, setIsOpen] = React.useState(initiallyOpen); 25 | 26 | React.useEffect(() => { 27 | setIsOpen(initiallyOpen); 28 | }, [initiallyOpen]); 29 | 30 | function handleCloseEvent() { 31 | setIsOpen(false); 32 | } 33 | 34 | return ( 35 | 36 | {!!trigger && {trigger}} 37 | { 41 | e.preventDefault(); 42 | }} 43 | > 44 | 45 | {title} 46 | {children} 47 | 48 | 49 | {footerElements} 50 | {showActionButton && ( 51 | setIsOpen(false)}> 52 | {actionButtonText} 53 | 54 | )} 55 | 56 | 57 | 58 | ); 59 | } 60 | 61 | export default BaseModal; 62 | -------------------------------------------------------------------------------- /src/components/modals/BaseModal/index.js: -------------------------------------------------------------------------------- 1 | export * from './BaseModal'; 2 | export { default } from './BaseModal'; 3 | -------------------------------------------------------------------------------- /src/components/modals/GameLostModal/GameLostModal.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import BaseModal from "../BaseModal"; 3 | import { SolvedWordRow } from "../../GameGrid"; 4 | import ShareScoreButton from "../../ShareScoreButton"; 5 | import CountdownToNextPuzzle from "../../CountdownToNextPuzzle"; 6 | import { PuzzleDataContext } from "../../../providers/PuzzleDataProvider"; 7 | 8 | function GameLostModal({ open }) { 9 | const { gameData } = React.useContext(PuzzleDataContext); 10 | 11 | return ( 12 | } 16 | showActionButton={false} 17 | > 18 |
19 |

20 | Better luck next time. The correct answers are below. 21 |

22 | {gameData.map((obj) => ( 23 | 24 | ))} 25 |
26 | 27 |
28 | ); 29 | } 30 | 31 | export default GameLostModal; 32 | -------------------------------------------------------------------------------- /src/components/modals/GameLostModal/index.js: -------------------------------------------------------------------------------- 1 | export * from './GameLostModal'; 2 | export { default } from './GameLostModal'; 3 | -------------------------------------------------------------------------------- /src/components/modals/GameWonModal/GameWonModal.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import BaseModal from "../BaseModal"; 3 | 4 | import { generateEmojiGrid } from "../../../lib/game-helpers"; 5 | import ShareScoreButton from "../../ShareScoreButton"; 6 | import CountdownToNextPuzzle from "../../CountdownToNextPuzzle"; 7 | import { PuzzleDataContext } from "../../../providers/PuzzleDataProvider"; 8 | 9 | function GameWonModal({ open, submittedGuesses }) { 10 | const { gameData } = React.useContext(PuzzleDataContext); 11 | 12 | return ( 13 | } 17 | showActionButton={false} 18 | > 19 |

{"Great job, share your results!"}

20 |
21 | {/* the whitespace: pre style makes the emoji grid appear with new lines character */} 22 | 23 | {"\n"} 24 | {generateEmojiGrid(gameData, submittedGuesses)} 25 | 26 | 27 |
28 |
29 | ); 30 | } 31 | 32 | export default GameWonModal; 33 | -------------------------------------------------------------------------------- /src/components/modals/GameWonModal/index.js: -------------------------------------------------------------------------------- 1 | export * from './GameWonModal'; 2 | export { default } from './GameWonModal'; 3 | -------------------------------------------------------------------------------- /src/components/modals/InfoModal/InfoModal.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { MAX_MISTAKES } from "../../../lib/constants"; 3 | import { Info } from "lucide-react"; 4 | import { Tabs, TabsContent, TabsList, TabsTrigger } from "../../ui/tabs"; 5 | import { 6 | Accordion, 7 | AccordionContent, 8 | AccordionItem, 9 | AccordionTrigger, 10 | } from "../../ui/accordion"; 11 | import BaseModal from "../BaseModal"; 12 | 13 | function InfoModal() { 14 | return ( 15 | } 18 | initiallyOpen={false} 19 | actionButtonText="Got It!" 20 | > 21 | 22 | 23 | How To Play 24 | About Us 25 | 26 | 27 | {" "} 28 | 29 | 30 | What's The Goal? 31 | 32 | Find groups of items or names that share something in common. 33 | 34 | 35 | 36 | How Do I Play? 37 | 38 | Select the items and tap 'Submit' to check if your guess matches 39 | one of the answer categories. 40 | 41 | 42 | 43 | How Many Tries Do I Get? 44 | 45 | {`You can make ${MAX_MISTAKES} mistakes before the game ends.`} 46 | 47 | 48 | 49 | 50 | 51 | {" "} 52 | 53 | 54 | Who Are Y'all? 55 | 56 | This project is brought to you by andcomputers, feel free to 57 | subscribe to our writing and other experiments.{" "} 58 | 63 | Check out our writing here. 64 | 65 | 66 | 67 | 68 | How Can I Support? 69 | 70 |

If you'd like to support feel free!

71 | 110 |
111 |
112 | 113 | 114 | Any Other Projects to Check Out? 115 | 116 | 117 | 141 | 142 | 143 |
144 |
145 |
146 |
147 | ); 148 | } 149 | 150 | export default InfoModal; 151 | -------------------------------------------------------------------------------- /src/components/modals/InfoModal/index.js: -------------------------------------------------------------------------------- 1 | export * from './InfoModal'; 2 | export { default } from './InfoModal'; 3 | -------------------------------------------------------------------------------- /src/components/modals/ViewResultsModal/ViewResultsModal.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | import { generateEmojiGrid } from "../../../lib/game-helpers"; 4 | import CountdownToNextPuzzle from "../../CountdownToNextPuzzle"; 5 | import ShareScoreButton from "../../ShareScoreButton"; 6 | import BaseModal from "../BaseModal"; 7 | import { GameStatusContext } from "../../../providers/GameStatusProvider"; 8 | import { PuzzleDataContext } from "../../../providers/PuzzleDataProvider"; 9 | import { Button } from "../../ui/button"; 10 | 11 | function ViewResultsModal() { 12 | const { submittedGuesses } = React.useContext(GameStatusContext); 13 | const { gameData } = React.useContext(PuzzleDataContext); 14 | 15 | return ( 16 | 20 | } 21 | initiallyOpen={false} 22 | showActionButton={false} 23 | footerElements={} 24 | > 25 |
26 |

27 | Your Guesses Are Represented Below 28 |

29 | 30 | {"\n"} 31 | {generateEmojiGrid(gameData, submittedGuesses)} 32 | 33 | 34 |
35 |
36 | ); 37 | } 38 | 39 | export default ViewResultsModal; 40 | -------------------------------------------------------------------------------- /src/components/modals/ViewResultsModal/index.js: -------------------------------------------------------------------------------- 1 | export * from './ViewResultsModal'; 2 | export { default } from './ViewResultsModal'; 3 | -------------------------------------------------------------------------------- /src/components/ui/accordion.jsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import * as AccordionPrimitive from "@radix-ui/react-accordion"; 3 | import { ChevronDown } from "lucide-react"; 4 | 5 | import { cn } from "../../lib/utils"; 6 | 7 | const Accordion = AccordionPrimitive.Root; 8 | 9 | const AccordionItem = React.forwardRef(({ className, ...props }, ref) => ( 10 | 15 | )); 16 | AccordionItem.displayName = "AccordionItem"; 17 | 18 | const AccordionTrigger = React.forwardRef( 19 | ({ className, children, ...props }, ref) => ( 20 | 21 | svg]:rotate-180", 25 | className 26 | )} 27 | {...props} 28 | > 29 | {children} 30 | 31 | 32 | 33 | ) 34 | ); 35 | AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName; 36 | 37 | const AccordionContent = React.forwardRef( 38 | ({ className, children, ...props }, ref) => ( 39 | 47 |
{children}
48 |
49 | ) 50 | ); 51 | AccordionContent.displayName = AccordionPrimitive.Content.displayName; 52 | 53 | export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }; 54 | -------------------------------------------------------------------------------- /src/components/ui/alert-dialog.jsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog"; 3 | 4 | import { cn } from "../../lib/utils"; 5 | import { buttonVariants } from "./button"; 6 | 7 | const AlertDialog = AlertDialogPrimitive.Root; 8 | 9 | const AlertDialogTrigger = AlertDialogPrimitive.Trigger; 10 | 11 | const AlertDialogPortal = AlertDialogPrimitive.Portal; 12 | 13 | const AlertDialogOverlay = React.forwardRef( 14 | ({ className, children, ...props }, ref) => ( 15 | 23 | ) 24 | ); 25 | AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName; 26 | 27 | const AlertDialogContent = React.forwardRef( 28 | ({ className, handleMouseDownOnOverlay, ...props }, ref) => ( 29 | 30 | 31 | 39 | 40 | ) 41 | ); 42 | AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName; 43 | 44 | const AlertDialogHeader = ({ className, ...props }) => ( 45 |
52 | ); 53 | AlertDialogHeader.displayName = "AlertDialogHeader"; 54 | 55 | const AlertDialogFooter = ({ className, ...props }) => ( 56 |
60 | ); 61 | AlertDialogFooter.displayName = "AlertDialogFooter"; 62 | 63 | const AlertDialogTitle = React.forwardRef(({ className, ...props }, ref) => ( 64 | 69 | )); 70 | AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName; 71 | 72 | const AlertDialogDescription = React.forwardRef( 73 | ({ className, ...props }, ref) => ( 74 | 79 | ) 80 | ); 81 | AlertDialogDescription.displayName = 82 | AlertDialogPrimitive.Description.displayName; 83 | 84 | const AlertDialogAction = React.forwardRef(({ className, ...props }, ref) => ( 85 | 90 | )); 91 | AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName; 92 | 93 | const AlertDialogCancel = React.forwardRef(({ className, ...props }, ref) => ( 94 | 103 | )); 104 | AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName; 105 | 106 | export { 107 | AlertDialog, 108 | AlertDialogPortal, 109 | AlertDialogOverlay, 110 | AlertDialogTrigger, 111 | AlertDialogContent, 112 | AlertDialogHeader, 113 | AlertDialogFooter, 114 | AlertDialogTitle, 115 | AlertDialogDescription, 116 | AlertDialogAction, 117 | AlertDialogCancel, 118 | }; 119 | -------------------------------------------------------------------------------- /src/components/ui/badge.jsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import { cva } from "class-variance-authority"; 3 | 4 | import { cn } from "../../lib/utils"; 5 | 6 | const badgeVariants = cva( 7 | "inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2", 8 | { 9 | variants: { 10 | variant: { 11 | default: 12 | "border-transparent bg-primary text-primary-foreground hover:bg-primary/80", 13 | secondary: 14 | "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80", 15 | destructive: 16 | "border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80", 17 | outline: "text-foreground", 18 | }, 19 | }, 20 | defaultVariants: { 21 | variant: "default", 22 | }, 23 | } 24 | ); 25 | 26 | function Badge({ className, variant, ...props }) { 27 | return ( 28 |
29 | ); 30 | } 31 | 32 | export { Badge, badgeVariants }; 33 | -------------------------------------------------------------------------------- /src/components/ui/button.jsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import { Slot } from "@radix-ui/react-slot"; 3 | import { cva } from "class-variance-authority"; 4 | 5 | import { cn } from "../../lib/utils"; 6 | 7 | const buttonVariants = cva( 8 | "inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-30", 9 | { 10 | variants: { 11 | variant: { 12 | default: "bg-primary text-primary-foreground hover:bg-primary/90", 13 | destructive: 14 | "bg-destructive text-destructive-foreground hover:bg-destructive/90", 15 | submit: 16 | "bg-slate-500 text-destructive-foreground hover:bg-slate-500/90", 17 | outline: 18 | "border border-input bg-background hover:bg-accent hover:text-accent-foreground", 19 | secondary: 20 | "bg-secondary text-secondary-foreground hover:bg-secondary/80", 21 | ghost: "hover:bg-accent hover:text-accent-foreground", 22 | link: "text-primary underline-offset-4 hover:underline", 23 | share: "border-solid bg-fuchsia-400 basis-1/2 hover:bg-fuchsia-400/80", 24 | }, 25 | size: { 26 | default: "h-10 px-4 py-2", 27 | sm: "h-9 rounded-md px-3", 28 | lg: "h-11 rounded-md px-8", 29 | deselectallsize: "h-10 py-2", 30 | icon: "h-10 w-10", 31 | }, 32 | }, 33 | defaultVariants: { 34 | variant: "default", 35 | size: "default", 36 | }, 37 | } 38 | ); 39 | 40 | const Button = React.forwardRef( 41 | ({ className, variant, size, asChild = false, ...props }, ref) => { 42 | const Comp = asChild ? Slot : "button"; 43 | return ( 44 | 49 | ); 50 | } 51 | ); 52 | Button.displayName = "Button"; 53 | 54 | export { Button, buttonVariants }; 55 | -------------------------------------------------------------------------------- /src/components/ui/popover.jsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import * as PopoverPrimitive from "@radix-ui/react-popover" 3 | 4 | import { cn } from "../../lib/utils" 5 | 6 | const Popover = PopoverPrimitive.Root 7 | 8 | const PopoverTrigger = PopoverPrimitive.Trigger 9 | 10 | const PopoverContent = React.forwardRef(({ className, align = "center", sideOffset = 4, ...props }, ref) => ( 11 | 12 | 21 | 22 | )) 23 | PopoverContent.displayName = PopoverPrimitive.Content.displayName 24 | 25 | export { Popover, PopoverTrigger, PopoverContent } 26 | -------------------------------------------------------------------------------- /src/components/ui/separator.jsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import * as SeparatorPrimitive from "@radix-ui/react-separator"; 3 | 4 | import { cn } from "../../lib/utils"; 5 | 6 | const Separator = React.forwardRef( 7 | ( 8 | { className, orientation = "horizontal", decorative = true, ...props }, 9 | ref 10 | ) => ( 11 | 22 | ) 23 | ); 24 | Separator.displayName = SeparatorPrimitive.Root.displayName; 25 | 26 | export { Separator }; 27 | -------------------------------------------------------------------------------- /src/components/ui/tabs.jsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import * as TabsPrimitive from "@radix-ui/react-tabs"; 3 | 4 | import { cn } from "../../lib/utils"; 5 | 6 | const Tabs = TabsPrimitive.Root; 7 | 8 | const TabsList = React.forwardRef(({ className, ...props }, ref) => ( 9 | 17 | )); 18 | TabsList.displayName = TabsPrimitive.List.displayName; 19 | 20 | const TabsTrigger = React.forwardRef(({ className, ...props }, ref) => ( 21 | 29 | )); 30 | TabsTrigger.displayName = TabsPrimitive.Trigger.displayName; 31 | 32 | const TabsContent = React.forwardRef(({ className, ...props }, ref) => ( 33 | 41 | )); 42 | TabsContent.displayName = TabsPrimitive.Content.displayName; 43 | 44 | export { Tabs, TabsList, TabsTrigger, TabsContent }; 45 | -------------------------------------------------------------------------------- /src/components/ui/toast.jsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import * as ToastPrimitives from "@radix-ui/react-toast"; 3 | import * as Portal from "@radix-ui/react-portal"; 4 | import { cva } from "class-variance-authority"; 5 | import { X } from "lucide-react"; 6 | 7 | import { cn } from "../../lib/utils"; 8 | 9 | const ToastProvider = ToastPrimitives.Provider; 10 | 11 | const ToastViewport = React.forwardRef(({ className, ...props }, ref) => ( 12 | 13 | 21 | 22 | )); 23 | ToastViewport.displayName = ToastPrimitives.Viewport.displayName; 24 | 25 | const toastVariants = cva( 26 | "group pointer-events-auto z-160 relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full", 27 | { 28 | variants: { 29 | variant: { 30 | default: "border bg-background text-foreground", 31 | destructive: 32 | "destructive group border-destructive bg-destructive text-destructive-foreground", 33 | }, 34 | }, 35 | defaultVariants: { 36 | variant: "default", 37 | }, 38 | } 39 | ); 40 | 41 | const Toast = React.forwardRef(({ className, variant, ...props }, ref) => { 42 | return ( 43 | 48 | ); 49 | }); 50 | Toast.displayName = ToastPrimitives.Root.displayName; 51 | 52 | const ToastAction = React.forwardRef(({ className, ...props }, ref) => ( 53 | 61 | )); 62 | ToastAction.displayName = ToastPrimitives.Action.displayName; 63 | 64 | const ToastClose = React.forwardRef(({ className, ...props }, ref) => ( 65 | 74 | 75 | 76 | )); 77 | ToastClose.displayName = ToastPrimitives.Close.displayName; 78 | 79 | const ToastTitle = React.forwardRef(({ className, ...props }, ref) => ( 80 | 85 | )); 86 | ToastTitle.displayName = ToastPrimitives.Title.displayName; 87 | 88 | const ToastDescription = React.forwardRef(({ className, ...props }, ref) => ( 89 | 94 | )); 95 | ToastDescription.displayName = ToastPrimitives.Description.displayName; 96 | 97 | export { 98 | ToastProvider, 99 | ToastViewport, 100 | Toast, 101 | ToastTitle, 102 | ToastDescription, 103 | ToastClose, 104 | ToastAction, 105 | }; 106 | -------------------------------------------------------------------------------- /src/components/ui/toaster.jsx: -------------------------------------------------------------------------------- 1 | import { 2 | Toast, 3 | ToastClose, 4 | ToastDescription, 5 | ToastProvider, 6 | ToastTitle, 7 | ToastViewport, 8 | } from "./toast"; 9 | import { useToast } from "./use-toast"; 10 | 11 | export function Toaster() { 12 | const { toasts } = useToast(); 13 | 14 | return ( 15 | 16 | {toasts.map(function ({ id, title, description, action, ...props }) { 17 | return ( 18 | 19 |
20 | {title && {title}} 21 | {description && ( 22 | {description} 23 | )} 24 |
25 | {action} 26 | 27 |
28 | ); 29 | })} 30 | 31 |
32 | ); 33 | } 34 | -------------------------------------------------------------------------------- /src/components/ui/toggle.jsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import * as TogglePrimitive from "@radix-ui/react-toggle"; 3 | import { cva } from "class-variance-authority"; 4 | 5 | import { cn } from "../../lib/utils"; 6 | 7 | const toggleVariants = cva( 8 | "inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors lg:hover:bg-muted lg:hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-slate-300/70 data-[state=on]:text-accent-foreground", 9 | { 10 | variants: { 11 | variant: { 12 | default: "bg-transparent", 13 | outline: 14 | "border-solid border border-input bg-transparent lg:hover:bg-accent lg:hover:text-accent-foreground", 15 | }, 16 | size: { 17 | default: "h-10 px-3", 18 | sm: "h-9 px-2.5", 19 | lg: "h-11 px-5", 20 | }, 21 | }, 22 | defaultVariants: { 23 | variant: "default", 24 | size: "default", 25 | }, 26 | } 27 | ); 28 | 29 | const Toggle = React.forwardRef( 30 | ({ className, variant, size, ...props }, ref) => ( 31 | 36 | ) 37 | ); 38 | 39 | Toggle.displayName = TogglePrimitive.Root.displayName; 40 | 41 | export { Toggle, toggleVariants }; 42 | -------------------------------------------------------------------------------- /src/components/ui/use-toast.js: -------------------------------------------------------------------------------- 1 | // Inspired by react-hot-toast library 2 | import * as React from "react" 3 | 4 | const TOAST_LIMIT = 1 5 | const TOAST_REMOVE_DELAY = 1000000 6 | 7 | const actionTypes = { 8 | ADD_TOAST: "ADD_TOAST", 9 | UPDATE_TOAST: "UPDATE_TOAST", 10 | DISMISS_TOAST: "DISMISS_TOAST", 11 | REMOVE_TOAST: "REMOVE_TOAST" 12 | } 13 | 14 | let count = 0 15 | 16 | function genId() { 17 | count = (count + 1) % Number.MAX_VALUE 18 | return count.toString(); 19 | } 20 | 21 | const toastTimeouts = new Map() 22 | 23 | const addToRemoveQueue = (toastId) => { 24 | if (toastTimeouts.has(toastId)) { 25 | return 26 | } 27 | 28 | const timeout = setTimeout(() => { 29 | toastTimeouts.delete(toastId) 30 | dispatch({ 31 | type: "REMOVE_TOAST", 32 | toastId: toastId, 33 | }) 34 | }, TOAST_REMOVE_DELAY) 35 | 36 | toastTimeouts.set(toastId, timeout) 37 | } 38 | 39 | export const reducer = (state, action) => { 40 | switch (action.type) { 41 | case "ADD_TOAST": 42 | return { 43 | ...state, 44 | toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT), 45 | }; 46 | 47 | case "UPDATE_TOAST": 48 | return { 49 | ...state, 50 | toasts: state.toasts.map((t) => 51 | t.id === action.toast.id ? { ...t, ...action.toast } : t), 52 | }; 53 | 54 | case "DISMISS_TOAST": { 55 | const { toastId } = action 56 | 57 | // ! Side effects ! - This could be extracted into a dismissToast() action, 58 | // but I'll keep it here for simplicity 59 | if (toastId) { 60 | addToRemoveQueue(toastId) 61 | } else { 62 | state.toasts.forEach((toast) => { 63 | addToRemoveQueue(toast.id) 64 | }) 65 | } 66 | 67 | return { 68 | ...state, 69 | toasts: state.toasts.map((t) => 70 | t.id === toastId || toastId === undefined 71 | ? { 72 | ...t, 73 | open: false, 74 | } 75 | : t), 76 | }; 77 | } 78 | case "REMOVE_TOAST": 79 | if (action.toastId === undefined) { 80 | return { 81 | ...state, 82 | toasts: [], 83 | } 84 | } 85 | return { 86 | ...state, 87 | toasts: state.toasts.filter((t) => t.id !== action.toastId), 88 | }; 89 | } 90 | } 91 | 92 | const listeners = [] 93 | 94 | let memoryState = { toasts: [] } 95 | 96 | function dispatch(action) { 97 | memoryState = reducer(memoryState, action) 98 | listeners.forEach((listener) => { 99 | listener(memoryState) 100 | }) 101 | } 102 | 103 | function toast({ 104 | ...props 105 | }) { 106 | const id = genId() 107 | 108 | const update = (props) => 109 | dispatch({ 110 | type: "UPDATE_TOAST", 111 | toast: { ...props, id }, 112 | }) 113 | const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id }) 114 | 115 | dispatch({ 116 | type: "ADD_TOAST", 117 | toast: { 118 | ...props, 119 | id, 120 | open: true, 121 | onOpenChange: (open) => { 122 | if (!open) dismiss() 123 | }, 124 | }, 125 | }) 126 | 127 | return { 128 | id: id, 129 | dismiss, 130 | update, 131 | } 132 | } 133 | 134 | function useToast() { 135 | const [state, setState] = React.useState(memoryState) 136 | 137 | React.useEffect(() => { 138 | listeners.push(setState) 139 | return () => { 140 | const index = listeners.indexOf(setState) 141 | if (index > -1) { 142 | listeners.splice(index, 1) 143 | } 144 | }; 145 | }, [state]) 146 | 147 | return { 148 | ...state, 149 | toast, 150 | dismiss: (toastId) => dispatch({ type: "DISMISS_TOAST", toastId }), 151 | }; 152 | } 153 | 154 | export { useToast, toast } 155 | -------------------------------------------------------------------------------- /src/hooks/use-prefers-reduced-motion.hook.js: -------------------------------------------------------------------------------- 1 | // https://www.joshwcomeau.com/snippets/react-hooks/use-prefers-reduced-motion/ 2 | 3 | import React from "react"; 4 | 5 | const QUERY = "(prefers-reduced-motion: no-preference)"; 6 | const isRenderingOnServer = typeof window === "undefined"; 7 | const getInitialState = () => { 8 | // For our initial server render, we won't know if the user 9 | // prefers reduced motion, but it doesn't matter. This value 10 | // will be overwritten on the client, before any animations 11 | // occur. 12 | return isRenderingOnServer ? true : !window.matchMedia(QUERY).matches; 13 | }; 14 | function usePrefersReducedMotion() { 15 | const [prefersReducedMotion, setPrefersReducedMotion] = 16 | React.useState(getInitialState); 17 | React.useEffect(() => { 18 | const mediaQueryList = window.matchMedia(QUERY); 19 | const listener = (event) => { 20 | setPrefersReducedMotion(!event.matches); 21 | }; 22 | if (mediaQueryList.addEventListener) { 23 | mediaQueryList.addEventListener("change", listener); 24 | } else { 25 | mediaQueryList.addListener(listener); 26 | } 27 | return () => { 28 | if (mediaQueryList.removeEventListener) { 29 | mediaQueryList.removeEventListener("change", listener); 30 | } else { 31 | mediaQueryList.removeListener(listener); 32 | } 33 | }; 34 | }, []); 35 | return prefersReducedMotion; 36 | } 37 | export default usePrefersReducedMotion; 38 | -------------------------------------------------------------------------------- /src/hooks/use-random-interval.hook.js: -------------------------------------------------------------------------------- 1 | // Utility helper for random number generation 2 | // https://www.joshwcomeau.com/snippets/react-hooks/use-random-interval/ 3 | 4 | import React from "react"; 5 | 6 | const random = (min, max) => Math.floor(Math.random() * (max - min)) + min; 7 | const useRandomInterval = (callback, minDelay, maxDelay) => { 8 | const timeoutId = React.useRef(null); 9 | const savedCallback = React.useRef(callback); 10 | React.useEffect(() => { 11 | savedCallback.current = callback; 12 | }, [callback]); 13 | React.useEffect(() => { 14 | let isEnabled = 15 | typeof minDelay === "number" && typeof maxDelay === "number"; 16 | if (isEnabled) { 17 | const handleTick = () => { 18 | const nextTickAt = random(minDelay, maxDelay); 19 | timeoutId.current = window.setTimeout(() => { 20 | savedCallback.current(); 21 | handleTick(); 22 | }, nextTickAt); 23 | }; 24 | handleTick(); 25 | } 26 | return () => window.clearTimeout(timeoutId.current); 27 | }, [minDelay, maxDelay]); 28 | const cancel = React.useCallback(function () { 29 | window.clearTimeout(timeoutId.current); 30 | }, []); 31 | return cancel; 32 | }; 33 | 34 | export default useRandomInterval; 35 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | @layer base { 6 | :root { 7 | --background: 0 0% 100%; 8 | --foreground: 222.2 47.4% 11.2%; 9 | 10 | --muted: 210 40% 96.1%; 11 | --muted-foreground: 215.4 16.3% 46.9%; 12 | 13 | --popover: 0 0% 100%; 14 | --popover-foreground: 222.2 47.4% 11.2%; 15 | 16 | --border: 214.3 31.8% 91.4%; 17 | --input: 214.3 31.8% 91.4%; 18 | 19 | --card: 0 0% 100%; 20 | --card-foreground: 222.2 47.4% 11.2%; 21 | 22 | --primary: 222.2 47.4% 11.2%; 23 | --primary-foreground: 210 40% 98%; 24 | 25 | --secondary: 210 40% 96.1%; 26 | --secondary-foreground: 222.2 47.4% 11.2%; 27 | 28 | --accent: 210 40% 96.1%; 29 | --accent-foreground: 222.2 47.4% 11.2%; 30 | 31 | --destructive: 0 100% 50%; 32 | --destructive-foreground: 210 40% 98%; 33 | 34 | --ring: 215 20.2% 65.1%; 35 | 36 | --radius: 0.5rem; 37 | } 38 | 39 | .dark { 40 | --background: 224 71% 4%; 41 | --foreground: 213 31% 91%; 42 | 43 | --muted: 223 47% 11%; 44 | --muted-foreground: 215.4 16.3% 56.9%; 45 | 46 | --accent: 216 34% 17%; 47 | --accent-foreground: 210 40% 98%; 48 | 49 | --popover: 224 71% 4%; 50 | --popover-foreground: 215 20.2% 65.1%; 51 | 52 | --border: 216 34% 17%; 53 | --input: 216 34% 17%; 54 | 55 | --card: 224 71% 4%; 56 | --card-foreground: 213 31% 91%; 57 | 58 | --primary: 210 40% 98%; 59 | --primary-foreground: 222.2 47.4% 1.2%; 60 | 61 | --secondary: 222.2 47.4% 11.2%; 62 | --secondary-foreground: 210 40% 98%; 63 | 64 | --destructive: 0 63% 31%; 65 | --destructive-foreground: 210 40% 98%; 66 | 67 | --ring: 216 34% 17%; 68 | 69 | --radius: 0.5rem; 70 | } 71 | } 72 | 73 | @layer base { 74 | * { 75 | @apply border-border; 76 | } 77 | body { 78 | @apply bg-background text-foreground; 79 | font-feature-settings: "rlig" 1, "calt" 1; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | Connections (Black) 12 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { createRoot } from "react-dom/client"; 3 | 4 | import App from "./components/App"; 5 | 6 | import "./reset.css"; 7 | import "./styles.css"; 8 | 9 | const root = createRoot(document.querySelector("#root")); 10 | root.render(); 11 | -------------------------------------------------------------------------------- /src/lib/constants.js: -------------------------------------------------------------------------------- 1 | export const GAME_TITLE = "Black Connections"; 2 | export const MAX_MISTAKES = 4; 3 | -------------------------------------------------------------------------------- /src/lib/data.js: -------------------------------------------------------------------------------- 1 | export const CONNECTION_GAMES = [ 2 | [ 3 | { 4 | category: "Black Women Authors", 5 | words: ["Toni", "Paule", "Zora", "Alice"], 6 | difficulty: 1, 7 | imageSrc: "https://i.ibb.co/Gn36Ypb/Connections-1.png", 8 | }, 9 | { 10 | category: "Michael ____", 11 | words: ["Jackson", "Jordan", "Johnson", "Tyson"], 12 | difficulty: 2, 13 | imageSrc: "https://i.ibb.co/3B44zXX/Connections-2.png", 14 | }, 15 | { 16 | category: "Black Greek Sorority Symbols", 17 | words: ["Poodle", "Dove", "Ivy", "Pyramid"], 18 | difficulty: 3, 19 | imageSrc: "https://i.ibb.co/4MwD7zv/Connections-3.png", 20 | }, 21 | 22 | { 23 | category: "Boyz II Men", 24 | words: ["Michael", "Nathan", "Wanyá", "Shawn"], 25 | difficulty: 4, 26 | imageSrc: 27 | "https://i.ibb.co/V2vnr5P/boys2men-2-d53afdddf480401fac1204a3954aa5f6.webp", 28 | }, 29 | ], 30 | [ 31 | { 32 | category: "Countries in West Africa", 33 | words: ["Nigeria", "Cameroon", "Togo", "Benin"], 34 | difficulty: 1, 35 | }, 36 | { 37 | category: "Countries in East Africa", 38 | words: ["Tanzania", "Kenya", "Ethiopia", "Somalia"], 39 | difficulty: 2, 40 | }, 41 | { 42 | category: "Countries in North Africa", 43 | words: ["Morocco", "Algeria", "Tunisia", "Libya"], 44 | difficulty: 3, 45 | }, 46 | { 47 | category: "African Islands", 48 | words: ["Madagascar", "Mauritius", "Comoros", "Mayotte"], 49 | difficulty: 4, 50 | }, 51 | ], 52 | [ 53 | { 54 | category: "California Rappers", 55 | words: ["O'Shea", "Eric", "Lesane", "Todd"], 56 | difficulty: 1, 57 | }, 58 | { 59 | category: "Black Founded Clothing Brands", 60 | words: ["Fubu", "Phat Farm", "Enyce", "Rocawear"], 61 | difficulty: 2, 62 | }, 63 | { 64 | category: "Hair Cut Styles", 65 | words: ["Ceasar", "Wavelength", "Fade", "Taper"], 66 | difficulty: 3, 67 | }, 68 | { 69 | category: "Black Mayors", 70 | words: ["Bass", "Turner", "Adams", "Washington"], 71 | difficulty: 4, 72 | imageSrc: "https://i.ibb.co/pP1xn0Z/Connections.png", 73 | }, 74 | ], 75 | [ 76 | { 77 | category: "Church Leadership Roles", 78 | words: ["Deacon", "Elder", "Minister", "Pastor"], 79 | difficulty: 1, 80 | imageSrc: "https://d1isxmzxwhhjbk.cloudfront.net/3/Church-Roles.png", 81 | }, 82 | { 83 | category: "Synonyms for Lucky", 84 | words: ["Blessed", "Fortunate", "Favored", "Providential"], 85 | difficulty: 2, 86 | imageSrc: 87 | "https://d1isxmzxwhhjbk.cloudfront.net/3/Synonyms-for-Lucky.png", 88 | }, 89 | { 90 | category: "R&B Icons", 91 | words: ["Tyrese", "Usher", "Brandy", "Maxwell"], 92 | difficulty: 3, 93 | imageSrc: "https://d1isxmzxwhhjbk.cloudfront.net/3/R-B-Icons.png", 94 | }, 95 | 96 | { 97 | category: "Tupac's Movie Character Names", 98 | words: ["Bishop", "Lucky", "Birdie", "Tank"], 99 | difficulty: 4, 100 | imageSrc: "https://d1isxmzxwhhjbk.cloudfront.net/3/Tupac-Movie-Roles.png", 101 | }, 102 | ], 103 | [ 104 | { 105 | category: "Slang for 'A Lot'", 106 | words: ["Bare", "Mad", "Hella", "Buku"], 107 | difficulty: 1, 108 | }, 109 | { 110 | category: "Slang for 'Great'", 111 | words: ["Cold", "Raw", "Dope", "Lit"], 112 | difficulty: 2, 113 | }, 114 | { 115 | category: "Ways to Refer to Money", 116 | words: ["Brick", "Band", "Rack", "C-Note"], 117 | difficulty: 3, 118 | }, 119 | 120 | { 121 | category: "Things Needed to Make a Pizza", 122 | words: ["Cheddar", "Dough", "Sauce", "Heat"], 123 | difficulty: 4, 124 | }, 125 | ], 126 | [ 127 | { 128 | category: "Boondocks Characters", 129 | words: ["Riley", "Huey", "Jazmine", "Robert"], 130 | difficulty: 1, 131 | imageSrc: 132 | "https://d1isxmzxwhhjbk.cloudfront.net/4/Boondocks-Characters.png", 133 | }, 134 | { 135 | category: "Uncle ____", 136 | words: ["Ruckus", "Tom", "Luke", "Ben's"], 137 | difficulty: 2, 138 | imageSrc: "https://d1isxmzxwhhjbk.cloudfront.net/4/Uncle___.png", 139 | }, 140 | { 141 | category: "Bobby ____", 142 | words: ["Brown", "Womack", "Schmurda", "Valentino"], 143 | difficulty: 3, 144 | imageSrc: "https://d1isxmzxwhhjbk.cloudfront.net/4/Bobby___.png", 145 | }, 146 | { 147 | category: "Black Panther Leadership", 148 | words: ["Bobby", "Fred", "Elaine", "Kathleen"], 149 | difficulty: 4, 150 | 151 | imageSrc: "https://d1isxmzxwhhjbk.cloudfront.net/4/Black-Panthers.png", 152 | }, 153 | ], 154 | ]; 155 | -------------------------------------------------------------------------------- /src/lib/game-helpers.js: -------------------------------------------------------------------------------- 1 | import { 2 | shuffle, 3 | chunk, 4 | doArraysHaveSameValues, 5 | differenceOfArrays, 6 | } from "./utils"; 7 | 8 | function getAllWordsOfGameData({ gameData }) { 9 | const numCategories = gameData.length; 10 | let allWords = []; 11 | for (let i = 0; i < numCategories; i++) { 12 | if (gameData[i]?.words) { 13 | allWords.push(gameData[i].words); 14 | } else { 15 | allWords.push(gameData[i]); 16 | } 17 | } 18 | return allWords.flat(); 19 | } 20 | 21 | export function shuffleGameData({ gameData }) { 22 | let categorySize; 23 | if (gameData[0]?.words) { 24 | categorySize = gameData[0].words.length; 25 | } else { 26 | categorySize = gameData[0].length; 27 | } 28 | 29 | const allWordsFlattened = getAllWordsOfGameData({ gameData }); 30 | 31 | return chunk(categorySize, shuffle(allWordsFlattened)); 32 | } 33 | 34 | export function isGuessCorrect({ gameData, guessCandidate }) { 35 | let isCorrect = false; 36 | let correctWords = ""; 37 | let correctCategory = ""; 38 | let correctImageSrc = null; 39 | let isGuessOneAway = false; 40 | let correctDifficulty = null; 41 | const differencesOfArrays = []; 42 | for (let i = 0; i < gameData.length; i++) { 43 | correctWords = gameData[i].words; 44 | correctCategory = gameData[i].category; 45 | correctDifficulty = gameData[i].difficulty; 46 | correctImageSrc = gameData[i].imageSrc; 47 | 48 | if (doArraysHaveSameValues(guessCandidate, correctWords)) { 49 | isCorrect = true; 50 | return { 51 | isCorrect, 52 | correctWords, 53 | correctCategory, 54 | isGuessOneAway, 55 | correctDifficulty, 56 | correctImageSrc, 57 | }; 58 | } else { 59 | // check size of difference, were doing this twice, but no need to optimize for tiny arrays 60 | const differenceLength = differenceOfArrays( 61 | guessCandidate, 62 | correctWords 63 | ).length; 64 | // store how far off their guess was from category 65 | differencesOfArrays.push(differenceLength); 66 | } 67 | } 68 | 69 | isGuessOneAway = Math.min(...differencesOfArrays) === 1; 70 | 71 | return { 72 | isCorrect, 73 | correctWords, 74 | correctCategory, 75 | isGuessOneAway, 76 | correctImageSrc, 77 | }; 78 | } 79 | 80 | export function isGuessRepeated({ submittedGuesses, guessCandidate }) { 81 | for (let i = 0; i < submittedGuesses.length; i++) { 82 | const prevGuess = submittedGuesses[i]; 83 | 84 | if (doArraysHaveSameValues(guessCandidate, prevGuess)) { 85 | return true; 86 | } 87 | } 88 | 89 | return false; 90 | } 91 | 92 | export function isGameDataEquivalent({ gd1, gd2 }) { 93 | if (gd1 == null || gd2 == null) { 94 | return false; 95 | } 96 | if (gd1.length !== gd2.length) { 97 | return false; 98 | } 99 | for (let i = 0; i < gd1.lengthl; i++) { 100 | if (!doArraysHaveSameValues(gd1.words[i], gd2.words[i])) { 101 | return false; 102 | } 103 | } 104 | return true; 105 | } 106 | 107 | export function isGuessesFromGame({ gameData, submittedGuesses }) { 108 | const allGameWordsFlattened = getAllWordsOfGameData({ gameData }); 109 | const allGuessesFlattened = getAllWordsOfGameData({ 110 | gameData: submittedGuesses, 111 | }); 112 | 113 | if (submittedGuesses.length === 0) { 114 | return false; 115 | } 116 | 117 | const isSubset = allGuessesFlattened.every((val) => 118 | allGameWordsFlattened.includes(val) 119 | ); 120 | 121 | return isSubset; 122 | } 123 | 124 | export const generateEmojiGrid = (gameData, submittedGuesses) => { 125 | const wordToDifficultyMap = {}; 126 | const tiles = getEmojiTiles(); 127 | 128 | const numCategories = gameData.length; 129 | const allWords = []; 130 | for (let i = 0; i < numCategories; i++) { 131 | allWords.push(gameData[i].words); 132 | 133 | let difficulty = gameData[i].difficulty; 134 | gameData[i].words.map((word) => (wordToDifficultyMap[word] = difficulty)); 135 | } 136 | 137 | const allEmojiRowsArray = []; 138 | 139 | for (let i = 0; i < submittedGuesses.length; i++) { 140 | const submittedGuess = submittedGuesses[i]; 141 | 142 | let wordDifficultiesArray = submittedGuess.map( 143 | (word) => wordToDifficultyMap[word] 144 | ); 145 | 146 | const emojiRowForGuess = wordDifficultiesArray 147 | .map((wordDifficulty) => { 148 | switch (wordDifficulty) { 149 | case 1: 150 | return tiles[0]; 151 | case 2: 152 | return tiles[1]; 153 | case 3: 154 | return tiles[2]; 155 | case 4: 156 | return tiles[3]; 157 | } 158 | }) 159 | .join(""); 160 | 161 | allEmojiRowsArray.push(emojiRowForGuess); 162 | } 163 | 164 | return `${allEmojiRowsArray.join("\n")}`; 165 | }; 166 | 167 | export function getEmojiTiles() { 168 | let tiles = []; 169 | tiles.push("🟩"); 170 | tiles.push("🟨"); 171 | tiles.push("🟪"); 172 | tiles.push("🟦"); 173 | return tiles; 174 | } 175 | -------------------------------------------------------------------------------- /src/lib/local-storage.js: -------------------------------------------------------------------------------- 1 | const gameStateKey = "gameState"; 2 | 3 | export const saveGameStateToLocalStorage = (gameState) => { 4 | localStorage.setItem(gameStateKey, JSON.stringify(gameState)); 5 | }; 6 | 7 | export const loadGameStateFromLocalStorage = () => { 8 | const state = localStorage.getItem(gameStateKey); 9 | return state ? JSON.parse(state) : null; 10 | }; 11 | 12 | const gameStatKey = "gameStats"; 13 | 14 | export const saveStatsToLocalStorage = (gameStats) => { 15 | localStorage.setItem(gameStatKey, JSON.stringify(gameStats)); 16 | }; 17 | 18 | export const loadStatsFromLocalStorage = () => { 19 | const stats = localStorage.getItem(gameStatKey); 20 | return stats ? JSON.parse(stats) : null; 21 | }; 22 | -------------------------------------------------------------------------------- /src/lib/share-game.js: -------------------------------------------------------------------------------- 1 | import { UAParser } from "ua-parser-js"; 2 | 3 | import { GAME_TITLE } from "./constants"; 4 | import { puzzleIndex } from "./time-utils"; 5 | import { generateEmojiGrid } from "./game-helpers"; 6 | 7 | // Share logic from here: https://github.com/cwackerfuss/react-wordle/blob/main/src/lib/share.ts 8 | const webShareApiDeviceTypes = ["mobile", "smarttv", "wearable"]; 9 | const parser = new UAParser(); 10 | const browser = parser.getBrowser(); 11 | const device = parser.getDevice(); 12 | 13 | export const shareStatus = ( 14 | gameData, 15 | submittedGuesses, 16 | handleShareToClipboard, 17 | handleShareFailure, 18 | includeGameLink = true 19 | ) => { 20 | const GAME_URL = window.location.href; 21 | const textToShare = 22 | `${GAME_TITLE} #${puzzleIndex}\n\n` + 23 | generateEmojiGrid(gameData, submittedGuesses, true) + 24 | `${includeGameLink ? "\n\n" + GAME_URL : ""}`; 25 | 26 | const shareData = { text: textToShare }; 27 | 28 | let shareSuccess = false; 29 | 30 | try { 31 | if (attemptShare(shareData)) { 32 | navigator.share(shareData); 33 | shareSuccess = true; 34 | } 35 | } catch (error) { 36 | shareSuccess = false; 37 | } 38 | 39 | try { 40 | if (!shareSuccess) { 41 | if (navigator.clipboard) { 42 | navigator.clipboard 43 | .writeText(textToShare) 44 | .then(handleShareToClipboard) 45 | .catch(handleShareFailure); 46 | } else { 47 | handleShareFailure(); 48 | } 49 | } 50 | } catch (error) { 51 | handleShareFailure(); 52 | } 53 | }; 54 | 55 | const attemptShare = (shareData) => { 56 | return ( 57 | // Deliberately exclude Firefox Mobile, because its Web Share API isn't working correctly 58 | browser.name?.toUpperCase().indexOf("FIREFOX") === -1 && 59 | webShareApiDeviceTypes.indexOf(device.type ?? "") !== -1 && 60 | navigator.canShare && 61 | navigator.canShare(shareData) && 62 | navigator.share 63 | ); 64 | }; 65 | -------------------------------------------------------------------------------- /src/lib/time-utils.js: -------------------------------------------------------------------------------- 1 | import { 2 | addDays, 3 | differenceInDays, 4 | formatISO, 5 | parseISO, 6 | startOfDay, 7 | startOfToday, 8 | startOfYesterday, 9 | } from "date-fns"; 10 | 11 | import queryString from "query-string"; 12 | 13 | import { CONNECTION_GAMES } from "./data"; 14 | 15 | export const getToday = () => startOfToday(); 16 | export const getYesterday = () => startOfYesterday(); 17 | 18 | // October 2023 Game Epoch 19 | // https://stackoverflow.com/questions/2552483/why-does-the-month-argument-range-from-0-to-11-in-javascripts-date-constructor 20 | export const firstGameDate = new Date(2023, 9, 23); 21 | export const periodInDays = 7; 22 | 23 | export const getLastGameDate = (today) => { 24 | const t = startOfDay(today); 25 | let daysSinceLastGame = differenceInDays(t, firstGameDate) % periodInDays; 26 | return addDays(t, -daysSinceLastGame); 27 | }; 28 | 29 | export const getNextGameDate = (today) => { 30 | return addDays(getLastGameDate(today), periodInDays); 31 | }; 32 | 33 | export const isValidGameDate = (date) => { 34 | if (date < firstGameDate || date > getToday()) { 35 | return false; 36 | } 37 | 38 | return differenceInDays(firstGameDate, date) % periodInDays === 0; 39 | }; 40 | 41 | export const getIndex = (gameDate) => { 42 | let start = firstGameDate; 43 | let index = -1; 44 | console.log(firstGameDate); 45 | do { 46 | index++; 47 | start = addDays(start, periodInDays); 48 | } while (start <= gameDate); 49 | 50 | return index; 51 | }; 52 | 53 | export const getPuzzleOfDay = (index) => { 54 | if (index < 0) { 55 | throw new Error("Invalid index"); 56 | } 57 | 58 | return CONNECTION_GAMES[index % CONNECTION_GAMES.length]; 59 | }; 60 | 61 | export const getSolution = (gameDate) => { 62 | const nextGameDate = getNextGameDate(gameDate); 63 | const index = getIndex(gameDate); 64 | const puzzleOfTheDay = getPuzzleOfDay(index); 65 | console.log("index for today: ", index); 66 | return { 67 | puzzleAnswers: puzzleOfTheDay, 68 | puzzleGameDate: gameDate, 69 | puzzleIndex: index, 70 | dateOfNextPuzzle: nextGameDate.valueOf(), 71 | }; 72 | }; 73 | 74 | export const getGameDate = () => { 75 | if (getIsLatestGame()) { 76 | return getToday(); 77 | } 78 | 79 | const parsed = queryString.parse(window.location.search); 80 | try { 81 | const d = startOfDay(parseISO(parsed.d?.toString())); 82 | if (d >= getToday() || d < firstGameDate) { 83 | setGameDate(getToday()); 84 | } 85 | return d; 86 | } catch (e) { 87 | console.log(e); 88 | return getToday(); 89 | } 90 | }; 91 | 92 | export const setGameDate = (d) => { 93 | try { 94 | if (d < getToday()) { 95 | window.location.href = "/?d=" + formatISO(d, { representation: "date" }); 96 | return; 97 | } 98 | } catch (e) { 99 | console.log(e); 100 | } 101 | window.location.href = "/"; 102 | }; 103 | 104 | export const getIsLatestGame = () => { 105 | // https://github.com/cwackerfuss/react-wordle/pull/505 106 | const parsed = queryString.parse(window.location.search); 107 | return parsed === null || !("d" in parsed); 108 | }; 109 | 110 | export const { puzzleAnswers, puzzleGameDate, puzzleIndex, dateOfNextPuzzle } = 111 | getSolution(getGameDate()); 112 | -------------------------------------------------------------------------------- /src/lib/utils.js: -------------------------------------------------------------------------------- 1 | import { clsx } from "clsx"; 2 | import { twMerge } from "tailwind-merge"; 3 | 4 | export function cn(...inputs) { 5 | return twMerge(clsx(inputs)); 6 | } 7 | 8 | export function sleep(ms) { 9 | return new Promise((resolve) => setTimeout(resolve, ms)); 10 | } 11 | 12 | //https://www.joshwcomeau.com/snippets/javascript/random/ 13 | export const random = (min, max) => 14 | Math.floor(Math.random() * (max - min)) + min; 15 | 16 | // https://www.joshwcomeau.com/snippets/javascript/range/ 17 | export const range = (start, end, step = 1) => { 18 | let output = []; 19 | if (typeof end === "undefined") { 20 | end = start; 21 | start = 0; 22 | } 23 | for (let i = start; i < end; i += step) { 24 | output.push(i); 25 | } 26 | return output; 27 | }; 28 | 29 | export const sample = (arr) => { 30 | return arr[Math.floor(Math.random() * arr.length)]; 31 | }; 32 | 33 | // https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array 34 | export const shuffle = (array) => { 35 | let currentIndex = array.length, 36 | randomIndex; 37 | 38 | // While there remain elements to shuffle. 39 | while (currentIndex > 0) { 40 | // Pick a remaining element. 41 | randomIndex = Math.floor(Math.random() * currentIndex); 42 | currentIndex--; 43 | 44 | // And swap it with the current element. 45 | [array[currentIndex], array[randomIndex]] = [ 46 | array[randomIndex], 47 | array[currentIndex], 48 | ]; 49 | } 50 | 51 | return array; 52 | }; 53 | 54 | export const chunk = (chunkSize, array) => { 55 | const chunkedArray = []; 56 | for (let i = 0; i < array.length; i += chunkSize) { 57 | const sub = array.slice(i, i + chunkSize); 58 | chunkedArray.push(sub); 59 | } 60 | return chunkedArray; 61 | }; 62 | 63 | export const differenceOfArrays = (arr1, arr2) => { 64 | return [...arr1].filter((x) => !arr2.includes(x)); 65 | }; 66 | 67 | export const doArraysHaveSameValues = (arr1, arr2) => { 68 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set 69 | const difference = differenceOfArrays(arr1, arr2); 70 | 71 | return difference.length === 0 && arr1.length === arr2.length; 72 | }; 73 | -------------------------------------------------------------------------------- /src/providers/GameStatusProvider/GameStatusProvider.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { MAX_MISTAKES } from "../../lib/constants"; 3 | import { PuzzleDataContext } from "../PuzzleDataProvider"; 4 | import { 5 | loadGameStateFromLocalStorage, 6 | saveGameStateToLocalStorage, 7 | } from "../../lib/local-storage"; 8 | import { 9 | isGameDataEquivalent, 10 | isGuessesFromGame, 11 | } from "../../lib/game-helpers"; 12 | export const GameStatusContext = React.createContext(); 13 | 14 | function GameStatusProvider({ children }) { 15 | const { gameData } = React.useContext(PuzzleDataContext); 16 | const [submittedGuesses, setSubmittedGuesses] = React.useState([]); 17 | const [solvedGameData, setSolvedGameData] = React.useState(() => { 18 | const loadedState = loadGameStateFromLocalStorage(); 19 | console.log("checking game state!", { 20 | loadedState: loadedState, 21 | gd1: gameData, 22 | gd2: loadedState?.gameData, 23 | }); 24 | if (!isGameDataEquivalent({ gd1: gameData, gd2: loadedState?.gameData })) { 25 | return []; 26 | } 27 | if ( 28 | !isGuessesFromGame({ 29 | gameData, 30 | submittedGuesses: loadedState?.submittedGuesses, 31 | }) 32 | ) { 33 | return []; 34 | } 35 | if (Array.isArray(loadedState?.submittedGuesses)) { 36 | setSubmittedGuesses(loadedState.submittedGuesses); 37 | } 38 | 39 | if (Array.isArray(loadedState?.solvedGameData)) { 40 | return loadedState.solvedGameData; 41 | } 42 | return []; 43 | }); 44 | 45 | const [isGameOver, setIsGameOver] = React.useState(false); 46 | const [isGameWon, setIsGameWon] = React.useState(false); 47 | const [guessCandidate, setGuessCandidate] = React.useState([]); 48 | 49 | const numMistakesUsed = submittedGuesses.length - solvedGameData.length; 50 | 51 | // use effect to check if game is won 52 | React.useEffect(() => { 53 | if (solvedGameData.length === gameData.length) { 54 | setIsGameOver(true); 55 | setIsGameWon(true); 56 | } 57 | const gameState = { submittedGuesses, solvedGameData, gameData }; 58 | saveGameStateToLocalStorage(gameState); 59 | }, [solvedGameData]); 60 | 61 | // use effect to check if all mistakes have been used and end the game accordingly 62 | React.useEffect(() => { 63 | if (numMistakesUsed >= MAX_MISTAKES) { 64 | setIsGameOver(true); 65 | setIsGameWon(false); 66 | } 67 | const gameState = { submittedGuesses, solvedGameData, gameData }; 68 | saveGameStateToLocalStorage(gameState); 69 | }, [submittedGuesses]); 70 | 71 | return ( 72 | 85 | {children} 86 | 87 | ); 88 | } 89 | 90 | export default GameStatusProvider; 91 | -------------------------------------------------------------------------------- /src/providers/GameStatusProvider/index.js: -------------------------------------------------------------------------------- 1 | export * from './GameStatusProvider'; 2 | export { default } from './GameStatusProvider'; 3 | -------------------------------------------------------------------------------- /src/providers/PuzzleDataProvider/PuzzleDataProvider.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { puzzleAnswers } from "../../lib/time-utils"; 3 | 4 | export const PuzzleDataContext = React.createContext(); 5 | 6 | function PuzzleDataProvider({ children }) { 7 | const [gameData, setGameData] = React.useState(puzzleAnswers); 8 | const categorySize = gameData[0].words.length; 9 | const numCategories = gameData.length; 10 | return ( 11 | 14 | {children} 15 | 16 | ); 17 | } 18 | 19 | export default PuzzleDataProvider; 20 | -------------------------------------------------------------------------------- /src/providers/PuzzleDataProvider/index.js: -------------------------------------------------------------------------------- 1 | export * from './PuzzleDataProvider'; 2 | export { default } from './PuzzleDataProvider'; 3 | -------------------------------------------------------------------------------- /src/reset.css: -------------------------------------------------------------------------------- 1 | /* 2 | Josh's Custom CSS Reset 3 | https://www.joshwcomeau.com/css/custom-css-reset/ 4 | */ 5 | *, 6 | *::before, 7 | *::after { 8 | box-sizing: border-box; 9 | } 10 | * { 11 | margin: 0; 12 | } 13 | html, 14 | body, 15 | #root { 16 | height: 100%; 17 | } 18 | body { 19 | line-height: 1.5; 20 | -webkit-font-smoothing: antialiased; 21 | } 22 | img, 23 | picture, 24 | video, 25 | canvas, 26 | svg { 27 | display: block; 28 | max-width: 100%; 29 | } 30 | input, 31 | button, 32 | textarea, 33 | select { 34 | font: inherit; 35 | } 36 | p, 37 | h1, 38 | h2, 39 | h3, 40 | h4, 41 | h5, 42 | h6 { 43 | overflow-wrap: break-word; 44 | } 45 | #root, 46 | #__next { 47 | isolation: isolate; 48 | } 49 | -------------------------------------------------------------------------------- /src/styles.css: -------------------------------------------------------------------------------- 1 | /* 2 | Theme and global variables 3 | */ 4 | 5 | html { 6 | overflow-y: scroll; 7 | 8 | --game-spacing: 32px; 9 | --header-height: 4rem; 10 | 11 | --color-success: hsl(150deg 70% 30%); 12 | --color-warning: hsl(50deg 100% 30%); 13 | --color-error: hsl(0deg 70% 45%); 14 | --color-gray-100: hsl(0deg 0% 10%); 15 | --color-gray-300: hsl(0deg 0% 25%); 16 | --color-gray-500: hsl(0deg 0% 50%); 17 | --color-gray-700: hsl(0deg 0% 75%); 18 | --color-gray-900: hsl(0deg 0% 90%); 19 | } 20 | 21 | /* 22 | Custom styles 23 | */ 24 | body { 25 | font-family: sans-serif; 26 | } 27 | 28 | @media (max-height: 600px) { 29 | body { 30 | --game-spacing: 8px; 31 | } 32 | } 33 | 34 | .wrapper { 35 | display: flex; 36 | flex-direction: column; 37 | min-height: 100%; 38 | } 39 | 40 | header { 41 | display: flex; 42 | height: var(--header-height); 43 | border-bottom: 1px solid var(--color-gray-700); 44 | color: var(--color-gray-300); 45 | } 46 | 47 | header .side { 48 | width: var(--header-height); 49 | display: grid; 50 | place-content: center; 51 | } 52 | 53 | h1 { 54 | flex: 1; 55 | font-size: 2rem; 56 | line-height: var(--header-height); 57 | text-align: center; 58 | } 59 | 60 | @media (max-width: 25rem) { 61 | h1 { 62 | font-size: 1.25rem; 63 | } 64 | } 65 | 66 | .game-wrapper { 67 | flex: 1; 68 | display: flex; 69 | flex-direction: column; 70 | gap: var(--game-spacing); 71 | padding-top: 16px; 72 | padding-bottom: var(--game-spacing); 73 | padding-left: var(--game-spacing); 74 | padding-right: var(--game-spacing); 75 | margin: 0 auto; 76 | min-width: max(300px, 55vh, 40%); 77 | max-width: min(500px, 58vh, 100%); 78 | } 79 | 80 | .banner { 81 | position: fixed; 82 | left: 0; 83 | right: 0; 84 | bottom: 0; 85 | width: 100%; 86 | max-width: 600px; 87 | margin: 0 auto; 88 | padding: 32px; 89 | text-align: center; 90 | animation: slideUp 750ms cubic-bezier(0, 0.72, 0.24, 1.02); 91 | border-radius: 4px 4px 0px 0px; 92 | will-change: transform; 93 | } 94 | 95 | .happy.banner { 96 | background: var(--color-success); 97 | color: white; 98 | } 99 | .sad.banner { 100 | background: var(--color-error); 101 | color: white; 102 | } 103 | 104 | .visually-hidden { 105 | position: absolute; 106 | overflow: hidden; 107 | clip: rect(0 0 0 0); 108 | height: 1px; 109 | width: 1px; 110 | margin: -1px; 111 | padding: 0; 112 | border: 0; 113 | } 114 | 115 | /* 116 | Keyframe animations 117 | */ 118 | @keyframes slideUp { 119 | from { 120 | transform: translateY(100%); 121 | } 122 | to { 123 | transform: translateY(0%); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | const { fontFamily } = require("tailwindcss/defaultTheme"); 2 | 3 | /** @type {import('tailwindcss').Config} */ 4 | module.exports = { 5 | content: ["./src/**/*.{html,js,jsx,ts,tsx}"], 6 | theme: { 7 | container: { 8 | center: true, 9 | padding: "2rem", 10 | screens: { 11 | "2xl": "1400px", 12 | }, 13 | }, 14 | extend: { 15 | colors: { 16 | border: "hsl(var(--border))", 17 | input: "hsl(var(--input))", 18 | ring: "hsl(var(--ring))", 19 | background: "hsl(var(--background))", 20 | foreground: "hsl(var(--foreground))", 21 | primary: { 22 | DEFAULT: "hsl(var(--primary))", 23 | foreground: "hsl(var(--primary-foreground))", 24 | }, 25 | secondary: { 26 | DEFAULT: "hsl(var(--secondary))", 27 | foreground: "hsl(var(--secondary-foreground))", 28 | }, 29 | destructive: { 30 | DEFAULT: "hsl(var(--destructive))", 31 | foreground: "hsl(var(--destructive-foreground))", 32 | }, 33 | muted: { 34 | DEFAULT: "hsl(var(--muted))", 35 | foreground: "hsl(var(--muted-foreground))", 36 | }, 37 | accent: { 38 | DEFAULT: "hsl(var(--accent))", 39 | foreground: "hsl(var(--accent-foreground))", 40 | }, 41 | popover: { 42 | DEFAULT: "hsl(var(--popover))", 43 | foreground: "hsl(var(--popover-foreground))", 44 | }, 45 | card: { 46 | DEFAULT: "hsl(var(--card))", 47 | foreground: "hsl(var(--card-foreground))", 48 | }, 49 | }, 50 | borderRadius: { 51 | lg: `var(--radius)`, 52 | md: `calc(var(--radius) - 2px)`, 53 | sm: "calc(var(--radius) - 4px)", 54 | }, 55 | fontFamily: { 56 | sans: ["var(--font-sans)", ...fontFamily.sans], 57 | }, 58 | keyframes: { 59 | "accordion-down": { 60 | from: { height: 0 }, 61 | to: { height: "var(--radix-accordion-content-height)" }, 62 | }, 63 | "accordion-up": { 64 | from: { height: "var(--radix-accordion-content-height)" }, 65 | to: { height: 0 }, 66 | }, 67 | }, 68 | animation: { 69 | "accordion-down": "accordion-down 0.2s ease-out", 70 | "accordion-up": "accordion-up 0.2s ease-out", 71 | }, 72 | }, 73 | fontFamily: { 74 | "space-mono": ["Space Mono"], 75 | }, 76 | }, 77 | plugins: [require("tailwindcss-animate")], 78 | }; 79 | --------------------------------------------------------------------------------