modal example
This commit is contained in:
parent
4a441bd9b2
commit
774317793b
|
@ -10,18 +10,43 @@ AFRAME.registerComponent('helloworld', {
|
|||
|
||||
dom: {
|
||||
scale: 3.5,
|
||||
events: ['click'],
|
||||
html: `<div id="hello"><button>hello world</button></div>`,
|
||||
events: ['click','input'],
|
||||
html: `<div id="hello" class="modal">
|
||||
<button class="close">☓</button>
|
||||
<b>Hello world</b>
|
||||
<br><br>
|
||||
<fieldset>
|
||||
<legend>Colour</legend>
|
||||
<input type="radio" id="color-red" name="color" value="red" checked><label for="color-red"> Red</label><br>
|
||||
<input type="radio" id="color-blue" name="color" value="blue"><label for="color-blue"> Blue</label><br>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Material:</legend>
|
||||
<input id="material-wireframe" type="checkbox" name="wireframe"><label for="material-wireframe"> Wireframe</label><br>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>Size:</legend>
|
||||
<input type="range" min="0.1" max="2" value="1" step="0.01" id="myRange" style="background-color: transparent;">
|
||||
</fieldset>
|
||||
<button onclick="AFRAME.scenes[0].exitVR()" style="display: block;">Exit Immersive</button>
|
||||
</div>`,
|
||||
css: `div{ #hello {position:relative;top:0;width:300px} }`
|
||||
},
|
||||
|
||||
events:{
|
||||
"html": function( ){ console.log("htmlmesh component mounted!") }, // html-component was added to this AFRAME entity
|
||||
"title": function(e){ this.dom.el.querySelector("button").innerHTML = e.detail.v }, // this.data.title was changed
|
||||
"click": function(e){ // a click was detected on this.dom.el or AFRAME entity
|
||||
this.data.title = 'hello world '+(new Date().getTime())
|
||||
console.dir(e.detail.target || e.target)
|
||||
html: function( ){ console.log("htmlmesh component mounted!") }, // html-component was added to this AFRAME entity
|
||||
title: function(e){ this.dom.el.querySelector("b").innerHTML = e.detail.v }, // this.data.title was changed
|
||||
click: function(e){ // a click was detected on this.dom.el or AFRAME entity
|
||||
if( !e.detail.target ) return
|
||||
if( e.detail.target.className == 'close' ){
|
||||
this.dom.el.remove()
|
||||
this.el.removeAttribute("html")
|
||||
}
|
||||
},
|
||||
input: function(e){
|
||||
if( !e.detail.target ) return
|
||||
if( e.detail.target.id == 'myRange' ) this.data.title = e.detail.target.value // reactive demonstration
|
||||
}
|
||||
},
|
||||
|
||||
init: function () {
|
||||
|
|
92
com/app.js
92
com/app.js
|
@ -78,8 +78,8 @@ AFRAME.AComponent.prototype.updateProperties = function(updateProperties){
|
|||
let el = document.createElement('div')
|
||||
el.innerHTML = this.dom.html
|
||||
this.data = reactify( el, this.el )
|
||||
this.dom.events.map( (e) => el.addEventListener(e, (ev) => this.el.emit(e,ev) ) )
|
||||
this.dom.el = el
|
||||
this.dom.el = el.childNodes[0]
|
||||
this.dom.events.map( (e) => this.dom.el.addEventListener(e, (ev) => this.el.emit(e,ev) ) )
|
||||
// add css if any
|
||||
if( this.dom.css && !document.head.querySelector(`style#${this.attrName}`) ){
|
||||
document.head.innerHTML += `<style id="${this.attrName}">${this.dom.css}</style>`
|
||||
|
@ -99,23 +99,23 @@ document.head.innerHTML += `
|
|||
html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}main{display:block}h1{font-size:2em;margin:0.67em 0}hr{box-sizing:content-box;height:0;overflow:visible}pre{font-family:monospace, monospace;font-size:1em}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace, monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-0.25em}sup{top:-0.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}[type="button"],[type="reset"],[type="submit"],button{-webkit-appearance:button}[type="button"]::-moz-focus-inner,[type="reset"]::-moz-focus-inner,[type="submit"]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type="button"]:-moz-focusring,[type="reset"]:-moz-focusring,[type="submit"]:-moz-focusring,button:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:0.35em 0.75em 0.625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{vertical-align:baseline}textarea{overflow:auto}[type="checkbox"],[type="radio"]{box-sizing:border-box;padding:0}[type="number"]::-webkit-inner-spin-button,[type="number"]::-webkit-outer-spin-button{height:auto}[type="search"]{-webkit-appearance:textfield;outline-offset:-2px}[type="search"]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details{display:block}summary{display:list-item}template{display:none}[hidden]{display:none}
|
||||
|
||||
:root {
|
||||
--xrsh-primary: #6839dc;
|
||||
--xrsh-primary-fg: #FFF;
|
||||
--xrsh-light-primary: #00a3Ff;
|
||||
--xrsh-secondary: #872eff;
|
||||
--xrsh-third: #ce7df2;
|
||||
--xrsh-box-shadow: #0005;
|
||||
--xrsh-dark-gray: #343334;
|
||||
--xrsh-gray: #424280;
|
||||
--xrsh-white: #fdfdfd;
|
||||
--xrsh-light-gray: #efefef;
|
||||
--xrsh-lighter-gray: #e4e2fb96;
|
||||
--xrsh-font-sans-serif: system-ui, -apple-system, segoe ui, roboto, ubuntu, helvetica, cantarell, noto sans, sans-serif;
|
||||
--xrsh-font-monospace: menlo, monaco, lucida console, liberation mono, dejavu sans mono, bitstream vera sans mono, courier new, monospace, serif;
|
||||
--xrsh-font-size-0: 12px;
|
||||
--xrsh-font-size-1: 14px;
|
||||
--xrsh-font-size-2: 17px;
|
||||
--xrsh-font-size-3: 21px;
|
||||
--xrsh-primary: #3aacff;
|
||||
--xrsh-primary-fg: #FFF;
|
||||
--xrsh-light-primary: #00a3Ff;
|
||||
--xrsh-secondary: #872eff;
|
||||
--xrsh-third: #ce7df2;
|
||||
--xrsh-box-shadow: #0005;
|
||||
--xrsh-dark-gray: #343334;
|
||||
--xrsh-gray: #424280;
|
||||
--xrsh-white: #fdfdfd;
|
||||
--xrsh-light-gray: #efefef;
|
||||
--xrsh-lighter-gray: #e4e2fb96;
|
||||
--xrsh-font-sans-serif: system-ui, -apple-system, segoe ui, roboto, ubuntu, helvetica, cantarell, noto sans, sans-serif;
|
||||
--xrsh-font-monospace: menlo, monaco, lucida console, liberation mono, dejavu sans mono, bitstream vera sans mono, courier new, monospace, serif;
|
||||
--xrsh-font-size-0: 12px;
|
||||
--xrsh-font-size-1: 14px;
|
||||
--xrsh-font-size-2: 17px;
|
||||
--xrsh-font-size-3: 21px;
|
||||
}
|
||||
|
||||
a-scene{
|
||||
|
@ -125,6 +125,9 @@ document.head.innerHTML += `
|
|||
right:0;
|
||||
bottom:0;
|
||||
}
|
||||
canvas{
|
||||
z-index:10;
|
||||
}
|
||||
|
||||
body,
|
||||
html.a-fullscreen body{
|
||||
|
@ -132,6 +135,7 @@ document.head.innerHTML += `
|
|||
font-size: var(--xrsh-font-size-1);
|
||||
font-family: var(--xrsh-font-sans-serif);
|
||||
padding:15px;
|
||||
accent-color: var(--xrsh-light-primary);
|
||||
}
|
||||
|
||||
h1,h2,h3,h4,h5{
|
||||
|
@ -140,19 +144,65 @@ document.head.innerHTML += `
|
|||
h1 { font-size: var(--xrsh-font-size-3); }
|
||||
h2,h3,h4{ font-size: var(--xrsh-font-size-2); }
|
||||
|
||||
.modal{
|
||||
background: #f0f0f0;
|
||||
padding: 20px 20px 10px 20px;
|
||||
border-radius: 15px;
|
||||
display: inline-block;
|
||||
position:relative;
|
||||
z-index:50;
|
||||
}
|
||||
|
||||
button,.btn,input[type=submit]{
|
||||
border-radius:7px;
|
||||
background: var(--xrsh-primary);
|
||||
color: var(--xrsh-primary-fg);
|
||||
transition:1s;
|
||||
transition:0.3s;
|
||||
padding: 10px;
|
||||
font-weight: bold;
|
||||
border-block: none;
|
||||
border: none;
|
||||
cursor:pointer;
|
||||
}
|
||||
button:hover,.btn:hover,input[type=submit]:hover{
|
||||
filter: brightness(0.7);
|
||||
filter: brightness(1.5);
|
||||
}
|
||||
|
||||
button.close{
|
||||
background: transparent;
|
||||
color: #000;
|
||||
display: inline-block;
|
||||
float: right;
|
||||
font-size: 20px;
|
||||
padding: 0;
|
||||
transform: translate(-4px,-3px) scale(1.3,1);
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
legend{
|
||||
font-size: var(--xrsh-font-size-0);
|
||||
margin-bottom: 15px;
|
||||
border-bottom: 1px solid var(--xrsh-light-primary);
|
||||
}
|
||||
|
||||
fieldset{
|
||||
border: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
margin-bottom: 0px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
label{
|
||||
margin-left:10px;
|
||||
}
|
||||
button,input,.btn{
|
||||
margin-bottom:10px;
|
||||
}
|
||||
[type="checkbox"], [type="radio"]{
|
||||
transform: scale(1.4);
|
||||
margin-left:3px;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
`
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
AFRAME.registerComponent('helloworld', {
|
||||
schema:{
|
||||
things: {type:'array'},
|
||||
$: {default: document.createElement('div') }
|
||||
},
|
||||
init: function() {
|
||||
|
||||
this.data = new Proxy( this.data, {
|
||||
html(data){
|
||||
return `
|
||||
<style> ul{ position:absolute; top:0; left:0; z-index:0 } </style>
|
||||
<ul> ${this.render(data)} </ul>
|
||||
`
|
||||
},
|
||||
render(data ){ return `<li>${data.things.join("</li><li>")}</li>`},
|
||||
set(data,k,v){ (data[k] = v) && (data.$.innerHTML = this.html(data)) },
|
||||
get(data,k ){ return data[k] != undefined ? data[k] : data }
|
||||
})
|
||||
|
||||
document.body.appendChild(this.data.$)
|
||||
|
||||
setInterval( () => {
|
||||
// update js --> HTML+AFRAME
|
||||
this.data.things = [ ...this.data.things, Math.random() ].slice(-3)
|
||||
|
||||
},500)
|
||||
|
||||
},
|
||||
|
||||
})
|
Loading…
Reference in New Issue