Skip to content

Commit

Permalink
chore: add ui elements to storybook (#370)
Browse files Browse the repository at this point in the history
Co-authored-by: janniks <janniks@users.noreply.github.com>
  • Loading branch information
janniks and janniks committed Mar 2, 2024
1 parent 23a1970 commit 3aa29f0
Showing 1 changed file with 72 additions and 13 deletions.
85 changes: 72 additions & 13 deletions packages/connect/src/stories/ConnectPage.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,82 @@
import { clearSelectedProviderId } from '@stacks/connect-ui';
import { showConnect } from '../ui';
import { getSelectedProviderId } from '@stacks/connect-ui';
import { useReducer } from 'react';
import { disconnect, showConnect, showSignMessage } from '../ui';

export const ConnectPage = ({ children }: { children?: any }) => {
function connect() {
showConnect({
appDetails: {
name: 'Connect Demo',
icon: window.location.origin + '/favicon.ico',
},
});
}
const refresh = useReducer(x => x + 1, 0)[1];

const selectedProviderId = getSelectedProviderId();

return (
<div>
<button onClick={connect}>Connect Wallet</button>
<button onClick={() => clearSelectedProviderId()}>Disconnect</button>
<div style={{ fontFamily: 'monospace' }}>
<div
style={{
display: 'flex',
flexDirection: 'column',
gap: '16px',
}}
>
<div>
<code>selectedProviderId</code>:{' '}
{typeof selectedProviderId === 'undefined'
? 'undefined'
: JSON.stringify(selectedProviderId)}{' '}
<button onClick={() => refresh()}>
<code>Rerender</code>
</button>
</div>

<button
onClick={() => {
showConnect({
appDetails: {
name: 'Connect Demo',
icon: window.location.origin + '/favicon.ico',
},
onFinish: d => {
alert(JSON.stringify(d, null, 2));
refresh();
},
onCancel: () => refresh(),
});
}}
>
<code>showConnect()</code>
</button>

<button
onClick={() => {
showSignMessage({
appDetails: {
name: 'Connect Demo',
icon: window.location.origin + '/favicon.ico',
},
message: 'test',
onFinish: d => {
alert(JSON.stringify(d, null, 2));
refresh();
},
onCancel: () => refresh(),
});
}}
>
<code>showSignMessage()</code>
</button>

<button
onClick={() => {
disconnect();
refresh();
}}
>
<code>disconnect()</code>
</button>
</div>

{children}
<div
style={{
marginTop: '16px',
backgroundColor: '#f0f0f0',
height: '2000px', // very high, to test scrolling
}}
Expand Down

0 comments on commit 3aa29f0

Please sign in to comment.