Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor FigCaption to tailwind #2179 #2187

Merged
merged 4 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions web/components/src/FigureCaption/Attribution.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { forwardRef, HTMLAttributes } from 'react'
import styled from 'styled-components'

export type AttributionProps = HTMLAttributes<HTMLDivElement>

export const StyledAttribution = styled.div``

export const Attribution = forwardRef<HTMLDivElement, AttributionProps>(function ({ children, ...rest }, ref) {
return (
<StyledAttribution ref={ref} {...rest}>
<div ref={ref} {...rest}>
{children}
</StyledAttribution>
</div>
)
})
7 changes: 2 additions & 5 deletions web/components/src/FigureCaption/Caption.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { forwardRef, HTMLAttributes } from 'react'
import styled from 'styled-components'

export type CaptionProps = HTMLAttributes<HTMLDivElement>

export const StyledCaption = styled.div``

export const Caption = forwardRef<HTMLDivElement, CaptionProps>(function ({ children, ...rest }, ref) {
return (
<StyledCaption ref={ref} {...rest}>
<div ref={ref} {...rest}>
{children}
</StyledCaption>
</div>
)
})
46 changes: 14 additions & 32 deletions web/components/src/FigureCaption/FigureCaption.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,25 @@
import { forwardRef, HTMLAttributes, CSSProperties } from 'react'
import { Typography } from '@equinor/eds-core-react'
import styled from 'styled-components'
import { style } from '@equinor/eds-icons'

export const StyledFigCaption = styled(Typography)`
font-size: var(--size);
margin-top: var(--space-small);
color: var(--color-on-background);

@media (min-width: 800px) {
max-width: 560px;
}

@media (min-width: 1300px) {
max-width: 635px;
}
`
import { forwardRef, HTMLAttributes } from 'react'
import { twMerge } from 'tailwind-merge'

export type FigureCaptionProps = {
size?: 'small' | 'medium'
} & HTMLAttributes<HTMLElement>

