Skip to content

Commit

Permalink
Merge branch 'main' into padms/2010
Browse files Browse the repository at this point in the history
  • Loading branch information
padms committed Jan 25, 2024
2 parents f8efe68 + dd390f7 commit 24dae91
Show file tree
Hide file tree
Showing 35 changed files with 868 additions and 244 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/DEV-studio-v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- './FeatureFlags.js'
- '!./README.md'
- '!./.env.development.template'
- '!./sanityv3/scripts/**/*'
permissions:
id-token: write
packages: write
Expand Down Expand Up @@ -37,11 +38,10 @@ jobs:
run: |
pnpm install
pnpm sanityv3 install
# @TODO: Enable ESlint for v3
# - name: Run ESLint 🔎
# id: lint
# run: |
# pnpm lint:studio
- name: Run ESLint 🔎
id: lint
run: |
pnpm lint:sanityv3
- uses: act10ns/slack@v1
with:
status: ${{ job.status }}
Expand Down Expand Up @@ -133,4 +133,4 @@ jobs:
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
if: failure()
if: failure()
1 change: 1 addition & 0 deletions .github/workflows/PREPROD-studios-v3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- './FeatureFlags.js'
- '!./README.md'
- '!./.env.development.template'
- '!./sanityv3/scripts/**/*'
permissions:
id-token: write
packages: write
Expand Down
1 change: 1 addition & 0 deletions sanityv3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@types/react-dom": "^18.0.5",
"@types/styled-components": "^5.1.26",
"eslint": "^8.6.0",
"nanoid": "^5.0.4",
"prettier": "^2.8.3",
"typescript": "^4.0.0"
}
Expand Down
10 changes: 10 additions & 0 deletions sanityv3/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 12 additions & 13 deletions sanityv3/schemas/documents/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { HeroTypes } from '../HeroTypes'
import sharedHeroFields from './header/sharedHeaderFields'
import { EdsIcon } from '../../icons'
import { paste } from '@equinor/eds-icons'
// import { done } from '@equinor/eds-icons'

// export default ({ topicPrefix, title }: { topicPrefix: Topics; title: string }) => {
export default {
type: 'document',
name: 'page',
Expand Down Expand Up @@ -52,27 +50,28 @@ export default {
of: [
{ type: 'textBlock' },
{ type: 'teaser' },
{ type: 'textTeaser' },
{ type: 'fullWidthImage' },
{ type: 'fullWidthVideo' },
{ type: 'figure' },
{ type: 'textWithIconArray' },
{ type: 'fullWidthImage' },
{ type: 'pullQuote', initialValue: { background: defaultColors[0] } },
{ type: 'accordion' },
{ type: 'promoTileArray' },
{ type: 'promotion' },
{ type: 'table' },
{ type: 'stockValuesApi' },
{ type: 'iframe' },
{ type: 'cookieDeclaration' },
Flags.HAS_FORMS && { type: 'form' },
Flags.HAS_NEWS && { type: 'newsList' },
Flags.HAS_TWITTER_FEED && { type: 'twitterEmbed' },
{ type: 'fullWidthVideo' },
{ type: 'textWithIconArray' },
{ type: 'keyNumbers' },
{ type: 'textTeaser' },
{ type: 'promotion' },
{ type: 'anchorLink' },
{ type: 'imageCarousel' },
{ type: 'iframeCarousel' },
{ type: 'videoPlayer' },
{ type: 'videoPlayerCarousel' },
{ type: 'table' },
Flags.HAS_FORMS && { type: 'form' },
Flags.HAS_NEWS && { type: 'newsList' },
{ type: 'stockValuesApi' },
Flags.HAS_TWITTER_FEED && { type: 'twitterEmbed' },
{ type: 'cookieDeclaration' },
].filter((e) => e),
},
].filter((e) => e),
Expand Down
18 changes: 17 additions & 1 deletion sanityv3/schemas/editors/blockContentType.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { attach_file, external_link, link } from '@equinor/eds-icons'
import { attach_file, external_link, format_color_text, link } from '@equinor/eds-icons'
import type { BlockDefinition, Rule, ValidationContext } from 'sanity'
import { filterByPages, filterByPagesInOtherLanguages } from '../../helpers/referenceFilters'
import { EdsBlockEditorIcon, EdsIcon, IconSubScript, IconSuperScript } from '../../icons'
Expand All @@ -16,12 +16,23 @@ export type BlockContentProps = {
attachment?: boolean
lists?: boolean
smallText?: boolean
highlight?: boolean
normalTextOverride?: {
title: string
value: 'normal'
component?: ({ children }: { children: React.ReactNode }) => JSX.Element
}
}

