Skip to content

Commit

Permalink
feat: apply custom styles
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlLiu2023 committed Apr 6, 2023
1 parent be36efa commit 18d7a52
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 236 deletions.
26 changes: 17 additions & 9 deletions apps/storefront/src/components/button/CustomButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import {

import {
useContext,
MouseEvent,
} from 'react'

import {
CustomStyleContext,
} from '@/shared/customStyleButtton'

interface CustomButtonProps extends ButtonProps {
onClick?: () => void;
sx?: any;
customLabel?: string;
children: React.ReactNode
onClick?: (e?: MouseEvent<HTMLButtonElement> | any) => void,
sx?: any,
customLabel?: string,
children: React.ReactNode,
}

const CustomButton = ({
Expand All @@ -27,19 +28,26 @@ const CustomButton = ({
const {
state: {
globalColor,
golbalBackgroundColor,
globalBackgroundColor,
portalStyle,
},
} = useContext(CustomStyleContext)

const {
primaryColor = '',
backgroundColor = '',
} = portalStyle

return (
<Button
{...rest}
sx={{
...sx || {},
color: globalColor,
backgroundColor: golbalBackgroundColor,
color: primaryColor || globalColor,
backgroundColor: backgroundColor || globalBackgroundColor,
'&:hover': {
color: globalColor,
backgroundColor: golbalBackgroundColor,
color: primaryColor || globalColor,
backgroundColor: backgroundColor || globalBackgroundColor,
},
}}
onClick={onClick}
Expand Down
4 changes: 2 additions & 2 deletions apps/storefront/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ export {

export {
B3MasquradeGobalTip,
} from './B3MasquradeGobalTip'
} from './outSideComponents/B3MasquradeGobalTip'

export {
B3HoverButton,
} from './B3HoverButton'
} from './outSideComponents/B3HoverButton'

export {
CheckoutTip,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import {
SetStateAction,
useState,
useEffect,
useContext,
} from 'react'

import {
Box,
Button,
Snackbar,
SnackbarOrigin,
SxProps,
} from '@mui/material'

import type {
Expand All @@ -19,6 +22,15 @@ import {
B3LStorage,
} from '@/utils'

import {
CustomStyleContext,
} from '@/shared/customStyleButtton'

import {
getLocation,
getStyles,
} from './utils/b3CustomStyles'

interface B3HoverButtonProps {
isOpen: boolean,
productQuoteEnabled: boolean,
Expand Down Expand Up @@ -46,6 +58,33 @@ export const B3HoverButton = (props: B3HoverButtonProps) => {
href,
} = window.location

const {
state: {
floatingAction,
},
} = useContext(CustomStyleContext)

const {
text = '',
buttonText = '',
color = '',
customCss = '',
location = '',
horizontalPadding = '',
verticalPadding = '',
enabled = false,
} = floatingAction

const defaultLocation: SnackbarOrigin = {
vertical: 'bottom', horizontal: 'right',
}

const defaultSx: SxProps = {
color: `${color}`,
padding: `${verticalPadding}px ${horizontalPadding}px`,
...getStyles(customCss),
}

if (href.includes('/checkout')) return <></>
return (
<Snackbar
Expand All @@ -55,11 +94,8 @@ export const B3HoverButton = (props: B3HoverButtonProps) => {
bottom: '20px',
left: 'auto',
}}
anchorOrigin={{
vertical: 'bottom', horizontal: 'right',
}}
anchorOrigin={getLocation(location) || defaultLocation}
open
key="123"
>

<Box
Expand All @@ -72,11 +108,12 @@ export const B3HoverButton = (props: B3HoverButtonProps) => {
>

{
showFinishQuote && !isOpen && productQuoteEnabled && !href.includes('/cart') && (
enabled && showFinishQuote && !isOpen && productQuoteEnabled && !href.includes('/cart') && (
<Button
sx={{
backgroundColor: '#ED6C02',
height: '42px',
...defaultSx,
}}
onClick={() => {
setOpenPage({
Expand All @@ -89,7 +126,7 @@ export const B3HoverButton = (props: B3HoverButtonProps) => {
}}
variant="contained"
>
Finish quote
{buttonText || text}
</Button>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
import {
Box,
Button,
SnackbarOrigin,
SxProps,
} from '@mui/material'

import type {
Expand Down Expand Up @@ -36,6 +38,15 @@ import {
GlobaledContext,
} from '@/shared/global'

import {
CustomStyleContext,
} from '@/shared/customStyleButtton'

import {
getLocation,
getStyles,
} from './utils/b3CustomStyles'

interface B3MasquradeGobalTipProps {
isOpen: boolean,
setOpenPage: Dispatch<SetStateAction<OpenPageState>>,
Expand Down Expand Up @@ -64,6 +75,12 @@ export const B3MasquradeGobalTip = (props: B3MasquradeGobalTipProps) => {
href,
} = window.location

const {
state: {
masqueradeButton,
},
} = useContext(CustomStyleContext)

const isAddBottom = bottomHeightPage.some((item: string) => hash.includes(item))

const [isExpansion, setExpansion] = useState<boolean>(true)
Expand Down Expand Up @@ -102,7 +119,20 @@ export const B3MasquradeGobalTip = (props: B3MasquradeGobalTipProps) => {

if (!isAgenting) return <></>

let sx = {}
const {
text = '',
color = '',
customCss = '',
location = '',
horizontalPadding = '',
verticalPadding = '',
} = masqueradeButton

const defaultLocation: SnackbarOrigin = {
vertical: 'bottom', horizontal: 'left',
}

let sx: SxProps = {}

if (isMobile && isOpen) {
sx = {
Expand All @@ -116,6 +146,13 @@ export const B3MasquradeGobalTip = (props: B3MasquradeGobalTipProps) => {
bottom: '90px !important',
}
}

const customStyles: SxProps = {
color: `${color}`,
padding: `${verticalPadding}px ${horizontalPadding}px`,
...getStyles(customCss),
}

return (
<>
{
Expand All @@ -127,18 +164,16 @@ export const B3MasquradeGobalTip = (props: B3MasquradeGobalTipProps) => {
bottom: '20px',
right: 'auto',
}}
anchorOrigin={{
vertical: 'bottom', horizontal: 'left',
}}
anchorOrigin={getLocation(location) || defaultLocation}
open
key="123"
>

<Button
sx={{
backgroundColor: '#ED6C02',
height: '42px',
marginTop: '10px',
...customStyles,
}}
onClick={() => {
setOpenPage({
Expand Down Expand Up @@ -168,16 +203,14 @@ export const B3MasquradeGobalTip = (props: B3MasquradeGobalTipProps) => {
color: '#FFFFFF',
...sx,
}}
anchorOrigin={{
vertical: 'bottom', horizontal: 'left',
}}
anchorOrigin={getLocation(location) || defaultLocation}
open
key="123"
>
<Box
sx={{
padding: '5px 15px',
width: '100%',
...customStyles,
}}
>
{
Expand Down Expand Up @@ -223,7 +256,7 @@ export const B3MasquradeGobalTip = (props: B3MasquradeGobalTipProps) => {
}}
onClick={() => endActing()}
>
END MASQUERADE
{text}
</Box>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
SnackbarOrigin, SxProps,
} from '@mui/material'

import {
trim,
} from 'lodash'

const getLocation = (location: string): SnackbarOrigin => ({
vertical: location.includes('top') ? 'top' : 'bottom',
horizontal: location.includes('Left') ? 'left' : 'right',
})

const getStyles = (customCss: string): SxProps => {
const str = trim(customCss)
const sx = str.replace(/\n/g, '').split(';').reduce((acc: Record<string, string>, style) => {
const [property, value] = style.split(':')
if (property && value) {
acc[property.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())] = value.trim().replace(';', '')
}
return acc
}, {})

return sx
}

export {
getLocation,
getStyles,
}
4 changes: 2 additions & 2 deletions apps/storefront/src/hooks/dom/useCartToQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const useCartToQuote = ({

const {
color = '',
buttonText = '',
text = '',
customCss = '',
classSelector = '',
locationSelector = '',
Expand All @@ -79,7 +79,7 @@ const useCartToQuote = ({
addToQuoteAll.forEach((node: CustomFieldItems) => {
cartQuoteBtnDom = document.createElement('div')
cartQuoteBtnDom.setAttribute('id', `${locationSelector}`)
cartQuoteBtnDom.innerHTML = buttonText || 'Add All to Quote'
cartQuoteBtnDom.innerHTML = text
cartQuoteBtnDom.setAttribute('style', customCss)
cartQuoteBtnDom.style.color = color
cartQuoteBtnDom.setAttribute('class', `b3-cart-to-cart ${classSelector}`)
Expand Down
4 changes: 2 additions & 2 deletions apps/storefront/src/hooks/dom/useMyQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const useMyQuote = ({

const {
color = '',
buttonText = '',
text = '',
customCss = '',
classSelector = '',
locationSelector = '',
Expand All @@ -114,7 +114,7 @@ const useMyQuote = ({
myQuote = document.createElement('div')

myQuote.setAttribute('id', `${locationSelector}`)
myQuote.innerHTML = buttonText || 'Add to Quote'
myQuote.innerHTML = text
myQuote.setAttribute('style', customCss)
myQuote.style.color = color
myQuote.setAttribute('class', `b3-product-to-quote ${classSelector}`)
Expand Down
4 changes: 2 additions & 2 deletions apps/storefront/src/hooks/dom/useOpenPDP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const useOpenPDP = ({
if (document.querySelectorAll('.b2b-shopping-list-btn').length) return
const {
color = '',
buttonText = '',
text = '',
customCss = '',
classSelector = '',
locationSelector = '',
Expand All @@ -65,7 +65,7 @@ const useOpenPDP = ({
addToCartAll.forEach((node: CustomFieldItems) => {
shoppingBtnDom = document.createElement('div')
shoppingBtnDom.setAttribute('id', `${locationSelector}`)
shoppingBtnDom.innerHTML = buttonText || 'Add to Shopping List'
shoppingBtnDom.innerHTML = text
shoppingBtnDom.setAttribute('style', customCss)
shoppingBtnDom.style.color = color
shoppingBtnDom.setAttribute('class', `b2b-shopping-list-btn ${classSelector}`)
Expand Down
5 changes: 0 additions & 5 deletions apps/storefront/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import {
useCartToQuote,
} from './dom/useCartToQuote'

import {
useQuoteGlobalTip,
} from './useQuoteGlobalTip'

import {
useRegisteredbctob2b,
} from './useRegisteredbctob2b'
Expand Down Expand Up @@ -48,7 +44,6 @@ export {
useMyQuote,
useRegisteredbctob2b,
useCardListColumn,
useQuoteGlobalTip,
useSetCountry,
useGetCountry,
useCartToQuote,
Expand Down
Loading

0 comments on commit 18d7a52

Please sign in to comment.