Skip to content

Commit 3bfc1cb

Browse files
refactor: ⚡ move to tsup
1 parent b37541a commit 3bfc1cb

25 files changed

+1277
-2324
lines changed

Diff for: .eslintrc.cjs

+26-16
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,51 @@ module.exports = {
33
env: {
44
browser: true,
55
es2021: true,
6-
node: true
6+
node: true,
77
},
88
parser: "@typescript-eslint/parser",
9-
plugins: ["@typescript-eslint", "simple-import-sort"],
9+
plugins: ["@typescript-eslint", "prettier", "simple-import-sort"],
1010
extends: [
1111
"eslint:recommended",
12-
"plugin:react/recommended",
1312
"plugin:@typescript-eslint/eslint-recommended",
1413
"plugin:@typescript-eslint/recommended",
15-
"prettier"
14+
"plugin:react/recommended",
15+
"plugin:storybook/recommended",
1616
],
1717
rules: {
18-
"no-useless-escape": "off",
19-
"no-case-declarations": "off",
2018
"@typescript-eslint/ban-ts-comment": "off",
2119
"@typescript-eslint/ban-ts-ignore": "off",
2220
"@typescript-eslint/camelcase": "off",
23-
"@typescript-eslint/no-unused-vars": ["error", { ignoreRestSiblings: true }],
2421
"@typescript-eslint/explicit-function-return-type": "off",
22+
"@typescript-eslint/explicit-module-boundary-types": "off",
2523
"@typescript-eslint/interface-name-prefix": "off",
2624
"@typescript-eslint/no-empty-interface": "off",
2725
"@typescript-eslint/no-explicit-any": "off",
28-
"react/jsx-key": "off",
29-
"react/prop-types": "off",
26+
"@typescript-eslint/no-unused-vars": [
27+
"error",
28+
{
29+
ignoreRestSiblings: true,
30+
},
31+
],
32+
"no-case-declarations": "off",
33+
"no-console": [
34+
"error",
35+
{
36+
allow: ["warn", "error", "debug"],
37+
},
38+
],
39+
"no-useless-escape": "off",
40+
"prettier/prettier": "error",
3041
"react/display-name": "off",
42+
"react/jsx-key": "off",
3143
"react/no-children-prop": "off",
32-
"@typescript-eslint/explicit-module-boundary-types": "off",
33-
"simple-import-sort/imports": "error",
44+
"react/prop-types": "off",
3445
"simple-import-sort/exports": "error",
35-
36-
"no-console": ["error", { allow: ["warn", "error", "debug"] }]
46+
"simple-import-sort/imports": "error",
3747
},
3848
settings: {
3949
react: {
40-
version: "detect"
41-
}
42-
}
50+
version: "detect",
51+
},
52+
},
4353
};

Diff for: .husky/pre-commit

-4
This file was deleted.

Diff for: .nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12
1+
16

Diff for: .storybook/main.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
module.exports = {
2-
stories: ["../stories/**/*.stories.@(ts|tsx|js|jsx)"],
2+
stories: [
3+
"../stories/**/*.stories.mdx",
4+
"../stories/**/*.stories.@(js|jsx|ts|tsx)",
5+
],
36
addons: [
4-
"@storybook/addon-essentials",
5-
"@storybook/addon-knobs",
67
"@storybook/addon-links",
8+
"@storybook/addon-essentials",
79
{
8-
name: "storybook-addon-turbo-build",
10+
name: '@storybook/addon-docs',
911
options: {
10-
optimizationLevel: 2,
12+
configureJSX: true,
13+
transcludeMarkdown: true,
1114
},
1215
},
1316
],
14-
// https://storybook.js.org/docs/react/configure/typescript#mainjs-configuration
15-
typescript: {
16-
check: true, // type-check stories during Storybook build
17-
reactDocgen: "none",
18-
},
17+
framework: "@storybook/react",
1918
};

Diff for: .storybook/package.json

-3
This file was deleted.

Diff for: .storybook/preview.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
// https://storybook.js.org/docs/react/writing-stories/parameters#global-parameters
21
export const parameters = {
3-
// https://storybook.js.org/docs/react/essentials/actions#automatically-matching-args
4-
actions: { argTypesRegex: "^on.*" },
5-
};
2+
actions: { argTypesRegex: "^on[A-Z].*" },
3+
controls: {
4+
matchers: {
5+
color: /(background|color)$/i,
6+
date: /Date$/,
7+
},
8+
},
9+
}

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ yarn add react-multi-select-component # yarn
2323

2424
## 📦 Example
2525

