-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
197 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const Code: React.FC<{ children?: string }> = ({ children }) => { | ||
return <code className='bg-gray-100 px-2'>{children}</code> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import type { Meta, StoryFn, StoryObj } from '@storybook/react' | ||
import CommerceLayer from '../_internals/CommerceLayer' | ||
import { AvailabilityTemplate } from '#components/skus/AvailabilityTemplate' | ||
import { AvailabilityContainer } from '#components/skus/AvailabilityContainer' | ||
import PricesContainer from '#components/prices/PricesContainer' | ||
|
||
const setup: Meta<typeof AvailabilityTemplate> = { | ||
title: 'Components/Skus/Availability', | ||
component: AvailabilityTemplate, | ||
argTypes: { | ||
showShippingMethodName: { | ||
control: 'boolean' | ||
}, | ||
showShippingMethodPrice: { | ||
control: 'boolean' | ||
}, | ||
timeFormat: { | ||
control: 'radio', | ||
options: ['days', 'hours', undefined] | ||
} | ||
} | ||
} | ||
|
||
export default setup | ||
|
||
const Template: StoryFn<typeof AvailabilityTemplate> = (args) => { | ||
return ( | ||
<CommerceLayer | ||
accessToken='my-access-token' | ||
endpoint='https://demo-store.commercelayer.io' | ||
> | ||
<AvailabilityContainer skuCode='BABYONBU000000E63E7412MX'> | ||
<AvailabilityTemplate {...args} /> | ||
</AvailabilityContainer> | ||
</CommerceLayer> | ||
) | ||
} | ||
|
||
export const AvailableWithDeliveryTime = Template.bind({}) | ||
AvailableWithDeliveryTime.args = { | ||
timeFormat: 'days', | ||
showShippingMethodName: true, | ||
showShippingMethodPrice: true | ||
} | ||
|
||
/** | ||
* You can customize the text displayed in case of `available`, `outOfStock` or `negativeStock`, using custom `labels`. | ||
*/ | ||
export const WithCustomLabel = Template.bind({}) | ||
WithCustomLabel.args = { | ||
labels: { | ||
available: 'Item is available' | ||
} | ||
} | ||
|
||
/** | ||
* When `sku` is not available, the `delivery_lead_time` will not be displayed. | ||
*/ | ||
export const NotAvailable: StoryFn<typeof AvailabilityTemplate> = (args) => { | ||
return ( | ||
<CommerceLayer | ||
accessToken='my-access-token' | ||
endpoint='https://demo-store.commercelayer.io' | ||
> | ||
<AvailabilityContainer skuCode='BABYONBU000000FFFFFFNBXX'> | ||
<AvailabilityTemplate | ||
timeFormat='days' | ||
showShippingMethodName | ||
showShippingMethodPrice | ||
/> | ||
</AvailabilityContainer> | ||
</CommerceLayer> | ||
) | ||
} | ||
|
||
/** | ||
* You can access the `delivery_lead_times` object using the children props. | ||
* In this way you will be able to apply your own logic when displaying the availability info. | ||
* <span type='info'> | ||
* Check the `delivery_lead_times` resource from our [Core API documentation](https://docs.commercelayer.io/core/v/api-reference/delivery_lead_times/object). | ||
* </span> | ||
*/ | ||
export const ChildrenProps: StoryObj = () => { | ||
return ( | ||
<CommerceLayer | ||
accessToken='my-access-token' | ||
endpoint='https://demo-store.commercelayer.io' | ||
> | ||
<AvailabilityContainer skuCode='BABYONBU000000E63E7412MX'> | ||
<AvailabilityTemplate> | ||
{(childrenProps) => { | ||
return ( | ||
<div> | ||
<p className='font-bold'>Custom logic:</p> | ||
<p className='mb-8'> | ||
{childrenProps.quantity} items available delivered in{' '} | ||
{childrenProps.min?.hours} hours | ||
</p> | ||
<p className='font-bold'>The delivery_lead_times object</p> | ||
<pre key={childrenProps.id}> | ||
{JSON.stringify(childrenProps, null, 2)} | ||
</pre> | ||
</div> | ||
) | ||
}} | ||
</AvailabilityTemplate> | ||
</AvailabilityContainer> | ||
</CommerceLayer> | ||
) | ||
} | ||
ChildrenProps.decorators = [ | ||
(Story) => { | ||
return ( | ||
<CommerceLayer | ||
accessToken='my-access-token' | ||
endpoint='https://demo-store.commercelayer.io' | ||
> | ||
<PricesContainer> | ||
<Story /> | ||
</PricesContainer> | ||
</CommerceLayer> | ||
) | ||
} | ||
] | ||
ChildrenProps.parameters = { | ||
docs: { | ||
source: { | ||
type: 'code' | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/docs/stories/skus/AvailabilityContainer.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { Meta, StoryFn } from '@storybook/react' | ||
import CommerceLayer from '../_internals/CommerceLayer' | ||
import { AvailabilityContainer } from '#components/skus/AvailabilityContainer' | ||
import { Code } from '../_internals/Code' | ||
|
||
const setup: Meta<typeof AvailabilityContainer> = { | ||
title: 'Components/Skus/AvailabilityContainer', | ||
component: AvailabilityContainer | ||
} | ||
|
||
export default setup | ||
|
||
const Template: StoryFn<typeof AvailabilityContainer> = (args) => { | ||
return ( | ||
<CommerceLayer | ||
accessToken='my-access-token' | ||
endpoint='https://demo-store.commercelayer.io' | ||
> | ||
<AvailabilityContainer {...args}> | ||
<div> | ||
I am the availability container, responsible to fetch <Code>sku</Code>{' '} | ||
availability and <Code>delivery_lead_time</Code> | ||
</div> | ||
</AvailabilityContainer> | ||
</CommerceLayer> | ||
) | ||
} | ||
|
||
export const Default = Template.bind({}) | ||
Default.args = { | ||
skuCode: 'BABYONBU000000E63E7412MX', | ||
getQuantity: (quantity) => { | ||
console.log('quantity', quantity) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters