@modular-component/with-components 0.1.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.
- package/CHANGELOG.md +12 -0
- package/LICENSE +13 -0
- package/README.md +48 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
- package/src/index.ts +10 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright © Jérémie van der Sande
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
4
|
+
documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
|
|
5
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
6
|
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
7
|
+
|
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
9
|
+
|
|
10
|
+
The Software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the
|
|
11
|
+
warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or
|
|
12
|
+
copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise,
|
|
13
|
+
arising from, out of or in connection with the software or the use or other dealings in the Software.
|
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# `@modular-component/with-components`
|
|
2
|
+
|
|
3
|
+
Provides a `withComponents` stage that fills the `components` argument with
|
|
4
|
+
a map of React components. Useful when running tests in an environment that
|
|
5
|
+
does not allow module mocking: sub-components can be stubbed in tests by
|
|
6
|
+
calling the stage again to replace their implementations.
|
|
7
|
+
|
|
8
|
+
## Installation and usage
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
yarn add @modular-component/core @modular-component/with-components
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
// Usage in apps
|
|
16
|
+
import { modularFactory } from '@modular-component/core'
|
|
17
|
+
import { WithComponents } from '@modular-component/with-components'
|
|
18
|
+
|
|
19
|
+
const ModularComponent = modularFactory.extend(WithComponents).build()
|
|
20
|
+
|
|
21
|
+
const MyModularComponent = ModularComponent()
|
|
22
|
+
.withComponents({
|
|
23
|
+
SubComponent: () => <h2>Subtitle</h2>,
|
|
24
|
+
})
|
|
25
|
+
.withRender(({ components }) => (
|
|
26
|
+
<>
|
|
27
|
+
<h1>Main Title</h1>
|
|
28
|
+
<components.SubComponent />
|
|
29
|
+
</>
|
|
30
|
+
))
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
// Usage in tests
|
|
35
|
+
|
|
36
|
+
const SubComponentMock = someMock()
|
|
37
|
+
const TestMyModularComponent = MyModularComponent.withComponents({
|
|
38
|
+
SubComponent: SubComponentMock,
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
render(<TestMyModularComponent />)
|
|
42
|
+
|
|
43
|
+
expect(someMock).toHaveBeenCalledOnce()
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Learn more
|
|
47
|
+
|
|
48
|
+
Read the [`ModularComponent` ReadMe](https://github.com/jvdsande/modular-component/blob/master/README.md) for more information about the `ModularComponent` system.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAErC,eAAO,MAAM,cAAc;;;;;CAKhB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAI5D,MAAM,CAAC,MAAM,cAAc,GAAG,kBAAkB,CAAC;IAC/C,cAAc,EAAE;QACd,KAAK,EAAE,YAAY;QACnB,QAAQ,EAAE,EAAwC;KACnD;CACO,CAAC,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@modular-component/with-components",
|
|
3
|
+
"description": "Subcomponents injection for the ModularComponent system",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"React",
|
|
6
|
+
"Modular",
|
|
7
|
+
"Factory",
|
|
8
|
+
"Default",
|
|
9
|
+
"Sub-components",
|
|
10
|
+
"Injection"
|
|
11
|
+
],
|
|
12
|
+
"version": "0.1.0",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"src",
|
|
20
|
+
"dist",
|
|
21
|
+
"CHANGELOG.md"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "yarn build:core && yarn build:self",
|
|
25
|
+
"build:core": "yarn workspace @modular-component/core build",
|
|
26
|
+
"build:self": "tsc -p tsconfig.build.json",
|
|
27
|
+
"license": "cp ../../LICENSE ./LICENSE"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@modular-component/core": "0.1.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"react": ">=17 <19"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/react": "^18.0.17",
|
|
37
|
+
"typescript": "^4.6.4"
|
|
38
|
+
},
|
|
39
|
+
"main": "dist/index.js",
|
|
40
|
+
"types": "dist/index.d.ts"
|
|
41
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createMethodRecord } from '@modular-component/core'
|
|
2
|
+
|
|
3
|
+
import { ComponentType } from 'react'
|
|
4
|
+
|
|
5
|
+
export const WithComponents = createMethodRecord({
|
|
6
|
+
withComponents: {
|
|
7
|
+
field: 'components',
|
|
8
|
+
restrict: {} as Record<string, ComponentType<any>>,
|
|
9
|
+
},
|
|
10
|
+
} as const)
|