import * as React from "react"; import { range, get } from "lodash"; import styled from "styled-components"; import { Grid } from "@material-ui/core"; import { LiveFormFieldProps } from "../../LiveFormField/types"; import { LinearScaleFieldProps, LinearScaleDisplayType } from "../types"; import { EditorMode } from "../../../../Editor/types"; import { AttributeNames } from "@sc/modules/v2/CRUD/AttributeBuilder/types"; import { AttributeContainer } from "@sc/modules/v2/CRUD/AttributeBuilder"; import { ButtonSliderGroup } from "@sc/modules/v2/Properties/components/groups/"; /** * shows a list of numbered options */ const LinearScaleField: React.FC = (props) => { const { mode = EditorMode.LIVE, // data = [], displayType = LinearScaleDisplayType.RADIO, min = 1, max = 5, onChange = () => null, styles = { labelStyle: {}, descriptionStyle: {}, inputStyle: {}, containerStyle: {}, validationStyle: {}, iconStyle: {}, }, name, label, description, defaultValue, disabled, icon, columns = 12, 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); }; const { iconStyle = {}, descriptionStyle = {}, containerStyle = {}, inputStyle = {}, validationStyle = {}, labelStyle = {}, } = styles; return (
{mode === EditorMode.LIVE && (
{label &&
{label}
} {description &&
{description}
} {displayType === LinearScaleDisplayType.RADIO && ( {range(min, max + 1).map((itm, key) => (
{itm}
))}
)} {displayType === LinearScaleDisplayType.SLIDER && (
)}
)} {mode === EditorMode.EDITOR && (
Show as radio buttons Show as a slider
)}
); }; export default LinearScaleField;