forked from prevwong/craft.js
-
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.
- Loading branch information
Showing
16 changed files
with
468 additions
and
269 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 |
---|---|---|
@@ -1,29 +1,57 @@ | ||
import React from "react"; | ||
import { Box, Typography, Grid, Button as MaterialButton } from "@material-ui/core"; | ||
import { | ||
Box, | ||
Typography, | ||
Grid, | ||
Button as MaterialButton | ||
} from "@material-ui/core"; | ||
import { useEditor } from "@craftjs/core"; | ||
import { Card } from "./user/Card"; | ||
import { Button } from "./user/Button"; | ||
import { Text } from "./user/Text"; | ||
|
||
export const Toolbox = () => { | ||
const { connectors, query } = useEditor(); | ||
const { connectors } = useEditor(); | ||
|
||
return ( | ||
<Box px={2} py={2}> | ||
<Grid container direction="column" alignItems="center" justify="center" spacing={1}> | ||
<Grid | ||
container | ||
direction="column" | ||
alignItems="center" | ||
justify="center" | ||
spacing={1} | ||
> | ||
<Box pb={2}> | ||
<Typography>Drag to add</Typography> | ||
</Box> | ||
<Grid container direction="column" item> | ||
<MaterialButton ref={ref=> connectors.create(ref, <Button text="Click me" size="small" />)} variant="contained">Button</MaterialButton> | ||
<MaterialButton | ||
ref={ref => | ||
connectors.create(ref, <Button text="Click me" size="small" />) | ||
} | ||
variant="contained" | ||
> | ||
Button | ||
</MaterialButton> | ||
</Grid> | ||
<Grid container direction="column" item> | ||
<MaterialButton ref={ref=> connectors.create(ref, <Text text="Hi world" />)} variant="contained">Text</MaterialButton> | ||
<MaterialButton | ||
ref={ref => connectors.create(ref, <Text text="Hi world" />)} | ||
variant="contained" | ||
> | ||
Text | ||
</MaterialButton> | ||
</Grid> | ||
<Grid container direction="column" item> | ||
<MaterialButton ref={ref=> connectors.create(ref, <Card />)} variant="contained">Card</MaterialButton> | ||
<MaterialButton | ||
ref={ref => connectors.create(ref, <Card />)} | ||
variant="contained" | ||
> | ||
Card | ||
</MaterialButton> | ||
</Grid> | ||
</Grid> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,62 @@ | ||
import { Box, Chip, Grid, Typography, Button as MaterialButton } from "@material-ui/core"; | ||
import React from "react"; | ||
import { | ||
Box, | ||
Chip, | ||
Grid, | ||
Typography, | ||
Button as MaterialButton | ||
} from "@material-ui/core"; | ||
import { useEditor } from "@craftjs/core"; | ||
|
||
export const SettingsPanel = () => { | ||
const { actions, selected } = useEditor((state, query) => { | ||
const currentNodeId = state.events.selected; | ||
let selected; | ||
|
||
if ( currentNodeId ) { | ||
if (currentNodeId) { | ||
selected = { | ||
id: currentNodeId, | ||
name: state.nodes[currentNodeId].data.name, | ||
settings: state.nodes[currentNodeId].related && state.nodes[currentNodeId].related.settings, | ||
settings: | ||
state.nodes[currentNodeId].related && | ||
state.nodes[currentNodeId].related.settings, | ||
isDeletable: query.node(currentNodeId).isDeletable() | ||
}; | ||
} | ||
|
||
return { | ||
selected | ||
} | ||
}; | ||
}); | ||
|
||
return selected ? ( | ||
return selected ? ( | ||
<Box bgcolor="rgba(0, 0, 0, 0.06)" mt={2} px={2} py={2}> | ||
<Grid container direction="column" spacing={0}> | ||
<Grid item> | ||
<Box pb={2}> | ||
<Grid container alignItems="center"> | ||
<Grid item xs><Typography variant="subtitle1">Selected</Typography></Grid> | ||
<Grid item><Chip size="small" color="primary" label={selected.name} /></Grid> | ||
<Grid item xs> | ||
<Typography variant="subtitle1">Selected</Typography> | ||
</Grid> | ||
<Grid item> | ||
<Chip size="small" color="primary" label={selected.name} /> | ||
</Grid> | ||
</Grid> | ||
</Box> | ||
</Grid> | ||
{ | ||
selected.settings && React.createElement(selected.settings) | ||
} | ||
{ | ||
selected.isDeletable ? ( | ||
<MaterialButton | ||
variant="contained" | ||
color="default" | ||
onClick={() => { | ||
actions.delete(selected.id); | ||
}} | ||
> | ||
Delete | ||
</MaterialButton> | ||
) : null | ||
} | ||
{selected.settings && React.createElement(selected.settings)} | ||
{selected.isDeletable ? ( | ||
<MaterialButton | ||
variant="contained" | ||
color="default" | ||
onClick={() => { | ||
actions.delete(selected.id); | ||
}} | ||
> | ||
Delete | ||
</MaterialButton> | ||
) : null} | ||
</Grid> | ||
</Box> | ||
) : null | ||
} | ||
|
||
) : null; | ||
}; |
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,33 +1,68 @@ | ||
import React from "react"; | ||
import { Box, Typography, Grid, Button as MaterialButton } from "@material-ui/core"; | ||
import { | ||
Box, | ||
Typography, | ||
Grid, | ||
Button as MaterialButton | ||
} from "@material-ui/core"; | ||
import { useEditor, Canvas } from "@craftjs/core"; | ||
import { Container } from "./user/Container"; | ||
import { Card } from "./user/Card"; | ||
import { Button } from "./user/Button"; | ||
import { Text } from "./user/Text"; | ||
|
||
export const Toolbox = () => { | ||
const { connectors, query } = useEditor(); | ||
const { connectors } = useEditor(); | ||
|
||
return ( | ||
<Box px={2} py={2}> | ||
<Grid container direction="column" alignItems="center" justify="center" spacing={1}> | ||
<Grid | ||
container | ||
direction="column" | ||
alignItems="center" | ||
justify="center" | ||
spacing={1} | ||
> | ||
<Box pb={2}> | ||
<Typography>Drag to add</Typography> | ||
</Box> | ||
<Grid container direction="column" item> | ||
<MaterialButton ref={ref=> connectors.create(ref, <Button text="Click me" size="small" />)} variant="contained">Button</MaterialButton> | ||
<MaterialButton | ||
ref={ref => | ||
connectors.create(ref, <Button text="Click me" size="small" />) | ||
} | ||
variant="contained" | ||
> | ||
Button | ||
</MaterialButton> | ||
</Grid> | ||
<Grid container direction="column" item> | ||
<MaterialButton ref={ref=> connectors.create(ref, <Text text="Hi world" />)} variant="contained">Text</MaterialButton> | ||
<MaterialButton | ||
ref={ref => connectors.create(ref, <Text text="Hi world" />)} | ||
variant="contained" | ||
> | ||
Text | ||
</MaterialButton> | ||
</Grid> | ||
<Grid container direction="column" item> | ||
<MaterialButton ref={ref=> connectors.create(ref, <Canvas is={Container} padding={20} />)} variant="contained">Container</MaterialButton> | ||
<MaterialButton | ||
ref={ref => | ||
connectors.create(ref, <Canvas is={Container} padding={20} />) | ||
} | ||
variant="contained" | ||
> | ||
Container | ||
</MaterialButton> | ||
</Grid> | ||
<Grid container direction="column" item> | ||
<MaterialButton ref={ref=> connectors.create(ref, <Card />)} variant="contained">Card</MaterialButton> | ||
<MaterialButton | ||
ref={ref => connectors.create(ref, <Card />)} | ||
variant="contained" | ||
> | ||
Card | ||
</MaterialButton> | ||
</Grid> | ||
</Grid> | ||
</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
Oops, something went wrong.