@conduction/components 2.1.5 → 2.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  - **Version 2.1 (breaking changes from 2.0.x)**
6
6
 
7
+ - 2.1.6: Add disabled state to CreateKeyValue component
7
8
  - 2.1.4 & 2.1.5: Remove IInputProps from CreateKeyValue to undo duplicate defaultValue prop
8
9
  - 2.1.3: Export IKeyValue from CreateKeyValue component.
9
10
  - 2.1.2: REVERT 2.1.1 and 2.1.0.
@@ -8,6 +8,7 @@ interface CreateKeyValueProps {
8
8
  name: string;
9
9
  control: Control<FieldValues, any>;
10
10
  defaultValue?: IKeyValue[];
11
+ disabled?: boolean;
11
12
  }
12
13
  export interface IKeyValue {
13
14
  key: string;
@@ -4,12 +4,12 @@ import * as styles from "./CreateKeyValue.module.css";
4
4
  import { Controller } from "react-hook-form";
5
5
  import { Button } from "@gemeente-denhaag/components-react";
6
6
  import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@gemeente-denhaag/table";
7
- export const CreateKeyValue = ({ name, errors, control, validation, defaultValue, }) => {
7
+ export const CreateKeyValue = ({ name, errors, control, validation, defaultValue, disabled, }) => {
8
8
  return (_jsx(Controller, { ...{ control, name, errors }, rules: validation, render: ({ field: { onChange } }) => {
9
- return _jsx(KeyValueComponent, { handleChange: onChange, ...{ defaultValue, errors } });
9
+ return _jsx(KeyValueComponent, { handleChange: onChange, ...{ defaultValue, errors, disabled } });
10
10
  } }));
11
11
  };
12
- const KeyValueComponent = ({ defaultValue, handleChange }) => {
12
+ const KeyValueComponent = ({ defaultValue, handleChange, disabled }) => {
13
13
  const [currentKey, setCurrentKey] = React.useState("");
14
14
  const [currentValue, setCurrentValue] = React.useState("");
15
15
  const [keyValues, setKeyValues] = React.useState(defaultValue ?? []);
@@ -27,5 +27,5 @@ const KeyValueComponent = ({ defaultValue, handleChange }) => {
27
27
  React.useEffect(() => {
28
28
  handleChange(keyValues);
29
29
  }, [keyValues]);
30
- return (_jsxs("div", { className: styles.keyValue, children: [keyValues && (_jsxs(Table, { className: styles.table, children: [_jsx(TableHead, { children: _jsxs(TableRow, { children: [_jsx(TableHeader, { children: "Key" }), _jsx(TableHeader, { children: "Value" }), _jsx(TableHeader, {})] }) }), _jsx(TableBody, { children: keyValues.map((keyValue, idx) => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: keyValue.key }), _jsx(TableCell, { children: keyValue.value }), _jsx(TableCell, { className: styles.tdDelete, children: _jsx(Button, { onClick: () => setKeyValues(keyValues.filter((_keyValue) => _keyValue !== keyValue)), children: "Delete" }) })] }, `${keyValue}${idx}`))) })] })), _jsxs("div", { className: styles.form, children: [_jsx("input", { type: "text", placeholder: "Key", value: currentKey, ref: currentKeyRef, className: "denhaag-textfield__input", onChange: (e) => setCurrentKey(e.target.value) }), _jsx("input", { type: "text", placeholder: "Value", value: currentValue, ref: currentValueRef, className: "denhaag-textfield__input", onChange: (e) => setCurrentValue(e.target.value) }), _jsx(Button, { onClick: handleCreate, disabled: !currentKey || !currentValue, children: "Add" })] })] }));
30
+ return (_jsxs("div", { className: styles.keyValue, children: [keyValues && (_jsxs(Table, { className: styles.table, children: [_jsx(TableHead, { children: _jsxs(TableRow, { children: [_jsx(TableHeader, { children: "Key" }), _jsx(TableHeader, { children: "Value" }), _jsx(TableHeader, {})] }) }), _jsx(TableBody, { children: keyValues.map((keyValue, idx) => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: keyValue.key }), _jsx(TableCell, { children: keyValue.value }), _jsx(TableCell, { className: styles.tdDelete, children: _jsx(Button, { onClick: () => setKeyValues(keyValues.filter((_keyValue) => _keyValue !== keyValue)), children: "Delete" }) })] }, `${keyValue}${idx}`))) })] })), _jsxs("div", { className: styles.form, children: [_jsx("input", { type: "text", placeholder: "Key", value: currentKey, ref: currentKeyRef, className: "denhaag-textfield__input", onChange: (e) => setCurrentKey(e.target.value), ...{ disabled } }), _jsx("input", { type: "text", placeholder: "Value", value: currentValue, ref: currentValueRef, className: "denhaag-textfield__input", onChange: (e) => setCurrentValue(e.target.value), ...{ disabled } }), _jsx(Button, { onClick: handleCreate, disabled: !currentKey || !currentValue || disabled, children: "Add" })] })] }));
31
31
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@conduction/components",
3
- "version": "2.1.5",
3
+ "version": "2.1.6",
4
4
  "description": "React (Gatsby) components used within the Conduction Skeleton Application (and its implementations)",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -13,6 +13,7 @@ interface CreateKeyValueProps {
13
13
  name: string;
14
14
  control: Control<FieldValues, any>;
15
15
  defaultValue?: IKeyValue[];
16
+ disabled?: boolean;
16
17
  }
