Skip to content

Commit

Permalink
Improvements (premieroctet#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlenclos authored Feb 11, 2020
1 parent 23cb2a4 commit 53f7f89
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/components/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const Editor: React.FC = () => {
<Text maxWidth="md" color="gray.400" fontSize="xl" textAlign="center">
Drag some component to start coding without code! Or load a{' '}
<Link
onClick={() => {
onClick={(e: React.MouseEvent) => {
e.stopPropagation()
dispatch.components.loadDemo()
}}
textDecoration="underline"
Expand Down
9 changes: 4 additions & 5 deletions src/components/editor/previews/AccordionPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import {
AccordionPanel,
} from '@chakra-ui/core'
import ComponentPreview from '../ComponentPreview'
import { COMPONENTS } from '../../../utils/editor'
import { COMPONENTS, AccordionWhitelist } from '../../../utils/editor'

const acceptedTypes: ComponentType[] = ['AccordionItem']
const acceptedItemTypes: ComponentType[] = ['AccordionHeader', 'AccordionPanel']

const AccordionPreview: React.FC<IPreviewProps> = ({ component }) => {
const { props, ref } = useInteractive(component, true)
Expand All @@ -37,7 +36,7 @@ const AccordionPreview: React.FC<IPreviewProps> = ({ component }) => {

export const AccordionHeaderPreview = ({ component }: IPreviewProps) => {
const { props, ref } = useInteractive(component, true)
const { drop, isOver } = useDropComponent(component.id, COMPONENTS)
const { drop, isOver } = useDropComponent(component.id, AccordionWhitelist)

if (isOver) {
props.bg = 'teal.50'
Expand All @@ -54,7 +53,7 @@ export const AccordionHeaderPreview = ({ component }: IPreviewProps) => {

export const AccordionItemPreview = ({ component }: IPreviewProps) => {
const { props, ref } = useInteractive(component, true)
const { drop, isOver } = useDropComponent(component.id, acceptedItemTypes)
const { drop, isOver } = useDropComponent(component.id, AccordionWhitelist)

let boxProps: any = {}

Expand All @@ -75,7 +74,7 @@ export const AccordionItemPreview = ({ component }: IPreviewProps) => {

export const AccordionPanelPreview = ({ component }: IPreviewProps) => {
const { props, ref } = useInteractive(component, true)
const { drop, isOver } = useDropComponent(component.id, COMPONENTS)
const { drop, isOver } = useDropComponent(component.id, AccordionWhitelist)

let boxProps: any = {}

Expand Down
20 changes: 10 additions & 10 deletions src/components/inspector/AccordionContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React, { ReactNode, memo } from "react";
import React, { ReactNode, memo } from 'react'
import {
AccordionItem,
AccordionHeader,
AccordionIcon,
AccordionPanel,
Box,
AccordionItemProps
} from "@chakra-ui/core";
AccordionItemProps,
} from '@chakra-ui/core'

const AccordionContainer: React.FC<{
title: ReactNode;
defaultIsOpen?: boolean;
children: ReactNode;
} & AccordionItemProps> = ({ title, children, defaultIsOpen }) => {
title: ReactNode
defaultIsOpen?: boolean
children: ReactNode
} & AccordionItemProps> = ({ title, children, defaultIsOpen = true }) => {
return (
<AccordionItem defaultIsOpen={defaultIsOpen}>
<AccordionHeader zIndex={2} px={3} py={2} fontSize="sm">
Expand All @@ -25,7 +25,7 @@ const AccordionContainer: React.FC<{
{children}
</AccordionPanel>
</AccordionItem>
);
};
)
}

export default memo(AccordionContainer);
export default memo(AccordionContainer)
4 changes: 4 additions & 0 deletions src/core/models/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const components = createModel({
loadDemo(state: ComponentsState): ComponentsState {
return {
...state,
selectedId: 'comp-root',
components: airbnbCard as any,
}
},
Expand Down Expand Up @@ -197,6 +198,7 @@ const components = createModel({

return {
...state,
selectedId: id,
components: {
...state.components,
[payload.parentName]: {
Expand All @@ -218,8 +220,10 @@ const components = createModel({
state: ComponentsState,
payload: { components: IComponents; root: string; parent: string },
): ComponentsState {
console.log(payload)
return {
...state,
selectedId: payload.root,
components: {
...state.components,
[payload.parent]: {
Expand Down
10 changes: 5 additions & 5 deletions src/theme/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ export const airbnbCard = {
id: 'root',
parent: 'root',
type: 'box',
children: ['comp-1580479567'],
children: ['comp-root'],
props: {},
},
'comp-1580479567': {
id: 'comp-1580479567',
'comp-root': {
id: 'comp-root',
props: {
bg: '#ffffff',
rounded: 'lg',
Expand All @@ -25,7 +25,7 @@ export const airbnbCard = {
props: {},
children: ['comp-1580479588'],
type: 'Box',
parent: 'comp-1580479567',
parent: 'comp-root',
},
'comp-1580479588': {
id: 'comp-1580479588',
Expand Down Expand Up @@ -55,7 +55,7 @@ export const airbnbCard = {
'comp-1580479811',
],
type: 'Box',
parent: 'comp-1580479567',
parent: 'comp-root',
},
'comp-1580479631': {
id: 'comp-1580479631',
Expand Down
10 changes: 9 additions & 1 deletion src/utils/editor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
export const COMPONENTS: ComponentType[] = [
const ALERT_COMPONENTS: ComponentType[] = [
'Alert',
'AlertDescription',
'AlertIcon',
'AlertTitle',
]

export const COMPONENTS: ComponentType[] = [
...ALERT_COMPONENTS,
'Avatar',
'AvatarBadge',
'AvatarGroup',
Expand Down Expand Up @@ -63,6 +67,10 @@ export const COMPONENTS: ComponentType[] = [
'InputGroupMeta',
]

export const AccordionWhitelist: ComponentType[] = COMPONENTS.filter(
name => !ALERT_COMPONENTS.includes(name),
)

export const rootComponents = COMPONENTS
// Remove specific components
.filter(
Expand Down

0 comments on commit 53f7f89

Please sign in to comment.