import * as React from "react"; import styled from "styled-components"; import { get } from "lodash"; import { Grid } from "@material-ui/core"; import { CheckboxesProps, IListItem } from "../types"; import { EditorMode } from "../../../../Editor/types"; import { AttributeNames } from "@sc/modules/v2/CRUD/AttributeBuilder/types"; import { LiveFormFieldProps } from "../../LiveFormField/types"; import AttributeContainer from "@sc/modules/v2/CRUD/AttributeBuilder/AttributeContainer"; import SortableList from "@sc/modules/v2/CRUD/SortableList"; const CheckboxItem: React.FC = ({ id, label, key }) => { const [value, setValue] = React.useState(label); return (
{/* {label} ({id}) */} setValue(e.target.value)} />
); }; /** * A component that shows a LIVE list of checkboxes or tools for configuring the group of checkboxes look, feel, and behavior */ const Checkboxes: React.FC = (props) => { const { mode = EditorMode.LIVE, data = [], styles = { labelStyle: {}, descriptionStyle: {}, inputStyle: {}, containerStyle: {}, validationStyle: {}, iconStyle: {}, }, name, label, description, defaultValue, disabled, icon, columns = 12, onChange = () => null, attributeContainerDataSettings = {}, } = props; /** * Deals with any changes that comes from the various attributes that are loaded * * • Converts to LiveFormFieldProps shape * • Triggers (and passes along the mutated LiveFormFieldProps payload to) the onChange event * @params */ const handleChange = (data: LiveFormFieldProps): void => { onChange(data); // <-- why does it need "mode" seeing as how it is called by a mode specific component (e.g. LiveFormField and EditFormField) }; const { iconStyle = {}, descriptionStyle = {}, containerStyle = {}, inputStyle = {}, validationStyle = {}, labelStyle = {}, } = styles; return (
{mode === EditorMode.LIVE && (
{label &&
{label}
} {description &&
{description}
} {data.map(({ id, label }) => (
handleChange({ checked: e.checked, id })} style={{ marginRight: 10 }} /> {label}
))}
)} {mode === EditorMode.EDITOR && (
} // onAdd={() => setData([...data, { id: "5", firstName: "Crimson" }])} // onEdit={() => console.log("Edit Button Clicked")} // onChange={(updatedData) => setData(updatedData)} // onDelete={(payload, updatedData) => setData(updatedData)} canDragAndDrop // showDragHandle={false} />
)}
); }; export default Checkboxes;