-
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.
Merge branch 'bose/inpage-links-v2' into staging
- Loading branch information
Showing
9 changed files
with
202 additions
and
1 deletion.
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
53 changes: 53 additions & 0 deletions
53
sanityv3/schemas/objects/anchorLinkList/anchorLinkList.tsx
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,53 @@ | ||
/* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
import { format_line_spacing } from '@equinor/eds-icons' | ||
import { EdsIcon } from '../../../icons' | ||
|
||
export type AnchorLinkList = { | ||
_type: 'anchorLinkList' | ||
} | ||
|
||
export default { | ||
title: 'List of anchor links', | ||
name: 'anchorLinkList', | ||
type: 'object', | ||
|
||
fields: [ | ||
{ | ||
name: 'title', | ||
type: 'string', | ||
}, | ||
{ | ||
name: 'columns', | ||
type: 'string', | ||
description: 'Manually set number of columns. Defaults to even flow with set space between', | ||
options: { | ||
list: [ | ||
{ title: 'Even flow', value: 'flex' }, | ||
{ title: '3', value: '3' }, | ||
{ title: '4', value: '4' }, | ||
{ title: '5', value: '5' }, | ||
{ title: '6', value: '6' }, | ||
], | ||
}, | ||
initalValue: 'flex', | ||
}, | ||
{ | ||
title: 'List of anchors', | ||
name: 'anchorList', | ||
type: 'array', | ||
of: [{ type: 'anchorLinkReference' }], | ||
}, | ||
], | ||
preview: { | ||
select: { | ||
title: 'title', | ||
}, | ||
prepare({ title }: { title: string }) { | ||
return { | ||
title: title, | ||
subtitle: `List of anchor links component`, | ||
media: EdsIcon(format_line_spacing), | ||
} | ||
}, | ||
}, | ||
} |
39 changes: 39 additions & 0 deletions
39
sanityv3/schemas/objects/anchorLinkList/anchorLinkReference.tsx
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,39 @@ | ||
import { anchor } from '@equinor/eds-icons' | ||
import { EdsIcon } from '../../../icons' | ||
import { AnchorLinkDescription } from '../anchorReferenceField' | ||
|
||
export type AnchorLinkReference = { | ||
_type: 'anchorLinkReference' | ||
} | ||
|
||
export default { | ||
title: 'Anchor Link Reference', | ||
name: 'anchorLinkReference', | ||
type: 'object', | ||
|
||
fields: [ | ||
{ | ||
name: 'title', | ||
description: 'Visible title for the anchor link in the list of anchors', | ||
type: 'string', | ||
}, | ||
{ | ||
name: 'anchorReference', | ||
title: 'Anchor reference', | ||
type: 'anchorReferenceField', | ||
description: AnchorLinkDescription(), | ||
}, | ||
], | ||
preview: { | ||
select: { | ||
title: 'title', | ||
}, | ||
prepare({ title }: { title: string }) { | ||
return { | ||
title: title, | ||
subtitle: `Anchor Link Reference component`, | ||
media: EdsIcon(anchor), | ||
} | ||
}, | ||
}, | ||
} |
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,65 @@ | ||
import { twMerge } from 'tailwind-merge' | ||
import { HTMLAttributes, forwardRef } from 'react' | ||
import { AnchorLinkListData } from '../../types' | ||
import { Typography } from '../../core/Typography' | ||
import { ButtonLink } from '../../core/Link' | ||
|
||
export type AnchorLinkListProps = { | ||
data: AnchorLinkListData | ||
anchor?: string | ||
className?: string | ||
} & HTMLAttributes<HTMLElement> | ||
|
||
const AnchorLinkList = forwardRef<HTMLElement, AnchorLinkListProps>(function AnchorLinkList( | ||
{ data, anchor, className = '', ...rest }, | ||
ref, | ||
) { | ||
const { title, anchorList = [], columns } = data | ||
|
||
const getFlow = () => { | ||
const commonGridStyling = 'grid auto-fill-fr lg:place-items-start' | ||
switch (columns) { | ||
case '3': | ||
return `${commonGridStyling} lg:grid-cols-3` | ||
case '4': | ||
return `${commonGridStyling} lg:grid-cols-4` | ||
case '5': | ||
return `${commonGridStyling} lg:grid-cols-5` | ||
case '6': | ||
return `${commonGridStyling} lg:grid-cols-6` | ||
default: | ||
case 'flex': | ||
return 'grid auto-fill-fr justify-start' | ||
} | ||
} | ||
return ( | ||
<section | ||
ref={ref} | ||
className={twMerge(`px-layout-md pb-page-content max-w-viewport mx-auto flex flex-col items-center`, className)} | ||
id={anchor} | ||
{...rest} | ||
> | ||
<div className="w-full border-y border-moss-green-50 py-6"> | ||
{title && ( | ||
<Typography variant="h5" as="h2" className="pb-4 text-center"> | ||
{title} | ||
</Typography> | ||
)} | ||
<ul className={`w-full ${getFlow()} gap-x-4 gap-y-2 lg:gap-y-4 lg:gap-x-6`}> | ||
{anchorList?.map((anchorLink: { id: string; title?: string; anchorReference?: string }) => { | ||
const anchor = anchorLink?.anchorReference ? `#${anchorLink?.anchorReference}` : '' | ||
return ( | ||
<li key={`anchor_link_${anchorLink?.id}`} className="w-full flex justify-center"> | ||
<ButtonLink variant="ghost" href={anchor} className="w-max text-moss-green-100"> | ||
{anchorLink?.title} | ||
</ButtonLink> | ||
</li> | ||
) | ||
})} | ||
</ul> | ||
</div> | ||
</section> | ||
) | ||
}) | ||
|
||
export default AnchorLinkList |
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,2 @@ | ||
//"use client"; | ||
export { default as AnchorLinkList, type AnchorLinkListProps } from './AnchorLinkList' |
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