1
1
from __future__ import annotations
2
2
3
3
from base64 import b64encode
4
- from typing import Any , Callable , Dict , List , Optional , Sequence , Tuple , TypeVar , Union
4
+ from typing import Any , Callable , Iterable , Tuple , TypeVar , Union
5
5
6
6
from typing_extensions import Protocol
7
7
16
16
def image (
17
17
format : str ,
18
18
value : Union [str , bytes ] = "" ,
19
- attributes : Optional [ Dict [ str , Any ]] = None ,
19
+ ** attributes : Any ,
20
20
) -> VdomDict :
21
21
"""Utility for constructing an image from a string or bytes
22
22
@@ -33,19 +33,19 @@ def image(
33
33
base64_value = b64encode (bytes_value ).decode ()
34
34
src = f"data:image/{ format } ;base64,{ base64_value } "
35
35
36
- return {"tagName" : "img" , "attributes" : {"src" : src , ** ( attributes or {}) }}
36
+ return {"tagName" : "img" , "attributes" : {"src" : src , ** attributes }}
37
37
38
38
39
39
_Value = TypeVar ("_Value" )
40
40
41
41
42
42
def use_linked_inputs (
43
- attributes : Sequence [ Dict [str , Any ]],
43
+ attributes : Iterable [ dict [str , Any ]],
44
44
on_change : Callable [[_Value ], None ] = lambda value : None ,
45
45
cast : _CastFunc [_Value ] = lambda value : value ,
46
46
initial_value : str = "" ,
47
47
ignore_empty : bool = True ,
48
- ) -> List [VdomDict ]:
48
+ ) -> list [VdomDict ]:
49
49
"""Return a list of linked inputs equal to the number of given attributes.
50
50
51
51
Parameters:
@@ -67,7 +67,7 @@ def use_linked_inputs(
67
67
"""
68
68
value , set_value = idom .hooks .use_state (initial_value )
69
69
70
- def sync_inputs (event : Dict [str , Any ]) -> None :
70
+ def sync_inputs (event : dict [str , Any ]) -> None :
71
71
new_value = event ["target" ]["value" ]
72
72
set_value (new_value )
73
73
if not new_value and ignore_empty :
@@ -82,7 +82,7 @@ def sync_inputs(event: Dict[str, Any]) -> None:
82
82
key = attrs .pop ("key" , None )
83
83
attrs .update ({"onChange" : sync_inputs , "value" : value })
84
84
85
- inputs .append (html .input (attrs , key = key ))
85
+ inputs .append (html .input (key = key , ** attrs ))
86
86
87
87
return inputs
88
88
0 commit comments