-
Notifications
You must be signed in to change notification settings - Fork 1.3k
experimental: Animate UI #4851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
experimental: Animate UI #4851
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6f1a94c
Animate
istarkov b3f5e98
Fix
istarkov 26da52e
Add camel
istarkov 37b5478
Add camelCase
istarkov ddf0842
Fix
istarkov 8796550
Add inset support
istarkov d332123
Add
istarkov fb1892c
Fix
istarkov fa5f1f6
Fix test
istarkov 3c5090f
Fix commit
istarkov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,17 +14,14 @@ sudo rm -rf /tmp/corepack-cache | |
sudo rm -rf /usr/local/lib/node_modules/corepack # Manually remove global corepack | ||
|
||
# Reinstall corepack globally via npm | ||
npm install -g corepack@latest # Install latest corepack version | ||
npm install -g corepack@latest --force # Install latest corepack version | ||
sudo corepack enable # Re-enable corepack | ||
|
||
# Check corepack version after reinstall | ||
echo "--- Corepack version after reinstall ---" | ||
corepack --version | ||
echo "--- End corepack version check ---" | ||
|
||
|
||
# Prepare pnpm (again, after corepack reinstall) | ||
sudo corepack prepare [email protected] --activate | ||
corepack prepare [email protected] --activate | ||
|
||
# Go to workspace directory | ||
cd /workspaces/webstudio | ||
|
@@ -42,7 +39,7 @@ find . -name '.pnpm-store' -type d -prune -exec rm -rf '{}' + | |
|
||
# Install dependencies, build, and migrate | ||
pnpm install | ||
pnpm run build | ||
pnpm build | ||
pnpm migrations migrate | ||
|
||
# Add git aliases | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
218 changes: 218 additions & 0 deletions
218
...ilder/app/builder/features/settings-panel/props-section/animation/animation-keyframes.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
import { parseCss } from "@webstudio-is/css-data"; | ||
import { StyleValue, toValue } from "@webstudio-is/css-engine"; | ||
import { | ||
Text, | ||
Grid, | ||
IconButton, | ||
Label, | ||
Separator, | ||
Tooltip, | ||
} from "@webstudio-is/design-system"; | ||
import { MinusIcon, PlusIcon } from "@webstudio-is/icons"; | ||
import type { AnimationKeyframe } from "@webstudio-is/sdk"; | ||
import { Fragment, useMemo, useState } from "react"; | ||
import { | ||
CssValueInput, | ||
type IntermediateStyleValue, | ||
} from "~/builder/features/style-panel/shared/css-value-input"; | ||
import { toKebabCase } from "~/builder/features/style-panel/shared/keyword-utils"; | ||
import { CodeEditor } from "~/builder/shared/code-editor"; | ||
import { useIds } from "~/shared/form-utils"; | ||
|
||
const unitOptions = [ | ||
{ | ||
id: "%" as const, | ||
label: "%", | ||
type: "unit" as const, | ||
}, | ||
]; | ||
|
||
const OffsetInput = ({ | ||
id, | ||
value, | ||
onChange, | ||
}: { | ||
id: string; | ||
value: number | undefined; | ||
onChange: (value: number | undefined) => void; | ||
}) => { | ||
const [intermediateValue, setIntermediateValue] = useState< | ||
StyleValue | IntermediateStyleValue | ||
>(); | ||
|
||
return ( | ||
<CssValueInput | ||
id={id} | ||
placeholder="auto" | ||
getOptions={() => []} | ||
unitOptions={unitOptions} | ||
intermediateValue={intermediateValue} | ||
styleSource="default" | ||
/* same as offset has 0 - 100% */ | ||
property={"fontStretch"} | ||
value={ | ||
value !== undefined | ||
? { | ||
type: "unit", | ||
value: Math.round(value * 1000) / 10, | ||
unit: "%", | ||
} | ||
: undefined | ||
} | ||
onChange={(styleValue) => { | ||
if (styleValue === undefined) { | ||
setIntermediateValue(styleValue); | ||
return; | ||
} | ||
|
||
const clampedStyleValue = { ...styleValue }; | ||
if ( | ||
clampedStyleValue.type === "unit" && | ||
clampedStyleValue.unit === "%" | ||
) { | ||
clampedStyleValue.value = Math.min( | ||
100, | ||
Math.max(0, clampedStyleValue.value) | ||
); | ||
} | ||
|
||
setIntermediateValue(clampedStyleValue); | ||
}} | ||
onHighlight={(_styleValue) => { | ||
/* @todo: think about preview */ | ||
}} | ||
onChangeComplete={(event) => { | ||
setIntermediateValue(undefined); | ||
|
||
if (event.value.type === "unit" && event.value.unit === "%") { | ||
onChange(Math.min(100, Math.max(0, event.value.value)) / 100); | ||
return; | ||
} | ||
|
||
setIntermediateValue({ | ||
type: "invalid", | ||
value: toValue(event.value), | ||
}); | ||
}} | ||
onAbort={() => { | ||
/* @todo: allow to change some ephemeral property to see the result in action */ | ||
}} | ||
onReset={() => { | ||
setIntermediateValue(undefined); | ||
onChange(undefined); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
const Keyframe = ({ | ||
value, | ||
onChange, | ||
}: { | ||
value: AnimationKeyframe; | ||
onChange: (value: AnimationKeyframe | undefined) => void; | ||
}) => { | ||
const ids = useIds(["offset"]); | ||
|
||
const cssProperties = useMemo(() => { | ||
let result = ``; | ||
for (const [property, style] of Object.entries(value.styles)) { | ||
result = `${result}${toKebabCase(property)}: ${toValue(style)};\n`; | ||
} | ||
return result; | ||
}, [value.styles]); | ||
|
||
return ( | ||
<> | ||
<Grid | ||
gap={1} | ||
align={"center"} | ||
css={{ gridTemplateColumns: "1fr 1fr auto" }} | ||
> | ||
<Label htmlFor={ids.offset}>Offset</Label> | ||
<OffsetInput | ||
id={ids.offset} | ||
value={value.offset} | ||
onChange={(offset) => { | ||
onChange({ ...value, offset }); | ||
}} | ||
/> | ||
<Tooltip content="Remove keyframe"> | ||
<IconButton onClick={() => onChange(undefined)}> | ||
<MinusIcon /> | ||
</IconButton> | ||
</Tooltip> | ||
</Grid> | ||
<Grid> | ||
<CodeEditor | ||
lang="css-properties" | ||
size="keyframe" | ||
value={cssProperties} | ||
onChange={() => { | ||
/* do nothing */ | ||
}} | ||
onChangeComplete={(cssText) => { | ||
const parsedStyles = parseCss(`selector{${cssText}}`); | ||
onChange({ | ||
...value, | ||
styles: parsedStyles.reduce( | ||
istarkov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(r, { property, value }) => ({ ...r, [property]: value }), | ||
{} | ||
), | ||
}); | ||
}} | ||
/> | ||
</Grid> | ||
</> | ||
); | ||
}; | ||
|
||
export const Keyframes = ({ | ||
value: keyframes, | ||
onChange, | ||
}: { | ||
value: AnimationKeyframe[]; | ||
onChange: (value: AnimationKeyframe[]) => void; | ||
}) => { | ||
const ids = useIds(["addKeyframe"]); | ||
|
||
return ( | ||
<Grid gap={2}> | ||
<Grid gap={1} align={"center"} css={{ gridTemplateColumns: "1fr auto" }}> | ||
<Label htmlFor={ids.addKeyframe}> | ||
<Text variant={"titles"}>Keyframes</Text> | ||
</Label> | ||
<IconButton | ||
id={ids.addKeyframe} | ||
onClick={() => | ||
onChange([...keyframes, { offset: undefined, styles: {} }]) | ||
} | ||
> | ||
<PlusIcon /> | ||
</IconButton> | ||
</Grid> | ||
|
||
{keyframes.map((value, index) => ( | ||
<Fragment key={index}> | ||
<Separator /> | ||
<Keyframe | ||
key={index} | ||
value={value} | ||
onChange={(newValue) => { | ||
if (newValue === undefined) { | ||
const newValues = [...keyframes]; | ||
newValues.splice(index, 1); | ||
onChange(newValues); | ||
return; | ||
} | ||
|
||
const newValues = [...keyframes]; | ||
newValues[index] = newValue; | ||
onChange(newValues); | ||
}} | ||
/> | ||
</Fragment> | ||
))} | ||
</Grid> | ||
); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.