Skip to content

Commit

Permalink
✨ Alignment #2014
Browse files Browse the repository at this point in the history
  • Loading branch information
padms committed Feb 16, 2024
1 parent 2562bac commit f60e815
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 72 deletions.
65 changes: 65 additions & 0 deletions sanityv3/icons/customIcons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,71 @@ export const LeftAlignedImage = (): JSX.Element => (
</svg>
)

export const ContentCenterImage = (): JSX.Element => (
<svg
xmlns="http://www.w3.org/2000/svg"
class="icon icon-tabler icon-tabler-align-box-center-middle-filled"
width="48"
height="48"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path
d="M19 2a3 3 0 0 1 2.995 2.824l.005 .176v14a3 3 0 0 1 -2.824 2.995l-.176 .005h-14a3 3 0 0 1 -2.993 -2.802l-.007 -.198v-14a3 3 0 0 1 2.824 -2.995l.176 -.005h14zm-6 12h-2l-.117 .007a1 1 0 0 0 0 1.986l.117 .007h2l.117 -.007a1 1 0 0 0 0 -1.986l-.117 -.007zm2 -3h-6l-.117 .007a1 1 0 0 0 0 1.986l.117 .007h6l.117 -.007a1 1 0 0 0 0 -1.986l-.117 -.007zm-1 -3h-4l-.117 .007a1 1 0 0 0 0 1.986l.117 .007h4l.117 -.007a1 1 0 0 0 0 -1.986l-.117 -.007z"
stroke-width="0"
fill="currentColor"
/>
</svg>
)
export const ContentLeftImage = (): JSX.Element => (
<svg
xmlns="http://www.w3.org/2000/svg"
class="icon icon-tabler icon-tabler-align-box-left-middle-filled"
width="48"
height="48"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path
d="M18.333 2c1.96 0 3.56 1.537 3.662 3.472l.005 .195v12.666c0 1.96 -1.537 3.56 -3.472 3.662l-.195 .005h-12.666a3.667 3.667 0 0 1 -3.662 -3.472l-.005 -.195v-12.666c0 -1.96 1.537 -3.56 3.472 -3.662l.195 -.005h12.666zm-10.333 12h-2l-.117 .007a1 1 0 0 0 .117 1.993h2l.117 -.007a1 1 0 0 0 -.117 -1.993zm4 -3h-6l-.117 .007a1 1 0 0 0 .117 1.993h6l.117 -.007a1 1 0 0 0 -.117 -1.993zm-2 -3h-4l-.117 .007a1 1 0 0 0 .117 1.993h4l.117 -.007a1 1 0 0 0 -.117 -1.993z"
stroke-width="0"
fill="currentColor"
/>
</svg>
)

export const ContentRightImage = (): JSX.Element => (
<svg
xmlns="http://www.w3.org/2000/svg"
class="icon icon-tabler icon-tabler-align-box-right-middle-filled"
width="48"
height="48"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path
d="M18.333 2c1.96 0 3.56 1.537 3.662 3.472l.005 .195v12.666c0 1.96 -1.537 3.56 -3.472 3.662l-.195 .005h-12.666a3.667 3.667 0 0 1 -3.662 -3.472l-.005 -.195v-12.666c0 -1.96 1.537 -3.56 3.472 -3.662l.195 -.005h12.666zm-.333 12h-2l-.117 .007a1 1 0 0 0 0 1.986l.117 .007h2l.117 -.007a1 1 0 0 0 0 -1.986l-.117 -.007zm0 -3h-6l-.117 .007a1 1 0 0 0 0 1.986l.117 .007h6l.117 -.007a1 1 0 0 0 0 -1.986l-.117 -.007zm0 -3h-4l-.117 .007a1 1 0 0 0 0 1.986l.117 .007h4l.117 -.007a1 1 0 0 0 0 -1.986l-.117 -.007z"
stroke-width="0"
fill="currentColor"
/>
</svg>
)

export const RightAlignedImage = (): JSX.Element => (
<svg
width="48"
Expand Down
2 changes: 2 additions & 0 deletions sanityv3/schemas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import themeList from './objects/themeList'
import keyNumbers from './objects/keyNumbers'
import keyNumberItem from './objects/keyNumberItem'
import background from './objects/background/background'
import imageBackground from './objects/background/imageBackground'

const routeSchemas = languages.map(({ name, title }) => {
return route(name, title)
Expand Down Expand Up @@ -174,6 +175,7 @@ const RemainingSchemas = [
keyNumbers,
keyNumberItem,
background,
imageBackground,
]

// Then we give our schema to the builder and provide the result to Sanity
Expand Down
40 changes: 20 additions & 20 deletions sanityv3/schemas/objects/background/background.tsx
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,
}),
],
})
76 changes: 76 additions & 0 deletions sanityv3/schemas/objects/background/imageBackground.tsx
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,
}
},
},
})
11 changes: 7 additions & 4 deletions sanityv3/schemas/objects/textBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default {
name: 'textBlock',
title: 'Text block',
type: 'object',

fieldsets: [
{
title: 'Thumbnail Image',
Expand Down Expand Up @@ -207,6 +208,7 @@ export default {
return !(parent.action && parent?.action.length === 1)
},
},

{
title: 'Background',
description:
Expand All @@ -216,10 +218,11 @@ export default {
fieldset: 'design',
},
{
title: 'Background Image',
description: 'Pick a background image instead of color.',
name: 'imageBackground',
type: 'imageBackground',
title: 'More background options',
description:
'Pick a colour for the background. Default is white. If background image is not provided this color is used',
name: 'backgroundOption',
type: 'backgroundOption',
fieldset: 'design',
},
].filter((e) => e),
Expand Down
8 changes: 4 additions & 4 deletions web/components/src/Backgrounds/BackgroundContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { forwardRef, HTMLAttributes } from 'react'
import type { BackgroundColours, ImageBackground } from '../../../types/types'
import type { BackgroundColours, ImageBackground, BackgroundOption } from '../../../types/types'
import { ColouredContainer } from './ColouredContainer'
import { ImageBackgroundContainer } from './ImageBackgroundContainer'

export type BackgroundContainerProps = {
background?: {
backgroundColor?: BackgroundColours
imageBackground?: ImageBackground
backgroundOption?: BackgroundOption
}
} & HTMLAttributes<HTMLDivElement>

Expand All @@ -15,11 +15,11 @@ export const BackgroundContainer = forwardRef<HTMLDivElement, BackgroundContaine
ref,
) {
const Container = ({ children }: { children: React.ReactNode }) => {
return background?.imageBackground ? (
return background?.backgroundOption?.useSpecialBackground ? (
<ImageBackgroundContainer
ref={ref}
{...rest}
imageBackground={background?.imageBackground}
imageBackground={background?.backgroundOption?.background}
style={style}
className={className}
>
Expand Down
1 change: 1 addition & 0 deletions web/components/src/Backgrounds/ColouredContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type ColourContainerProps = {
} & HTMLAttributes<HTMLDivElement>

const ColourContainer = styled.div<ColourContainerProps>`
container: size;
background-color: var(--background-color);
color: var(--color-on-background);
${({ isInverted }) => (isInverted ? inverted : normal)}
Expand Down
Loading

0 comments on commit f60e815

Please sign in to comment.