instantsearch-ui-components 0.3.0 → 0.4.0

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.
@@ -31,8 +31,6 @@ function createHighlightComponent(_ref3) {
31
31
  Fragment: Fragment
32
32
  });
33
33
  return function Highlight(userProps) {
34
- // Not destructured in function signature, to make sure it's not exposed in
35
- // the type definition.
36
34
  var parts = userProps.parts,
37
35
  _userProps$highlighte = userProps.highlightedTagName,
38
36
  highlightedTagName = _userProps$highlighte === void 0 ? 'mark' : _userProps$highlighte,
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createHitsComponent = createHitsComponent;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
+ var _lib = require("../lib");
11
+ var _excluded = ["classNames", "hits", "itemComponent", "sendEvent", "emptyComponent"];
12
+ // Should be imported from a shared package in the future
13
+
14
+ function createHitsComponent(_ref) {
15
+ var createElement = _ref.createElement;
16
+ return function Hits(userProps) {
17
+ var _userProps$classNames = userProps.classNames,
18
+ classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames,
19
+ hits = userProps.hits,
20
+ ItemComponent = userProps.itemComponent,
21
+ sendEvent = userProps.sendEvent,
22
+ EmptyComponent = userProps.emptyComponent,
23
+ props = (0, _objectWithoutProperties2.default)(userProps, _excluded);
24
+ if (hits.length === 0 && EmptyComponent) {
25
+ return createElement(EmptyComponent, {
26
+ className: (0, _lib.cx)('ais-Hits', classNames.root, (0, _lib.cx)('ais-Hits--empty', classNames.emptyRoot), props.className)
27
+ });
28
+ }
29
+ return createElement("div", (0, _extends2.default)({}, props, {
30
+ className: (0, _lib.cx)('ais-Hits', classNames.root, hits.length === 0 && (0, _lib.cx)('ais-Hits--empty', classNames.emptyRoot), props.className)
31
+ }), createElement("ol", {
32
+ className: (0, _lib.cx)('ais-Hits-list', classNames.list)
33
+ }, hits.map(function (hit, index) {
34
+ return createElement(ItemComponent, {
35
+ key: hit.objectID,
36
+ hit: hit,
37
+ index: index,
38
+ className: (0, _lib.cx)('ais-Hits-item', classNames.item),
39
+ onClick: function onClick() {
40
+ sendEvent('click:internal', hit, 'Hit Clicked');
41
+ },
42
+ onAuxClick: function onAuxClick() {
43
+ sendEvent('click:internal', hit, 'Hit Clicked');
44
+ }
45
+ });
46
+ })));
47
+ };
48
+ }
@@ -13,4 +13,15 @@ Object.keys(_Highlight).forEach(function (key) {
13
13
  return _Highlight[key];
14
14
  }
15
15
  });
16
+ });
17
+ var _Hits = require("./Hits");
18
+ Object.keys(_Hits).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _Hits[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function get() {
24
+ return _Hits[key];
25
+ }
26
+ });
16
27
  });
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = '0.3.0';
7
+ var _default = '0.4.0';
8
8
  exports.default = _default;
@@ -24,8 +24,6 @@ export function createHighlightComponent(_ref3) {
24
24
  Fragment: Fragment
25
25
  });
