Skip to content

Commit

Permalink
add CircularProgress & TextArea & DividerPanel
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreCrb committed Jan 29, 2020
1 parent 548c077 commit 1fc127c
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 25 deletions.
4 changes: 3 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export const COMPONENTS: ComponentType[] = [
"Spinner",
"CloseButton",
"Divider",
"Code"
"Code",
"TextArea",
"CircularProgress"
];

const App = () => (
Expand Down
6 changes: 6 additions & 0 deletions src/components/editor/ComponentPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import SpinnerPreview from "./previews/SpinnerPreview";
import CloseButtonPreview from "./previews/CloseButtonPreview";
import DividerPreview from "./previews/DividerPreview";
import CodePreview from "./previews/CodePreview";
import TextAreaPreview from "./previews/TextAreaPreview";
import CircularProgressPreview from "./previews/CircularProgressPreview";

const ComponentPreview: React.FC<{ component: IComponent }> = ({
component
Expand Down Expand Up @@ -57,6 +59,10 @@ const ComponentPreview: React.FC<{ component: IComponent }> = ({
return <DividerPreview component={component} />;
case "Code":
return <CodePreview component={component} />;
case "TextArea":
return <TextAreaPreview component={component} />;
case "CircularProgress":
return <CircularProgressPreview component={component} />;
default:
return null;
}
Expand Down
12 changes: 12 additions & 0 deletions src/components/editor/previews/CircularProgressPreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";
import { CircularProgress } from "@chakra-ui/core";
import { useInteractive } from "../../../hooks/useInteractive";

const CircularProgressPreview: React.FC<{ component: IComponent }> = ({
component
}) => {
const { props, ref } = useInteractive(component);
return <CircularProgress ref={ref} {...props} />;
};

export default CircularProgressPreview;
12 changes: 12 additions & 0 deletions src/components/editor/previews/TextAreaPreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";
import { Textarea } from "@chakra-ui/core";
import { useInteractive } from "../../../hooks/useInteractive";

const TextAreaPreview: React.FC<{ component: IComponent }> = ({
component
}) => {
const { props, ref } = useInteractive(component);
return <Textarea ref={ref} {...props} />;
};

export default TextAreaPreview;
3 changes: 0 additions & 3 deletions src/components/inspector/Inspector.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React, { ChangeEvent, FormEvent, useState } from "react";
import {
Select,
Text,
Button,
Divider,
Link,
InputGroup,
InputRightElement,
Expand All @@ -23,7 +21,6 @@ import DimensionPanel from "./panels/DimensionPanel";
import BorderPanel from "./panels/BorderPanel";
import FlexPanel from "./panels/FlexPanel";
import TextPanel from "./panels/TextPanel";
import docs from "../../models/doc";
import { IoIosFlash } from "react-icons/io";
import FormControl from "./controls/FormControl";
import AccordionContainer from "./AccordionContainer";
Expand Down
67 changes: 67 additions & 0 deletions src/components/inspector/panels/CircularProgressPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from "react";
import {
Input,
Slider,
SliderTrack,
SliderFilledTrack,
SliderThumb,
Switch
} from "@chakra-ui/core";
import FormControl from "../controls/FormControl";
import { useForm } from "../../../hooks/useForm";
import ColorsControl from "../controls/ColorsControl";

const CircularProgressPanel = () => {
const { values, setValueFromEvent, setValue } = useForm();

return (
<>
<FormControl label="Valeur">
<Input
size="sm"
value={values.value || "75"}
type="text"
name="value"
onChange={setValueFromEvent}
/>
</FormControl>
<FormControl label="Size">
<Input
size="sm"
value={values.size || "50px"}
type="text"
name="size"
onChange={setValueFromEvent}
/>
</FormControl>

<FormControl label="Thickness">
<Slider
onChange={value => setValue("thickness", value)}
min={0.1}
max={1}
step={0.1}
defaultValue={values.thickness}
>
<SliderTrack />
<SliderFilledTrack />
<SliderThumb />
</Slider>
</FormControl>

<ColorsControl label="Color" name="color" value={values.color} />

<FormControl label="Loading" htmlFor="isIndeterminate">
<Switch
name="isIndeterminate"
id="isIndeterminate"
size="sm"
isChecked={values.isIndeterminate || false}
onChange={() => setValue("isIndeterminate", !values.isIndeterminate)}
/>
</FormControl>
</>
);
};

export default CircularProgressPanel;
35 changes: 22 additions & 13 deletions src/components/inspector/panels/DividerPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,33 @@ import React from "react";
import { Select } from "@chakra-ui/core";
import FormControl from "../controls/FormControl";
import { useForm } from "../../../hooks/useForm";
import ColorsControl from "../controls/ColorsControl";

const DividerPanel = () => {
const { values, setValueFromEvent } = useForm();

return (
<FormControl label="Orientation" htmlFor="orientation">
<Select
name="orientation"
id="orientation"
size="sm"
value={values.orientation || "md"}
onChange={setValueFromEvent}
>
<option>horizontal</option>
<option>vertical</option>
<option>lg</option>
</Select>
</FormControl>
<>
<FormControl label="Orientation" htmlFor="orientation">
<Select
name="orientation"
id="orientation"
size="sm"
value={values.orientation || "horizontal"}
onChange={setValueFromEvent}
>
<option>horizontal</option>
<option>vertical</option>
</Select>
</FormControl>
<ColorsControl
withFullColor
label="Border color"
name="borderColor"
enableHues
value={values.borderColor}
/>
</>
);
};

Expand Down
4 changes: 4 additions & 0 deletions src/components/inspector/panels/Panels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import SpinnerPanel from "./SpinnerPanel";
import CloseButtonPanel from "./CloseButtonPanel";
import DividerPanel from "./DividerPanel";
import CodePanel from "./CodePanel";
import TextAreaPanel from "./TextAreaPanel";
import CircularProgressPanel from "./CircularProgressPanel";

const Panels: React.FC<{ component: IComponent }> = ({ component }) => {
const { type } = component;
Expand All @@ -39,6 +41,8 @@ const Panels: React.FC<{ component: IComponent }> = ({ component }) => {
{type === "Code" && <CodePanel />}
{type === "CloseButton" && <CloseButtonPanel />}
{type === "Divider" && <DividerPanel />}
{type === "TextArea" && <TextAreaPanel />}
{type === "CircularProgress" && <CircularProgressPanel />}
</>
);
};
Expand Down
28 changes: 20 additions & 8 deletions src/components/inspector/panels/ProgressPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import React from "react";
import { Switch, Select, Input } from "@chakra-ui/core";
import {
Switch,
Select,
Slider,
SliderTrack,
SliderFilledTrack,
SliderThumb
} from "@chakra-ui/core";
import ColorsControl from "../controls/ColorsControl";
import FormControl from "../controls/FormControl";
import { useForm } from "../../../hooks/useForm";
Expand All @@ -10,14 +17,19 @@ const ProgressPanel = () => {
return (
<>
<FormControl label="Valeur">
<Input
size="sm"
value={values.value || ""}
type="text"
name="value"
onChange={setValueFromEvent}
/>
<Slider
onChange={value => setValue("value", value)}
min={0}
max={100}
step={1}
defaultValue={values.value}
>
<SliderTrack />
<SliderFilledTrack />
<SliderThumb />
</Slider>
</FormControl>

<FormControl label="Has Stripe" htmlFor="hasStripe">
<Switch
name="hasStripe"
Expand Down
48 changes: 48 additions & 0 deletions src/components/inspector/panels/TextAreaPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from "react";
import { Input, Select } from "@chakra-ui/core";
import FormControl from "../controls/FormControl";
import { useForm } from "../../../hooks/useForm";
import SizeControl from "../controls/SizeControl";

const TextAreaPanel = () => {
const { values, setValueFromEvent } = useForm();

return (
<>
<FormControl label="Valeur">
<Input
size="sm"
value={values.value || ""}
type="text"
name="value"
onChange={setValueFromEvent}
/>
</FormControl>
<FormControl label="Placeholder">
<Input
size="sm"
value={values.placeholder || ""}
type="text"
name="placeholder"
onChange={setValueFromEvent}
/>
</FormControl>
<SizeControl name="size" label="Size" value={values.size} />
<FormControl label="Resize" htmlFor="resize">
<Select
name="resize"
id="size"
size="sm"
value={values.resize || ""}
onChange={setValueFromEvent}
>
<option>horizontal</option>
<option>vertical</option>
<option>none</option>
</Select>
</FormControl>
</>
);
};

export default TextAreaPanel;
2 changes: 2 additions & 0 deletions src/hooks/useDropComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const DEFAULT_PROPS: PreviewDefaultProps = {
Link: {},
Code: {},
Spinner: {},
TextArea: {},
CloseButton: {},
CircularProgress: {},
Checkbox: {
isChecked: true
},
Expand Down
4 changes: 4 additions & 0 deletions src/react-app-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type ComponentType =
| "Spinner"
| "CloseButton"
| "Divider"
| "TextArea"
| "CircularProgress"
| "Code";

interface IComponent {
Expand Down Expand Up @@ -61,4 +63,6 @@ type PreviewDefaultProps = {
CloseButton?: CloseButtonProps;
Divider?: any;
Code?: any;
TextArea?: any;
CircularProgress?: any;
};

0 comments on commit 1fc127c

Please sign in to comment.