@wikicasa-dev/tailwind-plugins 0.0.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/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @wikicasa-dev/tailwind-plugins
2
+
3
+ To install dependencies:
4
+
5
+ ```bash
6
+ bun install
7
+ ```
8
+
9
+ To run:
10
+
11
+ ```bash
12
+ bun run index.ts
13
+ ```
14
+
15
+ This project was created using `bun init` in bun v1.1.10. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
package/bun.lockb ADDED
Binary file
package/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { buttonPlugin } from "./plugins/buttonPlugin";
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@wikicasa-dev/tailwind-plugins",
3
+ "module": "index.ts",
4
+ "main": "index.js",
5
+ "type": "module",
6
+ "peerDependencies": {
7
+ "typescript": "^5.0.0"
8
+ },
9
+ "devDependencies": {
10
+ "tailwindcss": "^3.4.3"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://matteocarniglia@bitbucket.org/wikicasa/wikicasa-fe.git"
15
+ },
16
+ "author": "",
17
+ "license": "ISC",
18
+ "bugs": {
19
+ "url": "https://bitbucket.org/wikicasa/wikicasa-fe/issues"
20
+ },
21
+ "homepage": "https://bitbucket.org/wikicasa/wikicasa-fe#readme",
22
+ "version": "0.0.1"
23
+ }
@@ -0,0 +1,334 @@
1
+ import plugin from "tailwindcss/plugin";
2
+ export const buttonPlugin = plugin(({ addComponents, theme }) => {
3
+ addComponents({
4
+ ".btn": {
5
+ "--btn-px": "25px",
6
+ "--btn-py": "11px",
7
+ "--btn-bg-color": "transparent",
8
+ "--btn-text-color": theme("colors.w-black"),
9
+ "--btn-border-color": "unset",
10
+ "--btn-border-width": "0",
11
+ "--btn-border-radius": theme("borderRadius.lg"),
12
+ "--btn-border-style": "solid",
13
+ "--btn-height": "42px",
14
+ "--btn-min-w": "90px",
15
+ "--btn-font-size": theme("fontSize.DEFAULT"),
16
+ "--btn-transition":
17
+ "color, background-color cubic-bezier(0.4, 0, 0.2, 1) 150ms",
18
+ display: "inline-block",
19
+ "font-size": "var(--btn-font-size)",
20
+ "font-weight": theme("fontWeight.semibold"),
21
+ "white-space": "nowrap",
22
+ border:
23
+ "var(--btn-border-width) var(--btn-border-color) var(--btn-border-style)",
24
+ "border-radius": "var(--btn-border-radius)",
25
+ cursor: "pointer",
26
+ height: "var(--btn-height)",
27
+ "min-width": "var(--btn-min-w)",
28
+ "background-color": "var(--btn-bg-color)",
29
+ color: "var(--btn-text-color)",
30
+ padding: "var(--btn-py) var(--btn-px)",
31
+ transition: "var(--btn-transition)",
32
+ "line-height": "1",
33
+ "-webkit-tap-highlight-color": "transparent",
34
+ "&:disabled": {
35
+ "--btn-bg-color": theme("colors.w-primary"),
36
+ "--btn-text-color": "rgb(255 255 255 / 0.8)",
37
+ cursor: "not-allowed",
38
+ opacity: "0.5",
39
+ },
40
+ "&.btn-lg": {
41
+ "--btn-height": "47px",
42
+ "--btn-px": "28px",
43
+ "--btn-py": "12px",
44
+ "line-height": "0",
45
+ },
46
+ "&.btn-md": {
47
+ "--btn-height": "42px",
48
+ },
49
+ "&.btn-sm": {
50
+ "--btn-px": "18px",
51
+ "--btn-py": "8px",
52
+ "--btn-height": "36px",
53
+ },
54
+ "&.btn-outline": {
55
+ "--btn-border-width": "1px",
56
+ "--btn-bg-color": theme("colors.white"),
57
+ [`@media screen and (max-width: ${theme("screens.sm")})`]: {
58
+ "&:hover": {
59
+ "--btn-bg-color": theme("colors.white"),
60
+ },
61
+ },
62
+ [`@media screen and (min-width: ${theme("screens.sm")})`]: {
63
+ "&:hover": {
64
+ "--btn-text-color": theme("colors.white"),
65
+ "& svg, & img": {
66
+ filter: "brightness(0) invert(1)",
67
+ },
68
+ },
69
+ },
70
+ "&:active": {
71
+ "--btn-text-color": theme("colors.white") + " !important",
72
+ "& svg, & img": {
73
+ filter: "brightness(0) invert(1)",
74
+ },
75
+ },
76
+ },
77
+ },
78
+ ".btn-empty": {
79
+ "--btn-min-w": "0",
80
+ },
81
+ ".btn-w-primary": createBtn(
82
+ theme("screens.sm"),
83
+ {
84
+ bgColor: theme("colors.w-primary"),
85
+ textColor: theme("colors.white"),
86
+ hoverBgColor: "#0057D9",
87
+ hoverDisabledBgColor: theme("colors.w-primary"),
88
+ },
89
+ {
90
+ mainColor: theme("colors.w-primary"),
91
+ }
92
+ ),
93
+ ".btn-light": createBtn(theme("screens.sm"), {
94
+ textColor: theme("colors.w-primary"),
95
+ bgColor: theme("colors.white"),
96
+ hoverTextColor: theme("colors.w-primary"),
97
+ hoverBgColor: "#FAFAFA",
98
+ hoverDisabledBgColor: theme("colors.white"),
99
+ }),
100
+ ".btn-w-secondary": createBtn(
101
+ theme("screens.sm"),
102
+ {
103
+ bgColor: theme("colors.w-secondary"),
104
+ textColor: theme("colors.white"),
105
+ hoverBgColor: "#8A9DDD",
106
+ hoverDisabledBgColor: theme("colors.w-secondary"),
107
+ },
108
+ {
109
+ mainColor: theme("colors.w-secondary"),
110
+ textColor: theme("colors.w-black"),
111
+ }
112
+ ),
113
+ ".btn-w-warning": createBtn(theme("screens.sm"), {
114
+ bgColor: theme("colors.w-warning"),
115
+ textColor: "#2A3761",
116
+ hoverBgColor: "#F2C761",
117
+ hoverDisabledBgColor: theme("colors.w-warning"),
118
+ }),
119
+ ".btn-w-danger": createBtn(
120
+ theme("screens.sm"),
121
+ {
122
+ bgColor: theme("colors.w-danger"),
123
+ textColor: theme("colors.white"),
124
+ hoverBgColor: "#E0485A",
125
+ hoverDisabledBgColor: theme("colors.w-danger"),
126
+ },
127
+ {
128
+ mainColor: theme("colors.w-danger"),
129
+ }
130
+ ),
131
+ ".btn-multi-selection, .btn-single-selection": {
132
+ "&[data-active='true']": {
133
+ "--btn-bg-color": theme("colors.w-lavender"),
134
+ "--btn-border-color": "#385CF6",
135
+ "&:hover": {
136
+ "--btn-text-color": theme("colors.w-black"),
137
+ },
138
+ },
139
+ },
140
+ ".btn-multi-selection": {
141
+ "--btn-py": "10px",
142
+ "--btn-height": "40px",
143
+ "font-weight": theme("fontWeight.regular"),
144
+ "--btn-border-radius": theme("borderRadius.xs"),
145
+ "--btn-border-color": "#EAEFFD",
146
+ "--btn-border-width": "1px",
147
+ "white-space": "normal",
148
+ ...createBtn(theme("screens.sm"), {
149
+ textColor: theme("colors.w-black"),
150
+ bgColor: "#F5F7FA",
151
+ hoverBgColor: theme("colors.w-lavender"),
152
+ hoverDisabledBgColor: theme("colors.white"),
153
+ hoverBorderColor: "#385CF6",
154
+ }),
155
+ },
156
+ ".btn-single-selection": {
157
+ "--btn-px": "16px",
158
+ "--btn-py": "8px",
159
+ "--btn-height": "40px",
160
+ "--btn-border-radius": "5px",
161
+ "font-weight": theme("fontWeight.regular"),
162
+ ...createBtn(theme("screens.sm"), {
163
+ textColor: theme("colors.w-black"),
164
+ bgColor: theme("colors.white"),
165
+ hoverBgColor: theme("colors.w-cultured"),
166
+ hoverDisabledBgColor: theme("colors.white"),
167
+ }),
168
+ },
169
+ ".btn-facile": {
170
+ "--btn-facile-color": "#FF6600",
171
+ "--btn-facile-hover-color": "#b34700",
172
+ ...createBtn(theme("screens.sm"), {
173
+ bgColor: "var(--btn-facile-color)",
174
+ textColor: theme("colors.white"),
175
+ hoverBgColor: "var(--btn-facile-hover-color)",
176
+ hoverTextColor: theme("colors.white"),
177
+ hoverDisabledBgColor: "var(--btn-facile-color)",
178
+ }),
179
+ },
180
+ ".btn-show-more": {
181
+ "--btn-border-radius": "0",
182
+ "--btn-border-color": theme("colors.white"),
183
+ ...createBtn(theme("screens.sm"), {
184
+ textColor: "#2B5DFF",
185
+ bgColor: theme("colors.white"),
186
+ hoverTextColor: "#3646B3",
187
+ hoverBgColor: theme("colors.white"),
188
+ hoverDisabledBgColor: theme("colors.white"),
189
+ }),
190
+ },
191
+ ".btn-transparent": {
192
+ "--border-color": "transparent",
193
+ "--btn-px": "0",
194
+ "--btn-py": "0",
195
+ "&:hover": {
196
+ "--btn-bg-color": "transparent",
197
+ "--border-color": "transparent",
198
+ },
199
+ "&:disabled": {
200
+ "--btn-bg-color": "transparent",
201
+ },
202
+ },
203
+ });
204
+ });
205
+
206
+ type BtnAttributes = {
207
+ bgColor: string;
208
+ textColor: string;
209
+ hoverBgColor: string;
210
+ hoverMobileBgColor?: string;
211
+ hoverTextColor?: string;
212
+ /* The border color will be applied to desktop mode */
213
+ hoverBorderColor?: string;
214
+ activeBorderColor?: string;
215
+ hoverMobileTextColor?: string;
216
+ activeBgColor?: string;
217
+ activeTextColor?: string;
218
+ hoverDisabledBgColor: string;
219
+ };
220
+ type BtnOutlineVariantAttributes = {
221
+ /* If present, it will be used to set the color to borders, text and background */
222
+ mainColor?: string;
223
+ borderColor?: string;
224
+ textColor?: string;
225
+ hoverMobileBgColor?: string;
226
+ /* The hover bg color will be activated only from tablet mode on */
227
+ hoverBgColor?: string;
228
+ hoverDisabledBgColor?: string;
229
+ /* The hover text color will be activated only from tablet mode on */
230
+ hoverTextColor?: string;
231
+ hoverMobileTextColor?: string;
232
+ activeBgColor?: string;
233
+ activeTextColor?: string;
234
+ };
235
+
236
+ const createBtn = (
237
+ smallBreakpoint: string,
238
+ btnProps: BtnAttributes,
239
+ btnOutlineProps?: BtnOutlineVariantAttributes
240
+ ): any => {
241
+ const res = {
242
+ "--btn-bg-color": btnProps.bgColor,
243
+ "--btn-text-color": btnProps.textColor,
244
+ [`@media screen and (max-width: ${smallBreakpoint})`]: {
245
+ "&:hover": {
246
+ "--btn-bg-color": btnProps.hoverMobileBgColor ?? btnProps.bgColor,
247
+ "--btn-text-color": btnProps.hoverMobileTextColor ?? btnProps.textColor,
248
+ },
249
+ },
250
+ [`@media screen and (min-width: ${smallBreakpoint})`]: {
251
+ "&:hover": {
252
+ "--btn-bg-color": btnProps.hoverBgColor,
253
+ ...(btnProps.hoverTextColor
254
+ ? { "--btn-text-color": btnProps.hoverTextColor }
255
+ : {}),
256
+ ...(btnProps.hoverBorderColor
257
+ ? { "--btn-border-color": btnProps.hoverBorderColor }
258
+ : {}),
259
+ },
260
+ },
261
+ "&:hover": {
262
+ "&:disabled": {
263
+ "--btn-bg-color": btnProps.hoverDisabledBgColor,
264
+ },
265
+ },
266
+ "&:active": {
267
+ "--btn-bg-color": btnProps.activeBgColor ?? btnProps.hoverBgColor,
268
+ "--btn-text-color": btnProps.activeTextColor ?? btnProps.hoverTextColor,
269
+ ...(btnProps.activeBorderColor || btnProps.hoverBorderColor
270
+ ? {
271
+ "--btn-border-color":
272
+ btnProps.activeBorderColor ?? btnProps.hoverBorderColor,
273
+ }
274
+ : {}),
275
+ },
276
+ ...(btnOutlineProps
277
+ ? {
278
+ "&.btn-outline": createOutlineVariant(
279
+ btnOutlineProps,
280
+ smallBreakpoint
281
+ ),
282
+ }
283
+ : {}),
284
+ };
285
+ return res;
286
+ };
287
+
288
+ const createOutlineVariant = (
289
+ props: BtnOutlineVariantAttributes,
290
+ smallBreakpoint: string
291
+ ): any => {
292
+ const res = {
293
+ "--btn-border-color": props.mainColor ?? props.borderColor,
294
+ "--btn-text-color":
295
+ props.mainColor && !props.textColor ? props.mainColor : props.textColor,
296
+ //By default, the active section is the same of the hover section in desktop mode
297
+ "&:active": {
298
+ "--btn-bg-color":
299
+ (props.mainColor ?? props.activeBgColor ?? props.hoverBgColor) +
300
+ " !important",
301
+ //By default, on active the text is white
302
+ ...(props.activeTextColor || props.hoverTextColor
303
+ ? {
304
+ "--btn-text-color": props.activeTextColor ?? props.hoverTextColor,
305
+ }
306
+ : {}),
307
+ },
308
+ "&:disabled": {
309
+ "&:hover": {
310
+ "--btn-bg-color": props.mainColor ?? props.hoverDisabledBgColor,
311
+ },
312
+ },
313
+ [`@media screen and (max-width: ${smallBreakpoint})`]: {
314
+ "&:hover": {
315
+ //By default, the text color is white
316
+ ...(props.hoverMobileBgColor
317
+ ? { "--btn-bg-color": props.hoverMobileBgColor }
318
+ : {}),
319
+ "--btn-text-color": props.hoverMobileTextColor ?? props.textColor,
320
+ },
321
+ },
322
+ [`@media screen and (min-width: ${smallBreakpoint})`]: {
323
+ "&:hover": {
324
+ "--btn-bg-color": props.mainColor ?? props.hoverBgColor,
325
+ //By default, the text color is white when hovering
326
+ ...(props.hoverTextColor
327
+ ? { "--btn-text-color": props.hoverTextColor }
328
+ : {}),
329
+ },
330
+ },
331
+ };
332
+
333
+ return res;
334
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "compilerOptions": {
3
+ // Enable latest features
4
+ "lib": ["ESNext", "DOM"],
5
+ "target": "ESNext",
6
+ "module": "ESNext",
7
+ "moduleDetection": "force",
8
+ "jsx": "react-jsx",
9
+ "allowJs": true,
10
+
11
+ // Bundler mode
12
+ "moduleResolution": "bundler",
13
+ "allowImportingTsExtensions": true,
14
+ "verbatimModuleSyntax": true,
15
+ "noEmit": true,
16
+
17
+ // Best practices
18
+ "strict": true,
19
+ "skipLibCheck": true,
20
+ "noFallthroughCasesInSwitch": true,
21
+
22
+ // Some stricter flags (disabled by default)
23
+ "noUnusedLocals": false,
24
+ "noUnusedParameters": false,
25
+ "noPropertyAccessFromIndexSignature": false,
26
+ "baseUrl": "."
27
+ },
28
+ "include": ["plugins"]
29
+ }