-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
272 additions
and
72 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
import { defineType, defineField } from 'sanity' | ||
|
||
export type ColorType = { | ||
title: string | ||
value: string | ||
} | ||
|
||
export default defineType({ | ||
name: 'imageBackground', | ||
title: 'Image background', | ||
type: 'object', | ||
name: 'backgroundOption', | ||
|
||
fields: [ | ||
defineField({ | ||
title: 'Background Image', | ||
name: 'image', | ||
type: 'imageWithAlt', | ||
description: 'Alt text is always ignored even if provided, considering background image as decorative.', | ||
}), | ||
defineField({ | ||
title: 'Animation', | ||
name: 'useAnimation', | ||
title: 'Use special background', | ||
name: 'useSpecialBackground', | ||
type: 'boolean', | ||
description: 'Animates content over the background image.', | ||
}), | ||
defineField({ | ||
title: 'Switch to dark theme.', | ||
description: 'Switch to dark theme if the background image is dark.', | ||
name: 'useDarkTheme', | ||
type: 'boolean', | ||
type: 'array', | ||
name: 'background', | ||
description: 'Select what type of background you want to apply', | ||
title: 'Type of background', | ||
of: [{ type: 'imageBackground', title: 'Image Background' }].filter((e) => e), | ||
options: { sortable: false }, | ||
validation: (Rule) => [ | ||
(Rule: Rule) => Rule.required().min(1).max(1), | ||
Rule.required().custom((background, context) => { | ||
if (context.parent.useSpecialBackground) { | ||
return background[0]._type === 'imageBackground' && background[0]?.image?.asset ? true : 'Image required' | ||
} | ||
return true | ||
}), | ||
], | ||
hidden: ({ parent }: any) => !parent?.useSpecialBackground, | ||
}), | ||
], | ||
}) |
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,76 @@ | ||
import { defineType, defineField } from 'sanity' | ||
import { RadioIconSelector } from '../../components' | ||
import { ContentRightImage, ContentLeftImage, ContentCenterImage } from '../../../icons' | ||
|
||
export type ColorType = { | ||
title: string | ||
value: string | ||
} | ||
|
||
const contentAlignmentOptions = [ | ||
{ value: 'left', icon: ContentLeftImage }, | ||
{ value: 'center', icon: ContentCenterImage }, | ||
{ value: 'right', icon: ContentRightImage }, | ||
] | ||
|
||
export default defineType({ | ||
name: 'imageBackground', | ||
title: 'Image background', | ||
type: 'object', | ||
fields: [ | ||
defineField({ | ||
title: 'Background Image', | ||
name: 'image', | ||
type: 'imageWithAlt', | ||
description: 'Alt text is always ignored even if provided, considering background image as decorative.', | ||
}), | ||
defineField({ | ||
title: 'Animation', | ||
name: 'useAnimation', | ||
type: 'boolean', | ||
description: 'Animates content over the background image.', | ||
}), | ||
defineField({ | ||
name: 'contentAlignment', | ||
title: 'Content Alignment', | ||
description: 'Select the content alignment on larger screens.', | ||
type: 'string', | ||
components: { | ||
input: function ({ onChange, value }: { onChange: any; value: string }) { | ||
return ( | ||
<RadioIconSelector | ||
name="imageAlignmentSelector" | ||
options={contentAlignmentOptions} | ||
defaultValue="left" | ||
currentValue={value} | ||
onChange={onChange} | ||
/> | ||
) | ||
}, | ||
}, | ||
}), | ||
], | ||
|
||
preview: { | ||
select: { | ||
image: 'image', | ||
useAnimation: 'useAnimation', | ||
contentAlignment: 'contentAlignment', | ||
}, | ||
prepare({ | ||
image, | ||
useAnimation, | ||
contentAlignment, | ||
}: { | ||
image: Reference | ||
useAnimation: boolean | ||
contentAlignment: string | ||
}) { | ||
return { | ||
title: `Image background`, | ||
subtitle: `${contentAlignment.toUpperCase() + ' aligned'} ${useAnimation ? ' | Animated ' : ''} content`, | ||
media: image, | ||
} | ||
}, | ||
}, | ||
}) |
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
Oops, something went wrong.