@leancodepl/styled-tools 8.4.0 → 8.5.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/README.md CHANGED
@@ -1,7 +1,58 @@
1
- # styled-tools
1
+ # @leancodepl/styled-tools
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ TypeScript utilities for styled-components with type-safe theme access.
4
4
 
5
- ## Running unit tests
5
+ ## Installation
6
6
 
7
- Run `nx test styled-tools` to execute the unit tests via [Jest](https://jestjs.io).
7
+ ```bash
8
+ npm install @leancodepl/styled-tools
9
+ # or
10
+ yarn add @leancodepl/styled-tools
11
+ ```
12
+
13
+ ## API
14
+
15
+ ### `mkTheme()`
16
+
17
+ Creates type-safe theme utilities for styled-components with full TypeScript support.
18
+
19
+ **Returns:** Object containing `theme` proxy and `useTheme` hook
20
+
21
+ ## Usage Examples
22
+
23
+ ### Basic Setup
24
+
25
+ ```typescript
26
+ // theme.ts
27
+ import { mkTheme } from '@leancodepl/styled-tools';
28
+ import styled from 'styled-components';
29
+
30
+ interface AppTheme {
31
+ colors: { primary: string; secondary: string };
32
+ spacing: { small: string; large: string };
33
+ }
34
+
35
+ export const { theme, useTheme } = mkTheme<AppTheme>();
36
+
37
+ const Button = styled.button`
38
+ color: ${theme.colors.primary};
39
+ padding: ${theme.spacing.small};
40
+ `;
41
+ ```
42
+
43
+ ### React Hook Usage
44
+
45
+ ```typescript
46
+ import React from 'react';
47
+ import { useTheme } from './theme';
48
+
49
+ function ThemedComponent() {
50
+ const theme = useTheme();
51
+
52
+ return (
53
+ <div style={{ backgroundColor: theme.colors.primary }}>
54
+ <h1>Themed Component</h1>
55
+ </div>
56
+ );
57
+ }
58
+ ```
package/package.json CHANGED
@@ -1,19 +1,55 @@
1
1
  {
2
2
  "name": "@leancodepl/styled-tools",
3
- "version": "8.4.0",
3
+ "version": "8.5.0",
4
4
  "peerDependencies": {
5
5
  "styled-components": ">=6.0.0"
6
6
  },
7
+ "publishConfig": {
8
+ "access": "public",
9
+ "registry": "https://registry.npmjs.org/"
10
+ },
11
+ "engines": {
12
+ "node": ">=18.0.0"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/leancodepl/js_corelibrary.git",
17
+ "directory": "packages/styled-tools"
18
+ },
19
+ "homepage": "https://github.com/leancodepl/js_corelibrary",
20
+ "bugs": {
21
+ "url": "https://github.com/leancodepl/js_corelibrary/issues"
22
+ },
23
+ "description": "Utilities for styled-components",
24
+ "keywords": [
25
+ "styled-components",
26
+ "theme",
27
+ "css-in-js",
28
+ "react",
29
+ "typescript",
30
+ "javascript",
31
+ "leancode"
32
+ ],
33
+ "author": {
34
+ "name": "LeanCode",
35
+ "url": "https://leancode.co"
36
+ },
37
+ "files": [
38
+ "dist",
39
+ "README.md",
40
+ "CHANGELOG.md"
41
+ ],
42
+ "sideEffects": false,
7
43
  "exports": {
8
44
  "./package.json": "./package.json",
9
45
  ".": {
10
46
  "module": "./index.esm.js",
11
- "types": "./index.esm.d.ts",
47
+ "types": "./index.d.ts",
12
48
  "import": "./index.cjs.mjs",
13
49
  "default": "./index.cjs.js"
14
50
  }
15
51
  },
16
52
  "module": "./index.esm.js",
17
53
  "main": "./index.cjs.js",
18
- "types": "./index.esm.d.ts"
54
+ "types": "./index.d.ts"
19
55
  }
package/index.cjs.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/index";
@@ -1 +0,0 @@
1
- exports._default = require('./index.cjs.js').default;
package/index.cjs.js DELETED
@@ -1,37 +0,0 @@
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
- function mkTheme() {
27
- return {
28
- theme: mkProxy(function(ctx) {
29
- return ctx.theme;
30
- }),
31
- useTheme: function() {
32
- return styledComponents.useTheme();
33
- }
34
- };
35
- }
36
-
37
- exports.mkTheme = mkTheme;
package/index.cjs.mjs DELETED
@@ -1,2 +0,0 @@
1
- export * from './index.cjs.js';
2
- export { _default as default } from './index.cjs.default.js';
package/index.esm.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/index";
package/index.esm.js DELETED
@@ -1,35 +0,0 @@
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
- function mkTheme() {
25
- return {
26
- theme: mkProxy(function(ctx) {
27
- return ctx.theme;
28
- }),
29
- useTheme: function() {
30
- return useTheme();
31
- }
32
- };
33
- }
34
-
35
- export { mkTheme };
package/src/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./lib/mkTheme";
@@ -1,5 +0,0 @@
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;
@@ -1,10 +0,0 @@
1
- import { type ExecutionContext, type RuleSet } from "styled-components";
2
- import { Value } from "./mkProxy";
3
- export declare function mkTheme<TTheme extends Value>(): {
4
- theme: TransformDeep<TTheme>;
5
- useTheme: () => TTheme;
6
- };
7
- type TransformDeep<T> = T extends RuleSet ? (context: ExecutionContext) => RuleSet : T extends Array<infer TArrayElement> ? Array<TransformDeep<TArrayElement>> : T extends object ? {
8
- [TKey in keyof T]: TransformDeep<T[TKey]>;
9
- } : T extends null ? undefined : (context: ExecutionContext) => T;
10
- export {};