-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(preact-components-bundlerecommendations): new component for upco…
…ming bundlerecs feature
- Loading branch information
1 parent
e97cb34
commit 5547094
Showing
18 changed files
with
74,227 additions
and
72,437 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
59 changes: 59 additions & 0 deletions
59
...ages/snap-preact-components/src/components/Organisms/BundledRecommendations/BundleCTA.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,59 @@ | ||
/** @jsx jsx */ | ||
import { h, Fragment } from 'preact'; | ||
import { jsx } from '@emotion/react'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { cloneWithProps } from '../../../utilities'; | ||
import { Button } from '../../Atoms/Button'; | ||
import { Price } from '../../Atoms/Price'; | ||
import type { selectedItem } from './BundledRecommendations'; | ||
|
||
export const BundledCTA = observer((properties: BundledCTAProps): JSX.Element => { | ||
const { ctaSlot, selectedItems, bundlePrice, bundleStrikePrice, addToCartFunc, addToCartText } = properties; | ||
|
||
let totalNumProdsInBundle = 0; | ||
|
||
selectedItems.forEach((item) => { | ||
totalNumProdsInBundle += item.quantity; | ||
}); | ||
|
||
return ( | ||
<div className={`ss__bundled-recommendations__product-wrapper__cta`}> | ||
{ctaSlot ? ( | ||
cloneWithProps(ctaSlot, { | ||
selectedItems: selectedItems, | ||
bundlePrice: bundlePrice, | ||
strikePrice: bundleStrikePrice, | ||
onclick: (e: any) => addToCartFunc(e), | ||
}) | ||
) : ( | ||
<Fragment> | ||
<p className="ss__bundled-recommendations__product-wrapper__cta__subtotal"> | ||
{`Subtotal for ${totalNumProdsInBundle} items `} | ||
<div className="ss__bundled-recommendations__product-wrapper__cta__subtotal__prices"> | ||
{bundleStrikePrice && bundleStrikePrice !== bundlePrice && ( | ||
<label className="ss__bundled-recommendations__product-wrapper__cta__subtotal__strike"> | ||
Was <Price lineThrough={true} value={bundleStrikePrice} /> | ||
</label> | ||
)} | ||
<label className="ss__bundled-recommendations__product-wrapper__cta__subtotal__price"> | ||
<Price value={bundlePrice} /> | ||
</label> | ||
</div> | ||
</p> | ||
|
||
<Button onClick={(e) => addToCartFunc(e)}>{addToCartText}</Button> | ||
</Fragment> | ||
)} | ||
</div> | ||
); | ||
}); | ||
|
||
interface BundledCTAProps { | ||
isMobile: boolean; | ||
ctaSlot?: JSX.Element; | ||
selectedItems: selectedItem[]; | ||
bundlePrice: number; | ||
bundleStrikePrice?: number; | ||
addToCartFunc: (e: any) => void; | ||
addToCartText?: string; | ||
} |
86 changes: 86 additions & 0 deletions
86
...snap-preact-components/src/components/Organisms/BundledRecommendations/BundleSelector.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,86 @@ | ||
/** @jsx jsx */ | ||
import { h, ComponentChildren } from 'preact'; | ||
import { jsx } from '@emotion/react'; | ||
import classnames from 'classnames'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { Theme, useTheme } from '../../../providers'; | ||
import { Checkbox, CheckboxProps } from '../../Molecules/Checkbox'; | ||
import { Icon, IconProps } from '../../Atoms/Icon'; | ||
|
||
export const BundleSelector = observer((properties: BundleSelectorProps): JSX.Element => { | ||
const globalTheme: Theme = useTheme(); | ||
|
||
const props: BundleSelectorProps = { | ||
// default props | ||
showCheckboxes: true, | ||
qtyText: 'Qty:', | ||
// global theme | ||
...properties, | ||
}; | ||
|
||
const { children, checked, quantity, icon, seedText, qtyText, showCheckboxes, onCheck, onInputChange } = props; | ||
|
||
const subProps: BundleSelectorSubProps = { | ||
icon: { | ||
// default props | ||
className: 'ss__bundled-recommendations__product-wrapper__selector__icon', | ||
color: 'black', | ||
size: 15, | ||
// global theme | ||
...globalTheme?.components?.icon, | ||
}, | ||
checkbox: { | ||
className: 'ss__bundled-recommendations__product-wrapper__selector__result-wrapper__checkbox', | ||
checked: checked, | ||
onClick: onCheck, | ||
...globalTheme?.components?.checkbox, | ||
}, | ||
}; | ||
|
||
return ( | ||
<div | ||
className={classnames( | ||
'ss__bundled-recommendations__product-wrapper__selector', | ||
seedText ? 'ss__bundled-recommendations__product-wrapper__selector--seed' : '' | ||
)} | ||
> | ||
<div className="ss__bundled-recommendations__product-wrapper__selector__result-wrapper"> | ||
{showCheckboxes && <Checkbox {...subProps.checkbox} />} | ||
{seedText && <div className={'ss__bundled-recommendations__product-wrapper__selector__result-wrapper__seed-badge'}>{seedText}</div>} | ||
{children} | ||
{typeof quantity == 'number' && ( | ||
<div className="ss__bundled-recommendations__product-wrapper__selector__qty"> | ||
{qtyText} | ||
<input | ||
className="ss__bundled-recommendations__product-wrapper__selector__qty__input" | ||
onChange={onInputChange} | ||
aria-label="Product Quantity" | ||
type="number" | ||
min="0" | ||
placeholder="QTY #" | ||
value={quantity} | ||
/> | ||
</div> | ||
)} | ||
</div> | ||
<Icon {...subProps.icon} {...(typeof icon == 'string' ? { icon: icon as string } : (icon as Partial<IconProps>))} /> | ||
</div> | ||
); | ||
}); | ||
|
||
export interface BundleSelectorSubProps { | ||
icon: Partial<IconProps>; | ||
checkbox: Partial<CheckboxProps>; | ||
} | ||
|
||
export interface BundleSelectorProps { | ||
children?: ComponentChildren; | ||
checked?: boolean; | ||
quantity?: number; | ||
seedText?: string; | ||
showCheckboxes?: boolean; | ||
qtyText?: string; | ||
onCheck?: () => void; | ||
onInputChange?: (e: any) => void; | ||
icon?: string | Partial<IconProps> | boolean; | ||
} |
Oops, something went wrong.