Skip to content

Commit

Permalink
example app: table, form, charts components (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
eshaan7 committed Oct 6, 2021
1 parent 691df5f commit 23fcc14
Show file tree
Hide file tree
Showing 6 changed files with 458 additions and 5 deletions.
26 changes: 22 additions & 4 deletions example/src/layouts/AppMain.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,24 @@ export default function AppMain() {
Title: () => <span>Buttons</span>,
Component: React.lazy(() => import("../sections/Buttons")),
},
{
key: "charts",
path: `${match.url}charts`,
Title: () => <span>Charts</span>,
Component: React.lazy(() => import("../sections/Charts")),
},
{
key: "containers",
path: `${match.url}containers`,
Title: () => <span>Containers</span>,
Component: React.lazy(() => import("../sections/Containers")),
},
{
key: "form",
path: `${match.url}form`,
Title: () => <span>Form</span>,
Component: React.lazy(() => import("../sections/Form")),
},
{
key: "icons",
path: `${match.url}icons`,
Expand All @@ -61,17 +73,23 @@ export default function AppMain() {
Title: () => <span>Navigation</span>,
Component: React.lazy(() => import("../sections/Nav")),
},
{
key: "table",
path: `${match.url}table`,
Title: () => <span>Table</span>,
Component: React.lazy(() => import("../sections/Table")),
},
{
key: "tabs",
path: `${match.url}tabs`,
Title: () => <span>Tabs</span>,
Component: React.lazy(() => import("../sections/Tabs")),
},
{
key: "texts",
path: `${match.url}texts`,
Title: () => <span>Texts</span>,
Component: React.lazy(() => import("../sections/Texts")),
key: "text",
path: `${match.url}text`,
Title: () => <span>Text</span>,
Component: React.lazy(() => import("../sections/Text")),
},
{
key: "time",
Expand Down
117 changes: 117 additions & 0 deletions example/src/sections/Charts.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import React from "react";
import { Bar, Area } from "recharts";

import { ContentSection, CustomComposedChart } from "@certego/certego-ui";

import ComponentAsExample from "./ComponentAsExample";

// constants
const chartData = [
{
name: "Page A",
uv: 4000,
pv: 2400,
amt: 2400,
},
{
name: "Page B",
uv: 3000,
pv: 1398,
amt: 2210,
},
{
name: "Page C",
uv: 2000,
pv: 9800,
amt: 2290,
},
{
name: "Page D",
uv: 2780,
pv: 3908,
amt: 2000,
},
{
name: "Page E",
uv: 1890,
pv: 4800,
amt: 2181,
},
{
name: "Page F",
uv: 2390,
pv: 3800,
amt: 2500,
},
{
name: "Page G",
uv: 3490,
pv: 4300,
amt: 2100,
},
];
const chartLabels = [
["uv", "#82ca9d"],
["pv", "#8884d8"],
["amt", "#abb000"],
];

// Example component
export default function Charts(props) {
return (
<ContentSection {...props}>
<ComponentAsExample
name="CustomComposedChart"
bodyNode={
<>
<h6 className="text-gradient">SimpleBarChart</h6>
<ContentSection className="bg-darker">
<CustomComposedChart xAxisDataKey="name" data={chartData}>
{chartLabels.slice(0, 2).map(([name, color]) => (
<Bar dataKey={name} fill={color} />
))}
</CustomComposedChart>
</ContentSection>
<h6 className="text-gradient">StackedBarChart</h6>
<ContentSection className="bg-darker">
<CustomComposedChart xAxisDataKey="name" data={chartData}>
{chartLabels.slice(0, 2).map(([name, color]) => (
<Bar stackId="a" dataKey={name} fill={color} />
))}
{chartLabels.slice(2, 3).map(([name, color]) => (
<Bar dataKey={name} fill={color} />
))}
</CustomComposedChart>
</ContentSection>
<h6 className="text-gradient">SimpleAreaChart</h6>
<ContentSection className="bg-darker">
<CustomComposedChart xAxisDataKey="name" data={chartData}>
{chartLabels.slice(0, 2).map(([name, color]) => (
<Area
type="monotone"
stackId="b"
dataKey={name}
stroke={color}
fill={color}
/>
))}
</CustomComposedChart>
</ContentSection>
</>
}
/>
<h6>
See{" "}
<a
href="https://recharts.org/en-US/examples"
target="_blank"
rel="noreferrer"
className="link-ul-primary"
>
Recharts examples
</a>{" "}
for more.
</h6>
</ContentSection>
);
}
178 changes: 178 additions & 0 deletions example/src/sections/Form.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import React from "react";
import { Col, Label, FormGroup } from "reactstrap";
import { CustomInput as FormInput, Submit } from "formstrap";
import { Form, Formik } from "formik";

import {
ContentSection,
Select,
AsyncSelect,
ButtonSelect,
TernaryCheckbox,
MultiSelectTextInput,
InputCheckBox,
CustomJsonInput,
TextBoxInput,
} from "@certego/certego-ui";

// constants
const asyncSelectProps = {
url: "https://raw.githubusercontent.com/samayo/country-json/master/src/country-by-name.json",
mapFn: (x) => ({ label: x["country"], value: x["country"] }),
};
const occupationChoices = [
{ label: "Software Engineer", value: "swe" },
{ label: "Super Shadowy Coder", value: "ssc" },
];
const genderChoices = ["Female", "Male", "Other"];
const initialValues = {
name: "",
country: "",
gender: genderChoices[0],
likeUI: true,
occupation: occupationChoices[0]["value"],
techTags: [],
acceptTerms: false,
additionalNote: "",
};

// Examples
export default function FormExample(props) {
const onFormSubmit = React.useCallback(async (values, formik) => {
try {
await alert(JSON.stringify(values));
} catch (e) {
// redundant catch
} finally {
formik.setSubmitting(false);
}
}, []);

return (
<ContentSection {...props}>
<Formik
initialValues={initialValues}
onSubmit={onFormSubmit}
validateOnMount
>
{(formik) => (
<Form className="content-section bg-body">
<FormGroup
row
className="d-flex-start-center flex-lg-row flex-md-column"
>
{/* FormInput */}
<Col lg={4}>
<Label className="required" htmlFor="name">
Name
</Label>
<FormInput
autoFocus
type="text"
name="name"
className="form-control"
/>
</Col>
{/* AsyncSelect */}
<Col lg={3}>
<Label className="required" htmlFor="country">
Country
</Label>
<AsyncSelect multi name="country" {...asyncSelectProps} />
</Col>
{/* ButtonSelect */}
<Col lg={3}>
<Label className="required" htmlFor="gender">
Gender
</Label>
<ButtonSelect
className="d-block"
name="gender"
value={formik.values.gender}
choices={genderChoices}
onChange={(ch) => formik.setFieldValue("gender", ch)}
/>
</Col>
</FormGroup>
<FormGroup
row
className="d-flex-start-start flex-lg-row flex-md-column"
>
{/* Select */}
<Col lg={3}>
<Label className="required" htmlFor="occupation">
Select Occupation
</Label>
<Select name="occupation" choices={occupationChoices} />
</Col>
{/* MultiSelectTextInput */}
<Col lg={6}>
<Label className="required" htmlFor="techTags">
Add some technologies you work with
</Label>
<MultiSelectTextInput
defaultElements={formik.values.techTags}
onElementsChange={(v) => formik.setFieldValue("techTags", v)}
/>
</Col>
</FormGroup>
<FormGroup
row
className="d-flex-start-start flex-lg-row flex-md-column"
>
{/* TernaryCheckbox */}
<Col md={6}>
<Label className="required" htmlFor="likeUI">
Do you like this UI ?
</Label>
<TernaryCheckbox
className="d-block"
undefLabel="Maybe"
value={formik.values.likeUI}
onChange={(ch) => formik.setFieldValue("likeUI", ch)}
/>
</Col>
</FormGroup>
<FormGroup row className="d-flex-start-start">
{/* TextBoxInput */}
<Col lg={6}>
<Label htmlFor="additionalNote">Additional Note</Label>
<TextBoxInput name="additionalNote" />
</Col>
</FormGroup>
<FormGroup row className="ml-1">
{/* InputCheckBox */}
<InputCheckBox
className="bg-body"
label="I Accept the terms and conditions"
name="acceptTerms"
valid={formik.values.acceptTerms}
/>
</FormGroup>
<FormGroup row className="d-flex-start-start">
{/* CustomJsonInput */}
<Col lg={6}>
<Label htmlFor="debugForm">Debug Form Values</Label>
<CustomJsonInput placeholder={formik.values} viewOnly />
</Col>
</FormGroup>
{/* Submit */}
<FormGroup row className="mt-5 d-flex-start-center">
<Submit
withSpinner
disabled={!(formik.isValid || formik.isSubmitting)}
color="primary"
outline
className="mx-auto"
size="md"
>
{!formik.isSubmitting && "Submit"}
</Submit>
</FormGroup>
</Form>
)}
</Formik>
<h6>Above example form shows usage of all components.</h6>
</ContentSection>
);
}
2 changes: 1 addition & 1 deletion example/src/sections/Lists.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from "react";

import {
ContentSection,
useAxiosComponentLoader,
InfiniteScrollList,
KvList,
useAxiosComponentLoader,
} from "@certego/certego-ui";

import ComponentAsExample from "./ComponentAsExample";
Expand Down
Loading

0 comments on commit 23fcc14

Please sign in to comment.