|
| 1 | +import { type InteractConfig } from '@wix/interact/web'; |
| 2 | +import { useInteractInstance } from '../hooks/useInteractInstance'; |
| 3 | + |
| 4 | +const svgPathMorphConfig: InteractConfig = { |
| 5 | + interactions: [ |
| 6 | + { |
| 7 | + key: 'svg-path-morph', |
| 8 | + trigger: 'viewEnter', |
| 9 | + effects: [ |
| 10 | + { |
| 11 | + effectId: 'svg-path-morph-effect', |
| 12 | + selector: 'path:nth-child(1)', |
| 13 | + }, |
| 14 | + ], |
| 15 | + }, |
| 16 | + ], |
| 17 | + effects: { |
| 18 | + 'svg-path-morph-effect': { |
| 19 | + duration: 2000, |
| 20 | + easing: 'linear', |
| 21 | + iterations: Infinity, |
| 22 | + triggerType: 'once', |
| 23 | + keyframeEffect: { |
| 24 | + name: 'morph-layer-0', |
| 25 | + keyframes: [ |
| 26 | + { offset: 0, d: 'path("M 0,0 L 100,100 L 0,100 Z")' }, |
| 27 | + { offset: 0.25, d: 'path("M 50,25 L 100,100 L 0,100 Z")' }, |
| 28 | + { offset: 0.5, d: 'path("M 100,0 L 100,100 L 0,100 Z")' }, |
| 29 | + { offset: 0.75, d: 'path("M 50,25 L 100,100 L 0,100 Z")' }, |
| 30 | + { offset: 1, d: 'path("M 0,0 L 100,100 L 0,100 Z")' }, |
| 31 | + ], |
| 32 | + }, |
| 33 | + }, |
| 34 | + }, |
| 35 | +}; |
| 36 | + |
| 37 | +export const SvgPathMorphDemo = () => { |
| 38 | + useInteractInstance(svgPathMorphConfig); |
| 39 | + |
| 40 | + return ( |
| 41 | + <section className="panel svg-path-morph-demo"> |
| 42 | + <p className="scroll-label">SVG path morph</p> |
| 43 | + <div className="svg-path-morph-header"> |
| 44 | + <div> |
| 45 | + <h3>Static SVG, Interact keyframes</h3> |
| 46 | + <p> |
| 47 | + The static path starts animating when this panel enters view. Interact targets the |
| 48 | + nested path and passes the supplied keyframes to the Web Animations API. |
| 49 | + </p> |
| 50 | + </div> |
| 51 | + <span className="svg-path-morph-status">Keyframes</span> |
| 52 | + </div> |
| 53 | + |
| 54 | + <interact-element data-interact-key="svg-path-morph"> |
| 55 | + <div className="svg-path-morph-stage"> |
| 56 | + <svg |
| 57 | + aria-label="" |
| 58 | + role="presentation" |
| 59 | + aria-hidden="true" |
| 60 | + preserveAspectRatio="xMidYMid meet" |
| 61 | + data-type="color" |
| 62 | + viewBox="0 0 100 100" |
| 63 | + xmlnsXlink="http://www.w3.org/1999/xlink" |
| 64 | + xmlns="http://www.w3.org/2000/svg" |
| 65 | + data-bbox="0 0 100 100" |
| 66 | + > |
| 67 | + <g className="_svgImageSource_1lilf_7" data-type="color"> |
| 68 | + <g> |
| 69 | + <path d="m0 0 100 100H0Z" fill="#c0ffee" /> |
| 70 | + </g> |
| 71 | + </g> |
| 72 | + </svg> |
| 73 | + </div> |
| 74 | + </interact-element> |
| 75 | + |
| 76 | + <p className="svg-path-morph-note"> |
| 77 | + The initial <code>d</code> attribute is static. The effect selector targets the nested |
| 78 | + <code>path:nth-child(1)</code>, so Interact applies the keyframes only after |
| 79 | + <code>viewEnter</code>. |
| 80 | + </p> |
| 81 | + </section> |
| 82 | + ); |
| 83 | +}; |
0 commit comments