working demo
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
.idea
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# Roster Grid
|
||||||
|
A smash-bros roster grid template in Vue
|
||||||
|
|
||||||
|
## [View demo](klemek.github.io/roster-grid/)
|
||||||
+95
-20
@@ -2,30 +2,105 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title><!-- TODO -->Change this you moron</title>
|
<title>Roster grid</title>
|
||||||
<link rel="stylesheet" href="style.css">
|
|
||||||
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
|
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
|
||||||
<script type="text/javascript" src="main.js"></script>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<!-- card related -->
|
|
||||||
<!--
|
<style>
|
||||||
<meta name="twitter:card" content="summary_large_image">
|
*, *::after, *::before {
|
||||||
<meta property="og:title" content="">
|
margin: 0;
|
||||||
<meta property="twitter:title" content="">
|
padding: 0;
|
||||||
<meta property="og:description" content="">
|
box-sizing: border-box;
|
||||||
<meta property="twitter:description" content="">
|
font-family: Verdana, serif;
|
||||||
<meta property="og:image" content="https://.../preview_640x320.jpg">
|
color: #F5F5F5;
|
||||||
<meta property="twitter:image" content="">
|
}
|
||||||
<meta property="org:url" content="https://...">
|
html, body, main {
|
||||||
-->
|
height: 100vh;
|
||||||
|
width: 100vw;
|
||||||
|
line-height: 1.5;
|
||||||
|
background-color: #212121;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
width: 100%;
|
||||||
|
height: fit-content;
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
transform: translate(0, -50%);
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
}
|
||||||
|
.item {
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
text-align: center;
|
||||||
|
background-color: #616161;
|
||||||
|
border-color: #212121;
|
||||||
|
border-style: solid;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
user-select: none;
|
||||||
|
cursor:pointer;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main id="app" style="display:none">
|
<main id="app">
|
||||||
<h1>{{title}}</h1>
|
<div class="container">
|
||||||
<br>
|
<h1 v-if="items.length === 0"><i>click to add items</i></h1>
|
||||||
<p v-html="content"></p>
|
<div v-for="item in items" class="item" :style="style" @click.stop="removeItem(item)" title="remove item">
|
||||||
<br>
|
<b>#{{ item.id }}</b>
|
||||||
<small><a href="https://twitter.com/_klemek" target="_blank">@Klemek</a> - <a href="" target="_blank">Github Repository</a> - {{currentYear}}</small>
|
</div>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
<script>
|
||||||
|
const { createApp } = Vue;
|
||||||
|
|
||||||
|
const app = createApp({
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
items: [],
|
||||||
|
style: {},
|
||||||
|
currentId: 0,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
computeStyle() {
|
||||||
|
const N = this.items.length;
|
||||||
|
const W = document.body.scrollWidth;
|
||||||
|
const H = document.body.scrollHeight;
|
||||||
|
const r = 6 / 7;
|
||||||
|
let c = Math.ceil((1 + Math.sqrt(1 + 4 * H * N * r / W)) * W / (2 * H * r));
|
||||||
|
c = (N / (c-1)) === Math.floor(N / (c - 1)) ? c - 1 : c;
|
||||||
|
const rw = 100 / c;
|
||||||
|
this.style = {
|
||||||
|
'font-size': rw * .3 / 2 + 'vw',
|
||||||
|
'width': rw + 'vw',
|
||||||
|
'height': (rw / r) + 'vw',
|
||||||
|
'border-width': rw * .1 / 3 + 'vw',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
addItem() {
|
||||||
|
this.currentId++;
|
||||||
|
this.items.push({id: this.currentId});
|
||||||
|
this.computeStyle();
|
||||||
|
},
|
||||||
|
removeItem(item) {
|
||||||
|
this.items.splice(this.items.indexOf(item), 1);
|
||||||
|
this.computeStyle();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
mounted: function() {
|
||||||
|
this.computeStyle();
|
||||||
|
addEventListener('resize', this.computeStyle);
|
||||||
|
document.body.addEventListener('click', this.addItem);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
app.mount('#app');
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,109 +0,0 @@
|
|||||||
/* exported app, utils */
|
|
||||||
|
|
||||||
const utils = {
|
|
||||||
ajax: {
|
|
||||||
proxy: 'cors-anywhere.herokuapp.com',
|
|
||||||
/**
|
|
||||||
* Define a get HTTP request to be executed with .then/.catch
|
|
||||||
* @param {string} url
|
|
||||||
* @param {Object} data
|
|
||||||
* @param {boolean} proxy - use cors proxy
|
|
||||||
* @returns {Promise<Object|string>} return JSON parsed data or string
|
|
||||||
*/
|
|
||||||
get: (url, data, proxy = false) => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
if (data && Object.keys(data).length) {
|
|
||||||
url += '?' + Object.keys(data)
|
|
||||||
.map(k => k + '=' + encodeURIComponent(data[k]))
|
|
||||||
.join('&')
|
|
||||||
.replace(/%20/g, '+');
|
|
||||||
}
|
|
||||||
const xhr = new XMLHttpRequest();
|
|
||||||
if (proxy) {
|
|
||||||
const http = (window.location.protocol === 'http:' ? 'http:' : 'https:');
|
|
||||||
url = `${http}//${utils.ajax.proxy}/${url}`;
|
|
||||||
}
|
|
||||||
xhr.open('GET', url);
|
|
||||||
xhr.onload = () => {
|
|
||||||
try {
|
|
||||||
resolve(JSON.parse(xhr.responseText));
|
|
||||||
} catch (ignored) {
|
|
||||||
resolve(xhr.responseText);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
xhr.onerror = () => reject(xhr);
|
|
||||||
xhr.send();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
|
||||||
cookies: {
|
|
||||||
/**
|
|
||||||
* Save a value in a cookie
|
|
||||||
* @param {string} name
|
|
||||||
* @param {string} value
|
|
||||||
* @param {number | undefined} days
|
|
||||||
*/
|
|
||||||
set: function (name, value, days = undefined) {
|
|
||||||
const maxAge = !days ? undefined : days * 864e2;
|
|
||||||
document.cookie = `${name}=${encodeURIComponent(value)}${maxAge ? `;max-age=${maxAge};` : ''}`;
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Get a value from a cookie
|
|
||||||
* @param {string} name
|
|
||||||
* @return {string} value from cookie or empty if not found
|
|
||||||
*/
|
|
||||||
get: function (name) {
|
|
||||||
return document.cookie.split('; ').reduce(function (r, v) {
|
|
||||||
const parts = v.split('=');
|
|
||||||
return parts[0] === name ? decodeURIComponent(parts[1]) : r;
|
|
||||||
}, '');
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Delete a cookie
|
|
||||||
* @param {string} name
|
|
||||||
*/
|
|
||||||
delete: function (name) {
|
|
||||||
this.set(name, '', -1);
|
|
||||||
},
|
|
||||||
/**
|
|
||||||
* Clear all cookies
|
|
||||||
*/
|
|
||||||
clear: function () {
|
|
||||||
const cookies = document.cookie.split(';');
|
|
||||||
for (let i = 0; i < cookies.length; i++) {
|
|
||||||
const cookie = cookies[i];
|
|
||||||
const eqPos = cookie.indexOf('=');
|
|
||||||
const name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
|
|
||||||
document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT`;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
let app = {
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
title: 'Vue-Boilerplate',
|
|
||||||
content: 'Fill this page with <i>whatever</i> you\'re going to develop.<br><b>Then enjoy!</b>',
|
|
||||||
};
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
currentYear() {
|
|
||||||
return new Date().getFullYear();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
showApp() {
|
|
||||||
document.getElementById('app').setAttribute('style', '');
|
|
||||||
},
|
|
||||||
},
|
|
||||||
mounted: function () {
|
|
||||||
console.log('app mounted');
|
|
||||||
setTimeout(this.showApp);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onload = () => {
|
|
||||||
app = Vue.createApp(app);
|
|
||||||
app.mount('#app');
|
|
||||||
};
|
|
||||||
@@ -1,159 +0,0 @@
|
|||||||
/*
|
|
||||||
=================================================
|
|
||||||
https://www.joshwcomeau.com/css/custom-css-reset/
|
|
||||||
=================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
1. Use a more-intuitive box-sizing model.
|
|
||||||
*/
|
|
||||||
*,
|
|
||||||
*::before,
|
|
||||||
*::after {
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
2. Remove default margin
|
|
||||||
*/
|
|
||||||
* {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
3. Allow percentage-based heights in the application
|
|
||||||
*/
|
|
||||||
html,
|
|
||||||
body {
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
Typographic tweaks!
|
|
||||||
4. Add accessible line-height
|
|
||||||
5. Improve text rendering
|
|
||||||
*/
|
|
||||||
body {
|
|
||||||
line-height: 1.5;
|
|
||||||
-webkit-font-smoothing: antialiased;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
6. Improve media defaults
|
|
||||||
*/
|
|
||||||
img,
|
|
||||||
picture,
|
|
||||||
video,
|
|
||||||
canvas,
|
|
||||||
svg {
|
|
||||||
display: block;
|
|
||||||
max-width: 100%;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
7. Remove built-in form typography styles
|
|
||||||
*/
|
|
||||||
input,
|
|
||||||
button,
|
|
||||||
textarea,
|
|
||||||
select {
|
|
||||||
font: inherit;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
8. Avoid text overflows
|
|
||||||
*/
|
|
||||||
p,
|
|
||||||
h1,
|
|
||||||
h2,
|
|
||||||
h3,
|
|
||||||
h4,
|
|
||||||
h5,
|
|
||||||
h6 {
|
|
||||||
overflow-wrap: break-word;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
9. Create a root stacking context
|
|
||||||
*/
|
|
||||||
#root,
|
|
||||||
#__next {
|
|
||||||
isolation: isolate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
=================================================
|
|
||||||
CUSTOM STYLE
|
|
||||||
=================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
:root {
|
|
||||||
/* https://materialui.co/colors/ */
|
|
||||||
--hue-primary: 65.52;
|
|
||||||
--sat-primary: 69.96%;
|
|
||||||
--background: hsl(var(--hue-primary), var(--sat-primary), 96.08%);
|
|
||||||
--background-primary: hsl(var(--hue-primary), var(--sat-primary), 93.33%);
|
|
||||||
--color-primary: hsl(var(--hue-primary), var(--sat-primary), 50%);
|
|
||||||
--text-primary: hsl(var(--hue-primary), var(--sat-primary), 25%);
|
|
||||||
--text-secondary: hsl(var(--hue-primary), var(--sat-primary), 30%);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
=================================================
|
|
||||||
https://blog.koley.in/2019/339-bytes-of-responsive-css
|
|
||||||
https://www.swyx.io/css-100-bytes
|
|
||||||
https://gist.github.com/JoeyBurzynski/617fb6201335779f8424ad9528b72c41
|
|
||||||
=================================================
|
|
||||||
*/
|
|
||||||
|
|
||||||
* {
|
|
||||||
box-sizing: border-box;
|
|
||||||
font-family: Verdana, serif;
|
|
||||||
color: var(--text-primary);
|
|
||||||
}
|
|
||||||
|
|
||||||
html,
|
|
||||||
body {
|
|
||||||
padding: 0;
|
|
||||||
max-width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
background-color: var(--background);
|
|
||||||
}
|
|
||||||
|
|
||||||
main {
|
|
||||||
padding: 1.5rem;
|
|
||||||
margin: auto;
|
|
||||||
background-color: var(--background-primary);
|
|
||||||
min-height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
margin-bottom: 0.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
table {
|
|
||||||
border-collapse: collapse;
|
|
||||||
width: 100%;
|
|
||||||
font-size: 0.9em;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1,
|
|
||||||
h2,
|
|
||||||
h3,
|
|
||||||
h4,
|
|
||||||
h5,
|
|
||||||
h6 {
|
|
||||||
margin: 1.5em 0 0.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
p,
|
|
||||||
ul,
|
|
||||||
ol {
|
|
||||||
margin-bottom: 2em;
|
|
||||||
color: var(--text-secondary);
|
|
||||||
font-family: sans-serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media only screen and (min-width: 768px) {
|
|
||||||
main {
|
|
||||||
max-width: 42rem;
|
|
||||||
}
|
|
||||||
table {
|
|
||||||
font-size: inherit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user