This commit is contained in:
Vut Pov 2020-07-14 16:04:58 +07:00
parent fd1e253177
commit 64ab6e4247
23 changed files with 239 additions and 110 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,40 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JSCodeStyleSettings version="0">
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
<option name="FORCE_SEMICOLON_STYLE" value="true" />
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
<option name="USE_DOUBLE_QUOTES" value="false" />
<option name="FORCE_QUOTE_STYlE" value="true" />
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
<option name="SPACES_WITHIN_IMPORTS" value="true" />
</JSCodeStyleSettings>
<TypeScriptCodeStyleSettings version="0">
<option name="USE_SEMICOLON_AFTER_STATEMENT" value="false" />
<option name="FORCE_SEMICOLON_STYLE" value="true" />
<option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
<option name="USE_DOUBLE_QUOTES" value="false" />
<option name="FORCE_QUOTE_STYlE" value="true" />
<option name="ENFORCE_TRAILING_COMMA" value="Remove" />
<option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
<option name="SPACES_WITHIN_IMPORTS" value="true" />
</TypeScriptCodeStyleSettings>
<codeStyleSettings language="JavaScript">
<option name="SOFT_MARGINS" value="80" />
<indentOptions>
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="2" />
<option name="TAB_SIZE" value="2" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="TypeScript">
<option name="SOFT_MARGINS" value="80" />
<indentOptions>
<option name="INDENT_SIZE" value="2" />
<option name="CONTINUATION_INDENT_SIZE" value="2" />
<option name="TAB_SIZE" value="2" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
</component>

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>

9
.idea/misc.xml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="JSX" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/base-context-provider.iml" filepath="$PROJECT_DIR$/.idea/base-context-provider.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -4,27 +4,6 @@
[![NPM](https://img.shields.io/npm/v/base-context-provider.svg)](https://www.npmjs.com/package/base-context-provider) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) [![NPM](https://img.shields.io/npm/v/base-context-provider.svg)](https://www.npmjs.com/package/base-context-provider) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
## Install
```bash
npm install --save base-context-provider
```
## Usage
```tsx
import React, { Component } from 'react'
import MyComponent from 'base-context-provider'
import 'base-context-provider/dist/index.css'
class Example extends Component {
render() {
return <MyComponent />
}
}
```
## License ## License
MIT © [vuthpov](https://github.com/vuthpov) MIT © [vuthpov](https://github.com/vuthpov)

View File

@ -17,8 +17,8 @@
"@types/node": "link:../node_modules/@types/node", "@types/node": "link:../node_modules/@types/node",
"@types/react": "link:../node_modules/@types/react", "@types/react": "link:../node_modules/@types/react",
"@types/react-dom": "link:../node_modules/@types/react-dom", "@types/react-dom": "link:../node_modules/@types/react-dom",
"react": "link:../node_modules/react", "react": "^16.13.1",
"react-dom": "link:../node_modules/react-dom", "react-dom": "^16.13.1",
"react-scripts": "link:../node_modules/react-scripts", "react-scripts": "link:../node_modules/react-scripts",
"typescript": "link:../node_modules/typescript", "typescript": "link:../node_modules/typescript",
"base-context-provider": "link:.." "base-context-provider": "link:.."

View File

@ -1,10 +1,11 @@
import React from 'react' import React from 'react'
import {wrapTestProvider} from './TestContext'
import { ExampleComponent } from 'base-context-provider' import Button from './Button'
import 'base-context-provider/dist/index.css'
const App = () => { const App = () => {
return <ExampleComponent text="Create React Library Example 😄" /> return <div>hello
<Button/>
</div>
} }
export default App export default wrapTestProvider(App)

15
example/src/Button.tsx Normal file
View File

@ -0,0 +1,15 @@
import React from 'react'
import { useTestContext, withTestContext } from './TestContext'
const Button = (props: any) => {
const {punishmentLevel} = props.testContextProps
const { heat }: any = useTestContext()
return (
<div>
heat: {heat} <br/>
levels: {punishmentLevel}
</div>
)
}
export default withTestContext(Button)

View File

@ -0,0 +1,33 @@
import React from 'react'
import BaseContextProvider, {
baseContextWrap,
baseUseContext,
baseWithContext
} from 'base-context-provider'
const Context = React.createContext({})
class TestContextProvider extends BaseContextProvider {
state = {
heat: 5,
punishmentLevel: 10
}
getContextReturnValue() {
return {
...this.state
}
}
getContext() {
return Context
}
}
export const useTestContext = baseUseContext(Context)
export const withTestContext = baseWithContext(Context, 'testContextProps')
export const wrapTestProvider = baseContextWrap(TestContextProvider)
export default TestContextProvider

View File

@ -1,5 +1,4 @@
import './index.css' import './index.css'
import React from 'react' import React from 'react'
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
import App from './App' import App from './App'

View File

@ -2,7 +2,10 @@
"compilerOptions": { "compilerOptions": {
"outDir": "dist", "outDir": "dist",
"module": "esnext", "module": "esnext",
"lib": ["dom", "esnext"], "lib": [
"dom",
"esnext"
],
"moduleResolution": "node", "moduleResolution": "node",
"jsx": "react", "jsx": "react",
"sourceMap": true, "sourceMap": true,
@ -15,8 +18,21 @@
"suppressImplicitAnyIndexErrors": true, "suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true, "noUnusedLocals": true,
"noUnusedParameters": true, "noUnusedParameters": true,
"allowSyntheticDefaultImports": true "allowSyntheticDefaultImports": true,
"target": "es5",
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true
}, },
"include": ["src"], "include": [
"exclude": ["node_modules", "build"] "src"
],
"exclude": [
"node_modules",
"build"
]
} }

View File

@ -8687,9 +8687,15 @@ react-dev-utils@^10.2.1:
strip-ansi "6.0.0" strip-ansi "6.0.0"
text-table "0.2.0" text-table "0.2.0"
"react-dom@link:../node_modules/react-dom": react-dom@^16.13.1:
version "0.0.0" version "16.13.1"
uid "" resolved "https://npm-registry.cubetiqs.com/react-dom/-/react-dom-16.13.1.tgz#c1bd37331a0486c078ee54c4740720993b2e0e7f"
integrity sha512-81PIMmVLnCNLO/fFOQxdQkvEq/+Hfpv24XNJfpyZhTRfO0QcmQIF/PgCa1zCOj2w1hrn12MFLyaJ/G0+Mxtfag==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.19.1"
react-error-overlay@^6.0.7: react-error-overlay@^6.0.7:
version "6.0.7" version "6.0.7"
@ -8705,9 +8711,14 @@ react-is@^16.12.0, react-is@^16.8.1, react-is@^16.8.4:
version "0.0.0" version "0.0.0"
uid "" uid ""
"react@link:../node_modules/react": react@^16.13.1:
version "0.0.0" version "16.13.1"
uid "" resolved "https://npm-registry.cubetiqs.com/react/-/react-16.13.1.tgz#2e818822f1a9743122c063d6410d85c1e3afe48e"
integrity sha512-YMZQQq32xHLX0bz5Mnibv1/LHb3Sqzngu7xstSM+vrkE5Kzr9xE0yMByK5kMoTK30YVJE61WfbxIFFvfeDKT1w==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
read-pkg-up@^2.0.0: read-pkg-up@^2.0.0:
version "2.0.0" version "2.0.0"

View File

@ -24,7 +24,8 @@
"deploy": "gh-pages -d example/build" "deploy": "gh-pages -d example/build"
}, },
"peerDependencies": { "peerDependencies": {
"react": "^16.0.0" "react": "^16.0.0",
"react-dom": "^16.0.0"
}, },
"devDependencies": { "devDependencies": {
"@testing-library/jest-dom": "^4.2.4", "@testing-library/jest-dom": "^4.2.4",
@ -52,8 +53,6 @@
"gh-pages": "^2.2.0", "gh-pages": "^2.2.0",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"prettier": "^2.0.4", "prettier": "^2.0.4",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "^3.4.1", "react-scripts": "^3.4.1",
"typescript": "^3.7.5" "typescript": "^3.7.5"
}, },

