Skip to content

Commit

Permalink
fix: correct Fork scripts; fixes #82
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed May 24, 2023
1 parent bee9b70 commit 6bac85b
Show file tree
Hide file tree
Showing 7 changed files with 2,020 additions and 1,842 deletions.
77 changes: 77 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module.exports = {
extends: ['plugin:@typescript-eslint/recommended', 'plugin:import/typescript', 'plugin:react-hooks/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'prettier', 'import'],
rules: {
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/ban-ts-ignore': 0,
'@typescript-eslint/no-var-requires': 0,
'@typescript-eslint/camelcase': 0,
'import/order': [
'error',
{
'newlines-between': 'always-and-inside-groups',
alphabetize: {
order: 'asc',
},
groups: ['builtin', 'external', 'internal', ['parent', 'index', 'sibling']],
},
],
'padding-line-between-statements': [
'error',
// IMPORT
{
blankLine: 'always',
prev: 'import',
next: '*',
},
{
blankLine: 'any',
prev: 'import',
next: 'import',
},
// EXPORT
{
blankLine: 'always',
prev: '*',
next: 'export',
},
{
blankLine: 'any',
prev: 'export',
next: 'export',
},
{
blankLine: 'always',
prev: '*',
next: ['const', 'let'],
},
{
blankLine: 'any',
prev: ['const', 'let'],
next: ['const', 'let'],
},
// BLOCKS
{
blankLine: 'always',
prev: ['block', 'block-like', 'class', 'function', 'multiline-expression'],
next: '*',
},
{
blankLine: 'always',
prev: '*',
next: ['block', 'block-like', 'class', 'function', 'return', 'multiline-expression'],
},
],
},
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
typescript: {
alwaysTryTypes: true,
},
},
},
};
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ node_modules/
.DS_Store
.idea
npm-debug.log
yarn-error.log
*.js
yarn-error.log
7 changes: 7 additions & 0 deletions .size.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"name": "dist/es2015/index.js",
"passed": true,
"size": 819
}
]
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
preset: 'ts-jest',
};
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"author": "Marina Korzunova ([email protected])",
"license": "MIT",
"devDependencies": {
"@theuiteam/lib-builder": "^0.3.0",
"@size-limit/preset-small-lib": "^2.1.6",
"@theuiteam/lib-builder": "^0.2.1",
"@types/react-test-renderer": "^18.0.0",
"react-test-renderer": "^18.2.0"
},
Expand All @@ -59,8 +59,8 @@
"node": ">=10"
},
"peerDependencies": {
"@types/react": "^16.8.0 || ^17.0.0 || ^18.0.0",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
"@types/react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"peerDependenciesMeta": {
"@types/react": {
Expand Down Expand Up @@ -91,5 +91,10 @@
"tabWidth": 2,
"semi": true,
"singleQuote": true
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}
12 changes: 7 additions & 5 deletions src/Control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useState } from 'react';

import { UID } from './UIDComponent';
import { createSource, UIDProps, source } from './context';
import { useUID } from './hooks';

interface WithPrefix {
prefix?: string;
Expand All @@ -30,11 +31,12 @@ export const UIDReset: React.FC<React.PropsWithChildren<WithPrefix>> = ({ childr
* Useful for self-contained elements or code splitting
* @see https://github.com/thearnica/react-uid#code-splitting
*/
export const UIDFork: React.FC<React.PropsWithChildren<WithPrefix>> = ({ children, prefix = '' }) => (
<UIDConsumer>
{(id) => <source.Provider value={createSource(id + '-' + prefix)}>{children}</source.Provider>}
</UIDConsumer>
);
export const UIDFork: React.FC<React.PropsWithChildren<WithPrefix>> = ({ children, prefix = '' }) => {
const id = useUID();
const [valueSource] = useState(() => createSource(id + '-' + prefix));

return <source.Provider value={valueSource}>{children}</source.Provider>;
};

/**
* UID in form of renderProps. Supports nesting and SSR. Prefer {@link useUID} hook version if possible.
Expand Down
Loading

0 comments on commit 6bac85b

Please sign in to comment.