Skip to content
This repository was archived by the owner on Feb 18, 2026. It is now read-only.

Commit fd6a54a

Browse files
committed
docs(examples): optimize source code of some components
1 parent df58db6 commit fd6a54a

File tree

219 files changed

+621
-723
lines changed

Some content is hidden

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

219 files changed

+621
-723
lines changed

docs-src/components/form-gauge/form-gauge.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ form-gauge {
9191

9292
&[disabled] {
9393
height: calc(0.8 * var(--form-gauge-size));
94+
overflow-y: hidden;
9495

9596
& button {
9697
display: none;

docs-src/components/form-gauge/form-gauge.ts

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import {
44
component,
55
computed,
66
fromDOM,
7-
fromEvents,
87
getProperty,
8+
on,
99
setAttribute,
1010
setProperty,
1111
setStyle,
1212
setText,
1313
} from '../../..'
1414

1515
export type FormGaugeProps = {
16-
readonly value: number
16+
value: number
1717
}
1818

1919
export type FormGaugeThreshold = {
@@ -24,29 +24,11 @@ export type FormGaugeThreshold = {
2424

2525
export default component(
2626
'form-gauge',
27-
{
28-
value: fromEvents<number>(
29-
'button',
30-
{
31-
click: ({ target, value }) =>
32-
value + (target.classList.contains('decrement') ? -1 : 1),
33-
keydown: ({ event, value }) => {
34-
const { key } = event as KeyboardEvent
35-
if (['ArrowUp', 'ArrowDown', '-', '+'].includes(key)) {
36-
event.stopPropagation()
37-
event.preventDefault()
38-
return (
39-
value +
40-
(key === 'ArrowDown' || key === '-' ? -1 : 1)
41-
)
42-
}
43-
},
44-
},
45-
fromDOM({ progress: getProperty('value') }, asInteger()),
46-
),
47-
},
48-
(el, { first }) => {
49-
const max = el.querySelector('progress')?.max ?? 100
27+
{ value: asInteger(fromDOM({ progress: getProperty('value') }, 0)) },
28+
(el, { first, useElement }) => {
29+
const max =
30+
useElement('progress', 'Add a native <progress> element.').max ??
31+
100
5032
const thresholds: FormGaugeThreshold[] = (() => {
5133
const attr = el.getAttribute('thresholds')
5234
if (!attr) return []
@@ -58,9 +40,7 @@ export default component(
5840
})()
5941
const qualification = computed(
6042
() =>
61-
thresholds.find(
62-
threshold => el.getSignal('value').get() >= threshold.min,
63-
) || {
43+
thresholds.find(threshold => el.value >= threshold.min) || {
6444
label: '',
6545
color: 'var(--color-primary)',
6646
},
@@ -78,14 +58,31 @@ export default component(
7858
() => `${(240 * el.value) / max}deg`,
7959
),
8060
setStyle('--form-gauge-color', () => qualification.get().color),
81-
first(
82-
'small',
83-
setText(() => qualification.get().label),
84-
),
61+
first('small', [setText(() => qualification.get().label)]),
8562

86-
// Enable/disable buttons based on value
87-
first('button.increment', setProperty('disabled', () => el.value >= max)),
88-
first('button.decrement', setProperty('disabled', () => el.value <= 0))
63+
// Event handlers on buttons and their disabled state
64+
first('button.increment', [
65+
setProperty('disabled', () => el.value >= max),
66+
on('click', ({ event }) => {
67+
el.value += event.shiftKey ? 10 : 1
68+
}),
69+
]),
70+
first('button.decrement', [
71+
setProperty('disabled', () => el.value <= 0),
72+
on('click', ({ event }) => {
73+
el.value -= event.shiftKey ? 10 : 1
74+
}),
75+
]),
76+
on('keydown', ({ event }) => {
77+
const { key, shiftKey } = event
78+
if ((key === 'ArrowLeft' || key === '-') && el.value > 0)
79+
el.value -= shiftKey ? 10 : 1
80+
else if (
81+
(key === 'ArrowRight' || key === '+') &&
82+
el.value < max
83+
)
84+
el.value += shiftKey ? 10 : 1
85+
}),
8986
]
9087
},
9188
)

docs-src/components/hello-world/hello-world.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
import { asString, type Component, component, on, setText } from '../../..'
1+
import {
2+
asString,
3+
type Component,
4+
component,
5+
fromDOM,
6+
getText,
7+
on,
8+
setText,
9+
} from '../../..'
210

311
export type HelloWorldProps = {
412
name: string
513
}
614

715
export default component(
816
'hello-world',
9-
{
10-
name: asString(
11-
el => el.querySelector('span')?.textContent?.trim() ?? '',
12-
),
13-
},
17+
{ name: asString(fromDOM({ span: getText() }, '')) },
1418
(el, { first }) => {
1519
const fallback = el.name
1620
return [

docs-src/components/module-dialog/module-dialog.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@ export default component(
3434
if (event.key === 'Escape') el.open = false
3535
}),
3636
]),
37-
first(
38-
'dialog .close',
37+
first('dialog .close', [
3938
on('click', () => {
4039
el.open = false
4140
}),
42-
),
41+
]),
4342
() =>
4443
effect(() => {
4544
if (el.open) {

docs-src/components/module-pagination/module-pagination.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {
22
asInteger,
33
type Component,
44
component,
5+
fromDOM,
6+
getProperty,
57
on,
68
setAttribute,
79
setProperty,
@@ -17,32 +19,36 @@ export type ModulePaginationProps = {
1719
export default component(
1820
'module-pagination',
1921
{
20-
value: asInteger(1),
21-
max: asInteger(1),
22+
value: asInteger(fromDOM({ input: getProperty('value') }, 1)),
23+
max: asInteger(fromDOM({ input: getProperty('max') }, 1)),
2224
},
2325
(el, { first }) => [
26+
// Reflect attributes of module-pagination component
2427
show(() => el.max > 1),
2528
setAttribute('value', () => String(el.value)),
2629
setAttribute('max', () => String(el.max)),
27-
first('.value', setText(() => String(el.value))),
28-
first('.max', setText(() => String(el.max))),
29-
on('keyup', ({ event }) => {
30-
if ((event.target as HTMLElement)?.localName === 'input') return
31-
const key = event.key
32-
if (key === 'ArrowLeft' && el.value > 1) el.value--
33-
else if (key === 'ArrowRight' && el.value < el.max) el.value++
34-
}),
30+
31+
// Text content for current and max page numbers
32+
first('.value', [setText(() => String(el.value))]),
33+
first('.max', [setText(() => String(el.max))]),
34+
35+
// Event handler on input and its value and max properties
3536
first(
3637
'input',
3738
[
3839
on('change', ({ target }) => {
39-
el.value = Math.max(1, Math.min(target.valueAsNumber, el.max))
40+
el.value = Math.max(
41+
1,
42+
Math.min(target.valueAsNumber, el.max),
43+
)
4044
}),
4145
setProperty('value', () => String(el.value)),
4246
setProperty('max', () => String(el.max)),
4347
],
44-
'Add an <input[type="number"]> to enter the page number to go to.'
48+
'Add an <input[type="number"]> to enter the page number to go to.',
4549
),
50+
51+
// Event handlers on buttons and their disabled state
4652
first(
4753
'button.prev',
4854
[
@@ -51,7 +57,7 @@ export default component(
5157
}),
5258
setProperty('disabled', () => el.value <= 1),
5359
],
54-
'Add a <button.prev> to go to previous page.',
60+
'Add a <button.prev> to go to the previous page.',
5561
),
5662
first(
5763
'button.next',
@@ -61,8 +67,15 @@ export default component(
6167
}),
6268
setProperty('disabled', () => el.value >= el.max),
6369
],
64-
'Add a <button.next> to go to next page.',
70+
'Add a <button.next> to go to the next page.',
6571
),
72+
on('keyup', ({ event }) => {
73+
if ((event.target as HTMLElement)?.localName === 'input') return
74+
const key = event.key
75+
if ((key === 'ArrowLeft' || key === '-') && el.value > 1) el.value--
76+
else if ((key === 'ArrowRight' || key === '+') && el.value < el.max)
77+
el.value++
78+
}),
6679
],
6780
)
6881

docs-src/pages/api/classes/CircularMutationError.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Class: CircularMutationError
88

9-
Defined in: [src/core/errors.ts:10](https://github.com/zeixcom/ui-element/blob/e094bd31ef74080268e6d1b7a25d938efebeb3ee/src/core/errors.ts#L10)
9+
Defined in: [src/core/errors.ts:10](https://github.com/zeixcom/ui-element/blob/df58db6949960ec0cd0685fb302ff1878e15bf79/src/core/errors.ts#L10)
1010

1111
Error thrown when a circular dependency is detected in a selection signal
1212

@@ -24,7 +24,7 @@ Error thrown when a circular dependency is detected in a selection signal
2424

2525
> **new CircularMutationError**(`host`, `selector`): `CircularMutationError`
2626
27-
Defined in: [src/core/errors.ts:15](https://github.com/zeixcom/ui-element/blob/e094bd31ef74080268e6d1b7a25d938efebeb3ee/src/core/errors.ts#L15)
27+
Defined in: [src/core/errors.ts:15](https://github.com/zeixcom/ui-element/blob/df58db6949960ec0cd0685fb302ff1878e15bf79/src/core/errors.ts#L15)
2828

2929
#### Parameters
3030

docs-src/pages/api/classes/DependencyTimeoutError.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Class: DependencyTimeoutError
88

9-
Defined in: [src/core/errors.ts:115](https://github.com/zeixcom/ui-element/blob/e094bd31ef74080268e6d1b7a25d938efebeb3ee/src/core/errors.ts#L115)
9+
Defined in: [src/core/errors.ts:115](https://github.com/zeixcom/ui-element/blob/df58db6949960ec0cd0685fb302ff1878e15bf79/src/core/errors.ts#L115)
1010

1111
Error when a component's dependencies are not met within a specified timeout
1212

@@ -24,7 +24,7 @@ Error when a component's dependencies are not met within a specified timeout
2424

2525
> **new DependencyTimeoutError**(`host`, `missing`): `DependencyTimeoutError`
2626
27-
Defined in: [src/core/errors.ts:116](https://github.com/zeixcom/ui-element/blob/e094bd31ef74080268e6d1b7a25d938efebeb3ee/src/core/errors.ts#L116)
27+
Defined in: [src/core/errors.ts:116](https://github.com/zeixcom/ui-element/blob/df58db6949960ec0cd0685fb302ff1878e15bf79/src/core/errors.ts#L116)
2828

2929
#### Parameters
3030

docs-src/pages/api/classes/InvalidComponentNameError.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Class: InvalidComponentNameError
88

9-
Defined in: [src/core/errors.ts:28](https://github.com/zeixcom/ui-element/blob/e094bd31ef74080268e6d1b7a25d938efebeb3ee/src/core/errors.ts#L28)
9+
Defined in: [src/core/errors.ts:28](https://github.com/zeixcom/ui-element/blob/df58db6949960ec0cd0685fb302ff1878e15bf79/src/core/errors.ts#L28)
1010

1111
Error thrown when component name violates rules for custom element names
1212

@@ -24,7 +24,7 @@ Error thrown when component name violates rules for custom element names
2424

2525
> **new InvalidComponentNameError**(`component`): `InvalidComponentNameError`
2626
27-
Defined in: [src/core/errors.ts:32](https://github.com/zeixcom/ui-element/blob/e094bd31ef74080268e6d1b7a25d938efebeb3ee/src/core/errors.ts#L32)
27+
Defined in: [src/core/errors.ts:32](https://github.com/zeixcom/ui-element/blob/df58db6949960ec0cd0685fb302ff1878e15bf79/src/core/errors.ts#L32)
2828

2929
#### Parameters
3030

docs-src/pages/api/classes/InvalidEffectsError.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Class: InvalidEffectsError
88

9-
Defined in: [src/core/errors.ts:64](https://github.com/zeixcom/ui-element/blob/e094bd31ef74080268e6d1b7a25d938efebeb3ee/src/core/errors.ts#L64)
9+
Defined in: [src/core/errors.ts:64](https://github.com/zeixcom/ui-element/blob/df58db6949960ec0cd0685fb302ff1878e15bf79/src/core/errors.ts#L64)
1010

1111
Error thrown when setup function does not return effects
1212

@@ -24,7 +24,7 @@ Error thrown when setup function does not return effects
2424

2525
> **new InvalidEffectsError**(`host`, `cause?`): `InvalidEffectsError`
2626
27-
Defined in: [src/core/errors.ts:69](https://github.com/zeixcom/ui-element/blob/e094bd31ef74080268e6d1b7a25d938efebeb3ee/src/core/errors.ts#L69)
27+
Defined in: [src/core/errors.ts:69](https://github.com/zeixcom/ui-element/blob/df58db6949960ec0cd0685fb302ff1878e15bf79/src/core/errors.ts#L69)
2828

2929
#### Parameters
3030

docs-src/pages/api/classes/InvalidPropertyNameError.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Class: InvalidPropertyNameError
88

9-
Defined in: [src/core/errors.ts:45](https://github.com/zeixcom/ui-element/blob/e094bd31ef74080268e6d1b7a25d938efebeb3ee/src/core/errors.ts#L45)
9+
Defined in: [src/core/errors.ts:45](https://github.com/zeixcom/ui-element/blob/df58db6949960ec0cd0685fb302ff1878e15bf79/src/core/errors.ts#L45)
1010

1111
Error thrown when trying to assign a property name that conflicts with reserved words or inherited HTMLElement properties
1212

@@ -24,7 +24,7 @@ Error thrown when trying to assign a property name that conflicts with reserved
2424

2525
> **new InvalidPropertyNameError**(`component`, `prop`, `reason`): `InvalidPropertyNameError`
2626
27-
Defined in: [src/core/errors.ts:51](https://github.com/zeixcom/ui-element/blob/e094bd31ef74080268e6d1b7a25d938efebeb3ee/src/core/errors.ts#L51)
27+
Defined in: [src/core/errors.ts:51](https://github.com/zeixcom/ui-element/blob/df58db6949960ec0cd0685fb302ff1878e15bf79/src/core/errors.ts#L51)
2828

2929
#### Parameters
3030

0 commit comments

Comments
 (0)