export const textColorConfig = {
title: 'Highlight',
value: 'highlight',
icon: EdsBlockEditorIcon(format_color_text),
component: ({ children }: { children: React.ReactNode }) => {
return <span style={{ color: 'hsl(348, 100%, 54%)' }}>{children}</span>
},
}

const SmallTextRender = (props: any) => {
const { children } = props
return <span style={{ fontSize: '0.8rem' }}>{children}</span>
Expand All @@ -38,6 +49,7 @@ export const configureBlockContent = (options: BlockContentProps = {}): BlockDef
attachment = false,
lists = true,
smallText = true,
highlight = false,
normalTextOverride = { title: 'Normal', value: 'normal' },
} = options

Expand Down Expand Up @@ -238,6 +250,10 @@ export const configureBlockContent = (options: BlockContentProps = {}): BlockDef
config?.marks?.annotations?.push(attachmentConfig)
}

if (highlight) {
config.marks?.decorators?.push(textColorConfig)
}

return config
}

Expand Down
1 change: 0 additions & 1 deletion sanityv3/schemas/editors/titleEditorContentType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { IconSuperScript, IconSubScript, EdsBlockEditorIcon } from '../../icons'
import { StrikethroughIcon } from '@sanity/icons'
import { BlockDefinition, BlockStyleDefinition } from 'sanity'
import { format_color_text } from '@equinor/eds-icons'
import React from 'react'

