Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New examples feel sergio #540

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions packages/web-new/src/scripts/examples-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* for the examples menu, such as displaying all the TD and TM examples,
* as well as filtering them by categories, a search function to find
* specific examples and a use a template example to directly added to an editor where it can be utilized and modified.
* In the future the option to see short snipets of the most important part of the example, might also be implemented.
* In the future the option to see short snippets of the most important part of the example, might also be implemented.
*/

import { createIde, ideCount, tabsLeft } from "./editor"
Expand Down Expand Up @@ -262,6 +262,7 @@ async function getAllExamples(categoryId, thingType) {
//create example title
const exampleName = document.createElement('div')
exampleName.classList.add("example__header--name")
exampleName.setAttribute("title", "Expand")
const exampleNameIcon = document.createElement('div')
exampleNameIcon.classList.add("example-icon")

Expand All @@ -287,19 +288,27 @@ async function getAllExamples(categoryId, thingType) {
// Append the icon container to the name container
exampleName.appendChild(exampleNameIcon)


//Create, populate and append the example title
const exampleNameTitle = document.createElement('p')
exampleNameTitle.innerText = example[1]["title"]
exampleName.appendChild(exampleNameTitle)

// //Create, populate and append the example title toggle arrow
const exampleNameArrow = document.createElement('i')
exampleNameArrow.classList.add("fa-solid", "fa-chevron-down", "toggle-arrow")
exampleName.appendChild(exampleNameArrow)

//Append the whole name component to the header component
exampleHeader.appendChild(exampleName)

//Create the example quick access button
const quickButton = document.createElement('button')
quickButton.classList.add("example__header--quick")
const quickBtn = document.createElement('button')
quickBtn.classList.add("example__header--quick")
quickBtn.setAttribute("title", "Use")
const quickButtonIcon = document.createElement('i')
quickButtonIcon.classList.add("fa-solid", "fa-file-import")
quickButton.appendChild(quickButtonIcon)
exampleHeader.appendChild(quickButton)
quickBtn.appendChild(quickButtonIcon)
exampleHeader.appendChild(quickBtn)


//add event listener to show example information and interaction btns
Expand All @@ -308,7 +317,7 @@ async function getAllExamples(categoryId, thingType) {
})

//Importing example to the monaco editor with the quick buttons
quickButton.addEventListener('click', () => {
quickBtn.addEventListener('click', () => {
getTemplateData(example[1]["path"])
closeCards()
tabsLeft.forEach(tab => {
Expand Down Expand Up @@ -369,7 +378,7 @@ async function getAllExamples(categoryId, thingType) {


/**
* Gets the example data to pupulate the monaco editor and allow the user to use it as a template
* Gets the example data to populate the monaco editor and allow the user to use it as a template
*/
async function getTemplateData(path) {
const res = await fetch(path)
Expand All @@ -380,7 +389,7 @@ async function getTemplateData(path) {

/**
* Listener when search input is used in the examples menu
* Gets all the examples that match the inputed text to the title and
* Gets all the examples that match the inputted text to the title and
* description of the examples, clones them and adds them to the
* search result category
* @param {event} e - submit event
Expand All @@ -405,15 +414,15 @@ filterForm.addEventListener("submit", (e) => {
categories.forEach(category => {
const examples = [...category.children[2].children]
examples.forEach(example => {
//If value of the search input mataches the title or description
//If value of the search input matches the title or description
//clone it, append it and add the respective event listeners
if ((example.firstChild.children[0].children[1].innerText.toLowerCase()).includes(searchInput.value.toLowerCase()) || (example.children[1].children[0].innerText.toLowerCase()).includes(searchInput.value.toLowerCase())) {
let clonedElement = example.cloneNode(true)
//Open the card when clicking on the name
clonedElement.children[0].children[0].addEventListener('click', () => {
clonedElement.classList.toggle("open")
})
//Opning the example when clicking on the quick access button
//Opening the example when clicking on the quick access button
clonedElement.children[0].children[1].addEventListener('click', () => {
example.querySelector(".example__btn--use").click()
closeCards()
Expand Down
92 changes: 63 additions & 29 deletions packages/web-new/src/styles/_examples-menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
}
}

.td-text, .tm-text{
.td-text,
.tm-text {
position: absolute;
height: 100%;
z-index: 1;
Expand All @@ -110,7 +111,7 @@
transition: color 250ms ease-in-out 200ms;
}

.tm-text{
.tm-text {
content: 'TM';
right: 1rem;
z-index: 1;
Expand All @@ -124,12 +125,12 @@
left: 3.2rem;
}

& ~ .td-text{
&~.td-text {
color: var(--clr-neutral-200);
transition: color 250ms ease-in-out;
}

& ~ .tm-text{
&~.tm-text {
color: var(--clr-neutral-900);
transition: color 250ms ease-in-out 200ms;
}
Expand Down Expand Up @@ -322,30 +323,32 @@
background-color: var(--clr-neutral-50);
border-radius: 5px;
width: fit-content;
padding: 2rem;
padding: .75rem;
box-shadow: 0px 0px 5px 0px var(--clr-shadow);
transition: box-shadow 250ms ease-in-out;
position: relative;

&__header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 2rem;
justify-content: center;

&--name {
width: 100%;
flex: 1;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
gap: 2rem;
gap: 1rem;
margin: 0 4rem;
cursor: pointer;
transition: all 250ms ease-in-out 250ms;

.example-icon{
.example-icon {
width: 1.8rem;

svg{
path{
svg {
path {
fill: var(--clr-primary-500);
}
}
Expand All @@ -354,25 +357,54 @@
p {
font-weight: var(--fw-bold);
}

.toggle-arrow {
font-size: var(--fs-footer);
transform: rotate(0);
transition: transform 250ms ease-in-out 250ms;
}
}

&--quick {
width: fit-content;
background-color: transparent;
opacity: 0;
position: absolute;
top: .25rem;
right: .5rem;
width: 4rem;
height: 4rem;
border-radius: 50%;
background-color: var(--clr-neutral-50);
border: none;
border-left: 2px solid var(--clr-primary-500);
padding: 1rem 1rem 1rem 2rem;
cursor: pointer;
transition: background-color 250ms ease-in-out, opacity 250ms ease-in-out;

i {
font-size: var(--fs-i);
color: var(--clr-primary-500);
transition: color 250ms ease-in-out 250ms;
color: var(--clr-neutral-50);
transition: color 250ms ease-in-out;
}
}
}

&:hover {
box-shadow: 0px 0px 10px 0px var(--clr-shadow);

.example__header {

&--quick {

opacity: 1;

&:hover {
i {
color: var(--clr-primary-700);
color: var(--clr-neutral-300);
}

&:hover {
background-color: var(--clr-neutral-100);

i {
color: var(--clr-neutral-900);
}
}
}
}
Expand All @@ -382,7 +414,7 @@
pointer-events: none;
display: flex;
flex-direction: column;
align-items: center;
align-items: flex-start;
justify-content: center;
flex-wrap: wrap;
}
Expand All @@ -392,21 +424,20 @@
opacity: 0;
font-size: var(--fs-p);
line-height: var(--lh-sub-header);
max-width: 50ch;
max-width: 60ch;
overflow-y: scroll;
overflow-x: hidden;
padding-right: 1rem;
transition: height 250ms ease-in-out 250ms, margin 250ms ease-in-out 250ms, opacity 250ms ease-in-out 0ms;

}

&__btn {
display: flex;
width: 100%;
gap: 2rem;
gap: .5rem;
height: 0;
opacity: 0;
transition: opacity 250ms ease-in-out 0ms, height 250ms ease-in-out 250ms, ;
transition: opacity 250ms ease-in-out 0ms, height 250ms ease-in-out 250ms;

button {
width: 100%;
Expand Down Expand Up @@ -458,10 +489,13 @@

.example.open {

.example__name {
border-bottom: 2px solid var(--clr-primary-500);
padding-bottom: 2rem;
transition: all 250ms ease-in-out 0s;
.example__header {
&--name {
.toggle-arrow {
transform: rotate(-90deg);
transition: transform 250ms ease-in-out 0s;
}
}
}

.example__content {
Expand Down
Loading