init lib
This commit is contained in:
parent
fd1e253177
commit
64ab6e4247
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal 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/
|
9
.idea/base-context-provider.iml
Normal file
9
.idea/base-context-provider.iml
Normal 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>
|
40
.idea/codeStyles/Project.xml
Normal file
40
.idea/codeStyles/Project.xml
Normal 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>
|
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
</state>
|
||||
</component>
|
6
.idea/inspectionProfiles/Project_Default.xml
Normal file
6
.idea/inspectionProfiles/Project_Default.xml
Normal 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
9
.idea/misc.xml
Normal 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
8
.idea/modules.xml
Normal 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
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
21
README.md
21
README.md
@ -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)
|
||||
|
||||
## 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
|
||||
|
||||
MIT © [vuthpov](https://github.com/vuthpov)
|
||||
|
@ -17,8 +17,8 @@
|
||||
"@types/node": "link:../node_modules/@types/node",
|
||||
"@types/react": "link:../node_modules/@types/react",
|
||||
"@types/react-dom": "link:../node_modules/@types/react-dom",
|
||||
"react": "link:../node_modules/react",
|
||||
"react-dom": "link:../node_modules/react-dom",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-scripts": "link:../node_modules/react-scripts",
|
||||
"typescript": "link:../node_modules/typescript",
|
||||
"base-context-provider": "link:.."
|
||||
|
@ -1,10 +1,11 @@
|
||||
import React from 'react'
|
||||
|
||||
import { ExampleComponent } from 'base-context-provider'
|
||||
import 'base-context-provider/dist/index.css'
|
||||
import {wrapTestProvider} from './TestContext'
|
||||
import Button from './Button'
|
||||
|
||||
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
15
example/src/Button.tsx
Normal 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)
|
33
example/src/TestContext.ts
Normal file
33
example/src/TestContext.ts
Normal 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
|
@ -1,5 +1,4 @@
|
||||
import './index.css'
|
||||
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import App from './App'
|
||||
|
@ -2,7 +2,10 @@
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"module": "esnext",
|
||||
"lib": ["dom", "esnext"],
|
||||
"lib": [
|
||||
"dom",
|
||||
"esnext"
|
||||
],
|
||||
"moduleResolution": "node",
|
||||
"jsx": "react",
|
||||
"sourceMap": true,
|
||||
@ -15,8 +18,21 @@
|
||||
"suppressImplicitAnyIndexErrors": true,
|
||||
"noUnusedLocals": 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"],
|
||||
"exclude": ["node_modules", "build"]
|
||||
"include": [
|
||||
"src"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"build"
|
||||
]
|
||||
}
|
||||
|
@ -8687,9 +8687,15 @@ react-dev-utils@^10.2.1:
|
||||
strip-ansi "6.0.0"
|
||||
text-table "0.2.0"
|
||||
|
||||
"react-dom@link:../node_modules/react-dom":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
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:
|
||||
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"
|
||||
uid ""
|
||||
|
||||
"react@link:../node_modules/react":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
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:
|
||||
version "2.0.0"
|
||||
|
@ -24,7 +24,8 @@
|
||||
"deploy": "gh-pages -d example/build"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.0.0"
|
||||
"react": "^16.0.0",
|
||||
"react-dom": "^16.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@testing-library/jest-dom": "^4.2.4",
|
||||
@ -52,8 +53,6 @@
|
||||
"gh-pages": "^2.2.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"prettier": "^2.0.4",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-scripts": "^3.4.1",
|
||||
"typescript": "^3.7.5"
|
||||
},
|
||||
|
@ -1,7 +0,0 @@
|
||||
import { ExampleComponent } from '.'
|
||||
|
||||
describe('ExampleComponent', () => {
|
||||
it('is truthy', () => {
|
||||
expect(ExampleComponent).toBeTruthy()
|
||||
})
|
||||
})
|
@ -1,10 +1,55 @@
|
||||
import * as React from 'react'
|
||||
import styles from './styles.module.css'
|
||||
import React from 'react'
|
||||
|
||||
interface Props {
|
||||
text: string
|
||||
const BaseContext = React.createContext({})
|
||||
|
||||
/**
|
||||
* Component : BaseContextProvider
|
||||
*
|
||||
* @author sl
|
||||
* @time 13/2/20
|
||||
* @param {{}}
|
||||
* @constructor
|
||||
*
|
||||
*/
|
||||
class BaseContextProvider extends React.Component {
|
||||
getContextReturnValue() {
|
||||
return {}
|
||||
}
|
||||
|
||||
export const ExampleComponent = ({ text }: Props) => {
|
||||
return <div className={styles.test}>Example Component: {text}</div>
|
||||
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 baseContextWrap = (Provider: any) => {
|
||||
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
|
||||
|
@ -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
17
src/typings.d.ts
vendored
@ -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 }
|
||||
}
|
31
yarn.lock
31
yarn.lock
@ -7200,7 +7200,7 @@ loglevel@^1.6.6:
|
||||
resolved "https://npm-registry.cubetiqs.com/loglevel/-/loglevel-1.6.8.tgz#8a25fb75d092230ecd4457270d80b54e28011171"
|
||||
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"
|
||||
resolved "https://npm-registry.cubetiqs.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
|
||||
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
|
||||
@ -9265,7 +9265,7 @@ prompts@^2.0.1:
|
||||
kleur "^3.0.3"
|
||||
sisteransi "^1.0.4"
|
||||
|
||||
prop-types@^15.6.2, prop-types@^15.7.2:
|
||||
prop-types@^15.7.2:
|
||||
version "15.7.2"
|
||||
resolved "https://npm-registry.cubetiqs.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
|
||||
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
|
||||
@ -9461,16 +9461,6 @@ react-dev-utils@^10.2.1:
|
||||
strip-ansi "6.0.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:
|
||||
version "6.0.7"
|
||||
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:
|
||||
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:
|
||||
version "2.0.0"
|
||||
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:
|
||||
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:
|
||||
version "1.0.0"
|
||||
resolved "https://npm-registry.cubetiqs.com/schema-utils/-/schema-utils-1.0.0.tgz#0b79a93204d7b600d4b2850d1f66c2a34951c770"
|
||||
|
Loading…
Reference in New Issue
Block a user