Skip to content

Commit 1e597a9

Browse files
authored
experimental: Use collapsible section in animations (#5026)
## Description 1. What is this PR about (link the issue and add a short description) ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent 9486d26 commit 1e597a9

File tree

3 files changed

+79
-71
lines changed

3 files changed

+79
-71
lines changed

apps/builder/app/builder/features/settings-panel/props-section/animation/animation-section.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ const animationSources = Object.keys(
178178
animationSourceDescriptions
179179
) as NonNullable<AnimationActionScroll["source"]>[];
180180

181-
export const AnimateSection = ({
181+
export const AnimationSection = ({
182182
animationAction,
183183
onChange,
184184
isAnimationEnabled,
@@ -221,11 +221,7 @@ export const AnimateSection = ({
221221
};
222222

223223
return (
224-
<Grid
225-
css={{
226-
paddingBottom: theme.panel.paddingBlock,
227-
}}
228-
>
224+
<Grid css={{ paddingBottom: theme.panel.paddingBlock }}>
229225
<Box css={{ height: theme.panel.paddingBlock }} />
230226

231227
<Separator />
@@ -417,7 +413,8 @@ export const AnimateSection = ({
417413
/>
418414
</Grid>
419415
)}
420-
416+
</Grid>
417+
<Grid gap={2}>
421418
<AnimationsSelect
422419
value={value}
423420
onChange={handleChange}

apps/builder/app/builder/features/settings-panel/props-section/animation/animations-select.tsx

Lines changed: 73 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useState, useMemo } from "react";
22
import {
33
theme,
4-
IconButton,
54
DropdownMenu,
65
DropdownMenuTrigger,
76
DropdownMenuContent,
@@ -12,7 +11,6 @@ import {
1211
SmallToggleButton,
1312
SmallIconButton,
1413
Box,
15-
Text,
1614
Label,
1715
Grid,
1816
useSortable,
@@ -21,6 +19,9 @@ import {
2119
InputField,
2220
DialogTitle,
2321
Tooltip,
22+
SectionTitleButton,
23+
SectionTitle,
24+
SectionTitleLabel,
2425
} from "@webstudio-is/design-system";
2526
import {
2627
EyeClosedIcon,
@@ -37,6 +38,7 @@ import { newScrollAnimations } from "./new-scroll-animations";
3738
import { newViewAnimations } from "./new-view-animations";
3839
import { useIds } from "~/shared/form-utils";
3940
import { AnimationPanelContent } from "./animation-panel-content";
41+
import { CollapsibleSectionRoot } from "~/builder/shared/collapsible-section";
4042

4143
const newAnimationsPerType: {
4244
scroll: ScrollAnimation[];
@@ -93,66 +95,76 @@ export const AnimationsSelect = ({
9395
};
9496

9597
return (
96-
<Grid gap={1} align={"center"} css={{ gridTemplateColumns: "1fr auto" }}>
97-
<Label htmlFor={fieldIds.addAnimation}>
98-
<Text variant={"titles"}>Animations</Text>
99-
</Label>
100-
101-
<DropdownMenu>
102-
<DropdownMenuTrigger asChild>
103-
<IconButton id={fieldIds.addAnimation}>
104-
<PlusIcon />
105-
</IconButton>
106-
</DropdownMenuTrigger>
107-
<DropdownMenuContent
108-
sideOffset={Number.parseFloat(rawTheme.spacing[5])}
109-
css={{ width: theme.spacing[25] }}
110-
>
111-
{newAnimations.map((animation, index) => (
112-
<DropdownMenuItem
113-
key={index}
114-
onSelect={() => {
115-
handleChange(
116-
{
117-
...value,
118-
animations: value.animations.concat(animation),
119-
},
120-
false
121-
);
122-
}}
123-
onFocus={() => setNewAnimationHint(animation.description)}
124-
onBlur={() => setNewAnimationHint(undefined)}
125-
>
126-
{animation.name}
127-
</DropdownMenuItem>
128-
))}
98+
<CollapsibleSectionRoot
99+
isOpen
100+
fullWidth
101+
trigger={
102+
<SectionTitle
103+
collapsible={false}
104+
suffix={
105+
<DropdownMenu>
106+
<DropdownMenuTrigger asChild>
107+
<SectionTitleButton
108+
prefix={<PlusIcon />}
109+
tabIndex={0}
110+
id={fieldIds.addAnimation}
111+
/>
112+
</DropdownMenuTrigger>
113+
<DropdownMenuContent
114+
sideOffset={Number.parseFloat(rawTheme.spacing[5])}
115+
css={{ width: theme.spacing[25] }}
116+
>
117+
{newAnimations.map((animation, index) => (
118+
<DropdownMenuItem
119+
key={index}
120+
onSelect={() => {
121+
handleChange(
122+
{
123+
...value,
124+
animations: value.animations.concat(animation),
125+
},
126+
false
127+
);
128+
}}
129+
onFocus={() => setNewAnimationHint(animation.description)}
130+
onBlur={() => setNewAnimationHint(undefined)}
131+
>
132+
{animation.name}
133+
</DropdownMenuItem>
134+
))}
129135

130-
<DropdownMenuSeparator />
136+
<DropdownMenuSeparator />
131137

132-
<DropdownMenuItem css={{ display: "grid" }} hint>
133-
{newAnimations.map(({ description }, index) => (
134-
<Box
135-
css={{
136-
gridColumn: "1",
137-
gridRow: "1",
138-
visibility: "hidden",
139-
}}
140-
key={index}
141-
>
142-
{description}
143-
</Box>
144-
))}
145-
<Box
146-
css={{
147-
gridColumn: "1",
148-
gridRow: "1",
149-
}}
150-
>
151-
{newAnimationHint ?? "Add new or select existing animation"}
152-
</Box>
153-
</DropdownMenuItem>
154-
</DropdownMenuContent>
155-
</DropdownMenu>
138+
<DropdownMenuItem css={{ display: "grid" }} hint>
139+
{newAnimations.map(({ description }, index) => (
140+
<Box
141+
css={{
142+
gridColumn: "1",
143+
gridRow: "1",
144+
visibility: "hidden",
145+
}}
146+
key={index}
147+
>
148+
{description}
149+
</Box>
150+
))}
151+
<Box
152+
css={{
153+
gridColumn: "1",
154+
gridRow: "1",
155+
}}
156+
>
157+
{newAnimationHint ?? "Add new or select existing animation"}
158+
</Box>
159+
</DropdownMenuItem>
160+
</DropdownMenuContent>
161+
</DropdownMenu>
162+
}
163+
>
164+
<SectionTitleLabel>Animations</SectionTitleLabel>
165+
</SectionTitle>
166+
}
167+
>
156168
<CssValueListArrowFocus dragItemId={dragItemId}>
157169
<Grid gap={1} css={{ gridColumn: "span 2" }} ref={sortableRefCallback}>
158170
{value.animations.map((animation, index) => {
@@ -286,6 +298,6 @@ export const AnimationsSelect = ({
286298
{placementIndicator}
287299
</Grid>
288300
</CssValueListArrowFocus>
289-
</Grid>
301+
</CollapsibleSectionRoot>
290302
);
291303
};

apps/builder/app/builder/features/settings-panel/props-section/props-section.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { renderControl } from "../controls/combined";
2626
import { usePropsLogic, type PropAndMeta } from "./use-props-logic";
2727
import { serverSyncStore } from "~/shared/sync";
2828
import { $selectedInstanceKey } from "~/shared/awareness";
29-
import { AnimateSection } from "./animation/animation-section";
29+
import { AnimationSection } from "./animation/animation-section";
3030
import { nanoid } from "nanoid";
3131
import { $matchingBreakpoints } from "../../style-panel/shared/model";
3232
import { matchMediaBreakpoints } from "./match-media-breakpoints";
@@ -171,7 +171,7 @@ export const PropsSection = (props: PropsSectionProps) => {
171171

172172
return hasAnimation && selectedBreakpoint?.id !== undefined ? (
173173
<>
174-
<AnimateSection
174+
<AnimationSection
175175
animationAction={animationAction}
176176
isAnimationEnabled={matchMediaValue}
177177
selectedBreakpointId={selectedBreakpoint?.id}
@@ -213,7 +213,6 @@ export const PropsSection = (props: PropsSectionProps) => {
213213
});
214214
}}
215215
/>
216-
<Separator />
217216
</>
218217
) : (
219218
<>

0 commit comments

Comments
 (0)