Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted about 3 years ago

Interactive Comments w/ React, Styled Components, & Framer Motion

accessibility, motion, react, styled-components, typescript
Jacob•140
@theschmocker
A solution to the Interactive comments section challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


I don't spend as much time working with React on the web these days (Vue/Svelte on the web; React Native on mobile), so I thought it'd be a good time to shake the rust off.

This project was mostly just for fun, but open to constructive feedback!

Some neat stuff stuff:

  • Comments are stored in localStorage. I set up a storage listener to update them when changed in another tab. The original, nested tree structure felt natural in terms of how I wanted to render the UI, but was difficult to update immutably. I flattened out the data for manipulation and storage, and then computed the tree from that to be used for rendering; best of both worlds
  • Animations with Framer Motion, smooth scrolling to edit forms that open off-screen, etc
  • Date distance formatting using date-fns. I've been using date-fns at work quite a bit lately, and I really like it. The label is recalculated about every 10 seconds, which adds a fun effect to recently-added comments. If this were a real system, I'd probably only recalculate the labeling for dates before a certain cutoff or would alter the interval to run less frequently.
  • I wrote a couple fun utilities for styled-components
    • A media query generator. It reduces a record of mediaQueryName->minWidth to a record of mediaQueryName->cssFunction. Felt nicer to use than plain media queries. I would have liked to proxy the tagged template arguments to css directly, but I found that when I did that, I lost syntax highlighting and prettier formatting for styles in the media query. Kind of a silly tradeoff... but oh well.
    • color, which is a simple, well-typed, higher-order-function for plucking colors out of the theme. Rather than writing stuff like ${props => props.theme.colors.moderateBlue} everywhere, I was instead able to write things like ${color("moderateBlue")}. Trivial, but felt a lot nicer to write.

Getting the animations to do (mostly) what I wanted was probably the toughest (self-imposed) part of this challenge. I don't have a very good intuition for Framer Motion at this point, so I spent a lot of time struggling with the docs. Would be interested to learn if a) there's a way to simplify the animations that I've added and/or b) how I might go about animating between the view and edit states; couldn't quite figure that one out.

Some of the code I had to write to work around various interactions between browser quirks, focus management, scrolling, and animations felt pretty hacky. In the end, I think things work pretty well, but I'm not sure how those hacks would scale in a larger project with more complex interactions

Code
Select a file

Please log in to post a comment

Log in with GitHub

Community feedback

No feedback yet. Be the first to give feedback on Jacob's solution.

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.