@blocklet/list 0.10.33 → 0.10.34

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/lib/base.js CHANGED
@@ -16,6 +16,7 @@ var _filter2 = require("./components/filter");
16
16
  var _utils = require("./libs/utils");
17
17
  var _list = _interopRequireDefault(require("./components/list"));
18
18
  var _aside = _interopRequireDefault(require("./components/aside"));
19
+ var _baseSearch = _interopRequireDefault(require("./components/base-search"));
19
20
  var _autocomplete = _interopRequireDefault(require("./components/autocomplete"));
20
21
  var _jsxRuntime = require("react/jsx-runtime");
21
22
  var _templateObject, _templateObject2;
@@ -35,7 +36,8 @@ function ListBase() {
35
36
  t,
36
37
  getCategoryLocale,
37
38
  priceOptions,
38
- wrapChildren
39
+ wrapChildren,
40
+ baseSearch
39
41
  } = (0, _filter.useFilterContext)();
40
42
  const sortOptions = (0, _utils.getSortOptions)(t);
41
43
  const sortLocale = ((_sortOptions$find = sortOptions.find(f => f.value === filters.sortBy)) === null || _sortOptions$find === void 0 ? void 0 : _sortOptions$find.name) || t('sort.sort');
@@ -54,7 +56,10 @@ function ListBase() {
54
56
  className: "filter-bar",
55
57
  display: "flex",
56
58
  alignItems: "center",
57
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_autocomplete.default, {
59
+ children: [baseSearch ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_baseSearch.default, {
60
+ className: "bl-search-container",
61
+ placeholder: t('common.searchStore')
62
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_autocomplete.default, {
58
63
  onSelect: handleSearchSelect,
59
64
  wrapChildren: wrapChildren
60
65
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Box, {
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = require("react");
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ var _Search = _interopRequireDefault(require("@mui/icons-material/Search"));
10
+ var _Close = _interopRequireDefault(require("@mui/icons-material/Close"));
11
+ var _material = require("@mui/material");
12
+ var _ahooks = require("ahooks");
13
+ var _styled = _interopRequireDefault(require("@emotion/styled"));
14
+ var _filter = require("../contexts/filter");
15
+ var _jsxRuntime = require("react/jsx-runtime");
16
+ var _templateObject, _templateObject2, _templateObject3;
17
+ const _excluded = ["placeholder"];
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
20
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
21
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
22
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
23
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
24
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
25
+ function BaseSearch(_ref) {
26
+ let {
27
+ placeholder
28
+ } = _ref,
29
+ rest = _objectWithoutProperties(_ref, _excluded);
30
+ const {
31
+ filters,
32
+ handleKeyword
33
+ } = (0, _filter.useFilterContext)();
34
+ const [searchStr, setSearchStr] = (0, _react.useState)(filters.keyword || '');
35
+ const debouncedSearch = (0, _ahooks.useDebounceFn)(handleKeyword, {
36
+ wait: 300
37
+ });
38
+ const handleChange = event => {
39
+ const {
40
+ value
41
+ } = event.target;
42
+ setSearchStr(value);
43
+ debouncedSearch.run(value);
44
+ };
45
+ const handleClose = () => {
46
+ setSearchStr('');
47
+ handleKeyword();
48
+ };
49
+ (0, _react.useEffect)(() => {
50
+ setSearchStr(filters.keyword || '');
51
+ }, [filters.keyword]);
52
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledSearch, _objectSpread({
53
+ inputProps: {
54
+ 'data-cy': 'search-blocklet'
55
+ },
56
+ startAdornment: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.InputAdornment, {
57
+ position: "start",
58
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledSearchIcon, {})
59
+ }),
60
+ onChange: handleChange,
61
+ placeholder: placeholder,
62
+ value: searchStr,
63
+ title: placeholder,
64
+ "data-cy": "search",
65
+ endAdornment: searchStr && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.InputAdornment, {
66
+ position: "end",
67
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledCloseIcon, {
68
+ "data-cy": "search-delete",
69
+ onClick: handleClose
70
+ })
71
+ })
72
+ }, rest));
73
+ }
74
+ BaseSearch.propTypes = {
75
+ placeholder: _propTypes.default.string
76
+ };
77
+ BaseSearch.defaultProps = {
78
+ placeholder: 'Type to search...'
79
+ };
80
+ const StyledSearch = (0, _styled.default)(_material.OutlinedInput)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n background-color: ", ";\n font-size: 14px;\n border-radius: 6px;\n .MuiInputBase-input {\n padding: 8px 0 8px 10px;\n }\n .MuiOutlinedInput-notchedOutline {\n border: none;\n }\n .Mui-focused {\n background-color: #f6f6f6;\n .MuiInputBase-input::placeholder {\n color: transparent;\n }\n }\n"])), props => props.theme.palette.grey[50]);
81
+ const StyledSearchIcon = (0, _styled.default)(_Search.default)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n color: ", ";\n font-size: 28px;\n @media (max-width: ", "px) {\n font-size: 24px;\n }\n"])), props => props.theme.palette.grey[500], props => props.theme.breakpoints.values.md);
82
+ const StyledCloseIcon = (0, _styled.default)(_Close.default)(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n color: ", ";\n font-size: 16px;\n cursor: pointer;\n"])), props => props.theme.palette.grey[500]);
83
+ var _default = BaseSearch;
84
+ exports.default = _default;
@@ -36,7 +36,8 @@ function FilterProvider(_ref) {
36
36
  onFilterChange,
37
37
  onSearchSelect,
38
38
  extraFilter,
39
- wrapChildren
39
+ wrapChildren,
40
+ baseSearch
40
41
  } = _ref;
41
42
  const storeApi = (0, _react.useMemo)(() => {
42
43
  return _axios.default.create({
@@ -140,6 +141,7 @@ function FilterProvider(_ref) {
140
141
  categoryOptions,
141
142
  priceOptions,
142
143
  storeApi,
144
+ baseSearch,
143
145
  hasNextPage: blockletsState.list.length < blockletsState.total,
144
146
  handleSort: sort => {
145
147
  const changeData = _objectSpread(_objectSpread({}, finalFilters), {}, {
@@ -21,7 +21,8 @@ const propTypes = {
21
21
  blockletRender: _propTypes.default.func.isRequired,
22
22
  onFilterChange: _propTypes.default.func,
23
23
  onSearchSelect: _propTypes.default.func,
24
- locale: _propTypes.default.oneOf(['zh', 'en'])
24
+ locale: _propTypes.default.oneOf(['zh', 'en']),
25
+ baseSearch: _propTypes.default.bool
25
26
  };
26
27
  exports.propTypes = propTypes;
27
28
  const defaultProps = {
@@ -35,6 +36,7 @@ const defaultProps = {
35
36
  window.location.href = detailUrl;
36
37
  },
37
38
  wrapChildren: children => children,
38
- extraFilter: list => list
39
+ extraFilter: list => list,
40
+ baseSearch: false
39
41
  };
40
42
  exports.defaultProps = defaultProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/list",
3
- "version": "0.10.33",
3
+ "version": "0.10.34",
4
4
  "description": "Common ux components of blocklet",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -47,7 +47,6 @@
47
47
  "@emotion/styled": "^11.10.0",
48
48
  "@mui/icons-material": "^5.8.4",
49
49
  "ahooks": "^3.7.0",
50
- "algoliasearch": "^4.14.2",
51
50
  "axios": "^0.27.2",
52
51
  "color": "^4.2.3",
53
52
  "flat": "^5.0.2",
@@ -71,5 +70,5 @@
71
70
  "eslint": "^8.22.0",
72
71
  "prettier": "^2.7.1"
73
72
  },
74
- "gitHead": "d5fb6c10f6e9920d854d5116bc089e63b3260b7f"
73
+ "gitHead": "a937d5fcacee474b9f024440587a94975f8c0361"
75
74
  }
package/src/base.js CHANGED
@@ -11,6 +11,7 @@ import { CustomChip, FilterIcon } from './components/filter';
11
11
  import { getSortOptions } from './libs/utils';
12
12
  import BlockletList from './components/list';
13
13
  import Aside from './components/aside';
14
+ import BaseSearch from './components/base-search';
14
15
  import Autocomplete from './components/autocomplete';
15
16
 
16
17
  function ListBase() {
@@ -27,6 +28,7 @@ function ListBase() {
27
28
  getCategoryLocale,
28
29
  priceOptions,
29
30
  wrapChildren,
31
+ baseSearch,
30
32
  } = useFilterContext();
31
33
  const sortOptions = getSortOptions(t);
32
34
  const sortLocale = sortOptions.find((f) => f.value === filters.sortBy)?.name || t('sort.sort');
@@ -40,7 +42,12 @@ function ListBase() {
40
42
  <StyledMin>
41
43
  <FilterContainer>
42
44
  <Box className="filter-bar" display="flex" alignItems="center">
43
- <Autocomplete onSelect={handleSearchSelect} wrapChildren={wrapChildren} />
45
+ {/* see: https://github.com/blocklet/blocklet-store/pull/852 */}
46
+ {baseSearch ? (
47
+ <BaseSearch className="bl-search-container" placeholder={t('common.searchStore')} />
48
+ ) : (
49
+ <Autocomplete onSelect={handleSearchSelect} wrapChildren={wrapChildren} />
50
+ )}
44
51
  <Box mt={0} ml="16px" className="filter-container">
45
52
  <Hidden mdUp>
46
53
  {/* 小屏幕下类别 */}
@@ -0,0 +1,93 @@
1
+ import { useEffect, useState } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import SearchIcon from '@mui/icons-material/Search';
4
+ import CloseIcon from '@mui/icons-material/Close';
5
+ import { OutlinedInput, InputAdornment } from '@mui/material';
6
+ import { useDebounceFn } from 'ahooks';
7
+ import styled from '@emotion/styled';
8
+
9
+ import { useFilterContext } from '../contexts/filter';
10
+
11
+ function BaseSearch({ placeholder, ...rest }) {
12
+ const { filters, handleKeyword } = useFilterContext();
13
+ const [searchStr, setSearchStr] = useState(filters.keyword || '');
14
+
15
+ const debouncedSearch = useDebounceFn(handleKeyword, { wait: 300 });
16
+ const handleChange = (event) => {
17
+ const { value } = event.target;
18
+ setSearchStr(value);
19
+ debouncedSearch.run(value);
20
+ };
21
+ const handleClose = () => {
22
+ setSearchStr('');
23
+ handleKeyword();
24
+ };
25
+ useEffect(() => {
26
+ setSearchStr(filters.keyword || '');
27
+ }, [filters.keyword]);
28
+
29
+ return (
30
+ <StyledSearch
31
+ inputProps={{
32
+ 'data-cy': 'search-blocklet',
33
+ }}
34
+ startAdornment={
35
+ <InputAdornment position="start">
36
+ <StyledSearchIcon />
37
+ </InputAdornment>
38
+ }
39
+ onChange={handleChange}
40
+ placeholder={placeholder}
41
+ value={searchStr}
42
+ title={placeholder}
43
+ data-cy="search"
44
+ endAdornment={
45
+ searchStr && (
46
+ <InputAdornment position="end">
47
+ <StyledCloseIcon data-cy="search-delete" onClick={handleClose} />
48
+ </InputAdornment>
49
+ )
50
+ }
51
+ {...rest}
52
+ />
53
+ );
54
+ }
55
+ BaseSearch.propTypes = {
56
+ placeholder: PropTypes.string,
57
+ };
58
+ BaseSearch.defaultProps = {
59
+ placeholder: 'Type to search...',
60
+ };
61
+ const StyledSearch = styled(OutlinedInput)`
62
+ background-color: ${(props) => props.theme.palette.grey[50]};
63
+ font-size: 14px;
64
+ border-radius: 6px;
65
+ .MuiInputBase-input {
66
+ padding: 8px 0 8px 10px;
67
+ }
68
+ .MuiOutlinedInput-notchedOutline {
69
+ border: none;
70
+ }
71
+ .Mui-focused {
72
+ background-color: #f6f6f6;
73
+ .MuiInputBase-input::placeholder {
74
+ color: transparent;
75
+ }
76
+ }
77
+ `;
78
+
79
+ const StyledSearchIcon = styled(SearchIcon)`
80
+ color: ${(props) => props.theme.palette.grey[500]};
81
+ font-size: 28px;
82
+ @media (max-width: ${(props) => props.theme.breakpoints.values.md}px) {
83
+ font-size: 24px;
84
+ }
85
+ `;
86
+
87
+ const StyledCloseIcon = styled(CloseIcon)`
88
+ color: ${(props) => props.theme.palette.grey[500]};
89
+ font-size: 16px;
90
+ cursor: pointer;
91
+ `;
92
+
93
+ export default BaseSearch;
@@ -21,6 +21,7 @@ function FilterProvider({
21
21
  onSearchSelect,
22
22
  extraFilter,
23
23
  wrapChildren,
24
+ baseSearch,
24
25
  }) {
25
26
  const storeApi = useMemo(() => {
26
27
  return axios.create({
@@ -118,6 +119,7 @@ function FilterProvider({
118
119
  categoryOptions,
119
120
  priceOptions,
120
121
  storeApi,
122
+ baseSearch,
121
123
  hasNextPage: blockletsState.list.length < blockletsState.total,
122
124
  handleSort: (sort) => {
123
125
  const changeData = {
@@ -16,6 +16,7 @@ const propTypes = {
16
16
  onFilterChange: PropTypes.func,
17
17
  onSearchSelect: PropTypes.func,
18
18
  locale: PropTypes.oneOf(['zh', 'en']),
19
+ baseSearch: PropTypes.bool,
19
20
  };
20
21
 
21
22
  const defaultProps = {
@@ -27,6 +28,7 @@ const defaultProps = {
27
28
  },
28
29
  wrapChildren: (children) => children,
29
30
  extraFilter: (list) => list,
31
+ baseSearch: false,
30
32
  };
31
33
 
32
34
  export { propTypes, defaultProps };