dinocollab-shared 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import{objectSpread2 as r,inherits as e,createClass as n,classCallCheck as o,callSuper as t,defineProperty as i}from"../_virtual/_rollupPluginBabelHelpers.js";import{jsx as a,jsxs as l}from"react/jsx-runtime";import{Fragment as c,Component as s}from"react";import{ImageWithFallback as m}from"dinocollab-core/components";import{Badge as d,Typography as p,Divider as u,Button as h,Box as f,IconButton as v}from"@mui/material";import C from"@mui/icons-material/Remove";import g from"@mui/icons-material/ShoppingCartOutlined";import x from"@mui/icons-material/ShoppingCartCheckout";import{MenuStyled as b,CartContentStyled as k,cartContentClasses as N}from"./styled.js";import{getTotalData as P}from"./helpers.js";import{useCartStore as y,useCartActions as S}from"./hook.js";import{DarkIconButton as j}from"../components/buttons.js";import{NoDataPanel as E}from"../components/no-data-panel.js";var I=function(){function r(e){var n;return o(this,r),n=t(this,r,[e]),i(n,"render",function(){return l(c,{children:[a(j,{onClick:function(r){return n.onOpen(r.currentTarget)},children:a(d,{badgeContent:n.props.data.length,color:"primary",children:a(g,{})})}),a(b,{disableScrollLock:!0,anchorEl:n.state.anchorEl,open:Boolean(n.state.anchorEl),onClose:n.onClose,anchorOrigin:{vertical:"top",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{component:"div"},children:n.renderContent()})]})}),i(n,"renderContent",function(){var r=P(n.props.data);return l(k,{children:[l("div",{className:N.header,children:[l(p,{variant:"h6",component:"span",sx:{flex:1},children:["Your Cart (",r.amount," items)"]}),l(p,{variant:"h6",component:"span",children:["Total: $ ",r.price.toFixed(2)]})]}),a(u,{}),l("div",{className:N.items,children:[n.props.data.map(function(r,e){return a(c,{children:n.renderItem(r)},"key"+e)}),n.props.data.length<1&&a(E,{title:"Your cart is empty",subTitle:"Try adding some products",sx:{height:"100%"}})]}),a(u,{}),a("div",{className:N.footer,children:a(h,{color:"inherit",endIcon:a(x,{}),onClick:n.onClose,disabled:n.props.data.length<1,children:"Show in cart"})})]})}),i(n,"renderItem",function(r){var e,o,t,i,c,s=n.props.baseUrl.api+(null==r?void 0:r.PictureUrl);return l("div",{className:N.item,children:[a(m,{className:N.itemImg,src:s,title:s,fallbackSrc:"images/default-video.webp",alt:"product-picture"}),l("div",{className:N.itemContent,children:[a(p,{className:N.itemTag,variant:"caption",sx:{color:null!==(e=r.PriceColor)&&void 0!==e?e:"#000"},children:null!==(o=r.PriceName)&&void 0!==o?o:"Unknown Price"}),a(p,{className:N.itemTitle,noWrap:!0,variant:"subtitle1",children:null!==(t=r.ProductName)&&void 0!==t?t:"Unknown Product"}),l(f,{sx:{display:"flex",alignItems:"flex-end",gap:"2px",justifyContent:"flex-end"},children:[l(p,{variant:"subtitle1",children:["$ ",null!==(i=r.Price)&&void 0!==i?i:0]}),l(p,{variant:"body1",sx:{fontSize:"14px",mb:"3px",color:"#818181"},children:["x",null!==(c=r.Amount)&&void 0!==c?c:0," urls"]})]})]}),a(v,{size:"small",onClick:function(){var e,o;return null===(e=(o=n.props).onRemove)||void 0===e?void 0:e.call(o,r)},sx:{color:"#818181"},children:a(C,{})})]})}),i(n,"onOpen",function(r){n.setState({anchorEl:r})}),i(n,"onClose",function(){n.setState({anchorEl:null})}),n.state={anchorEl:null},n}return e(r,s),n(r)}(),T=function(e){var n=y().items,o=S().removeFromCart;return a(I,r({data:n,onRemove:function(r){o(r.ProductId)}},e))},O=function(e){var n=function(n){return a(T,r(r({},e),n))};return n.displayName="CartWidget",n};export{T as CartWidget,O as createCartWidget};
1
+ import{objectSpread2 as r,inherits as e,createClass as n,classCallCheck as o,callSuper as t,defineProperty as i}from"../_virtual/_rollupPluginBabelHelpers.js";import{jsx as a,jsxs as l}from"react/jsx-runtime";import{Fragment as c,Component as s}from"react";import{ImageWithFallback as m}from"dinocollab-core/components";import{Badge as d,Typography as p,Divider as u,Button as h,Box as f,IconButton as v}from"@mui/material";import{MfeLink as C}from"dinocollab-core/mfe-shared";import g from"@mui/icons-material/Remove";import b from"@mui/icons-material/ShoppingCartOutlined";import x from"@mui/icons-material/ShoppingCartCheckout";import{MenuStyled as y,CartContentStyled as k,cartContentClasses as N}from"./styled.js";import{getTotalData as P}from"./helpers.js";import{useCartStore as S,useCartActions as j}from"./hook.js";import{DarkIconButton as E}from"../components/buttons.js";import{NoDataPanel as I}from"../components/no-data-panel.js";var T=function(){function r(e){var n;return o(this,r),n=t(this,r,[e]),i(n,"render",function(){return l(c,{children:[a(E,{onClick:function(r){return n.onOpen(r.currentTarget)},children:a(d,{badgeContent:n.props.data.length,color:"primary",children:a(b,{})})}),a(y,{disableScrollLock:!0,anchorEl:n.state.anchorEl,open:Boolean(n.state.anchorEl),onClose:n.onClose,anchorOrigin:{vertical:"top",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"right"},MenuListProps:{component:"div"},children:n.renderContent()})]})}),i(n,"renderContent",function(){var r=P(n.props.data);return l(k,{children:[l("div",{className:N.header,children:[l(p,{variant:"h6",component:"span",sx:{flex:1},children:["Your Cart (",r.amount," items)"]}),l(p,{variant:"h6",component:"span",children:["Total: $ ",r.price.toFixed(2)]})]}),a(u,{}),l("div",{className:N.items,children:[n.props.data.map(function(r,e){return a(c,{children:n.renderItem(r)},"key"+e)}),n.props.data.length<1&&a(I,{title:"Your cart is empty",subTitle:"Try adding some products",sx:{height:"100%"}})]}),a(u,{}),a("div",{className:N.footer,children:a(h,{component:C,primaryHref:n.props.baseUrl.client+"/cart",secondaryHref:"cart",internal:"client"===n.props.site,color:"inherit",endIcon:a(x,{}),onClick:n.onClose,disabled:n.props.data.length<1,children:"Show in cart"})})]})}),i(n,"renderItem",function(r){var e,o,t,i,c,s=n.props.baseUrl.api+(null==r?void 0:r.PictureUrl);return l("div",{className:N.item,children:[a(m,{className:N.itemImg,src:s,title:s,fallbackSrc:"images/default-video.webp",alt:"product-picture"}),l("div",{className:N.itemContent,children:[a(p,{className:N.itemTag,variant:"caption",sx:{color:null!==(e=r.PriceColor)&&void 0!==e?e:"#000"},children:null!==(o=r.PriceName)&&void 0!==o?o:"Unknown Price"}),a(p,{className:N.itemTitle,noWrap:!0,variant:"subtitle1",children:null!==(t=r.ProductName)&&void 0!==t?t:"Unknown Product"}),l(f,{sx:{display:"flex",alignItems:"flex-end",gap:"2px",justifyContent:"flex-end"},children:[l(p,{variant:"subtitle1",children:["$ ",null!==(i=r.Price)&&void 0!==i?i:0]}),l(p,{variant:"body1",sx:{fontSize:"14px",mb:"3px",color:"#818181"},children:["x",null!==(c=r.Amount)&&void 0!==c?c:0," urls"]})]})]}),a(v,{size:"small",onClick:function(){var e,o;return null===(e=(o=n.props).onRemove)||void 0===e?void 0:e.call(o,r)},sx:{color:"#818181"},children:a(g,{})})]})}),i(n,"onOpen",function(r){n.setState({anchorEl:r})}),i(n,"onClose",function(){n.setState({anchorEl:null})}),n.state={anchorEl:null},n}return e(r,s),n(r)}(),O=function(e){var n=S().items,o=j().removeFromCart;return a(T,r({data:n,onRemove:function(r){o(r.ProductId)}},e))},U=function(e){var n=function(n){return a(O,r(r({},e),n))};return n.displayName="CartWidget",n};export{O as CartWidget,U as createCartWidget};
2
2
  //# sourceMappingURL=widget.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"widget.js","sources":["../../src/cart/widget.tsx"],"sourcesContent":["import { Component, Fragment, useCallback } from 'react'\r\nimport { ImageWithFallback } from 'dinocollab-core/components'\r\nimport { Badge, Box, Button, Divider, IconButton, Typography } from '@mui/material'\r\nimport { MfeLink } from 'dinocollab-core/mfe-shared'\r\nimport type { FC } from 'react'\r\nimport RemoveIcon from '@mui/icons-material/Remove'\r\nimport ShoppingCartOutlinedIcon from '@mui/icons-material/ShoppingCartOutlined'\r\nimport ShoppingCartCheckoutIcon from '@mui/icons-material/ShoppingCartCheckout'\r\nimport { ICartItem } from './types'\r\nimport { cartContentClasses, CartContentStyled, MenuStyled } from './styled'\r\nimport { getTotalData } from './helpers'\r\nimport { useCartActions, useCartStore } from './hook'\r\nimport { IAppSiteBaseUrl, IAppSiteProps } from '../types'\r\nimport { DarkIconButton, NoDataPanel } from '../components'\r\n\r\ninterface ICartWidgetBaseProps extends IAppSiteProps {\r\n baseUrl: IAppSiteBaseUrl\r\n /** Optional storage key to differentiate between different cart instances */\r\n storageKey?: string\r\n}\r\n\r\ninterface ICartWidgetProps extends ICartWidgetBaseProps {\r\n data: ICartItem[]\r\n onRemove?: (item: ICartItem) => void\r\n}\r\n\r\ninterface ICartWidgetState {\r\n anchorEl: HTMLElement | null\r\n}\r\n\r\nclass CartWidgetBase extends Component<ICartWidgetProps, ICartWidgetState> {\r\n constructor(props: ICartWidgetProps) {\r\n super(props)\r\n this.state = { anchorEl: null }\r\n }\r\n\r\n render = () => (\r\n <Fragment>\r\n <DarkIconButton onClick={(e) => this.onOpen(e.currentTarget)}>\r\n <Badge badgeContent={this.props.data.length} color='primary'>\r\n <ShoppingCartOutlinedIcon />\r\n </Badge>\r\n </DarkIconButton>\r\n <MenuStyled\r\n disableScrollLock\r\n anchorEl={this.state.anchorEl}\r\n open={Boolean(this.state.anchorEl)}\r\n onClose={this.onClose}\r\n anchorOrigin={{ vertical: 'top', horizontal: 'right' }}\r\n transformOrigin={{ vertical: 'top', horizontal: 'right' }}\r\n MenuListProps={{ component: 'div' }}\r\n >\r\n {this.renderContent()}\r\n </MenuStyled>\r\n </Fragment>\r\n )\r\n\r\n renderContent = () => {\r\n const totalData = getTotalData(this.props.data)\r\n return (\r\n <CartContentStyled>\r\n <div className={cartContentClasses.header}>\r\n <Typography variant='h6' component='span' sx={{ flex: 1 }}>\r\n Your Cart ({totalData.amount} items)\r\n </Typography>\r\n <Typography variant='h6' component='span'>\r\n Total: $ {totalData.price.toFixed(2)}\r\n </Typography>\r\n </div>\r\n <Divider />\r\n <div className={cartContentClasses.items}>\r\n {this.props.data.map((x, i) => (\r\n <Fragment key={'key' + i}>{this.renderItem(x)}</Fragment>\r\n ))}\r\n {this.props.data.length < 1 && <NoDataPanel title='Your cart is empty' subTitle='Try adding some products' sx={{ height: '100%' }} />}\r\n </div>\r\n <Divider />\r\n <div className={cartContentClasses.footer}>\r\n <Button\r\n // component={MfeLink}\r\n // primaryHref={this.props.baseUrl.client + '/cart'}\r\n // secondaryHref='cart'\r\n // internal={this.props.site === 'client'}\r\n color='inherit'\r\n endIcon={<ShoppingCartCheckoutIcon />}\r\n onClick={this.onClose}\r\n disabled={this.props.data.length < 1}\r\n >\r\n Show in cart\r\n </Button>\r\n </div>\r\n </CartContentStyled>\r\n )\r\n }\r\n\r\n renderItem = (item: ICartItem) => {\r\n const src = this.props.baseUrl.api + item?.PictureUrl\r\n return (\r\n <div className={cartContentClasses.item}>\r\n <ImageWithFallback\r\n className={cartContentClasses.itemImg}\r\n src={src}\r\n title={src}\r\n fallbackSrc='images/default-video.webp'\r\n alt='product-picture'\r\n />\r\n <div className={cartContentClasses.itemContent}>\r\n <Typography className={cartContentClasses.itemTag} variant='caption' sx={{ color: item.PriceColor ?? '#000' }}>\r\n {item.PriceName ?? 'Unknown Price'}\r\n </Typography>\r\n <Typography className={cartContentClasses.itemTitle} noWrap variant='subtitle1'>\r\n {item.ProductName ?? 'Unknown Product'}\r\n </Typography>\r\n <Box sx={{ display: 'flex', alignItems: 'flex-end', gap: '2px', justifyContent: 'flex-end' }}>\r\n <Typography variant='subtitle1'>$ {item.Price ?? 0}</Typography>\r\n <Typography variant='body1' sx={{ fontSize: '14px', mb: '3px', color: '#818181' }}>\r\n x{item.Amount ?? 0} urls\r\n </Typography>\r\n </Box>\r\n </div>\r\n <IconButton size='small' onClick={() => this.props.onRemove?.(item)} sx={{ color: '#818181' }}>\r\n <RemoveIcon />\r\n </IconButton>\r\n </div>\r\n )\r\n }\r\n\r\n onOpen = (target: HTMLElement) => {\r\n this.setState({ anchorEl: target })\r\n }\r\n\r\n onClose = () => {\r\n this.setState({ anchorEl: null })\r\n }\r\n}\r\n\r\nexport const CartWidget: FC<ICartWidgetBaseProps> = (props) => {\r\n const { items } = useCartStore()\r\n const { removeFromCart } = useCartActions<ICartItem>()\r\n\r\n return (\r\n <CartWidgetBase\r\n data={items}\r\n onRemove={(x) => {\r\n removeFromCart(x.ProductId)\r\n }}\r\n {...props}\r\n />\r\n )\r\n}\r\n\r\nexport const createCartWidget = (params: ICartWidgetBaseProps) => {\r\n const _CartWidget: FC<Partial<ICartWidgetBaseProps>> = (props) => <CartWidget {...params} {...props} />\r\n _CartWidget.displayName = 'CartWidget'\r\n return _CartWidget\r\n}\r\n"],"names":["CartWidgetBase","props","_this","_classCallCheck","_callSuper","_defineProperty","_jsxs","Fragment","children","_jsx","DarkIconButton","onClick","e","onOpen","currentTarget","Badge","badgeContent","data","length","color","ShoppingCartOutlinedIcon","MenuStyled","disableScrollLock","anchorEl","state","open","Boolean","onClose","anchorOrigin","vertical","horizontal","transformOrigin","MenuListProps","component","renderContent","totalData","getTotalData","CartContentStyled","className","cartContentClasses","header","Typography","variant","sx","flex","amount","price","toFixed","Divider","items","map","x","i","renderItem","NoDataPanel","title","subTitle","height","footer","Button","endIcon","ShoppingCartCheckoutIcon","disabled","item","_item$PriceColor","_item$PriceName","_item$ProductName","_item$Price","_item$Amount","src","baseUrl","api","PictureUrl","ImageWithFallback","itemImg","fallbackSrc","alt","itemContent","itemTag","PriceColor","PriceName","itemTitle","noWrap","ProductName","Box","display","alignItems","gap","justifyContent","Price","fontSize","mb","Amount","IconButton","size","_this$props$onRemove","_this$props","onRemove","call","RemoveIcon","target","setState","_inherits","Component","_createClass","CartWidget","useCartStore","removeFromCart","useCartActions","_objectSpread","ProductId","createCartWidget","params","_CartWidget","displayName"],"mappings":"03BAa2D,IAiBrDA,aACJ,SAAAA,EAAYC,GAAuB,IAAAC,EAEF,OAFEC,OAAAH,GACjCE,EAAAE,EAAAJ,KAAAA,GAAMC,IAAMI,EAAAH,EAIL,SAAA,WAAA,OACPI,EAACC,EACC,CAAAC,SAAA,CAAAC,EAACC,EAAc,CAACC,QAAS,S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D,GAAQC,EAAA9F,EAAKD,OAAMgG,gBAAQ,IAAAF,OAAA,EAAnBA,EAAAG,KAAAF,EAAsBjC,EAAK,EAAEpB,GAAI,CAAExB,MAAO,WAChFX,SAAAC,EAAC0F,EAAa,CAAA,UAIrB9F,EAAAH,EAEQ,SAAA,SAACkG,GACRlG,EAAKmG,SAAS,CAAE9E,SAAU6E,MAC3B/F,EAAAH,EAAA,UAES,WACRA,EAAKmG,SAAS,CAAE9E,SAAU,SAnG1BrB,EAAKsB,MAAQ,CAAED,SAAU,MAAMrB,CACjC,CAAC,OAAAoG,EAAAtG,EAJ0BuG,GAI1BC,EAAAxG,EAAA,IAsGUyG,EAAuC,SAACxG,GACnD,IAAQgD,EAAUyD,IAAVzD,MACA0D,EAAmBC,IAAnBD,eAER,OACElG,EAACT,EAAc6G,EAAA,CACb5F,KAAMgC,EACNgD,SAAU,SAAC9C,GACTwD,EAAexD,EAAE2D,UACnB,GACI7G,GAGV,EAEa8G,EAAmB,SAACC,GAC/B,IAAMC,EAAiD,SAAChH,GAAK,OAAKQ,EAACgG,EAAUI,EAAAA,EAAA,CAAA,EAAKG,GAAY/G,GAAS,EAEvG,OADAgH,EAAYC,YAAc,aACnBD,CACT"}
1
+ {"version":3,"file":"widget.js","sources":["../../src/cart/widget.tsx"],"sourcesContent":["import { Component, Fragment, useCallback } from 'react'\r\nimport { ImageWithFallback } from 'dinocollab-core/components'\r\nimport { Badge, Box, Button, Divider, IconButton, Typography } from '@mui/material'\r\nimport { MfeLink } from 'dinocollab-core/mfe-shared'\r\nimport type { FC } from 'react'\r\nimport RemoveIcon from '@mui/icons-material/Remove'\r\nimport ShoppingCartOutlinedIcon from '@mui/icons-material/ShoppingCartOutlined'\r\nimport ShoppingCartCheckoutIcon from '@mui/icons-material/ShoppingCartCheckout'\r\nimport { ICartItem } from './types'\r\nimport { cartContentClasses, CartContentStyled, MenuStyled } from './styled'\r\nimport { getTotalData } from './helpers'\r\nimport { useCartActions, useCartStore } from './hook'\r\nimport { IAppSiteBaseUrl, IAppSiteProps } from '../types'\r\nimport { DarkIconButton, NoDataPanel } from '../components'\r\n\r\ninterface ICartWidgetBaseProps extends IAppSiteProps {\r\n baseUrl: IAppSiteBaseUrl\r\n /** Optional storage key to differentiate between different cart instances */\r\n storageKey?: string\r\n}\r\n\r\ninterface ICartWidgetProps extends ICartWidgetBaseProps {\r\n data: ICartItem[]\r\n onRemove?: (item: ICartItem) => void\r\n}\r\n\r\ninterface ICartWidgetState {\r\n anchorEl: HTMLElement | null\r\n}\r\n\r\nclass CartWidgetBase extends Component<ICartWidgetProps, ICartWidgetState> {\r\n constructor(props: ICartWidgetProps) {\r\n super(props)\r\n this.state = { anchorEl: null }\r\n }\r\n\r\n render = () => (\r\n <Fragment>\r\n <DarkIconButton onClick={(e) => this.onOpen(e.currentTarget)}>\r\n <Badge badgeContent={this.props.data.length} color='primary'>\r\n <ShoppingCartOutlinedIcon />\r\n </Badge>\r\n </DarkIconButton>\r\n <MenuStyled\r\n disableScrollLock\r\n anchorEl={this.state.anchorEl}\r\n open={Boolean(this.state.anchorEl)}\r\n onClose={this.onClose}\r\n anchorOrigin={{ vertical: 'top', horizontal: 'right' }}\r\n transformOrigin={{ vertical: 'top', horizontal: 'right' }}\r\n MenuListProps={{ component: 'div' }}\r\n >\r\n {this.renderContent()}\r\n </MenuStyled>\r\n </Fragment>\r\n )\r\n\r\n renderContent = () => {\r\n const totalData = getTotalData(this.props.data)\r\n return (\r\n <CartContentStyled>\r\n <div className={cartContentClasses.header}>\r\n <Typography variant='h6' component='span' sx={{ flex: 1 }}>\r\n Your Cart ({totalData.amount} items)\r\n </Typography>\r\n <Typography variant='h6' component='span'>\r\n Total: $ {totalData.price.toFixed(2)}\r\n </Typography>\r\n </div>\r\n <Divider />\r\n <div className={cartContentClasses.items}>\r\n {this.props.data.map((x, i) => (\r\n <Fragment key={'key' + i}>{this.renderItem(x)}</Fragment>\r\n ))}\r\n {this.props.data.length < 1 && <NoDataPanel title='Your cart is empty' subTitle='Try adding some products' sx={{ height: '100%' }} />}\r\n </div>\r\n <Divider />\r\n <div className={cartContentClasses.footer}>\r\n <Button\r\n component={MfeLink}\r\n primaryHref={this.props.baseUrl.client + '/cart'}\r\n secondaryHref='cart'\r\n internal={this.props.site === 'client'}\r\n color='inherit'\r\n endIcon={<ShoppingCartCheckoutIcon />}\r\n onClick={this.onClose}\r\n disabled={this.props.data.length < 1}\r\n >\r\n Show in cart\r\n </Button>\r\n </div>\r\n </CartContentStyled>\r\n )\r\n }\r\n\r\n renderItem = (item: ICartItem) => {\r\n const src = this.props.baseUrl.api + item?.PictureUrl\r\n return (\r\n <div className={cartContentClasses.item}>\r\n <ImageWithFallback\r\n className={cartContentClasses.itemImg}\r\n src={src}\r\n title={src}\r\n fallbackSrc='images/default-video.webp'\r\n alt='product-picture'\r\n />\r\n <div className={cartContentClasses.itemContent}>\r\n <Typography className={cartContentClasses.itemTag} variant='caption' sx={{ color: item.PriceColor ?? '#000' }}>\r\n {item.PriceName ?? 'Unknown Price'}\r\n </Typography>\r\n <Typography className={cartContentClasses.itemTitle} noWrap variant='subtitle1'>\r\n {item.ProductName ?? 'Unknown Product'}\r\n </Typography>\r\n <Box sx={{ display: 'flex', alignItems: 'flex-end', gap: '2px', justifyContent: 'flex-end' }}>\r\n <Typography variant='subtitle1'>$ {item.Price ?? 0}</Typography>\r\n <Typography variant='body1' sx={{ fontSize: '14px', mb: '3px', color: '#818181' }}>\r\n x{item.Amount ?? 0} urls\r\n </Typography>\r\n </Box>\r\n </div>\r\n <IconButton size='small' onClick={() => this.props.onRemove?.(item)} sx={{ color: '#818181' }}>\r\n <RemoveIcon />\r\n </IconButton>\r\n </div>\r\n )\r\n }\r\n\r\n onOpen = (target: HTMLElement) => {\r\n this.setState({ anchorEl: target })\r\n }\r\n\r\n onClose = () => {\r\n this.setState({ anchorEl: null })\r\n }\r\n}\r\n\r\nexport const CartWidget: FC<ICartWidgetBaseProps> = (props) => {\r\n const { items } = useCartStore()\r\n const { removeFromCart } = useCartActions<ICartItem>()\r\n\r\n return (\r\n <CartWidgetBase\r\n data={items}\r\n onRemove={(x) => {\r\n removeFromCart(x.ProductId)\r\n }}\r\n {...props}\r\n />\r\n )\r\n}\r\n\r\nexport const createCartWidget = (params: ICartWidgetBaseProps) => {\r\n const _CartWidget: FC<Partial<ICartWidgetBaseProps>> = (props) => <CartWidget {...params} {...props} />\r\n _CartWidget.displayName = 'CartWidget'\r\n return _CartWidget\r\n}\r\n"],"names":["CartWidgetBase","props","_this","_classCallCheck","_callSuper","_defineProperty","_jsxs","Fragment","children","_jsx","DarkIconButton","onClick","e","onOpen","currentTarget","Badge","badgeContent","data","length","color","ShoppingCartOutlinedIcon","MenuStyled","disableScrollLock","anchorEl","state","open","Boolean","onClose","anchorOrigin","vertical","horizontal","transformOrigin","MenuListProps","component","renderContent","totalData","getTotalData","CartContentStyled","className","cartContentClasses","header","Typography","variant","sx","flex","amount","price","toFixed","Divider","items","map","x","i","renderItem","NoDataPanel","title","subTitle","height","footer","Button","MfeLink","primaryHref","baseUrl","client","secondaryHref","internal","site","endIcon","ShoppingCartCheckoutIcon","disabled","item","_item$PriceColor","_item$PriceName","_item$ProductName","_item$Price","_item$Amount","src","api","PictureUrl","ImageWithFallback","itemImg","fallbackSrc","alt","itemContent","itemTag","PriceColor","PriceName","itemTitle","noWrap","ProductName","Box","display","alignItems","gap","justifyContent","Price","fontSize","mb","Amount","IconButton","size","_this$props$onRemove","_this$props","onRemove","call","RemoveIcon","target","setState","_inherits","Component","_createClass","CartWidget","useCartStore","removeFromCart","useCartActions","_objectSpread","ProductId","createCartWidget","params","_CartWidget","displayName"],"mappings":"+6BAa2D,IAiBrDA,aACJ,SAAAA,EAAYC,GAAuB,IAAAC,EAEF,OAFEC,OAAAH,GACjCE,EAAAE,EAAAJ,KAAAA,GAAMC,IAAMI,EAAAH,EAIL,SAAA,WAAA,OACPI,EAACC,EACC,CAAAC,SAAA,CAAAC,EAACC,EAAc,CAACC,QAAS,SAACC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UAAXmD,EAAK4B,cAAMvB,IAAAA,EAAAA,EAAI,mBAIvBlE,EAAC0F,GAAWC,KAAK,QAAQzF,QAAS,WAAF,IAAA0F,EAAAC,EAAA,eAAAD,GAAQC,EAAApG,EAAKD,OAAMsG,gBAAQ,IAAAF,OAAA,EAAnBA,EAAAG,KAAAF,EAAsBhC,EAAK,EAAE3B,GAAI,CAAExB,MAAO,WAChFX,SAAAC,EAACgG,EAAa,CAAA,UAIrBpG,EAAAH,EAEQ,SAAA,SAACwG,GACRxG,EAAKyG,SAAS,CAAEpF,SAAUmF,MAC3BrG,EAAAH,EAAA,UAES,WACRA,EAAKyG,SAAS,CAAEpF,SAAU,SAnG1BrB,EAAKsB,MAAQ,CAAED,SAAU,MAAMrB,CACjC,CAAC,OAAA0G,EAAA5G,EAJ0B6G,GAI1BC,EAAA9G,EAAA,IAsGU+G,EAAuC,SAAC9G,GACnD,IAAQgD,EAAU+D,IAAV/D,MACAgE,EAAmBC,IAAnBD,eAER,OACExG,EAACT,EAAcmH,EAAA,CACblG,KAAMgC,EACNsD,SAAU,SAACpD,GACT8D,EAAe9D,EAAEiE,UACnB,GACInH,GAGV,EAEaoH,EAAmB,SAACC,GAC/B,IAAMC,EAAiD,SAACtH,GAAK,OAAKQ,EAACsG,EAAUI,EAAAA,EAAA,CAAA,EAAKG,GAAYrH,GAAS,EAEvG,OADAsH,EAAYC,YAAc,aACnBD,CACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dinocollab-shared",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "DinoCollab shared utilities and components",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",