@commercetools-uikit/creatable-select-field 0.0.0-canary-2021830134526

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 commercetools GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,128 @@
1
+ <!-- THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -->
2
+ <!-- This file is created by the `yarn generate-readme` script. -->
3
+
4
+ # CreatableSelectField
5
+
6
+ ## Description
7
+
8
+ A controlled input component with validation states and a label getting a selection from the user, and where options can also be created by the user.
9
+
10
+ ## Installation
11
+
12
+ ```
13
+ yarn add @commercetools-uikit/creatable-select-field
14
+ ```
15
+
16
+ ```
17
+ npm --save install @commercetools-uikit/creatable-select-field
18
+ ```
19
+
20
+ Additionally install the peer dependencies (if not present)
21
+
22
+ ```
23
+ yarn add react
24
+ ```
25
+
26
+ ```
27
+ npm --save install react
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ```jsx
33
+ import CreatableSelectField from '@commercetools-uikit/creatable-select-field';
34
+
35
+ const Example = () => (
36
+ <CreatableSelectField
37
+ title="State"
38
+ value="ready"
39
+ options={[
40
+ { value: 'ready', label: 'Ready' },
41
+ { value: 'shipped', label: 'Shipped' },
42
+ ]}
43
+ onChange={(event) => alert(event.target.value)}
44
+ />
45
+ );
46
+
47
+ export default Example;
48
+ ```
49
+
50
+ ## Properties
51
+
52
+ | Props | Type | Required | Default | Description |
53
+ | ---------------------------------- | -------------------------------------------------------------------------------------------------- | :------: | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
54
+ | `id` | `string` | | | Used as HTML id property. An id is auto-generated when it is not specified. |
55
+ | `horizontalConstraint` | `enum`<br/>Possible values:<br/>`3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` | | `'scale'` | Horizontal size limit of the input fields. |
56
+ | `errors` | `object` | | | A map of errors. Error messages for known errors are rendered automatically.&#xA;<br />&#xA;Unknown errors will be forwarded to `renderError` |
57
+ | `errors.missing` | `bool` | | | |
58
+ | `renderError` | `func` | | | Called with custom errors. This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error.&#xA;<br />&#xA;Signature: `(key, error) => React.node` |
59
+ | `isRequired` | `bool` | | | Indicates if the value is required. Shows an the "required asterisk" if so. |
60
+ | `touched` | `custom` | | | Indicates whether the field was touched. Errors will only be shown when the field was touched. |
61
+ | `aria-label` | `string` | | | Aria label (for assistive tech) |
62
+ | `aria-labelledby` | `string` | | | HTML ID of an element that should be used as the label (for assistive tech) |
63
+ | `isAutofocussed` | `bool` | | | Focus the control when it is mounted |
64
+ | `backspaceRemovesValue` | `bool` | | | Remove the currently focused option when the user presses backspace |
65
+ | `components` | `objectOf(func)` | | | Map of components to overwrite the default ones, see [what components you can override](https://react-select.com/components) |
66
+ | `filterOption` | `func` | | | Custom method to filter whether an option should be displayed in the menu |
67
+ | `containerId` | `string` | | | The id to set on the SelectContainer component |
68
+ | `isClearable` | `bool` | | | Is the select value clearable |
69
+ | `isDisabled` | `bool` | | | Is the select disabled |
70
+ | `isReadOnly` | `bool` | | | Is the select read-only |
71
+ | `isOptionDisabled` | `func` | | | Override the built-in logic to detect whether an option is disabled |
72
+ | `isMulti` | `bool` | | | Support multiple selected options |
73
+ | `isSearchable` | `bool` | | | Whether to enable search functionality |
74
+ | `hasWarning` | `bool` | | | |
75
+ | `maxMenuHeight` | `number` | | | Maximum height of the menu before scrolling |
76
+ | `menuPortalTarget` | `SafeHTMLElement` | | | Dom element to portal the select menu to |
77
+ | `menuPortalZIndex` | `number` | | | z-index value for the menu portal |
78
+ | `menuShouldBlockScroll` | `bool` | | | whether the menu should block scroll while open |
79
+ | `name` | `string` | | | Name of the HTML Input (optional - without this, no input will be rendered) |
80
+ | `noOptionsMessage` | `func` | | | Can be used to render a custom value when there are no options (either because of no search results, or all options have been used, or there were none in the first place).&#xA;<br/>&#xA;Gets called with `{ inputValue: String }`. `inputValue` will be an empty string when no search text is present.&#xA;<br />&#xA;Signature: `({ inputValue }) => string` |
81
+ | `onBlur` | `func` | | | Handle blur events on the control |
82
+ | `onChange` | `func` | | | Called with a fake event when value changes.&#xA;<br />&#xA;The event's `target.name` will be the name supplied in props. The event's `target.value` will hold the value. The value will be the selected option, or an array of options in case `isMulti` is `true`.&#xA;<br />&#xA;Signature: `(event) => void` |
83
+ | `onFocus` | `func` | | | Handle focus events on the control |
84
+ | `onInputChange` | `func` | | | Handle change events on the input |
85
+ | `options` | `array` | | | Array of options that populate the select menu |
86
+ | `options[]<shape>` | `object` | | | |
87
+ | `options[]<shape>.value` | `string` | ✅ | | |
88
+ | `options[]<shape>.options` | `array` | | | |
89
+ | `options[]<shape>.options[].value` | `string` | ✅ | | |
90
+ | `placeholder` | `string` | | | Placeholder text for the select value |
91
+ | `tabIndex` | `string` | | | Sets the tabIndex attribute on the input |
92
+ | `tabSelectsValue` | `bool` | | | Select the currently focused option when the user presses tab |
93
+ | `value` | `custom` | | | The value of the select; reflected by the selected option |
94
+ | `showOptionGroupDivider` | `bool` | | | |
95
+ | `allowCreateWhileLoading` | `bool` | | | Allow options to be created while the isLoading prop is true. Useful to prevent the "create new ..." option being displayed while async results are still being loaded. |
96
+ | `formatCreateLabel` | `func` | | | Gets the label for the "create new ..." option in the menu. Is given the current input value. |
97
+ | `isValidNewOption` | `func` | | | Determines whether the "create new ..." option should be displayed based on the current input value, select value and options array. |
98
+ | `getNewOptionData` | `func` | | | Returns the data for the new option when it is created. Used to display the value, and is passed to onChange. |
99
+ | `onCreateOption` | `func` | | | If provided, this will be called with the input value when a new option is created, and onChange will not be called. Use this when you need more control over what happens when new options are created. |
100
+ | `createOptionPosition` | `string` | | | Sets the position of the createOption element in your options list. |
101
+ | `title` | `<string, node>` | ✅ | | Title of the label |
102
+ | `hint` | `custom` | | | Hint for the label. Provides a supplementary but important information regarding the behaviour of the input (e.g warn about uniqueness of a field, when it can only be set once), whereas `description` can describe it in more depth. Can also receive a `hintIcon`. |
103
+ | `description` | `<string, node>` | | | Provides a description for the title. |
104
+ | `onInfoButtonClick` | `func` | | | Function called when info button is pressed.&#xA;<br />&#xA;Info button will only be visible when this prop is passed.&#xA;<br />&#xA;Signature: `(event) => void` |
105
+ | `hintIcon` | `node` | | | Icon to be displayed beside the hint text.&#xA;<br />&#xA;Will only get rendered when `hint` is passed as well. |
106
+ | `badge` | `node` | | | Badge to be displayed beside the label.&#xA;<br />&#xA;Might be used to display additional information about the content of the field (E.g verified email) |
107
+ | `iconLeft` | `node` | | | Icon to display on the left of the placeholder text and selected value. Has no effect when isMulti is enabled. |
108
+
109
+ ## `data-*` props
110
+
111
+ The component further forwards all `data-` attributes to the underlying `CreatableSelectInput` component.
112
+
113
+ This input is built on top of [`react-select`](https://github.com/JedWatson/react-select) v2.
114
+ It supports mostly same properties as `react-select`. Behaviour for some props was changed, and support for others was dropped.
115
+
116
+ In case you need one of the currently excluded props, feel free to open a PR adding them.
117
+
118
+ ## `errors`
119
+
120
+ This object is a key-value map. The `renderError` prop will be called for each entry with the key and the value. The return value will be rendered inside an `ErrorMessage` component underneath the input.
121
+
122
+ The `CreatableSelectField` supports some errors out of the box. Return `undefined` from `renderError` for these and the default errors will be shown instead. This prevents consumers from having to reimplement the same error messages for known errors while still keeping the flexibility of showing custom error messages for them.
123
+
124
+ When the `key` is known, and when the value is truthy, and when `renderError` returned `undefined` for that error entry, then the `CreatableSelectField` will render an appropriate error automatically.
125
+
126
+ Known error keys are:
127
+
128
+ - `missing`: tells the user that this field is required