forked from premieroctet/openchakra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Stack & Flex components (premieroctet#4)
* add Stack & Flex components * add Tab & TabList & TabPanel & FormControl & Form Label... * Improve * update readme Co-authored-by: Baptiste Adrien <adrien.baptiste@gmail.com>
- Loading branch information
Showing
19 changed files
with
844 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import React from "react"; | ||
import { useInteractive } from "../../../hooks/useInteractive"; | ||
import { useDropComponent } from "../../../hooks/useDropComponent"; | ||
import { | ||
Box, | ||
Accordion, | ||
AccordionItem, | ||
AccordionHeader, | ||
AccordionPanel, | ||
AccordionIcon | ||
} from "@chakra-ui/core"; | ||
import ComponentPreview from "../ComponentPreview"; | ||
|
||
const acceptedTypes = [ | ||
"AccordionItem", | ||
"AccordionHeader", | ||
"AccordionPanel", | ||
"AccordionIcon" | ||
] as ComponentType[]; | ||
|
||
const AccordionPreview: React.FC<IPreviewProps> = ({ component }) => { | ||
const { props, ref } = useInteractive(component, true); | ||
const { drop, isOver } = useDropComponent(component.id, acceptedTypes); | ||
|
||
let boxProps: any = {}; | ||
|
||
if (isOver) { | ||
props.bg = "teal.50"; | ||
} | ||
|
||
return ( | ||
<Box ref={drop(ref)} {...boxProps}> | ||
<Accordion {...props}> | ||
{component.children.map((key: string) => ( | ||
<ComponentPreview componentName={key} /> | ||
))} | ||
</Accordion> | ||
</Box> | ||
); | ||
}; | ||
|
||
export const AccordionItemPreview = ({ component }: IPreviewProps) => { | ||
const { props, ref } = useInteractive(component, true); | ||
const { drop, isOver } = useDropComponent(component.id, acceptedTypes); | ||
|
||
if (isOver) { | ||
props.bg = "teal.50"; | ||
} | ||
|
||
return ( | ||
<AccordionItem ref={drop(ref)} {...props}> | ||
{component.children.map((key: string) => ( | ||
<ComponentPreview componentName={key} /> | ||
))} | ||
</AccordionItem> | ||
); | ||
}; | ||
|
||
export const AccordionHeaderPreview = ({ component }: IPreviewProps) => { | ||
const { props, ref } = useInteractive(component, true); | ||
const { drop, isOver } = useDropComponent(component.id, acceptedTypes); | ||
|
||
if (isOver) { | ||
props.bg = "teal.50"; | ||
} | ||
|
||
return ( | ||
<AccordionHeader ref={drop(ref)} {...props}> | ||
{component.children.map((key: string) => ( | ||
<ComponentPreview componentName={key} /> | ||
))} | ||
</AccordionHeader> | ||
); | ||
}; | ||
|
||
export const AccordionPanelPreview = ({ component }: IPreviewProps) => { | ||
const { props, ref } = useInteractive(component, true); | ||
const { drop, isOver } = useDropComponent(component.id); | ||
|
||
if (isOver) { | ||
props.bg = "teal.50"; | ||
} | ||
|
||
return ( | ||
<AccordionPanel ref={drop(ref)} {...props}> | ||
{component.children.map((key: string) => ( | ||
<ComponentPreview componentName={key} /> | ||
))} | ||
</AccordionPanel> | ||
); | ||
}; | ||
|
||
export const AccordionIconPreview = ({ component }: IPreviewProps) => { | ||
const { props, ref } = useInteractive(component); | ||
return <AccordionIcon ref={ref} {...props} />; | ||
}; | ||
|
||
export default AccordionPreview; |
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,25 @@ | ||
import React from "react"; | ||
import { Flex } from "@chakra-ui/core"; | ||
import { useDropComponent } from "../../../hooks/useDropComponent"; | ||
|
||
import { useInteractive } from "../../../hooks/useInteractive"; | ||
import ComponentPreview from "../ComponentPreview"; | ||
|
||
const FlexPreview: React.FC<{ component: IComponent }> = ({ component }) => { | ||
const { drop, isOver } = useDropComponent(component.id); | ||
const { props, ref } = useInteractive(component, true); | ||
|
||
if (isOver) { | ||
props.bg = "teal.50"; | ||
} | ||
|
||
return ( | ||
<Flex pos="relative" ref={drop(ref)} {...props}> | ||
{component.children.map((key: string) => ( | ||
<ComponentPreview componentName={key} /> | ||
))} | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default FlexPreview; |
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,54 @@ | ||
import React from "react"; | ||
import { useInteractive } from "../../../hooks/useInteractive"; | ||
import { useDropComponent } from "../../../hooks/useDropComponent"; | ||
import { | ||
FormControl, | ||
FormLabel, | ||
FormHelperText, | ||
FormErrorMessage | ||
} from "@chakra-ui/core"; | ||
import ComponentPreview from "../ComponentPreview"; | ||
|
||
const acceptedTypes = [ | ||
"FormLabel", | ||
"FormHelperText", | ||
"FormErrorMessage", | ||
"Input", | ||
"Select", | ||
"Text", | ||
"Image" | ||
] as ComponentType[]; | ||
|
||
const FormControlPreview: React.FC<IPreviewProps> = ({ component }) => { | ||
const { props, ref } = useInteractive(component, true); | ||
const { drop, isOver } = useDropComponent(component.id, acceptedTypes); | ||
|
||
if (isOver) { | ||
props.bg = "teal.50"; | ||
} | ||
|
||
return ( | ||
<FormControl ref={drop(ref)} {...props}> | ||
{component.children.map((key: string) => ( | ||
<ComponentPreview componentName={key} /> | ||
))} | ||
</FormControl> | ||
); | ||
}; | ||
|
||
export const FormLabelPreview = ({ component }: IPreviewProps) => { | ||
const { props, ref } = useInteractive(component); | ||
return <FormLabel ref={ref} {...props} />; | ||
}; | ||
|
||
export const FormHelperTextPreview = ({ component }: IPreviewProps) => { | ||
const { props, ref } = useInteractive(component); | ||
return <FormHelperText ref={ref} {...props} />; | ||
}; | ||
|
||
export const FormErrorMessagePreview = ({ component }: IPreviewProps) => { | ||
const { props, ref } = useInteractive(component); | ||
return <FormErrorMessage ref={ref} {...props} />; | ||
}; | ||
|
||
export default FormControlPreview; |
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,10 @@ | ||
import React from "react"; | ||
import { Input } from "@chakra-ui/core"; | ||
import { useInteractive } from "../../../hooks/useInteractive"; | ||
|
||
const InputPreview: React.FC<{ component: IComponent }> = ({ component }) => { | ||
const { props, ref } = useInteractive(component); | ||
return <Input ref={ref} {...props} />; | ||
}; | ||
|
||
export default InputPreview; |
Oops, something went wrong.