Coverage for src / lexigram / admin / ui / molecules / filter_dropdown.py: 46%

13 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-08-11 02:23 +0800

1from __future__ import annotations 

2 

3from typing import Any 

4 

5from lexigram.ui import Component, el 

6 

7 

8class FilterDropdown(Component): 

9 """ 

10 A dropdown filter for selecting categories or status. 

11 """ 

12 

13 def __init__( 

14 self, 

15 name: str, 

16 label: str, 

17 options: list[tuple[str, str]], 

18 multi: bool = False, 

19 **props, 

20 ) -> None: 

21 super().__init__(name=name, label=label, options=options, multi=multi, **props) 

22 self.name = name 

23 self.label = label 

24 self.options = options 

25 self.multi = multi 

26 

27 def render(self) -> Any: 

28 option_els = [ 

29 el("option", option[1], value=option[0]) for option in self.options 

30 ] 

31 

32 return el( 

33 "div", 

34 el( 

35 "label", 

36 self.label, 

37 for_=self.name, 

38 class_="block text-sm font-medium text-foreground mb-1.5", 

39 ), 

40 el( 

41 "select", 

42 el("option", f"All {self.label}s", value=""), 

43 *option_els, 

44 name=self.name, 

45 id=self.name, 

46 multiple=self.multi, 

47 class_="block w-full rounded-md border-border bg-card dark:bg-background text-sm focus:border-primary-500 focus:ring-primary-500 py-2 pl-3 pr-10 transition-colors", 

48 hx_get=self.props.get("hx_get"), 

49 hx_trigger="change", 

50 hx_target=self.props.get("hx_target", "#main-content"), 

51 hx_include=self.props.get("hx_include", "closest form"), 

52 ), 

53 class_="min-w-[150px]", 

54 )