Skip to content

Commit 74fa846

Browse files
committed
refactor(collapsible-section): use more custom css props to control animations
Using a private custom CSS prop for controlling grid-template-rows, not only makes the code better structured, but also enables internal components to dynamically expand or collapse the body element, without actually collapsing the section using its props. This will be used in follow up commits.
1 parent 46f08e7 commit 74fa846

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

src/components/collapsible-section/collapsible-section.scss

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -149,35 +149,29 @@ limel-icon {
149149
// This animates height of the body,
150150
// from `0` to `auto`
151151
.body {
152-
// All below vars are for internal use only!
153-
--limel-cs-opacity-transition-speed: 0.1s;
154-
--limel-cs-opacity-transition-delay: 0s;
155-
--limel-cs-grid-template-rows-transition-speed: 0.3s;
156152
transition: grid-template-rows
157-
var(--limel-cs-grid-template-rows-transition-speed)
153+
var(--limel-cs-grid-template-rows-transition-speed, 0.3s)
158154
cubic-bezier(1, 0.09, 0, 0.89);
159155
display: grid;
160-
grid-template-rows: 0fr;
156+
grid-template-rows: var(--limel-cs-grid-template-rows, 0fr);
161157

162158
slot {
163-
transition: opacity var(--limel-cs-opacity-transition-speed) ease
164-
var(--limel-cs-opacity-transition-delay);
159+
transition: opacity var(--limel-cs-opacity-transition-speed, 0.1s) ease
160+
var(--limel-cs-opacity-transition-delay, 0s);
165161
display: block;
166162
overflow: hidden;
167163
opacity: 0;
168164
}
169165
}
170166

171-
section.open {
172-
.body {
173-
--limel-cs-opacity-transition-speed: 0.4s;
174-
--limel-cs-opacity-transition-delay: 0.3s;
175-
--limel-cs-grid-template-rows-transition-speed: 0.46s;
176-
grid-template-rows: 1fr;
167+
:host(limel-collapsible-section[is-open]) {
168+
--limel-cs-opacity-transition-speed: 0.4s;
169+
--limel-cs-opacity-transition-delay: 0.3s;
170+
--limel-cs-grid-template-rows-transition-speed: 0.46s;
171+
--limel-cs-grid-template-rows: 1fr;
177172

178-
slot {
179-
opacity: 1;
180-
}
173+
slot {
174+
opacity: 1;
181175
}
182176
}
183177

0 commit comments

Comments
 (0)