generated from garronej/ts-ci
/
index.tsx
572 lines (480 loc) · 17.4 KB
/
index.tsx
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
import { useReducer, memo } from "react";
import { GlobalStyles, useMergedClasses } from "tss-react";
import { makeStyles, useStyles, withStyles } from "../shared/makeStyles";
import { styled } from "@mui/material";
import Button from "@mui/material/Button"
import Breadcrumbs from "@mui/material/Breadcrumbs";
import { useDarkMode } from "next-dark-mode";
import Typography from "@mui/material/Typography";
import type { CSSObject } from "tss-react";
import InputBase from "@mui/material/InputBase";
export default function Index() {
const { css } = useStyles();
return (
<App
className={css({ "boxShadow": "10px 5px 5px teal" })}
/>
);
}
const { App } = (() => {
const H1 = styled('h1')({
"color": "yellow"
});
function App(props: { className?: string; }) {
const { className } = props;
const { classes, css, cx, theme } = useStyles();
const { darkModeActive, switchToLightMode, switchToDarkMode } = useDarkMode();
console.log({ darkModeActive });
return (
<>
<GlobalStyles
styles={{
"body": {
"backgroundColor": "pink"
},
".foo": {
"color": "cyan"
}
}}
/>
<div className={classes.root}>
<h1>Black (in light mode)</h1>
<h1>Should be lime green</h1>
<h1
className={cx(
css({ "border": "1px solid black" }),
className
)}
>
Black (in light mode), should have border and shadow
</h1>
<h1 className="foo">Should be cyan</h1>
<H1>Should be yellow</H1>
<H1 className={classes.ovStyled}>Should be dark red</H1>
<Button variant="contained" color="primary"> Background should be lime green </Button>
<Button
variant="contained"
color="primary"
className={classes.ovInternal}
>
Background should be dark blue
</Button>
<div className={classes.parent}>
<div className={classes.child}>
Background should turn red when mouse is hover the parent.
</div>
</div>
<Breadcrumbs
className={classes.breadcrumbs_className}
color="primary"
>
<span>background should be lightblue</span>
<span>and the separator (/) should be red except when hover, then it is blue</span>
</Breadcrumbs>
<div style={{ "height": 10 }} />
<Breadcrumbs
classes={{
"root": classes.breadcrumbs2_root,
"separator": classes.breadcrumbs2_separator
}}
color="primary"
>
<span>background should be lightblue</span>
<span>and the separator (/) should be red except when hover, then it is blue</span>
</Breadcrumbs>
<MyBreadcrumbs>
<span>The separator</span>
<span>should be lightgreen</span>
</MyBreadcrumbs>
<Button
variant="contained"
color="primary"
className={classes.button2_className}
>
<span>The background should be red</span>
</Button>
<Button
variant="contained"
color="primary"
classes={{ "root": classes.button2_root, }}
>
<span>The background should be red</span>
</Button>
<div className={cx(classes.testCx_bgYellow, classes.testCx_bgCyan)}>
Background should be cyan
</div>
<div className={cx(classes.testCx_bgCyan, classes.testCx_bgYellow)}>
Background should be yellow
</div>
<div className={classes.childRefTest_wrapper}>
<div className={cx(
classes.childRefTest_textColorPink,
classes.childRefTest_wrapper1
)}>
Background should turn cyan when mouse hover the parent.
Also the text should NOT be pink
</div>
<div className={cx(classes.childRefTest_wrapper2)}>
Background should NOT turn cyan when mouse hover the parent.
</div>
</div>
<div className={classes.mq}>
The background color should turn from lightgreen to cyan when the window
inner with goes below 960px
</div>
<MyComponentStyled
className={css({ "color": "red" })}
colorSmall="cyan"
/>
<MyStyledButton>
The text should turn from red to blue when the
window inner width goes below 960px
And I should have a class like tss-xxxxxx-MyStyledButton-text
</MyStyledButton>
<br />
<MyAnchorStyled href="http://exampe.com">
Background should be red
</MyAnchorStyled>
<MyAnchorStyled href="https://exampe.com">
Background should be limegreen
</MyAnchorStyled>
<div className={cx(
css({
"@media screen and (min-width: 1px)": {
"backgroundColor": "red"
},
"height": 50
}),
css({
"backgroundColor": "lightgreen"
})
)}>
background should be lightgreen
</div>
<div className={css({
"padding": 30,
"backgroundColor": theme.palette.background.paper
})}>
<Button
onClick={
() => {
if (darkModeActive) {
switchToLightMode();
} else {
switchToDarkMode();
}
}
}
>
Currently in {darkModeActive ? "dark" : "light"} mode, click to toggle
</Button>
</div>
<SecondNestedSelectorExample />
<MyTestComponentForMergedClasses />
<TestCastingMuiTypographyStyleToCSSObject />
<TestPr54 />
<TestingStyleOverrides
className={css({ "backgroundColor": "white" })}
classes={{
"root": css({
"backgroundColor": "red",
"border": "1px solid black"
})
}}
lightBulbBorderColor="black"
/>
</div>
</>
);
}
const useStyles = makeStyles<void, "child" | "breadcrumbs2_separator" | "childRefTest_wrapper2" | "childRefTest_wrapper1">({
"name": { App },
})((theme, _params, classes) => {
const childRefTest_wrapper2 = {
"border": "1px solid black",
"margin": 30,
"height": 100,
"color": "black"
};
return {
"root": {
"& > h1:nth-child(2)": {
"color": theme.palette.primary.main,
}
},
"ovStyled": {
"color": "darkred"
},
"ovInternal": {
"backgroundColor": "darkblue"
},
"parent": {
"border": "1px solid black",
"padding": 30,
[`&:hover .${classes.child}`]: {
"background": "red",
}
},
"child": {
"background": "blue",
"border": "1px solid black"
},
"breadcrumbs_className": {
"backgroundColor": "lightblue",
"& .MuiBreadcrumbs-separator": {
"color": "red"
},
"&:hover .MuiBreadcrumbs-separator": {
"color": "blue"
}
},
"breadcrumbs2_root": {
"backgroundColor": "lightblue",
[`&:hover .${classes.breadcrumbs2_separator}`]: {
"color": "blue"
}
},
"breadcrumbs2_separator": {
"color": "red"
},
"button2_className": {
"backgroundColor": "red"
},
"button2_root": {
"backgroundColor": "red"
},
"testCx_bgYellow": {
"backgroundColor": "yellow"
},
"testCx_bgCyan": {
"backgroundColor": "cyan"
},
"childRefTest_wrapper": {
"border": "1px solid black",
[`&:hover .${classes.childRefTest_wrapper1}`]: {
"backgroundColor": "cyan"
}
},
"childRefTest_wrapper1": {
...childRefTest_wrapper2
},
childRefTest_wrapper2,
"childRefTest_textColorPink": {
"color": "pink"
},
"mq": {
"height": 100,
"backgroundColor": "lightgreen",
"@media (max-width: 960px)": {
"backgroundColor": "cyan"
}
},
};
});
return { App };
})();
function MyComponent(props: { className?: string; colorSmall: string; }) {
return (
<div className={props.className}>
The background color should turn from limegreen to cyan when the window
inner with goes below 960px.
Font should be red
</div>
);
}
const MyComponentStyled = withStyles(
MyComponent,
(theme, props) => ({
"root": {
"backgroundColor": theme.palette.primary.main,
"height": 100,
"marginTop": 20
},
"@media (max-width: 960px)": {
"root": {
"backgroundColor": props.colorSmall
},
}
})
);
const MyStyledButton = withStyles(
Button,
{
"text": {
"color": "red",
"textTransform": "unset"
},
"@media (max-width: 960px)": {
"text": {
"color": "blue"
},
}
},
{ "name": "MyStyledButton" }
);
const MyAnchorStyled = withStyles(
"a",
(theme, { href }) => ({
"root": {
"border": "1px solid black",
"backgroundColor":
href?.startsWith("https") ?
theme.palette.primary.main :
"red"
}
})
);
const MyBreadcrumbs = withStyles(
Breadcrumbs,
(theme, _props, classes) => ({
"ol": {
[`& .${classes.separator}`]: {
"color": theme.palette.primary.main
}
}
})
);
const { SecondNestedSelectorExample } = (() => {
const SecondNestedSelectorExample = memo(() => {
const { classes, cx } = useStyles({ "color": "primary" });
return (
<div className={classes.root}>
<div className={classes.child}>
The Background take the primary theme color when the mouse is hover the parent.
</div>
<div className={cx(classes.child, classes.small)}>
The Background take the primary theme color when the mouse is hover the parent.
I am smaller than the other child.
</div>
</div>
);
});
const useStyles = makeStyles<{ color: "primary" | "secondary" }, "child" | "small">({
"name": { SecondNestedSelectorExample }
})(
(theme, { color }, classes) => ({
"root": {
"padding": 30,
[`&:hover .${classes.child}`]: {
"backgroundColor": theme.palette[color].main,
},
},
"small": {},
"child": {
"border": "1px solid black",
"height": 50,
[`&.${classes.small}`]: {
"height": 30,
}
},
})
);
return { SecondNestedSelectorExample };
})();
const { MyTestComponentForMergedClasses } = (() => {
const useStyles = makeStyles()({
"foo": {
"border": "3px dotted black",
"backgroundColor": "red"
},
"bar": {
"color": "pink"
}
});
type Props = {
classes?: Partial<ReturnType<typeof useStyles>["classes"]>;
};
const MyTestComponentForMergedClassesInternal = (props: Props) => {
let { classes } = useStyles();
classes = useMergedClasses(classes, props.classes);
return (
<div className={classes.foo}>
<span className={classes.bar}>The background should be green, the box should have a dotted border and the text should be pink</span>
</div>
);
};
const MyTestComponentForMergedClasses = () => {
const { css } = useStyles();
return <MyTestComponentForMergedClassesInternal classes={{ "foo": css({ "backgroundColor": "green" }) }} />;
};
return { MyTestComponentForMergedClasses };
})();
const { TestCastingMuiTypographyStyleToCSSObject } = (() => {
const useStyles = makeStyles()(theme => ({
"root": {
...(theme.typography.subtitle2 as CSSObject),
"color": "red"
}
}));
const TestCastingMuiTypographyStyleToCSSObject = () => {
const { classes } = useStyles();
return (
<>
<Typography variant="subtitle2">This text should be italic</Typography>
<span className={classes.root}>This text should be italic and red</span>
</>
);
};
return { TestCastingMuiTypographyStyleToCSSObject };
})();
const { TestPr54 } = (() => {
const CustomInputBase = withStyles(
InputBase,
{
"input": {
"backgroundColor": "red",
"color": "pink"
}
}
);
const StyledInput = withStyles(CustomInputBase, theme => ({
"input": {
"backgroundColor": theme.palette.primary.main
}
}));
const TestPr54 = () => (
<>
<span>The Input below should have a lime green background and when you type the text should be pink</span>
<StyledInput />
</>
);
return { TestPr54 };
})();
const { TestingStyleOverrides } = (() => {
type Props = {
className?: string;
classes?: Partial<ReturnType<typeof useStyles>["classes"]>;
lightBulbBorderColor: string;
}
function TestingStyleOverrides(props: Props) {
const { className } = props;
const [isOn, toggleIsOn] = useReducer(isOn => !isOn, false);
const { classes, cx } = useStyles(undefined, { props, "ownerState": { isOn } });
return (
<div className={cx(classes.root, className)} >
<div className={classes.lightBulb}></div>
<button onClick={toggleIsOn}>{`Turn ${isOn?"off":"on"}`}</button>
<p>Div should have a border, background should be white</p>
<p>Light bulb should have black border, it should be yellow when turned on.</p>
</div>
);
}
const useStyles = makeStyles({ "name": { TestingStyleOverrides } })(theme => ({
"root": {
"border": "1px solid black",
"width": 500,
"height": 200,
"position": "relative",
"color": "black"
},
"lightBulb": {
"position": "absolute",
"width": 50,
"height": 50,
"top": 120,
"left": 500/2 - 50,
"borderRadius": "50%"
}
}));
return { TestingStyleOverrides };
})();