shadcn-rails 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +69 -2
- data/README.md +102 -1398
- data/__mocks__/@floating-ui/dom.js +67 -0
- data/app/assets/javascripts/shadcn/controllers/base_menu_controller.js +266 -0
- data/app/assets/javascripts/shadcn/controllers/combobox_controller.js +34 -8
- data/app/assets/javascripts/shadcn/controllers/command_controller.js +5 -1
- data/app/assets/javascripts/shadcn/controllers/context_menu_controller.js +64 -135
- data/app/assets/javascripts/shadcn/controllers/dropdown_controller.js +56 -186
- data/app/assets/javascripts/shadcn/controllers/hover_card_controller.js +29 -55
- data/app/assets/javascripts/shadcn/controllers/menubar_controller.js +10 -7
- data/app/assets/javascripts/shadcn/controllers/navigation_menu_controller.js +10 -6
- data/app/assets/javascripts/shadcn/controllers/popover_controller.js +35 -60
- data/app/assets/javascripts/shadcn/controllers/select_controller.js +37 -17
- data/app/assets/javascripts/shadcn/controllers/sidebar_controller.js +24 -14
- data/app/assets/javascripts/shadcn/controllers/tooltip_controller.js +28 -59
- data/app/assets/javascripts/shadcn/index.js +9 -1
- data/app/assets/javascripts/shadcn/utils/floating.js +179 -0
- data/app/assets/stylesheets/shadcn/base.css +32 -0
- data/app/assets/stylesheets/shadcn/components.css +12 -0
- data/app/components/shadcn/accordion_component.html.erb +8 -0
- data/app/components/shadcn/accordion_component.rb +6 -15
- data/app/components/shadcn/alert_component.html.erb +6 -0
- data/app/components/shadcn/alert_component.rb +0 -18
- data/app/components/shadcn/alert_dialog_component.html.erb +12 -0
- data/app/components/shadcn/alert_dialog_component.rb +7 -27
- data/app/components/shadcn/aspect_ratio_component.html.erb +7 -0
- data/app/components/shadcn/aspect_ratio_component.rb +4 -19
- data/app/components/shadcn/avatar_component.html.erb +20 -0
- data/app/components/shadcn/avatar_component.rb +8 -36
- data/app/components/shadcn/badge_component.html.erb +1 -0
- data/app/components/shadcn/badge_component.rb +0 -11
- data/app/components/shadcn/base_component.rb +15 -2
- data/app/components/shadcn/breadcrumb_component.html.erb +5 -0
- data/app/components/shadcn/breadcrumb_component.rb +6 -16
- data/app/components/shadcn/button_component.html.erb +18 -0
- data/app/components/shadcn/button_component.rb +1 -41
- data/app/components/shadcn/card_component.html.erb +8 -0
- data/app/components/shadcn/card_component.rb +2 -6
- data/app/components/shadcn/checkbox_component.html.erb +32 -0
- data/app/components/shadcn/checkbox_component.rb +4 -43
- data/app/components/shadcn/collapsible_component.html.erb +8 -0
- data/app/components/shadcn/collapsible_component.rb +6 -15
- data/app/components/shadcn/command_list_component.rb +29 -14
- data/app/components/shadcn/context_menu_checkbox_item_component.rb +76 -0
- data/app/components/shadcn/context_menu_component.html.erb +11 -0
- data/app/components/shadcn/context_menu_component.rb +6 -26
- data/app/components/shadcn/context_menu_content_component.rb +37 -14
- data/app/components/shadcn/context_menu_item_component.rb +3 -2
- data/app/components/shadcn/context_menu_radio_group_component.rb +42 -0
- data/app/components/shadcn/context_menu_radio_item_component.rb +76 -0
- data/app/components/shadcn/dialog_component.html.erb +14 -0
- data/app/components/shadcn/dialog_component.rb +8 -29
- data/app/components/shadcn/drawer_component.html.erb +12 -0
- data/app/components/shadcn/drawer_component.rb +7 -27
- data/app/components/shadcn/dropdown_menu_checkbox_item_component.rb +76 -0
- data/app/components/shadcn/dropdown_menu_component.html.erb +14 -0
- data/app/components/shadcn/dropdown_menu_component.rb +9 -29
- data/app/components/shadcn/dropdown_menu_content_component.rb +45 -16
- data/app/components/shadcn/dropdown_menu_radio_group_component.rb +42 -0
- data/app/components/shadcn/dropdown_menu_radio_item_component.rb +76 -0
- data/app/components/shadcn/field_component.rb +7 -8
- data/app/components/shadcn/hover_card_component.html.erb +12 -0
- data/app/components/shadcn/hover_card_component.rb +7 -26
- data/app/components/shadcn/input_component.html.erb +18 -0
- data/app/components/shadcn/input_component.rb +2 -27
- data/app/components/shadcn/input_otp_component.rb +3 -3
- data/app/components/shadcn/kbd_component.html.erb +1 -0
- data/app/components/shadcn/kbd_component.rb +3 -10
- data/app/components/shadcn/label_component.html.erb +3 -0
- data/app/components/shadcn/label_component.rb +2 -18
- data/app/components/shadcn/menubar_component.html.erb +6 -0
- data/app/components/shadcn/menubar_component.rb +4 -15
- data/app/components/shadcn/menubar_content_component.rb +45 -20
- data/app/components/shadcn/menubar_sub_content_component.rb +21 -8
- data/app/components/shadcn/native_select_component.html.erb +22 -0
- data/app/components/shadcn/native_select_component.rb +9 -39
- data/app/components/shadcn/navigation_menu_component.html.erb +6 -0
- data/app/components/shadcn/navigation_menu_component.rb +4 -15
- data/app/components/shadcn/pagination_component.html.erb +5 -0
- data/app/components/shadcn/pagination_component.rb +11 -15
- data/app/components/shadcn/popover_component.html.erb +15 -0
- data/app/components/shadcn/popover_component.rb +10 -30
- data/app/components/shadcn/progress_component.html.erb +13 -0
- data/app/components/shadcn/progress_component.rb +6 -26
- data/app/components/shadcn/radio_group_component.html.erb +8 -0
- data/app/components/shadcn/radio_group_component.rb +12 -26
- data/app/components/shadcn/radio_group_item_component.rb +32 -6
- data/app/components/shadcn/resizable_panel_group_component.rb +27 -16
- data/app/components/shadcn/scroll_area_component.html.erb +7 -0
- data/app/components/shadcn/scroll_area_component.rb +4 -16
- data/app/components/shadcn/select_component.html.erb +46 -0
- data/app/components/shadcn/select_component.rb +29 -86
- data/app/components/shadcn/separator_component.html.erb +5 -0
- data/app/components/shadcn/separator_component.rb +6 -14
- data/app/components/shadcn/sheet_component.html.erb +12 -0
- data/app/components/shadcn/sheet_component.rb +7 -27
- data/app/components/shadcn/sidebar_component.rb +2 -2
- data/app/components/shadcn/skeleton_component.html.erb +1 -0
- data/app/components/shadcn/skeleton_component.rb +4 -2
- data/app/components/shadcn/slider_component.html.erb +12 -0
- data/app/components/shadcn/slider_component.rb +2 -21
- data/app/components/shadcn/spinner_component.html.erb +18 -0
- data/app/components/shadcn/spinner_component.rb +2 -30
- data/app/components/shadcn/switch_component.html.erb +72 -0
- data/app/components/shadcn/switch_component.rb +4 -82
- data/app/components/shadcn/table_component.html.erb +9 -0
- data/app/components/shadcn/table_component.rb +2 -10
- data/app/components/shadcn/tabs_component.html.erb +8 -0
- data/app/components/shadcn/tabs_component.rb +4 -17
- data/app/components/shadcn/textarea_component.html.erb +13 -0
- data/app/components/shadcn/textarea_component.rb +6 -22
- data/app/components/shadcn/toast_component.html.erb +36 -0
- data/app/components/shadcn/toast_component.rb +6 -54
- data/app/components/shadcn/toggle_component.html.erb +12 -0
- data/app/components/shadcn/toggle_component.rb +6 -21
- data/app/components/shadcn/toggle_group_component.html.erb +14 -0
- data/app/components/shadcn/toggle_group_component.rb +6 -29
- data/app/components/shadcn/tooltip_component.html.erb +20 -0
- data/app/components/shadcn/tooltip_component.rb +13 -38
- data/lib/generators/shadcn/add/USAGE +24 -0
- data/lib/generators/shadcn/add/add_generator.rb +279 -0
- data/lib/generators/shadcn/install/USAGE +22 -0
- data/lib/generators/shadcn/install/install_generator.rb +8 -3
- data/lib/generators/shadcn/install/templates/initializer.rb.tt +7 -27
- data/lib/generators/shadcn/install/templates/shadcn.yml.tt +15 -31
- data/lib/shadcn/rails/version.rb +1 -1
- metadata +54 -42
- data/.dockerignore +0 -40
- data/CLAUDE.md +0 -463
- data/PROGRESS.md +0 -485
- data/Rakefile +0 -29
- data/__tests__/controllers/__snapshots__/calendar_controller.test.js.snap +0 -13
- data/__tests__/controllers/__snapshots__/popover_controller.test.js.snap +0 -46
- data/__tests__/controllers/__snapshots__/sheet_controller.test.js.snap +0 -111
- data/__tests__/controllers/__snapshots__/tabs_controller.test.js.snap +0 -27
- data/__tests__/controllers/accordion_controller.test.js +0 -904
- data/__tests__/controllers/calendar_controller.test.js +0 -1370
- data/__tests__/controllers/carousel_controller.test.js +0 -912
- data/__tests__/controllers/checkbox_controller.test.js +0 -454
- data/__tests__/controllers/collapsible_controller.test.js +0 -407
- data/__tests__/controllers/combobox_controller.test.js +0 -966
- data/__tests__/controllers/context_menu_controller.test.js +0 -627
- data/__tests__/controllers/date_picker_controller.test.js +0 -636
- data/__tests__/controllers/dialog_controller.test.js +0 -878
- data/__tests__/controllers/drawer_controller.test.js +0 -995
- data/__tests__/controllers/menubar_controller.test.js +0 -736
- data/__tests__/controllers/navigation_menu_controller.test.js +0 -598
- data/__tests__/controllers/popover_controller.test.js +0 -1007
- data/__tests__/controllers/radio_group_controller.test.js +0 -640
- data/__tests__/controllers/resizable_controller.test.js +0 -680
- data/__tests__/controllers/select_controller.test.js +0 -674
- data/__tests__/controllers/sheet_controller.test.js +0 -986
- data/__tests__/controllers/slider_controller.test.js +0 -1036
- data/__tests__/controllers/switch_controller.test.js +0 -424
- data/__tests__/controllers/tabs_controller.test.js +0 -907
- data/__tests__/controllers/toggle_group_controller.test.js +0 -839
- data/__tests__/controllers/tooltip_controller.test.js +0 -808
- data/__tests__/helpers/stimulus-test-helper.js +0 -203
- data/babel.config.cjs +0 -5
- data/bin/console +0 -11
- data/bin/setup +0 -8
- data/jest.config.js +0 -19
- data/jest.setup.js +0 -8
- data/lib/generators/shadcn/component/component_generator.rb +0 -188
- data/lib/generators/shadcn/theme/theme_generator.rb +0 -128
- data/package-lock.json +0 -7415
- data/package.json +0 -68
- data/rollup.config.js +0 -29
|
@@ -1,407 +0,0 @@
|
|
|
1
|
-
import { Application } from "@hotwired/stimulus"
|
|
2
|
-
import CollapsibleController from "../../app/assets/javascripts/shadcn/controllers/collapsible_controller.js"
|
|
3
|
-
import { setupController, cleanupController, click, nextFrame, wait } from '../helpers/stimulus-test-helper.js'
|
|
4
|
-
|
|
5
|
-
describe("CollapsibleController", () => {
|
|
6
|
-
let application
|
|
7
|
-
let element
|
|
8
|
-
let controller
|
|
9
|
-
|
|
10
|
-
afterEach(() => {
|
|
11
|
-
cleanupController(application)
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
describe("basic rendering and initialization", () => {
|
|
15
|
-
const basicHTML = `
|
|
16
|
-
<div data-controller="shadcn--collapsible"
|
|
17
|
-
data-shadcn--collapsible-open-value="false"
|
|
18
|
-
data-shadcn--collapsible-disabled-value="false">
|
|
19
|
-
<button data-shadcn--collapsible-target="trigger"
|
|
20
|
-
data-action="click->shadcn--collapsible#toggle">
|
|
21
|
-
Toggle
|
|
22
|
-
</button>
|
|
23
|
-
<div data-shadcn--collapsible-target="content" hidden>
|
|
24
|
-
<p>Collapsible content</p>
|
|
25
|
-
</div>
|
|
26
|
-
</div>
|
|
27
|
-
`
|
|
28
|
-
|
|
29
|
-
beforeEach(async () => {
|
|
30
|
-
const setup = await setupController(CollapsibleController, basicHTML, 'shadcn--collapsible')
|
|
31
|
-
application = setup.application
|
|
32
|
-
element = setup.element
|
|
33
|
-
controller = setup.controller
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
test("initializes with closed state", () => {
|
|
37
|
-
expect(controller.openValue).toBe(false)
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
test("initializes with disabled false", () => {
|
|
41
|
-
expect(controller.disabledValue).toBe(false)
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
test("sets data-state closed on element", () => {
|
|
45
|
-
expect(element.dataset.state).toBe("closed")
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
test("sets data-state closed on content", () => {
|
|
49
|
-
expect(controller.contentTarget.dataset.state).toBe("closed")
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
test("content is hidden initially", () => {
|
|
53
|
-
expect(controller.contentTarget.hidden).toBe(true)
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
describe("toggle functionality", () => {
|
|
58
|
-
const toggleHTML = `
|
|
59
|
-
<div data-controller="shadcn--collapsible"
|
|
60
|
-
data-shadcn--collapsible-open-value="false">
|
|
61
|
-
<button data-shadcn--collapsible-target="trigger"
|
|
62
|
-
data-action="click->shadcn--collapsible#toggle">
|
|
63
|
-
Toggle
|
|
64
|
-
</button>
|
|
65
|
-
<div data-shadcn--collapsible-target="content" hidden>
|
|
66
|
-
Content
|
|
67
|
-
</div>
|
|
68
|
-
</div>
|
|
69
|
-
`
|
|
70
|
-
|
|
71
|
-
beforeEach(async () => {
|
|
72
|
-
const setup = await setupController(CollapsibleController, toggleHTML, 'shadcn--collapsible')
|
|
73
|
-
application = setup.application
|
|
74
|
-
element = setup.element
|
|
75
|
-
controller = setup.controller
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
test("toggles open state when closed", async () => {
|
|
79
|
-
controller.toggle()
|
|
80
|
-
await nextFrame()
|
|
81
|
-
|
|
82
|
-
expect(controller.openValue).toBe(true)
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
test("toggles closed state when open", async () => {
|
|
86
|
-
controller.openValue = true
|
|
87
|
-
controller.toggle()
|
|
88
|
-
await nextFrame()
|
|
89
|
-
|
|
90
|
-
expect(controller.openValue).toBe(false)
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
test("updates element data-state on toggle", async () => {
|
|
94
|
-
controller.toggle()
|
|
95
|
-
await nextFrame()
|
|
96
|
-
|
|
97
|
-
expect(element.dataset.state).toBe("open")
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
test("updates content data-state on toggle", async () => {
|
|
101
|
-
controller.toggle()
|
|
102
|
-
await nextFrame()
|
|
103
|
-
|
|
104
|
-
expect(controller.contentTarget.dataset.state).toBe("open")
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
test("shows content when toggled open", async () => {
|
|
108
|
-
controller.toggle()
|
|
109
|
-
await nextFrame()
|
|
110
|
-
|
|
111
|
-
expect(controller.contentTarget.hidden).toBe(false)
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
test("dispatches opened event when opening", async () => {
|
|
115
|
-
let eventFired = false
|
|
116
|
-
element.addEventListener("shadcn--collapsible:opened", () => {
|
|
117
|
-
eventFired = true
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
controller.toggle()
|
|
121
|
-
await nextFrame()
|
|
122
|
-
|
|
123
|
-
expect(eventFired).toBe(true)
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
test("dispatches closed event when closing", async () => {
|
|
127
|
-
controller.openValue = true
|
|
128
|
-
controller.updateState()
|
|
129
|
-
|
|
130
|
-
let eventFired = false
|
|
131
|
-
element.addEventListener("shadcn--collapsible:closed", () => {
|
|
132
|
-
eventFired = true
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
controller.toggle()
|
|
136
|
-
await nextFrame()
|
|
137
|
-
|
|
138
|
-
expect(eventFired).toBe(true)
|
|
139
|
-
})
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
describe("open and close methods", () => {
|
|
143
|
-
const methodsHTML = `
|
|
144
|
-
<div data-controller="shadcn--collapsible"
|
|
145
|
-
data-shadcn--collapsible-open-value="false">
|
|
146
|
-
<button data-shadcn--collapsible-target="trigger">Toggle</button>
|
|
147
|
-
<div data-shadcn--collapsible-target="content" hidden>Content</div>
|
|
148
|
-
</div>
|
|
149
|
-
`
|
|
150
|
-
|
|
151
|
-
beforeEach(async () => {
|
|
152
|
-
const setup = await setupController(CollapsibleController, methodsHTML, 'shadcn--collapsible')
|
|
153
|
-
application = setup.application
|
|
154
|
-
element = setup.element
|
|
155
|
-
controller = setup.controller
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
test("open() sets openValue to true", async () => {
|
|
159
|
-
controller.open()
|
|
160
|
-
await nextFrame()
|
|
161
|
-
|
|
162
|
-
expect(controller.openValue).toBe(true)
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
test("open() updates state", async () => {
|
|
166
|
-
controller.open()
|
|
167
|
-
await nextFrame()
|
|
168
|
-
|
|
169
|
-
expect(element.dataset.state).toBe("open")
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
test("close() sets openValue to false", async () => {
|
|
173
|
-
controller.openValue = true
|
|
174
|
-
controller.close()
|
|
175
|
-
await nextFrame()
|
|
176
|
-
|
|
177
|
-
expect(controller.openValue).toBe(false)
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
test("close() updates state", async () => {
|
|
181
|
-
controller.openValue = true
|
|
182
|
-
controller.updateState()
|
|
183
|
-
controller.close()
|
|
184
|
-
await nextFrame()
|
|
185
|
-
|
|
186
|
-
expect(element.dataset.state).toBe("closed")
|
|
187
|
-
})
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
describe("disabled state", () => {
|
|
191
|
-
const disabledHTML = `
|
|
192
|
-
<div data-controller="shadcn--collapsible"
|
|
193
|
-
data-shadcn--collapsible-open-value="false"
|
|
194
|
-
data-shadcn--collapsible-disabled-value="true">
|
|
195
|
-
<button data-shadcn--collapsible-target="trigger"
|
|
196
|
-
data-action="click->shadcn--collapsible#toggle">Toggle</button>
|
|
197
|
-
<div data-shadcn--collapsible-target="content" hidden>Content</div>
|
|
198
|
-
</div>
|
|
199
|
-
`
|
|
200
|
-
|
|
201
|
-
beforeEach(async () => {
|
|
202
|
-
const setup = await setupController(CollapsibleController, disabledHTML, 'shadcn--collapsible')
|
|
203
|
-
application = setup.application
|
|
204
|
-
element = setup.element
|
|
205
|
-
controller = setup.controller
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
test("toggle does not change state when disabled", async () => {
|
|
209
|
-
controller.toggle()
|
|
210
|
-
await nextFrame()
|
|
211
|
-
|
|
212
|
-
expect(controller.openValue).toBe(false)
|
|
213
|
-
})
|
|
214
|
-
|
|
215
|
-
test("open does not change state when disabled", async () => {
|
|
216
|
-
controller.open()
|
|
217
|
-
await nextFrame()
|
|
218
|
-
|
|
219
|
-
expect(controller.openValue).toBe(false)
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
test("close still works when disabled", async () => {
|
|
223
|
-
// Force open state
|
|
224
|
-
controller.openValue = true
|
|
225
|
-
controller.disabledValue = true
|
|
226
|
-
|
|
227
|
-
controller.close()
|
|
228
|
-
await nextFrame()
|
|
229
|
-
|
|
230
|
-
expect(controller.openValue).toBe(false)
|
|
231
|
-
})
|
|
232
|
-
})
|
|
233
|
-
|
|
234
|
-
describe("initial open state", () => {
|
|
235
|
-
const openHTML = `
|
|
236
|
-
<div data-controller="shadcn--collapsible"
|
|
237
|
-
data-shadcn--collapsible-open-value="true">
|
|
238
|
-
<button data-shadcn--collapsible-target="trigger">Toggle</button>
|
|
239
|
-
<div data-shadcn--collapsible-target="content">Content</div>
|
|
240
|
-
</div>
|
|
241
|
-
`
|
|
242
|
-
|
|
243
|
-
beforeEach(async () => {
|
|
244
|
-
const setup = await setupController(CollapsibleController, openHTML, 'shadcn--collapsible')
|
|
245
|
-
application = setup.application
|
|
246
|
-
element = setup.element
|
|
247
|
-
controller = setup.controller
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
test("initializes with open state", () => {
|
|
251
|
-
expect(controller.openValue).toBe(true)
|
|
252
|
-
})
|
|
253
|
-
|
|
254
|
-
test("sets data-state open on element", () => {
|
|
255
|
-
expect(element.dataset.state).toBe("open")
|
|
256
|
-
})
|
|
257
|
-
|
|
258
|
-
test("content is visible initially", () => {
|
|
259
|
-
expect(controller.contentTarget.hidden).toBe(false)
|
|
260
|
-
})
|
|
261
|
-
})
|
|
262
|
-
|
|
263
|
-
describe("programmatic value change", () => {
|
|
264
|
-
const programmaticHTML = `
|
|
265
|
-
<div data-controller="shadcn--collapsible"
|
|
266
|
-
data-shadcn--collapsible-open-value="false">
|
|
267
|
-
<button data-shadcn--collapsible-target="trigger">Toggle</button>
|
|
268
|
-
<div data-shadcn--collapsible-target="content" hidden>Content</div>
|
|
269
|
-
</div>
|
|
270
|
-
`
|
|
271
|
-
|
|
272
|
-
beforeEach(async () => {
|
|
273
|
-
const setup = await setupController(CollapsibleController, programmaticHTML, 'shadcn--collapsible')
|
|
274
|
-
application = setup.application
|
|
275
|
-
element = setup.element
|
|
276
|
-
controller = setup.controller
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
test("openValueChanged callback updates state", async () => {
|
|
280
|
-
controller.openValue = true
|
|
281
|
-
await nextFrame()
|
|
282
|
-
|
|
283
|
-
expect(element.dataset.state).toBe("open")
|
|
284
|
-
})
|
|
285
|
-
|
|
286
|
-
test("changing openValue shows content", async () => {
|
|
287
|
-
controller.openValue = true
|
|
288
|
-
await nextFrame()
|
|
289
|
-
|
|
290
|
-
expect(controller.contentTarget.hidden).toBe(false)
|
|
291
|
-
})
|
|
292
|
-
})
|
|
293
|
-
|
|
294
|
-
describe("click handler", () => {
|
|
295
|
-
const clickHTML = `
|
|
296
|
-
<div data-controller="shadcn--collapsible"
|
|
297
|
-
data-shadcn--collapsible-open-value="false">
|
|
298
|
-
<button data-shadcn--collapsible-target="trigger"
|
|
299
|
-
data-action="click->shadcn--collapsible#toggle">Toggle</button>
|
|
300
|
-
<div data-shadcn--collapsible-target="content" hidden>Content</div>
|
|
301
|
-
</div>
|
|
302
|
-
`
|
|
303
|
-
|
|
304
|
-
beforeEach(async () => {
|
|
305
|
-
const setup = await setupController(CollapsibleController, clickHTML, 'shadcn--collapsible')
|
|
306
|
-
application = setup.application
|
|
307
|
-
element = setup.element
|
|
308
|
-
controller = setup.controller
|
|
309
|
-
})
|
|
310
|
-
|
|
311
|
-
test("toggles on trigger click", async () => {
|
|
312
|
-
click(controller.triggerTarget)
|
|
313
|
-
await nextFrame()
|
|
314
|
-
|
|
315
|
-
expect(controller.openValue).toBe(true)
|
|
316
|
-
})
|
|
317
|
-
|
|
318
|
-
test("toggles back on second click", async () => {
|
|
319
|
-
click(controller.triggerTarget)
|
|
320
|
-
await nextFrame()
|
|
321
|
-
click(controller.triggerTarget)
|
|
322
|
-
await nextFrame()
|
|
323
|
-
|
|
324
|
-
expect(controller.openValue).toBe(false)
|
|
325
|
-
})
|
|
326
|
-
})
|
|
327
|
-
|
|
328
|
-
describe("without content target", () => {
|
|
329
|
-
const noContentHTML = `
|
|
330
|
-
<div data-controller="shadcn--collapsible"
|
|
331
|
-
data-shadcn--collapsible-open-value="false">
|
|
332
|
-
<button data-shadcn--collapsible-target="trigger"
|
|
333
|
-
data-action="click->shadcn--collapsible#toggle">Toggle</button>
|
|
334
|
-
</div>
|
|
335
|
-
`
|
|
336
|
-
|
|
337
|
-
beforeEach(async () => {
|
|
338
|
-
const setup = await setupController(CollapsibleController, noContentHTML, 'shadcn--collapsible')
|
|
339
|
-
application = setup.application
|
|
340
|
-
element = setup.element
|
|
341
|
-
controller = setup.controller
|
|
342
|
-
})
|
|
343
|
-
|
|
344
|
-
test("works without content target", async () => {
|
|
345
|
-
expect(() => {
|
|
346
|
-
controller.toggle()
|
|
347
|
-
}).not.toThrow()
|
|
348
|
-
|
|
349
|
-
expect(controller.openValue).toBe(true)
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
test("updates element state without content", async () => {
|
|
353
|
-
controller.toggle()
|
|
354
|
-
await nextFrame()
|
|
355
|
-
|
|
356
|
-
expect(element.dataset.state).toBe("open")
|
|
357
|
-
})
|
|
358
|
-
})
|
|
359
|
-
|
|
360
|
-
describe("multiple toggles", () => {
|
|
361
|
-
const multipleHTML = `
|
|
362
|
-
<div data-controller="shadcn--collapsible"
|
|
363
|
-
data-shadcn--collapsible-open-value="false">
|
|
364
|
-
<button data-shadcn--collapsible-target="trigger"
|
|
365
|
-
data-action="click->shadcn--collapsible#toggle">Toggle</button>
|
|
366
|
-
<div data-shadcn--collapsible-target="content" hidden>Content</div>
|
|
367
|
-
</div>
|
|
368
|
-
`
|
|
369
|
-
|
|
370
|
-
beforeEach(async () => {
|
|
371
|
-
const setup = await setupController(CollapsibleController, multipleHTML, 'shadcn--collapsible')
|
|
372
|
-
application = setup.application
|
|
373
|
-
element = setup.element
|
|
374
|
-
controller = setup.controller
|
|
375
|
-
})
|
|
376
|
-
|
|
377
|
-
test("handles rapid toggles", async () => {
|
|
378
|
-
controller.toggle() // open
|
|
379
|
-
controller.toggle() // close
|
|
380
|
-
controller.toggle() // open
|
|
381
|
-
await nextFrame()
|
|
382
|
-
|
|
383
|
-
expect(controller.openValue).toBe(true)
|
|
384
|
-
})
|
|
385
|
-
|
|
386
|
-
test("dispatches events for each toggle", async () => {
|
|
387
|
-
let openedCount = 0
|
|
388
|
-
let closedCount = 0
|
|
389
|
-
|
|
390
|
-
element.addEventListener("shadcn--collapsible:opened", () => openedCount++)
|
|
391
|
-
element.addEventListener("shadcn--collapsible:closed", () => closedCount++)
|
|
392
|
-
|
|
393
|
-
// Note: The controller dispatches events from both toggle() and openValueChanged()
|
|
394
|
-
// so each toggle fires two events. This is the current behavior.
|
|
395
|
-
controller.toggle() // open
|
|
396
|
-
await nextFrame()
|
|
397
|
-
controller.toggle() // close
|
|
398
|
-
await nextFrame()
|
|
399
|
-
controller.toggle() // open
|
|
400
|
-
await nextFrame()
|
|
401
|
-
|
|
402
|
-
// Events fire twice per toggle (from toggle() and openValueChanged())
|
|
403
|
-
expect(openedCount).toBe(4) // 2 opens * 2 events each
|
|
404
|
-
expect(closedCount).toBe(2) // 1 close * 2 events
|
|
405
|
-
})
|
|
406
|
-
})
|
|
407
|
-
})
|