Skip to content

Commit 361507b

Browse files
committed
feat: hide if set (hide background color from container if background image is set)
1 parent 0ead465 commit 361507b

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/lib/assets/Container.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ const defaultContainer: DndContainerItem = {
9393
{ id: 'style.backgroundImage', type: 'image', grid: 12 },
9494
{ id: 'style.padding', type: 'imagePadding', grid: 12 },
9595
{ id: 'style.textAlign', type: 'align', grid: 12 },
96-
{ id: 'style.backgroundColor', type: 'backgroundColor', grid: 12 }
96+
{
97+
id: 'style.backgroundColor',
98+
type: 'backgroundColor',
99+
grid: 12,
100+
hideIfSet: 'style.backgroundImage'
101+
}
97102
],
98103
label: <Trans>Container</Trans>,
99104
type: 'container'

src/lib/components/preferences/items/Field.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,20 @@ interface Props {
6767
name: string
6868
type?: SettingComponentType
6969
Component?: React.ComponentType<any>
70+
hideIfSet?: string
7071
[key: string]: any
7172
}
7273

73-
const Field: React.FC<Props> = ({ name, type, Component: _Component, ...props }) => {
74+
const Field: React.FC<Props> = ({ name, type, Component: _Component, hideIfSet, ...props }) => {
7475
const Component = _Component || (type && fields[type])
7576
const formik = useFormikContext()
7677
let formikProps: any = {}
7778
if (formik) {
7879
formikProps.value = get(formik.values, name)
7980
formikProps.onChange = (value: Primitive) => formik.setFieldValue(name, value, true)
81+
if (hideIfSet && Boolean(get(formik.values, hideIfSet))) {
82+
return null
83+
}
8084
}
8185
if (Component) {
8286
return <Component {...props} {...formikProps} />

src/lib/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ export type DndComponentSetting = {
8585
grid?: GridSize
8686
id: string
8787
label?: React.ReactElement
88+
//hideIfSet hides the settings if other setting is set. Container uses this field
89+
hideIfSet?: string
8890
}
8991

9092
export type DndItemSetting = {

0 commit comments

Comments
 (0)