-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
web-wallet: Add
UsageIndicator
component
Resolves #2073
- Loading branch information
1 parent
f8ba62b
commit 253c8f2
Showing
8 changed files
with
161 additions
and
2 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
web-wallet/src/lib/components/UsageIndicator/UsageIndicator.svelte
This file contains 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,73 @@ | ||
<svelte:options immutable={true} /> | ||
|
||
<script> | ||
import { mdiShieldLock, mdiShieldLockOpenOutline } from "@mdi/js"; | ||
import { makeClassName } from "$lib/dusk/string"; | ||
import { Icon } from "$lib/dusk/components"; | ||
/** @type {string | undefined} */ | ||
export let className = undefined; | ||
/** @type {number} */ | ||
export let value; | ||
$: classes = makeClassName(["usage-indicator", className]); | ||
</script> | ||
|
||
<div class={classes}> | ||
<Icon | ||
className="usage-indicator__icon" | ||
data-tooltip-id="main-tooltip" | ||
data-tooltip-text="Funds in private account" | ||
path={mdiShieldLock} | ||
/> | ||
<div | ||
class="usage-indicator__meter" | ||
role="meter" | ||
aria-valuemax="100" | ||
aria-valuemin="0" | ||
aria-valuenow={value} | ||
aria-valuetext={`You have put ${value}% of your funds in your private account`} | ||
> | ||
<div | ||
aria-hidden="true" | ||
class="usage-indicator__meter-bar" | ||
style:width={`${value}%`} | ||
></div> | ||
</div> | ||
<Icon | ||
className="usage-indicator__icon" | ||
data-tooltip-id="main-tooltip" | ||
data-tooltip-text="Funds in public account" | ||
path={mdiShieldLockOpenOutline} | ||
/> | ||
</div> | ||
|
||
<style lang="postcss"> | ||
:global { | ||
.usage-indicator { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
gap: var(--small-gap); | ||
} | ||
.usage-indicator__icon { | ||
cursor: help; | ||
} | ||
.usage-indicator__meter { | ||
flex: 1; | ||
height: 1rem; | ||
background-color: var(--success-color); | ||
overflow: hidden; | ||
border-radius: var(--control-border-radius-size); | ||
} | ||
.usage-indicator__meter-bar { | ||
background-color: var(--success-color-variant-dark); | ||
height: 100%; | ||
} | ||
} | ||
</style> |
22 changes: 22 additions & 0 deletions
22
web-wallet/src/lib/components/__tests__/UsageIndicator.spec.js
This file contains 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,22 @@ | ||
import { afterEach, describe, expect, it } from "vitest"; | ||
import { cleanup, render } from "@testing-library/svelte"; | ||
|
||
import { UsageIndicator } from ".."; | ||
|
||
describe("UsageIndicator", () => { | ||
const baseProps = { | ||
value: 45, | ||
}; | ||
const baseOptions = { | ||
props: baseProps, | ||
target: document.body, | ||
}; | ||
|
||
afterEach(cleanup); | ||
|
||
it("should render the `UsageIndicator` component", () => { | ||
const { container } = render(UsageIndicator, baseOptions); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
web-wallet/src/lib/components/__tests__/__snapshots__/UsageIndicator.spec.js.snap
This file contains 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,48 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`UsageIndicator > should render the \`UsageIndicator\` component 1`] = ` | ||
<div | ||
class="usage-indicator" | ||
> | ||
<svg | ||
class="dusk-icon dusk-icon--size--default usage-indicator__icon" | ||
data-tooltip-id="main-tooltip" | ||
data-tooltip-text="Funds in private account" | ||
role="graphics-symbol" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
d="M12,1L3,5V11C3,16.55 6.84,21.74 12,23C17.16,21.74 21,16.55 21,11V5L12,1M12,7C13.4,7 14.8,8.1 14.8,9.5V11C15.4,11 16,11.6 16,12.3V15.8C16,16.4 15.4,17 14.7,17H9.2C8.6,17 8,16.4 8,15.7V12.2C8,11.6 8.6,11 9.2,11V9.5C9.2,8.1 10.6,7 12,7M12,8.2C11.2,8.2 10.5,8.7 10.5,9.5V11H13.5V9.5C13.5,8.7 12.8,8.2 12,8.2Z" | ||
/> | ||
</svg> | ||
<div | ||
aria-valuemax="100" | ||
aria-valuemin="0" | ||
aria-valuenow="45" | ||
aria-valuetext="You have put 45% of your funds in your private account" | ||
class="usage-indicator__meter" | ||
role="meter" | ||
> | ||
<div | ||
aria-hidden="true" | ||
class="usage-indicator__meter-bar" | ||
style="width: 45%;" | ||
/> | ||
</div> | ||
<svg | ||
class="dusk-icon dusk-icon--size--default usage-indicator__icon" | ||
data-tooltip-id="main-tooltip" | ||
data-tooltip-text="Funds in public account" | ||
role="graphics-symbol" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
d="M21 11C21 16.5 17.2 21.7 12 23C6.8 21.7 3 16.5 3 11V5L12 1L21 5V11M12 21C15.8 20 19 15.5 19 11.2V6.3L12 3.2L5 6.3V11.2C5 15.5 8.2 20 12 21M14.8 11H10.5V8.5C10.5 7.7 11.2 7.2 12 7.2S13.5 7.7 13.5 8.5V9H14.8V8.5C14.8 7.1 13.4 6 12 6S9.2 7.1 9.2 8.5V11C8.6 11 8 11.6 8 12.2V15.7C8 16.4 8.6 17 9.2 17H14.7C15.4 17 16 16.4 16 15.8V12.3C16 11.6 15.4 11 14.8 11Z" | ||
/> | ||
</svg> | ||
</div> | ||
`; |
This file contains 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 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
11 changes: 11 additions & 0 deletions
11
web-wallet/src/routes/components-showcase/UsageIndicators.svelte
This file contains 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,11 @@ | ||
<svelte:options immutable={true} /> | ||
|
||
<script> | ||
import { UsageIndicator } from "$lib/components"; | ||
</script> | ||
|
||
<section> | ||
<div style="width: 60%"> | ||
<UsageIndicator value={45} /> | ||
</div> | ||
</section> |
This file contains 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 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