-
-
Notifications
You must be signed in to change notification settings - Fork 267
Add Bmotion tool (#12447) #12448
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
Open
msynk
wants to merge
23
commits into
bitfoundation:develop
Choose a base branch
from
msynk:12447-add-bmotion
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Bmotion tool (#12447) #12448
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
ee041c4
add Bmotion tool #12447
msynk a812a9f
code formatting
msynk e79d03a
resolve review comments
msynk 4ae6e2d
reolve local review findings
msynk e7c9a7a
add missing code snippets
msynk db470a9
apply massive improvements
msynk 5253085
resolve review comments II
msynk 576029c
resolve review comments III
msynk 265a833
resolve review comments IV
msynk fc5046f
resolve local review findings II
msynk 551b1f0
resolve review comments V
msynk c378a5a
resolve local review comments III
msynk dc75899
resolve review comments VI
msynk 5606086
resolve review comments VII
msynk 7df7f95
resolve review comments VIII
msynk 20d0e4c
resolve review comments IX
msynk eaf648f
resolve review comments X
msynk af9bece
resolve review comments XI
msynk ee1ae8d
Merge branch 'develop' into 12447-add-bmotion
msynk 60a0b52
resolve review comments XII
msynk 9c2703b
resolve review comments XIII
msynk 5a55545
resolve review comments XIV
msynk 9fa4356
resolve review comments XV
msynk 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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <Router AppAssembly="@typeof(App).Assembly"> | ||
| <Found Context="routeData"> | ||
| <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | ||
| <FocusOnNavigate RouteData="@routeData" Selector="h1, h2" /> | ||
| </Found> | ||
| <NotFound> | ||
| <PageTitle>Not found</PageTitle> | ||
| <LayoutView Layout="@typeof(MainLayout)"> | ||
| <h1>Not found</h1> | ||
| <p role="alert">Sorry, there's nothing at this address.</p> | ||
| </LayoutView> | ||
| </NotFound> | ||
| </Router> |
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,26 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile> | ||
| <!-- | ||
| Disable static web asset fingerprinting for this dev/sample app so the running | ||
| dev server and the browser's cached boot manifest can't drift and trigger SRI | ||
| integrity 404s on fingerprinted _framework assets. | ||
| --> | ||
| <WasmFingerprintAssets>false</WasmFingerprintAssets> | ||
| <StaticWebAssetFingerprintingEnabled>false</StaticWebAssetFingerprintingEnabled> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.8" /> | ||
| <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.8" PrivateAssets="all" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Bit.Bmotion\Bit.Bmotion.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
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,19 @@ | ||
| @inherits LayoutComponentBase | ||
|
|
||
| <nav class="bm-nav" aria-label="Bmotion demos"> | ||
| <span class="logo">Bmotion</span> | ||
| <NavLink href="" Match="NavLinkMatch.All">Home</NavLink> | ||
| <NavLink href="basic">Basics</NavLink> | ||
| <NavLink href="springs">Springs</NavLink> | ||
| <NavLink href="gestures">Gestures</NavLink> | ||
| <NavLink href="variants">Variants</NavLink> | ||
| <NavLink href="keyframes">Keyframes</NavLink> | ||
| <NavLink href="presence">AnimatePresence</NavLink> | ||
| <NavLink href="drag">Drag</NavLink> | ||
| <NavLink href="scroll">Scroll</NavLink> | ||
| <NavLink href="layout">Layout</NavLink> | ||
| </nav> | ||
|
|
||
| <div class="bm-page"> | ||
| @Body | ||
| </div> |
209 changes: 209 additions & 0 deletions
209
src/Bmotion/Bit.Bmotion.Demos/Pages/AnimatePresencePage.razor
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,209 @@ | ||
| @page "/presence" | ||
|
|
||
| <div class="demo-section"> | ||
| <h2>AnimatePresence</h2> | ||
| <p> | ||
| Wrap conditional content in <strong>AnimatePresence</strong>. When | ||
| <c>IsPresent</c> becomes <c>false</c> the children play their <c>Exit</c> | ||
| animation before being removed from the DOM. | ||
| </p> | ||
|
|
||
| <div class="demo-row"> | ||
| <div class="demo-card" style="min-height:200px; position:relative; overflow:hidden;"> | ||
| <BmotionAnimatePresence IsPresent="@_visible"> | ||
| <Bmotion Tag="div" | ||
| Class="box" | ||
| Initial="@(new BmotionAnimationProps { Opacity = 0, Y = 40, Scale = 0.8 })" | ||
| Animate="@(new BmotionAnimationProps { Opacity = 1, Y = 0, Scale = 1 })" | ||
| Exit="@(new BmotionAnimationProps { Opacity = 0, Y = -40, Scale = 0.8 })" | ||
| Transition="@BmotionTransitionConfig.Spring(stiffness:220, damping:18)" /> | ||
| </BmotionAnimatePresence> | ||
| </div> | ||
| </div> | ||
|
|
||
| <button class="btn-bm" style="margin-top:1rem" @onclick="@(() => _visible = !_visible)"> | ||
| @(_visible ? "Remove" : "Add") | ||
| </button> | ||
|
|
||
| <CodeSnippet Code="@_presenceCode" /> | ||
| </div> | ||
|
|
||
| <div class="demo-section"> | ||
| <h2>List Items</h2> | ||
| <p>Add and remove items from a list with staggered enter/exit animations.</p> | ||
|
|
||
| <div class="demo-row"> | ||
| <div class="demo-card" style="flex-direction:column;gap:.5rem;align-items:stretch;width:100%;min-width:280px;"> | ||
| @foreach (var item in _items) | ||
| { | ||
| <BmotionAnimatePresence IsPresent="@item.Present" @key="item.Id"> | ||
| <Bmotion Tag="div" | ||
| Style="display:flex;justify-content:space-between;align-items:center;background:rgba(108,71,255,.12);border:1px solid rgba(108,71,255,.25);border-radius:8px;padding:.6rem 1rem;" | ||
| Initial="@(new BmotionAnimationProps { Opacity = 0, X = -30 })" | ||
| Animate="@(new BmotionAnimationProps { Opacity = 1, X = 0 })" | ||
| Exit="@(new BmotionAnimationProps { Opacity = 0, X = 30 })" | ||
| Transition="@BmotionTransitionConfig.Spring(stiffness:300, damping:25)"> | ||
| <span>@item.Label</span> | ||
| <button style="background:none;border:none;color:#ff4785;cursor:pointer;font-size:1.1rem" | ||
| aria-label="Remove item" | ||
| @onclick="@(() => RemoveItem(item.Id))">✕</button> | ||
| </Bmotion> | ||
| </BmotionAnimatePresence> | ||
| } | ||
| </div> | ||
| </div> | ||
|
|
||
| <button class="btn-bm" style="margin-top:1rem" @onclick="AddItem">Add item</button> | ||
|
|
||
| <CodeSnippet Code="@_listCode" /> | ||
| </div> | ||
|
|
||
| @code { | ||
| private bool _visible = true; | ||
| private int _nextId = 4; | ||
|
|
||
| private sealed class Item(int id, string label) | ||
| { | ||
| public int Id { get; } = id; | ||
| public string Label { get; } = label; | ||
| // Drives the per-item AnimatePresence: flipped to false to play the exit animation | ||
| // *before* the item is removed from the collection. | ||
| public bool Present { get; set; } = true; | ||
| } | ||
|
|
||
| private List<Item> _items = [new(1,"Item One"), new(2,"Item Two"), new(3,"Item Three")]; | ||
|
|
||
| void AddItem() => _items.Add(new(_nextId++, $"Item {_nextId - 1}")); | ||
|
|
||
| async Task RemoveItem(int id) | ||
| { | ||
| var item = _items.Find(i => i.Id == id); | ||
| if (item is null || !item.Present) return; | ||
| item.Present = false; // trigger the exit animation | ||
| StateHasChanged(); // force a render so the exit animation runs before the delay | ||
| await Task.Delay(400); // let it finish before dropping the item from the list | ||
| _items.Remove(item); | ||
|
msynk marked this conversation as resolved.
|
||
| } | ||
|
|
||
| private const string _presenceCode = """ | ||
| @using Bit.Bmotion | ||
|
|
||
| <style> | ||
| :root { --bm-primary: #6c47ff; --bm-secondary: #ff4785; --bm-card: #1e1e2e; } | ||
| .demo-section { margin-bottom: 3rem; } | ||
| .demo-section h2 { font-size: 1.4rem; font-weight: 700; margin-bottom: .5rem; } | ||
| .demo-row { display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: center; } | ||
| .demo-card { | ||
| background: var(--bm-card); border: 1px solid rgba(255,255,255,.07); | ||
| border-radius: 12px; padding: 2rem; min-height: 160px; flex: 1; min-width: 220px; | ||
| display: flex; align-items: center; justify-content: center; | ||
| } | ||
| .box { | ||
| width: 80px; height: 80px; border-radius: 10px; | ||
| background: linear-gradient(135deg, var(--bm-primary), var(--bm-secondary)); | ||
| } | ||
| .btn-bm { | ||
| background: var(--bm-primary); color: #fff; border: none; border-radius: 8px; | ||
| padding: .6rem 1.4rem; font-weight: 600; cursor: pointer; | ||
| } | ||
| </style> | ||
|
|
||
| <div class="demo-section"> | ||
| <h2>AnimatePresence</h2> | ||
|
|
||
| <div class="demo-row"> | ||
| <div class="demo-card" style="min-height:200px; position:relative; overflow:hidden;"> | ||
| <BmotionAnimatePresence IsPresent="@_visible"> | ||
| <Bmotion Tag="div" | ||
| Class="box" | ||
| Initial="@(new BmotionAnimationProps { Opacity = 0, Y = 40, Scale = 0.8 })" | ||
| Animate="@(new BmotionAnimationProps { Opacity = 1, Y = 0, Scale = 1 })" | ||
| Exit="@(new BmotionAnimationProps { Opacity = 0, Y = -40, Scale = 0.8 })" | ||
| Transition="@BmotionTransitionConfig.Spring(stiffness:220, damping:18)" /> | ||
| </BmotionAnimatePresence> | ||
| </div> | ||
| </div> | ||
|
|
||
| <button class="btn-bm" style="margin-top:1rem" @onclick="@(() => _visible = !_visible)"> | ||
| @(_visible ? "Remove" : "Add") | ||
| </button> | ||
| </div> | ||
|
|
||
| @code { | ||
| private bool _visible = true; | ||
| } | ||
| """; | ||
|
|
||
| private const string _listCode = """ | ||
| @using Bit.Bmotion | ||
|
|
||
| <style> | ||
| .demo-section { margin-bottom: 3rem; } | ||
| .demo-section h2 { font-size: 1.4rem; font-weight: 700; margin-bottom: .5rem; } | ||
| .demo-section p { color: #888; margin-bottom: 1.5rem; line-height: 1.6; } | ||
| .demo-row { display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: center; } | ||
| .demo-card { | ||
| background: #1e1e2e; border: 1px solid rgba(255,255,255,.07); | ||
| border-radius: 12px; padding: 2rem; min-height: 160px; flex: 1; min-width: 220px; | ||
| display: flex; align-items: center; justify-content: center; | ||
| } | ||
| .btn-bm { | ||
| background: #6c47ff; color: #fff; border: none; border-radius: 8px; | ||
| padding: .6rem 1.4rem; font-weight: 600; cursor: pointer; | ||
| } | ||
| </style> | ||
|
|
||
| <div class="demo-section"> | ||
| <h2>List Items</h2> | ||
| <p>Add and remove items from a list with staggered enter/exit animations.</p> | ||
|
|
||
| <div class="demo-row"> | ||
| <div class="demo-card" style="flex-direction:column;gap:.5rem;align-items:stretch;width:100%;min-width:280px;"> | ||
| @foreach (var item in _items) | ||
| { | ||
| <BmotionAnimatePresence IsPresent="@item.Present" @key="item.Id"> | ||
| <Bmotion Tag="div" | ||
| Style="display:flex;justify-content:space-between;align-items:center;background:rgba(108,71,255,.12);border:1px solid rgba(108,71,255,.25);border-radius:8px;padding:.6rem 1rem;" | ||
| Initial="@(new BmotionAnimationProps { Opacity = 0, X = -30 })" | ||
| Animate="@(new BmotionAnimationProps { Opacity = 1, X = 0 })" | ||
| Exit="@(new BmotionAnimationProps { Opacity = 0, X = 30 })" | ||
| Transition="@BmotionTransitionConfig.Spring(stiffness:300, damping:25)"> | ||
| <span>@item.Label</span> | ||
| <button style="background:none;border:none;color:#ff4785;cursor:pointer;font-size:1.1rem" | ||
| aria-label="Remove item" | ||
| @onclick="@(() => RemoveItem(item.Id))">✕</button> | ||
| </Bmotion> | ||
| </BmotionAnimatePresence> | ||
| } | ||
| </div> | ||
| </div> | ||
|
|
||
| <button class="btn-bm" style="margin-top:1rem" @onclick="AddItem">Add item</button> | ||
| </div> | ||
|
|
||
| @code { | ||
| private int _nextId = 4; | ||
|
|
||
| private sealed class Item(int id, string label) | ||
| { | ||
| public int Id { get; } = id; | ||
| public string Label { get; } = label; | ||
| public bool Present { get; set; } = true; | ||
| } | ||
|
|
||
| private List<Item> _items = [new(1,"Item One"), new(2,"Item Two"), new(3,"Item Three")]; | ||
|
|
||
| void AddItem() => _items.Add(new(_nextId++, $"Item {_nextId - 1}")); | ||
|
|
||
| async Task RemoveItem(int id) | ||
| { | ||
| var item = _items.Find(i => i.Id == id); | ||
| if (item is null || !item.Present) return; | ||
| item.Present = false; // trigger the exit animation | ||
| StateHasChanged(); // force a render so the exit animation runs before the delay | ||
| await Task.Delay(400); // let it finish before removing the item | ||
| _items.Remove(item); | ||
| } | ||
| } | ||
| """; | ||
| } | ||
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.