|
| 1 | +import React, { useEffect, useRef } from 'react'; |
| 2 | +import '../styles/christmas-trees.css'; |
| 3 | + |
| 4 | +export default function ChristmasTree() { |
| 5 | + const containerRef = useRef<HTMLDivElement>(null); |
| 6 | + |
| 7 | + useEffect(() => { |
| 8 | + const container = containerRef.current; |
| 9 | + if (!container) return; |
| 10 | + |
| 11 | + // Create SVG tree element |
| 12 | + const createTreeSVG = (scale: number = 1) => { |
| 13 | + const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); |
| 14 | + svg.setAttribute('viewBox', '0 0 100 140'); |
| 15 | + svg.setAttribute('width', `${80 * scale}`); |
| 16 | + svg.setAttribute('height', `${112 * scale}`); |
| 17 | + svg.className = 'dancing-tree'; |
| 18 | + |
| 19 | + // Tree foliage layers |
| 20 | + const foliage1 = document.createElementNS('http://www.w3.org/2000/svg', 'polygon'); |
| 21 | + foliage1.setAttribute('points', '50,10 20,60 80,60'); |
| 22 | + foliage1.setAttribute('fill', '#1b4d2e'); |
| 23 | + svg.appendChild(foliage1); |
| 24 | + |
| 25 | + const foliage2 = document.createElementNS('http://www.w3.org/2000/svg', 'polygon'); |
| 26 | + foliage2.setAttribute('points', '50,40 10,90 90,90'); |
| 27 | + foliage2.setAttribute('fill', '#0d3c1f'); |
| 28 | + svg.appendChild(foliage2); |
| 29 | + |
| 30 | + const foliage3 = document.createElementNS('http://www.w3.org/2000/svg', 'polygon'); |
| 31 | + foliage3.setAttribute('points', '50,70 15,120 85,120'); |
| 32 | + foliage3.setAttribute('fill', '#1b4d2e'); |
| 33 | + svg.appendChild(foliage3); |
| 34 | + |
| 35 | + // Tree trunk |
| 36 | + const trunk = document.createElementNS('http://www.w3.org/2000/svg', 'rect'); |
| 37 | + trunk.setAttribute('x', '40'); |
| 38 | + trunk.setAttribute('y', '110'); |
| 39 | + trunk.setAttribute('width', '20'); |
| 40 | + trunk.setAttribute('height', '30'); |
| 41 | + trunk.setAttribute('fill', '#8B4513'); |
| 42 | + svg.appendChild(trunk); |
| 43 | + |
| 44 | + // Star on top |
| 45 | + const star = document.createElementNS('http://www.w3.org/2000/svg', 'polygon'); |
| 46 | + star.setAttribute('points', '50,0 55,15 70,15 58,25 63,40 50,30 37,40 42,25 30,15 45,15'); |
| 47 | + star.setAttribute('fill', '#ffd700'); |
| 48 | + star.className = 'tree-star'; |
| 49 | + svg.appendChild(star); |
| 50 | + |
| 51 | + // Ornaments |
| 52 | + const ornaments = [ |
| 53 | + { cx: 35, cy: 40, color: '#c8102e' }, |
| 54 | + { cx: 65, cy: 45, color: '#ffd700' }, |
| 55 | + { cx: 50, cy: 50, color: '#ffd700' }, |
| 56 | + { cx: 25, cy: 75, color: '#c8102e' }, |
| 57 | + { cx: 50, cy: 85, color: '#ffd700' }, |
| 58 | + { cx: 75, cy: 80, color: '#c8102e' }, |
| 59 | + { cx: 35, cy: 105, color: '#ffd700' }, |
| 60 | + { cx: 65, cy: 110, color: '#c8102e' }, |
| 61 | + ]; |
| 62 | + |
| 63 | + ornaments.forEach((ornament) => { |
| 64 | + const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle'); |
| 65 | + circle.setAttribute('cx', ornament.cx.toString()); |
| 66 | + circle.setAttribute('cy', ornament.cy.toString()); |
| 67 | + circle.setAttribute('r', '3'); |
| 68 | + circle.setAttribute('fill', ornament.color); |
| 69 | + circle.className = 'ornament-light'; |
| 70 | + svg.appendChild(circle); |
| 71 | + }); |
| 72 | + |
| 73 | + return svg; |
| 74 | + }; |
| 75 | + |
| 76 | + // Create tree with wrapper |
| 77 | + const createTree = (x: number, y: number, scale: number, opacity: number, delay: number) => { |
| 78 | + const wrapper = document.createElement('div'); |
| 79 | + wrapper.className = 'tree-wrapper'; |
| 80 | + wrapper.style.position = 'absolute'; |
| 81 | + wrapper.style.left = `${x}px`; |
| 82 | + wrapper.style.top = `${y}px`; |
| 83 | + wrapper.style.opacity = `${opacity}`; |
| 84 | + wrapper.style.transformOrigin = 'center bottom'; |
| 85 | + wrapper.style.setProperty('--animation-delay', `${delay}s`); |
| 86 | + wrapper.appendChild(createTreeSVG(scale)); |
| 87 | + return wrapper; |
| 88 | + }; |
| 89 | + |
| 90 | + const viewportHeight = window.innerHeight || 800; |
| 91 | + const treePositions = [ |
| 92 | + { x: 10, y: viewportHeight * 0.35, scale: 1.4, opacity: 1, delay: 0 }, |
| 93 | + { x: window.innerWidth - 130, y: viewportHeight * 0.25, scale: 1.5, opacity: 1, delay: 0.1 }, |
| 94 | + { x: 80, y: viewportHeight * 0.5, scale: 1.1, opacity: 0.85, delay: 0.2 }, |
| 95 | + { x: window.innerWidth - 240, y: viewportHeight * 0.55, scale: 1.2, opacity: 0.85, delay: 0.15 }, |
| 96 | + { x: window.innerWidth / 2 - 80, y: viewportHeight * 0.45, scale: 1.3, opacity: 0.9, delay: 0.25 }, |
| 97 | + { x: 120, y: viewportHeight * 0.15, scale: 0.9, opacity: 0.6, delay: 0.3 }, |
| 98 | + { x: window.innerWidth - 200, y: viewportHeight * 0.05, scale: 0.95, opacity: 0.65, delay: 0.35 }, |
| 99 | + { x: window.innerWidth / 2 - 150, y: viewportHeight * 0.12, scale: 0.85, opacity: 0.55, delay: 0.4 }, |
| 100 | + { x: window.innerWidth / 2 + 100, y: viewportHeight * 0.2, scale: 0.9, opacity: 0.6, delay: 0.45 }, |
| 101 | + { x: 200, y: viewportHeight * 0.4, scale: 1.0, opacity: 0.75, delay: 0.05 }, |
| 102 | + { x: window.innerWidth - 350, y: viewportHeight * 0.42, scale: 1.0, opacity: 0.75, delay: 0.22 }, |
| 103 | + ]; |
| 104 | + |
| 105 | + treePositions.forEach((pos) => { |
| 106 | + container.appendChild(createTree(pos.x, pos.y, pos.scale, pos.opacity, pos.delay)); |
| 107 | + }); |
| 108 | + }, []); |
| 109 | + |
| 110 | + return ( |
| 111 | + <div |
| 112 | + ref={containerRef} |
| 113 | + style={{ |
| 114 | + position: 'absolute', |
| 115 | + width: '100%', |
| 116 | + height: '100%', |
| 117 | + overflow: 'hidden', |
| 118 | + pointerEvents: 'none', |
| 119 | + zIndex: 0, |
| 120 | + }} |
| 121 | + /> |
| 122 | + ); |
| 123 | +} |
0 commit comments