26-
![Example](docs/images/preview.gif)
26+
![Example](https://user-images.githubusercontent.com/5774849/150685427-6025d7d3-ddfc-4787-a856-241c4cc100cb.gif)
2727

2828
```tsx
2929
import React, { useState } from "react";
@@ -55,7 +55,7 @@ const Example = () => {
5555
export default Example;
5656
```
5757

58-
More examples can be found [here ↗](./docs/recipes)
58+
More examples can be found [here ↗](https://react-multi-select-component.pages.dev/)
5959

6060
## 👀 Props
6161

Diff for: babel.config.js

-29
This file was deleted.

Diff for: docs/images/custom-value.gif

-62.7 KB
Binary file not shown.

Diff for: docs/images/preview.gif

-101 KB
Binary file not shown.

Diff for: docs/recipes/custom-item.md

-5
This file was deleted.

Diff for: package.json

+19-38
Original file line numberDiff line numberDiff line change
@@ -5,77 +5,58 @@
55
"author": "harshzalavadiya",
66
"license": "MIT",
77
"repository": "https://github.com/hc-oss/react-multi-select-component",
8-
"main": "dist/cjs/index.js",
9-
"module": "dist/esm/index.js",
10-
"types": "dist/types/index.d.ts",
11-
"typings": "dist/types/index.d.ts",
12-
"exports": {
13-
".": {
14-
"require": "./dist/cjs/index.js",
15-
"default": "./dist/esm/index.js"
16-
}
17-
},
8+
"main": "./dist/index.js",
9+
"module": "./dist/index.mjs",
10+
"types": "./dist/index.d.ts",
1811
"scripts": {
19-
"analyze": "size-limit --why",
20-
"build-storybook": "build-storybook",
21-
"prebuild": "rimraf dist",
22-
"build": "concurrently yarn:build:*",
23-
"build:esm": "cross-env BABEL_ENV=esm babel src --root-mode upward --extensions .ts,.tsx -d dist/esm --source-maps",
24-
"build:cjs": "cross-env BABEL_ENV=cjs babel src --root-mode upward --extensions .ts,.tsx -d dist/cjs --source-maps",
25-
"build:types": "tsc --emitDeclarationOnly --declaration --declarationDir dist/types",
26-
"format": "prettier --write src/**/*",
27-
"lint": "eslint src/**/*.{ts,tsx}",
12+
"build": "tsup src/index.tsx --inject-style --minify --format esm,cjs --dts --external react",
13+
"dev": "tsup src/index.tsx --inject-style --format esm,cjs --watch --dts --external react",
14+
"lint": "eslint src --fix",
2815
"size": "size-limit",
29-
"storybook": "start-storybook -p 6006"
16+
"storybook": "start-storybook -p 6006",
17+
"build-storybook": "build-storybook"
3018
},
3119
"peerDependencies": {
3220
"react": "^16 || ^17",
3321
"react-dom": "^16 || ^17"
3422
},
3523
"dependencies": {},
3624
"devDependencies": {
37-
"@babel/cli": "^7.16.8",
38-
"@babel/core": "^7.16.10",
39-
"@babel/preset-env": "^7.16.11",
40-
"@babel/preset-react": "^7.16.7",
41-
"@babel/preset-typescript": "^7.16.7",
4225
"@size-limit/preset-small-lib": "^7.0.5",
4326
"@storybook/addon-actions": "^6.4.14",
4427
"@storybook/addon-essentials": "^6.4.14",
45-
"@storybook/addon-knobs": "^6.3.1",
28+
"@storybook/addon-knobs": "^6.4.0",
4629
"@storybook/addon-links": "^6.4.14",
4730
"@storybook/react": "^6.4.14",
48-
"@types/react": "^17.0.38",
49-
"@types/react-dom": "^17.0.11",
31+
"@types/react": "^17.0.13",
32+
"@types/react-dom": "^17.0.8",
5033
"@typescript-eslint/eslint-plugin": "^5.10.0",
5134
"@typescript-eslint/parser": "^5.10.0",
52-
"babel-loader": "^8.2.3",
53-
"babel-plugin-transform-css-import-to-string": "^0.0.2",
54-
"concurrently": "^7.0.0",
55-
"cross-env": "^7.0.3",
56-
"eslint": "^8.7.0",
57-
"eslint-config-prettier": "^8.3.0",
35+
"eslint": "7.32.0",
5836
"eslint-plugin-prettier": "^4.0.0",
5937
"eslint-plugin-react": "^7.28.0",
6038
"eslint-plugin-simple-import-sort": "^7.0.0",
61-
"husky": "^7.0.4",
39+
"eslint-plugin-storybook": "^0.5.6",
40+
"postcss": "^8.4.5",
6241
"prettier": "^2.5.1",
6342
"react": "^17.0.2",
6443
"react-dom": "^17.0.2",
44+
"size-limit": "^7.0.5",
6545
"storybook-addon-turbo-build": "^1.0.1",
66-
"typescript": "^4.5.5"
46+
"tsup": "^5.10.1",
47+
"typescript": "^4.5.3"
6748
},
6849
"browserslist": [
6950
"defaults",
7051
"not IE 11",
7152
"maintained node versions"
7253
],
7354
"files": [
74-
"dist"
55+
"dist/**"
7556
],
7657
"size-limit": [
7758
{
78-
"path": "dist/cjs/index.js",
59+
"path": "dist/index.js",
7960
"limit": "10 KB"
8061
}
8162
],

Diff for: src/hooks/use-multi-select.tsx

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import React, { useEffect, useMemo, useState } from "react";
1+
import React, { useEffect, useState } from "react";
22

3-
import { injectStyles } from "../lib/inject-style";
43
import { ISelectProps, Option } from "../lib/interfaces";
54

65
const defaultStrings = {
@@ -44,8 +43,6 @@ export const MultiSelectProvider = ({
4443
const [options, setOptions] = useState(props.options);
4544
const t = (key) => props.overrideStrings?.[key] || defaultStrings[key];
4645

47-
useMemo(() => injectStyles(), []);
48-
4946
useEffect(() => {
5047
setOptions(props.options);
5148
}, [props.options]);

Diff for: src/lib/fuzzy-match-utils.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ export function filterOptions(
4646
}))
4747
// Only include matches of the entire substring, with a slight
4848
// affordance for transposition or extra characters.
49-
.filter((pair) => pair.score >= Math.max(cleanFilter.length - 2, cleanFilter.length) /** Filter text might have length less than 2 */)
49+
.filter(
50+
(pair) =>
51+
pair.score >=
52+
Math.max(
53+
cleanFilter.length - 2,
54+
cleanFilter.length
55+
) /** Filter text might have length less than 2 */
56+
)
5057
// Sort 'em by order of their score.
5158
.sort((a, b) => b.score - a.score)
5259
// …and grab the original Options back from their pairs.

Diff for: src/lib/inject-style.tsx

-12
This file was deleted.

Diff for: src/multi-select/index.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import React from "react";
1+
import "../style.css";
2+
3+
import * as React from "react";
24

35
import { MultiSelectProvider } from "../hooks/use-multi-select";
46
import { ISelectProps } from "../lib/interfaces";

Diff for: src/select-panel/index.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ const SelectPanel = () => {
7777
const selectedValues = value.map((o) => o.value);
7878
const finalSelectedValues = [...selectedValues, ...filteredValues];
7979

80-
return (customFilterOptions ? filteredOptions : options).filter((o) => finalSelectedValues.includes(o.value));
80+
return (customFilterOptions ? filteredOptions : options).filter((o) =>
81+
finalSelectedValues.includes(o.value)
82+
);
8183
}
8284

8385
return value.filter((o) => !filteredValues.includes(o.value));

Diff for: docs/recipes/custom-filter.md renamed to stories/recipes/custom-filter.stories.mdx

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { Meta } from "@storybook/addon-docs";
2+
3+
<Meta title="recipes/Custom Filter Logic" />
4+
15
# 🔍 Custom Filter Logic
26

37
By default this component uses a fuzzy search algorithm to filter options but also allows you to opt-out and use your custom logic by specifying `filterOptions` prop to component

Diff for: stories/recipes/custom-item.stories.mdx

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Meta } from "@storybook/addon-docs";
2+
3+
<Meta title="recipes/Custom Item Renderer" />
4+
5+
# 🎛 Custom Item Renderer
6+
7+
Optionally customise dropdown item by passing `ItemRenderer` prop
8+
9+
[Default Item Renderer ↗](https://github.com/hc-oss/react-multi-select-component/blob/master/src/select-panel/default-item.tsx#L12-L28)

Diff for: docs/recipes/custom-value.md renamed to stories/recipes/custom-value.stories.mdx

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { Meta } from "@storybook/addon-docs";
2+
3+
<Meta title="recipes/Custom Value Renderer" />
4+
15
# 🎛 Custom Value Renderer
26

37
Optionally customise value renderer view by passing `valueRenderer` prop
@@ -10,5 +14,4 @@ const customValueRenderer = (selected, _options) => {
1014
};
1115
```
1216

13-
![Custom Value Renderer](/custom-value.gif)
14-
F
17+
![Custom Value Renderer](https://user-images.githubusercontent.com/5774849/150685369-dd5426c5-1e91-441f-b461-9fd88844f8d0.gif)

Diff for: docs/recipes/localization.md renamed to stories/recipes/localization.stories.mdx

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { Meta } from "@storybook/addon-docs";
2+
3+
<Meta title="recipes/Localization" />
4+
15
# 🌐 Localization
26

37
You can easily Internationalize this component by passing prop `overrideStrings` so that UI strings can be presented in a different language

0 commit comments

Comments
 (0)