Tutorial

Let's create something simple to show how this library can be used. First, install the dependency with NPM or Yarn.

npm install gooey-react

Next, we'll add some elements inside the component. You can use regular HTML elements (like a div), but an SVG is used here for optimal browser support.

import Goo from 'gooey-react'

<Goo>
  <svg>
    <circle />
    <circle />
  </svg>
</Goo>

We'll want to add some dimensions and color to these elements so they're visible.

<svg width="192" height="192">
  <circle cx="34%" cy="34%" fill="orchid" r="32" />
  <circle cx="66%" cy="66%" fill="mediumorchid" r="32" />
</svg>

Which will look like the following.

If we move the elements closer together, the effect becomes apparent. You can use the intensity prop to control how strong the goo is applied.

<circle cx="37%" cy="37%" />
<circle cx="63%" cy="63%" />

We can add animations and transitions with some simple CSS transforms. For more complex and engaging movement, an animation library is recommended.

<g style={{ animation: 'left 4s linear infinite' }}>
  <circle style={{ animation: 'right 1s linear infinite' }} />
  <circle />
</g>
svg * { transform-origin: 50% }

@keyframes left {
  100% { transform: rotate(-360deg) }
}

@keyframes right {
  100% { transform: rotate(360deg) }
}

Which will result in the following.

Below is a similar example using regular HTML elements, without animation.

<Goo style={{ height: '12rem', position: 'relative', width: '12rem' }}>
  <div style={{
    background: 'sandybrown',
    borderRadius: '50%',
    height: '4rem', width: '4rem',
    left: '2.5rem', top: '5.5rem',
    position: 'absolute',
  }} />
  <div style={{
    background: 'palevioletred',
    borderRadius: '50%',
    height: '4rem', width: '4rem',
    left: '5.5rem', top: '2.5rem',
    position: 'absolute',
  }} />
</Goo>

gooey-react is a project by Luuk.