-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(base): new preview components using Sanity UI (#2749)
- Loading branch information
Showing
26 changed files
with
905 additions
and
28 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 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
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
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
35 changes: 35 additions & 0 deletions
35
packages/@sanity/base/src/components/previews/blockImagePreview.styled.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,35 @@ | ||
import {Box} from '@sanity/ui' | ||
import styled from 'styled-components' | ||
|
||
export const MediaWrapper = styled(Box)` | ||
position: relative; | ||
flex: 1; | ||
img { | ||
display: block; | ||
width: 100%; | ||
height: auto; | ||
pointer-events: none; | ||
} | ||
svg { | ||
display: block; | ||
width: calc(2.5rem + 1px) !important; | ||
height: calc(2.5rem + 1px) !important; | ||
margin: 0.5rem; | ||
} | ||
` | ||
|
||
export const Root = styled(Box)` | ||
user-select: none; | ||
width: 100%; | ||
` | ||
|
||
export const MetadataWrapper = styled(Box)` | ||
user-select: none; | ||
width: 100%; | ||
${MediaWrapper} + &:empty { | ||
display: none; | ||
} | ||
` |
68 changes: 68 additions & 0 deletions
68
packages/@sanity/base/src/components/previews/blockImagePreview.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,68 @@ | ||
import React from 'react' | ||
import {Box, Flex, Heading, Text} from '@sanity/ui' | ||
import {getDevicePixelRatio} from 'use-device-pixel-ratio' | ||
import {MediaDimensions, PreviewProps} from './types' | ||
import {Root, MediaWrapper, MetadataWrapper} from './blockImagePreview.styled' | ||
|
||
const DEFAULT_MEDIA_DIMENSIONS: MediaDimensions = { | ||
width: 600, | ||
height: 600, | ||
fit: 'fillmax', | ||
dpr: getDevicePixelRatio(), | ||
} | ||
|
||
// @todo This is to make sure there is the correct amount of spacing below the dropdown in `BlockObjectPreview`. Remove when `BlockObjectPreview` is migrated to Sanity UI. | ||
const STYLE_HEADING = {marginBottom: '2px'} | ||
|
||
export const BlockImagePreview: React.FunctionComponent<PreviewProps<'block'>> = (props) => { | ||
const {title, subtitle, description, mediaDimensions, media, children, status} = props | ||
return ( | ||
<Root> | ||
{title && ( | ||
<Box as="header" paddingY={4} paddingX={[3, 4]} marginTop={1}> | ||
<Heading textOverflow="ellipsis" size={1} style={STYLE_HEADING}> | ||
{title} | ||
</Heading> | ||
</Box> | ||
)} | ||
|
||
<Flex justify="center" direction="column"> | ||
{media && ( | ||
<MediaWrapper> | ||
{typeof media === 'function' && | ||
media({ | ||
dimensions: mediaDimensions || DEFAULT_MEDIA_DIMENSIONS, | ||
layout: 'block', | ||
})} | ||
{typeof media === 'string' && <Box>{media}</Box>} | ||
{React.isValidElement(media) && media} | ||
</MediaWrapper> | ||
)} | ||
|
||
{subtitle || description || status || ( | ||
<MetadataWrapper paddingX={2} paddingY={2}> | ||
{subtitle && ( | ||
<Text muted size={1} textOverflow="ellipsis"> | ||
{subtitle} | ||
</Text> | ||
)} | ||
{description && ( | ||
<Box marginTop={2}> | ||
<Text muted size={1} textOverflow="ellipsis"> | ||
{typeof description === 'function' ? description({layout: 'block'}) : description} | ||
</Text> | ||
</Box> | ||
)} | ||
{status && ( | ||
<Box marginTop={2}> | ||
{typeof status === 'function' ? status({layout: 'block'}) : status} | ||
</Box> | ||
)} | ||
</MetadataWrapper> | ||
)} | ||
</Flex> | ||
|
||
{children && <Box>{children}</Box>} | ||
</Root> | ||
) | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/@sanity/base/src/components/previews/blockPreview.styled.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,35 @@ | ||
import {Box, Flex} from '@sanity/ui' | ||
import styled from 'styled-components' | ||
|
||
export const Root = styled(Box)` | ||
user-select: none; | ||
position: relative; | ||
width: 100%; | ||
` | ||
|
||
export const ContentWrapper = styled(Box)`` | ||
|
||
export const Header = styled(Flex)` | ||
flex-grow: 1; | ||
` | ||
|
||
export const MediaWrapper = styled(Box)` | ||
height: calc(2.5rem + 1px); | ||
width: calc(2.5rem + 1px); | ||
min-width: calc(2.5rem + 1px); | ||
position: relative; | ||
overflow: hidden; | ||
img { | ||
width: 100%; | ||
height: 100%; | ||
display: block; | ||
object-fit: cover; | ||
} | ||
svg { | ||
display: block; | ||
width: calc(2.5rem + 1px) !important; | ||
height: calc(2.5rem + 1px) !important; | ||
} | ||
` |
73 changes: 73 additions & 0 deletions
73
packages/@sanity/base/src/components/previews/blockPreview.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,73 @@ | ||
import React, {createElement} from 'react' | ||
import {Box, Text} from '@sanity/ui' | ||
import {getDevicePixelRatio} from 'use-device-pixel-ratio' | ||
import {MediaDimensions, PreviewProps} from './types' | ||
import {MediaWrapper, Root, Header, ContentWrapper} from './blockPreview.styled' | ||
|
||
const DEFAULT_MEDIA_DIMENSIONS: MediaDimensions = { | ||
width: 40, | ||
height: 40, | ||
aspect: 1, | ||
fit: 'crop', | ||
dpr: getDevicePixelRatio(), | ||
} | ||
|
||
export const BlockPreview: React.FunctionComponent<PreviewProps<'block'>> = (props) => { | ||
const { | ||
title, | ||
subtitle, | ||
description, | ||
mediaDimensions, | ||
media, | ||
status, | ||
children, | ||
extendedPreview, | ||
} = props | ||
return ( | ||
<Root> | ||
<Header padding={2} align="center"> | ||
{media && ( | ||
<MediaWrapper marginRight={3}> | ||
{typeof media === 'function' && | ||
media({ | ||
dimensions: mediaDimensions || DEFAULT_MEDIA_DIMENSIONS, | ||
layout: 'block', | ||
})} | ||
{typeof media === 'string' && <Box>{media}</Box>} | ||
{React.isValidElement(media) && media} | ||
</MediaWrapper> | ||
)} | ||
|
||
<ContentWrapper flex={1} paddingY={1}> | ||
<Text textOverflow="ellipsis" style={{color: 'inherit'}}> | ||
{title && typeof title === 'function' ? title({layout: 'block'}) : title} | ||
{!title && <>Untitled</>} | ||
</Text> | ||
|
||
{subtitle && ( | ||
<Box marginTop={1}> | ||
<Text muted size={1} textOverflow="ellipsis"> | ||
{typeof subtitle === 'function' ? subtitle({layout: 'block'}) : subtitle} | ||
</Text> | ||
</Box> | ||
)} | ||
{description && ( | ||
<Box marginTop={3}> | ||
<Text muted size={1} textOverflow="ellipsis"> | ||
{typeof description === 'function' ? description({layout: 'block'}) : description} | ||
</Text> | ||
</Box> | ||
)} | ||
</ContentWrapper> | ||
|
||
{status && ( | ||
<Box padding={3}>{typeof status === 'function' ? status({layout: 'block'}) : status}</Box> | ||
)} | ||
</Header> | ||
|
||
{children && <Box>{children}</Box>} | ||
|
||
{extendedPreview && <Box>{extendedPreview}</Box>} | ||
</Root> | ||
) | ||
} |
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
Oops, something went wrong.
3696728
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
test-studio – ./
test-studio-git-next.sanity.build
test-studio.sanity.build
3696728
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
perf-studio – ./
perf-studio-git-next.sanity.build
perf-studio.sanity.build