commit 56ef1edcfe596932403d5752c66dfbeb523a1f25 Author: HerrHase Date: Thu Jul 17 17:57:06 2025 +0200 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/README.md b/README.md new file mode 100644 index 0000000..59d24cc --- /dev/null +++ b/README.md @@ -0,0 +1,88 @@ +# Tiny Components - Validator + +Created with [Riot.js](https://riot.js.org) + +Validate Form or a Single Form-Field, Error Messages can be show just in time +or after Submit entire Form. + +For Validation this Component uses [Validate.js](https://validatejs.org/) + +## Install + +```bash +npm install @tiny-components/validator --save +``` + +## You can use it like this + +```javascript +
( state.validator.submit(event) ) }>> +
+ + +
+
+ + +
+ +
+ + +``` \ No newline at end of file diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..fbf95c8 Binary files /dev/null and b/bun.lockb differ diff --git a/bunfig.toml b/bunfig.toml new file mode 100644 index 0000000..0f8e733 --- /dev/null +++ b/bunfig.toml @@ -0,0 +1,2 @@ +[install.scopes] +"@tiny-components" = "https://gitea.node001.net/api/packages/tiny-components/npm/" diff --git a/example/css/styles.css b/example/css/styles.css new file mode 100644 index 0000000..ab3db09 --- /dev/null +++ b/example/css/styles.css @@ -0,0 +1 @@ +@font-face{font-family:"IBM Plex Mono";src:url("IBMPlexMono.eot");src:url("IBMPlexMono.eot?#iefix") format("embedded-opentype"),url("IBMPlexMono.woff2") format("woff2"),url("IBMPlexMono.woff") format("woff"),url("IBMPlexMono.ttf") format("truetype");font-weight:normal;font-style:normal;font-display:swap}@font-face{font-family:"IBM Plex Mono";src:url("IBMPlexMono-Bold.eot");src:url("IBMPlexMono-Bold.eot?#iefix") format("embedded-opentype"),url("IBMPlexMono-Bold.woff2") format("woff2"),url("IBMPlexMono-Bold.woff") format("woff"),url("IBMPlexMono-Bold.ttf") format("truetype");font-weight:bold;font-style:normal;font-display:swap}:root{--grid-columns: 12;--grid-grid-spacing: 15px;--grid-xs: 576px;--grid-sm: 768px;--grid-md: 992px;--grid-lg: 1200px;--grid-xlg: 1600px;--grid-xxs-max: 575px;--grid-xs-max: 767px;--grid-sm-max: 991px;--grid-md-max: 1199px;--grid-lg-max: 1599px}:root{--body:#f9f9f9;--text:#363636;--text-contrast:#fff;--primary:#3e3e3e;--primary-contrast:#3e3e3e;--active:#717171;--active-contrast:#fff;--link:#363636;--link-hover:#d95959;--danger:#d95959;--danger-contrast:#ecacac;--info:#0090d4;--info-constrast:rgb(59,192.1320754717,255);--success:#64ac64;--success-contrast:hsl(120,30.2521008403%,73.3333333333%);--warning:#f0ad4e;--warning-contrast:rgb(247.96875,216.5625,172.03125);--background:#3e3e3e;--background-contrast:#fff;--background-alpha:rgba(0,0,0,.7);--border:#3e3e3e;--border-contrast:#fff;--font-family: IBM Plex Mono, sans-serif}html{font-size:100%;line-height:1.15;-webkit-text-size-adjust:100%}body,html{margin:0;height:100%}html,legend{box-sizing:border-box}body{font-family:var(--font-family);color:var(--text);background-color:var(--body);direction:ltr;font-size:.9rem;line-height:1.618}@media only screen and (min-width: 992px){body{font-size:1rem}}a{color:var(--link);transition:color .5s;text-decoration:none}a:hover{color:var(--link-hover)}a:focus{outline:none}main{display:block}*,*::after,*::before{box-sizing:inherit}table{border-collapse:collapse;border-spacing:0}figure{margin:0}figcaption{margin:0}p{margin:0}button,input,optgroup,select,textarea{margin:0}fieldset{margin:0 0 1rem}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}legend{box-sizing:border-box;display:table;max-width:100%;padding:0;white-space:normal}[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}hr{box-sizing:content-box;height:0;overflow:visible;border:0;border-top:1px solid var(--border);margin:0 0 1rem}progress{vertical-align:baseline}details{display:block}summary{display:list-item}code,kbd,pre,samp{font-family:var(--font-family);font-size:.9rem}.content p{margin:0 0 1rem}@media only screen and (min-width: 992px){.content p{margin:0 0 1.2rem}}.content a,.content ins,.content u{text-decoration-skip:ink edges}.content a{text-decoration:underline}.content b,.content strong{font-weight:bolder}.content small{font-size:80%}.content sub,.content sup{font-size:70%;line-height:0;position:relative;vertical-align:baseline}.content sub{bottom:-0.25em}.content sup{top:-0.5em}.content abbr[title]{border-bottom:1px dotted;cursor:help;text-decoration:none}.content mark{padding:.25rem;background-color:var(--warning)}.content blockquote{border-left:1px solid var(--border);margin-left:0;padding:.6rem .8rem}.content blockquote p:last-child{margin-bottom:0}.content dl,.content ol,.content ul{padding:0;margin:0 0 1rem}@media only screen and (min-width: 992px){.content dl,.content ol,.content ul{margin:0 0 1.2rem}}.content ul{margin-left:1.5rem}.content ol{margin-left:2.5rem}.content ol ol,.content ul ul{margin-top:0;margin-left:1.5rem}.content ol{list-style:decimal outside}.content ul{list-style:square outside}.content dl{margin-left:.5rem}.content dd,.content dt{margin:0}.content dt{font-weight:bold}.content code{white-space:pre;display:block;color:var(--text-contrast);overflow-y:hidden;overflow-x:auto;border:1px solid var(--border);border-radius:2px;background-color:var(--background);margin:0 0 1rem;padding:.6rem .8rem}@media only screen and (min-width: 992px){.content code{margin:0 0 1.2rem}}@media only screen and (min-width: 992px){.content code{padding:.7rem 1rem .9rem}}.highlight{padding:.15rem .4rem .25rem;background:var(--primary);color:var(--text-contrast);border-radius:2px}h1,.h1,h2,.h2,h3,.h3,h4,.h4,h5,.h5,h6,.h6{font-family:"IBM Plex Mono",sans-serif;font-weight:bold;line-height:1.2;margin:0 0 1rem}h1.highlight,.h1.highlight,h2.highlight,.h2.highlight,h3.highlight,.h3.highlight,h4.highlight,.h4.highlight,h5.highlight,.h5.highlight,h6.highlight,.h6.highlight{display:table}h1,.h1{font-size:2.5rem}h2,.h2{font-size:2rem}h3,.h3{font-size:1.75rem}h4,.h4{font-size:1.5rem}h5,.h5{font-size:1.25rem}h6,.h6{font-size:1rem}@media only screen and (min-width: 992px){h1,.h1{font-size:2.75rem}h2,.h2{font-size:2.5rem}h3,.h3{font-size:2rem}h4,.h4{font-size:1.75rem}h5,.h5{font-size:1.5rem}h6,.h6{font-size:1.2rem}}.badge{display:inline-block;background-color:var(--background);color:var(--text-contrast);font-size:.85rem;padding:.4rem .8rem;border:1px solid var(--border);border-radius:2px}.badge--round{display:inline-flex;justify-content:center;border-radius:50%;width:2.8em}.button{appearance:none;position:relative;display:inline-flex;align-items:center;text-decoration:none;font-family:var(--font-family);font-size:1rem;border:1px solid var(--border);background-color:var(--background-contrast);color:var(--text);border-radius:2px;transition:background-color .1s;margin:0 0 1rem;padding:.5rem 1.3rem;width:100%}@media only screen and (min-width: 768px){.button{width:auto}}.button--small{padding:.3rem 1.1rem;font-size:.8rem}.button:hover,.button--selected{cursor:pointer;text-decoration:none;color:#fff;background-color:var(--active)}.button:focus,.button:active{outline:1px solid var(--active)}.button:disabled{opacity:.5}.button:disabled:hover{cursor:not-allowed;border:1px solid var(--border);background-color:var(--background-contrast);color:var(--border)}.button--transparent{margin:0;padding:0;border:none;background:rgba(0,0,0,0);border-radius:0}.button--transparent:focus,.button--transparent:active{outline:none}.button--danger{border-color:var(--danger)}.button--danger:hover{background-color:var(--danger)}.button--danger:focus,.button--danger:active{outline:2px solid var(--danger)}.button--info{border-color:var(--info)}.button--info:hover{background-color:var(--info)}.button--info:focus,.button--info:active{outline:2px solid var(--info)}.button--warning{border-color:var(--warning)}.button--warning:hover{background-color:var(--warning)}.button--warning:focus,.button--warning:active{outline:2px solid var(--warning)}.button--success{border-color:var(--success)}.button--success:hover{background-color:var(--success)}.button--success:focus,.button--success:active{outline:2px solid var(--success)}.button--outline{background-color:rgba(0,0,0,0)}.button--outline:hover{color:var(--border);border-color:#a4a4a4;background-color:rgba(0,0,0,0)}.button--danger.button--outline:hover{border-color:#ecacac}.button--info.button--outline:hover{border-color:rgb(59,192.1320754717,255)}.button--warning.button--outline:hover{border-color:rgb(247.96875,216.5625,172.03125)}.button--success.button--outline:hover{border-color:hsl(120,30.2521008403%,73.3333333333%)}.button--full{background-color:var(--active);color:#fff}.button--full:hover{background-color:var(--background-contrast);color:var(--text)}.button--danger.button--full{background-color:var(--danger)}.button--danger.button--full:hover{background-color:var(--background-contrast);border-color:var(--danger)}.button--danger.button--full:focus,.button--danger.button--full:active{outline:2px solid var(--danger)}.button--info.button--full{background-color:var(--info)}.button--info.button--full:hover{background-color:var(--background-contrast);border-color:var(--info)}.button--info.button--full:focus,.button--info.button--full:active{outline:2px solid var(--info)}.button--warning.button--full{background-color:var(--warning)}.button--warning.button--full:hover{background-color:var(--background-contrast);border-color:var(--warning)}.button--warning.button--full:focus,.button--warning.button--full:active{outline:2px solid var(--warning)}.button--success.button--full{background-color:var(--success)}.button--success.button--full:hover{background-color:var(--background-contrast);border-color:var(--success)}.button--success.button--full:focus,.button--success.button--full:active{outline:2px solid var(--success)}.field-group{margin:0 0 1rem}.field-group--valid .field-text{border-color:var(--success)}.field-group--valid .icon{fill:var(--success)}.field-group--error .field-text{border-color:var(--danger)}.field-group--error .icon{fill:var(--danger)}.field-label{font-size:1rem;font-family:var(--font-family)}.field-label .icon{vertical-align:text-bottom}.field-label:hover{cursor:pointer}.field-text,.field-choice{font-family:var(--font-family);font-size:.95rem;width:100%;border:1px solid #a4a4a4;border-radius:2px;margin:.7rem 0 0}.field-text:focus,.field-text:active,.field-choice:focus,.field-choice:active{outline:0;border-color:var(--border)}.field-text{padding:.8em 1.1em}textarea.field-text{height:180px}.field-choice{appearance:none;padding:.8em;background-image:linear-gradient(to right, #717171, #717171);background-position:100%;background-size:1.5rem 100%;background-repeat:no-repeat}.field-choice:active,.field-choice:focus{background-image:linear-gradient(to right, #3e3e3e, #3e3e3e)}[type=checkbox].field-choice,[type=radio].field-choice{position:relative;display:none}[type=checkbox].field-choice~.field-choice__checked,[type=radio].field-choice~.field-choice__checked{display:none}[type=checkbox].field-choice:checked~.field-choice__checked,[type=radio].field-choice:checked~.field-choice__checked{display:inline-block}[type=checkbox].field-choice:checked~.field-choice__unchecked,[type=radio].field-choice:checked~.field-choice__unchecked{display:none}svg.field-choice__unchecked{fill:var(--active)}svg.field-choice__checked{fill:var(--success)}.field-error{display:inline-block;width:100%;padding:.6em .5em;font-size:.8rem}.field-switch{position:relative;display:inline-block;width:75px;height:35px;border:1px solid var(--border);border-radius:2px}.field-switch:after{position:absolute;top:0;left:0;width:50%;height:100%;content:"";border:1px solid var(--border);border-color:var(--border-contrast);border-radius:2px;background-color:var(--active);transition:transform .25s}[type=checkbox].field-choice~.field-switch:after{left:0}[type=checkbox].field-choice:checked~.field-switch{border-color:var(--success)}[type=checkbox].field-choice:checked~.field-switch:after{background-color:var(--success);transform:translateX(100%)}.field-error{color:var(--danger)}.group__item{width:auto;display:inline-block;margin:0 0 1rem;margin-right:.25rem}.group__item:last-child{margin-right:0}.icon{width:1em;height:1em;max-height:100%;max-width:100%;vertical-align:middle;overflow:hidden;font-size:1.4rem;fill:var(--text)}.hero{position:relative}.hero img{width:100%;object-fit:cover;object-position:50% 50%}.tabs{display:flex;flex-direction:column;width:100%;border-bottom:1px solid var(--border)}@media only screen and (min-width: 768px){.tabs{width:auto;flex-direction:row}}.tabs__item{min-height:2.8em;display:flex;align-items:center;padding:0 1em;color:var(--text);transition:background-color .1s;border-bottom:3px solid rgba(0,0,0,0);background-color:rgba(0,0,0,0);width:100%}@media only screen and (min-width: 768px){.tabs__item{width:auto;display:inline-flex}}.tabs__item:hover{cursor:pointer;background-color:var(--active);color:var(--text-contrast);border-top-left-radius:2px;border-top-right-radius:2px}.tabs__item--selected{color:var(--text);border-color:var(--border)}.tabs--contrast{border:0}.tabs--contrast .tabs__item{color:var(--text-contrast)}.tabs--contrast .tabs__item:hover{background-color:var(--background-contrast);color:var(--text);border-radius:0}.tabs--contrast .tabs__item--selected{border-color:var(--border-contrast)}.tabs--contrast .tabs__item--selected:hover{border-color:var(--active)}.panel,.sidebar__inner{border:1px solid var(--border);border-radius:2px;background-color:var(--background-contrast)}.panel__body,.sidebar__body{padding:.6rem .8rem}@media only screen and (min-width: 992px){.panel__body,.sidebar__body{padding:.7rem 1rem .9rem}}.panel--border-highlight{border-left-width:12px}.progress{height:40px;width:100%;border:1px solid var(--border)}.progress__inner{height:100%;border:1px solid var(--background-contrast);background-color:var(--background)}.figure{margin:0;display:inline-block;line-height:0;border:1px solid var(--border);border-radius:2px;overflow:hidden}.figure__caption{padding:.75em 1.1em;font-size:.7rem;background:var(--background);line-height:1.618;margin:0;color:var(--text-contrast);border-top:1px solid var(--border-contrast)}.figure .media{border:0;border-radius:0}.media{border-radius:2px;border:1px solid var(--border);width:100%;height:auto}.table{width:100%;border:1px solid var(--border);background:var(--white)}.table__td{color:var(--text)}.table__td,.table__th{text-align:left;border-bottom:1px solid var(--border);padding:.25em .75em}@media only screen and (min-width: 992px){.table__td,.table__th{padding:.5em 1.25em}}.table__th{color:#fff;background-color:var(--background)}.table--striped .table__tr:nth-child(even) .table__td{background-color:hsl(0,0%,89.3137254902%)}.table--hover .table__tr:hover .table__td{color:#fff;background-color:rgb(87.5,87.5,87.5)}.bar{display:flex;min-height:2.8em;background-color:var(--background);color:var(--text-contrast);border:1px solid var(--border);border-radius:2px}.bar__start{justify-content:start}.bar__main{flex-grow:1}.bar__end{justify-content:end}.bar__start,.bar__main,.bar__end{display:flex;align-self:center;align-items:center;margin-left:.75em}.bar__start:last-child,.bar__main:last-child,.bar__end:last-child{margin-right:.75em}.modal{position:fixed;width:100%;height:100%;top:0;left:0;display:flex;visibility:hidden;transition:visibility 0s linear .5s;padding:1rem;z-index:20;align-items:center;justify-content:center}.modal:before{position:fixed;top:0;left:0;width:100%;height:100%;background-color:transparent;transition:background-color .5s;z-index:19;content:"";transition:background-color .5s}.modal__inner{position:relative;z-index:21;transition:transform .5s;transform:scale(0);max-width:600px;width:100%}.modal__title{font-size:2rem;text-align:center;white-space:pre-line;margin-bottom:2rem}.modal__title .icon{font-size:3rem}.modal__title,.modal__body{color:var(--text-contrast)}.modal__body{margin-bottom:1.5rem}.modal .button{color:var(--text-contrast)}.modal--open{display:flex;visibility:visible;transition:visibility 0s linear 0s}.modal--open:before{background-color:var(--background-alpha)}.modal--open .modal__inner{transform:scale(1)}.loading{height:60px;width:47px;margin:0 auto;display:flex;align-items:center}.loading span{display:block;width:15px;height:80px;background-color:var(--background);animation-name:loading-animation;animation-duration:.5s;animation-iteration-count:infinite;animation-delay:.15s;border-top:1px solid var(--background);border-bottom:1px solid var(--background)}.loading span:first-child{margin-right:1px;animation-delay:0s}.loading span:last-child{margin-left:1px;animation-delay:.3s}@keyframes loading-animation{0%{height:60px}50%{height:40px}100%{height:60px}}.sidebar{position:fixed;z-index:9;top:0;left:0;width:100%;height:100%;max-width:95%;visibility:hidden;transition:visibility 0s linear .5s}.sidebar:before{position:fixed;top:0;left:0;width:100%;height:100%;background-color:transparent;transition:background-color .5s;z-index:9;content:"";transition:background-color .5s}.sidebar__inner{position:relative;height:100%;z-index:10;transition:transform .2s;transform:translateX(-100%)}.sidebar__footer{position:fixed;left:0;bottom:0;display:flex;justify-content:space-between;background:var(--background);width:100%;padding:1rem}.sidebar--open{visibility:visible;transition:visibility 0s linear 0s}.sidebar--open .sidebar__inner{transform:translateX(0)}.sidebar--open:before{background:var(--background-alpha)}@media only screen and (min-width: 992px){.sidebar{max-width:33%}}.toast{display:flex;background:var(--background);border:1px solid var(--border);max-width:800px;width:max-content;margin-top:1.25rem;position:relative;left:calc(-100% - 2rem);transition:left .1s;pointer-events:auto}.toast--animation{left:0}.toast__body{width:100%;padding:1em 1.25em}.toast__button{border:0;appearance:none;background:var(--background)}.toast__button:hover{cursor:pointer}.toast__body,.toast__button{color:var(--text-contrast)}.toast__icon,.toast__button{display:flex;align-self:stretch;align-items:center;padding:0 1em}.toast__icon svg,.toast__button svg{font-size:2rem}.toast--danger{background:var(--danger)}.toast--danger .toast__button{background:var(--danger)}.toast-wrapper{position:fixed;left:0;bottom:0;margin:2rem;z-index:30;pointer-events:none}.masonry{display:flex;width:100%;flex-flow:row wrap;gap:15px}.masonry__item{width:100%;height:200px}@media only screen and (min-width: 768px){.masonry__item{height:300px}.masonry__item:nth-child(4n+1){width:calc(25% - 10px)}.masonry__item:nth-child(4n+2){width:calc(55% - 10px)}.masonry__item:nth-child(4n+3){width:calc(20% - 10px)}.masonry__item:nth-child(4n+4){width:calc(67% - 10px)}.masonry__item:nth-child(4n+5){width:calc(33% - 10px)}}.slider{position:relative;overflow-x:visible}.slider__inner{display:flex;white-space:nowrap}.slider__item{padding:0 .6em;display:inline-block;white-space:normal;flex-shrink:0}.wrap{-webkit-flex-wrap:wrap;flex-wrap:wrap}.wrap-reverse{-webkit-flex-wrap:wrap-reverse;flex-wrap:wrap-reverse}.justify-end{-webkit-justify-content:flex-end;justify-content:flex-end}.justify-center{-webkit-justify-content:center;justify-content:center}.container{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;width:100%;margin-right:auto;margin-left:auto;padding-right:30px;padding-left:30px}.container .grid{margin-right:-15px;margin-left:-15px}@media(min-width: 576px){.container{max-width:576px}}@media(min-width: 768px){.container{max-width:768px}}@media(min-width: 992px){.container{max-width:992px}}@media(min-width: 1200px){.container{max-width:1200px}}@media(min-width: 1600px){.container{max-width:1600px}}.grid{display:block;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;display:-webkit-flex;display:flex;-webkit-flex-wrap:wrap;flex-wrap:wrap;padding:0;margin:0 auto;position:relative;list-style-type:none}.grid::after,.grid::before{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.col-12{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;position:relative;width:100%;vertical-align:top;padding:15px}.col-12::after,.col-12::before{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.col-12 .grid{-webkit-flex:1 1 auto;flex:1 1 auto;margin:-15px}.col-12{width:100%}.border{border:1px solid var(--border)}.round{border-radius:50%}.float-right{float:right}.centered{margin-left:auto;margin-right:auto}.absolute{position:absolute !important}.fixed{position:fixed !important}.relative{position:relative !important}.overflow-x-hidden{overflow-x:hidden}.object-fit-cover{object-fit:cover}.h-1{height:1px}.h-100{height:100%}.w-col-12{width:100%}.h-1{height:0.5rem}.h-6{height:3rem}.h-17{height:8.5rem}.h-70{height:35rem}.marginless{margin:0}.m-last-child-0>*:last-child{margin:0}.m-bottom-last-child-0>*:last-child{margin-bottom:0}.m-1{margin:1px}.m-top-4{margin-top:1.125rem}.m-top-5{margin-top:2rem}.m-bottom-0{margin-bottom:0}.m-bottom-4{margin-bottom:1.125rem}.m-bottom-5{margin-bottom:2rem}.m-left-3{margin-left:.5rem}@media only screen and (min-width: 768px){.m-left-sm-3{margin-left:.5rem}}.p-0{padding:0}.p-1{padding:1px}.p-0{padding:.125rem}.p-1{padding:0rem}.p-3{padding:.5rem}.color-text-contrast{color:var(--text-contrast)}.fill-text{fill:var(--text)}.fill-text svg{fill:var(--text)}.fill-text-contrast{fill:var(--text-contrast)}.fill-text-contrast svg{fill:var(--text-contrast)}.fill-danger{fill:var(--danger)}.fill-danger svg{fill:var(--danger)}.fill-success{fill:var(--success)}.fill-success svg{fill:var(--success)}.fill-text-hover:hover{fill:var(--text)}.fill-text-hover:hover svg{fill:var(--text)}.border-color-danger{border-color:var(--danger)}.border-color-info{border-color:var(--info)}.background-color-primary{background-color:var(--primary)}.left{text-align:left}.right{text-align:right}.center{text-align:center}.justify{text-align:justify}.uppercase{text-transform:uppercase}.lowercase{text-transform:lowercase}.crossed{text-decoration:line-through}.underline{text-decoration:underline}.capitalize{text-transform:capitalize}.italic{font-style:italic}.light{font-weight:lighter}.normal{font-weight:normal}.medium{font-weight:medium}.bold{font-weight:bolder}.size-big{font-size:2.7rem}.tiny-field-upload input[type=file]{display:none}.tiny-field-upload__files{display:flex;flex-wrap:wrap;margin:0 -0.5em 0}.tiny-field-upload__files-item{width:calc(25% - 1em);margin:0 .5em 1em}.tiny-field-upload__files-item img.tiny-field-upload__files-media{width:100%}.tiny-field-upload__files-item .panel__body,.tiny-field-upload__files-item .sidebar__body{line-height:0} diff --git a/example/index.html b/example/index.html new file mode 100644 index 0000000..3e05043 --- /dev/null +++ b/example/index.html @@ -0,0 +1,73 @@ + + + + + + Tiny Components | Field Upload + + + + + + +
+
+
+

+ @tiny-components/upload +

+
+ +
+
+ +
+
+
+ +

+ Upload +

+ +
+
+ + +
+ +
+ +
+ +
+ +

+ Upload / Max +

+ +
+
+ + +
+ +
+ +
+
+
+ + + + diff --git a/example/js/index.js b/example/js/index.js new file mode 100644 index 0000000..0b54d38 --- /dev/null +++ b/example/js/index.js @@ -0,0 +1 @@ +(()=>{"use strict";const t=new Map,e=Symbol("riot-component"),n=new Set,s="is",i="mount",r="update",o="unmount",a="shouldUpdate",u="onBeforeMount",l="onMounted",c="onBeforeUpdate",d="onUpdated",h="onBeforeUnmount",p="onUnmounted",m="props",f="state",b="slots",v="root",y=Symbol("pure"),x=Symbol("is_updating"),g=Symbol("parent"),N=Symbol("attributes"),T=Symbol("template"),E=0,A=1,O=2,M=3,j=4,w={ATTRIBUTE:0,EVENT:A,TEXT:2,VALUE:3,REF:j};function S(t){return t.replace(/-(\w)/g,(t,e)=>e.toUpperCase())}function _(t,e){throw new Error(t,{cause:e})}function C(t){const e=new Map,n=n=>(e.has(n)||e.set(n,t.call(this,n)))&&e.get(n);return n.cache=e,n}function D(t){return t.reduce((t,e)=>{const{value:n,type:s}=e;switch(!0){case e.type===j:break;case!e.name&&0===s:return{...t,...n};case 3===s:t.value=e.value;break;default:t[S(e.name)]=e.value}return t},{})}function k(t,e){return typeof t===e}function I(t){const e=t.ownerSVGElement;return!!e||null===e}function B(t){return"template"===t.tagName.toLowerCase()}function U(t){return k(t,"function")}function L(t){return!$(t)&&t.constructor===Object}function $(t){return null==t}function R(){return this}function F(t){return U(t)?t.prototype&&t.prototype.constructor?new t:t():t}function P(t){return Array.from(t.attributes).reduce((t,e)=>(t[S(e.name)]=e.value,t),{})}function z(t){for(;t.firstChild;)t.removeChild(t.firstChild)}const V=t=>t.remove(),H=(t,e)=>e&&e.parentNode&&e.parentNode.insertBefore(t,e),K=(t,e)=>e&&e.parentNode&&e.parentNode.replaceChild(t,e),X={[i](t){this.el=t},[r]:R,[o](t,e,n=!1){n?V(this.el):n||z(this.el)},clone(){return{...this}},createDOM:R},q=0,G=1,W=2,Y=3,Z=4,J={EACH:0,IF:1,SIMPLE:2,TAG:3,SLOT:4};function Q(t,e,n,s={}){return Object.defineProperty(t,e,{value:n,enumerable:!1,writable:!1,configurable:!0,...s}),t}function tt(t,e,n){return Object.entries(e).forEach(([e,s])=>{Q(t,e,s,n)}),t}function et(t,e){return Object.entries(e).forEach(([e,n])=>{t[e]||(t[e]=n)}),t}const nt=Symbol(),st=Symbol();function it(t){const e=t.dom.cloneNode(!0),{head:n,tail:s}=function(){const t=document.createTextNode(""),e=document.createTextNode("");return t[nt]=!0,e[st]=!0,{head:t,tail:e}}();return{avoidDOMInjection:!0,fragment:e,head:n,tail:s,children:[n,...Array.from(e.childNodes),s]}}const rt=Symbol("unmount"),ot={nodes:[],mount(t,e){return this.update(t,e)},update(t,e){const{placeholder:n,nodes:s,childrenMap:i}=this,r=t===rt?null:this.evaluate(t),o=r?Array.from(r):[],{newChildrenMap:a,batches:u,futureNodes:l}=function(t,e,n,s){const{condition:i,template:r,childrenMap:o,itemName:a,getKey:u,indexName:l,root:c,isTemplateTag:d}=s,h=new Map,p=[],m=[];return t.forEach((t,s)=>{const f=function(t,{itemName:e,indexName:n,index:s,item:i}){Q(t,e,i),n&&Q(t,n,s);return t}(Object.create(e),{itemName:a,indexName:l,index:s,item:t}),b=u?u(f):s,v=o.get(b),y=[];if(function(t,e){return!!t&&!t(e)}(i,f))return;const x=!v,g=v?v.template:r.clone(),N=g.el||c.cloneNode(),T=d&&x?it(g):g.meta;x?p.push(()=>g.mount(N,f,n,T)):p.push(()=>g.update(f,n)),d?y.push(...T.children):y.push(N),o.delete(b),m.push(...y),h.set(b,{nodes:y,template:g,context:f,index:s})}),{newChildrenMap:h,batches:p,futureNodes:m}}(o,t,e,this);return((t,e,n,s)=>{const i=e.length;let r=t.length,o=i,a=0,u=0,l=null;for(;as-u){const i=n(t[a],0);for(;u{if(s<0){const n=t[t.length-1];if(n){const{template:s,nodes:i,context:r}=n;i.pop(),i.length||(t.pop(),s.unmount(r,e,null))}}return n}}(Array.from(i.values()),e),n),u.forEach(t=>t()),this.childrenMap=a,this.nodes=l,this},unmount(t,e){return this.update(rt,e),this}};const at={mount(t,e){return this.update(t,e)},update(t,e){const n=!!this.evaluate(t),s=!this.value&&n,i=this.value&&!n,r=()=>{const n=this.node.cloneNode();H(n,this.placeholder),this.template=this.template.clone(),this.template.mount(n,t,e)};switch(!0){case s:r();break;case i:this.unmount(t);break;default:n&&this.template.update(t,e)}return this.value=n,this},unmount(t,e){return this.template.unmount(t,e,!0),this}};const ut="undefined"==typeof Element?{}:Element.prototype,lt=C(t=>ut.hasOwnProperty(t));function ct({node:t,name:e,isBoolean:n,value:s},i){if(!e)return s&&function(t,e,n){const s=e?Object.keys(e):[];Object.keys(n).filter(t=>!s.includes(t)).forEach(e=>t.removeAttribute(e))}(t,i,s),void(i&&function(t,e){Object.keys(e).forEach(n=>ct({node:t,name:n},e[n]))}(t,i));!lt(e)&&(function(t){return k(t,"boolean")}(i)||L(i)||U(i))&&(t[e]=i),!function(t,e){return e?!t&&0!==t:null==t}(i,n)?function(t){return["string","number","boolean"].includes(typeof t)}(i)&&t.setAttribute(e,function(t,e,n){return!0===e&&n?t:e}(e,i,n)):t.removeAttribute(e)}const dt=/^on/,ht={handleEvent(t){this[t.type](t)}},pt=new WeakMap;function mt(t){return $(t)?"":t}const ft=(t,e)=>t.childNodes[e];const bt={[E]:ct,[A]:function({node:t,name:e},n){const s=e.replace(dt,""),i=pt.get(t)||(t=>{const e=Object.create(ht);return pt.set(t,e),e})(t),[r,o]=(t=>Array.isArray(t)?t:[t,!1])(n),a=i[s],u=r&&!a;a&&!r&&t.removeEventListener(s,i),u&&t.addEventListener(s,i,o),i[s]=r},[O]:function({node:t},e){t.data=mt(e)},[M]:function({node:t},e){t.value=mt(e)},[j]:function({node:t,value:e},n){n?n(t):e(null)}},vt={mount(t){return this.value=this.evaluate(t),bt[this.type](this,this.value),this},update(t){const e=this.evaluate(t);return this.value!==e&&(bt[this.type](this,e),this.value=e),this},unmount(){return[A,j].includes(this.type)&&bt[this.type](this,null),this}};function yt(t,e){return{...vt,...e,node:2===e.type?ft(t,e.childNodeIndex):t}}const xt=(t,e)=>e?.find(e=>e.id===t),gt=(t,e)=>t[g]||e,Nt={attributes:[],getTemplateScope(t,e){return((t,e,n)=>{if(!t||!t.length)return n;const s=t.map(t=>({...t,value:t.evaluate(e)}));return Object.assign(Object.create(n||null),D(s))})(this.attributes,t,e)},mount(t,e){const n=!!t.slots&&xt(this.name,t.slots),{parentNode:s}=this.node,i=n?gt(t,e):t;return this.templateData=n?.html?n:xt(this.name,i.slots),this.template=this.templateData&&St(this.templateData.html,this.templateData.bindings).createDOM(s)||this.template?.clone(),this.template&&(z(this.node),this.template.mount(this.node,this.getTemplateScope(t,i),i),this.template.children=Array.from(this.node.childNodes)),Tt(this.node),V(this.node),this},update(t,e){if(this.template){const n=this.templateData?gt(t,e):t;this.template.update(this.getTemplateScope(t,n),n)}return this},unmount(t,e,n){return this.template&&this.template.unmount(this.getTemplateScope(t,e),null,n),this}};function Tt(t){const e=t&&t.firstChild;e&&(H(e,t),Tt(t))}function Et(t){return t.reduce((t,{bindings:e})=>t.concat(e),[])}const At={mount(t){return this.update(t)},update(t,e){const n=this.evaluate(t);return n&&n===this.name?this.tag.update(t):(this.unmount(t,e,!0),this.name=n,this.tag=function(t,e=[],n=[]){return t?t({slots:e,attributes:n}):St(function(t){return t.reduce((t,e)=>t+e.html,"")}(e),[...Et(e),{expressions:n.map(t=>({type:0,...t}))}])}(this.getComponent(n),this.slots,this.attributes),this.tag.mount(this.node,t)),this},unmount(t,e,n){return this.tag&&this.tag.unmount(n),this}};const Ot={[G]:function(t,{evaluate:e,template:n}){const s=document.createTextNode("");return H(s,t),V(t),{...at,node:t,evaluate:e,placeholder:s,template:n.createDOM(t)}},[W]:function(t,{expressions:e}){return n=e.map(e=>yt(t,e)),["mount","update","unmount"].reduce((t,e)=>({...t,[e]:t=>n.map(n=>n[e](t))&&s}),{});var n,s},[q]:function(t,{evaluate:e,condition:n,itemName:s,indexName:i,getKey:r,template:o}){const a=document.createTextNode(""),u=t.cloneNode();return H(a,t),V(t),{...ot,childrenMap:new Map,node:t,root:u,condition:n,evaluate:e,isTemplateTag:B(u),template:o.createDOM(t),getKey:r,indexName:i,itemName:s,placeholder:a}},[Y]:function(t,{evaluate:e,getComponent:n,slots:s,attributes:i}){return{...At,node:t,evaluate:e,slots:s,attributes:i,getComponent:n}},[Z]:function(t,{name:e,attributes:n,template:s}){return{...Nt,attributes:n,template:s,node:t,name:e}}};function Mt(t,e){return t.map(t=>2===t.type?{...t,childNodeIndex:t.childNodeIndex+e}:t)}function jt(t,e){return I(t)?function(t,e){return e.ownerDocument.importNode((new window.DOMParser).parseFromString(`${t}`,"application/xml").documentElement,!0)}(e,t):function(t,e){const n=B(e)?e:document.createElement("template");return n.innerHTML=t,n.content}(e,t)}const wt={createDOM(t){return this.dom=this.dom||function(t,e){return e&&("string"==typeof e?jt(t,e):e)}(t,this.html)||document.createDocumentFragment(),this},mount(t,e,n,s={}){t||_("Please provide DOM node to mount properly your template"),this.el&&this.unmount(e);const{fragment:i,children:r,avoidDOMInjection:o}=s,{parentNode:a}=r?r[0]:t,u=B(t),l=u?function(t,e,n){const s=Array.from(t.childNodes);return Math.max(s.indexOf(e),s.indexOf(n.head)+1,0)}(a,t,s):null;this.createDOM(t);const c=i||this.dom.cloneNode(!0);return this.el=u?a:t,this.children=u?r||Array.from(c.childNodes):null,!o&&c&&function(t,e){switch(!0){case I(t):!function(t,e){for(;t.firstChild;)e.appendChild(t.firstChild)}(e,t);break;case B(t):t.parentNode.replaceChild(e,t);break;default:t.appendChild(e)}}(t,c),this.bindings=this.bindingsData.map(t=>function(t,e,n){const{selector:s,type:i,redundantAttribute:r,expressions:o}=e,a=s?t.querySelector(s):t;r&&a.removeAttribute(r);const u=o||[];return(Ot[i]||Ot[2])(a,{...e,expressions:n&&!s?Mt(u,n):u})}(this.el,t,l)),this.bindings.forEach(t=>t.mount(e,n)),this.meta=s,this},update(t,e){return this.bindings.forEach(n=>n.update(t,e)),this},unmount(t,e,n=!1){const s=this.el;if(!s)return this;switch(this.bindings.forEach(s=>s.unmount(t,e,n)),!0){case s[y]||null===n:break;case Array.isArray(this.children):!function(t){for(let e=0;et[e]=n;function Dt(t){return[i,r,o].reduce((e,n)=>(e[n]=t(n),e),{})}function kt(t){return Array.isArray(t)?t:/^\[object (HTMLCollection|NodeList|Object)\]$/.test(Object.prototype.toString.call(t))&&"number"==typeof t.length?Array.from(t):[t]}function It(t,e){return kt("string"==typeof t?(e||document).querySelectorAll(t):t)}const Bt=Object.freeze({$(t){return It(t,this.root)[0]},$$(t){return It(t,this.root)}}),Ut=Object.freeze({[a]:R,[u]:R,[l]:R,[c]:R,[d]:R,[h]:R,[p]:R}),Lt=t=>1===t.length?t[0]:t;function $t(t,e,n){const s="object"==typeof e?e:{[e]:n},i=Object.keys(s);return kt(t).forEach(t=>{i.forEach(e=>t.setAttribute(e,s[e]))}),t}function Rt(t,e){return function(t,e,n){const s="string"==typeof e?[e]:e;return Lt(kt(t).map(t=>Lt(s.map(e=>t[n](e)))))}(t,e,"getAttribute")}const Ft=new Map,Pt=()=>zt||($t(zt=It("style[riot]")[0]||document.createElement("style"),"type","text/css"),zt.parentNode||document.head.appendChild(zt),zt);var zt;const Vt={CSS_BY_NAME:Ft,add(t,e){return Ft.has(t)||(Ft.set(t,e),this.inject()),this},inject(){return Pt().innerHTML=[...Ft.values()].join("\n"),this},remove(t){return Ft.has(t)&&(Ft.delete(t),this.inject()),this}};function Ht(t,...e){return(...n)=>(n=[...e,...n]).length{const e=t?.bindingsData?.[0];return e?.selector?[]:e?.expressions?.reduce((t,{name:e,type:n})=>n===w.ATTRIBUTE?t.concat([e]):t,[])??[]});function Wt(t,{slots:e,attributes:i,props:r}){return o=function(t){return[...n].reduce((t,e)=>e(t)||t,t)}(tt(L(t)?Object.create(t):t,{mount(n,o={},a){return Q(n,y,!1),this[g]=a,this[N]=function(t,e=[]){const n=e.map(e=>yt(t,e)),s={};return Object.assign(s,{expressions:n,...Dt(t=>e=>(n.forEach(n=>n[t](e)),s))})}(n,i).mount(a),Q(this,m,Object.freeze({...qt(n,r),...D(this[N].expressions)})),this[f]=Xt(this[f],o),this[T]=this.template.createDOM(n).clone(),Ct(n,this),t.name&&function(t,e){Kt(t)!==e&&$t(t,s,e)}(n,t.name),Q(this,v,n),Q(this,b,e),this[u](this[m],this[f]),this[T].mount(n,this,a),this[l](this[m],this[f]),this},update(t={},e){e&&(this[g]=e,this[N].update(e));const n=Gt(this[T]),i=P({attributes:Array.from(this[v].attributes).filter(({name:t})=>!n.includes(t))}),{[s]:r,...o}={...i,...D(this[N].expressions)};var u,l;if(!1!==this[a](o,this[m]))return Q(this,m,Object.freeze({...e?(u=this[m],l=n,L(u)?Object.fromEntries(l.map(t=>[t,u[t]])):u):this[m],...o})),this[f]=Xt(this[f],t),this[c](this[m],this[f]),this[x]||(this[x]=!0,this[T].update(this,this[g])),this[d](this[m],this[f]),this[x]=!1,this},unmount(t){return this[h](this[m],this[f]),this[N].unmount(),this[T].unmount(this,this[g],null===t?null:!t),this[p](this[m],this[f]),this}})),Object.keys(t).filter(e=>U(t[e])).forEach(t=>{o[t]=o[t].bind(o)}),o;var o}function Yt({css:t,template:e,componentAPI:n,name:s}){return t&&s&&Vt.add(s,t),Ht(Wt)(tt(et(n,{...Ut,[m]:{},[f]:{}}),{[b]:null,[v]:null,...Bt,name:s,css:t,template:e}))}const Zt=e=>{const n=function(t={}){return Object.entries(F(t)).reduce((t,[e,n])=>{var s;return t[(s=e,s.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase())]=Qt(n),t},{})}(e.exports?e.exports.components:{});return s=>s===e.name?Jt(e):n[s]||t.get(s)},Jt=C(Qt);function Qt(t){const{css:e,template:n,exports:s,name:r}=t,o=n?function(t,e,n){return t(St,w,J,n)}(n,0,Zt(t)):X;return({slots:t,attributes:a,props:u})=>{if(s&&s[y])return function(t,{slots:e,attributes:n,props:s,css:r,template:o}){o&&_("Pure components can not have html"),r&&_("Pure components do not have css");const a=et(t({slots:e,attributes:n,props:s}),_t);return Dt(t=>(...e)=>{if(t===i){const[t]=e;Q(t,y,!0),Ct(t,a)}return a[t](...e),a})}(s,{slots:t,attributes:a,props:u,css:e,template:n});const l=F(s)||{},c=Yt({css:e,template:o,componentAPI:l,name:r})({slots:t,attributes:a,props:u});return{mount:(t,e,n)=>c.mount(t,n,e),update:(t,e)=>c.update(e,t),unmount:t=>c.unmount(t)}}}const te={css:null,exports:{state:{files:[],field:void 0,disabled:!1},onMounted(){this.field=this.$(".tiny-field-upload__field")},onUpdated(t,e){const n=this.$$(".tiny-field-upload__item input");let s=0;if(n.length>0)for(const t of n){const n=new DataTransfer;n.items.add(e.files[s++]),t.files=n.files}},addSrc:t=>URL.createObjectURL(t),handleOpenFileManager(t){this.field.click()},handleRemoveFile(t,e){const n=this.state.files.indexOf(e);this.state.files.splice(n,1),this.validateMax(),this.update()},handleSelectFile(t){let e=0;for(const n of t.target.files)(!this.props.max||this.props.max&&1+e++<=this.props.max)&&this.state.files.push(n);this.validateMax(),this.update()},validateMax(){this.state.disabled=!1,this.props.max&&this.state.files.length>=this.props.max&&(this.state.disabled=!0)}},template:(t,e,n,s)=>t('
',[{redundantAttribute:"expr0",selector:"[expr0]",expressions:[{type:e.ATTRIBUTE,isBoolean:!0,name:"multiple",evaluate:t=>void 0!==t.props.multiple},{type:e.EVENT,name:"onchange",evaluate:t=>e=>{t.handleSelectFile(e)}}]},{redundantAttribute:"expr1",selector:"[expr1]",expressions:[{type:e.TEXT,childNodeIndex:1,evaluate:t=>[t.props.label].join("")},{type:e.EVENT,name:"onclick",evaluate:t=>e=>{t.handleOpenFileManager(e)}},{type:e.ATTRIBUTE,isBoolean:!0,name:"disabled",evaluate:t=>t.state.disabled}]},{type:n.EACH,getKey:null,condition:null,template:t('
',[{redundantAttribute:"expr3",selector:"[expr3]",expressions:[{type:e.TEXT,childNodeIndex:0,evaluate:t=>t.file.name}]},{redundantAttribute:"expr4",selector:"[expr4]",expressions:[{type:e.EVENT,name:"onclick",evaluate:t=>e=>{t.handleRemoveFile(e,t.file)}}]},{redundantAttribute:"expr5",selector:"[expr5]",expressions:[{type:e.ATTRIBUTE,isBoolean:!1,name:"name",evaluate:t=>[t.props.name,"[]"].join("")}]},{redundantAttribute:"expr6",selector:"[expr6]",expressions:[{type:e.ATTRIBUTE,isBoolean:!1,name:"src",evaluate:t=>t.addSrc(t.file)}]}]),redundantAttribute:"expr2",selector:"[expr2]",itemName:"file",indexName:null,evaluate:t=>t.state.files}]),name:"tiny-field-upload"};var ee,ne;!function(e,{css:n,template:s,exports:i}){t.has(e)&&_(`The component "${e}" was already registered`),t.set(e,Qt({name:e,css:n,template:s,exports:i}))}("tiny-field-upload",te),It("tiny-field-upload").map(e=>function(e,n,s,i){const r=s||Kt(e);return t.has(r)||_(`The component named "${r}" was never registered`),t.get(r)({props:n,slots:i}).mount(e)}(e,ee,ne))})(); \ No newline at end of file diff --git a/example/js/spritemap.js b/example/js/spritemap.js new file mode 100644 index 0000000..cf16298 --- /dev/null +++ b/example/js/spritemap.js @@ -0,0 +1 @@ +(self.webpackChunk_tiny_components_upload=self.webpackChunk_tiny_components_upload||[]).push([[654],{874:()=>{}}]); \ No newline at end of file diff --git a/example/symbol-defs.svg b/example/symbol-defs.svg new file mode 100644 index 0000000..250cd5e --- /dev/null +++ b/example/symbol-defs.svg @@ -0,0 +1 @@ +addarchivearrow-downarrow-left-downarrow-left-uparrow-leftarrow-right-downarrow-right-uparrow-rightarrow-upattachmentbackspacebanbar-chart-altbar-chartboardboldbookbookmarkcalendarcallcameracaret-downcaret-leftcaret-rightcaret-upcheckcheckbox-checkedcheckboxchevron-double-downchevron-double-leftchevron-double-rightchevron-double-upchevron-downchevron-leftchevron-rightchevron-upcircle-addcircle-arrow-downcircle-arrow-leftcircle-arrow-rightcircle-arrow-upcircle-checkcircle-errorcircle-helpcircle-informationcircle-removecircle-warningcircleclipboard-checkclipboard-listclipboardclockclosecloud-downloadcloud-uploadcloudcloudycommentcompasscomputercopycredit-carddatabasedelete-altdeletedocument-adddocument-checkdocument-downloaddocument-emptydocument-removedocumentdownloaddragdropedit-alteditemailenterexpandexportexternal-linkeye-offeyefavoritefilter-1filter-altfilterflagfogfolder-addfolder-checkfolder-downloadfolder-removefoldergridhearthomeimageinboxitaliclaptoplayerslayoutlink-altlinklistlocationlocklog-inlog-outmapmegaphonemenumessage-altmessageminimizemobilemoonnextnotification-offnotificationoptions-horizontaloptions-verticalpausepenpercentagepinplaypreviousprintrainrefreshremovereorder-altreorderrepeatsavesearchselectsendsettingsshareshopping-cart-addshopping-cartshufflesnowsnowflakesortspeakersstopstormstrikethroughsunsunrise-altsunrisesunsetswitchtabletablettagtemperaturetextthree-rowstwo-columnstwo-rowsunderlineundounlockuser-adduser-checkuser-removeuserusersvolume-offvolume-upwarningwebcamwindwindowzoom-inzoom-out \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..a08ae47 --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "@tiny-components/upload", + "version": "0.1.0", + "description": "Upload Field for Riotjs", + "repository": { + "type": "git", + "url": "git@github.com:node001-net/tiny-components/upload.git" + }, + "author": "Björn Hase", + "license": "MIT", + "dependencies": { + "@tiny-components/plain-ui": "^0.6.0", + "riot": "^9.4.10" + }, + "devDependencies": { + "@riotjs/compiler": "^9.0.7", + "@riotjs/webpack-loader": "^9.0.1", + "@tiny-components/webpack": "^0.2.0" + }, + "scripts": { + "build": "webpack --mode production --config webpack.config.js", + "build-dev": "webpack --mode development --config webpack.config.js" + } +} diff --git a/src/example.js b/src/example.js new file mode 100644 index 0000000..2cbb7ac --- /dev/null +++ b/src/example.js @@ -0,0 +1,6 @@ +import * as riot from 'riot' + +import FieldUpload from './fieldUpload.riot' + +riot.register('tiny-field-upload', FieldUpload) +riot.mount('tiny-field-upload') diff --git a/src/example.scss b/src/example.scss new file mode 100644 index 0000000..e3af616 --- /dev/null +++ b/src/example.scss @@ -0,0 +1,3 @@ +@import + '../node_modules/@tiny-components/plain-ui/src/scss/plain-ui', + 'fieldUpload.scss'; diff --git a/src/fieldUpload.riot b/src/fieldUpload.riot new file mode 100644 index 0000000..776ae5f --- /dev/null +++ b/src/fieldUpload.riot @@ -0,0 +1,140 @@ + +
+ { handleSelectFile(event) } } /> + +
+
+
+
+
+
{ file.name }
+
+ +
+
+
+ + +
+
+
+
+
+ + +
diff --git a/src/fieldUpload.scss b/src/fieldUpload.scss new file mode 100644 index 0000000..6549d8c --- /dev/null +++ b/src/fieldUpload.scss @@ -0,0 +1,32 @@ +/** + * + * + */ + +.tiny-field-upload { + + // hide all file inputs + input[type="file"] { + display: none; + } + + &__files { + display: flex; + flex-wrap: wrap; + margin: 0 -0.5em 0; + } + + &__files-item { + width: calc(25% - 1em); + margin: 0 0.5em 1em; + + img.tiny-field-upload__files-media { + width: 100%; + } + + .panel__body { + line-height: 0; + } + } + +} diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..f0a841a --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,24 @@ +const tinyComponentsWebpack = require('@tiny-components/webpack') +const riotRules = require('@tiny-components/webpack/rules/riot') +const path = require('path') + +module.exports = tinyComponentsWebpack({ + index: [ + './src/example.js' + ], + styles: [ + './src/example.scss' + ], + }, { + publicPath: '/example/', + destination: path.resolve(process.cwd(), 'example'), + rules: [ riotRules ], + svg: { + src: [ + 'node_modules/@tiny-components/plain-ui/src/icons/mono-icons/svg/*.svg' + ] + }, + purge: { + src: path.join(__dirname, './**') + } + })