Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id='app'></div>

<!-- Courtesy to OMDB API -->
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@300;400;700&display=swap");

* {
  box-sizing: border-box;
  font-family: "Roboto Condensed", sans-serif;
}

body {
  // background-color: #EEF2F7;
  // background-color: #000;
  // color: #fff;
  // background-image: linear-gradient(to right, #485563, #29323c);
  background: linear-gradient(to right, #42275a, #734b6d);
  margin: 0;
  padding: 0;
  &::-webkit-scrollbar-track{
    background-color: #734b6d;
  }

  &::-webkit-scrollbar{
    width: 6px;
    height: 6px;
    background-color: transparent;
  }

  &::-webkit-scrollbar-thumb{
    background-color: #42275a;
  }
}

img{
  max-width: 100%;
}


.head{
  text-align: center;
  font-size: 3rem;
  color: #a8e063;
  text-shadow: 0 13.36px 14.896px #42275a;
  margin: 20px;
}


// Search component styles 
.search{
  height: 100px;
  display: grid;
  place-content: center;
  &-box{
    display: flex;
    transition: all .2s ease;
    &:focus-within{
      box-shadow: 0 3px 5px -2px rgba(0, 0, 0, 0.3);
    }
    input {
      appearance: none;
      border: 0;
      outline: 0;
      height: 40px;
      background-color: white;
      padding: 0 10px;
      min-width: 350px;
    }
    button {
      appearance: none;
      border: 0;
      outline: 0;
      height: 40px;
      background-color: white;
      padding: 0 10px;
      cursor: pointer;
    }
  }
}



// Cards styles 
.cards{
  animation: poof .5s;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  grid-auto-rows: minmax(min-content, max-content);
  padding: 10px;
  gap: 10px;
  min-height: 68vh;
  align-items: start;
}

@for $i from 1 through 10 {
  .cards > div:nth-child(#{$i}) { animation-delay: $i * 0.1s; }
}

.card{
  opacity: 0;
  animation: poof .5s forwards;
  overflow: hidden;
  transition: all .3s ease;
  box-shadow: 0 3px 5px -2px rgba(0, 0, 0, 0.3);
  &:hover{
    img{
      transform: scale(1.04);
    }
  }
  img{
    cursor: pointer;
    display: block;
    width: 100%;
    // height: 100%;
    // max-height: 232px;
    transition: all .3s ease;
    &:hover{
    }
  }
}

// Popup styles -------------------------------------------------

.show-expand{
  z-index: 100000;
  position: fixed;
  // width: 100%;
  // height: 100%;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 100vh;
  overflow-y: auto;
  padding: 10px;
  background-color: rgba(255, 255, 255, .15);  
  backdrop-filter: blur(5px);
  &::-webkit-scrollbar-track{
    background-color: transparent;
  }

  &::-webkit-scrollbar{
    width: 6px;
    height: 6px;
    background-color: transparent;
  }

  &::-webkit-scrollbar-thumb{
    background-color: #42275a;
  }
}

.show-content{
  position: relative;
  display: flex;
  // flex-direction: column;
  justify-content: center;
  min-height: 400px;
  animation: poof .5s;
  
  overflow: hidden;
  margin: 12px auto;
  width: 100%;
  max-width: 800px;
  color: #fff;
  // background-color: white;
  // background: linear-gradient(to right, #56ab2f, #a8e063); 
  background: linear-gradient(to left, #3ca55c, #56ab2f);
  border-radius: 0.8em;
  box-shadow: rgba(0, 0, 0, 0.2) 0 30px 18px -24px;
  
  @media (max-width: 600px) {
   flex-direction: column;
  }
}

.show-poster{
  position: relative;
  display: flex;
  // width: 100%;
  &-bg{
    position: absolute;
    overflow: hidden;
    top: -20%;
    bottom: -20%;
    left: -20%;
    width: 100%;
    height: 150%;
    transform: rotate(5deg);
    
    @media (max-width: 600px) {
     left: auto;
     top: -80%;
      width: 150%;
    }
    img{
      filter: blur(6px);
      object-fit: cover;
      width: 100%;
      height: 100%;
      transform: scale(1.4);
    }
  }
  &-main{
    position: relative;
    left: 56px;
    align-self: center;
    overflow: hidden;
    // margin-top: 84px;
    // margin-left: 24px;
    width: 140px;
    background-color: gainsboro;
    border-radius: 2px;
    box-shadow: rgba(0, 0, 0, 0.6) 0 6px 12px -6px;
    z-index: 1;
    @media (max-width: 600px) {
      left: auto;
      margin-top: 84px;
      margin-left: 24px;
    } 
    img{
      width: 140px;
      vertical-align: middle;
    }
  }
}


.show-detail{
  flex: 1;
  padding: 72px;
  @media (max-width: 600px) {
    padding: 24px;
  }
  h2{
    font-size: 2em;
    margin: 0;
    margin-bottom: 12px;
  }
  .show-tags{
    margin: 0;
    padding: 0;
    font-size: 0.75em;
    color: lighten(#a8e063, 20%);
    // background: linear-gradient(to right, #56ab2f, #a8e063); 
    list-style: none;
    margin-bottom: 12px;
    li{
      display: inline-block;
      margin-right: 12px;
      font-size: 0.9em;
      line-height: 1.5;
    }
  }
  .show-plot{
    font-size: 0.9em;
    line-height: 1.5;
    margin-bottom: 12px;
  }
  .show-credits{

    p{
      margin: 0;
      font-size: 0.9em;
      line-height: 1.2;
      margin-bottom: 8px
    }
  }
}

.show-close{
  z-index: 1;
  font-size: 24px;
  position: absolute;
  top: 14px;
  right: 14px;
  margin: auto;
  padding: 15px 20px;
  cursor: pointer;
  @media (max-width: 600px) {
    color: #fff;
  }  
  &:hover{
    color: red;
  }
}

// Loader / Error styles 
.loader, .error{
  grid-column: 1/-1;
  text-align: center;
  font-size: 24px;
  animation: poof .5s;
  color: #a8e063;
}

// Pagination component CSS 

.pagination {
  margin: 15px auto;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  list-style: none;
  outline: none;
}
.pagination > .active > a{
  background-color: #fff ;
  border-color: #fff ;
  color: #56ab2f;
}
.pagination > li > a{
  border: 1px solid #fff ;
  padding: 5px 10px;
  outline: none;
  cursor: pointer;
}
.pagination > .active > a, .pagination > .active > span, .pagination > .active > a:hover, .pagination > .active > span:hover, .pagination > .active > a:focus, .pagination > .active > span:focus{
  background-color: #fff ;
  border-color: #fff;
  outline: none ;
}
.pagination > li > a, .pagination > li > span{
  color: #fff;
}
.pagination > li:first-child > a, .pagination > li:first-child > span, .pagination > li:last-child > a, .pagination > li:last-child > span{
  border-radius: unset
}


/* Keyframes  */

@keyframes poof {
  0%   { 
    opacity: 0;
    transform: translateY(-5px)
  }
  100% { 
    opacity: 1;
    transform: translateY(0px)
  }
}
              
            
!

JS

              
                import axios, * as others from "https://cdn.skypack.dev/axios@0.21.1";
import ReactPaginate from "https://cdn.skypack.dev/react-paginate@7.1.0";

// https://www.omdbapi.com/?apikey=756abb2f&i=tt4154664&plot=full

const { useState, useEffect } = React;

// Main component -------------------------------
const Main = (props) => {
  
  const getMovies = (term='war', page=1) => {
    setLoading(true);
    axios.get(`https://www.omdbapi.com/?apikey=756abb2f&s=${encodeURIComponent(term)}&plot=full&page=${page}`)
      .then(response => {
      // console.log(response.data);
      setMovies(response.data.Search);
      setTotal(Math.ceil(response.data.totalResults/10))
      setPages(page);
      setLoading(false);
    }).catch(error => {
      // console.log(error);
      setMovies([]);
      setLoading(false);
    });
  }
  
  const getMovie = (movieId) => {
    axios.get(`https://www.omdbapi.com/?apikey=756abb2f&i=${movieId}&plot=full`)
    .then(response => {
      // console.log(response.data);
      setMovie(response.data);
      setShowPop(true);
    });
  }
  
  const [loading, setLoading] = useState(true);
  const [showPop, setShowPop] = useState(false);
  const [movies, setMovies] = useState([]);
  const [movie, setMovie] = useState({});
  const [keyword, setKeyword] = useState('frozen');
  const [pages, setPages] = useState(1);
  const [total, setTotal] = useState();
  useEffect(() => {
    getMovies();
  }, []);
  
  const handlePageClick = e => {
    console.log(e.selected);
    getMovies(keyword, (e.selected + 1));
  }
  
  const handleCardClicked = movieId => {
    // console.log(movieId);
    getMovie(movieId);
    
  }
  
  const genCards = () => {
    let allCards = [];
    if(movies){
      movies.map(movie => {
        allCards.push(<Card {...movie} cardClicked={handleCardClicked} />);
      });
    }
    return allCards;
  }
  
  let allCards = genCards();
  
  return(
    <div className='main'>
      <h1 className='head'>Movieflix</h1>
      <Search 
        getInputValue={val => setKeyword(val)} 
        sendEnter={() => getMovies(keyword)} 
        getSubmit={() => getMovies(keyword)} />
      
     { showPop ? <Showexpand {...movie} closePop={() => setShowPop(false)} /> : null }
      
      <div className='cards'>
        { loading ? <Loader /> : 
        (allCards.length === 0 ? 
         <div className='error'>
           No movie found...
           <i class="far fa-grin-beam-sweat"></i>
         </div> : allCards) }
      </div>
      
      <div className='paginate'>
        <ReactPaginate 
          previousLabel={"Back"}
          nextLabel={"Next"}
          breakLabel={"..."}
          breakClassName={"break-me"}
          pageCount={total}
          marginPagesDisplayed={1}
          pageRangeDisplayed={4}
          onPageChange={handlePageClick}
          containerClassName={"pagination"}
          subContainerClassName={"pages pagination"}
          activeClassName={"active"}
          />
      </div>
      
    </div>
  )
  
}



// Loader component -------------------------------
const Loader = props => {
  
  return (
     <div className='loader'>
      Loading...
      <i class="fas fa-sync-alt fa-spin"></i>
    </div>
  )
}


// Search component -------------------------
const Search = (props) => {

  let sendValue = (e) => {
    props.getInputValue(e.target.value)
  }
  
  const handleSubmit = () => {
    props.getSubmit();
  }
  
  const handleKeyDown = (e) => {
    if(e.key === 'Enter'){
      props.sendEnter();
      // console.log('Enter');
    }
  }
  
  return(
    <div className='search'>
      <div className='search-box'>
        <input type='text'
          onChange={sendValue}
          onKeyDown={handleKeyDown}
          placeholder='Find movie...' />
        <button onClick={handleSubmit} ><i class="fas fa-search"></i></button>
      </div>
    </div>
  )
}


// Card component ------------------------------------------------
const Card = props => {
  
  // console.log(props);
  const handleClick = (e) => {
    // console.log(e.target.dataset.id);
    props.cardClicked(e.target.dataset.id);
  }
  return (
    <div className='card' title={props.Title} data-id={props.imdbID} onClick={handleClick}>
      <img src={props.Poster !== 'N/A' ? props.Poster : 'https://via.placeholder.com/163x240/111217/FFFFFF/?text=No%20Image'} alt={props.Title} data-id={props.imdbID} />
    </div>
  )
}



// Show expand component ---------------------------------------
const Showexpand = (props) => {
  
  console.log(props)
  
  return (
    <div className='show-expand'>
      
      <div className='show-content'>
        <i class="show-close fas fa-times" onClick={props.closePop} ></i>
        
        <div className='show-poster'>
          <span className='show-poster-bg'>
            <img src={props.Poster !== 'N/A' ? props.Poster : 'https://via.placeholder.com/163x240/111217/FFFFFF/?text=No%20Image'} alt={props.Title} />
          </span>
          <span className='show-poster-main'>
            <img src={props.Poster !== 'N/A' ? props.Poster : 'https://via.placeholder.com/163x240/111217/FFFFFF/?text=No%20Image'} alt={props.Title} />
          </span>
        </div>
        
        <div className='show-detail'>
          <h2>{props.Title}</h2>
          <ul className="show-tags">
            <li className="show-rated">{props.Country}</li>
            <li className="show-rated">{props.Year}</li>
            <li className="show-year">{props.Rated}</li>
            <li className="show-year">{props.Genre}</li>
          </ul>
          <div class="show-plot">
            <p>{props.Plot}</p>
          </div>
          
          <div class="show-credits">
            <p><strong>Production:</strong> {props.Production}</p>
            <p><strong>Runtime:</strong> {props.Runtime || 'N/A '}</p>
            <p><strong>Rating:</strong> {props.imdbRating}</p>
            <p><strong>Director:</strong> {props.Director}</p>
            <p><strong>Actors:</strong> {props.Actors}</p>
            <p><strong>BoxOffice:</strong> {props.BoxOffice || 'N/A '}</p>
          </div>
        </div>
        
      </div>
    </div>
  )
}

ReactDOM.render(<Main />, document.getElementById('app'));
              
            
!
999px

Console