Skip to content

Commit

Permalink
Merge branch 'bose/2671' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
BorghildSelle committed Dec 3, 2024
2 parents 63e6be9 + c2f3d8e commit 22e6fb5
Show file tree
Hide file tree
Showing 19 changed files with 401 additions and 43 deletions.
18 changes: 18 additions & 0 deletions sanityv3/schemas/objects/accordionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const contentType = configureBlockContent({
h3: false,
h4: false,
attachment: false,
internalLink: false,
externalLink: false,
})

export default {
Expand All @@ -27,12 +29,28 @@ export default {
type: 'string',
validation: (Rule: Rule) => Rule.required().error(),
},
{
title: 'Image',
name: 'image',
type: 'image',
description: 'Image will be presented as landscape format',
options: {
hotspot: true,
collapsed: false,
},
},
{
title: 'Content',
name: 'content',
type: 'array',
of: [contentType],
},
{
name: 'links',
type: 'array',
title: 'Links',
of: [{ type: 'linkSelector', title: 'Link' }],
},
],
preview: {
select: {
Expand Down
8 changes: 7 additions & 1 deletion sanityv3/schemas/textSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const groups = {
pensionForm: { title: 'Pension form', hidden: !Flags.HAS_PENSION_FORM },
form: { title: 'Form', hidden: !Flags.HAS_FORMS },
cookie: { title: 'Cookie' },
carousel: { title: 'Carousel' },
others: { title: 'Others' },
common: { title: 'Common' },
}
Expand Down Expand Up @@ -295,7 +296,7 @@ const snippets: textSnippet = {
title: 'Pension Category',
defaultValue: 'Pension',
group: groups.pensionForm,
},
},
pension_form_select_topic: {
title: 'Default Pension Category',
defaultValue: 'Pension',
Expand Down Expand Up @@ -816,6 +817,11 @@ const snippets: textSnippet = {
defaultValue: `Please don't enter any personal information`,
group: groups.common,
},
carousel_controls: {
title: 'Carousel controls',
defaultValue: 'Carousel controls',
group: groups.carousel,
},
categories: {
title: 'Categories',
defaultValue: 'Categories',
Expand Down
5 changes: 3 additions & 2 deletions web/components/src/Backgrounds/BackgroundContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { BackgroundColours, BackgroundTypes, ImageBackground } from '../../
import { ColouredContainer } from './ColouredContainer'
import { ImageBackgroundContainer } from './ImageBackgroundContainer'
import { ColorKeyTokens } from '../../../styles/colorKeyToUtilityMap'
import envisTwMerge from '../../../twMerge'

const StyledImageBackground = styled(ImageBackgroundContainer)<{ $isInverted: boolean }>`
${({ $isInverted }) => ($isInverted ? inverted : normal)}
Expand Down Expand Up @@ -57,7 +58,7 @@ export const BackgroundContainer = forwardRef<HTMLDivElement, BackgroundContaine
ref={ref}
id={id}
{...backgroundImage}
className={className}
className={envisTwMerge(`${id ? 'scroll-mt-topbar' : ''}`, className)}
scrimClassName={scrimClassName}
dontSplit={dontSplit}
>
Expand All @@ -77,7 +78,7 @@ export const BackgroundContainer = forwardRef<HTMLDivElement, BackgroundContaine
id={id}
{...restBackground}
style={style}
className={`${className} ${twClassName}`}
className={envisTwMerge(`${id ? 'scroll-mt-topbar' : ''}`, className, twClassName)}
{...rest}
>
{children}
Expand Down
2 changes: 2 additions & 0 deletions web/core/Accordion/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ interface AccordionMultipleProps extends _Accordion.AccordionMultipleProps {
type: 'multiple'
}

export type Variants = 'primary' | 'secondary'

export type AccordionProps = {
className?: string
} & (AccordionSingleProps | AccordionMultipleProps)
Expand Down
84 changes: 72 additions & 12 deletions web/core/Accordion/Content.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,106 @@
import { CSSProperties, forwardRef, useEffect, useMemo, useRef, useState } from 'react'
import { forwardRef, useMemo, useRef } from 'react'
import { AccordionContent, AccordionContentProps as _AccordionContentProps } from '@radix-ui/react-accordion'
import envisTwMerge from '../../twMerge'
import { mergeRefs } from '@equinor/eds-utils'
import { Variants } from './Accordion'

export type AccordionContentProps = _AccordionContentProps
export type AccordionContentProps = {
variant?: Variants
} & _AccordionContentProps

export const Content = forwardRef<HTMLDivElement, AccordionContentProps>(function Content(
{ children, className = '', forceMount, ...rest },
{ variant = 'primary', children, className = '', ...rest },
forwardedRef,
) {
const contentRef = useRef<HTMLDivElement>(null)
const combinedContentRef = useMemo(
() => mergeRefs<HTMLDivElement>(contentRef, forwardedRef),
[contentRef, forwardedRef],
)
const [collapsedHeight, setCollapsedHeight] = useState<number>()

/* const [collapsedHeight, setCollapsedHeight] = useState<number>()
useEffect(() => {
if (!contentRef.current) {
return
}
if (contentRef.current && forceMount) {
const currentHeight = contentRef.current.clientHeight
const height = Math.max(collapsedHeight ?? 0, currentHeight)

setCollapsedHeight(height)
}
}, [collapsedHeight, contentRef, forceMount])
}, [collapsedHeight, contentRef, forceMount]) */

const variantClassName: Partial<Record<Variants, string>> = {
primary: '',
secondary: '',
}

/**
* pt-0
ml-2.5
border-l
border-dashed
border-energy-red-100
pl-7
pr-4
pb-6
mb-6
[&p]:last:mb-0
flex
flex-col
gap-6
*/

const getVariantBody = () => {
switch (variant) {
case 'primary':
return (
<div
className={`pt-0
ml-2.5
border-l
border-dashed
border-energy-red-100
pl-7
pr-4
pb-6
mb-6
flex
flex-col
gap-6`}
>
{children}
</div>
)

default:
return <>{children}</>
}
}

return (
<AccordionContent
ref={combinedContentRef}
forceMount={forceMount}
{...(forceMount && {
/* forceMount={forceMount} */
/* {...(forceMount && {
style: {
'--radix-collapsible-content-height': `${collapsedHeight}px`,
'--radix-collapsible-content-height': `${height}px`,
} as CSSProperties,
})}
className={envisTwMerge(`${forceMount ? 'data-closed:hidden' : ''}`, className)}
})}
motion-safe:data-open:animate-slideUp
motion-safe:data-closed:animate-slideDown
*/
className={envisTwMerge(
`overflow-hidden
motion-safe:data-closed:animate-slideDown
motion-safe:data-open:animate-slideUp
${variantClassName[variant]}`,
className,
)}
{...rest}
>
{children}
{getVariantBody()}
</AccordionContent>
)
})
136 changes: 122 additions & 14 deletions web/core/Accordion/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import {
AccordionTriggerProps,
} from '@radix-ui/react-accordion'
import envisTwMerge from '../../twMerge'
import { chevron_down } from '@equinor/eds-icons'
import { add_circle_filled, add_circle_outlined, chevron_down, remove, remove_outlined } from '@equinor/eds-icons'
import { TransformableIcon } from '../../icons/TransformableIcon'
import { Variants } from './Accordion'
import { Typography } from '@core/Typography'

export type AccordionHeaderProps = {
hasSectionTitle?: boolean
variant?: Variants
headerClassName?: string
className?: string
} & _AccordionHeaderProps &
Expand All @@ -23,22 +27,126 @@ export type AccordionHeaderProps = {
* @see 🏷️ {@link AccordionHeaderProps}
*/
export const Header = forwardRef<HTMLButtonElement, AccordionHeaderProps>(function Header(
{ children, className = '', headerClassName = '', ...rest },
{ variant = 'primary', children, hasSectionTitle = false, className = '', headerClassName = '', ...rest },
ref,
) {
const headerVariantClassName: Partial<Record<Variants, string>> = {
primary: '',
secondary: '',
}
const variantClassName: Partial<Record<Variants, string>> = {
primary: `flex
items-center
w-full
bg-transparent
sm:py-6
border-none
cursor-pointer
focus-visible:envis-outline
dark:focus-visible:envis-outline-invert`,
secondary: 'group/trigger w-full flex justify-between border-b py-3 border-moss-green-90',
}
const iconVariantClassName: Partial<Record<Variants, string>> = {
primary: '',
secondary: 'rotate-180 group-data-closed/trigger:rotate-0',
}

const getVariantBody = () => {
switch (variant) {
case 'secondary':
return (
<>
{children}
<TransformableIcon className={iconVariantClassName[variant]} iconData={chevron_down} />
</>
)
default:
return (
<>
<span className="grid pr-4">
<TransformableIcon
className={`fill-energy-red-100
dark:fill-white-100
opacity-100
group-hover:opacity-0
group-data-open:opacity-0
transition-opacity
col-span-full
row-span-full`}
size={24}
iconData={add_circle_outlined}
/>
<TransformableIcon
className={`fill-energy-red-100
dark:fill-white-100
opacity-0
group-hover:opacity-100
group-data-open:opacity-0
transition-opacity
col-span-full
row-span-full`}
size={24}
iconData={add_circle_filled}
/>
<TransformableIcon
className={`fill-energy-red-100
dark:fill-white-100
opacity-0
group-data-open:opacity-100
group-data-open:group-hover:opacity-0
transition-opacity
col-span-full
row-span-full`}
size={24}
iconData={remove_outlined}
/>
<TransformableIcon
className={`fill-energy-red-100
dark:fill-white-100
opacity-0
group-data-open:opacity-0
group-data-open:group-hover:opacity-100
transition-opacity
col-span-full
row-span-full`}
size={24}
iconData={remove}
/>
</span>
<Typography
as="span"
className={`
motion-safe:transition-all
motion-safe:duration-100
motion-safe:ease-in-out
font-normal
group-data-open:font-bold
pt-2
leading-earthy`}
>
{children}
</Typography>
</>
)
}
}

return (
<AccordionHeader className={envisTwMerge(``, headerClassName)}>
<AccordionTrigger
ref={ref}
className={envisTwMerge(
`group/trigger w-full flex justify-between border-b py-3 border-moss-green-90`,
className,
)}
{...rest}
>
{children}
<TransformableIcon className={'rotate-180 group-data-closed/trigger:rotate-0'} iconData={chevron_down} />
</AccordionTrigger>
<AccordionHeader asChild className={envisTwMerge(`${headerVariantClassName[variant]}`, headerClassName)}>
<Typography as={hasSectionTitle ? 'h3' : 'h2'}>
<AccordionTrigger
ref={ref}
className={envisTwMerge(
`group
${variantClassName[variant]}
`,
className,
)}
{...rest}
>
{getVariantBody()}
</AccordionTrigger>
</Typography>
</AccordionHeader>
)
})
Loading

0 comments on commit 22e6fb5

Please sign in to comment.