17
18
 
18
19
  export interface IKeyValue {
@@ -26,13 +27,14 @@ export const CreateKeyValue: React.FC<CreateKeyValueProps & IReactHookFormProps>
26
27
  control,
27
28
  validation,
28
29
  defaultValue,
30
+ disabled,
29
31
  }) => {
30
32
  return (
31
33
  <Controller
32
34
  {...{ control, name, errors }}
33
35
  rules={validation}
34
36
  render={({ field: { onChange } }) => {
35
- return <KeyValueComponent handleChange={onChange} {...{ defaultValue, errors }} />;
37
+ return <KeyValueComponent handleChange={onChange} {...{ defaultValue, errors, disabled }} />;
36
38
  }}
37
39
  />
38
40
  );
@@ -44,9 +46,10 @@ export const CreateKeyValue: React.FC<CreateKeyValueProps & IReactHookFormProps>
44
46
  interface CreateKeyValueComponentProps {
45
47
  defaultValue?: IKeyValue[];
46
48
  handleChange: (...event: any[]) => void;
49
+ disabled?: boolean;
47
50
  }
48
51
 
49
- const KeyValueComponent: React.FC<CreateKeyValueComponentProps> = ({ defaultValue, handleChange }) => {
52
+ const KeyValueComponent: React.FC<CreateKeyValueComponentProps> = ({ defaultValue, handleChange, disabled }) => {
50
53
  const [currentKey, setCurrentKey] = React.useState<string>("");
51
54
  const [currentValue, setCurrentValue] = React.useState<string>("");
52
55
  const [keyValues, setKeyValues] = React.useState<IKeyValue[]>(defaultValue ?? []);
@@ -106,6 +109,7 @@ const KeyValueComponent: React.FC<CreateKeyValueComponentProps> = ({ defaultValu
106
109
  ref={currentKeyRef}
107
110
  className="denhaag-textfield__input"
108
111
  onChange={(e) => setCurrentKey(e.target.value)}
112
+ {...{ disabled }}
109
113
  />
110
114
 
111
115
  <input
@@ -115,9 +119,10 @@ const KeyValueComponent: React.FC<CreateKeyValueComponentProps> = ({ defaultValu
115
119
  ref={currentValueRef}
116
120
  className="denhaag-textfield__input"
117
121
  onChange={(e) => setCurrentValue(e.target.value)}
122
+ {...{ disabled }}
118
123
  />
119
124
 
120
- <Button onClick={handleCreate} disabled={!currentKey || !currentValue}>
125
+ <Button onClick={handleCreate} disabled={!currentKey || !currentValue || disabled}>
121
126
  Add
122
127
  </Button>
123
128
  </div>