rettangoli-ui 0.1.0-rc1 → 0.1.0-rc3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -27
- package/dist/rettangoli-iife-layout.min.js +360 -284
- package/dist/rettangoli-iife-ui.min.js +382 -548
- package/package.json +13 -5
- package/src/common/BaseElement.js +182 -0
- package/src/common.js +190 -0
- package/src/components/dialog/dialog.handlers.js +5 -0
- package/src/components/dialog/dialog.store.js +24 -0
- package/src/components/dialog/dialog.view.yaml +40 -0
- package/src/components/form/form.handlers.js +30 -0
- package/src/components/form/form.store.js +45 -0
- package/src/components/form/form.view.yaml +47 -0
- package/src/components/navbar/navbar.examples.yaml +86 -0
- package/src/components/navbar/navbar.handlers.js +10 -0
- package/src/components/navbar/navbar.store.js +46 -0
- package/src/components/navbar/navbar.view.yaml +74 -0
- package/src/components/pageOutline/pageOutline.handlers.js +69 -0
- package/src/components/pageOutline/pageOutline.store.js +40 -0
- package/src/components/pageOutline/pageOutline.view.yaml +34 -0
- package/src/components/popover/popover.handlers.js +17 -0
- package/src/components/popover/popover.store.js +37 -0
- package/src/components/popover/popover.view.yaml +50 -0
- package/src/components/select/select.handlers.js +15 -0
- package/src/components/select/select.store.js +25 -0
- package/src/components/select/select.view.yaml +38 -0
- package/src/components/sidebar/sidebar.handlers.js +36 -0
- package/src/components/sidebar/sidebar.store.js +125 -0
- package/src/components/sidebar/sidebar.view.yaml +186 -0
- package/src/entry-iife-layout.js +15 -0
- package/src/entry-iife-ui.js +18 -0
- package/src/index.js +17 -0
- package/src/lib/uhtml.js +9 -0
- package/src/primitives/button.js +263 -0
- package/src/primitives/image.js +234 -0
- package/src/primitives/input.js +208 -0
- package/src/primitives/svg.js +95 -0
- package/src/primitives/text.js +141 -0
- package/src/primitives/textarea.js +103 -0
- package/src/primitives/view.js +215 -0
- package/src/setup.js +16 -0
- package/src/styles/anchorStyles.js +13 -0
- package/src/styles/buttonMarginStyles.js +84 -0
- package/src/styles/cursorStyles.js +12 -0
- package/src/styles/flexChildStyles.js +43 -0
- package/src/styles/flexDirectionStyles.js +74 -0
- package/src/styles/marginStyles.js +13 -0
- package/src/styles/paddingSvgStyles.js +120 -0
- package/src/styles/scrollStyles.js +22 -0
- package/src/styles/textColorStyles.js +14 -0
- package/src/styles/textStyles.js +62 -0
- package/src/styles/viewStyles.js +119 -0
@@ -0,0 +1,186 @@
|
|
1
|
+
elementName: rtgl-sidebar
|
2
|
+
|
3
|
+
viewDataSchema:
|
4
|
+
type: object
|
5
|
+
properties:
|
6
|
+
containerAttrString:
|
7
|
+
type: string
|
8
|
+
mode:
|
9
|
+
type: string
|
10
|
+
enum: ['full', 'shrunk', 'shrunk-lg']
|
11
|
+
default: 'full'
|
12
|
+
sidebarWidth:
|
13
|
+
type: number
|
14
|
+
headerAlign:
|
15
|
+
type: string
|
16
|
+
itemAlign:
|
17
|
+
type: string
|
18
|
+
headerPadding:
|
19
|
+
type: string
|
20
|
+
itemPadding:
|
21
|
+
type: string
|
22
|
+
itemHeight:
|
23
|
+
type: number
|
24
|
+
iconSize:
|
25
|
+
type: number
|
26
|
+
firstLetterSize:
|
27
|
+
type: string
|
28
|
+
showLabels:
|
29
|
+
type: boolean
|
30
|
+
showGroupLabels:
|
31
|
+
type: boolean
|
32
|
+
itemContentAlign:
|
33
|
+
type: string
|
34
|
+
itemAlignAttr:
|
35
|
+
type: string
|
36
|
+
itemWidth:
|
37
|
+
type: string
|
38
|
+
headerWidth:
|
39
|
+
type: string
|
40
|
+
header:
|
41
|
+
type: object
|
42
|
+
properties:
|
43
|
+
label:
|
44
|
+
type: string
|
45
|
+
href:
|
46
|
+
type: string
|
47
|
+
image:
|
48
|
+
type: object
|
49
|
+
properties:
|
50
|
+
src:
|
51
|
+
type: string
|
52
|
+
width:
|
53
|
+
type: number
|
54
|
+
height:
|
55
|
+
type: number
|
56
|
+
alt:
|
57
|
+
type: string
|
58
|
+
items:
|
59
|
+
type: array
|
60
|
+
items:
|
61
|
+
type: object
|
62
|
+
properties:
|
63
|
+
title:
|
64
|
+
type: string
|
65
|
+
slug:
|
66
|
+
type: string
|
67
|
+
type:
|
68
|
+
type: string
|
69
|
+
active:
|
70
|
+
type: boolean
|
71
|
+
icon:
|
72
|
+
type: string
|
73
|
+
|
74
|
+
propsSchema:
|
75
|
+
type: object
|
76
|
+
properties:
|
77
|
+
header:
|
78
|
+
type: object
|
79
|
+
properties:
|
80
|
+
label:
|
81
|
+
type: string
|
82
|
+
href:
|
83
|
+
type: string
|
84
|
+
image:
|
85
|
+
type: object
|
86
|
+
properties:
|
87
|
+
src:
|
88
|
+
type: string
|
89
|
+
width:
|
90
|
+
type: number
|
91
|
+
height:
|
92
|
+
type: number
|
93
|
+
alt:
|
94
|
+
type: string
|
95
|
+
items:
|
96
|
+
type: array
|
97
|
+
items:
|
98
|
+
type: object
|
99
|
+
properties:
|
100
|
+
title:
|
101
|
+
type: string
|
102
|
+
slug:
|
103
|
+
type: string
|
104
|
+
type:
|
105
|
+
type: string
|
106
|
+
items:
|
107
|
+
type: array
|
108
|
+
|
109
|
+
refs:
|
110
|
+
header-image:
|
111
|
+
eventListeners:
|
112
|
+
click:
|
113
|
+
handler: handleHeaderClick
|
114
|
+
header-label:
|
115
|
+
eventListeners:
|
116
|
+
click:
|
117
|
+
handler: handleHeaderClick
|
118
|
+
header:
|
119
|
+
eventListeners:
|
120
|
+
click:
|
121
|
+
handler: handleHeaderClick
|
122
|
+
item-*:
|
123
|
+
eventListeners:
|
124
|
+
click:
|
125
|
+
handler: handleItemClick
|
126
|
+
|
127
|
+
events:
|
128
|
+
headerClick:
|
129
|
+
type: object
|
130
|
+
properties:
|
131
|
+
path:
|
132
|
+
type: string
|
133
|
+
|
134
|
+
anchors:
|
135
|
+
- &headerContent
|
136
|
+
- $if header.image && header.image.src:
|
137
|
+
- $if header.image.href:
|
138
|
+
- a href=${header.image.href}:
|
139
|
+
- rtgl-image w=${header.image.width} h=${header.image.height} src=${header.image.src} alt="${header.image.alt}":
|
140
|
+
$elif header.image.path:
|
141
|
+
- rtgl-view#header-image cur=p:
|
142
|
+
- rtgl-image w=${header.image.width} h=${header.image.height} src=${header.image.src} alt="${header.image.alt}":
|
143
|
+
$else:
|
144
|
+
- rtgl-image w=${header.image.width} h=${header.image.height} src=${header.image.src} alt="${header.image.alt}":
|
145
|
+
- $if header.label && showLabels:
|
146
|
+
- $if header.labelHref:
|
147
|
+
- rtgl-text href=${header.labelHref} s=lg: "${header.label}"
|
148
|
+
$elif header.labelPath:
|
149
|
+
- rtgl-view#header-label cur=p:
|
150
|
+
- rtgl-text s=lg: "${header.label}"
|
151
|
+
$else:
|
152
|
+
- rtgl-text s=lg: "${header.label}"
|
153
|
+
|
154
|
+
template:
|
155
|
+
- rtgl-view h=f w=${sidebarWidth} bwr=xs ${containerAttrString}:
|
156
|
+
- rtgl-view ph=${headerPadding} pv=lg:
|
157
|
+
- $if header.href:
|
158
|
+
- rtgl-view href=${header.href} d=h av=c ah=${headerAlign} g=lg w=${headerWidth}:
|
159
|
+
- *headerContent
|
160
|
+
$else:
|
161
|
+
- rtgl-view#header d=h av=c ah=${headerAlign} g=lg w=${headerWidth} cur=p:
|
162
|
+
- *headerContent
|
163
|
+
|
164
|
+
- rtgl-view w=f ph=${headerPadding} pb=lg g=xs:
|
165
|
+
- $for item, i in items:
|
166
|
+
- $if item.type == "groupLabel":
|
167
|
+
- $if showGroupLabels:
|
168
|
+
- rtgl-view mt=md h=32 av=c ph=md:
|
169
|
+
- rtgl-text s=xs c=mu-fg: "${item.title}"
|
170
|
+
$else:
|
171
|
+
- rtgl-view mt=md h=1 bgc=mu-bg:
|
172
|
+
$else:
|
173
|
+
- rtgl-view#item-${item.id} ${item.hrefAttr} h=${itemHeight} av=c ${itemAlignAttr} ph=${itemPadding} w=${itemWidth} h-bgc=mu br=lg bgc=bg cur=p title="${item.title}":
|
174
|
+
- $if item.icon:
|
175
|
+
- $if showLabels:
|
176
|
+
- rtgl-view d=h ah=${itemContentAlign} g=sm:
|
177
|
+
- rtgl-svg wh=16 svg=${item.icon} c=fg:
|
178
|
+
- rtgl-text s=sm: "${item.title}"
|
179
|
+
$else:
|
180
|
+
- rtgl-svg wh=${iconSize} svg=${item.icon} c=fg:
|
181
|
+
$else:
|
182
|
+
- $if showLabels:
|
183
|
+
- rtgl-text s=sm: "${item.title}"
|
184
|
+
$else:
|
185
|
+
- rtgl-view wh=${iconSize} br=f bgc=mu av=c ah=c:
|
186
|
+
- rtgl-text s=${firstLetterSize} c=fg: "${item.title.charAt(0).toUpperCase()}"
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import RettangoliButton from './primitives/button.js'
|
2
|
+
import RettangoliView from './primitives/view.js';
|
3
|
+
import RettangoliText from './primitives/text.js';
|
4
|
+
import RettangoliImage from './primitives/image.js';
|
5
|
+
import RettangoliSvg from './primitives/svg.js';
|
6
|
+
import RettangoliInput from './primitives/input.js';
|
7
|
+
import RettangoliTextArea from './primitives/textarea.js';
|
8
|
+
|
9
|
+
customElements.define("rtgl-button", RettangoliButton({}));
|
10
|
+
customElements.define("rtgl-view", RettangoliView({}));
|
11
|
+
customElements.define("rtgl-text", RettangoliText({}));
|
12
|
+
customElements.define("rtgl-image", RettangoliImage({}));
|
13
|
+
customElements.define("rtgl-svg", RettangoliSvg({}));
|
14
|
+
customElements.define("rtgl-input", RettangoliInput({}));
|
15
|
+
customElements.define("rtgl-textarea", RettangoliTextArea({}));
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import RettangoliButton from './primitives/button.js'
|
2
|
+
import RettangoliView from './primitives/view.js';
|
3
|
+
import RettangoliText from './primitives/text.js';
|
4
|
+
import RettangoliImage from './primitives/image.js';
|
5
|
+
import RettangoliSvg from './primitives/svg.js';
|
6
|
+
import RettangoliInput from './primitives/input.js';
|
7
|
+
import RettangoliTextArea from './primitives/textarea.js';
|
8
|
+
|
9
|
+
customElements.define("rtgl-button", RettangoliButton({}));
|
10
|
+
customElements.define("rtgl-view", RettangoliView({}));
|
11
|
+
customElements.define("rtgl-text", RettangoliText({}));
|
12
|
+
customElements.define("rtgl-image", RettangoliImage({}));
|
13
|
+
customElements.define("rtgl-svg", RettangoliSvg({}));
|
14
|
+
customElements.define("rtgl-input", RettangoliInput({}));
|
15
|
+
customElements.define("rtgl-textarea", RettangoliTextArea({}));
|
16
|
+
|
17
|
+
// built from rettangoli cli fe
|
18
|
+
import '../.temp/dynamicImport.js'
|
package/src/index.js
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
import RettangoliButton from './primitives/button.js'
|
2
|
+
import RettangoliView from './primitives/view.js';
|
3
|
+
import RettangoliText from './primitives/text.js';
|
4
|
+
import RettangoliImage from './primitives/image.js';
|
5
|
+
import RettangoliSvg from './primitives/svg.js';
|
6
|
+
import RettangoliInput from './primitives/input.js';
|
7
|
+
import RettangoliTextArea from './primitives/textarea.js';
|
8
|
+
|
9
|
+
export {
|
10
|
+
RettangoliButton,
|
11
|
+
RettangoliView,
|
12
|
+
RettangoliText,
|
13
|
+
RettangoliImage,
|
14
|
+
RettangoliSvg,
|
15
|
+
RettangoliInput,
|
16
|
+
RettangoliTextArea,
|
17
|
+
}
|
package/src/lib/uhtml.js
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* Skipped minification because the original files appears to be already minified.
|
3
|
+
* Original file: /npm/uhtml@4.7.0/keyed.js
|
4
|
+
*
|
5
|
+
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
|
6
|
+
*/
|
7
|
+
const{isArray:e}=Array,{getPrototypeOf:t,getOwnPropertyDescriptor:n}=Object,r=[],s=()=>document.createRange(),l=(e,t,n)=>(e.set(t,n),n),i=(e,t)=>t.reduceRight(o,e),o=(e,t)=>e.childNodes[t],{setPrototypeOf:c}=Object;let a;var u=(e,t,n)=>(a||(a=s()),n?a.setStartAfter(e):a.setStartBefore(e),a.setEndAfter(t),a.deleteContents(),e);const h=({firstChild:e,lastChild:t},n)=>u(e,t,n);let d=!1;const f=(e,t)=>d&&11===e.nodeType?1/t<0?t?h(e,!0):e.lastChild:t?e.valueOf():e.firstChild:e,p=e=>document.createComment(e);class g extends((e=>{function t(e){return c(e,new.target.prototype)}return t.prototype=e.prototype,t})(DocumentFragment)){#e=p("<>");#t=p("</>");#n=r;constructor(e){super(e),this.replaceChildren(this.#e,...e.childNodes,this.#t),d=!0}get firstChild(){return this.#e}get lastChild(){return this.#t}get parentNode(){return this.#e.parentNode}remove(){h(this,!1)}replaceWith(e){h(this,!0).replaceWith(e)}valueOf(){const{parentNode:e}=this;if(e===this)this.#n===r&&(this.#n=[...this.childNodes]);else{if(e){let{firstChild:e,lastChild:t}=this;for(this.#n=[e];e!==t;)this.#n.push(e=e.nextSibling)}this.replaceChildren(...this.#n)}return this}}const m=(e,t,n)=>e.setAttribute(t,n),b=(e,t)=>e.removeAttribute(t);let v;const C=(t,n,r)=>{r=r.slice(1),v||(v=new WeakMap);const s=v.get(t)||l(v,t,{});let i=s[r];return i&&i[0]&&t.removeEventListener(r,...i),i=e(n)?n:[n,!1],s[r]=i,i[0]&&t.addEventListener(r,...i),n},w=(e,t)=>{const{t:n,n:r}=e;let s=!1;switch(typeof t){case"object":if(null!==t){(r||n).replaceWith(e.n=t.valueOf());break}case"undefined":s=!0;default:n.data=s?"":t,r&&(e.n=null,r.replaceWith(n))}return t},x=(e,t,n)=>e[n]=t,$=(e,t,n)=>x(e,t,n.slice(1)),y=(e,t,n)=>null==t?(b(e,n),t):x(e,t,n),N=(e,t)=>("function"==typeof t?t(e):t.current=e,t),O=(e,t,n)=>(null==t?b(e,n):m(e,n,t),t),k=(e,t,n)=>(e.toggleAttribute(n.slice(1),t),t),A=(e,t,n)=>{const{length:s}=t;if(e.data=`[${s}]`,s)return((e,t,n,r,s)=>{const l=n.length;let i=t.length,o=l,c=0,a=0,u=null;for(;c<i||a<o;)if(i===c){const t=o<l?a?r(n[a-1],-0).nextSibling:r(n[o],0):s;for(;a<o;)e.insertBefore(r(n[a++],1),t)}else if(o===a)for(;c<i;)u&&u.has(t[c])||e.removeChild(r(t[c],-1)),c++;else if(t[c]===n[a])c++,a++;else if(t[i-1]===n[o-1])i--,o--;else if(t[c]===n[o-1]&&n[a]===t[i-1]){const s=r(t[--i],-0).nextSibling;e.insertBefore(r(n[a++],1),r(t[c++],-0).nextSibling),e.insertBefore(r(n[--o],1),s),t[i]=n[o]}else{if(!u){u=new Map;let e=a;for(;e<o;)u.set(n[e],e++)}if(u.has(t[c])){const s=u.get(t[c]);if(a<s&&s<o){let l=c,h=1;for(;++l<i&&l<o&&u.get(t[l])===s+h;)h++;if(h>s-a){const l=r(t[c],0);for(;a<s;)e.insertBefore(r(n[a++],1),l)}else e.replaceChild(r(n[a++],1),r(t[c++],-1))}else c++}else e.removeChild(r(t[c++],-1))}return n})(e.parentNode,n,t,f,e);switch(n.length){case 1:n[0].remove();case 0:break;default:u(f(n[0],0),f(n.at(-1),-0),!1)}return r},M=new Map([["aria",(e,t)=>{for(const n in t){const r=t[n],s="role"===n?n:`aria-${n}`;null==r?b(e,s):m(e,s,r)}return t}],["class",(e,t)=>y(e,t,null==t?"class":"className")],["data",(e,t)=>{const{dataset:n}=e;for(const e in t)null==t[e]?delete n[e]:n[e]=t[e];return t}],["ref",N],["style",(e,t)=>null==t?y(e,t,"style"):x(e.style,t,"cssText")]]),W=(e,r,s)=>{switch(r[0]){case".":return $;case"?":return k;case"@":return C;default:return s||"ownerSVGElement"in e?"ref"===r?N:O:M.get(r)||(r in e?r.startsWith("on")?x:((e,r)=>{let s;do{s=n(e,r)}while(!s&&(e=t(e)));return s})(e,r)?.set?y:O:O)}},S=(e,t)=>(e.textContent=null==t?"":t,t),E=(e,t,n)=>({a:e,b:t,c:n}),T=()=>E(null,null,r);var B=e=>(t,n)=>{const{a:s,b:l,c:o}=e(t,n),c=document.importNode(s,!0);let a=r;if(l!==r){a=[];for(let e,t,n=0;n<l.length;n++){const{a:s,b:o,c:p}=l[n],g=s===t?e:e=i(c,t=s);a[n]=(u=o,h=g,d=p,f=o===A?[]:o===w?T():null,{v:r,u:u,t:h,n:d,c:f})}}var u,h,d,f;return((e,t)=>({b:e,c:t}))(o?c.firstChild:new g(c),a)};const D=/^(?:plaintext|script|style|textarea|title|xmp)$/i,j=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i,L=/<([a-zA-Z0-9]+[a-zA-Z0-9:._-]*)([^>]*?)(\/?)>/g,P=/([^\s\\>"'=]+)\s*=\s*(['"]?)\x01/g,z=/[\x01\x02]/g;let F,R,Z=document.createElement("template");var G=(e,t)=>{if(t)return F||(F=document.createElementNS("http://www.w3.org/2000/svg","svg"),R=s(),R.selectNodeContents(F)),R.createContextualFragment(e);Z.innerHTML=e;const{content:n}=Z;return Z=Z.cloneNode(!1),n};const H=e=>{const t=[];let n;for(;n=e.parentNode;)t.push(t.indexOf.call(n.childNodes,e)),e=n;return t},V=()=>document.createTextNode(""),_=(t,n,s)=>{const i=G(((e,t,n)=>{let r=0;return e.join("").trim().replace(L,((e,t,r,s)=>`<${t}${r.replace(P,"=$2$1").trimEnd()}${s?n||j.test(t)?" /":`></${t}`:""}>`)).replace(z,(e=>""===e?`\x3c!--${t+r++}--\x3e`:t+r++))})(t,I,s),s),{length:o}=t;let c=r;if(o>1){const t=[],r=document.createTreeWalker(i,129);let l=0,a=`${I}${l++}`;for(c=[];l<o;){const i=r.nextNode();if(8===i.nodeType){if(i.data===a){const r=e(n[l-1])?A:w;r===w&&t.push(i),c.push(E(H(i),r,null)),a=`${I}${l++}`}}else{let e;for(;i.hasAttribute(a);){e||(e=H(i));const t=i.getAttribute(a);c.push(E(e,W(i,t,s),t)),b(i,a),a=`${I}${l++}`}!s&&D.test(i.localName)&&i.textContent.trim()===`\x3c!--${a}--\x3e`&&(c.push(E(e||H(i),S,null)),a=`${I}${l++}`)}}for(l=0;l<t.length;l++)t[l].replaceWith(V())}const{childNodes:a}=i;let{length:u}=a;return u<1?(u=1,i.appendChild(V())):1===u&&1!==o&&1!==a[0].nodeType&&(u=0),l(q,t,E(i,c,1===u))},q=new WeakMap,I="isµ";var J=e=>(t,n)=>q.get(t)||_(t,n,e);const K=B(J(!1)),Q=B(J(!0)),U=(e,{s:t,t:n,v:r})=>{if(e.a!==n){const{b:s,c:l}=(t?Q:K)(n,r);e.a=n,e.b=s,e.c=l}for(let{c:t}=e,n=0;n<t.length;n++){const e=r[n],s=t[n];switch(s.u){case A:s.v=A(s.t,X(s.c,e),s.v);break;case w:const t=e instanceof Y?U(s.c||(s.c=T()),e):(s.c=null,e);t!==s.v&&(s.v=w(s,t));break;default:e!==s.v&&(s.v=s.u(s.t,e,s.n,s.v))}}return e.b},X=(e,t)=>{let n=0,{length:r}=t;for(r<e.length&&e.splice(r);n<r;n++){const r=t[n];r instanceof Y?t[n]=U(e[n]||(e[n]=T()),r):e[n]=null}return t};class Y{constructor(e,t,n){this.s=e,this.t=t,this.v=n}toDOM(e=T()){return U(e,this)}}
|
8
|
+
/*! (c) Andrea Giammarchi - MIT */const ee=e=>(t,...n)=>new Y(e,t,n),te=ee(!1),ne=ee(!0),re=new WeakMap;var se=(e,t)=>((e,t)=>{const n=re.get(e)||l(re,e,T()),{b:r}=n,s="function"==typeof t?t():t,i=s instanceof Y?s.toDOM(n):s;return r!==i&&e.replaceChildren((n.b=i).valueOf()),e})(e,t)
|
9
|
+
/*! (c) Andrea Giammarchi - MIT */;const le=new WeakMap,ie=e=>(t,n)=>{const r=le.get(t)||l(le,t,new Map);return r.get(n)||l(r,n,function(t,...n){return new Y(e,t,n).toDOM(this)}.bind(T()))},oe=ie(!1),ce=ie(!0);export{Y as Hole,M as attr,te as html,oe as htmlFor,se as render,ne as svg,ce as svgFor};
|
@@ -0,0 +1,263 @@
|
|
1
|
+
import { css, dimensionWithUnit } from "../common.js";
|
2
|
+
import flexChildStyles from "../styles/flexChildStyles.js";
|
3
|
+
import buttonMarginStyles from "../styles/buttonMarginStyles.js";
|
4
|
+
import anchorStyles from "../styles/anchorStyles.js";
|
5
|
+
|
6
|
+
// Internal implementation without uhtml
|
7
|
+
class RettangoliButtonElement extends HTMLElement {
|
8
|
+
static styleSheet = null;
|
9
|
+
|
10
|
+
static initializeStyleSheet() {
|
11
|
+
if (!RettangoliButtonElement.styleSheet) {
|
12
|
+
RettangoliButtonElement.styleSheet = new CSSStyleSheet();
|
13
|
+
RettangoliButtonElement.styleSheet.replaceSync(css`
|
14
|
+
:host {
|
15
|
+
display: contents;
|
16
|
+
}
|
17
|
+
slot {
|
18
|
+
display: contents;
|
19
|
+
}
|
20
|
+
|
21
|
+
button {
|
22
|
+
display: flex;
|
23
|
+
flex-direction: row;
|
24
|
+
align-items: center;
|
25
|
+
justify-content: center;
|
26
|
+
gap: var(--spacing-sm);
|
27
|
+
border-width: 0px;
|
28
|
+
border-style: solid;
|
29
|
+
border-color: var(--border);
|
30
|
+
padding: 0px;
|
31
|
+
height: 32px;
|
32
|
+
padding-left: 16px;
|
33
|
+
padding-right: 16px;
|
34
|
+
border-radius: 4px;
|
35
|
+
|
36
|
+
font-size: var(--sm-font-size);
|
37
|
+
font-weight: var(--sm-font-weight);
|
38
|
+
line-height: var(--sm-line-height);
|
39
|
+
letter-spacing: var(--sm-letter-spacing);
|
40
|
+
|
41
|
+
background-color: var(--primary);
|
42
|
+
color: var(--primary-foreground);
|
43
|
+
}
|
44
|
+
|
45
|
+
button:hover {
|
46
|
+
cursor: pointer;
|
47
|
+
background-color: color-mix(
|
48
|
+
in srgb,
|
49
|
+
var(--primary) 85%,
|
50
|
+
white 15%
|
51
|
+
);
|
52
|
+
}
|
53
|
+
|
54
|
+
button:disabled {
|
55
|
+
cursor: not-allowed;
|
56
|
+
}
|
57
|
+
|
58
|
+
button:active {
|
59
|
+
cursor: pointer;
|
60
|
+
background-color: color-mix(
|
61
|
+
in srgb,
|
62
|
+
var(--primary) 80%,
|
63
|
+
white 20%
|
64
|
+
);
|
65
|
+
}
|
66
|
+
|
67
|
+
:host([v="pr"]) button:hover {
|
68
|
+
background-color: color-mix(
|
69
|
+
in srgb,
|
70
|
+
var(--primary) 85%,
|
71
|
+
white 15%
|
72
|
+
);
|
73
|
+
}
|
74
|
+
|
75
|
+
:host([v="pr"]) button:active {
|
76
|
+
background-color: color-mix(
|
77
|
+
in srgb,
|
78
|
+
var(--primary) 80%,
|
79
|
+
white 20%
|
80
|
+
);
|
81
|
+
}
|
82
|
+
|
83
|
+
:host([v="se"]) button:hover {
|
84
|
+
background-color: color-mix(
|
85
|
+
in srgb,
|
86
|
+
var(--secondary) 85%,
|
87
|
+
white 15%
|
88
|
+
);
|
89
|
+
}
|
90
|
+
|
91
|
+
:host([v="se"]) button:active {
|
92
|
+
background-color: color-mix(
|
93
|
+
in srgb,
|
94
|
+
var(--secondary) 80%,
|
95
|
+
white 20%
|
96
|
+
);
|
97
|
+
}
|
98
|
+
|
99
|
+
:host([v="de"]) button:hover {
|
100
|
+
background-color: color-mix(
|
101
|
+
in srgb,
|
102
|
+
var(--destructive) 85%,
|
103
|
+
white 15%
|
104
|
+
);
|
105
|
+
}
|
106
|
+
|
107
|
+
:host([v="de"]) button:active {
|
108
|
+
background-color: color-mix(
|
109
|
+
in srgb,
|
110
|
+
var(--destructive) 80%,
|
111
|
+
white 20%
|
112
|
+
);
|
113
|
+
}
|
114
|
+
|
115
|
+
:host([v="ol"]) button:hover {
|
116
|
+
background-color: var(--accent);
|
117
|
+
}
|
118
|
+
|
119
|
+
:host([v="gh"]) button:hover {
|
120
|
+
background-color: var(--accent);
|
121
|
+
}
|
122
|
+
|
123
|
+
:host([v="lk"]) button:hover {
|
124
|
+
text-decoration: underline;
|
125
|
+
}
|
126
|
+
|
127
|
+
${anchorStyles}
|
128
|
+
|
129
|
+
a {
|
130
|
+
display: contents;
|
131
|
+
}
|
132
|
+
|
133
|
+
${buttonMarginStyles}
|
134
|
+
${flexChildStyles}
|
135
|
+
`);
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
139
|
+
constructor() {
|
140
|
+
super();
|
141
|
+
RettangoliButtonElement.initializeStyleSheet();
|
142
|
+
this.shadow = this.attachShadow({ mode: "closed" });
|
143
|
+
this.shadow.adoptedStyleSheets = [RettangoliButtonElement.styleSheet];
|
144
|
+
|
145
|
+
// Create initial DOM structure
|
146
|
+
this._containerElement = null;
|
147
|
+
this._buttonElement = document.createElement('button');
|
148
|
+
this._slotElement = document.createElement('slot');
|
149
|
+
this._iconElement = null;
|
150
|
+
|
151
|
+
this._buttonElement.appendChild(this._slotElement);
|
152
|
+
}
|
153
|
+
|
154
|
+
static get observedAttributes() {
|
155
|
+
return ["key", "href", "target", "w", "t", "icon", "disabled", "v", "s"];
|
156
|
+
}
|
157
|
+
|
158
|
+
connectedCallback() {
|
159
|
+
this._updateButton();
|
160
|
+
}
|
161
|
+
|
162
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
163
|
+
this._updateButton();
|
164
|
+
}
|
165
|
+
|
166
|
+
_updateButton() {
|
167
|
+
// Clear shadow DOM
|
168
|
+
this.shadow.innerHTML = '';
|
169
|
+
|
170
|
+
// Update icon
|
171
|
+
this._updateIcon();
|
172
|
+
|
173
|
+
// Update width styling
|
174
|
+
this._updateWidth();
|
175
|
+
|
176
|
+
// Update disabled state
|
177
|
+
const isDisabled = this.hasAttribute('disabled');
|
178
|
+
if (isDisabled) {
|
179
|
+
this._buttonElement.setAttribute('disabled', '');
|
180
|
+
} else {
|
181
|
+
this._buttonElement.removeAttribute('disabled');
|
182
|
+
}
|
183
|
+
|
184
|
+
// Handle href (link) vs button
|
185
|
+
const href = this.getAttribute("href");
|
186
|
+
if (href) {
|
187
|
+
// Create anchor wrapper
|
188
|
+
const anchorElement = document.createElement('a');
|
189
|
+
anchorElement.setAttribute('href', href);
|
190
|
+
|
191
|
+
const target = this.getAttribute("target");
|
192
|
+
if (target) {
|
193
|
+
anchorElement.setAttribute('target', target);
|
194
|
+
}
|
195
|
+
|
196
|
+
anchorElement.appendChild(this._buttonElement);
|
197
|
+
this.shadow.appendChild(anchorElement);
|
198
|
+
this._containerElement = anchorElement;
|
199
|
+
} else {
|
200
|
+
// Direct button
|
201
|
+
this.shadow.appendChild(this._buttonElement);
|
202
|
+
this._containerElement = this._buttonElement;
|
203
|
+
}
|
204
|
+
}
|
205
|
+
|
206
|
+
_updateIcon() {
|
207
|
+
// Remove existing icon if any
|
208
|
+
if (this._iconElement) {
|
209
|
+
this._iconElement.remove();
|
210
|
+
this._iconElement = null;
|
211
|
+
}
|
212
|
+
|
213
|
+
const icon = this.getAttribute("icon");
|
214
|
+
if (icon) {
|
215
|
+
const colorMap = {
|
216
|
+
pr: 'pr-fg',
|
217
|
+
se: 'ac-fg',
|
218
|
+
de: 'pr-fg',
|
219
|
+
ol: 'ac-fg',
|
220
|
+
gh: 'ac-fg',
|
221
|
+
lk: 'ac-fg'
|
222
|
+
};
|
223
|
+
const sizeMap = {
|
224
|
+
sm: 14,
|
225
|
+
md: 18,
|
226
|
+
lg: 22
|
227
|
+
};
|
228
|
+
const color = colorMap[this.getAttribute("v")] || 'pr-fg';
|
229
|
+
const size = sizeMap[this.getAttribute("t")] || 18;
|
230
|
+
|
231
|
+
this._iconElement = document.createElement('rtgl-svg');
|
232
|
+
this._iconElement.setAttribute('svg', icon);
|
233
|
+
this._iconElement.setAttribute('c', color);
|
234
|
+
this._iconElement.setAttribute('wh', size.toString());
|
235
|
+
|
236
|
+
// Insert icon before slot
|
237
|
+
this._buttonElement.insertBefore(this._iconElement, this._slotElement);
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
_updateWidth() {
|
242
|
+
const width = dimensionWithUnit(this.getAttribute("w"));
|
243
|
+
|
244
|
+
if (width === "f") {
|
245
|
+
this._buttonElement.style.width = "var(--width-stretch)";
|
246
|
+
} else if (width !== undefined && width !== null) {
|
247
|
+
this._buttonElement.style.width = width;
|
248
|
+
this._buttonElement.style.minWidth = width;
|
249
|
+
this._buttonElement.style.maxWidth = width;
|
250
|
+
} else {
|
251
|
+
this._buttonElement.style.width = "";
|
252
|
+
this._buttonElement.style.minWidth = "";
|
253
|
+
this._buttonElement.style.maxWidth = "";
|
254
|
+
}
|
255
|
+
}
|
256
|
+
}
|
257
|
+
|
258
|
+
// Export factory function to maintain API compatibility
|
259
|
+
export default ({ render, html }) => {
|
260
|
+
// Note: render and html parameters are accepted but not used
|
261
|
+
// This maintains backward compatibility with existing code
|
262
|
+
return RettangoliButtonElement;
|
263
|
+
};
|