Skip to content

Commit

Permalink
chore: add advanced example in demo
Browse files Browse the repository at this point in the history
  • Loading branch information
David Luna authored and David Luna committed Sep 8, 2024
1 parent 727d8b6 commit 117645f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 25 deletions.
18 changes: 14 additions & 4 deletions demo/bundle.js

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
border: 1px solid;
}
.container {
display: flex;
text-align: center;
}
.item {
flex: 1;
}
#code {
text-align: initial;
}
Expand All @@ -36,20 +40,22 @@
</head>
<body>
<div class="container">
<table class="item">
<tbody id="playground"></tbody>
</table>
<div class="item">
<table>
<tbody id="playground"></tbody>
</table>
</div>
<div class="item">
<p id="comment">
Csset is a utility class to treat CSS selector like sets of elements.
The following grid contains cells with different classes and attributes and we can use CSS selectors
to define different sets of cells.
</p>
<button id="next">Next</button>
<pre>
<code class="language-javascript" id="code">
</code>
</pre>
<button id="next">Next</button>
</div>
</div>
<script src="./bundle.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const nextButton = document.querySelector('#next');

// Prepare the playground
// Size MUST be odd number
const playgroundSize = 101;
const playgroundSize = 51;
const playground = document.querySelector('#playground');
setPlayground(playground, playgroundSize);

Expand Down
2 changes: 2 additions & 0 deletions demo/steps/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { STEPS_BEGIN } from './steps-begin.js';
import { STEPS_UNION } from './steps-union.js';
import { STEPS_INTERSECTION } from './steps-intersection.js';
import { STEPS_ADVANCED } from './steps-advanced.js';

export * from './runner.js';
// eslint-disable-next-line prettier/prettier
export const STEPS = [
...STEPS_BEGIN,
...STEPS_UNION,
...STEPS_INTERSECTION,
...STEPS_ADVANCED,
];
15 changes: 15 additions & 0 deletions demo/steps/steps-advanced.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable no-undef */

/** @type {import('./runner').Step[]} */
export const STEPS_ADVANCED = [
{
comment: 'You can combine union and instersections',
code: () => {
const quadrantOne = new Csset('.quadrant-one');
const quadrantFour = new Csset('.quadrant-four');
const circle = new Csset('.circle');

return quadrantOne.union(quadrantFour).intersection(circle);
},
},
];
24 changes: 8 additions & 16 deletions demo/steps/steps-intersection.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,22 @@ export const STEPS_INTERSECTION = [
},
},
{
comment: 'Like unions you can calculate intersection for more than two sets',
comment: 'This is another example of intersection',
code: () => {
const quadrantOne = new Csset('.quadrant-one');
const even = new Csset('[d-even=true]');
const diamond = new Csset('.diamond');
const quadrantOne = new Csset('.quadrant-four');
const diamond = new Csset('.circle');

return quadrantOne.intersection(even).intersection(diamond);
return quadrantOne.intersection(diamond);
},
},
{
comment: 'A bigger intersection',
comment: 'Like unions you can calculate intersection for more than two sets',
code: () => {
const quadrantFour = new Csset('.quadrant-four');
const quadrantOne = new Csset('.quadrant-one');
const even = new Csset('[d-even=true]');
const diamond = new Csset('.diamond');
let result = quadrantFour;

for (let i = 0; i < 50; i++) {
if (i % 2 === 0) {
const s = new Csset(`[d-col=${i}]`);
result = result.intersection(s);
}
}

return result.intersection(diamond);
return quadrantOne.intersection(even).intersection(diamond);
},
},
];

0 comments on commit 117645f

Please sign in to comment.