“Time Ago” React Component to display Timestamp as formatted String

Hey fellows,

There are many ways to display a Date or a timestamp, but the often appropriate is to show the elapsed time in a readable format.

So I drafted a little React component that takes a number of milliseconds for props and turns into a string of relative seconds, minutes, hours, days, months or years.

import TimeAgo from '../components/TimeAgo';

const date = Date.now(),
    tests = [date - 6789, date - 456789, date - 23456789, date - 123456789, date - 9123456789, date - 89123456789];

return <ul>{tests.map((timestamp, key) => <li key={key}>
    <TimeAgo timestamp={timestamp}/>.
</li>)}</ul>;
  • .
  • .
  • .
  • .
  • .
  • .

The component gives a time element with a datetime property.

<time datetime="2018-02-22T00:21:08.005Z">1 day ago</time>

The code is fairly short and simple, and is available on GitHub as susual.

😉

Reddit API Front-End on React

Good morning everyone,

Reddit is an American social news aggregation, web content rating, and discussion website.

And it opens a cool API to engineer your own front-end.

So here comes my take on it : http://reddit.webmaestro.fr.

It basically fetches JSON data, parses image and video sources, embedded players or templated content and turns it into optimized React components. The design is minimalistic and based entirely on Semantic UI.

With iframes, video players and heavy GIFs mixing over infinite scrolling, the main idea was to mount and unmount components depending on their visibility. And it was just too easy with react-lazyload.

I had some fun setting the volume of videos in relation to their position on the viewport. It works pretty well, try it out !

Slide Up and Down with React Transition Group

Some UI effects are very simple, yet difficult to achieve. I already solved the vertical slide dilemma with jQuery, but I needed to implement it for React Transition Group.

When items are entering a list, we want them to fade in and smoothly slide the surrounding elements away, instead of brutally shifting our interface.

Transitions work by easing from one initial value to an other defined one. The problem with vertical sliding is that most HTML element containers do not have a predefined height, but rather auto adapt this value to fit the content. Therefor, it is quite tricky to animate the entrance of randomly sized blocks without jumping stroboscopically into the margin, padding and box-sizing soup.

My approach is to use the CSSTransition component callbacks to animate a negative margin and slide our items from the top.

The code is available on GitHub.

Terminal Window React Component with Keystroke Sounds

Yup, you read that right.

Here is a React component that will mock an OSX Terminal window, and play keystroke sounds to simulate typing.

See the demo at http://keystrokes.webmaestro.fr.

If you listen carefuly, you will notice that “space” and “enter” keys even have their specific sounds ! The audio samples were created by my homonymous friend Etienne. Together we have some more JavaScript sound design exercises in mind so stay tuned.

OSX Terminal window

The window is pure CSS and SVG. The console uses my favorite Fira Code monospace font.

It is also based on my actual ~/.bash_profile :
export PS1="\n[\e[0;31m\w\e[m]\n| > ".

It was made in the building process of a portfolio that should be available to you soon.

You can find the component code and CSS on GitHub.