Skip to content

Commit f1cbc16

Browse files
Merge pull request #121 from commercelayer/docs-update-demo
Update demo example
2 parents 10a21cf + 353650e commit f1cbc16

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

packages/docs/stories/introduction.mdx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Canvas, Meta, Story } from '@storybook/addon-docs/blocks'
22
import { linkTo } from '@storybook/addon-links'
3-
import * as Stories from './introduction.stories.ts';
3+
import * as Stories from './introduction.stories.ts'
4+
import { Alert } from './assets/components'
45
import { Card } from './assets/components'
56

67
<Meta of={Stories} />
@@ -51,3 +52,9 @@ If you want to see most of the reusable components above in action before diggin
5152
We've called it a demo, but the truth is that by switching the linked organization [from test to live mode](https://docs.commercelayer.io/core/api-specification#environments) on the Commerce Layer Admin Dashboard, this can be considered a full-fledged, up and running production website 😮 — and it took a snap to build it!
5253

5354
<Canvas sourceState="hidden" of={Stories.Basic} />
55+
56+
<Alert title="How to run the demo locally?" type="info">
57+
You can simply copy and paste the example above into a new HTML file named `index.html`.
58+
Opening the `index.html` file directly in a browser won’t work because cookies are disabled when using the `file://` protocol for security reasons.
59+
Make sure to run the file through an HTTP server instead, for example, by using the [Live Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) extension in VS Code, or by running [`npx serve`](https://www.npmjs.com/package/serve) if you’re familiar with Node.js.
60+
</Alert>

packages/docs/stories/introduction.stories.ts

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import type { Meta, StoryFn } from "@storybook/html-vite"
22
import { html } from "lit-html"
3+
import { PARAM_KEY as DROP_IN_CSS_PARAM_KEY } from "../.storybook/addon-drop-in-css/constants"
4+
import { PARAM_KEY as MINICART_CSS_PARAM_KEY } from "../.storybook/addon-minicart-css/constants"
5+
import { getSelectedScopeValue } from "../.storybook/addon-scope-selector/constants"
36
import { create } from "../utils"
47
import { codes } from "./assets/constants"
58

@@ -9,9 +12,45 @@ const meta: Meta = {
912

1013
export default meta
1114

12-
export const Basic: StoryFn = () => {
15+
export const Basic: StoryFn = (_args, context) => {
16+
const baseUrl = location.href.substring(
17+
0,
18+
location.href.indexOf("/iframe.html"),
19+
)
20+
21+
const dropInCssEnabled = context.globals[DROP_IN_CSS_PARAM_KEY]
22+
const minicartCssEnabled = context.globals[MINICART_CSS_PARAM_KEY]
23+
1324
return create(
1425
html`
26+
${dropInCssEnabled ? html`<link href="https://cdn.jsdelivr.net/npm/@commercelayer/drop-in.js@2/dist/drop-in/drop-in.css" rel="stylesheet" />` : ""}
27+
${minicartCssEnabled ? html`<link href="https://cdn.jsdelivr.net/npm/@commercelayer/drop-in.js@2/dist/drop-in/minicart.css" rel="stylesheet" />` : ""}
28+
29+
<script type="module" src="https://cdn.jsdelivr.net/npm/@commercelayer/drop-in.js@2/dist/drop-in/drop-in.esm.js"></script>
30+
31+
<script>
32+
window.commercelayerConfig = {
33+
clientId: 'kuSKPbeKbU9LG9LjndzieKWRcfiXFuEfO0OYHXKH9J8',
34+
scope: '${getSelectedScopeValue()}',
35+
debug: 'all', // default is 'none'
36+
defaultAttributes: {
37+
orders: {
38+
/**
39+
* The preferred language code (ISO 639-1) to be used when communicating with the customer.
40+
* If the language is supported, the hosted checkout will be localized accordingly.
41+
* @default 'en'
42+
*/
43+
language_code: 'en',
44+
/**
45+
* The URL the cart's *Continue shopping* button points to. This is also used in the thank you page.
46+
* @optional
47+
*/
48+
return_url: 'https://example.com'
49+
}
50+
}
51+
}
52+
</script>
53+
1554
<!-- for demonstration purpose only -->
1655
<script src="https://cdn.tailwindcss.com"></script>
1756
@@ -54,6 +93,7 @@ export const Basic: StoryFn = () => {
5493
<div class="flex flex-col">
5594
<div class="h-80 sm:h-64">
5695
<img
96+
alt="Gray Five-Panel Cap with White Logo"
5797
src="https://data.commercelayer.app/seed/images/skus/${codes.outOfStock}_FLAT.png"
5898
class="w-full h-full object-center object-contain"
5999
/>
@@ -83,6 +123,7 @@ export const Basic: StoryFn = () => {
83123
<div class="flex flex-col">
84124
<div class="h-80 sm:h-64">
85125
<img
126+
alt="White Backpack with Black Logo"
86127
src="https://data.commercelayer.app/seed/images/skus/${codes.noDiscount}_FLAT.png"
87128
class="w-full h-full object-center object-contain"
88129
/>
@@ -112,6 +153,7 @@ export const Basic: StoryFn = () => {
112153
<div class="flex flex-col">
113154
<div class="h-80 sm:h-64 flex justify-center">
114155
<img
156+
alt="Getting Started bundle"
115157
src="https://res.cloudinary.com/commercelayer/image/upload/v1681465805/demo-store/assets/white-glossy-mug-15oz-valentines-day.png"
116158
class="h-full object-center object-contain rounded-md"
117159
/>
@@ -142,13 +184,15 @@ export const Basic: StoryFn = () => {
142184
<!-- Editorial Banner -->
143185
<div class="flex flex-col items-center mt-8">
144186
<cl-identity-status class="h-full" type="guest">
145-
<img class="object-contain position-top max-h-[470px]" src="register-h.jpg" />
187+
<cl-identity-link type="signup" target="_parent">
188+
<img class="object-contain position-top max-h-[470px]" src="${baseUrl}/register-h.jpg" alt="Register" />
189+
</cl-identity-link>
146190
</cl-identity-status>
147191
148192
<cl-identity-status class="h-full" type="customer">
149-
<img class="object-contain position-top max-h-[470px]" src="welcomeback-h.jpg" />
193+
<img class="object-contain position-top max-h-[470px]" src="${baseUrl}/welcomeback-h.jpg" alt="Welcome Back" />
150194
</cl-identity-status>
151195
</div>
152196
`,
153-
)
197+
).replaceAll("<!---->", "")
154198
}

0 commit comments

Comments
 (0)