View File

@ -1,7 +0,0 @@
import { ExampleComponent } from '.'
describe('ExampleComponent', () => {
it('is truthy', () => {
expect(ExampleComponent).toBeTruthy()
})
})

View File

@ -1,10 +1,55 @@
import * as React from 'react' import React from 'react'
import styles from './styles.module.css'
interface Props { const BaseContext = React.createContext({})
text: string
/**
* Component : BaseContextProvider
*
* @author sl
* @time 13/2/20
* @param {{}}
* @constructor
*
*/
class BaseContextProvider extends React.Component {
getContextReturnValue() {
return {}
}
getContext() {
return BaseContext
}
render() {
const contextReturn = this.getContextReturnValue()
const Context = this.getContext()
const { children } = this.props
return <Context.Provider value={contextReturn}>{children}</Context.Provider>
}
} }
export const ExampleComponent = ({ text }: Props) => { export const baseContextWrap = (Provider: any) => {
return <div className={styles.test}>Example Component: {text}</div> return (Component: any) => (props: any) => (
<Provider children={<Component {...props} />} />
)
} }
export function baseUseContext(context: any) {
return function () {
return React.useContext(context)
}
}
export function baseWithContext(context: any, contextPassPropKey: any) {
const Consumer = context.Consumer
return (Component: any) => (props: any) => (
<Consumer>
{(contextValue: any) => (
<Component {...{ ...props, [contextPassPropKey]: contextValue }} />
)}
</Consumer>
)
}
export default BaseContextProvider

View File

@ -1,9 +0,0 @@
/* add css module styles here (optional) */
.test {
margin: 2em;
padding: 0.5em;
border: 2px solid #000;
font-size: 2em;
text-align: center;
}

17
src/typings.d.ts vendored
View File

