reboottime / React-Develpment

Some notes, thought, articles or source code readings aggregated here about React Web development.
0 stars 0 forks source link

[Mantine UI Series] Transition #3

Open reboottime opened 1 year ago

reboottime commented 1 year ago

Overview

This React daily article discusses the design of the Transition component in Mantine UI, and its rationales - CSS3 transitions and corresponding JavaScript events.

reboottime commented 1 year ago

The rationales: CSS3 transition and JavaScript Transition Events

How CSS3 transition works

  1. You declare the transition works on which property with what kind of animation function and duration
  2. Triggering change on the transition property which triggers the transition. An example is to adding decoration class to a main class and trigger property changes.

For example

.notification {
   background: red;
   height: 24px;
   width: 100px;
   transition: background-color ease .2s;
}

.notification.warning {
  background-color: yellow;
}

Corresponding JavaScript events

reboottime commented 1 year ago

Mantine UI Transition component

Here's an example code snippet that demonstrates the usage of the Transition component:

<Transition mounted={opened} transition={scaleY} duration={200} timingFunction="ease">
  {(styles) => (
    <Paper
      shadow="md"
      style={{ ...styles, position: 'absolute', top: 0, left: 0, right: 0, height: rem(120) }}
      ref={clickOutsideRef}
    >
      Dropdown
    </Paper>
  )}
</Transition>

As you see above, the child(only one direct child) of the Transition component is implemented as a function. .

reboottime commented 1 year ago

References

  1. MDN: transition events
  2. Mantine UI: Transition
  3. CSS3 transition