-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: add contentful section * conditionally show section * finetune hover/dragging interactions * fix: prettify
- Loading branch information
1 parent
e09d8c9
commit 5517c4d
Showing
11 changed files
with
425 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Flex } from '@contentful/f36-core' | ||
import tokens from '@contentful/f36-tokens' | ||
import { css, cx } from '@emotion/css' | ||
import React from 'react' | ||
import { useInteraction } from '../hooks' | ||
|
||
const styles = { | ||
defaultStyles: css({ | ||
minHeight: '200px', | ||
overflow: 'scroll', | ||
flexWrap: 'wrap', | ||
justifyContent: 'center', | ||
}), | ||
lineHorizontal: css({ | ||
margin: '10px', | ||
height: '0px', | ||
borderTop: `3px solid ${tokens.blue500}`, | ||
}), | ||
lineVertical: css({ | ||
width: '0px', | ||
margin: '10px', | ||
borderLeft: `3px solid ${tokens.blue500}`, | ||
}), | ||
} | ||
|
||
interface StyleProps { | ||
margin: string | ||
padding: string | ||
backgroundColor: string | ||
width: string | ||
height: string | ||
flexDirection: 'row' | 'column' | ||
border: string | ||
gap: string | ||
} | ||
|
||
interface ContentfulSectionProps extends StyleProps { | ||
onClick: () => void | ||
isDragging: boolean | ||
children: React.ReactNode | ||
className?: string | ||
} | ||
export const ContentfulSection = ({ | ||
flexDirection, | ||
margin, | ||
padding, | ||
backgroundColor, | ||
width, | ||
height, | ||
border, | ||
gap, | ||
isDragging, | ||
className, | ||
...props | ||
}: ContentfulSectionProps) => { | ||
const { isMouseOver, onMouseOver, onMouseLeave } = useInteraction() | ||
|
||
console.log({ margin, padding, backgroundColor, width, height, border, gap }) | ||
|
||
const styleOverrides = css({ margin, padding, backgroundColor, width, height, border, gap }) | ||
|
||
const lineStyles = flexDirection === 'row' ? styles.lineVertical : styles.lineHorizontal | ||
|
||
return ( | ||
<Flex | ||
flexDirection={flexDirection} | ||
onMouseOver={onMouseOver} | ||
onMouseLeave={onMouseLeave} | ||
className={cx(styles.defaultStyles, className, styleOverrides)} | ||
{...props}> | ||
{props.children} | ||
{isDragging && isMouseOver && <div key="lineIndicator" className={lineStyles}></div>} | ||
</Flex> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export const CONTENTFUL_WEB_APP_ORIGIN = 'https://app.contentful.com' | ||
|
||
export const CONTENTFUL_SECTION_ID = 'contentful-section' |
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,65 @@ | ||
import { useComponents } from './useComponents' | ||
import { ContentfulSection } from '../blocks/ContentfulSection' | ||
import { CONTENTFUL_SECTION_ID } from '../constants' | ||
import { useEffect } from 'react' | ||
|
||
export const useContentfulSection = () => { | ||
const { defineComponent } = useComponents() | ||
useEffect(() => { | ||
defineComponent(ContentfulSection, { | ||
id: CONTENTFUL_SECTION_ID, | ||
name: 'Contentful Section', | ||
variables: { | ||
margin: { | ||
type: 'Text', | ||
group: 'style', | ||
description: 'The margin of the section', | ||
defaultValue: '0', | ||
}, | ||
padding: { | ||
type: 'Text', | ||
group: 'style', | ||
description: 'The padding of the section', | ||
defaultValue: '0', | ||
}, | ||
backgroundColor: { | ||
type: 'Text', | ||
group: 'style', | ||
description: 'The background color of the section', | ||
defaultValue: 'transparent', | ||
}, | ||
width: { | ||
type: 'Text', | ||
group: 'style', | ||
description: 'The width of the section', | ||
defaultValue: '100%', | ||
}, | ||
height: { | ||
type: 'Text', | ||
group: 'style', | ||
description: 'The height of the section', | ||
defaultValue: 'auto', | ||
}, | ||
flexDirection: { | ||
type: 'Text', | ||
group: 'style', | ||
description: 'The orientation of the section', | ||
defaultValue: 'row', | ||
}, | ||
border: { | ||
type: 'Text', | ||
group: 'style', | ||
description: 'The border of the section', | ||
defaultValue: '0', | ||
}, | ||
gap: { | ||
type: 'Text', | ||
group: 'style', | ||
description: 'The spacing between the elements of the section', | ||
defaultValue: '0px', | ||
}, | ||
}, | ||
children: true, | ||
}) | ||
}, []) | ||
} |
Oops, something went wrong.