@modular-component/with-default-props 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 ADDED
@@ -0,0 +1,12 @@
1
+ # @modular-component/with-default-props
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - be1b38e: Initial release of the ModularComponent system
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [be1b38e]
12
+ - @modular-component/core@0.1.0
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,42 @@
1
+ # `@modular-component/with-default-props`
2
+
3
+ Provides a `withDefaultProps` stage providing default values for props.
4
+
5
+ Correctly updates typing of `props` argument to mark props with default
6
+ values as non-nullable.
7
+
8
+ ## Installation and usage
9
+
10
+ ```bash
11
+ yarn add @modular-component/core @modular-component/with-default-props
12
+ ```
13
+
14
+ ```tsx
15
+ import { modularFactory } from '@modular-component/core'
16
+ import { WithDefaultProps } from '@modular-component/with-default-props'
17
+
18
+ const ModularComponent = modularFactory.extend(WithDefaultProps).build()
19
+
20
+ const MyModularComponent = ModularComponent<{
21
+ content?: {
22
+ title: string
23
+ subtitle: string
24
+ }
25
+ }>()
26
+ .withDefaultProps({
27
+ content: {
28
+ title: 'Default title',
29
+ subtitle: 'Default subtitle',
30
+ },
31
+ })
32
+ .withRender(({ props }) => (
33
+ <>
34
+ <h1>{props.content.title}</h1>
35
+ <h2>{props.content.subtitle}</h2>
36
+ </>
37
+ ))
38
+ ```
39
+
40
+ ## Learn more
41
+
42
+ Read the [`ModularComponent` ReadMe](https://github.com/jvdsande/modular-component/blob/master/README.md) for more information about the `ModularComponent` system.
@@ -0,0 +1,10 @@
1
+ export declare const WithDefaultProps: {
2
+ readonly withDefaultProps: {
3
+ readonly field: "props";
4
+ readonly transform: <A extends {
5
+ props: {};
6
+ }, P>(args: A, props: P) => any;
7
+ readonly restrict: Record<string, unknown>;
8
+ };
9
+ };
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB;;;;mBAGM,EAAE;;;;CAM1B,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ import { createMethodRecord } from '@modular-component/core';
2
+ export const WithDefaultProps = createMethodRecord({
3
+ withDefaultProps: {
4
+ field: 'props',
5
+ transform: (args, props) => ({
6
+ ...(typeof props == 'function' ? props(args) : props),
7
+ ...args.props,
8
+ }),
9
+ restrict: {},
10
+ },
11
+ });
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;IACjD,gBAAgB,EAAE;QAChB,KAAK,EAAE,OAAO;QACd,SAAS,EAAE,CAA6B,IAAO,EAAE,KAAQ,EAAE,EAAE,CAAC,CAAC;YAC7D,GAAG,CAAC,OAAO,KAAK,IAAI,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YACrD,GAAG,IAAI,CAAC,KAAK;SACd,CAAC;QACF,QAAQ,EAAE,EAA6B;KACxC;CACO,CAAC,CAAA"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@modular-component/with-default-props",
3
+ "description": "ModularComponent stage for handling default props. Part of the @modular-component/default package.",
4
+ "keywords": [
5
+ "React",
6
+ "Modular",
7
+ "Factory",
8
+ "Default",
9
+ "Conditional"
10
+ ],
11
+ "version": "0.1.0",
12
+ "type": "module",
13
+ "license": "MIT",
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "files": [
18
+ "src",
19
+ "dist",
20
+ "CHANGELOG.md"
21
+ ],
22
+ "scripts": {
23
+ "build": "yarn build:core && yarn build:self",
24
+ "build:core": "yarn workspace @modular-component/core build",
25
+ "build:self": "tsc -p tsconfig.build.json",
26
+ "license": "cp ../../LICENSE ./LICENSE"
27
+ },
28
+ "dependencies": {
29
+ "@modular-component/core": "0.1.0"
30
+ },
31
+ "devDependencies": {
32
+ "typescript": "^4.6.4"
33
+ },
34
+ "main": "dist/index.js",
35
+ "types": "dist/index.d.ts"
36
+ }
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { createMethodRecord } from '@modular-component/core'
2
+
3
+ export const WithDefaultProps = createMethodRecord({
4
+ withDefaultProps: {
5
+ field: 'props',
6
+ transform: <A extends { props: {} }, P>(args: A, props: P) => ({
7
+ ...(typeof props == 'function' ? props(args) : props),
8
+ ...args.props,
9
+ }),
10
+ restrict: {} as Record<string, unknown>,
11
+ },
12
+ } as const)