@reykjavik/webtools 0.1.32 → 0.1.33
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 +12 -0
- package/README.md +31 -129
- package/esm/vanillaExtract.d.ts +109 -5
- package/esm/vanillaExtract.js +43 -3
- package/package.json +1 -1
- package/vanillaExtract.d.ts +109 -5
- package/vanillaExtract.js +43 -3
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
- ... <!-- Add new lines here. -->
|
|
6
6
|
|
|
7
|
+
## 0.1.33
|
|
8
|
+
|
|
9
|
+
_2024-10-16_
|
|
10
|
+
|
|
11
|
+
- `@reykjavik/webtools/next/vanillaExtract`:
|
|
12
|
+
- feat: Deprecate `vanillaNest` and `vanillaClassNested` — in favor of
|
|
13
|
+
`vanillaClass` with `className` function parameter, or other home-brew
|
|
14
|
+
solutions.
|
|
15
|
+
- docs: Improve inline JSDocs and README for the `vanilla*` helpers
|
|
16
|
+
- `@reykjavik/webtools/errorhandling`:
|
|
17
|
+
- docs: Improve code examples in README
|
|
18
|
+
|
|
7
19
|
## 0.1.32
|
|
8
20
|
|
|
9
21
|
_2024-10-02_
|
package/README.md
CHANGED
|
@@ -47,11 +47,9 @@ bun add @reykjavik/webtools
|
|
|
47
47
|
- [`CookieHubProvider` component](#cookiehubprovider-component)
|
|
48
48
|
- [`useCookieHubConsent`](#usecookiehubconsent)
|
|
49
49
|
- [`@reykjavik/webtools/vanillaExtract`](#reykjavikwebtoolsvanillaextract)
|
|
50
|
+
- [`vanillaClass`](#vanillaclass)
|
|
50
51
|
- [`vanillaGlobal`](#vanillaglobal)
|
|
51
52
|
- [`vanillaProps`](#vanillaprops)
|
|
52
|
-
- [`vanillaClass`](#vanillaclass)
|
|
53
|
-
- [`vanillaClassNested`](#vanillaclassnested)
|
|
54
|
-
- [`vanillaNest`](#vanillanest)
|
|
55
53
|
- [Framework Specific Tools](#framework-specific-tools)
|
|
56
54
|
- [Remix.run Tools](#remixrun-tools)
|
|
57
55
|
- [Next.js Tools](#nextjs-tools)
|
|
@@ -372,7 +370,7 @@ console.log(posts?.reason); // undefined | unknown
|
|
|
372
370
|
## `@reykjavik/webtools/errorhandling`
|
|
373
371
|
|
|
374
372
|
A small set of lightweight tools for handling errors and promises in a safer,
|
|
375
|
-
more structured, FP-
|
|
373
|
+
more structured, FP-ish way.
|
|
376
374
|
|
|
377
375
|
Errors are always the first return value to promote early, explicit error
|
|
378
376
|
handling.
|
|
@@ -386,7 +384,7 @@ Guarantees that a caught (`catch (e)`) value of `unknown` type, is indeed an
|
|
|
386
384
|
|
|
387
385
|
If the input is an `Error` instance, it is returned as-is. If the input is
|
|
388
386
|
something else it is wrapped in a new `ErrorFromPayload` instance, and the
|
|
389
|
-
original value is stored in a `payload`
|
|
387
|
+
original value is stored in as a `payload` property.
|
|
390
388
|
|
|
391
389
|
```ts
|
|
392
390
|
import { asError, type ErrorFromPayload } from '@reykjavik/webtools/errorhandling';
|
|
@@ -408,6 +406,7 @@ try {
|
|
|
408
406
|
console.error(error === someObject); // false
|
|
409
407
|
console.error(error.message === someObject.join(',')); // false
|
|
410
408
|
console.error(error instanceOf ErrorFromPayload); // true
|
|
409
|
+
|
|
411
410
|
console.error(error.payload === someObject); // true
|
|
412
411
|
}
|
|
413
412
|
```
|
|
@@ -437,7 +436,7 @@ import { type ResultTuple } from '@reykjavik/webtools/errorhandling';
|
|
|
437
436
|
declare const myResult: ResultTuple<string, Error>;
|
|
438
437
|
|
|
439
438
|
const [error, result] = myResult;
|
|
440
|
-
//
|
|
439
|
+
// (One of these two is always `undefined`)
|
|
441
440
|
|
|
442
441
|
if (error) {
|
|
443
442
|
// Here `error` is an Error instance
|
|
@@ -463,7 +462,7 @@ import { type ResultTuple } from '@reykjavik/webtools/errorhandling';
|
|
|
463
462
|
declare const myResult: ResultTuple<string, Error>;
|
|
464
463
|
|
|
465
464
|
const [error, result] = myResult;
|
|
466
|
-
//
|
|
465
|
+
// (One of these two is always `undefined`)
|
|
467
466
|
|
|
468
467
|
if (error) {
|
|
469
468
|
// Here `error` is an Error instance
|
|
@@ -589,7 +588,7 @@ import { Result } from '@reykjavik/webtools/errorhandling';
|
|
|
589
588
|
try {
|
|
590
589
|
const fooResults = Result.throw(await getFooResultsTuple());
|
|
591
590
|
} catch (fooError) {
|
|
592
|
-
// error
|
|
591
|
+
// Do something with the error from `getFooResultsTuple()`
|
|
593
592
|
}
|
|
594
593
|
```
|
|
595
594
|
|
|
@@ -765,48 +764,6 @@ local type-safety for access to the full features and expressiveness of real
|
|
|
765
764
|
CSS.
|
|
766
765
|
([Background info](https://github.com/vanilla-extract-css/vanilla-extract/discussions/898#discussioncomment-7125457).)
|
|
767
766
|
|
|
768
|
-
### `vanillaGlobal`
|
|
769
|
-
|
|
770
|
-
**Syntax:** `vanillaGlobal(css: string): void`
|
|
771
|
-
|
|
772
|
-
Inserts free-form CSS as a vanilla-extract `globalStyle`.
|
|
773
|
-
|
|
774
|
-
```ts
|
|
775
|
-
// someFile.css.ts
|
|
776
|
-
import { vanillaGlobal } from '@reykjavik/webtools/vanillaExtract';
|
|
777
|
-
|
|
778
|
-
vanillaGlobal(`
|
|
779
|
-
body {
|
|
780
|
-
background-color: rebeccapurple;
|
|
781
|
-
}
|
|
782
|
-
`);
|
|
783
|
-
```
|
|
784
|
-
|
|
785
|
-
### `vanillaProps`
|
|
786
|
-
|
|
787
|
-
**Syntax:** `vanillaProps(css: string): GlobalStyleRule`
|
|
788
|
-
|
|
789
|
-
Spreads the return value into a style object, to inject free-form CSS
|
|
790
|
-
properties (or nested blocks)
|
|
791
|
-
|
|
792
|
-
```ts
|
|
793
|
-
// someFile.css.ts
|
|
794
|
-
import { style } from '@vanilla-extract/css';
|
|
795
|
-
import { vanillaProps } from '@reykjavik/webtools/vanillaExtract';
|
|
796
|
-
|
|
797
|
-
const myStyle = style({
|
|
798
|
-
color: 'darksalmon',
|
|
799
|
-
// ...other style props...
|
|
800
|
-
|
|
801
|
-
...vanillaProps(`
|
|
802
|
-
/* Plain CSS that's injected into the "myStyle" style block */
|
|
803
|
-
border-bottom: 1px solid red;
|
|
804
|
-
color: ${theme.color.primary}; /* I can still use typesafe values */
|
|
805
|
-
random-css-prop-normally-rejected-by-vanilla-extract: 'YOLO!';
|
|
806
|
-
`),
|
|
807
|
-
});
|
|
808
|
-
```
|
|
809
|
-
|
|
810
767
|
### `vanillaClass`
|
|
811
768
|
|
|
812
769
|
**Syntax:**
|
|
@@ -854,112 +811,57 @@ export const humanReadableClass = vanillaClass(
|
|
|
854
811
|
);
|
|
855
812
|
```
|
|
856
813
|
|
|
857
|
-
### `
|
|
858
|
-
|
|
859
|
-
**Syntax:** `vanillaClassNested(css: string): string`
|
|
860
|
-
**Syntax:** `vanillaClassNested(debugId: string, css: string): string`
|
|
814
|
+
### `vanillaGlobal`
|
|
861
815
|
|
|
862
|
-
|
|
816
|
+
**Syntax:** `vanillaGlobal(css: string): void`
|
|
863
817
|
|
|
864
|
-
|
|
865
|
-
auto-generated class-name.
|
|
818
|
+
Inserts free-form CSS as a vanilla-extract `globalStyle`.
|
|
866
819
|
|
|
867
820
|
```ts
|
|
868
821
|
// someFile.css.ts
|
|
869
|
-
import {
|
|
870
|
-
|
|
871
|
-
export const myClass = vanillaClassNested(`
|
|
872
|
-
background-color: #ccc;
|
|
873
|
-
padding: .5em 1em;
|
|
822
|
+
import { vanillaGlobal } from '@reykjavik/webtools/vanillaExtract';
|
|
874
823
|
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
background-color:
|
|
878
|
-
color: white;
|
|
879
|
-
}
|
|
880
|
-
& > strong {
|
|
881
|
-
color: maroon;
|
|
882
|
-
}
|
|
883
|
-
html[data-color-theme="unicorn"] & {
|
|
884
|
-
background-color: pink;
|
|
824
|
+
vanillaGlobal(`
|
|
825
|
+
body {
|
|
826
|
+
background-color: rebeccapurple;
|
|
885
827
|
}
|
|
886
828
|
`);
|
|
887
829
|
```
|
|
888
830
|
|
|
889
|
-
|
|
890
|
-
any nested blocks.
|
|
891
|
-
|
|
892
|
-
**NOTE 2:** `vanillaClassNested` does NOT support deeply nested blocks, or
|
|
893
|
-
anything so fancy. It will also replace `&` characters inside values,
|
|
894
|
-
comments, etc. If you need something more sophisticated, use a custom
|
|
895
|
-
`postcss` config.
|
|
896
|
-
|
|
897
|
-
### `vanillaNest`
|
|
898
|
-
|
|
899
|
-
**Syntax:** `vanillaNest(ampSelector: string, css: string): string`
|
|
831
|
+
### `vanillaProps`
|
|
900
832
|
|
|
901
|
-
|
|
902
|
-
"dumb") way. It's mainly useful when used with style-mixins, etc.
|
|
833
|
+
**Syntax:** `vanillaProps(css: string): GlobalStyleRule`
|
|
903
834
|
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
something more sophisticated, use a custom `postcss` config.
|
|
835
|
+
Returns an object that can be safely spread into a vanilla-extract style
|
|
836
|
+
object, to inject free-form CSS properties (or nested blocks).
|
|
907
837
|
|
|
908
838
|
```ts
|
|
909
|
-
//
|
|
910
|
-
import {
|
|
911
|
-
|
|
912
|
-
export const hoverGlow = (
|
|
913
|
-
ampSelector: string,
|
|
914
|
-
glowiness?: 'normal' | 'insane'
|
|
915
|
-
) =>
|
|
916
|
-
vanillaNest(
|
|
917
|
-
ampSelector,
|
|
918
|
-
`
|
|
919
|
-
&:hover {
|
|
920
|
-
box-shadow: 0 0 20px 5px ${
|
|
921
|
-
glowiness === 'insane' ? 'hotpink' : 'salmon'
|
|
922
|
-
};
|
|
923
|
-
}
|
|
924
|
-
`
|
|
925
|
-
);
|
|
926
|
-
|
|
927
|
-
// ...then, somewhere else in a *.css.ts file:
|
|
928
|
-
|
|
929
|
-
import { hoverGlow } from '~/someCssHelper.js';
|
|
930
|
-
import { vanillaGlobal } from '@reykjavik/webtools/vanillaExtract';
|
|
839
|
+
// someFile.css.ts
|
|
840
|
+
import { style } from '@vanilla-extract/css';
|
|
841
|
+
import { vanillaProps } from '@reykjavik/webtools/vanillaExtract';
|
|
931
842
|
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
padding: 1em;
|
|
936
|
-
}
|
|
937
|
-
${hoverGlow('.MyComponent')}
|
|
843
|
+
const myStyle = style({
|
|
844
|
+
color: 'darksalmon',
|
|
845
|
+
// ...other style props...
|
|
938
846
|
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
`)
|
|
847
|
+
...vanillaProps(`
|
|
848
|
+
/* Plain CSS that's injected into the "myStyle" style block */
|
|
849
|
+
border-bottom: 1px solid red;
|
|
850
|
+
color: ${theme.color.primary}; /* I can still use typesafe values */
|
|
851
|
+
random-css-prop-normally-rejected-by-vanilla-extract: 'YOLO!';
|
|
852
|
+
`),
|
|
853
|
+
});
|
|
945
854
|
```
|
|
946
855
|
|
|
947
|
-
(This low-level utility function is used internally by
|
|
948
|
-
[`vanillaClassNested`](#vanillaclassnested).)
|
|
949
|
-
|
|
950
856
|
---
|
|
951
857
|
|
|
952
858
|
## Framework Specific Tools
|
|
953
859
|
|
|
954
|
-
---
|
|
955
|
-
|
|
956
860
|
### Remix.run Tools
|
|
957
861
|
|
|
958
862
|
See [README-remix.md](./README-remix.md) for helpers and components
|
|
959
863
|
specifically designed for use in Remix.run projects.
|
|
960
864
|
|
|
961
|
-
---
|
|
962
|
-
|
|
963
865
|
<!-- #fragment anchors to not break older v0.1 @see links -->
|
|
964
866
|
|
|
965
867
|
<a name="reykjavikwebtoolsnexthttp"></a> <a name="makeerrorizeapphoc"></a>
|
package/esm/vanillaExtract.d.ts
CHANGED
|
@@ -20,27 +20,131 @@ export declare const vanillaProps: (css: string) => GlobalStyleRule;
|
|
|
20
20
|
export declare function vanillaClass(css: string | ((className: string) => string)): string;
|
|
21
21
|
export declare function vanillaClass(debugId: string, css: string | ((className: string) => string)): string;
|
|
22
22
|
/**
|
|
23
|
+
* @deprecated (Will be removed in v0.2)
|
|
24
|
+
*
|
|
23
25
|
* Replaces all `&` tokens with the given selector string, in a direct
|
|
24
26
|
* (read. "dumb") way. It's mainly useful when used with style-mixins, etc.
|
|
25
27
|
*
|
|
26
|
-
* NOTE
|
|
27
|
-
* It will also replace
|
|
28
|
+
* **NOTE:** `vanillaNest` does NOT support deeply nested blocks, or anything
|
|
29
|
+
* so fancy. It will also replace `&` characters inside values, comments, etc.
|
|
28
30
|
* If you need something more sophisticated, use a custom `postcss` config.
|
|
29
31
|
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* // someCssHelper.ts
|
|
34
|
+
* import { vanillaNest } from '@reykjavik/webtools/vanillaExtract';
|
|
35
|
+
*
|
|
36
|
+
* export const hoverGlow = (
|
|
37
|
+
* ampSelector: string,
|
|
38
|
+
* glowiness?: 'normal' | 'insane'
|
|
39
|
+
* ) =>
|
|
40
|
+
* vanillaNest(
|
|
41
|
+
* ampSelector,
|
|
42
|
+
* `
|
|
43
|
+
* &:hover {
|
|
44
|
+
* box-shadow: 0 0 20px 5px ${
|
|
45
|
+
* glowiness === 'insane' ? 'hotpink' : 'salmon'
|
|
46
|
+
* };
|
|
47
|
+
* }
|
|
48
|
+
* `
|
|
49
|
+
* );
|
|
50
|
+
*
|
|
51
|
+
* // ...then, somewhere else in a *.css.ts file:
|
|
52
|
+
*
|
|
53
|
+
* import { hoverGlow } from '~/someCssHelper.js';
|
|
54
|
+
* import { vanillaGlobal } from '@reykjavik/webtools/vanillaExtract';
|
|
55
|
+
*
|
|
56
|
+
* vanillaGlobal(`
|
|
57
|
+
* .MyComponent {
|
|
58
|
+
* border: 1px solid #ccc;
|
|
59
|
+
* padding: 1em;
|
|
60
|
+
* }
|
|
61
|
+
* ${hoverGlow('.MyComponent')}
|
|
62
|
+
*
|
|
63
|
+
* .MyOtherComponent {
|
|
64
|
+
* border: 1px solid #ccc;
|
|
65
|
+
* padding: 1em;
|
|
66
|
+
* }
|
|
67
|
+
* ${hoverGlow('.MyOtherComponent', 'insane')}
|
|
68
|
+
* `);
|
|
69
|
+
* ```
|
|
30
70
|
*
|
|
31
|
-
*
|
|
71
|
+
* (This low-level utility function is used internally by `vanillaClassNested`.
|
|
32
72
|
*/
|
|
33
73
|
export declare const vanillaNest: (ampSelector: string, css: string) => string;
|
|
34
74
|
/**
|
|
75
|
+
* @deprecated (Will be removed in v0.2)
|
|
76
|
+
*
|
|
35
77
|
* Returns a scoped cssClassName styled with free-form CSS.
|
|
36
78
|
*
|
|
37
79
|
* It also automatically replaces all `&`-tokens with
|
|
38
80
|
* the selector for the auto-generated class-name.
|
|
39
81
|
*
|
|
40
|
-
*
|
|
82
|
+
* ```ts
|
|
83
|
+
* // someFile.css.ts
|
|
84
|
+
* import { vanillaClassNested } from '@reykjavik/webtools/vanillaExtract';
|
|
85
|
+
*
|
|
86
|
+
* export const myClass = vanillaClassNested(`
|
|
87
|
+
* background-color: #ccc;
|
|
88
|
+
* padding: .5em 1em;
|
|
89
|
+
*
|
|
90
|
+
* /* Nested blocks begin: */
|
|
91
|
+
* &:hover {
|
|
92
|
+
* background-color: #666;
|
|
93
|
+
* color: white;
|
|
94
|
+
* }
|
|
95
|
+
* & > strong {
|
|
96
|
+
* color: maroon;
|
|
97
|
+
* }
|
|
98
|
+
* html[data-color-theme="unicorn"] & {
|
|
99
|
+
* background-color: pink;
|
|
100
|
+
* }
|
|
101
|
+
* `);
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* **NOTE:** All "bare" (un-nested) style properties **must come first**,
|
|
41
105
|
* before any nested blocks.
|
|
42
106
|
*
|
|
43
|
-
*
|
|
107
|
+
* **NOTE 2:** `vanillaClassNested` does NOT support deeply nested blocks, or
|
|
108
|
+
* anything so fancy. It will also replace `&` characters inside values,
|
|
109
|
+
* comments, etc. If you need something more sophisticated, use a custom
|
|
110
|
+
* `postcss` config.
|
|
44
111
|
*/
|
|
45
112
|
export declare function vanillaClassNested(css: string): string;
|
|
113
|
+
/** @deprecated (Will be removed in v0.2) */
|
|
114
|
+
/**
|
|
115
|
+
* Returns a scoped cssClassName styled with free-form CSS.
|
|
116
|
+
*
|
|
117
|
+
* It also automatically replaces all `&`-tokens with
|
|
118
|
+
* the selector for the auto-generated class-name.
|
|
119
|
+
*
|
|
120
|
+
* ```ts
|
|
121
|
+
* // someFile.css.ts
|
|
122
|
+
* import { vanillaClassNested } from '@reykjavik/webtools/vanillaExtract';
|
|
123
|
+
*
|
|
124
|
+
* export const myClass = vanillaClassNested(`
|
|
125
|
+
* background-color: #ccc;
|
|
126
|
+
* padding: .5em 1em;
|
|
127
|
+
*
|
|
128
|
+
* /* Nested blocks begin: */
|
|
129
|
+
* &:hover {
|
|
130
|
+
* background-color: #666;
|
|
131
|
+
* color: white;
|
|
132
|
+
* }
|
|
133
|
+
* & > strong {
|
|
134
|
+
* color: maroon;
|
|
135
|
+
* }
|
|
136
|
+
* html[data-color-theme="unicorn"] & {
|
|
137
|
+
* background-color: pink;
|
|
138
|
+
* }
|
|
139
|
+
* `);
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* **NOTE:** All "bare" (un-nested) style properties **must come first**,
|
|
143
|
+
* before any nested blocks.
|
|
144
|
+
*
|
|
145
|
+
* **NOTE 2:** `vanillaClassNested` does NOT support deeply nested blocks, or
|
|
146
|
+
* anything so fancy. It will also replace `&` characters inside values,
|
|
147
|
+
* comments, etc. If you need something more sophisticated, use a custom
|
|
148
|
+
* `postcss` config.
|
|
149
|
+
*/
|
|
46
150
|
export declare function vanillaClassNested(debugId: string, css: string): string;
|
package/esm/vanillaExtract.js
CHANGED
|
@@ -25,15 +25,55 @@ export function vanillaClass(cssOrDebugId, css) {
|
|
|
25
25
|
}
|
|
26
26
|
// ---------------------------------------------------------------------------
|
|
27
27
|
/**
|
|
28
|
+
* @deprecated (Will be removed in v0.2)
|
|
29
|
+
*
|
|
28
30
|
* Replaces all `&` tokens with the given selector string, in a direct
|
|
29
31
|
* (read. "dumb") way. It's mainly useful when used with style-mixins, etc.
|
|
30
32
|
*
|
|
31
|
-
* NOTE
|
|
32
|
-
* It will also replace
|
|
33
|
+
* **NOTE:** `vanillaNest` does NOT support deeply nested blocks, or anything
|
|
34
|
+
* so fancy. It will also replace `&` characters inside values, comments, etc.
|
|
33
35
|
* If you need something more sophisticated, use a custom `postcss` config.
|
|
34
36
|
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* // someCssHelper.ts
|
|
39
|
+
* import { vanillaNest } from '@reykjavik/webtools/vanillaExtract';
|
|
40
|
+
*
|
|
41
|
+
* export const hoverGlow = (
|
|
42
|
+
* ampSelector: string,
|
|
43
|
+
* glowiness?: 'normal' | 'insane'
|
|
44
|
+
* ) =>
|
|
45
|
+
* vanillaNest(
|
|
46
|
+
* ampSelector,
|
|
47
|
+
* `
|
|
48
|
+
* &:hover {
|
|
49
|
+
* box-shadow: 0 0 20px 5px ${
|
|
50
|
+
* glowiness === 'insane' ? 'hotpink' : 'salmon'
|
|
51
|
+
* };
|
|
52
|
+
* }
|
|
53
|
+
* `
|
|
54
|
+
* );
|
|
55
|
+
*
|
|
56
|
+
* // ...then, somewhere else in a *.css.ts file:
|
|
57
|
+
*
|
|
58
|
+
* import { hoverGlow } from '~/someCssHelper.js';
|
|
59
|
+
* import { vanillaGlobal } from '@reykjavik/webtools/vanillaExtract';
|
|
60
|
+
*
|
|
61
|
+
* vanillaGlobal(`
|
|
62
|
+
* .MyComponent {
|
|
63
|
+
* border: 1px solid #ccc;
|
|
64
|
+
* padding: 1em;
|
|
65
|
+
* }
|
|
66
|
+
* ${hoverGlow('.MyComponent')}
|
|
67
|
+
*
|
|
68
|
+
* .MyOtherComponent {
|
|
69
|
+
* border: 1px solid #ccc;
|
|
70
|
+
* padding: 1em;
|
|
71
|
+
* }
|
|
72
|
+
* ${hoverGlow('.MyOtherComponent', 'insane')}
|
|
73
|
+
* `);
|
|
74
|
+
* ```
|
|
35
75
|
*
|
|
36
|
-
*
|
|
76
|
+
* (This low-level utility function is used internally by `vanillaClassNested`.
|
|
37
77
|
*/
|
|
38
78
|
export const vanillaNest = (ampSelector, css) => css.replace(/&/g, ampSelector);
|
|
39
79
|
export function vanillaClassNested(cssOrDebugId, css) {
|
package/package.json
CHANGED
package/vanillaExtract.d.ts
CHANGED
|
@@ -20,27 +20,131 @@ export declare const vanillaProps: (css: string) => GlobalStyleRule;
|
|
|
20
20
|
export declare function vanillaClass(css: string | ((className: string) => string)): string;
|
|
21
21
|
export declare function vanillaClass(debugId: string, css: string | ((className: string) => string)): string;
|
|
22
22
|
/**
|
|
23
|
+
* @deprecated (Will be removed in v0.2)
|
|
24
|
+
*
|
|
23
25
|
* Replaces all `&` tokens with the given selector string, in a direct
|
|
24
26
|
* (read. "dumb") way. It's mainly useful when used with style-mixins, etc.
|
|
25
27
|
*
|
|
26
|
-
* NOTE
|
|
27
|
-
* It will also replace
|
|
28
|
+
* **NOTE:** `vanillaNest` does NOT support deeply nested blocks, or anything
|
|
29
|
+
* so fancy. It will also replace `&` characters inside values, comments, etc.
|
|
28
30
|
* If you need something more sophisticated, use a custom `postcss` config.
|
|
29
31
|
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* // someCssHelper.ts
|
|
34
|
+
* import { vanillaNest } from '@reykjavik/webtools/vanillaExtract';
|
|
35
|
+
*
|
|
36
|
+
* export const hoverGlow = (
|
|
37
|
+
* ampSelector: string,
|
|
38
|
+
* glowiness?: 'normal' | 'insane'
|
|
39
|
+
* ) =>
|
|
40
|
+
* vanillaNest(
|
|
41
|
+
* ampSelector,
|
|
42
|
+
* `
|
|
43
|
+
* &:hover {
|
|
44
|
+
* box-shadow: 0 0 20px 5px ${
|
|
45
|
+
* glowiness === 'insane' ? 'hotpink' : 'salmon'
|
|
46
|
+
* };
|
|
47
|
+
* }
|
|
48
|
+
* `
|
|
49
|
+
* );
|
|
50
|
+
*
|
|
51
|
+
* // ...then, somewhere else in a *.css.ts file:
|
|
52
|
+
*
|
|
53
|
+
* import { hoverGlow } from '~/someCssHelper.js';
|
|
54
|
+
* import { vanillaGlobal } from '@reykjavik/webtools/vanillaExtract';
|
|
55
|
+
*
|
|
56
|
+
* vanillaGlobal(`
|
|
57
|
+
* .MyComponent {
|
|
58
|
+
* border: 1px solid #ccc;
|
|
59
|
+
* padding: 1em;
|
|
60
|
+
* }
|
|
61
|
+
* ${hoverGlow('.MyComponent')}
|
|
62
|
+
*
|
|
63
|
+
* .MyOtherComponent {
|
|
64
|
+
* border: 1px solid #ccc;
|
|
65
|
+
* padding: 1em;
|
|
66
|
+
* }
|
|
67
|
+
* ${hoverGlow('.MyOtherComponent', 'insane')}
|
|
68
|
+
* `);
|
|
69
|
+
* ```
|
|
30
70
|
*
|
|
31
|
-
*
|
|
71
|
+
* (This low-level utility function is used internally by `vanillaClassNested`.
|
|
32
72
|
*/
|
|
33
73
|
export declare const vanillaNest: (ampSelector: string, css: string) => string;
|
|
34
74
|
/**
|
|
75
|
+
* @deprecated (Will be removed in v0.2)
|
|
76
|
+
*
|
|
35
77
|
* Returns a scoped cssClassName styled with free-form CSS.
|
|
36
78
|
*
|
|
37
79
|
* It also automatically replaces all `&`-tokens with
|
|
38
80
|
* the selector for the auto-generated class-name.
|
|
39
81
|
*
|
|
40
|
-
*
|
|
82
|
+
* ```ts
|
|
83
|
+
* // someFile.css.ts
|
|
84
|
+
* import { vanillaClassNested } from '@reykjavik/webtools/vanillaExtract';
|
|
85
|
+
*
|
|
86
|
+
* export const myClass = vanillaClassNested(`
|
|
87
|
+
* background-color: #ccc;
|
|
88
|
+
* padding: .5em 1em;
|
|
89
|
+
*
|
|
90
|
+
* /* Nested blocks begin: */
|
|
91
|
+
* &:hover {
|
|
92
|
+
* background-color: #666;
|
|
93
|
+
* color: white;
|
|
94
|
+
* }
|
|
95
|
+
* & > strong {
|
|
96
|
+
* color: maroon;
|
|
97
|
+
* }
|
|
98
|
+
* html[data-color-theme="unicorn"] & {
|
|
99
|
+
* background-color: pink;
|
|
100
|
+
* }
|
|
101
|
+
* `);
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* **NOTE:** All "bare" (un-nested) style properties **must come first**,
|
|
41
105
|
* before any nested blocks.
|
|
42
106
|
*
|
|
43
|
-
*
|
|
107
|
+
* **NOTE 2:** `vanillaClassNested` does NOT support deeply nested blocks, or
|
|
108
|
+
* anything so fancy. It will also replace `&` characters inside values,
|
|
109
|
+
* comments, etc. If you need something more sophisticated, use a custom
|
|
110
|
+
* `postcss` config.
|
|
44
111
|
*/
|
|
45
112
|
export declare function vanillaClassNested(css: string): string;
|
|
113
|
+
/** @deprecated (Will be removed in v0.2) */
|
|
114
|
+
/**
|
|
115
|
+
* Returns a scoped cssClassName styled with free-form CSS.
|
|
116
|
+
*
|
|
117
|
+
* It also automatically replaces all `&`-tokens with
|
|
118
|
+
* the selector for the auto-generated class-name.
|
|
119
|
+
*
|
|
120
|
+
* ```ts
|
|
121
|
+
* // someFile.css.ts
|
|
122
|
+
* import { vanillaClassNested } from '@reykjavik/webtools/vanillaExtract';
|
|
123
|
+
*
|
|
124
|
+
* export const myClass = vanillaClassNested(`
|
|
125
|
+
* background-color: #ccc;
|
|
126
|
+
* padding: .5em 1em;
|
|
127
|
+
*
|
|
128
|
+
* /* Nested blocks begin: */
|
|
129
|
+
* &:hover {
|
|
130
|
+
* background-color: #666;
|
|
131
|
+
* color: white;
|
|
132
|
+
* }
|
|
133
|
+
* & > strong {
|
|
134
|
+
* color: maroon;
|
|
135
|
+
* }
|
|
136
|
+
* html[data-color-theme="unicorn"] & {
|
|
137
|
+
* background-color: pink;
|
|
138
|
+
* }
|
|
139
|
+
* `);
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* **NOTE:** All "bare" (un-nested) style properties **must come first**,
|
|
143
|
+
* before any nested blocks.
|
|
144
|
+
*
|
|
145
|
+
* **NOTE 2:** `vanillaClassNested` does NOT support deeply nested blocks, or
|
|
146
|
+
* anything so fancy. It will also replace `&` characters inside values,
|
|
147
|
+
* comments, etc. If you need something more sophisticated, use a custom
|
|
148
|
+
* `postcss` config.
|
|
149
|
+
*/
|
|
46
150
|
export declare function vanillaClassNested(debugId: string, css: string): string;
|
package/vanillaExtract.js
CHANGED
|
@@ -31,15 +31,55 @@ function vanillaClass(cssOrDebugId, css) {
|
|
|
31
31
|
exports.vanillaClass = vanillaClass;
|
|
32
32
|
// ---------------------------------------------------------------------------
|
|
33
33
|
/**
|
|
34
|
+
* @deprecated (Will be removed in v0.2)
|
|
35
|
+
*
|
|
34
36
|
* Replaces all `&` tokens with the given selector string, in a direct
|
|
35
37
|
* (read. "dumb") way. It's mainly useful when used with style-mixins, etc.
|
|
36
38
|
*
|
|
37
|
-
* NOTE
|
|
38
|
-
* It will also replace
|
|
39
|
+
* **NOTE:** `vanillaNest` does NOT support deeply nested blocks, or anything
|
|
40
|
+
* so fancy. It will also replace `&` characters inside values, comments, etc.
|
|
39
41
|
* If you need something more sophisticated, use a custom `postcss` config.
|
|
40
42
|
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* // someCssHelper.ts
|
|
45
|
+
* import { vanillaNest } from '@reykjavik/webtools/vanillaExtract';
|
|
46
|
+
*
|
|
47
|
+
* export const hoverGlow = (
|
|
48
|
+
* ampSelector: string,
|
|
49
|
+
* glowiness?: 'normal' | 'insane'
|
|
50
|
+
* ) =>
|
|
51
|
+
* vanillaNest(
|
|
52
|
+
* ampSelector,
|
|
53
|
+
* `
|
|
54
|
+
* &:hover {
|
|
55
|
+
* box-shadow: 0 0 20px 5px ${
|
|
56
|
+
* glowiness === 'insane' ? 'hotpink' : 'salmon'
|
|
57
|
+
* };
|
|
58
|
+
* }
|
|
59
|
+
* `
|
|
60
|
+
* );
|
|
61
|
+
*
|
|
62
|
+
* // ...then, somewhere else in a *.css.ts file:
|
|
63
|
+
*
|
|
64
|
+
* import { hoverGlow } from '~/someCssHelper.js';
|
|
65
|
+
* import { vanillaGlobal } from '@reykjavik/webtools/vanillaExtract';
|
|
66
|
+
*
|
|
67
|
+
* vanillaGlobal(`
|
|
68
|
+
* .MyComponent {
|
|
69
|
+
* border: 1px solid #ccc;
|
|
70
|
+
* padding: 1em;
|
|
71
|
+
* }
|
|
72
|
+
* ${hoverGlow('.MyComponent')}
|
|
73
|
+
*
|
|
74
|
+
* .MyOtherComponent {
|
|
75
|
+
* border: 1px solid #ccc;
|
|
76
|
+
* padding: 1em;
|
|
77
|
+
* }
|
|
78
|
+
* ${hoverGlow('.MyOtherComponent', 'insane')}
|
|
79
|
+
* `);
|
|
80
|
+
* ```
|
|
41
81
|
*
|
|
42
|
-
*
|
|
82
|
+
* (This low-level utility function is used internally by `vanillaClassNested`.
|
|
43
83
|
*/
|
|
44
84
|
const vanillaNest = (ampSelector, css) => css.replace(/&/g, ampSelector);
|
|
45
85
|
exports.vanillaNest = vanillaNest;
|