@themes/react
Advanced tools
| import * as React from 'react' | ||
| import { create } from 'react-test-renderer' | ||
| import { withDefaultProps } from '@themes/react' | ||
| type ButtonProps = { content: string } | ||
| const Button = ({ content }: ButtonProps) => <button>{content}</button> | ||
| const DEFAULT_CONTENT = 'DEFAULT_CONTENT' | ||
| const ButtonWithDefaultContent = withDefaultProps(Button, { content: DEFAULT_CONTENT }) | ||
| describe('with-default-props', () => { | ||
| it(`should use default props to render if not exist`, () => { | ||
| const testRenderer = create(<ButtonWithDefaultContent />) | ||
| expect(testRenderer.root.findByType('button').children).toEqual([DEFAULT_CONTENT]) | ||
| }) | ||
| it(`should using specific props if exist`, () => { | ||
| const testRenderer = create(<ButtonWithDefaultContent content="new content" />) | ||
| expect(testRenderer.root.findByType('button').children).toEqual(['new content']) | ||
| }) | ||
| }) |
| import * as React from 'react' | ||
| import { MarkOptional } from 'ts-essentials' | ||
| export declare function withDefaultProps<P1, P2 extends P1>( | ||
| Component: React.ComponentType<P1>, | ||
| defaultProps: P2, | ||
| ): React.FunctionComponent<MarkOptional<P1, Extract<keyof P1, keyof P2>>> | ||
| //# sourceMappingURL=with-default-props.d.ts.map |
| {"version":3,"file":"with-default-props.d.ts","sourceRoot":"","sources":["../src/with-default-props.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAE5C,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,EAChD,SAAS,EAAE,KAAK,CAAC,aAAa,CAAC,EAAE,CAAC,EAClC,YAAY,EAAE,EAAE,GACf,KAAK,CAAC,iBAAiB,CAAC,YAAY,CAAC,EAAE,EAAE,OAAO,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAIxE"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var tslib_1 = require("tslib"); | ||
| var React = require("react"); | ||
| function withDefaultProps(Component, defaultProps) { | ||
| return function WithDefaultProps(props) { | ||
| return React.createElement(Component, tslib_1.__assign({}, defaultProps, props)); | ||
| }; | ||
| } | ||
| exports.withDefaultProps = withDefaultProps; |
| import * as React from 'react' | ||
| import { MarkOptional } from 'ts-essentials' | ||
| export function withDefaultProps<P1, P2 extends P1>( | ||
| Component: React.ComponentType<P1>, | ||
| defaultProps: P2, | ||
| ): React.FunctionComponent<MarkOptional<P1, Extract<keyof P1, keyof P2>>> { | ||
| return function WithDefaultProps(props) { | ||
| return <Component {...defaultProps} {...props} /> | ||
| } | ||
| } |
| { | ||
| "extends": "../../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "rootDir": "./src", | ||
| "outDir": "./dist", | ||
| "tsBuildInfoFile": "./dist/.tsbuildinfo" | ||
| }, | ||
| "references": [{ "path": "../scheme/tsconfig.build.json" }], | ||
| "include": ["src/**/*"] | ||
| } |
| import * as React from 'react' | ||
| import { create } from 'react-test-renderer' | ||
| import { override, SchemeConfig } from '@themes/scheme' | ||
| import { combine } from '@themes/react' | ||
| import { combine } from '../' | ||
| describe('combine', () => { | ||
@@ -8,0 +8,0 @@ type ButtonType = 'normal' | 'primary' |
| import * as React from 'react' | ||
| import { SchemeConfig } from '@themes/scheme' | ||
| import { create } from 'react-test-renderer' | ||
| import { combine, createContextSchemeConfig, useContextSchemeConfig } from '../' | ||
| import { SchemeConfig } from '@themes/scheme' | ||
| import { combine, createContextSchemeConfig, useContextSchemeConfig } from '@themes/react' | ||
@@ -7,0 +7,0 @@ describe('context-scheme-config', () => { |
| import * as React from 'react' | ||
| import { create } from 'react-test-renderer' | ||
| import { SchemeConfig } from '@themes/scheme' | ||
| import { combine, createSchemeConfigByContext } from '@themes/react' | ||
| import { combine, createSchemeConfigByContext } from '../' | ||
| import { create } from 'react-test-renderer' | ||
| describe('create-scheme-config-by-context', () => { | ||
@@ -8,0 +8,0 @@ type SizeType = 'sm' | 'lg' |
+21
-10
@@ -1,11 +0,22 @@ | ||
| import * as React from 'react'; | ||
| import { SchemeConfig, ValidSchemeKey } from '@themes/scheme'; | ||
| declare type CombinedComponentProps<Props, Config extends CombineConfig<Props>> = Omit<Props, keyof Config> & { | ||
| [Key in keyof Config]?: Key extends keyof Props ? Config[Key] extends SchemeConfig<infer SchemeKey, infer Scheme> ? ValidSchemeKey<SchemeKey, Scheme> : never : never; | ||
| }; | ||
| import * as React from 'react' | ||
| import { SchemeConfig, ValidSchemeKey } from '@themes/scheme' | ||
| declare type CombinedComponentProps<Props, Config extends CombineConfig<Props>> = Omit< | ||
| Props, | ||
| keyof Config | ||
| > & | ||
| { | ||
| [Key in keyof Config]?: Key extends keyof Props | ||
| ? Config[Key] extends SchemeConfig<infer SchemeKey, infer Scheme> | ||
| ? ValidSchemeKey<SchemeKey, Scheme> | ||
| : never | ||
| : never | ||
| } | ||
| declare type CombineConfig<Props> = { | ||
| [Key in keyof Props]?: Props[Key] extends object ? SchemeConfig<any, Props[Key]> : never; | ||
| }; | ||
| export declare function combine<Props, Config extends CombineConfig<any>>(config: Config, Component: React.ComponentType<Props>): React.FunctionComponent<CombinedComponentProps<Props, Config>>; | ||
| export {}; | ||
| //# sourceMappingURL=combine.d.ts.map | ||
| [Key in keyof Props]?: Props[Key] extends object ? SchemeConfig<any, Props[Key]> : never | ||
| } | ||
| export declare function combine<Props, Config extends CombineConfig<any>>( | ||
| config: Config, | ||
| Component: React.ComponentType<Props>, | ||
| ): React.FunctionComponent<CombinedComponentProps<Props, Config>> | ||
| export {} | ||
| //# sourceMappingURL=combine.d.ts.map |
@@ -1,4 +0,7 @@ | ||
| import { SchemeConfig, SchemeKeyType, SchemeType } from '@themes/scheme'; | ||
| import { ContextSchemeConfig } from './types'; | ||
| export declare function createContextSchemeConfig<SchemeKey extends SchemeKeyType, Scheme extends SchemeType>(schemeConfig: SchemeConfig<SchemeKey, Scheme>): ContextSchemeConfig<SchemeKey, Scheme>; | ||
| //# sourceMappingURL=create-context-scheme-config.d.ts.map | ||
| import { SchemeConfig, SchemeKeyType, SchemeType } from '@themes/scheme' | ||
| import { ContextSchemeConfig } from './types' | ||
| export declare function createContextSchemeConfig< | ||
| SchemeKey extends SchemeKeyType, | ||
| Scheme extends SchemeType | ||
| >(schemeConfig: SchemeConfig<SchemeKey, Scheme>): ContextSchemeConfig<SchemeKey, Scheme> | ||
| //# sourceMappingURL=create-context-scheme-config.d.ts.map |
@@ -1,4 +0,4 @@ | ||
| export * from './create-context-scheme-config'; | ||
| export * from './use-context-scheme-config'; | ||
| export * from './types'; | ||
| //# sourceMappingURL=index.d.ts.map | ||
| export * from './create-context-scheme-config' | ||
| export * from './use-context-scheme-config' | ||
| export * from './types' | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,7 +0,14 @@ | ||
| import * as React from 'react'; | ||
| import { SchemeConfig, SchemeKeyType, SchemeType } from '@themes/scheme'; | ||
| export declare type ContextSchemeConfig<SchemeKey extends SchemeKeyType, Scheme extends SchemeType> = Readonly<SchemeConfig<SchemeKey, Scheme> & { | ||
| Context: React.Context<SchemeKey>; | ||
| transform: <SK extends SchemeKeyType, S extends SchemeType>(transformerSchemeConfig: SchemeConfig<SK, (scheme: Scheme) => S>) => SchemeConfig<SK, S>; | ||
| }>; | ||
| //# sourceMappingURL=types.d.ts.map | ||
| import * as React from 'react' | ||
| import { SchemeConfig, SchemeKeyType, SchemeType } from '@themes/scheme' | ||
| export declare type ContextSchemeConfig< | ||
| SchemeKey extends SchemeKeyType, | ||
| Scheme extends SchemeType | ||
| > = Readonly< | ||
| SchemeConfig<SchemeKey, Scheme> & { | ||
| Context: React.Context<SchemeKey> | ||
| transform: <SK extends SchemeKeyType, S extends SchemeType>( | ||
| transformerSchemeConfig: SchemeConfig<SK, (scheme: Scheme) => S>, | ||
| ) => SchemeConfig<SK, S> | ||
| } | ||
| > | ||
| //# sourceMappingURL=types.d.ts.map |
@@ -1,4 +0,7 @@ | ||
| import { SchemeKeyType, SchemeType } from '@themes/scheme'; | ||
| import { ContextSchemeConfig } from './types'; | ||
| export declare function useContextSchemeConfig<SchemeKey extends SchemeKeyType, Scheme extends SchemeType>(schemeConfig: ContextSchemeConfig<SchemeKey, Scheme>): Scheme; | ||
| //# sourceMappingURL=use-context-scheme-config.d.ts.map | ||
| import { SchemeKeyType, SchemeType } from '@themes/scheme' | ||
| import { ContextSchemeConfig } from './types' | ||
| export declare function useContextSchemeConfig< | ||
| SchemeKey extends SchemeKeyType, | ||
| Scheme extends SchemeType | ||
| >(schemeConfig: ContextSchemeConfig<SchemeKey, Scheme>): Scheme | ||
| //# sourceMappingURL=use-context-scheme-config.d.ts.map |
@@ -1,7 +0,15 @@ | ||
| import { SchemeConfig, SchemeKeyType, SchemeType } from '@themes/scheme'; | ||
| import { ContextSchemeConfig } from '../types'; | ||
| export declare function transformByContextSchemeConfig<ContextSchemeKey extends SchemeKeyType, ContextScheme extends SchemeType, SchemeKey extends SchemeKeyType, Scheme extends SchemeType>(contextSchemeConfig: ContextSchemeConfig<ContextSchemeKey, ContextScheme>, transformerSchemeConfig: SchemeConfig<SchemeKey, (context: ContextScheme) => Scheme>): Readonly<{ | ||
| defaultScheme: SchemeKey; | ||
| schemes: Record<SchemeKey, Scheme | (() => Scheme)>; | ||
| }>; | ||
| //# sourceMappingURL=transform-by-context-scheme-config.d.ts.map | ||
| import { SchemeConfig, SchemeKeyType, SchemeType } from '@themes/scheme' | ||
| import { ContextSchemeConfig } from '../types' | ||
| export declare function transformByContextSchemeConfig< | ||
| ContextSchemeKey extends SchemeKeyType, | ||
| ContextScheme extends SchemeType, | ||
| SchemeKey extends SchemeKeyType, | ||
| Scheme extends SchemeType | ||
| >( | ||
| contextSchemeConfig: ContextSchemeConfig<ContextSchemeKey, ContextScheme>, | ||
| transformerSchemeConfig: SchemeConfig<SchemeKey, (context: ContextScheme) => Scheme>, | ||
| ): Readonly<{ | ||
| defaultScheme: SchemeKey | ||
| schemes: Record<SchemeKey, Scheme | (() => Scheme)> | ||
| }> | ||
| //# sourceMappingURL=transform-by-context-scheme-config.d.ts.map |
@@ -1,4 +0,11 @@ | ||
| import { Context } from 'react'; | ||
| import { SchemeConfig, SchemeKeyType, SchemeType } from '@themes/scheme'; | ||
| export declare function createSchemeConfigByContext<ContextValue, SchemeKey extends SchemeKeyType, Scheme extends SchemeType>(context: Context<ContextValue>, transformerSchemeConfig: SchemeConfig<SchemeKey, (context: ContextValue) => Scheme>): SchemeConfig<SchemeKey, Scheme>; | ||
| //# sourceMappingURL=create-scheme-config-by-context.d.ts.map | ||
| import { Context } from 'react' | ||
| import { SchemeConfig, SchemeKeyType, SchemeType } from '@themes/scheme' | ||
| export declare function createSchemeConfigByContext< | ||
| ContextValue, | ||
| SchemeKey extends SchemeKeyType, | ||
| Scheme extends SchemeType | ||
| >( | ||
| context: Context<ContextValue>, | ||
| transformerSchemeConfig: SchemeConfig<SchemeKey, (context: ContextValue) => Scheme>, | ||
| ): SchemeConfig<SchemeKey, Scheme> | ||
| //# sourceMappingURL=create-scheme-config-by-context.d.ts.map |
@@ -1,2 +0,2 @@ | ||
| export * from './use-match-media'; | ||
| //# sourceMappingURL=index.d.ts.map | ||
| export * from './use-match-media' | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
| export declare function useMatchMedia(query: string): boolean; | ||
| //# sourceMappingURL=use-match-media.d.ts.map | ||
| export declare function useMatchMedia(query: string): boolean | ||
| //# sourceMappingURL=use-match-media.d.ts.map |
+6
-5
@@ -1,5 +0,6 @@ | ||
| export * from './context-scheme-config'; | ||
| export * from './create-scheme-config-by-context'; | ||
| export * from './combine'; | ||
| export * from './hooks'; | ||
| //# sourceMappingURL=index.d.ts.map | ||
| export * from './context-scheme-config' | ||
| export * from './create-scheme-config-by-context' | ||
| export * from './combine' | ||
| export * from './hooks' | ||
| export * from './with-default-props' | ||
| //# sourceMappingURL=index.d.ts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AACvC,cAAc,mCAAmC,CAAA;AACjD,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA"} | ||
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AACvC,cAAc,mCAAmC,CAAA;AACjD,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,sBAAsB,CAAA"} |
+1
-0
@@ -8,1 +8,2 @@ "use strict"; | ||
| tslib_1.__exportStar(require("./hooks"), exports); | ||
| tslib_1.__exportStar(require("./with-default-props"), exports); |
+6
-5
| { | ||
| "name": "@themes/react", | ||
| "version": "0.0.31", | ||
| "version": "0.0.32", | ||
| "description": "", | ||
@@ -14,5 +14,5 @@ "license": "MIT", | ||
| "scripts": { | ||
| "build": "yarn run clean && tsc -p tsconfig.json", | ||
| "build": "yarn run clean && tsc -p tsconfig.build.json", | ||
| "clean": "rm -rf ./dist", | ||
| "lint:tsc": "tsc -p tsconfig.json --noEmit", | ||
| "lint:tsc": "tsc -p tsconfig.json --noEmit --composite false", | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
@@ -25,6 +25,7 @@ }, | ||
| "devDependencies": { | ||
| "@themes/scheme": "^0.0.31", | ||
| "@themes/scheme": "^0.0.32", | ||
| "@types/react-test-renderer": "^16.9.1", | ||
| "react-test-renderer": "^16.12.0" | ||
| "react-test-renderer": "^16.12.0", | ||
| "ts-essentials": "^6.0.4" | ||
| } | ||
| } |
+1
-0
@@ -5,1 +5,2 @@ export * from './context-scheme-config' | ||
| export * from './hooks' | ||
| export * from './with-default-props' |
+1
-7
| { | ||
| "extends": "../../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "rootDir": "./src", | ||
| "outDir": "./dist", | ||
| "tsBuildInfoFile": "./dist/.tsbuildinfo" | ||
| }, | ||
| "references": [{ "path": "../scheme" }], | ||
| "include": ["src/**/*"] | ||
| "references": [{ "path": "../scheme/tsconfig.build.json" }] | ||
| } |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
165337
10.38%54
12.5%644
17.95%4
33.33%1
Infinity%