@conduction/components 2.1.5 → 2.1.7

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,8 @@
4
4
 
5
5
  - **Version 2.1 (breaking changes from 2.0.x)**
6
6
 
7
+ - 2.1.7: Add disabled placholders to all Select elements.
8
+ - 2.1.6: Add disabled state to CreateKeyValue component
7
9
  - 2.1.4 & 2.1.5: Remove IInputProps from CreateKeyValue to undo duplicate defaultValue prop
8
10
  - 2.1.3: Export IKeyValue from CreateKeyValue component.
9
11
  - 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
  };
@@ -6,16 +6,16 @@ import CreatableSelect from "react-select/creatable";
6
6
  import clsx from "clsx";
7
7
  export const SelectMultiple = ({ name, options, errors, control, validation, defaultValue, disabled, }) => {
8
8
  return (_jsx(Controller, { ...{ control, name, defaultValue }, rules: validation, render: ({ field: { onChange, value } }) => {
9
- return (_jsx(ReactSelect, { value: value ?? "", className: clsx(styles.select, errors[name] && styles.error), isMulti: true, isDisabled: disabled, ...{ options, onChange, errors }, menuPortalTarget: document.body, styles: { menuPortal: (base) => ({ ...base, zIndex: 100 }) } }));
9
+ return (_jsx(ReactSelect, { value: value ?? "", className: clsx(styles.select, errors[name] && styles.error), isMulti: true, isDisabled: disabled, ...{ options, onChange, errors }, menuPortalTarget: document.body, styles: { menuPortal: (base) => ({ ...base, zIndex: 100 }) }, placeholder: disabled ? "Disabled..." : "Select one or more options..." }));
10
10
  } }));
11
11
  };
12
12
  export const SelectCreate = ({ name, options, errors, control, validation, defaultValue, disabled, }) => {
13
13
  return (_jsx(Controller, { ...{ control, name, defaultValue }, rules: validation, render: ({ field: { onChange, value } }) => {
14
- return (_jsx(CreatableSelect, { value: value ?? "", placeholder: "Select existing or create new entries", className: clsx(styles.select, errors[name] && styles.error), isMulti: true, isDisabled: disabled, ...{ options, onChange, errors }, menuPortalTarget: document.body, styles: { menuPortal: (base) => ({ ...base, zIndex: 100 }) } }));
14
+ return (_jsx(CreatableSelect, { value: value ?? "", placeholder: disabled ? "Disabled..." : "Select or create one or multiple options...", className: clsx(styles.select, errors[name] && styles.error), isMulti: true, isDisabled: disabled, ...{ options, onChange, errors }, menuPortalTarget: document.body, styles: { menuPortal: (base) => ({ ...base, zIndex: 100 }) } }));
15
15
  } }));
16
16
  };
17
17
  export const SelectSingle = ({ name, options, errors, control, validation, isClearable, defaultValue, disabled, }) => {
18
18
  return (_jsx(Controller, { ...{ control, name, defaultValue }, rules: validation, render: ({ field: { onChange, value } }) => {
19
- return (_jsx(ReactSelect, { value: value ?? "", className: clsx(styles.select, errors[name] && styles.error), isDisabled: disabled, ...{ options, onChange, errors, isClearable }, menuPortalTarget: document.body, styles: { menuPortal: (base) => ({ ...base, zIndex: 100 }) } }));
19
+ return (_jsx(ReactSelect, { value: value ?? "", className: clsx(styles.select, errors[name] && styles.error), isDisabled: disabled, ...{ options, onChange, errors, isClearable }, menuPortalTarget: document.body, styles: { menuPortal: (base) => ({ ...base, zIndex: 100 }) }, placeholder: disabled ? "Disabled..." : "Select an option..." }));
20
20
  } }));
21
21
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@conduction/components",
3
- "version": "2.1.5",
3
+ "version": "2.1.7",
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>
@@ -38,6 +38,7 @@ export const SelectMultiple: React.FC<ISelectProps & IReactHookFormProps> = ({
38
38
  {...{ options, onChange, errors }}
39
39
  menuPortalTarget={document.body}
40
40
  styles={{ menuPortal: (base) => ({ ...base, zIndex: 100 }) }}
41
+ placeholder={disabled ? "Disabled..." : "Select one or more options..."}
41
42
  />
42
43
  );
43
44
  }}
@@ -62,7 +63,7 @@ export const SelectCreate: React.FC<ISelectProps & IReactHookFormProps> = ({
62
63
  return (
63
64
  <CreatableSelect
64
65
  value={value ?? ""}
65
- placeholder="Select existing or create new entries"
66
+ placeholder={disabled ? "Disabled..." : "Select or create one or multiple options..."}
66
67
  className={clsx(styles.select, errors[name] && styles.error)}
67
68
  isMulti
68
69
  isDisabled={disabled}
@@ -99,6 +100,7 @@ export const SelectSingle: React.FC<ISelectProps & IReactHookFormProps> = ({
99
100
  {...{ options, onChange, errors, isClearable }}
100
101
  menuPortalTarget={document.body}
101
102
  styles={{ menuPortal: (base) => ({ ...base, zIndex: 100 }) }}
103
+ placeholder={disabled ? "Disabled..." : "Select an option..."}
102
104
  />
103
105
  );
104
106
  }}