Coder Social home page Coder Social logo

employee-directory's Introduction

Employee Directory

The challenge:

This is a Scrimba solo project using HTML, CSS and JavaScript to create an Employee Directory.

The requirements:

screenshot

Stretch goals:

screenshot

Screenshot:

screenshot

Process

  • Consult Figma design files
  • Create draft of README file
  • Create .gitignore file and check that meta tag is included
  • Create Github repository
  • Work on HTML, CSS and JS files
  • Check final code and accessibility
  • Finalize README file
  • Publish live URL

Questions

  • Hero image: Is there a better way to display the hero image in general/responsively?

  • For the employee cards...how to display left and right margins in the browser. Solution: Added left and right margin to the class: employee-container

.employee-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  justify-content: center;
  gap: 20px;
  margin: 0 20px;
  padding-top: 20px;
}
  • Better way to display the select input field and/or make it more accessible?

Challenges

  • When mapping over the employees data, only the second image displayed. Solution: The employee file should only display the following code for image:
image: "jansen.jpg",

...and not the entire path.

  • Had to learn to use "change" (not "click") in order to target the selected option in the dropdown menu:
selectMenu.addEventListener("change", filterEmployeesByTeam);

Improvements/Enhancements to Consider

  • Make it a React project
  • Complete the stretch goals

Useful Code Snippets

Responsive design with grid:

  display: grid;

  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));

Accessibility:

  • Add select: focus to the select menu
select:hover,
select:focus {
  background-color: #5e716a;
  color: #fff;
  border: 2px solid #fff;
}
  • Add helper class visually-hidden to the label of the select menu. That way it is hidden to the user, yet accessible.
<label for="select" class="visually-hidden">Search for members by team</label>
.visually-hidden {
  position: absolute;
  clip: rect(0 0 0 0);
  height: 1px;
  width: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
}

Refactor code with html helper function:

  • Create an html function to refactor code and make code DRYer
function generateEmployeeHtml(emp) { return `
<div class="card">
  <img
    class="employee-img"
    src="images/photos/${emp.image}"
    alt="${emp.name}"
  />
  <h2>${emp.name}</h2>
  <h3>${emp.title}</h3>
  <p>${emp.bio}</p>
</div>
`; }

That way I can use this html function two places instead of repeating the html code twice.

Here:

function renderEmployees() {
  const employeeList = employees.map(generateEmployeeHtml).join("");
  employeeContainer.innerHTML = employeeList;
}
renderEmployees();

And here:

//Render function to filter the employees by team
function filteredEmployeesByTeam() {
  // returns an array of employee objects that match the condition
  const filteredTeams = employees.filter(function (emp) {
    if (select.value.toLowerCase().includes(emp.team)) {
      return emp;
    }
  });

  const filteredEmployeeList = filteredTeams.map(generateEmployeeHtml).join("");

  employeeContainer.innerHTML = filteredEmployeeList;

  //Render everyone if "everyone" or "select-team" options are selected
  const checkedValue = document.querySelector("option:checked").value;

  if (checkedValue === "everyone" || checkedValue === "select-team") {
    renderEmployees();
  }
}

Make the employee cards appear more visually appealing with justify-content: flex-start. The cards are then the same size and the text blocks align with each other:

.card {
  display: flex;
  flex-direction: column;
  gap: 18px;
  /* justify-content: space-around; */

  justify-content: flex-start; /* flex-start aligns the cards more succinctly */
  background-color: #fff;
  margin: 0 auto;
  padding: 1em 1.5em;
  border: 1px solid #eaeaea;
  border-radius: 0.3em;
}

Displaying social icons:

function generateEmployeeHtml(emp) {
  // create html for social icons
  let socialHtml = "";

  if (emp.social.linkedin && emp.social.twitter) {
    socialHtml = `
      <img src=${linkedinIcon} class="social-icon" alt="LinkedIn icon" >
      <img src=${twitterIcon} class="social-icon" alt="Twitter icon" >`;
  } else if (emp.social.linkedin) {
    socialHtml = `<img src=${linkedinIcon} class="social-icon" alt="LinkedIn icon" >`;
  } else {
    socialHtml = `<img src=${twitterIcon} class="social-icon" alt="Twitter icon" >`;
  }

  // create html for the card
  return `
  <div class="card" >
    <img class="employee-img" src="images/photos/${emp.image}" alt="${emp.name}"/>
    <h2>${emp.name}</h2>
    <h3>${emp.title}</h3>
    <p>${emp.bio}</p> 
    <div class="social-container">${socialHtml}</div>    
  </div>`;
}

โ€ฆ and making the icon stick to the bottom of the card with** margin-top: auto;

.social-container {
  margin-top: auto;
}

Resources used:

Acknowledgements

A special thank you to Micha from Scrimba for reviewing my code.

employee-directory's People

Contributors

codercreative avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.