diff --git a/src/components/Dashboard/common/ArrayDisplay.jsx b/src/components/Dashboard/common/ArrayDisplay.jsx new file mode 100644 index 0000000..20f1e6b --- /dev/null +++ b/src/components/Dashboard/common/ArrayDisplay.jsx @@ -0,0 +1,30 @@ +import PropTypes from 'prop-types' +import { Flex, Tag, Typography } from 'antd' + +const { Text } = Typography + +const ArrayDisplay = ({ value, prefix, suffix }) => { + if (!Array.isArray(value) || value.length === 0) { + return n/a + } + + return ( + + {value.map((item, index) => ( + + {prefix} + {item} + {suffix} + + ))} + + ) +} + +ArrayDisplay.propTypes = { + value: PropTypes.array, + prefix: PropTypes.node, + suffix: PropTypes.node +} + +export default ArrayDisplay diff --git a/src/components/Dashboard/common/ArrayInput.jsx b/src/components/Dashboard/common/ArrayInput.jsx new file mode 100644 index 0000000..0be4e15 --- /dev/null +++ b/src/components/Dashboard/common/ArrayInput.jsx @@ -0,0 +1,83 @@ +import PropTypes from 'prop-types' +import { Button, Flex, Input, InputNumber } from 'antd' + +const ArrayInput = ({ + value = [], + onChange, + disabled = false, + numeric = false, + min, + max, + step, + placeholder +}) => { + const values = Array.isArray(value) ? value : [] + + const updateValue = (index, nextValue) => { + const nextValues = [...values] + nextValues[index] = nextValue + onChange?.(nextValues) + } + + const removeValue = (index) => { + onChange?.(values.filter((_, valueIndex) => valueIndex !== index)) + } + + return ( + + {values.map((item, index) => ( + + {numeric ? ( + updateValue(index, nextValue)} + min={min} + max={max} + step={step} + placeholder={placeholder} + disabled={disabled} + style={{ flex: 1 }} + /> + ) : ( + updateValue(index, event.target.value)} + placeholder={placeholder} + disabled={disabled} + style={{ flex: 1 }} + /> + )} + + + ))} + + + ) +} + +ArrayInput.propTypes = { + value: PropTypes.array, + onChange: PropTypes.func, + disabled: PropTypes.bool, + numeric: PropTypes.bool, + min: PropTypes.number, + max: PropTypes.number, + step: PropTypes.number, + placeholder: PropTypes.string +} + +export default ArrayInput