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 1 commit
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
42 changes: 10 additions & 32 deletions web/components/src/FigureCaption/FigureCaption.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,21 @@
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 React from 'react'
import { forwardRef, HTMLAttributes } from 'react'

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,
...rest
}) {
return (
<StyledFigCaption
forwardedAs="figcaption"
style={
{
...style,
'--size': size === 'small' ? 'var(--typeScale-0)' : 'var(--typeScale-1)',
} as CSSProperties
}
ref={ref}
<figcaption
className={`max-w-prose mt-sm text-slate ${size === 'small' ? 'text-xs' : 'text-base'} figCaption`}
{...rest}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use spacing.2 instead of custom size

>
{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
4 changes: 3 additions & 1 deletion web/tailwind.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,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
Loading