Skip to content

Commit

Permalink
feat: apply custom primaryColor
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlLiu2023 committed Apr 12, 2023
1 parent cde113a commit c96f0e2
Show file tree
Hide file tree
Showing 29 changed files with 358 additions and 89 deletions.
5 changes: 5 additions & 0 deletions apps/storefront/src/components/B3ProductList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ interface ProductProps <T> {
totalText?: string,
canToProduct?: boolean,
textAlign?: string,
customColor?: string,
}

export const B3ProductList: <T>(props: ProductProps<T>) => ReactElement = (props) => {
Expand All @@ -158,6 +159,7 @@ export const B3ProductList: <T>(props: ProductProps<T>) => ReactElement = (props
totalText = 'Total',
canToProduct = false,
textAlign = 'left',
customColor = '',
} = props

const [list, setList] = useState<ProductItem[]>([])
Expand Down Expand Up @@ -379,6 +381,9 @@ export const B3ProductList: <T>(props: ProductProps<T>) => ReactElement = (props
marginLeft: '0',
marginRight: '0',
},
'& .MuiFilledInput-root:after': {
borderBottom: `2px solid ${customColor || '#1976d2'}`,
},
}}
error={!!product.helperText}
helperText={product.helperText}
Expand Down
16 changes: 3 additions & 13 deletions apps/storefront/src/components/button/CustomButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,16 @@ const CustomButton = ({
const {
state: {
globalButtonBackgroundColor,
portalStyle,
portalStyle: {
primaryColor = '',
},
},
} = useContext(CustomStyleContext)

const {
variant,
} = rest

const {
primaryColor = '',
} = portalStyle

return (
<>
{
Expand All @@ -55,10 +53,6 @@ const CustomButton = ({
...sx || {},
backgroundColor: primaryColor || globalButtonBackgroundColor,
color: getContrastColor(primaryColor) || getContrastColor(globalButtonBackgroundColor),
'&:hover': {
backgroundColor: primaryColor || globalButtonBackgroundColor,
color: getContrastColor(primaryColor) || getContrastColor(globalButtonBackgroundColor),
},
}}
onClick={onClick}
>
Expand All @@ -71,10 +65,6 @@ const CustomButton = ({
...sx || {},
color: primaryColor || globalButtonBackgroundColor,
borderColor: primaryColor,
'&:hover': {
color: primaryColor || globalButtonBackgroundColor,
borderColor: primaryColor,
},
}}
onClick={onClick}
>
Expand Down
30 changes: 29 additions & 1 deletion apps/storefront/src/components/form/B3ControlCheckbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@ import {
import {
useB3Lang,
} from '@b3/lang'

import {
useContext,
} from 'react'

import Form from './ui'

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

interface CheckboxListProps {
value: string,
label: string,
Expand All @@ -36,6 +45,14 @@ export const B3ControlCheckbox = ({
options,
} = rest

const {
state: {
portalStyle: {
primaryColor = '',
},
},
} = useContext(CustomStyleContext)

const b3Lang = useB3Lang()

const fieldsProps = {
Expand Down Expand Up @@ -67,7 +84,13 @@ export const B3ControlCheckbox = ({
<>
{
['checkbox'].includes(fieldType) && (
<FormControl>
<FormControl
sx={{
'& .MuiFormLabel-root.Mui-focused': {
color: primaryColor,
},
}}
>
{
label && (
<FormLabel
Expand Down Expand Up @@ -95,6 +118,11 @@ export const B3ControlCheckbox = ({
)}
key={list.value}
label={list.label}
sx={{
'& .MuiCheckbox-root.Mui-checked': {
color: primaryColor,
},
}}
/>
))}
/>
Expand Down
29 changes: 28 additions & 1 deletion apps/storefront/src/components/form/B3ControlRadioGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ import {
useB3Lang,
} from '@b3/lang'

import {
useContext,
} from 'react'

import Form from './ui'

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

export const B3ControlRadioGroup = ({
control,
errors,
Expand All @@ -30,6 +38,14 @@ export const B3ControlRadioGroup = ({
options,
} = rest

const {
state: {
portalStyle: {
primaryColor = '',
},
},
} = useContext(CustomStyleContext)

const b3Lang = useB3Lang()

const fieldsProps = {
Expand All @@ -50,7 +66,13 @@ export const B3ControlRadioGroup = ({
<>
{
['radio'].includes(fieldType) && (
<FormControl>
<FormControl
sx={{
'& .MuiFormLabel-root.Mui-focused': {
color: primaryColor,
},
}}
>
{
label && (
<FormLabel
Expand Down Expand Up @@ -79,6 +101,11 @@ export const B3ControlRadioGroup = ({
control={(
<Radio />
)}
sx={{
'& .MuiRadio-root.Mui-checked': {
color: primaryColor,
},
}}
/>
))
)
Expand Down
31 changes: 28 additions & 3 deletions apps/storefront/src/components/form/B3ControlRectangle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ import {
useB3Lang,
} from '@b3/lang'

import {
useContext,
} from 'react'

import Form from './ui'

import {
StyleRectangleFormControlLabel,
} from './styled'

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

export const B3ControlRectangle = ({
control,
errors,
Expand All @@ -36,6 +44,14 @@ export const B3ControlRectangle = ({
labelStyle = {},
} = rest

const {
state: {
portalStyle: {
primaryColor: customColor = '',
},
},
} = useContext(CustomStyleContext)

const b3Lang = useB3Lang()
const theme = useTheme()

Expand All @@ -59,7 +75,13 @@ export const B3ControlRectangle = ({
<>
{
['rectangle'].includes(fieldType) && (
<FormControl>
<FormControl
sx={{
'& .MuiFormLabel-root.Mui-focused': {
color: customColor,
},
}}
>
{
label && (
<FormLabel
Expand Down Expand Up @@ -93,9 +115,12 @@ export const B3ControlRectangle = ({
label={option.label}
key={option.value}
sx={{
border: isActive ? `1px solid ${primaryColor}` : '1px solid #767676',
boxShadow: isActive ? `0 0 0 1px ${primaryColor}` : 'none',
border: isActive ? `1px solid ${customColor || primaryColor}` : '1px solid #767676',
boxShadow: isActive ? `0 0 0 1px ${customColor || primaryColor}` : 'none',
...labelStyle,
'& .MuiRadio-root.Mui-checked': {
color: customColor || primaryColor,
},
}}
control={(
<Radio />
Expand Down
22 changes: 21 additions & 1 deletion apps/storefront/src/components/form/B3ControlSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
ChangeEvent,
ChangeEvent, useContext,
} from 'react'

import {
Expand All @@ -18,6 +18,10 @@ import {

import Form from './ui'

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

export const B3ControlSelect = ({
control,
errors,
Expand All @@ -38,6 +42,14 @@ export const B3ControlSelect = ({
size = 'small',
} = rest

const {
state: {
portalStyle: {
primaryColor = '',
},
},
} = useContext(CustomStyleContext)

const b3Lang = useB3Lang()

const muiAttributeProps = muiSelectProps || {}
Expand Down Expand Up @@ -75,6 +87,14 @@ export const B3ControlSelect = ({
width: '100%',
color: muiSelectProps?.disabled ? 'rgba(0, 0, 0, 0.38)' : 'rgba(0, 0, 0, 0.6)',
}}
sx={{
'& .MuiInputLabel-root.Mui-focused': {
color: primaryColor,
},
'& .MuiFilledInput-root:after': {
borderBottom: `2px solid ${primaryColor || '#1976d2'}`,
},
}}
>
{
label && (
Expand Down
24 changes: 24 additions & 0 deletions apps/storefront/src/components/form/B3ControlTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ import {
import {
KeyboardEvent,
WheelEvent,
useContext,
} from 'react'
import Form from './ui'
import {
StyleNumberTextField,
} from './styled'
import {
CustomStyleContext,
} from '@/shared/customStyleButtton'

export const B3ControlTextField = ({
control,
Expand Down Expand Up @@ -44,6 +48,14 @@ export const B3ControlTextField = ({
allowArrow = false,
} = rest

const {
state: {
portalStyle: {
primaryColor = '',
},
},
} = useContext(CustomStyleContext)

const b3Lang = useB3Lang()

let requiredText = ''
Expand Down Expand Up @@ -142,6 +154,12 @@ export const B3ControlTextField = ({
{...rest}
sx={{
color: disabled ? 'rgba(0, 0, 0, 0.38)' : 'rgba(0, 0, 0, 0.6)',
'& label.Mui-focused': {
color: primaryColor,
},
'& .MuiFilledInput-root:after': {
borderBottom: `2px solid ${primaryColor || '#1976d2'}`,
},
}}
allowarrow={allowArrow ? 1 : 0}
inputProps={muiAttributeProps}
Expand All @@ -157,6 +175,12 @@ export const B3ControlTextField = ({
{...rest}
sx={{
color: disabled ? 'rgba(0, 0, 0, 0.38)' : 'rgba(0, 0, 0, 0.6)',
'& label.Mui-focused': {
color: primaryColor,
},
'& .MuiFilledInput-root:after': {
borderBottom: `2px solid ${primaryColor || '#1976d2'}`,
},
}}
inputProps={muiAttributeProps}
error={!!errors[name]}
Expand Down
8 changes: 3 additions & 5 deletions apps/storefront/src/components/layout/B3Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ export const B3Nav = ({

const {
state: {
portalStyle,
portalStyle: {
primaryColor = '',
},
},
} = useContext(CustomStyleContext)

const {
primaryColor = '',
} = portalStyle

const jumpRegister = () => {
navigate('/registered')
dispatch({
Expand Down
Loading

0 comments on commit c96f0e2

Please sign in to comment.