Skip to content

Commit

Permalink
Add transition to the export list (#251)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Oliver <[email protected]>
  • Loading branch information
jeromecornet and excid3 authored Sep 11, 2024
1 parent 5f6a9b9 commit ba42415
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ This will start StimulusJS and load any controllers that you have locally and th
* [Tabs](/docs/tabs.md)
* [Toggle](/docs/toggle.md)

## Utilities

* [transition](/docs/transition.md)

## Styling

All of the styles for the Stimulus components are configurable. Our
Expand Down
59 changes: 59 additions & 0 deletions docs/transition.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# transition function (for custom components)

This is a function that is useful to write custom components or extend the components with animations.

## Usage
```js
import { transition } from "tailwindcss-stimulus-components"
import { Controller } from "@hotwired/stimulus"

class CustomController extends Controller {
static targets = ['content']

showContent() {
transition(this.contentTarget, true, this.defaultOptions())
}

hideContent() {
transition(this.contentTarget, false, this.defaultOptions())
}

defaultOptions() {
return {
enter: this.hasEnterClass ? this.enterClass : 'transition ease-out duration-100',
enterFrom: this.hasEnterFromClass ? this.enterFromClass : 'transform opacity-0 scale-95',
enterTo: this.hasEnterToClass ? this.enterToClass : 'transform opacity-100 scale-100',
leave: this.hasLeaveClass ? this.leaveClass : 'transition ease-in duration-75',
leaveFrom: this.hasLeaveFromClass ? this.leaveFromClass : 'transform opacity-100 scale-100',
leaveTo: this.hasLeaveToClass ? this.leaveToClass : 'transform opacity-0 scale-95',
toggleClass: this.hasToggleClass ? this.toggleClass : 'hidden',
}
}
}

application.register('custom', CustomController)

```

The default animation attributes can be put in a controller like this so they can optionnaly be overwritten
on an element by element basis

```html
<div class="inline-block relative cursor-pointer" data-controller="custom" >
<span class="underline" data-action="custom#showContent">Show</span>
<span class="underline" data-action="custom#hideContent">Hide</span>
<div class="hidden absolute left-0 bottom-7 w-max bg-white border border-gray-200 shadow rounded p-2"
data-custom-target="content"

data-custom-enter="transition ease-out duration-100"
data-custom-enter-from="transform opacity-0 scale-95"
data-custom-enter-to="transform opacity-100 scale-100"
data-custom-leave="transition ease-in duration-75"
data-custom-leave-from="transform opacity-100 scale-100"
data-custom-leave-to="transform opacity-0 scale-95-0"
data-toggle="hidden"
>
Content
</div>
</div>
```
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export { default as Popover } from './popover'
export { default as Slideover } from './slideover'
export { default as Tabs } from './tabs'
export { default as Toggle } from './toggle'
export { transition } from "./transition"

0 comments on commit ba42415

Please sign in to comment.