/
pipeable.ts
170 lines (146 loc) · 4.71 KB
/
pipeable.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import { TWSClass } from './TWSClass';
import {
BooleanFN,
_add,
_ifElse,
_remove,
_unless,
_when,
_wordMap,
convertToHover,
convertToVariants,
} from './utils';
export const add = (className: string) => (tw: TWSClass) =>
new TWSClass(_add(tw.className, className));
export const addWhen = (condition: boolean | BooleanFN, className: string) => (
tw: TWSClass
) => new TWSClass(_when(condition)(_add)(tw.className, className));
export const addUnless = (
condition: boolean | BooleanFN,
className: string
) => (tw: TWSClass) =>
new TWSClass(_unless(condition)(_add)(tw.className, className));
export const addIfElse = (
condition: boolean | BooleanFN,
classNameRight: string,
classNameLeft: string
) => (tw: TWSClass) =>
new TWSClass(
_ifElse(condition)(_add)(tw.className, classNameRight, classNameLeft)
);
export const remove = (className: string) => (tw: TWSClass) =>
new TWSClass(_remove(tw.className, className));
export const removeWhen = (
condition: boolean | BooleanFN,
className: string
) => (tw: TWSClass) =>
new TWSClass(_when(condition)(_remove)(tw.className, className));
export const removeUnless = (
condition: boolean | BooleanFN,
className: string
) => (tw: TWSClass) =>
new TWSClass(_unless(condition)(_remove)(tw.className, className));
export const removeIfElse = (
condition: boolean | BooleanFN,
classNameRight: string,
classNameLeft: string
) => (tw: TWSClass) =>
new TWSClass(
_ifElse(condition)(_remove)(tw.className, classNameRight, classNameLeft)
);
export const addHover = (className: string) => (tw: TWSClass) =>
add(_wordMap(convertToHover)(className))(tw);
export const addHoverWhen = (
condition: boolean | BooleanFN,
className: string
) => (tw: TWSClass) =>
addWhen(condition, _wordMap(convertToHover)(className))(tw);
export const addHoverUnless = (
condition: boolean | BooleanFN,
className: string
) => (tw: TWSClass) =>
addUnless(condition, _wordMap(convertToHover)(className))(tw);
export const addHoverIfElse = (
condition: boolean | BooleanFN,
classNameRight: string,
classNameLeft: string
) => (tw: TWSClass) =>
addIfElse(
condition,
_wordMap(convertToHover)(classNameRight),
_wordMap(convertToHover)(classNameLeft)
)(tw);
export const removeHover = (className: string) => (tw: TWSClass) =>
remove(_wordMap(convertToHover)(className))(tw);
export const removeHoverWhen = (
condition: boolean | BooleanFN,
className: string
) => (tw: TWSClass) =>
removeWhen(condition, _wordMap(convertToHover)(className))(tw);
export const removeHoverUnless = (
condition: boolean | BooleanFN,
className: string
) => (tw: TWSClass) =>
removeUnless(condition, _wordMap(convertToHover)(className))(tw);
export const removeHoverIfElse = (
condition: boolean | BooleanFN,
classNameRight: string,
classNameLeft: string
) => (tw: TWSClass) =>
removeIfElse(
condition,
_wordMap(convertToHover)(classNameRight),
_wordMap(convertToHover)(classNameLeft)
)(tw);
export const addVariants = (variants: string, className: string) => (
tw: TWSClass
) => add(_wordMap(convertToVariants(variants))(className))(tw);
export const addVariantsWhen = (
variants: string,
condition: boolean | BooleanFN,
className: string
) => (tw: TWSClass) =>
addWhen(condition, _wordMap(convertToVariants(variants))(className))(tw);
export const addVariantsUnless = (
variants: string,
condition: boolean | BooleanFN,
className: string
) => (tw: TWSClass) =>
addUnless(condition, _wordMap(convertToVariants(variants))(className))(tw);
export const addVariantsIfElse = (
variants: string,
condition: boolean | BooleanFN,
classNameRight: string,
classNameLeft: string
) => (tw: TWSClass) =>
addIfElse(
condition,
_wordMap(convertToVariants(variants))(classNameRight),
_wordMap(convertToVariants(variants))(classNameLeft)
)(tw);
export const removeVariants = (variants: string, className: string) => (
tw: TWSClass
) => remove(_wordMap(convertToVariants(variants))(className))(tw);
export const removeVariantsWhen = (
variants: string,
condition: boolean | BooleanFN,
className: string
) => (tw: TWSClass) =>
removeWhen(condition, _wordMap(convertToVariants(variants))(className))(tw);
export const removeVariantsUnless = (
variants: string,
condition: boolean | BooleanFN,
className: string
) => (tw: TWSClass) =>
removeUnless(condition, _wordMap(convertToVariants(variants))(className))(tw);
export const removeVariantsIfElse = (
variants: string,
condition: boolean | BooleanFN,
classNameRight: string,
classNameLeft: string
) => (tw: TWSClass) =>
removeIfElse(
condition,
_wordMap(convertToVariants(variants))(classNameRight),
_wordMap(convertToVariants(variants))(classNameLeft)
)(tw);