From 2c541cbdffcd3cedd2c53e26a7ad4ff25b810aa4 Mon Sep 17 00:00:00 2001 From: Persephone Flores <34418758+hp0844182@users.noreply.github.com> Date: Fri, 4 Apr 2025 19:47:35 +0800 Subject: [PATCH 1/2] fix: rm svg stroke-width style --- packages/motion/src/state/style.ts | 1 + playground/nuxt/pages/layout.vue | 19 +-- playground/nuxt/pages/test.ts | 3 - playground/nuxt/pages/test.vue | 199 ++++++++++++++--------------- 4 files changed, 100 insertions(+), 122 deletions(-) delete mode 100644 playground/nuxt/pages/test.ts diff --git a/packages/motion/src/state/style.ts b/packages/motion/src/state/style.ts index 53c7f6f..912e6a2 100644 --- a/packages/motion/src/state/style.ts +++ b/packages/motion/src/state/style.ts @@ -76,6 +76,7 @@ const SVG_STYLE_TO_ATTRIBUTES = { 'fill': true, 'stroke': true, 'opacity': true, + 'stroke-width': true, 'fill-opacity': true, 'stroke-opacity': true, 'stroke-linecap': true, diff --git a/playground/nuxt/pages/layout.vue b/playground/nuxt/pages/layout.vue index 2f6b1b7..5114675 100644 --- a/playground/nuxt/pages/layout.vue +++ b/playground/nuxt/pages/layout.vue @@ -1,8 +1,7 @@ @@ -91,40 +76,52 @@ function changeCurrency() { .container { display: flex; flex-direction: column; + gap: 16px; align-items: center; - gap: 20px; -} - -.number { - font-size: 78px; + justify-content: center; + padding: 16px; + height: 80px; } -.controls { +.button-wrapper { + position: relative; display: flex; - gap: 20px; - border-radius: 50px; + align-items: center; + justify-content: center; } -.controls > div { - display: flex; - align-items: center; - gap: 10px; - font-size: 18px; +.progress-ring { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + pointer-events: none; } -.switch-container { - width: 40px; - height: 20px; - border-radius: 25px; - cursor: pointer; - display: flex; - padding: 5px; +.button { + color: var(--black); + background-color: var(--white); + border-radius: 999px; + padding: 12px 20px; + position: relative; + isolation: isolate; + overflow: hidden; + will-change: transform; + user-select: none; + -webkit-user-select: none; + -webkit-touch-callout: none; } -.switch-handle { - width: 20px; - height: 20px; - background-color: #4ff0b7; - border-radius: 50%; +.button-background { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background-color: var(--green); + border-radius: 999px; + z-index: -1; + filter: blur(20px); + scale: 2; } From 36a1e0596bf6095d59c80683ff71222d7f9fa3c3 Mon Sep 17 00:00:00 2001 From: Persephone Flores <34418758+hp0844182@users.noreply.github.com> Date: Fri, 4 Apr 2025 19:52:41 +0800 Subject: [PATCH 2/2] test: add test for stroke-width attribute handling in SVG --- .../src/components/__tests__/svg.test.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/motion/src/components/__tests__/svg.test.ts b/packages/motion/src/components/__tests__/svg.test.ts index b91522e..7eba13a 100644 --- a/packages/motion/src/components/__tests__/svg.test.ts +++ b/packages/motion/src/components/__tests__/svg.test.ts @@ -35,4 +35,26 @@ describe('row-value', () => { expect(path.getAttribute('stroke')).toBe('blue') expect(path.getAttribute('opacity')).toBe('1') }) + it('should update stroke-width through attributes instead of style', async () => { + const strokeWidth = motionValue(2) + const wrapper = render(Motion, { + props: { + as: 'path', + style: { + strokeWidth, + }, + }, + attrs: { + 'data-testid': 'path', + }, + }) + await nextTick() + const path = wrapper.getByTestId('path') + expect(path.style.strokeWidth).toBeFalsy() + expect(path.getAttribute('stroke-width')).toBe('2') + strokeWidth.set(4) + await delay(100) + expect(path.style.strokeWidth).toBeFalsy() + expect(path.getAttribute('stroke-width')).toBe('4') + }) })