@rlabs-inc/create-tui 0.2.0 → 0.2.1
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/package.json
CHANGED
|
@@ -9,23 +9,31 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { derived } from '@rlabs-inc/signals'
|
|
12
|
-
import { box, text, t, BorderStyle, Attr, getVariantStyle } from '@rlabs-inc/tui'
|
|
12
|
+
import { box, text, t, BorderStyle, Attr, getVariantStyle, reactiveProps } from '@rlabs-inc/tui'
|
|
13
13
|
import type { Counter as CounterState } from '../state/counters'
|
|
14
|
+
import type { PropInput } from '@rlabs-inc/tui'
|
|
14
15
|
|
|
15
16
|
interface CounterProps {
|
|
16
17
|
counter: CounterState
|
|
17
|
-
focused: boolean
|
|
18
|
+
focused: PropInput<boolean>
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
export function Counter(
|
|
21
|
+
export function Counter(rawProps: CounterProps) {
|
|
22
|
+
// Complex objects with nested signals: use directly (don't wrap)
|
|
23
|
+
const { counter } = rawProps
|
|
24
|
+
|
|
25
|
+
// Simple PropInput props: wrap with reactiveProps for consistent .value access
|
|
26
|
+
const { focused } = reactiveProps({ focused: rawProps.focused })
|
|
27
|
+
|
|
21
28
|
// Get variant colors
|
|
22
29
|
const variantStyle = getVariantStyle(counter.variant)
|
|
23
30
|
|
|
24
31
|
box({
|
|
25
|
-
border
|
|
26
|
-
|
|
32
|
+
// Use getters for reactive border/bg based on focus state
|
|
33
|
+
border: () => focused.value ? BorderStyle.DOUBLE : BorderStyle.SINGLE,
|
|
34
|
+
borderColor: () => focused.value ? t.primary.value : t.border.value,
|
|
27
35
|
padding: 1,
|
|
28
|
-
bg: focused ? t.surface :
|
|
36
|
+
bg: () => focused.value ? t.surface.value : null,
|
|
29
37
|
children: () => {
|
|
30
38
|
// Counter name with variant indicator
|
|
31
39
|
box({
|
|
@@ -34,8 +42,8 @@ export function Counter({ counter, focused }: CounterProps) {
|
|
|
34
42
|
children: () => {
|
|
35
43
|
text({
|
|
36
44
|
content: counter.name,
|
|
37
|
-
fg: focused ? t.primary : t.text,
|
|
38
|
-
attrs: focused ? Attr.BOLD : 0,
|
|
45
|
+
fg: () => focused.value ? t.primary.value : t.text.value,
|
|
46
|
+
attrs: () => focused.value ? Attr.BOLD : 0,
|
|
39
47
|
})
|
|
40
48
|
box({
|
|
41
49
|
width: 2,
|
|
@@ -68,7 +76,7 @@ export function Counter({ counter, focused }: CounterProps) {
|
|
|
68
76
|
alignItems: 'center',
|
|
69
77
|
children: () => {
|
|
70
78
|
text({
|
|
71
|
-
content: focused ? '[+/-] to change' : '',
|
|
79
|
+
content: () => focused.value ? '[+/-] to change' : '',
|
|
72
80
|
fg: t.textDim,
|
|
73
81
|
})
|
|
74
82
|
},
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
* - Focus tracking per item
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { derived } from '@rlabs-inc/signals'
|
|
11
10
|
import { box, text, each, t, BorderStyle, Attr, focusManager } from '@rlabs-inc/tui'
|
|
12
11
|
import { counters } from '../state/counters'
|
|
13
12
|
import { Counter } from './Counter'
|
|
@@ -50,9 +49,6 @@ export function CounterPanel() {
|
|
|
50
49
|
const counter = getCounter()
|
|
51
50
|
// Find index for focus tracking
|
|
52
51
|
const counterIndex = counters.value.findIndex(c => String(c.id) === key)
|
|
53
|
-
const isFocused = derived(
|
|
54
|
-
() => focusManager.focusedIndex === counterIndex
|
|
55
|
-
)
|
|
56
52
|
|
|
57
53
|
return box({
|
|
58
54
|
width: '48%',
|
|
@@ -60,7 +56,8 @@ export function CounterPanel() {
|
|
|
60
56
|
children: () => {
|
|
61
57
|
Counter({
|
|
62
58
|
counter,
|
|
63
|
-
|
|
59
|
+
// Pass as getter - Counter uses reactiveProps to normalize
|
|
60
|
+
focused: () => focusManager.focusedIndex === counterIndex,
|
|
64
61
|
})
|
|
65
62
|
},
|
|
66
63
|
})
|