Skip to content

Commit a4db09c

Browse files
committed
isPinned
1 parent 54ddbdc commit a4db09c

File tree

5 files changed

+41
-33
lines changed

5 files changed

+41
-33
lines changed

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

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Tooltip,
1111
ToggleGroupButton,
1212
Text,
13+
Switch,
1314
} from "@webstudio-is/design-system";
1415
import { useIds } from "~/shared/form-utils";
1516
import type { PropAndMeta } from "../use-props-logic";
@@ -92,6 +93,16 @@ export const AnimateSection = ({
9293
const value: AnimationAction =
9394
prop?.type === "animationAction" ? prop.value : defaultActionValue;
9495

96+
const handleChange = (value: unknown) => {
97+
const parsedValue = animationActionSchema.safeParse(value);
98+
if (parsedValue.success) {
99+
onChange(parsedValue.data);
100+
return;
101+
}
102+
103+
toast.error("Schemas are incompatible, try fix");
104+
};
105+
95106
return (
96107
<Grid
97108
css={{
@@ -101,14 +112,27 @@ export const AnimateSection = ({
101112
<Box css={{ height: theme.panel.paddingBlock }} />
102113

103114
<Separator />
104-
<Text
115+
116+
<Grid
117+
gap={1}
118+
align={"center"}
105119
css={{
120+
gridTemplateColumns: "1fr auto",
106121
padding: theme.panel.paddingInline,
107122
}}
108-
variant={"titles"}
109123
>
110-
Animation
111-
</Text>
124+
<Text variant={"titles"}>Animation</Text>
125+
126+
<Tooltip content={value.isPinned ? "Unpin Animation" : "Pin Animation"}>
127+
<Switch
128+
checked={value.isPinned ?? false}
129+
onCheckedChange={(isPinned) => {
130+
handleChange({ ...value, isPinned });
131+
}}
132+
/>
133+
</Tooltip>
134+
</Grid>
135+
112136
<Separator />
113137

114138
<Box css={{ height: theme.panel.paddingBlock }} />
@@ -132,14 +156,7 @@ export const AnimateSection = ({
132156
</Box>
133157
)}
134158
onChange={(typeValue) => {
135-
const newValue = { ...value, type: typeValue, animations: [] };
136-
const parsedValue = animationActionSchema.safeParse(newValue);
137-
if (parsedValue.success) {
138-
onChange(parsedValue.data);
139-
return;
140-
}
141-
142-
toast.error("Schemas are incompatible, try fix");
159+
handleChange({ ...value, type: typeValue, animations: [] });
143160
}}
144161
/>
145162
</Grid>
@@ -150,14 +167,7 @@ export const AnimateSection = ({
150167
type="single"
151168
value={value.axis ?? ("block" as const)}
152169
onValueChange={(axis) => {
153-
const newValue = { ...value, axis };
154-
const parsedValue = animationActionSchema.safeParse(newValue);
155-
if (parsedValue.success) {
156-
onChange(parsedValue.data);
157-
return;
158-
}
159-
160-
toast.error("Schemas are incompatible, try fix");
170+
handleChange({ ...value, axis });
161171
}}
162172
>
163173
{Object.entries(animationAxisDescription).map(
@@ -205,14 +215,7 @@ export const AnimateSection = ({
205215
</Box>
206216
)}
207217
onChange={(source) => {
208-
const newValue = { ...value, source };
209-
const parsedValue = animationActionSchema.safeParse(newValue);
210-
if (parsedValue.success) {
211-
onChange(parsedValue.data);
212-
return;
213-
}
214-
215-
toast.error("Schemas are incompatible, try fix");
218+
handleChange({ ...value, source });
216219
}}
217220
/>
218221
</Grid>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ export const AnimationsSelect = ({ value, onChange }: Props) => {
231231
<>
232232
<SmallToggleButton
233233
pressed={false}
234-
onPressedChange={() => {}}
234+
onPressedChange={() => {
235+
alert("Not implemented");
236+
}}
235237
variant="normal"
236238
tabIndex={-1}
237239
icon={

packages/design-system/src/components/switch.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ const switchStyle = css({
3030
backgroundColor: theme.colors.backgroundNeutralDark,
3131
},
3232

33-
"&[data-state=checked]:not([data-disabled]):before": {
34-
backgroundColor: theme.colors.backgroundPrimary,
35-
},
33+
"&[data-state=checked]:not([data-disabled]):before, &[aria-checked=true]:not([data-disabled]):before":
34+
{
35+
backgroundColor: theme.colors.backgroundPrimary,
36+
},
3637

3738
"&[data-disabled]:before": {
3839
backgroundColor: theme.colors.foregroundDisabled,

packages/sdk/src/schema/animation-schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export const scrollActionSchema = z.object({
161161
.optional(),
162162
axis: animationAxisSchema.optional(),
163163
animations: z.array(scrollAnimationSchema),
164+
isPinned: z.boolean().optional(),
164165
});
165166

166167
export const viewAnimationSchema = baseAnimation.merge(
@@ -175,6 +176,7 @@ export const viewActionSchema = z.object({
175176
subject: z.string().optional(),
176177
axis: animationAxisSchema.optional(),
177178
animations: z.array(viewAnimationSchema),
179+
isPinned: z.boolean().optional(),
178180
});
179181

180182
// Animation Action

0 commit comments

Comments
 (0)