@leancodepl/styled-tools 8.5.0 → 8.5.1
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/index.cjs.default.js +1 -0
- package/index.cjs.js +56 -0
- package/index.cjs.mjs +2 -0
- package/index.d.ts +1 -0
- package/index.esm.js +54 -0
- package/package.json +1 -6
- package/src/index.d.ts +1 -0
- package/src/lib/mkProxy.d.ts +5 -0
- package/src/lib/mkTheme.d.ts +30 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
exports._default = require('./index.cjs.js').default;
|
package/index.cjs.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var styledComponents = require('styled-components');
|
|
4
|
+
|
|
5
|
+
function mkProxy(accessor) {
|
|
6
|
+
var cache = {};
|
|
7
|
+
return new Proxy(accessor, {
|
|
8
|
+
get: function get(target, property) {
|
|
9
|
+
var _cache, _property;
|
|
10
|
+
if (property === "prototype") {
|
|
11
|
+
return Function.prototype;
|
|
12
|
+
}
|
|
13
|
+
var _;
|
|
14
|
+
(_ = (_cache = cache)[_property = property]) !== null && _ !== void 0 ? _ : _cache[_property] = mkProxy(function(context) {
|
|
15
|
+
var value = target(context);
|
|
16
|
+
return guard(value) ? value === null || value === void 0 ? void 0 : value[property] : undefined;
|
|
17
|
+
});
|
|
18
|
+
return cache[property];
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function guard(value) {
|
|
23
|
+
return typeof value === "object";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Creates type-safe theme utilities for styled-components with full TypeScript support.
|
|
28
|
+
*
|
|
29
|
+
* @template TTheme - The theme object type extending Value
|
|
30
|
+
* @returns Object containing theme proxy and useTheme hook
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* interface AppTheme {
|
|
34
|
+
* colors: { primary: string; secondary: string };
|
|
35
|
+
* spacing: { small: string; large: string };
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* const { theme, useTheme } = mkTheme<AppTheme>();
|
|
39
|
+
*
|
|
40
|
+
* const Button = styled.button`
|
|
41
|
+
* color: ${theme.colors.primary};
|
|
42
|
+
* padding: ${theme.spacing.small};
|
|
43
|
+
* `;
|
|
44
|
+
* ```
|
|
45
|
+
*/ function mkTheme() {
|
|
46
|
+
return {
|
|
47
|
+
theme: mkProxy(function(ctx) {
|
|
48
|
+
return ctx.theme;
|
|
49
|
+
}),
|
|
50
|
+
useTheme: function() {
|
|
51
|
+
return styledComponents.useTheme();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
exports.mkTheme = mkTheme;
|
package/index.cjs.mjs
ADDED
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
package/index.esm.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useTheme } from 'styled-components';
|
|
2
|
+
|
|
3
|
+
function mkProxy(accessor) {
|
|
4
|
+
var cache = {};
|
|
5
|
+
return new Proxy(accessor, {
|
|
6
|
+
get: function get(target, property) {
|
|
7
|
+
var _cache, _property;
|
|
8
|
+
if (property === "prototype") {
|
|
9
|
+
return Function.prototype;
|
|
10
|
+
}
|
|
11
|
+
var _;
|
|
12
|
+
(_ = (_cache = cache)[_property = property]) !== null && _ !== void 0 ? _ : _cache[_property] = mkProxy(function(context) {
|
|
13
|
+
var value = target(context);
|
|
14
|
+
return guard(value) ? value === null || value === void 0 ? void 0 : value[property] : undefined;
|
|
15
|
+
});
|
|
16
|
+
return cache[property];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function guard(value) {
|
|
21
|
+
return typeof value === "object";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Creates type-safe theme utilities for styled-components with full TypeScript support.
|
|
26
|
+
*
|
|
27
|
+
* @template TTheme - The theme object type extending Value
|
|
28
|
+
* @returns Object containing theme proxy and useTheme hook
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* interface AppTheme {
|
|
32
|
+
* colors: { primary: string; secondary: string };
|
|
33
|
+
* spacing: { small: string; large: string };
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* const { theme, useTheme } = mkTheme<AppTheme>();
|
|
37
|
+
*
|
|
38
|
+
* const Button = styled.button`
|
|
39
|
+
* color: ${theme.colors.primary};
|
|
40
|
+
* padding: ${theme.spacing.small};
|
|
41
|
+
* `;
|
|
42
|
+
* ```
|
|
43
|
+
*/ function mkTheme() {
|
|
44
|
+
return {
|
|
45
|
+
theme: mkProxy(function(ctx) {
|
|
46
|
+
return ctx.theme;
|
|
47
|
+
}),
|
|
48
|
+
useTheme: function() {
|
|
49
|
+
return useTheme();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { mkTheme };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leancodepl/styled-tools",
|
|
3
|
-
"version": "8.5.
|
|
3
|
+
"version": "8.5.1",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"styled-components": ">=6.0.0"
|
|
6
6
|
},
|
|
@@ -34,11 +34,6 @@
|
|
|
34
34
|
"name": "LeanCode",
|
|
35
35
|
"url": "https://leancode.co"
|
|
36
36
|
},
|
|
37
|
-
"files": [
|
|
38
|
-
"dist",
|
|
39
|
-
"README.md",
|
|
40
|
-
"CHANGELOG.md"
|
|
41
|
-
],
|
|
42
37
|
"sideEffects": false,
|
|
43
38
|
"exports": {
|
|
44
39
|
"./package.json": "./package.json",
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./lib/mkTheme";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ExecutionContext, RuleSet } from "styled-components";
|
|
2
|
+
export declare function mkProxy(accessor: (context: ExecutionContext) => Value): (context: ExecutionContext) => Value;
|
|
3
|
+
export type Value = number | RuleSet | string | {
|
|
4
|
+
[key: string | symbol]: Value | undefined;
|
|
5
|
+
} | undefined;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type ExecutionContext, type RuleSet } from "styled-components";
|
|
2
|
+
import { Value } from "./mkProxy";
|
|
3
|
+
/**
|
|
4
|
+
* Creates type-safe theme utilities for styled-components with full TypeScript support.
|
|
5
|
+
*
|
|
6
|
+
* @template TTheme - The theme object type extending Value
|
|
7
|
+
* @returns Object containing theme proxy and useTheme hook
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* interface AppTheme {
|
|
11
|
+
* colors: { primary: string; secondary: string };
|
|
12
|
+
* spacing: { small: string; large: string };
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* const { theme, useTheme } = mkTheme<AppTheme>();
|
|
16
|
+
*
|
|
17
|
+
* const Button = styled.button`
|
|
18
|
+
* color: ${theme.colors.primary};
|
|
19
|
+
* padding: ${theme.spacing.small};
|
|
20
|
+
* `;
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function mkTheme<TTheme extends Value>(): {
|
|
24
|
+
theme: TransformDeep<TTheme>;
|
|
25
|
+
useTheme: () => TTheme;
|
|
26
|
+
};
|
|
27
|
+
type TransformDeep<T> = T extends RuleSet ? (context: ExecutionContext) => RuleSet : T extends Array<infer TArrayElement> ? Array<TransformDeep<TArrayElement>> : T extends object ? {
|
|
28
|
+
[TKey in keyof T]: TransformDeep<T[TKey]>;
|
|
29
|
+
} : T extends null ? undefined : (context: ExecutionContext) => T;
|
|
30
|
+
export {};
|