From 4245628da16fdcf70a7af797fee07dee10e3ac04 Mon Sep 17 00:00:00 2001 From: Henrik Larsson Date: Tue, 15 Aug 2023 13:32:36 +0200 Subject: [PATCH] Alert banner --- .../header/alert-banner/alert-banner.tsx | 13 +++++ components/layout/header/header.tsx | 2 +- components/modules/hero/hero.tsx | 11 ++++- .../modules/usp-section/usp-section.tsx | 44 ++++++++--------- components/ui/alert.tsx | 49 +++++++++++++++++++ components/ui/text/text.tsx | 2 +- lib/sanity/queries.tsx | 2 + lib/sanity/schemas/documents/usp.tsx | 34 ++++++------- lib/sanity/schemas/objects/hero.ts | 29 +++++++++-- 9 files changed, 138 insertions(+), 48 deletions(-) create mode 100644 components/layout/header/alert-banner/alert-banner.tsx create mode 100644 components/ui/alert.tsx diff --git a/components/layout/header/alert-banner/alert-banner.tsx b/components/layout/header/alert-banner/alert-banner.tsx new file mode 100644 index 000000000..934739da7 --- /dev/null +++ b/components/layout/header/alert-banner/alert-banner.tsx @@ -0,0 +1,13 @@ +import { ExclamationTriangleIcon } from '@heroicons/react/24/outline'; + +import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'; + +export function AlertBanner() { + return ( + + + Error + Your session has expired. Please log in again. + + ); +} diff --git a/components/layout/header/header.tsx b/components/layout/header/header.tsx index 77f53fa18..de063e7fa 100644 --- a/components/layout/header/header.tsx +++ b/components/layout/header/header.tsx @@ -26,7 +26,7 @@ export default async function Header({ locale }: HeaderProps) { return (
-
+
}> diff --git a/components/modules/hero/hero.tsx b/components/modules/hero/hero.tsx index b23966356..31604204f 100644 --- a/components/modules/hero/hero.tsx +++ b/components/modules/hero/hero.tsx @@ -8,6 +8,8 @@ interface HeroProps { label?: string; title: string; image: object | any; + color?: string; + overlay?: boolean; link: { title: string; reference: { @@ -26,7 +28,7 @@ const heroSize = { halfScreen: 'aspect-square max-h-[50vh] lg:aspect-auto lg:min-h-[50vh]' }; -const Hero = ({ variant, title, text, label, image, link }: HeroProps) => { +const Hero = ({ variant, title, text, label, image, link, color, overlay }: HeroProps) => { const heroClass = heroSize[variant as HeroSize] || heroSize.fullScreen; return ( @@ -43,7 +45,12 @@ const Hero = ({ variant, title, text, label, image, link }: HeroProps) => { fill /> )} -
+ {overlay &&
} +
{label && ( {label} diff --git a/components/modules/usp-section/usp-section.tsx b/components/modules/usp-section/usp-section.tsx index 28955c04a..ef741301a 100644 --- a/components/modules/usp-section/usp-section.tsx +++ b/components/modules/usp-section/usp-section.tsx @@ -1,9 +1,9 @@ -'use client' +'use client'; import SanityImage from '../../ui/sanity-image'; interface USPSectionProps { - usps: [] | any + usps: [] | any; } const USPSection = ({ usps }: USPSectionProps) => { @@ -12,35 +12,33 @@ const USPSection = ({ usps }: USPSectionProps) => { return (
{usps.map((usp: any, index: number) => ( -
-
- -
-

{usp.title}

+
+ {usp?.image && ( +
+ +
+ )} +

{usp.title}

{usp.text && ( -

+

{usp.text}

)}
))}
-
- ) -} + ); +}; -export default USPSection \ No newline at end of file +export default USPSection; diff --git a/components/ui/alert.tsx b/components/ui/alert.tsx new file mode 100644 index 000000000..962f9dbd3 --- /dev/null +++ b/components/ui/alert.tsx @@ -0,0 +1,49 @@ +import { cva, type VariantProps } from 'class-variance-authority'; +import * as React from 'react'; + +import { cn } from '@/lib/utils'; + +const alertVariants = cva( + 'relative w-full border px-4 py-2 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground', + { + variants: { + variant: { + default: 'bg-background text-foreground', + destructive: + 'border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive' + } + }, + defaultVariants: { + variant: 'default' + } + } +); + +const Alert = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes & VariantProps +>(({ className, variant, ...props }, ref) => ( +
+)); +Alert.displayName = 'Alert'; + +const AlertTitle = React.forwardRef>( + ({ className, ...props }, ref) => ( +
+ ) +); +AlertTitle.displayName = 'AlertTitle'; + +const AlertDescription = React.forwardRef< + HTMLParagraphElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+)); +AlertDescription.displayName = 'AlertDescription'; + +export { Alert, AlertDescription, AlertTitle }; diff --git a/components/ui/text/text.tsx b/components/ui/text/text.tsx index 9bc831e71..950f3bd3f 100644 --- a/components/ui/text/text.tsx +++ b/components/ui/text/text.tsx @@ -70,7 +70,7 @@ const Text: FunctionComponent = ({ ['max-w-prose font-display text-2xl font-extrabold leading-none md:text-3xl md:leading-none lg:text-4xl lg:leading-none']: variant === 'sectionHeading', ['text-sm leading-tight lg:text-base']: variant === 'listChildHeading', - ['max-w-prose text-lg text-high-contrast lg:text-xl']: variant === 'label', + ['max-w-prose text-lg lg:text-xl']: variant === 'label', ['max-w-prose']: variant === 'paragraph' }, className diff --git a/lib/sanity/queries.tsx b/lib/sanity/queries.tsx index fb8a0cd4c..358c364dc 100644 --- a/lib/sanity/queries.tsx +++ b/lib/sanity/queries.tsx @@ -33,6 +33,8 @@ export const modules = ` variant, headingLevel, text, + color, + overlay, link { title, reference->{title, slug, "locale": language} diff --git a/lib/sanity/schemas/documents/usp.tsx b/lib/sanity/schemas/documents/usp.tsx index b372884e9..e9dbfe709 100644 --- a/lib/sanity/schemas/documents/usp.tsx +++ b/lib/sanity/schemas/documents/usp.tsx @@ -1,7 +1,6 @@ -import {StarIcon} from '@sanity/icons' -import {defineField} from 'sanity' -import {languages} from '../../languages' -import {validateImage} from '../../utils/validation' +import { StarIcon } from '@sanity/icons'; +import { defineField } from 'sanity'; +import { languages } from '../../languages'; export default defineField({ name: 'usp', @@ -13,7 +12,7 @@ export default defineField({ name: 'language', type: 'string', readOnly: true, - description: 'Language of this document.', + description: 'Language of this document.' // hidden: true, }), // Title @@ -22,15 +21,14 @@ export default defineField({ title: 'Title', type: 'string', description: 'USP title', - validation: (Rule) => Rule.required(), + validation: (Rule) => Rule.required() }), // Image defineField({ name: 'image', title: 'Image', type: 'mainImage', - description: 'USP icon', - validation: (Rule) => validateImage(Rule, true), + description: 'USP icon' }), // Text defineField({ @@ -38,25 +36,25 @@ export default defineField({ title: 'Text', type: 'text', description: 'Small text displayed below title.', - rows: 5, - }), + rows: 5 + }) ], preview: { select: { title: 'title', image: 'image', - language: 'language', + language: 'language' }, prepare(selection) { - const {image, title, language} = selection + const { image, title, language } = selection; - const currentLang = languages.find((lang) => lang.id === language) + const currentLang = languages.find((lang) => lang.id === language); return { media: image, title, - subtitle: `${currentLang ? currentLang.title : ''}`, - } - }, - }, -}) + subtitle: `${currentLang ? currentLang.title : ''}` + }; + } + } +}); diff --git a/lib/sanity/schemas/objects/hero.ts b/lib/sanity/schemas/objects/hero.ts index c60d9c5b0..a8e59835d 100644 --- a/lib/sanity/schemas/objects/hero.ts +++ b/lib/sanity/schemas/objects/hero.ts @@ -1,5 +1,5 @@ -import {defineField} from 'sanity' -import {StarIcon} from '@sanity/icons' +import { StarIcon } from '@sanity/icons' +import { defineField } from 'sanity' import { validateImage } from '../../utils/validation' export default defineField({ @@ -58,6 +58,30 @@ export default defineField({ layout: 'radio', }, }, + { + name: 'color', + type: 'string', + title: 'Color', + initialValue: 'dark', + fieldset: 'settings', + description: 'Set appropriate color depending on image characteristics.', + options: { + list: [ + {title: 'Dark', value: 'dark'}, + {title: 'Light', value: 'light'}, + ], + layout: 'radio', + }, + }, + { + name: 'overlay', + type: 'boolean', + title: 'Overlay?', + fieldset: 'settings', + description: 'Adds a dark overlay to the image.', + initialValue: false, + validation: (Rule) => Rule.required(), + }, { name: 'label', type: 'string', @@ -101,7 +125,6 @@ export default defineField({ title: 'Link', description: 'Link to internal page.', options: { - collapsed: true, collapsible: true, }, },