@ -1,17 +0,0 @@
/**
* Default CSS definition for typescript,
* will be overridden with file-specific definitions by rollup
*/
declare module '*.css' {
const content: { [className: string]: string };
export default content;
}
interface SvgrComponent extends React.StatelessComponent<React.SVGAttributes<SVGElement>> {}
declare module '*.svg' {
const svgUrl: string;
const svgComponent: SvgrComponent;
export default svgUrl;
export { svgComponent as ReactComponent }
}

View File

@ -7200,7 +7200,7 @@ loglevel@^1.6.6:
resolved "https://npm-registry.cubetiqs.com/loglevel/-/loglevel-1.6.8.tgz#8a25fb75d092230ecd4457270d80b54e28011171" resolved "https://npm-registry.cubetiqs.com/loglevel/-/loglevel-1.6.8.tgz#8a25fb75d092230ecd4457270d80b54e28011171"
integrity sha512-bsU7+gc9AJ2SqpzxwU3+1fedl8zAntbtC5XYlt3s2j1hJcn2PsXSmgN8TaLG/J1/2mod4+cE/3vNL70/c1RNCA== integrity sha512-bsU7+gc9AJ2SqpzxwU3+1fedl8zAntbtC5XYlt3s2j1hJcn2PsXSmgN8TaLG/J1/2mod4+cE/3vNL70/c1RNCA==
loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.4.0: loose-envify@^1.0.0, loose-envify@^1.4.0:
version "1.4.0" version "1.4.0"
resolved "https://npm-registry.cubetiqs.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" resolved "https://npm-registry.cubetiqs.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q== integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
@ -9265,7 +9265,7 @@ prompts@^2.0.1:
kleur "^3.0.3" kleur "^3.0.3"
sisteransi "^1.0.4" sisteransi "^1.0.4"
prop-types@^15.6.2, prop-types@^15.7.2: prop-types@^15.7.2:
version "15.7.2" version "15.7.2"
resolved "https://npm-registry.cubetiqs.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5" resolved "https://npm-registry.cubetiqs.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ== integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
@ -9461,16 +9461,6 @@ react-dev-utils@^10.2.1:
strip-ansi "6.0.0" strip-ansi "6.0.0"
text-table "0.2.0" text-table "0.2.0"
react-dom@^16.13.1:
version "16.13.1"
resolved "https://npm-registry.cubetiqs.com/react-dom/-/react-dom-16.13.1.tgz#c1bd37331a0486c078ee54c4740720993b2e0e7f"
integrity sha512-81PIMmVLnCNLO/fFOQxdQkvEq/+Hfpv24XNJfpyZhTRfO0QcmQIF/PgCa1zCOj2w1hrn12MFLyaJ/G0+Mxtfag==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.19.1"
react-error-overlay@^6.0.7: react-error-overlay@^6.0.7:
version "6.0.7" version "6.0.7"
resolved "https://npm-registry.cubetiqs.com/react-error-overlay/-/react-error-overlay-6.0.7.tgz#1dcfb459ab671d53f660a991513cb2f0a0553108" resolved "https://npm-registry.cubetiqs.com/react-error-overlay/-/react-error-overlay-6.0.7.tgz#1dcfb459ab671d53f660a991513cb2f0a0553108"
@ -9541,15 +9531,6 @@ react-scripts@^3.4.1:
optionalDependencies: optionalDependencies:
fsevents "2.1.2" fsevents "2.1.2"
react@^16.13.1:
version "16.13.1"
resolved "https://npm-registry.cubetiqs.com/react/-/react-16.13.1.tgz#2e818822f1a9743122c063d6410d85c1e3afe48e"
integrity sha512-YMZQQq32xHLX0bz5Mnibv1/LHb3Sqzngu7xstSM+vrkE5Kzr9xE0yMByK5kMoTK30YVJE61WfbxIFFvfeDKT1w==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
read-pkg-up@^2.0.0: read-pkg-up@^2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://npm-registry.cubetiqs.com/read-pkg-up/-/read-pkg-up-2.0.0.tgz#6b72a8048984e0c41e79510fd5e9fa99b3b549be" resolved "https://npm-registry.cubetiqs.com/read-pkg-up/-/read-pkg-up-2.0.0.tgz#6b72a8048984e0c41e79510fd5e9fa99b3b549be"
@ -10153,14 +10134,6 @@ saxes@^3.1.9:
dependencies: dependencies:
xmlchars "^2.1.1" xmlchars "^2.1.1"
scheduler@^0.19.1:
version "0.19.1"
resolved "https://npm-registry.cubetiqs.com/scheduler/-/scheduler-0.19.1.tgz#4f3e2ed2c1a7d65681f4c854fa8c5a1ccb40f196"
integrity sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
schema-utils@^1.0.0: schema-utils@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://npm-registry.cubetiqs.com/schema-utils/-/schema-utils-1.0.0.tgz#0b79a93204d7b600d4b2850d1f66c2a34951c770" resolved "https://npm-registry.cubetiqs.com/schema-utils/-/schema-utils-1.0.0.tgz#0b79a93204d7b600d4b2850d1f66c2a34951c770"