Skip to content

Commit 97bf5d9

Browse files
Merge pull request #44 from zeixcom/feature/type-inference
Feature/type inference
2 parents 15c8bf8 + 7e43b26 commit 97bf5d9

File tree

122 files changed

+3715
-2548
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+3715
-2548
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ bun run serve:docs
9797

9898
To maintain a high-quality codebase, please follow these guidelines:
9999

100-
* Follow the projects existing coding style.
100+
* Follow the project's existing coding style.
101101
* Avoid unnecessary dependencies.
102102
* Use functional programming principles where applicable.
103103
* Prefer composition over inheritance.

README.md

+13-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# UIElement
22

3-
Version 0.10.0
3+
Version 0.10.1
44

55
**UIElement** - transform reusable markup, styles and behavior into powerful, reactive, and maintainable Web Components.
66

@@ -158,15 +158,17 @@ class TabList extends UIElement {
158158
// Handle click events on menu buttons and update active tab index
159159
this.all('menu button')
160160
.on('click', (_el, index) => () => this.set('active', index))
161-
.sync((host, target, index) => setAttribute(
162-
'aria-pressed',
163-
() => host.get('active') === index ? 'true' : 'false')(host, target)
164-
)
161+
.sync((host, target, index) => {
162+
setAttribute(
163+
'aria-pressed',
164+
() => host.get('active') === index ? 'true' : 'false'
165+
)(host, target)
166+
})
165167

166168
// Pass open attribute to tab-panel elements based on active tab index
167-
this.all('tab-panel').pass({
168-
open: (_el, index) => () => index === this.get('active')
169-
})
169+
this.all('tab-panel').pass((_el, index) => ({
170+
open: () => index === this.get('active')
171+
}))
170172
}
171173
}
172174
TabList.define('tab-list')
@@ -218,7 +220,7 @@ import { UIElement, setText, setProperty, effect, enqueue } from '@zeix/ui-eleme
218220

