@khanacademy/wonder-blocks-search-field 1.0.0 → 1.0.3
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/CHANGELOG.md +24 -2
- package/dist/es/index.js +24 -38
- package/dist/index.js +103 -558
- package/package.json +6 -6
- package/src/components/__docs__/search-field.stories.js +1 -3
- package/src/components/__tests__/search-field.test.js +77 -13
- package/src/components/search-field.js +97 -73
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,32 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-search-field
|
|
2
2
|
|
|
3
|
+
## 1.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @khanacademy/wonder-blocks-core@4.3.1
|
|
8
|
+
- @khanacademy/wonder-blocks-icon@1.2.27
|
|
9
|
+
- @khanacademy/wonder-blocks-icon-button@3.4.6
|
|
10
|
+
- @khanacademy/wonder-blocks-typography@1.1.31
|
|
11
|
+
|
|
12
|
+
## 1.0.2
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 9ecc853d: Wrap the field in a UniqueIDProvider
|
|
17
|
+
|
|
18
|
+
## 1.0.1
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- 9f8ca907: Added forwardRef so it can be used by dropdown
|
|
23
|
+
|
|
3
24
|
## 1.0.0
|
|
25
|
+
|
|
4
26
|
### Major Changes
|
|
5
27
|
|
|
6
|
-
-
|
|
28
|
+
- 2d9198ff: Create SearchField component
|
|
7
29
|
|
|
8
30
|
### Minor Changes
|
|
9
31
|
|
|
10
|
-
-
|
|
32
|
+
- 80aebdc2: Adds `wonder-blocks-search-field` package
|
package/dist/es/index.js
CHANGED
|
@@ -1,45 +1,21 @@
|
|
|
1
1
|
import _extends from '@babel/runtime/helpers/extends';
|
|
2
2
|
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import * as ReactDOM from 'react-dom';
|
|
5
4
|
import { StyleSheet } from 'aphrodite';
|
|
6
5
|
import { styles as styles$1 } from '@khanacademy/wonder-blocks-typography';
|
|
7
|
-
import { View } from '@khanacademy/wonder-blocks-core';
|
|
6
|
+
import { IDProvider, View } from '@khanacademy/wonder-blocks-core';
|
|
8
7
|
import IconButton from '@khanacademy/wonder-blocks-icon-button';
|
|
9
8
|
import { TextField } from '@khanacademy/wonder-blocks-form';
|
|
10
9
|
import Icon, { icons } from '@khanacademy/wonder-blocks-icon';
|
|
11
10
|
import Color from '@khanacademy/wonder-blocks-color';
|
|
12
11
|
import Spacing from '@khanacademy/wonder-blocks-spacing';
|
|
13
12
|
|
|
14
|
-
// The default labels that will be used by different components
|
|
15
13
|
const defaultLabels = {
|
|
16
14
|
clearSearch: "Clear search"
|
|
17
15
|
};
|
|
18
16
|
|
|
19
17
|
const _excluded = ["clearAriaLabel", "disabled", "light", "id", "value", "placeholder", "style", "testId", "onClick", "onChange", "onFocus", "onBlur"];
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Search Field. A TextField with a search icon on its left side
|
|
23
|
-
* and an X icon on its right side.
|
|
24
|
-
*
|
|
25
|
-
* ### Usage
|
|
26
|
-
* ```jsx
|
|
27
|
-
* import {SearchField} from "@khanacademy/wonder-blocks-search-field";
|
|
28
|
-
*
|
|
29
|
-
* const [value, setValue] = React.useState("");
|
|
30
|
-
*
|
|
31
|
-
* const handleChange = (newValue: string) => {
|
|
32
|
-
* setValue(newValue);
|
|
33
|
-
* };
|
|
34
|
-
*
|
|
35
|
-
* <SearchField
|
|
36
|
-
* id="some-id"
|
|
37
|
-
* value={value}
|
|
38
|
-
* onChange={handleChange}
|
|
39
|
-
* />
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
function SearchField(props) {
|
|
18
|
+
const SearchField = React.forwardRef((props, ref) => {
|
|
43
19
|
const {
|
|
44
20
|
clearAriaLabel = defaultLabels.clearSearch,
|
|
45
21
|
disabled = false,
|
|
@@ -56,13 +32,13 @@ function SearchField(props) {
|
|
|
56
32
|
} = props,
|
|
57
33
|
otherProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
58
34
|
|
|
35
|
+
const innerRef = React.useRef(null);
|
|
36
|
+
|
|
59
37
|
const handleClear = () => {
|
|
60
|
-
|
|
61
|
-
onChange(""); // Focus back on the text field since the clear button disappears after
|
|
62
|
-
// the field is cleared.
|
|
38
|
+
var _innerRef$current;
|
|
63
39
|
|
|
64
|
-
|
|
65
|
-
|
|
40
|
+
onChange("");
|
|
41
|
+
innerRef == null ? void 0 : (_innerRef$current = innerRef.current) == null ? void 0 : _innerRef$current.focus();
|
|
66
42
|
};
|
|
67
43
|
|
|
68
44
|
const maybeRenderClearIconButton = () => {
|
|
@@ -70,7 +46,7 @@ function SearchField(props) {
|
|
|
70
46
|
return null;
|
|
71
47
|
}
|
|
72
48
|
|
|
73
|
-
return
|
|
49
|
+
return React.createElement(IconButton, {
|
|
74
50
|
icon: icons.dismiss,
|
|
75
51
|
kind: "tertiary",
|
|
76
52
|
onClick: handleClear,
|
|
@@ -79,17 +55,20 @@ function SearchField(props) {
|
|
|
79
55
|
});
|
|
80
56
|
};
|
|
81
57
|
|
|
82
|
-
return
|
|
58
|
+
return React.createElement(IDProvider, {
|
|
59
|
+
id: id,
|
|
60
|
+
scope: "search-field"
|
|
61
|
+
}, uniqueId => React.createElement(View, {
|
|
83
62
|
onClick: onClick,
|
|
84
63
|
style: [styles.inputContainer, style]
|
|
85
|
-
},
|
|
64
|
+
}, React.createElement(Icon, {
|
|
86
65
|
icon: icons.search,
|
|
87
66
|
size: "medium",
|
|
88
67
|
color: Color.offBlack64,
|
|
89
68
|
style: styles.searchIcon,
|
|
90
69
|
"aria-hidden": "true"
|
|
91
|
-
}),
|
|
92
|
-
id:
|
|
70
|
+
}), React.createElement(TextField, _extends({
|
|
71
|
+
id: `${uniqueId}-field`,
|
|
93
72
|
type: "text",
|
|
94
73
|
disabled: disabled,
|
|
95
74
|
light: light,
|
|
@@ -97,11 +76,18 @@ function SearchField(props) {
|
|
|
97
76
|
onFocus: onFocus,
|
|
98
77
|
onBlur: onBlur,
|
|
99
78
|
placeholder: placeholder,
|
|
79
|
+
ref: node => {
|
|
80
|
+
if (ref) {
|
|
81
|
+
ref.current = node;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
innerRef.current = node;
|
|
85
|
+
},
|
|
100
86
|
value: value,
|
|
101
87
|
style: [styles.inputStyleReset, styles$1.LabelMedium],
|
|
102
88
|
testId: testId
|
|
103
|
-
}, otherProps)), maybeRenderClearIconButton());
|
|
104
|
-
}
|
|
89
|
+
}, otherProps)), maybeRenderClearIconButton()));
|
|
90
|
+
});
|
|
105
91
|
const styles = StyleSheet.create({
|
|
106
92
|
inputContainer: {
|
|
107
93
|
boxSizing: "border-box",
|