Skip to content

Commit

Permalink
Merge pull request #103 from commerce-docs/USF-1323-checkout-dropin
Browse files Browse the repository at this point in the history
USF-1323: Checkout dropin
  • Loading branch information
jeff-matthews authored Nov 11, 2024
2 parents af89c3b + 33a3059 commit 270c781
Show file tree
Hide file tree
Showing 37 changed files with 2,192 additions and 101 deletions.
25 changes: 20 additions & 5 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,26 @@ export default defineConfig({
collapsed: true,
items: [
{ label: 'Overview', link: '/dropins/checkout/' },
// { label: 'Checkout Installation', link: '/dropins/checkout/checkout-installation/' },
// { label: 'Checkout Styles', link: '/dropins/checkout/checkout-styles/' },
// { label: 'Checkout Containers', link: '/dropins/checkout/checkout-containers/' },
// { label: 'Checkout Slots', link: '/dropins/checkout/checkout-slots/' },
// { label: 'Checkout Functions', link: '/dropins/checkout/checkout-functions/' },
{ label: 'Installation', link: '/dropins/checkout/installation/' },
{ label: 'Initialization', link: '/dropins/checkout/initialization/' },
{ label: 'Styles', link: '/dropins/checkout/styles/' },
{ label: 'Containers',
collapsed: true,
items: [
{ label: 'BillToShippingAddress', link: '/dropins/checkout/containers/bill-to-shipping-address/' },
{ label: 'EstimateShipping', link: '/dropins/checkout/containers/estimate-shipping/' },
{ label: 'LoginForm', link: '/dropins/checkout/containers/login-form/' },
{ label: 'MergedCartBanner', link: '/dropins/checkout/containers/merged-cart-banner/' },
{ label: 'OrderConfirmationHeader', link: '/dropins/checkout/containers/order-confirmation-header/' },
{ label: 'OutOfStock', link: '/dropins/checkout/containers/out-of-stock/' },
{ label: 'PaymentMethods', link: '/dropins/checkout/containers/payment-methods/' },
{ label: 'PlaceOrder', link: '/dropins/checkout/containers/place-order/' },
{ label: 'ServerError', link: '/dropins/checkout/containers/server-error/' },
{ label: 'ShippingMethods', link: '/dropins/checkout/containers/shipping-methods/' },
]
},
// { label: 'Slots', link: '/dropins/checkout/slots/' },
{ label: 'Functions', link: '/dropins/checkout/functions/' },
]
},
{
Expand Down
Binary file added public/images/dropins/findstylescheckout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/images/pdp/pdp-installation.png
Binary file not shown.
32 changes: 20 additions & 12 deletions src/components/OptionsTable.astro
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ const newRows = rows.map((row) => {
} else {
let isLastCell = index === row.length - 1;
if (isLastCell) {
return <td class="lastCell">{cell}</td>;
return (
<td class="lastCell">
<markdown>{cell}</markdown>
</td>
);
}
return <td class={cellClassNameOverride}>{cell}</td>;
}
Expand All @@ -104,7 +108,7 @@ const newRows = rows.map((row) => {
margin-left: 0;
}
.optionsTable table.table {
display: table;
display: inline-block;
min-width: 100%;
table-layout: auto;
border-collapse: collapse;
Expand All @@ -121,42 +125,43 @@ const newRows = rows.map((row) => {

tr.headerRow {
border-top: 0 none transparent;
border-bottom: 1px solid rgb(220, 220, 220);
padding: 1rem 1rem;
border-bottom: 0.5px solid rgb(220, 220, 220);
padding: 1rem;
padding-bottom: 0.5rem;
text-align: left;
white-space: nowrap;
}

td.headerCell {
border: none;
padding: 0.5rem 0;
padding: 2rem 0;
font-weight: 600;
white-space: nowrap;
}

tbody.body {
vertical-align: baseline;
white-space: nowrap;
font-size: 0.9rem;
font-size: 1rem;
padding: 1rem 0;
}

tr.row {
white-space: nowrap;
border-bottom: 1px solid rgb(220, 220, 220);
border-bottom: 0.5px solid rgb(220, 220, 220);
line-height: 1.5rem;
padding: 1rem 0;
}

tr td.cell {
padding: 0;
padding-right: 1.5rem;
padding: 0.5rem 0;
padding-right: 3rem;
font-family: inherit;
border-bottom: 1px solid rgb(220, 220, 220);
white-space: nowrap;
}

tr td.compactCell {
padding: 0;
padding-right: 1.5rem;
padding-right: 3rem;
padding-left: 0.25rem;
line-height: 1.5rem;
border: none;
Expand Down Expand Up @@ -191,6 +196,9 @@ const newRows = rows.map((row) => {
td td a:hover {
color: var(--sl-color-text-accent);
}
td.lastCell {
padding-bottom: 0.5rem;
}

@media screen and (max-width: 600px) {
tbody.body {
Expand Down
9 changes: 0 additions & 9 deletions src/content/docs/dropins/checkout/checkout-containers.mdx

This file was deleted.

9 changes: 0 additions & 9 deletions src/content/docs/dropins/checkout/checkout-functions.mdx

This file was deleted.

9 changes: 0 additions & 9 deletions src/content/docs/dropins/checkout/checkout-installation.mdx

This file was deleted.

9 changes: 0 additions & 9 deletions src/content/docs/dropins/checkout/checkout-slots.mdx

This file was deleted.

9 changes: 0 additions & 9 deletions src/content/docs/dropins/checkout/checkout-styles.mdx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: BillToShippingAddress container
description: Configure the BillToShippingAddress container to manage and display the billing address form during checkout.
---

import OptionsTable from '@components/OptionsTable.astro';

The `BillToShippingAddress` container includes a checkbox that allows users to indicate if the billing address is the same as the shipping address. If unchecked, the billing address form will be displayed.

## BillToShippingAddress configurations

The `BillToShippingAddress` container provides the following configuration options:

<OptionsTable
compact
options={[
['Option', 'Type', 'Req?', 'Description'],
['hideOnVirtualCart', 'boolean', 'No', 'Hides the container if the cart is virtual.'],
['onChange', 'function', 'No', 'Callback function that is called when the checkbox state changes.'],
]}
/>

## Example

The following example renders the `BillToShippingAddress` container on a checkout page. It includes functionality to hide the component for virtual carts and to handle changes to the billing address form visibility and validation. If the billing address form is shown, it validates the form data and updates the billing address on the cart.

```ts
import BillToShippingAddress from '@dropins/storefront-checkout/containers/BillToShippingAddress.js';
import { render as CheckoutProvider } from '@dropins/storefront-checkout/render.js';

const $billToShipping = checkoutFragment.querySelector(
'.checkout__bill-to-shipping'
);

CheckoutProvider.render(BillToShippingAddress, {
hideOnVirtualCart: true,
onChange: (checked) => {
$billingForm.style.display = checked ? 'none' : 'block';

if (!checked && billingFormRef.current) {
const isDataValid = billingFormRef.current.handleValidationSubmit();

setAddressOnCart(
{ data: billingFormRef.current.formData, isDataValid },
checkoutApi.setBillingAddress
);
}
},
})($billToShipping),
```
36 changes: 36 additions & 0 deletions src/content/docs/dropins/checkout/containers/estimate-shipping.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: EstimateShipping container
description: Learn how the EstimateShipping container displays shipping costs during checkout.
---

import OptionsTable from '@components/OptionsTable.astro';

The `EstimateShipping` container is designed to estimate and display shipping costs during the checkout process.

## EstimateShipping configurations

The `EstimateShipping` container is read-only, unlike the editable [`EstimateShipping`](/dropins/cart/cart-slots/#estimateshipping) container in the cart drop-in component. Initially, it displays estimated shipping costs. After a customer provides a shipping address and selects a shipping method, it shows the actual shipping cost. This container is designed to be used as a slot within the `OrderSummary` container from the cart, where the estimated shipping information is displayed.

## Example

The following example renders an `OrderSummary` container within a checkout page and includes a slot for estimating shipping:

```ts
import { OrderSummary } from '@dropins/storefront-cart/containers/OrderSummary.js';
import { render as CartProvider } from '@dropins/storefront-cart/render.js';
import EstimateShipping from '@dropins/storefront-checkout/containers/EstimateShipping.js';

const $orderSummary = checkoutFragment.querySelector(
'.checkout__order-summary'
);

CartProvider.render(OrderSummary, {
slots: {
EstimateShipping: (esCtx) => {
const estimateShippingForm = document.createElement('div');
CheckoutProvider.render(EstimateShipping)(estimateShippingForm);
esCtx.appendChild(estimateShippingForm);
},
},
})($orderSummary),
```
59 changes: 59 additions & 0 deletions src/content/docs/dropins/checkout/containers/login-form.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: LoginForm container
description: Configure the LoginForm container to handle user email input and validation during checkout.
---

import OptionsTable from '@components/OptionsTable.astro';

The `LoginForm` container is designed to handle user email input and validation within the checkout process.

## LoginForm configurations

The `LoginForm` container provides the following configuration options:

<OptionsTable
compact
options={[
['Option', 'Type', 'Req?', 'Description'],
['onSignInClick', 'function', 'No', 'A function that handles the sign-in button click. It takes the email (string or null) as an argument.'],
['onSignOutClick', 'function', 'No', 'A function that handles the sign-out button click. It takes no arguments.'],
]}
/>

## Example

The following example renders the `LoginForm` container on a checkout page, which includes rendering the [`AuthCombine`](/dropins/user-auth/containers/auth-combine/) container from the user auth drop-in component in a modal for authentication:

```ts
import AuthCombine from '@dropins/storefront-auth/containers/AuthCombine.js';
import { render as AuthProvider } from '@dropins/storefront-auth/render.js';

import LoginForm from '@dropins/storefront-checkout/containers/LoginForm.js';
import { render as CheckoutProvider } from '@dropins/storefront-checkout/render.js';

const $login = checkoutFragment.querySelector('.checkout__login');

CheckoutProvider.render(LoginForm, {
name: LOGIN_FORM_NAME,
onSignInClick: async (initialEmailValue) => {
const signInForm = document.createElement('div');

AuthProvider.render(AuthCombine, {
signInFormConfig: {
renderSignUpLink: true,
initialEmailValue,
onSuccessCallback: () => {
displayOverlaySpinner();
},
},
signUpFormConfig: {},
resetPasswordFormConfig: {},
})(signInForm);

showModal(signInForm);
},
onSignOutClick: () => {
authApi.revokeCustomerToken();
},
})($login),
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: MergedCartBanner container
description: Configure the MergedCartBanner container to display notifications when items from an old cart are merged into the current cart.
---

import OptionsTable from '@components/OptionsTable.astro';

The `MergedCartBanner` container is designed to display a notification banner when items from an old cart are merged into the current cart.

When a customer signs in, if they had items in a previous cart, a banner will notify them that the items from their previous cart have been merged with the current cart. You can apply styles to the banner by passing a `className` prop to the container.

## MergedCartBanner configurations

The `MergedCartBanner` container provides the following configuration options:

<OptionsTable
compact
options={[
['Option', 'Type', 'Req?', 'Description'],
['className', 'string', 'No', 'The CSS class name(s) to apply to the component.'],
]}
/>

## Example

The following example renders the `MergedCartBanner` container with a custom class name:

```ts
import MergedCartBanner from '@dropins/storefront-checkout/containers/MergedCartBanner.js';
import { render as CheckoutProvider } from '@dropins/storefront-checkout/render.js';

const $mergedCartBanner = checkoutFragment.querySelector(
'.checkout__merged-cart-banner'
);

CheckoutProvider.render(MergedCartBanner, {
className: 'checkout__merged-cart-banner--custom',
})($mergedCartBanner);
```
`;
Loading

0 comments on commit 270c781

Please sign in to comment.