-
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.
Browse files
Browse the repository at this point in the history
* ✨ Key numbers component #2048 * Missing commit #2028 * ♻️ Remove any #2048 * ✨ horizontal scroll option for mobiles #2048 * 💄 Increased width of item #2048 * 💄 Fix padding issue and scroll offset * Remove duplicate item #2048
- Loading branch information
Showing
12 changed files
with
392 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Rule } from 'sanity' | ||
import { NumberIcon } from '@sanity/icons' | ||
|
||
export default { | ||
name: 'keyNumberItem', | ||
type: 'object', | ||
title: 'Key Number', | ||
fields: [ | ||
{ | ||
name: 'keyNumber', | ||
title: 'Key Number', | ||
type: 'number', | ||
validation: (Rule: Rule) => Rule.required(), | ||
}, | ||
{ | ||
name: 'unit', | ||
title: 'Unit', | ||
description: 'A short abbreviated text describing the unit of the key number', | ||
type: 'string', | ||
}, | ||
{ | ||
name: 'description', | ||
title: 'Description', | ||
type: 'string', | ||
description: 'Short description to show below the key number', | ||
}, | ||
], | ||
|
||
preview: { | ||
select: { | ||
keyNumber: 'keyNumber', | ||
unit: 'unit', | ||
description: 'description', | ||
}, | ||
prepare(selection: Record<string, string | number>) { | ||
const { keyNumber, unit, description } = selection | ||
return { | ||
title: `${keyNumber} ${unit ?? ''}`, | ||
subtitle: description, | ||
media: NumberIcon, | ||
} | ||
}, | ||
}, | ||
} |
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,116 @@ | ||
import CompactBlockEditor from '../components/CompactBlockEditor' | ||
import { configureBlockContent, configureTitleBlockContent } from '../editors' | ||
import { PortableTextBlock, Rule } from 'sanity' | ||
import { NumberIcon } from '@sanity/icons' | ||
import blocksToText from '../../helpers/blocksToText' | ||
|
||
const titleContentType = configureTitleBlockContent() | ||
const ingressContentType = configureBlockContent({ | ||
h1: false, | ||
h2: false, | ||
h3: false, | ||
h4: false, | ||
attachment: false, | ||
}) | ||
|
||
const disclaimerContentType = configureBlockContent({ | ||
h1: false, | ||
h2: false, | ||
h3: false, | ||
h4: false, | ||
attachment: false, | ||
smallText: true, | ||
}) | ||
|
||
export default { | ||
name: 'keyNumbers', | ||
title: 'Key Numbers', | ||
type: 'object', | ||
fieldsets: [ | ||
{ | ||
name: 'link', | ||
title: 'Link', | ||
description: 'Select either an internal link or external URL.', | ||
}, | ||
{ | ||
name: 'design', | ||
title: 'Design options', | ||
}, | ||
], | ||
|
||
fields: [ | ||
{ | ||
title: 'Title', | ||
name: 'title', | ||
type: 'array', | ||
components: { | ||
input: CompactBlockEditor, | ||
}, | ||
of: [titleContentType], | ||
validation: (Rule: Rule) => Rule.required().warning('In most cases you should add a title'), | ||
}, | ||
{ | ||
name: 'ingress', | ||
title: 'Ingress', | ||
type: 'array', | ||
of: [ingressContentType], | ||
}, | ||
{ | ||
name: 'keyNumberItems', | ||
title: 'Key Number Items', | ||
type: 'array', | ||
of: [{ type: 'keyNumberItem' }], | ||
validation: (Rule: Rule) => Rule.min(2).error('Need minimum 2 key numbers'), | ||
}, | ||
{ | ||
name: 'useHorizontalScroll', | ||
title: 'Use horizontal scroll', | ||
description: | ||
'When this is enabled, the key numbers will use horizontal scroll if the amount of content is greater than the screen size allows. Only for mobiles.', | ||
type: 'boolean', | ||
initialValue: false, | ||
}, | ||
{ | ||
name: 'disclaimer', | ||
title: 'Disclaimer', | ||
type: 'array', | ||
components: { | ||
input: CompactBlockEditor, | ||
}, | ||
of: [disclaimerContentType], | ||
}, | ||
{ | ||
name: 'action', | ||
title: 'Link/action', | ||
description: 'Select the link or downloadable file for the teaser', | ||
fieldset: 'link', | ||
type: 'array', | ||
of: [ | ||
{ type: 'linkSelector', title: 'Link' }, | ||
{ type: 'downloadableImage', title: 'Downloadable image' }, | ||
{ type: 'downloadableFile', title: 'Downloadable file' }, | ||
], | ||
validation: (Rule: Rule) => Rule.max(1).error('Only one action is permitted'), | ||
}, | ||
{ | ||
title: 'Background', | ||
description: 'Pick a colour for the background. Default is white.', | ||
name: 'background', | ||
type: 'colorlist', | ||
fieldset: 'design', | ||
}, | ||
], | ||
preview: { | ||
select: { | ||
title: 'title', | ||
items: 'keyNumberItems', | ||
}, | ||
prepare(selection: { title: PortableTextBlock[]; items: Array<object> }) { | ||
return { | ||
title: blocksToText(selection.title), | ||
subtitle: `Showing ${selection.items.length} key numbers`, | ||
media: NumberIcon, | ||
} | ||
}, | ||
}, | ||
} |
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,27 @@ | ||
import downloadableFileFields from './actions/downloadableFileFields' | ||
import downloadableImageFields from './actions/downloadableImageFields' | ||
import linkSelectorFields from './actions/linkSelectorFields' | ||
import markDefs from './blockEditorMarks' | ||
|
||
export const keyNumbersFields = /*groq*/ ` | ||
"type": _type, | ||
"id" : _key, | ||
title, | ||
ingress[]{..., ${markDefs}}, | ||
disclaimer[]{..., ${markDefs}}, | ||
useHorizontalScroll, | ||
"designOptions": { | ||
"background": coalesce(background.title, 'White'), | ||
}, | ||
"action": action[0]{ | ||
${linkSelectorFields}, | ||
${downloadableFileFields}, | ||
${downloadableImageFields}, | ||
}, | ||
"items" : keyNumberItems[]{ | ||
"id": _key, | ||
keyNumber, | ||
unit, | ||
description, | ||
}, | ||
` |
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
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,34 @@ | ||
import { LinkData } from '../../types' | ||
import { getUrlFromAction } from '../../common/helpers' | ||
import { getLocaleFromName } from '../../lib/localization' | ||
import { Link } from '@components/Link' | ||
import styled from 'styled-components' | ||
|
||
const StyledLink = styled(Link)` | ||
font-size: var(--typeScale-1); | ||
` | ||
const ReadMoreLink = ({ action }: { action: LinkData }) => { | ||
const { type, label, extension } = action | ||
const url = getUrlFromAction(action) | ||
if (!url) { | ||
console.warn(`Missing URL on 'TeaserAction' link with type: '${type}' and label: '${label}'`) | ||
return null | ||
} | ||
|
||
if (action.type === 'internalUrl') { | ||
const locale = getLocaleFromName(action.link?.lang) | ||
return ( | ||
<StyledLink href={url} locale={locale} variant="readMore" aria-label={action.ariaLabel}> | ||
{action.label} | ||
</StyledLink> | ||
) | ||
} | ||
|
||
return ( | ||
<StyledLink variant="readMore" href={url} type={action.type} aria-label={action.ariaLabel}> | ||
{action.label} {extension && `(${extension.toUpperCase()})`} | ||
</StyledLink> | ||
) | ||
} | ||
|
||
export default ReadMoreLink |
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.