export type TitleContentProps = {
styles?: BlockStyleDefinition[]
Expand Down
2 changes: 2 additions & 0 deletions sanityv3/schemas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import simpleMenuGroup from './objects/simpleMenuGroup'
import simpleMenuLink from './objects/simpleMenuLink'
import stockValuesApi from './objects/stockValuesApi'
import table from './objects/table'
import tableRichText from './objects/table/tableRichText'
import teaser from './objects/teaser'
import textTeaser from './objects/textTeaser'
import textBlock from './objects/textBlock'
Expand Down Expand Up @@ -145,6 +146,7 @@ const RemainingSchemas = [
promotePeople,
contactList,
table,
tableRichText,
assetFile,
assetTag,
cookieDeclaration,
Expand Down
5 changes: 5 additions & 0 deletions sanityv3/schemas/objects/colorList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { ColorSelector, defaultColors } from '../components/ColorSelector'
import { defineType, defineField } from 'sanity'

export type ColorType = {
title: string
value: string
}

export default defineType({
name: 'colorlist',
title: 'Color',
Expand Down
14 changes: 14 additions & 0 deletions sanityv3/schemas/objects/fullWidthImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ export default {
type: 'imageWithAltAndCaption',
validation: (Rule: Rule) => Rule.required(),
},
{
name: 'aspectRatio',
type: 'number',
title: 'Aspect ratio',
options: {
list: [
{ title: '10:3', value: 0.3 },
{ title: '2:1', value: 0.5 },
],
layout: 'dropdown',
},
initialValue: 0.3,
validation: (Rule: Rule) => Rule.required(),
},
],
preview: {
select: {
Expand Down
2 changes: 1 addition & 1 deletion sanityv3/schemas/objects/promotion/promoteTopic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default {
description: 'A short and catchy introduction text for this topic content card (max. 215 chars)',
type: 'array',
of: [introBlockContentType],
validation: (Rule: Rule) => Rule.custom((value: any) => validateCharCounterEditor(value, 215)),
validation: (Rule: Rule) => Rule.custom((value: any) => validateCharCounterEditor(value, 215, true)),
},
],
preview: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
import blocksToText from '../../helpers/blocksToText'
import { defaultColors } from '../components/ColorSelector'
import CompactBlockEditor from '../components/CompactBlockEditor'
import { configureBlockContent, configureTitleBlockContent } from '../editors'
import blocksToText from '../../../helpers/blocksToText'
import { defaultColors } from '../../components/ColorSelector'
import CompactBlockEditor from '../../components/CompactBlockEditor'
import { configureBlockContent, configureTitleBlockContent } from '../../editors'

import { PortableTextBlock, Rule } from 'sanity'
import type { ColorSelectorValue } from '../components/ColorSelector'
import { EdsIcon } from '../../icons'
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: 'promotion'
_type: 'table'
title?: PortableTextBlock[]
ingress?: PortableTextBlock[]
background?: ColorSelectorValue
theme?: ColorType
}

const titleContentType = configureTitleBlockContent()

const themes: ColorType[] = [
{
title: 'Grey',
value: '#e7e7e7',
},
{
title: 'Blue',
value: '#A8C3DB',
},
{
title: 'Green',
value: '#C2D4D6',
},
]

const ingressContentType = configureBlockContent({
h1: false,
h2: false,
Expand All @@ -36,15 +53,7 @@ const headerCellContentType = configureBlockContent({
lists: false,
smallText: false,
})
/* const tableCellContentType = configureBlockContent({
h1: false,
h2: false,
h3: false,
h4: false,
lists: false,
attachment: true,
})
*/

const chosenColors = ['White', 'Mid Green', 'Moss Green Light', 'Spruce Wood', 'Mist Blue']
const backgroundColors = defaultColors.filter((color) => chosenColors.includes(color.title))
export default {
Expand Down Expand Up @@ -113,10 +122,9 @@ export default {
{ type: 'linkSelector', title: 'Link' },
{ type: 'downloadableFile', title: 'Downloadable file' },
{
type: 'object',
title: 'Text Field',
name: 'textField',
fields: [{ type: 'string', name: 'text', title: 'Text' }],
title: 'RichText',
name: 'richText',
type: 'tableRichText',
},
{
type: 'object',
Expand All @@ -134,7 +142,6 @@ export default {
},
],
},

{
type: 'object',
title: 'Number Field',
Expand All @@ -157,14 +164,14 @@ export default {
prepare({ cells }: { cells: any[] }) {
const [cellOne, cellTwo, cellThree, cellFour] = cells
const numberOfCells = cells.length

const getText = (cellContent: any) => {
if (cellContent._type === 'linkSelector') {
return cellContent.label
} else if (cellContent._type === 'downloadableFile') {
return cellContent.filename
} else if (cellContent._type === 'textField') {
return cellContent.text
} else if (cellContent._type === 'richText') {
const cellString = blocksToText(cellContent.text) || ''
return cellString.length > 15 ? cellString.slice(0, 15) + '...' : cellString
} else if (cellContent._type === 'dateField') {
return cellContent.date
}
Expand All @@ -187,6 +194,17 @@ export default {
},
],
},
{
title: 'Table theme',
description: 'Pick a theme for the table. Default is grey.',
name: 'theme',
type: 'colorlist',
options: {
colors: themes,
},
initialValue: themes[0],
fieldset: 'design',
},
{
title: 'Background',
description: 'Pick a colour for the background. Default is white.',
Expand All @@ -196,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
Loading

0 comments on commit 24dae91

Please sign in to comment.