Skip to content

Commit

Permalink
Add symbol part for #84 workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
barvian committed Dec 16, 2024
1 parent e626a3f commit 46ab8bd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
8 changes: 8 additions & 0 deletions .changeset/brown-oranges-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'number-flow': patch
'@number-flow/react': patch
'@number-flow/svelte': patch
'@number-flow/vue': patch
---

Add symbol part for styling all symbols
2 changes: 1 addition & 1 deletion packages/number-flow/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ class Sym extends Char<KeyedSymbolPart> {
createElement(
'span',
{
part: type,
part: `symbol ${type}`,
className: `symbol`
},
[val]
Expand Down
14 changes: 10 additions & 4 deletions packages/number-flow/src/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ const styles = css`
display: inline-block;
direction: ltr;
white-space: nowrap;
line-height: ${charHeight} !important;
isolation: isolate; /* for .number z-index */
/* Technically this is only needed on the .number, but applying it here makes the ::selection the same height for the whole element: */
line-height: ${charHeight} !important;
}
.number,
Expand Down Expand Up @@ -160,7 +161,6 @@ const styles = css`
*/
content: '\200b'; /* zero-width space */
display: inline-block;
padding: ${halfMaskHeight} 0;
}
.section--justify-left {
Expand All @@ -184,12 +184,18 @@ const styles = css`
--c: var(--current) + var(${deltaVar});
}
.digit__num,
.number .section::after {
padding: ${halfMaskHeight} 0;
}
.digit__num {
display: inline-block;
padding: ${halfMaskHeight} 0;
/* Claude + https://buildui.com/recipes/animated-counter */
--offset-raw: mod(var(--length) + var(--n) - mod(var(--c), var(--length)), var(--length));
--offset: calc(var(--offset-raw) - var(--length) * round(down, var(--offset-raw) / (var(--length)/2), 1));
--offset: calc(
var(--offset-raw) - var(--length) * round(down, var(--offset-raw) / (var(--length) / 2), 1)
);
/* Technically we just need var(--offset)*100%, but clamping should reduce the layer size: */
--y: clamp(-100%, var(--offset) * 100%, 100%);
transform: translateY(var(--y));
Expand Down
3 changes: 1 addition & 2 deletions site/src/pages/[...framework]/_Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ export default function Hero({ sandbox }: { sandbox: string }) {
/>
</div>
<p className="~text-base/lg prose prose-muted dark:prose-invert text-balance">
An animated number component. Dependency-free. Accessible.
Customizable.
An animated number component. Dependency-free. Accessible. Customizable.
</p>
<div className="~mt-3/5 flex w-full flex-wrap items-stretch justify-center gap-3">
<button
Expand Down

0 comments on commit 46ab8bd

Please sign in to comment.