Skip to content

Commit 07fa5e2

Browse files
committed
feat: define button as web component
1 parent f9c2f33 commit 07fa5e2

20 files changed

Lines changed: 1502 additions & 2314 deletions

examples/index.html

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@ <h3>superhero-utils example using plain js</h3>
66
<a href="./vue-vite/dist/">vue vite</a>
77

88
<hr />
9-
<div class="icon">Donate</div>
10-
<div class="small">Donate</div>
11-
<div class="medium">Donate</div>
12-
<div class="large">Donate</div>
9+
10+
<link rel="stylesheet" href="./superhero-utils/index.css" />
11+
<link rel="module" href="./superhero-utils/index-without-styles.js" />
12+
13+
<superhero-button
14+
target="ak_gvxNbZf5CuxYVfcUFoKAP4geZatWaC2Yy4jpx5vZoCKank4Gc"
15+
size="icon"
16+
></superhero-button>
17+
<superhero-button target="2707" size="small"></superhero-button>
18+
<superhero-button target="nancyismyname.chain" size="medium"></superhero-button>
19+
<superhero-button
20+
target="ak_gvxNbZf5CuxYVfcUFoKAP4geZatWaC2Yy4jpx5vZoCKank4Gc"
21+
size="large"
22+
></superhero-button>
1323

1424
<hr />
1525
<button class="ensure-paid">Ensure paid</button>
@@ -129,34 +139,19 @@ <h3>superhero-utils example using plain js</h3>
129139
senectus et netus et malesuada fames ac turpis egestas. Donec convallis non odio a commodo.
130140
</p>
131141

132-
<link rel="stylesheet" href="./superhero-utils/index.css" />
133142
<script type="module">
134-
import { createButton, ensurePaid } from './superhero-utils/index-without-styles.js';
143+
import { ensurePaid } from './superhero-utils/index-without-styles.js';
135144

136145
const target = 'ak_gvxNbZf5CuxYVfcUFoKAP4geZatWaC2Yy4jpx5vZoCKank4Gc';
137146

138-
/*
139-
* Create superhero button instance by pointing element with its selector
140-
*/
141-
createButton('.icon', target, { size: 'icon' });
142-
createButton('.small', 2707, { size: 'small' });
143-
createButton('.medium', 'nancyismyname.chain', { size: 'medium' });
144-
145-
/*
146-
* Create superhero button instance by passing DOM element instance
147-
*/
148-
createButton(document.querySelector('.large'), target, { size: 'large' });
149-
150-
// Initialize button a.superhero-tip-button appears dynamically
147+
// Initialize a superhero-button appearing dynamically
151148
setTimeout(function () {
152-
var btn = document.createElement('div');
149+
var btn = document.createElement('superhero-button');
150+
btn.setAttribute('target', target);
153151
document.body.appendChild(btn);
154-
createButton(btn, target);
155152
}, 5000);
156153

157-
document
158-
.querySelector('.ensure-paid')
159-
.addEventListener('click', () => ensurePaid(target));
154+
document.querySelector('.ensure-paid').addEventListener('click', () => ensurePaid(target));
160155

161156
document
162157
.querySelector('.reset-paid-state')

examples/react-unpkg.html

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
<div id="app"></div>
22

3-
<script src="https://unpkg.com/react@17/umd/react.production.min.js"></script>
4-
<script src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>
5-
<script src="https://unpkg.com/prop-types@15/prop-types.min.js"></script>
6-
<script src="./superhero-utils/react-without-styles.js"></script>
73
<link rel="stylesheet" href="./superhero-utils/index.css" />
8-
<script>
9-
class App extends React.Component {
10-
render() {
11-
return React.createElement('div', {}, [
12-
React.createElement('h3', {}, ['superhero-utils example using react, script tag']),
13-
React.createElement(superheroUtils.Button, {
14-
target: 'ak_gvxNbZf5CuxYVfcUFoKAP4geZatWaC2Yy4jpx5vZoCKank4Gc',
15-
size: 'medium',
16-
}),
17-
]);
18-
}
4+
<script type="module">
5+
import React from 'https://esm.sh/react@19';
6+
import { createRoot } from 'https://esm.sh/react-dom@19/client';
7+
import './superhero-utils/index-without-styles.js';
8+
9+
function App() {
10+
return React.createElement('div', {}, [
11+
React.createElement('h3', {}, ['superhero-utils example using react, script tag']),
12+
React.createElement('superhero-button', {
13+
target: 'ak_gvxNbZf5CuxYVfcUFoKAP4geZatWaC2Yy4jpx5vZoCKank4Gc',
14+
size: 'medium',
15+
}),
16+
]);
1917
}
2018

21-
ReactDOM.render(React.createElement(App), document.querySelector('#app'));
19+
createRoot(document.getElementById('app')).render(React.createElement(App));
2220
</script>

0 commit comments

Comments
 (0)