-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from thomasKn/thomas/fv-215-annoucement-bar
Annoucement bar
- Loading branch information
Showing
11 changed files
with
197 additions
and
5 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,114 @@ | ||
import type {TypeFromSelection} from 'groqd'; | ||
|
||
import {cx} from 'class-variance-authority'; | ||
import Autoplay from 'embla-carousel-autoplay'; | ||
import {useMemo} from 'react'; | ||
|
||
import type {ANNOUCEMENT_BAR_FRAGMENT} from '~/qroq/fragments'; | ||
|
||
import {useSanityRoot} from '~/hooks/useSanityRoot'; | ||
import {useSettingsCssVars} from '~/hooks/useSettingsCssVars'; | ||
|
||
import {Icon} from '../icons/Icon'; | ||
import {SanityInternalLink} from '../sanity/link/SanityInternalLink'; | ||
import { | ||
Carousel, | ||
CarouselContent, | ||
CarouselItem, | ||
CarouselNext, | ||
CarouselPrevious, | ||
} from '../ui/Carousel'; | ||
|
||
type AnnoucementBarProps = TypeFromSelection<typeof ANNOUCEMENT_BAR_FRAGMENT>; | ||
|
||
export function AnnouncementBar() { | ||
const {data} = useSanityRoot(); | ||
const header = data?.header; | ||
const annoucementBar = header?.annoucementBar; | ||
const plugins = useMemo( | ||
() => | ||
header?.autoRotateAnnoucements | ||
? [Autoplay({delay: 5000, stopOnMouseEnter: true})] | ||
: [], | ||
[header], | ||
); | ||
|
||
const cssVars = useSettingsCssVars({ | ||
selector: `#announcement-bar`, | ||
settings: { | ||
colorScheme: header?.annoucementBarColorScheme!, | ||
customCss: null, | ||
hide: null, | ||
padding: null, | ||
}, | ||
}); | ||
|
||
const isActive = annoucementBar?.length! > 1; | ||
|
||
return ( | ||
<section className="bg-background text-foreground" id="announcement-bar"> | ||
<div className="container"> | ||
<style dangerouslySetInnerHTML={{__html: cssVars}} /> | ||
<Carousel opts={{active: isActive}} plugins={plugins}> | ||
<CarouselContent className="relative"> | ||
{annoucementBar?.map((item) => ( | ||
<CarouselItem key={item._key}> | ||
<Item _key={item._key} link={item.link} text={item.text} /> | ||
</CarouselItem> | ||
))} | ||
</CarouselContent> | ||
{isActive && ( | ||
<> | ||
<CarouselPrevious /> | ||
<CarouselNext /> | ||
</> | ||
)} | ||
</Carousel> | ||
</div> | ||
</section> | ||
); | ||
} | ||
|
||
function Item(props: AnnoucementBarProps) { | ||
if (!props.text) return null; | ||
|
||
const className = cx('flex w-full justify-center py-3 text-center'); | ||
|
||
return props.link ? ( | ||
<SanityInternalLink | ||
className={cx(['group', className])} | ||
data={{ | ||
_key: props.link.slug.current, | ||
_type: 'internalLink', | ||
anchor: null, | ||
link: props.link, | ||
name: props.text, | ||
}} | ||
> | ||
<p className="flex items-center text-sm underline-offset-4 group-hover:underline"> | ||
<span className="relative z-[2] block bg-background pr-2"> | ||
{props.text} | ||
</span> | ||
<span className="-translate-x-[2px] transition-transform group-hover:translate-x-0"> | ||
<ArrowRight /> | ||
</span> | ||
</p> | ||
</SanityInternalLink> | ||
) : ( | ||
<p className={className}>{props.text}</p> | ||
); | ||
} | ||
|
||
function ArrowRight() { | ||
return ( | ||
<Icon className="size-4" fill="none" viewBox="0 0 14 10"> | ||
<title>Arrow Right</title> | ||
<path | ||
clipRule="evenodd" | ||
d="M8.537.808a.5.5 0 01.817-.162l4 4a.5.5 0 010 .708l-4 4a.5.5 0 11-.708-.708L11.793 5.5H1a.5.5 0 010-1h10.793L8.646 1.354a.5.5 0 01-.109-.546z" | ||
fill="currentColor" | ||
fillRule="evenodd" | ||
></path> | ||
</Icon> | ||
); | ||
} |
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
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
module.exports = { | ||
arrowParens: 'always', | ||
singleQuote: true, | ||
bracketSpacing: false, | ||
trailingComma: 'all', | ||
plugins: ['prettier-plugin-tailwindcss'], | ||
singleQuote: true, | ||
trailingComma: 'all', | ||
}; |
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,22 @@ | ||
import {Megaphone} from 'lucide-react'; | ||
import {defineField} from 'sanity'; | ||
import {internalLinkField} from './headerNavigation'; | ||
|
||
export default defineField({ | ||
type: 'array', | ||
name: 'announcementBar', | ||
of: [ | ||
{ | ||
type: 'object', | ||
name: 'announcementBar', | ||
icon: Megaphone, | ||
fields: [ | ||
defineField({ | ||
name: 'text', | ||
type: 'string', | ||
}), | ||
internalLinkField, | ||
], | ||
}, | ||
], | ||
}); |
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