-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
90 additions
and
29 deletions.
There are no files selected for viewing
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,5 @@ | ||
--- | ||
'@number-flow/vue': patch | ||
--- | ||
|
||
Add <NumberFlowGroup> |
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,38 @@ | ||
<script lang="ts" setup> | ||
import type { NumberFlowLite } from 'number-flow' | ||
import { key, type RegisterWithGroup } from './group' | ||
import { provide, watch, type Ref, nextTick, onUnmounted } from 'vue' | ||
const flows = new Set<Ref<NumberFlowLite | undefined>>() | ||
let updating = false | ||
const registerWithGroup: RegisterWithGroup = (el, parts) => { | ||
flows.add(el) | ||
watch( | ||
parts, | ||
async () => { | ||
if (updating) return | ||
updating = true | ||
flows.forEach((flow) => { | ||
flow.value?.willUpdate() | ||
}) | ||
await nextTick() | ||
flows.forEach((flow) => { | ||
flow.value?.didUpdate() | ||
}) | ||
updating = false | ||
} | ||
// { flush: 'pre' } // default | ||
) | ||
onUnmounted(() => { | ||
flows.delete(el) | ||
}) | ||
} | ||
provide(key, registerWithGroup) | ||
</script> | ||
<template> | ||
<slot /> | ||
</template> |
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,9 @@ | ||
import type { NumberFlowLite, partitionParts } from 'number-flow' | ||
import type { InjectionKey, Ref, ComputedRef, MaybeRefOrGetter } from 'vue' | ||
|
||
export type RegisterWithGroup = ( | ||
el: Ref<NumberFlowLite | undefined>, | ||
parts: ComputedRef<ReturnType<typeof partitionParts>> | ||
) => void | ||
|
||
export const key = Symbol() as InjectionKey<RegisterWithGroup | undefined> |
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
22 changes: 14 additions & 8 deletions
22
site/src/pages/[...framework]/examples/_Group/vue/Component.vue
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 |
---|---|---|
@@ -1,17 +1,23 @@ | ||
<script setup lang="ts"> | ||
import NumberFlow from '@number-flow/vue' | ||
import NumberFlow, { NumberFlowGroup } from '@number-flow/vue' | ||
const { value, diff } = defineProps<{ | ||
value: number | ||
diff: number | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<div | ||
style="--number-flow-char-height: 0.85em" | ||
class="~text-xl/4xl flex items-center gap-2 font-semibold" | ||
> | ||
<NumberFlow :value :format="{ style: 'currency', currency: 'USD' }" /> | ||
<NumberFlow :value="diff" :format="{ style: 'percent', maximumFractionDigits: 2 }" /> | ||
</div> | ||
<NumberFlowGroup> | ||
<div style="--number-flow-char-height: 0.85em" class="flex items-center gap-4 font-semibold"> | ||
<NumberFlow :value :format="{ style: 'currency', currency: 'USD' }" class="~text-2xl/4xl" /> | ||
<NumberFlow | ||
:value="diff" | ||
:format="{ style: 'percent', maximumFractionDigits: 2, signDisplay: 'always' }" | ||
:class="[ | ||
'~text-lg/2xl transition-colors duration-300', | ||
diff < 0 ? 'text-red-500' : 'text-emerald-500' | ||
]" | ||
/> | ||
</div> | ||
</NumberFlowGroup> | ||
</template> |
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