26
26
  return function Highlight(userProps) {
27
- // Not destructured in function signature, to make sure it's not exposed in
28
- // the type definition.
29
27
  var parts = userProps.parts,
30
28
  _userProps$highlighte = userProps.highlightedTagName,
31
29
  highlightedTagName = _userProps$highlighte === void 0 ? 'mark' : _userProps$highlighte,
@@ -0,0 +1,40 @@
1
+ import type { ComponentProps, Renderer } from '../types';
2
+ type Hit = Record<string, unknown> & {
3
+ objectID: string;
4
+ };
5
+ type SendEventForHits = (...props: unknown[]) => void;
6
+ export type HitsProps<THit> = ComponentProps<'div'> & {
7
+ hits: THit[];
8
+ itemComponent: (props: {
9
+ hit: THit;
10
+ index: number;
11
+ className: string;
12
+ onClick: () => void;
13
+ onAuxClick: () => void;
14
+ }) => JSX.Element;
15
+ sendEvent: SendEventForHits;
16
+ classNames?: Partial<HitsClassNames>;
17
+ emptyComponent?: (props: {
18
+ className: string;
19
+ }) => JSX.Element;
20
+ };
21
+ export type HitsClassNames = {
22
+ /**
23
+ * Class names to apply to the root element
24
+ */
25
+ root: string | string[];
26
+ /**
27
+ * Class names to apply to the root element without results
28
+ */
29
+ emptyRoot: string | string[];
30
+ /**
31
+ * Class names to apply to the list element
32
+ */
33
+ list: string | string[];
34
+ /**
35
+ * Class names to apply to each item element
36
+ */
37
+ item: string | string[];
38
+ };
39
+ export declare function createHitsComponent({ createElement }: Renderer): <THit extends Hit>(userProps: HitsProps<THit>) => JSX.Element;
40
+ export {};
@@ -0,0 +1,42 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["classNames", "hits", "itemComponent", "sendEvent", "emptyComponent"];
4
+ import { cx } from "../lib/index.js";
5
+
6
+ // Should be imported from a shared package in the future
7
+
8
+ export function createHitsComponent(_ref) {
9
+ var createElement = _ref.createElement;
10
+ return function Hits(userProps) {
11
+ var _userProps$classNames = userProps.classNames,
12
+ classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames,
13
+ hits = userProps.hits,
14
+ ItemComponent = userProps.itemComponent,
15
+ sendEvent = userProps.sendEvent,
16
+ EmptyComponent = userProps.emptyComponent,
17
+ props = _objectWithoutProperties(userProps, _excluded);
18
+ if (hits.length === 0 && EmptyComponent) {
19
+ return createElement(EmptyComponent, {
20
+ className: cx('ais-Hits', classNames.root, cx('ais-Hits--empty', classNames.emptyRoot), props.className)
21
+ });
22
+ }
23
+ return createElement("div", _extends({}, props, {
24
+ className: cx('ais-Hits', classNames.root, hits.length === 0 && cx('ais-Hits--empty', classNames.emptyRoot), props.className)
25
+ }), createElement("ol", {
26
+ className: cx('ais-Hits-list', classNames.list)
27
+ }, hits.map(function (hit, index) {
28
+ return createElement(ItemComponent, {
29
+ key: hit.objectID,
30
+ hit: hit,
31
+ index: index,
32
+ className: cx('ais-Hits-item', classNames.item),
33
+ onClick: function onClick() {
34
+ sendEvent('click:internal', hit, 'Hit Clicked');
35
+ },
36
+ onAuxClick: function onAuxClick() {
37
+ sendEvent('click:internal', hit, 'Hit Clicked');
38
+ }
39
+ });
40
+ })));
41
+ };
42
+ }
@@ -1 +1,2 @@
1
1
  export * from './Highlight';
2
+ export * from './Hits';
@@ -1 +1,2 @@
1
- export * from "./Highlight.js";
1
+ export * from "./Highlight.js";
2
+ export * from "./Hits.js";
@@ -1,2 +1,2 @@
1
- declare const _default: "0.3.0";
1
+ declare const _default: "0.4.0";
2
2
  export default _default;
@@ -1 +1 @@
1
- export default '0.3.0';
1
+ export default '0.4.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instantsearch-ui-components",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Common UI components for InstantSearch.",
5
5
  "types": "dist/es/index.d.ts",
6
6
  "main": "dist/cjs/index.js",
@@ -39,10 +39,15 @@
39
39
  "scripts": {
40
40
  "clean": "rm -rf dist",
41
41
  "build": "yarn build:cjs && yarn build:es && yarn build:types",
42
- "build:es": "BABEL_ENV=es babel src --root-mode upward --extensions '.js,.ts,.tsx' --out-dir dist/es --ignore '**/__tests__/**/*','**/__mocks__/**/*' --quiet",
42
+ "build:es:base": "BABEL_ENV=es babel src --root-mode upward --extensions '.js,.ts,.tsx' --out-dir dist/es --ignore '**/__tests__/**/*','**/__mocks__/**/*'",
43
+ "build:es": "yarn build:es:base --quiet",
43
44
  "build:cjs": "BABEL_ENV=cjs babel src --root-mode upward --extensions '.js,.ts,.tsx' --out-dir dist/cjs --ignore '**/__tests__/**/*','**/__mocks__/**/*' --quiet && ../../scripts/prepare-cjs.sh",
44
45
  "build:types": "tsc -p ./tsconfig.declaration.json --outDir ./dist/es",
45
- "version": "./scripts/version.cjs"
46
+ "version": "./scripts/version.cjs",
47
+ "watch:es": "yarn --silent build:es:base --watch"
46
48
  },
47
- "gitHead": "084aff3d29e15cea8125076c46fb753c83d4dcad"
49
+ "dependencies": {
50
+ "@babel/runtime": "^7.1.2"
51
+ },
52
+ "gitHead": "358f849cba15cbbb415da05feb582b47358aa239"
48
53
  }