219221
class LazyLoad extends UIElement {
220222
static observedAttributes = ['src']
221-
static states = {
223+
states = {
222224
src: v => {
223225
let url = ''
224226
try {
@@ -238,12 +240,12 @@ class LazyLoad extends UIElement {
238240

239241
// Show / hide loading message
240242
this.first('.loading')
241-
.sync(setProperty('ariaHidden', () => !!this.get('error')))
243+
.sync(setProperty('hidden', () => !!this.get('error')))
242244

243245
// Set and show / hide error message
244246
this.first('.error')
245247
.sync(setText('error'))
246-
.sync(setProperty('ariaHidden', () => !this.get('error')))
248+
.sync(setProperty('hidden', () => !this.get('error')))
247249

248250
// Load content from provided URL
249251
effect(async () => {

bun.lockb

1009 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
1-
import { asBoolean, setProperty, toggleAttribute, UIElement } from "@zeix/ui-element"
1+
import { asBoolean, setProperty, toggleAttribute, UIElement } from "../../../"
22

3-
export class AccordionPanel extends UIElement {
4-
static states = {
5-
open: asBoolean,
6-
collapsible: asBoolean
7-
}
3+
export class AccordionPanel extends UIElement<{
4+
open: boolean,
5+
collapsible: boolean,
6+
}> {
7+
static readonly localName = 'accordion-panel'
8+
static observedAttributes = ['open', 'collapsible']
9+
10+
states = {
11+
open: asBoolean,
12+
collapsible: asBoolean
13+
}
814

915
connectedCallback() {
1016
super.connectedCallback()
11-
17+
1218
// Handle open and collapsible state changes
1319
this.self.sync(
1420
toggleAttribute('open'),
1521
toggleAttribute('collapsible'),
16-
setProperty('ariaHidden', () => !this.get('open') && !this.get('collapsible'))
22+
setProperty('hidden', () => !this.get('open') && !this.get('collapsible'))
1723
)
1824

1925
// Control inner details panel
20-
this.first('details').sync(
26+
this.first<HTMLDetailsElement>('details').sync(
2127
setProperty('open'),
22-
setProperty('ariaDisabled', () => !this.get('collapsible'))
28+
setProperty('ariaDisabled', () => String(!this.get('collapsible')))
2329
)
2430
}
2531
}
26-
AccordionPanel.define('accordion-panel')
32+
AccordionPanel.define()

docs-src/components/badge-button/badge-button.css

-44
This file was deleted.

docs-src/components/badge-button/badge-button.html

-6
This file was deleted.

docs-src/components/badge-button/badge-button.ts

-8
This file was deleted.

docs-src/components/code-block/code-block.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010
</p>
1111
<pre><code class="language-html"></code></pre>
1212
<input-button class="copy">
13-
<button type="button" class="secondary small">Copy</button>
13+
<button type="button" class="secondary small">
14+
<span class="label">Copy</span>
15+
</button>
1416
</input-button>
1517
<button type="button" class="overlay">Expand</button>
1618
</code-block></code></pre>
1719
<input-button class="copy">
18-
<button type="button" class="secondary small">Copy</button>
20+
<button type="button" class="secondary small">
21+
<span class="label">Copy</span>
22+
</button>
1923
</input-button>
2024
<button type="button" class="overlay">Expand</button>
2125
</code-block>

docs-src/components/code-block/code-block.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
import { asBoolean, toggleAttribute, UIElement } from "@zeix/ui-element"
1+
import { asBoolean, toggleAttribute, UIElement } from '../../../'
22
// import Prism from 'prismjs'
33
// import 'prismjs/components/prism-bash';
44
// import 'prismjs/components/prism-json';
55
// import 'prismjs/components/prism-typescript';
66

77
import type { InputButton } from '../input-button/input-button'
88

9-
export class CodeBlock extends UIElement {
9+
export class CodeBlock extends UIElement<{ collapsed: boolean }> {
10+
static readonly localName = 'code-block'
1011
static observedAttributes = ['collapsed']
11-
static states = {
12+
13+
states = {
1214
collapsed: asBoolean
1315
}
1416

@@ -39,7 +41,7 @@ export class CodeBlock extends UIElement {
3941
// Copy to clipboard
4042
this.first('.copy').on('click', async (e: Event) => {
4143
const copyButton = e.currentTarget as InputButton
42-
const label = copyButton.textContent
44+
const label = copyButton.textContent ?? ''
4345
let status = 'success'
4446
try {
4547
await navigator.clipboard.writeText(content.textContent ?? '')
@@ -48,7 +50,7 @@ export class CodeBlock extends UIElement {
4850
status = 'error'
4951
}
5052
copyButton.set('disabled', true)
51-
copyButton.set('label', this.getAttribute(`copy-${status}`))
53+
copyButton.set('label', this.getAttribute(`copy-${status}`) ?? label)
5254
setTimeout(() => {
5355
copyButton.set('disabled', false)
5456
copyButton.set('label', label)
@@ -61,4 +63,4 @@ export class CodeBlock extends UIElement {
6163
}
6264
}
6365
}
64-
CodeBlock.define('code-block')
66+
CodeBlock.define()
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { setText, UIElement } from "@zeix/ui-element"
1+
import { setText, UIElement, RESET } from "../../../"
2+
3+
export class HelloWorld extends UIElement<{ name?: string }> {
4+
static localName = 'hello-world'
25

3-
export class HelloWorld extends UIElement {
46
connectedCallback() {
5-
this.first('span').sync(setText('name'))
7+
this.first('span').sync(setText('name'))
68
this.first('input').on('input', (e: Event) => {
7-
this.set('name', (e.target as HTMLInputElement)?.value || undefined)
9+
this.set('name', (e.target as HTMLInputElement)?.value || RESET)
810
})
911
}
1012
}
11-
HelloWorld.define('hello-world')
13+
HelloWorld.define()

docs-src/components/input-button/input-button.css

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
input-button {
2+
position: relative;
23
display: inline-block;
34
flex: 0;
45

@@ -37,9 +38,9 @@ input-button {
3738
color: var(--color-text-inverted);
3839
background-color: var(--color-primary);
3940
border-color: var(--color-primary-active);
40-
opacity: var(--opacity-solid);
41-
41+
4242
&:not(:disabled) {
43+
opacity: var(--opacity-solid);
4344

4445
&:hover {
4546
background-color: var(--color-primary-hover);
@@ -55,9 +56,9 @@ input-button {
5556
color: var(--color-text-inverted);
5657
background-color: var(--color-error);
5758
border-color: var(--color-error-active);
58-
opacity: var(--opacity-solid);
59-
59+
6060
&:not(:disabled) {
61+
opacity: var(--opacity-solid);
6162

6263
&:hover {
6364
background-color: var(--color-error-hover);
@@ -73,9 +74,9 @@ input-button {
7374
color: var(--color-text-inverted);
7475
background-color: var(--color-success);
7576
border-color: var(--color-success-active);
76-
opacity: var(--opacity-solid);
77-
77+
7878
&:not(:disabled) {
79+
opacity: var(--opacity-solid);
7980

8081
&:hover {
8182
background-color: var(--color-success-hover);
@@ -99,4 +100,23 @@ input-button {
99100
padding-inline: var(--space-m);
100101
}
101102
}
103+
104+
.badge {
105+
position: absolute;
106+
box-sizing: border-box;
107+
top: calc(-1* var(--space-s));
108+
right: calc(-1* var(--space-s));
109+
font-size: var(--font-size-xs);
110+
line-height: var(--line-height-xs);
111+
background-color: var(--color-primary);
112+
color: var(--color-white);
113+
padding: var(--space-xxs) var(--space-xs);
114+
height: calc(2* var(--space-s));
115+
min-width: calc(2* var(--space-s));
116+
border-radius: var(--space-s);
117+
118+
&:empty {
119+
display: none;
120+
}
121+
}
102122
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<input-button>
2-
<button type="button">Button</button>
2+
<button type="button">
3+
<span class="label">🛒 Shopping Cart</span>
4+
<span class="badge">5</span>
5+
</button>
36
</input-button>
47

5-
<input-button>
8+
<input-button disabled>
69
<button type="submit" class="primary" disabled>Submit</button>
710
</input-button>
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1-
import { asBoolean, setProperty, setText, UIElement } from "@zeix/ui-element"
1+
import { asBoolean, setProperty, setText, UIElement } from "../../../"
22

3-
export class InputButton extends UIElement {
3+
export class InputButton extends UIElement<{
4+
disabled: boolean,
5+
label?: string,
6+
badge?: string,
7+
}> {
8+
static localName = 'input-button'
49
static observedAttributes = ['disabled']
5-
static states = {
6-
disabled: asBoolean
7-
}
10+
11+
states = {
12+
disabled: asBoolean,
13+
}
814

915
connectedCallback() {
10-
this.first('button').sync(
11-
setText('label'),
12-
setProperty('disabled')
13-
)
14-
}
16+
super.connectedCallback()
17+
18+
this.first<HTMLButtonElement>('button').sync(setProperty('disabled'))
19+
this.first('.label').sync(setText('label'))
20+
this.first('.badge').sync(setText('badge'))
21+
}
1522
}
16-
InputButton.define('input-button')
23+
InputButton.define()

docs-src/components/input-checkbox/input-checkbox.css

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
input-checkbox {
22
flex-grow: 1;
3+
border-radius: var(--space-xs);
4+
5+
&:focus-within {
6+
box-shadow: 0 0 var(--space-xxs) 2px var(--color-selection);
7+
}
8+
9+
& input:focus {
10+
outline: none;
11+
box-shadow: none;
12+
}
313

414
& label {
515
font-size: var(--font-size-s);

0 commit comments

Comments
 (0)