Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: useargs #63

Merged
merged 2 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .storybook/preview-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#key { width: 100%; }

[label="Publishable Key"] {
[data-arg] {
width: 100%;
}

Expand All @@ -24,4 +24,16 @@
grid-gap: 12px;
grid-template-areas: 'stripe button';
}

.cardholder-inputs {
align-items: center;
display: grid;
grid-gap: 12px;
}

@media (min-width: 800px) {
.cardholder-inputs {
grid-template-columns: 1fr 1fr;
}
}
</style>
29 changes: 27 additions & 2 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { setCustomElements } from '@web/storybook-prebuilt/web-components.js';
import { setCustomElementsManifest } from '@web/storybook-prebuilt/web-components.js';
import { useArgs, useEffect } from '@web/storybook-prebuilt/client-api.js';
import cem from '../custom-elements.json';

setCustomElements(cem);
setCustomElementsManifest(cem);

export const parameters = {
controls: { expanded: true },
Expand All @@ -13,3 +14,27 @@ export const parameters = {
},
},
};

const listeners = new WeakSet();

export const decorators = [
story => {
const [, updateArgs] = useArgs();
useEffect(() => {
for (const input of document.querySelectorAll('[data-arg]')) {
if (listeners.has(input))
return;
// prevent storybook ui from responding to keyevents in this input
input.addEventListener('keyup', e => e.stopPropagation());
input.addEventListener('keydown', e => e.stopPropagation());
// update the args
input.addEventListener('change', e => {
updateArgs({ [e.target.dataset.arg]: e.target.value });
localStorage.setItem(`stripe-elements-demo-${e.target.dataset.arg}`, e.target.value);
});
listeners.add(input);
}
});
return story();
}
];
Loading