@salty-css/core 0.0.1-alpha.7 → 0.0.1-alpha.9
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +22 -18
- package/config/config-types.d.ts +3 -3
- package/generator/index.cjs +1 -1
- package/generator/index.js +14 -13
- package/generator/style-generator.d.ts +3 -4
- package/package.json +1 -1
- package/types/index.d.ts +4 -1
package/README.md
CHANGED
@@ -54,8 +54,10 @@ export const IndexPage = () => {
|
|
54
54
|
import { styled } from '@salty-css/react/styled';
|
55
55
|
|
56
56
|
export const Wrapper = styled('div', {
|
57
|
-
|
58
|
-
|
57
|
+
base: {
|
58
|
+
display: 'block',
|
59
|
+
padding: '2vw',
|
60
|
+
},
|
59
61
|
});
|
60
62
|
```
|
61
63
|
|
@@ -65,22 +67,24 @@ export const Wrapper = styled('div', {
|
|
65
67
|
import { styled } from '@salty-css/react/styled';
|
66
68
|
|
67
69
|
export const Button = styled('button', {
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
70
|
+
base: {
|
71
|
+
display: 'block',
|
72
|
+
padding: `0.6em 1.2em`,
|
73
|
+
border: '1px solid currentColor',
|
74
|
+
background: 'transparent',
|
75
|
+
color: 'currentColor/40',
|
76
|
+
cursor: 'pointer',
|
77
|
+
transition: '200ms',
|
78
|
+
textDecoration: 'none',
|
79
|
+
'&:hover': {
|
80
|
+
background: 'black',
|
81
|
+
borderColor: 'black',
|
82
|
+
color: 'white',
|
83
|
+
},
|
84
|
+
'&:disabled': {
|
85
|
+
opacity: 0.25,
|
86
|
+
pointerEvents: 'none',
|
87
|
+
},
|
84
88
|
},
|
85
89
|
variants: {
|
86
90
|
variant: {
|
package/config/config-types.d.ts
CHANGED
@@ -30,11 +30,11 @@ export interface SaltyConfig {
|
|
30
30
|
* - `root` will import the css file from the root of the project.
|
31
31
|
* - `component` will import the css file from the component's directory.
|
32
32
|
*/
|
33
|
-
importStrategy
|
33
|
+
importStrategy?: 'root' | 'component';
|
34
34
|
/**
|
35
35
|
* Base variables that can be used in all styles as they are applied globally to :root.
|
36
36
|
*/
|
37
|
-
variables
|
37
|
+
variables?: CssVariables;
|
38
38
|
/**
|
39
39
|
* Variables that are defined for different media queries.
|
40
40
|
*/
|
@@ -46,7 +46,7 @@ export interface SaltyConfig {
|
|
46
46
|
/**
|
47
47
|
* The global styles that are imported in the root of the project.
|
48
48
|
*/
|
49
|
-
global
|
49
|
+
global?: CssStyles;
|
50
50
|
/**
|
51
51
|
* The templates that can be used in styles to create reusable css.
|
52
52
|
*/
|
package/generator/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../util/index.cjs"),
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../util/index.cjs"),i=require("../parse-templates-BY1Xai-_.cjs");class o{constructor(t,s){this.tagName=t,this.params=s}get hash(){return n.toHash(this.params.base||this.params)}get priority(){var t;return typeof this.tagName=="function"||typeof this.tagName=="object"?(((t=this.tagName.generator)==null?void 0:t.priority)||0)+1:0}get classNames(){const t=[this.hash],{className:s}=this.params;return s&&t.push(s),t.join(" ")}get cssClassName(){return this.hash}get cssDisplayNameVar(){return`--${this.hash}-display-name: ${this._callerName};`}get templateKeys(){var t;return(t=this._context)!=null&&t.config.templates?i.getTemplateKeys(this._context.config.templates):[]}get css(){var a;const{base:t={},variants:s={},compoundVariants:e=[]}=this.params,r={...t,variants:s,compoundVariants:e};return i.parseStyles(r,`.${this.cssClassName}`,this.priority,(a=this._context)==null?void 0:a.config)}get props(){const{element:t}=this.params,s=this.params.variants?Object.keys(this.params.variants).map(e=>{var a;const r=(a=this.params.defaultVariants)==null?void 0:a[e];return r!==void 0?`${e}=${String(r)}`:e}):void 0;return{element:t,variantKeys:s}}_withBuildContext(t){this._context=t;const{name:s,config:e}=t;return this._callerName=s,this}}exports.StyleComponentGenerator=o;
|
package/generator/index.js
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
import { toHash as
|
1
|
+
import { toHash as i } from "../util/index.js";
|
2
2
|
import { g as n, p as o } from "../parse-templates-BOSK0Tb6.js";
|
3
3
|
class p {
|
4
|
-
constructor(t, s
|
5
|
-
this.tagName = t, this.
|
4
|
+
constructor(t, s) {
|
5
|
+
this.tagName = t, this.params = s;
|
6
6
|
}
|
7
7
|
get hash() {
|
8
|
-
return
|
8
|
+
return i(this.params.base || this.params);
|
9
9
|
}
|
10
10
|
get priority() {
|
11
11
|
var t;
|
12
|
-
return typeof this.tagName == "function" ? (((t = this.tagName.generator) == null ? void 0 : t.priority) || 0) + 1 : 0;
|
12
|
+
return typeof this.tagName == "function" || typeof this.tagName == "object" ? (((t = this.tagName.generator) == null ? void 0 : t.priority) || 0) + 1 : 0;
|
13
13
|
}
|
14
14
|
get classNames() {
|
15
|
-
const t = [this.hash], { className: s } = this.
|
15
|
+
const t = [this.hash], { className: s } = this.params;
|
16
16
|
return s && t.push(s), t.join(" ");
|
17
17
|
}
|
18
18
|
get cssClassName() {
|
@@ -26,14 +26,15 @@ class p {
|
|
26
26
|
return (t = this._context) != null && t.config.templates ? n(this._context.config.templates) : [];
|
27
27
|
}
|
28
28
|
get css() {
|
29
|
-
var
|
30
|
-
|
29
|
+
var e;
|
30
|
+
const { base: t = {}, variants: s = {}, compoundVariants: a = [] } = this.params, r = { ...t, variants: s, compoundVariants: a };
|
31
|
+
return o(r, `.${this.cssClassName}`, this.priority, (e = this._context) == null ? void 0 : e.config);
|
31
32
|
}
|
32
33
|
get props() {
|
33
|
-
const { element: t } = this.
|
34
|
-
var
|
35
|
-
const
|
36
|
-
return
|
34
|
+
const { element: t } = this.params, s = this.params.variants ? Object.keys(this.params.variants).map((a) => {
|
35
|
+
var e;
|
36
|
+
const r = (e = this.params.defaultVariants) == null ? void 0 : e[a];
|
37
|
+
return r !== void 0 ? `${a}=${String(r)}` : a;
|
37
38
|
}) : void 0;
|
38
39
|
return {
|
39
40
|
element: t,
|
@@ -42,7 +43,7 @@ class p {
|
|
42
43
|
}
|
43
44
|
_withBuildContext(t) {
|
44
45
|
this._context = t;
|
45
|
-
const { name: s, config:
|
46
|
+
const { name: s, config: a } = t;
|
46
47
|
return this._callerName = s, this;
|
47
48
|
}
|
48
49
|
}
|
@@ -1,14 +1,13 @@
|
|
1
|
-
import {
|
1
|
+
import { StyledParams, Tag } from '../types';
|
2
2
|
export declare class StyleComponentGenerator {
|
3
3
|
tagName: Tag<any>;
|
4
|
-
|
5
|
-
private options;
|
4
|
+
params: StyledParams;
|
6
5
|
_callerName: string | undefined;
|
7
6
|
_context: {
|
8
7
|
name: string;
|
9
8
|
config: any;
|
10
9
|
} | undefined;
|
11
|
-
constructor(tagName: Tag<any>,
|
10
|
+
constructor(tagName: Tag<any>, params: StyledParams);
|
12
11
|
get hash(): string;
|
13
12
|
get priority(): number;
|
14
13
|
get classNames(): string;
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
@@ -38,7 +38,7 @@ type Variants = {
|
|
38
38
|
compoundVariants?: CompoundVariant[];
|
39
39
|
};
|
40
40
|
type VariantPropValue<T> = T extends 'true' ? 'true' | true : T;
|
41
|
-
export type VariantProps<STYLES extends
|
41
|
+
export type VariantProps<STYLES extends StyledParams> = STYLES['variants'] extends undefined ? {} : {
|
42
42
|
[K in keyof STYLES['variants']]?: VariantPropValue<keyof STYLES['variants'][K]> | '';
|
43
43
|
};
|
44
44
|
export type ParentComponentProps<TAG extends Tag<any>> = TAG extends (props: infer P) => ReactNode ? P : unknown;
|
@@ -52,4 +52,7 @@ export interface GeneratorOptions {
|
|
52
52
|
displayName?: string;
|
53
53
|
element?: string;
|
54
54
|
}
|
55
|
+
export interface StyledParams extends GeneratorOptions, Variants {
|
56
|
+
base?: CssStyles;
|
57
|
+
}
|
55
58
|
export {};
|