export const FigureCaption = forwardRef<HTMLElement, FigureCaptionProps>(function FigureCaption(
{ size = 'small', children, ...rest },
ref,
) {
export const FigureCaption = forwardRef<HTMLElement, FigureCaptionProps>(function FigureCaption({
size = 'small',
children,
className,
...rest
}) {
return (
<StyledFigCaption
forwardedAs="figcaption"
style={
{
...style,
'--size': size === 'small' ? 'var(--typeScale-0)' : 'var(--typeScale-1)',
} as CSSProperties
}
ref={ref}
<figcaption
className={twMerge(
`max-w-prose mt-2 leading-misty text-slate ${size === 'small' ? 'text-xs' : 'text-base'} figCaption`,
className,
)}
{...rest}
>
{children}
</StyledFigCaption>
</figcaption>
)
})
4 changes: 2 additions & 2 deletions web/components/src/FigureCaption/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FigureCaption as FigureCaptionWrapper, FigureCaptionProps, StyledFigCaption } from './FigureCaption'
import { FigureCaption as FigureCaptionWrapper, FigureCaptionProps } from './FigureCaption'
import { Attribution } from './Attribution'
import { Caption } from './Caption'

Expand All @@ -12,5 +12,5 @@ const FigureCaption = FigureCaptionWrapper as FigureCaptionCompoundProps
FigureCaption.Caption = Caption
FigureCaption.Attribution = Attribution

export { FigureCaption, StyledFigCaption }
export { FigureCaption }
export type { FigureCaptionProps }
3 changes: 1 addition & 2 deletions web/components/src/Text/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { forwardRef, HTMLAttributes, CSSProperties } from 'react'
import { Typography, TypographyProps } from '@equinor/eds-core-react'
import styled from 'styled-components'
import { StyledFigCaption } from '../FigureCaption'

type StyledTextProps = {
centered?: boolean
Expand All @@ -19,7 +18,7 @@ const StyledText = styled(Typography)<StyledTextProps>`
}

/* If the text block is within a figcaption, we don't want the bottom margin */
${StyledFigCaption} &:last-child {
.figCaption > &:last-child {
margin-bottom: 0;
}

Expand Down
9 changes: 2 additions & 7 deletions web/pageComponents/shared/Hero/DefaultHeroImage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import styled from 'styled-components'
import type { ImageWithCaptionData } from '../../../types/types'
import Image, { Ratios } from '../SanityImage'
import { Caption } from '../image/Caption'
Expand All @@ -7,14 +6,10 @@ type HeroImageProps = {
data: ImageWithCaptionData
}

const StyledFigure = styled.figure`
margin: 0;
`

const DefaulHeroImage = ({ data }: HeroImageProps) => {
const { image, caption, attribution } = data
padms marked this conversation as resolved.
Show resolved Hide resolved
return (
<StyledFigure>
<figure>
<Image
maxWidth={1420}
aspectRatio={Ratios.ONE_TO_TWO}
Expand All @@ -32,7 +27,7 @@ const DefaulHeroImage = ({ data }: HeroImageProps) => {
priority
/>
<Caption caption={caption} attribution={attribution} />
</StyledFigure>
</figure>
)
}

Expand Down
6 changes: 4 additions & 2 deletions web/pageComponents/shared/image/Caption.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { CaptionData } from 'types/types'
import { FigureCaption } from '@components'
import { HTMLAttributes } from 'react'
import { twMerge } from 'tailwind-merge'

export const Caption = ({ caption, attribution, ...rest }: CaptionData) => {
export const Caption = ({ caption, attribution, className }: CaptionData & HTMLAttributes<HTMLElement>) => {
return caption || attribution ? (
<FigureCaption {...rest}>
<FigureCaption className={className}>
{caption && <FigureCaption.Caption>{caption}</FigureCaption.Caption>}
{attribution && <FigureCaption.Attribution>{attribution}</FigureCaption.Attribution>}
</FigureCaption>
Expand Down
22 changes: 7 additions & 15 deletions web/pageComponents/shared/image/StyledCaption.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
import { CaptionData } from '../../../types'
import styled from 'styled-components'
import { Caption } from './Caption'
import { BackgroundContainer, BackgroundContainerProps } from '@components'

type CaptionProps = CaptionData & BackgroundContainerProps

const CaptionWithPadding = styled(Caption)`
max-width: var(--maxViewportWidth);
padding: 0 var(--layout-paddingHorizontal-small) var(--space-xLarge) var(--layout-paddingHorizontal-small);
margin-left: auto;
margin-right: auto;
`
const CaptionWrapper = styled(BackgroundContainer)`
display: inline-block;
width: 100%;
`

export const StyledCaption = ({ attribution, caption, background }: CaptionProps) => {
return caption || attribution ? (
<CaptionWrapper background={background}>
<CaptionWithPadding attribution={attribution} caption={caption} />
</CaptionWrapper>
<BackgroundContainer className={'inline-block w-full'} background={background}>
<Caption
className={'max-w-viewport mx-auto pt-0 px-layout-sm pb-8'}
attribution={attribution}
caption={caption}
/>
</BackgroundContainer>
) : (
<></>
)
Expand Down
5 changes: 4 additions & 1 deletion web/tailwind.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ module.exports = {
}),
fontSize: {
//--typeScale-00
xs: ['clamp(calc(11.11 / 16 * 1rem), 0.19vw + 0.65rem, calc(14.08 / 16 * 1rem))'],
'2xs': ['clamp(calc(11.11 / 16 * 1rem), 0.19vw + 0.65rem, calc(14.08 / 16 * 1rem))'],
//--typeScale-0
xs: ['clamp(calc(13.33 / 16 * 1rem), 0.28vw + 0.77rem, calc(17.60 / 16 * 1rem))'],
//--typeScale-05
sm: ['clamp(calc(14.61 / 16 * 1rem), 0.33vw + 0.84rem, calc(19.68 / 16 * 1rem))'],
//--typeScale-1
Expand Down Expand Up @@ -187,6 +189,7 @@ module.exports = {
//--lineHeight-2
earthy: 1.2,
//--lineHeight-2_5
misty: 1.25,
cloudy: 1.35,
//-lineHeight-3
planetary: 1.5,
Expand Down
Loading