-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Renamed `HeaderImageCaption` to `ImageDetails` - Simplified component API - Broke up component CSS - Added type definitions to common - Lifted `pipe` and `maybeRender` to common - Added stories - Fix credit rendering
- Loading branch information
Showing
9 changed files
with
197 additions
and
157 deletions.
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
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
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,27 @@ | ||
// ----- Imports ----- // | ||
|
||
import { some } from '@guardian/types'; | ||
import type { FC } from 'react'; | ||
|
||
import ImageDetails from './imageDetails'; | ||
|
||
// ----- Stories ----- // | ||
|
||
const Default: FC = () => | ||
<ImageDetails | ||
caption={some('A caption')} | ||
credit={some('By a person')} | ||
supportsDarkMode | ||
id="caption-id" | ||
/> | ||
|
||
// ----- Exports ----- // | ||
|
||
export default { | ||
component: ImageDetails, | ||
title: 'Common/Components/ImageDetails', | ||
} | ||
|
||
export { | ||
Default, | ||
} |
13 changes: 11 additions & 2 deletions
13
...rc/components/headerImageCaption.test.tsx → ...ring/src/components/imageDetails.test.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
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,115 @@ | ||
// ----- Imports ----- // | ||
|
||
import type { SerializedStyles } from '@emotion/react'; | ||
import { css } from '@emotion/react'; | ||
import { remSpace } from '@guardian/src-foundations'; | ||
import { brandAlt, neutral } from '@guardian/src-foundations/palette'; | ||
import { textSans } from '@guardian/src-foundations/typography'; | ||
import { SvgCamera } from '@guardian/src-icons'; | ||
import { Option, OptionKind } from '@guardian/types'; | ||
import { withDefault } from '@guardian/types'; | ||
import { darkModeCss } from '@guardian/common-rendering/src/lib'; | ||
import type { FC } from 'react'; | ||
|
||
// ----- Component ----- // | ||
|
||
const styles = css` | ||
position: absolute; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
`; | ||
|
||
const detailsStyles = (supportsDarkMode: boolean): SerializedStyles => css` | ||
&[open] { | ||
min-height: 44px; | ||
max-height: 999px; | ||
background-color: rgba(0, 0, 0, 0.8); | ||
padding: ${remSpace[3]}; | ||
overflow: hidden; | ||
padding-right: ${remSpace[12]}; | ||
z-index: 1; | ||
color: ${neutral[100]}; | ||
${textSans.small()}; | ||
box-sizing: border-box; | ||
${darkModeCss(supportsDarkMode)` | ||
color: ${neutral[60]}; | ||
`} | ||
} | ||
`; | ||
|
||
const iconStyles = (supportsDarkMode: boolean): SerializedStyles => css` | ||
display: block; | ||
text-align: center; | ||
background-color: ${brandAlt[400]}; | ||
width: 34px; | ||
height: 34px; | ||
position: absolute; | ||
bottom: 8px; | ||
right: 8px; | ||
border-radius: 100%; | ||
outline: none; | ||
&::-webkit-details-marker { | ||
display: none; | ||
} | ||
${darkModeCss(supportsDarkMode)` | ||
background-color: ${neutral[60]}; | ||
opacity: .7; | ||
`} | ||
`; | ||
|
||
const svgStyles: SerializedStyles = css` | ||
line-height: 32px; | ||
font-size: 0; | ||
svg { | ||
width: 75%; | ||
height: 75%; | ||
margin: 12.5%; | ||
} | ||
path { | ||
fill: ${neutral[7]}; | ||
} | ||
`; | ||
|
||
interface Props { | ||
caption: Option<string>; | ||
credit: Option<string>; | ||
supportsDarkMode: boolean; | ||
id: string; | ||
} | ||
|
||
const ImageDetails: FC<Props> = ({ | ||
caption, | ||
credit, | ||
supportsDarkMode, | ||
id, | ||
}: Props) => { | ||
if (caption.kind === OptionKind.None && credit.kind === OptionKind.None) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<figcaption css={styles}> | ||
<details css={detailsStyles(supportsDarkMode)}> | ||
<summary css={iconStyles(supportsDarkMode)}> | ||
<span css={svgStyles}> | ||
<SvgCamera /> | ||
Click to see figure caption | ||
</span> | ||
</summary> | ||
<span id={id}> | ||
{withDefault('')(caption)} {withDefault('')(credit)} | ||
</span> | ||
</details> | ||
</figcaption> | ||
); | ||
} | ||
|
||
// ----- Exports ----- // | ||
|
||
export default ImageDetails; |
Oops, something went wrong.