-
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.
refactor(form-builder): migrate Details component to Sanity UI
- Loading branch information
Showing
6 changed files
with
82 additions
and
124 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import {ToggleArrowRightIcon} from '@sanity/icons' | ||
import {Box, Flex, Text} from '@sanity/ui' | ||
import React, {useCallback, useEffect, useState} from 'react' | ||
import styled from 'styled-components' | ||
|
||
interface DetailsProps { | ||
children?: React.ReactNode | ||
margin?: number | number[] | ||
marginX?: number | number[] | ||
marginY?: number | number[] | ||
marginTop?: number | number[] | ||
marginRight?: number | number[] | ||
marginBottom?: number | number[] | ||
marginLeft?: number | number[] | ||
open?: boolean | ||
title?: React.ReactNode | ||
} | ||
|
||
const HeaderButton = styled.button` | ||
display: block; | ||
-webkit-font-smoothing: inherit; | ||
appearance: none; | ||
font: inherit; | ||
background: none; | ||
width: 100%; | ||
text-align: left; | ||
border: 0; | ||
margin: 0; | ||
padding: 0; | ||
outline: none; | ||
` | ||
|
||
const Header = styled(Flex)` | ||
cursor: default; | ||
` | ||
|
||
const IconBox = styled(Box)` | ||
& > div > svg { | ||
transform: rotate(0); | ||
transition: transform 100ms; | ||
} | ||
&[data-open] > div > svg { | ||
transform: rotate(90deg); | ||
} | ||
` | ||
|
||
export function Details(props: DetailsProps) { | ||
const {children, open: openProp, title = 'Details', ...restProps} = props | ||
const [open, setOpen] = useState(openProp || false) | ||
|
||
const handleToggle = useCallback(() => setOpen((v) => !v), []) | ||
|
||
useEffect(() => setOpen(openProp || false), [openProp]) | ||
|
||
return ( | ||
<Box {...restProps}> | ||
<HeaderButton type="button" onClick={handleToggle}> | ||
<Header align="center"> | ||
<IconBox data-open={open ? '' : undefined}> | ||
<Text size={1}> | ||
<ToggleArrowRightIcon /> | ||
</Text> | ||
</IconBox> | ||
|
||
<Box flex={1} marginLeft={1}> | ||
<Text size={1} weight="medium"> | ||
{title} | ||
</Text> | ||
</Box> | ||
</Header> | ||
</HeaderButton> | ||
|
||
<Box hidden={!open} marginTop={3}> | ||
{children} | ||
</Box> | ||
</Box> | ||
) | ||
} |
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
2 changes: 1 addition & 1 deletion
2
packages/@sanity/form-builder/src/inputs/ObjectInput/UnknownFields.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
71 changes: 0 additions & 71 deletions
71
packages/@sanity/form-builder/src/inputs/common/Details.css
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
packages/@sanity/form-builder/src/inputs/common/Details.tsx
This file was deleted.
Oops, something went wrong.