File size: 2,593 Bytes
dcb9dda
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
class BucketMasterButton extends HTMLElement {
  static get observedAttributes() {
    return ['variant', 'size', 'disabled'];
  }

  constructor() {
    super();
    this.attachShadow({ mode: 'open' });
    this.shadowRoot.innerHTML = `
      <style>
        button {
          display: inline-flex;
          align-items: center;
          justify-content: center;
          border-radius: 6px;
          font-weight: 500;
          transition: all 0.2s;
          cursor: pointer;
          gap: 0.5rem;
        }
        
        /* Variants */
        button.primary {
          background-color: #F7D348;
          color: #000000;
          border: 1px solid #F7D348;
        }
        button.primary:hover {
          background-color: #FFE699;
        }
        
        button.secondary {
          background-color: #FFFFFF;
          color: #000000;
          border: 1px solid #E4E7EB;
        }
        button.secondary:hover {
          background-color: #F8F9FA;
        }
        
        button.danger {
          background-color: #FFFFFF;
          color: #EF4444;
          border: 1px solid #EF4444;
        }
        button.danger:hover {
          background-color: #FEE2E2;
        }
        
        /* Sizes */
        button.small {
          padding: 0.375rem 0.75rem;
          font-size: 0.875rem;
        }
        
        button.medium {
          padding: 0.5rem 1rem;
          font-size: 1rem;
        }
        
        button.large {
          padding: 0.75rem 1.5rem;
          font-size: 1.125rem;
        }
        
        /* Disabled */
        button:disabled {
          opacity: 0.5;
          cursor: not-allowed;
        }
      </style>
      <button>
        <slot></slot>
      </button>
    `;
  }

  connectedCallback() {
    const button = this.shadowRoot.querySelector('button');
    const variant = this.getAttribute('variant') || 'primary';
    const size = this.getAttribute('size') || 'medium';
    const disabled = this.hasAttribute('disabled');

    button.classList.add(variant, size);
    button.disabled = disabled;
  }

  attributeChangedCallback(name, oldValue, newValue) {
    const button = this.shadowRoot.querySelector('button');
    
    if (name === 'variant') {
      button.classList.remove(oldValue);
      button.classList.add(newValue);
    }
    
    if (name === 'size') {
      button.classList.remove(oldValue);
      button.classList.add(newValue);
    }
    
    if (name === 'disabled') {
      button.disabled = newValue !== null;
    }
  }
}
customElements.define('bucketmaster-button', BucketMasterButton);