Skip to content

Commit 520d083

Browse files
committed
Add transition to the export list
1 parent 3f2b3ce commit 520d083

7 files changed

+70
-6
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ This will start StimulusJS and load any controllers that you have locally and th
6868
* [Tabs](/docs/tabs.md)
6969
* [Toggle](/docs/toggle.md)
7070

71+
## Utilities
72+
73+
* [transition](/docs/transition.md)
74+
7175
## Styling
7276

7377
All of the styles for the Stimulus components are configurable. Our

dist/tailwindcss-stimulus-components.cjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/tailwindcss-stimulus-components.cjs.map

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

dist/tailwindcss-stimulus-components.module.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/tailwindcss-stimulus-components.module.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/transition.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# transition function (for custom components)
2+
3+
This is a function that is useful to write custom components or extend the components with animations.
4+
5+
## Usage
6+
```js
7+
import { transition } from "tailwindcss-stimulus-components"
8+
import { Controller } from "@hotwired/stimulus"
9+
10+
class CustomController extends Controller {
11+
static targets = ['content']
12+
13+
showContent() {
14+
transition(this.contentTarget, true, this.defaultOptions())
15+
}
16+
17+
hideContent() {
18+
transition(this.contentTarget, , this.defaultOptions())
19+
}
20+
21+
defaultOptions() {
22+
return {
23+
enter: this.hasEnterClass ? this.enterClass : 'transition ease-out duration-100',
24+
enterFrom: this.hasEnterFromClass ? this.enterFromClass : 'transform opacity-0 scale-95',
25+
enterTo: this.hasEnterToClass ? this.enterToClass : 'transform opacity-100 scale-100',
26+
leave: this.hasLeaveClass ? this.leaveClass : 'transition ease-in duration-75',
27+
leaveFrom: this.hasLeaveFromClass ? this.leaveFromClass : 'transform opacity-100 scale-100',
28+
leaveTo: this.hasLeaveToClass ? this.leaveToClass : 'transform opacity-0 scale-95',
29+
toggleClass: this.hasToggleClass ? this.toggleClass : 'hidden',
30+
}
31+
}
32+
}
33+
34+
application.register('custom', CustomController)
35+
36+
```
37+
38+
The default animation attributes can be put in a controller like this so they can optionnaly be overwritten
39+
on an element by element basis
40+
41+
```html
42+
<div class="inline-block relative cursor-pointer" data-controller="custom" >
43+
<span class="underline" data-action="custom#showContent">Show</span>
44+
<span class="underline" data-action="custom#hideContent">Hide</span>
45+
<div class="hidden absolute left-0 bottom-7 w-max bg-white border border-gray-200 shadow rounded p-2"
46+
data-custom-target="content"
47+
48+
data-custom-enter="transition ease-out duration-100"
49+
data-custom-enter-from="transform opacity-0 scale-95"
50+
data-custom-enter-to="transform opacity-100 scale-100"
51+
data-custom-leave="transition ease-in duration-75"
52+
data-custom-leave-from="transform opacity-100 scale-100"
53+
data-custom-leave-to="transform opacity-0 scale-95-0"
54+
data-toggle="hidden"
55+
>
56+
Content
57+
</div>
58+
</div>
59+
```

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export { default as Popover } from './popover'
77
export { default as Slideover } from './slideover'
88
export { default as Tabs } from './tabs'
99
export { default as Toggle } from './toggle'
10+
export { transition } from "./transition"

0 commit comments

Comments
 (0)