Skip to content

Commit

Permalink
Merge branch 'fer/1832' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandolucchesi committed Jan 19, 2024
2 parents 9fd99b0 + e7ae6ef commit 7abb196
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions sanityv3/schemas/objects/table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { defaultColors } from '../../components/ColorSelector'
import CompactBlockEditor from '../../components/CompactBlockEditor'
import { configureBlockContent, configureTitleBlockContent } from '../../editors'

import { PortableTextBlock, Rule } from 'sanity'
import { PortableTextBlock, Rule, ValidationContext } from 'sanity'
import type { ColorSelectorValue } from '../../components/ColorSelector'
import { EdsIcon } from '../../../icons'
import { table_chart } from '@equinor/eds-icons'
import { ColorType } from '../colorList'

export type Table = {
_type: 'table'
Expand All @@ -18,11 +19,6 @@ export type Table = {

const titleContentType = configureTitleBlockContent()

type ColorType = {
title: string
value: string
}

const themes: ColorType[] = [
{
title: 'Grey',
Expand Down Expand Up @@ -218,6 +214,19 @@ export default {
colors: backgroundColors,
},
fieldset: 'design',
validation: (Rule: Rule) =>
Rule.custom((value: ColorType, ctx: ValidationContext) => {
const tableTheme = (ctx.parent as Table).theme?.title
const invalidCombinations: Record<string, string> = {
'Mist Blue': 'Blue',
'Mid Green': 'Green',
'Moss Green Light': 'Green',
}
if (invalidCombinations[value.title] === tableTheme) {
return `${value.title} background cannot be used with ${tableTheme} table theme`
}
return true
}),
},
],
preview: {
Expand Down

0 comments on commit 7abb196

Please sign in to comment.