|
24 | 24 | load_file_into_form) |
25 | 25 |
|
26 | 26 |
|
| 27 | +class LabeledInput(Vertical): |
| 28 | + |
| 29 | + DEFAULT_CSS = """ |
| 30 | + LabeledInput { |
| 31 | + height: auto; |
| 32 | + |
| 33 | + } |
| 34 | + LabeledInput Static { |
| 35 | + width: 25%; |
| 36 | +
|
| 37 | + } |
| 38 | + LabeledInput Input { |
| 39 | + width: 100%; |
| 40 | + } |
| 41 | + """ |
| 42 | + |
| 43 | + def __init__( |
| 44 | + self, label: str, placeholder: str = "", value: str = "", **kwargs |
| 45 | + ): |
| 46 | + super().__init__(**kwargs) |
| 47 | + self.label = label |
| 48 | + self.placeholder = placeholder |
| 49 | + self._value = value |
| 50 | + |
| 51 | + def compose(self) -> ComposeResult: |
| 52 | + yield Static(self.label, classes="label") |
| 53 | + yield Input( |
| 54 | + id="input", placeholder=self.placeholder, value=self._value |
| 55 | + ) |
| 56 | + |
| 57 | + @property |
| 58 | + def value(self): |
| 59 | + return self._value |
| 60 | + |
| 61 | + @value.setter |
| 62 | + def value(self, v: str): |
| 63 | + self._value = v |
| 64 | + self.query_one(selector="#input").value = v |
| 65 | + |
| 66 | + |
27 | 67 | class SocialEntry(Horizontal): |
28 | 68 | DEFAULT_CSS = """ |
29 | 69 | SocialEntry Select { |
@@ -129,10 +169,18 @@ def on_mount(self) -> None: |
129 | 169 |
|
130 | 170 | # 2) Build the form portion, hidden at first |
131 | 171 | self.form_header = Static(FORM_HEADER, classes="header") |
132 | | - self.name_input = Input(placeholder=PLACEHOLDER_NAME) |
133 | | - self.email_input = Input(placeholder=PLACEHOLDER_EMAIL) |
134 | | - self.city_input = Input(placeholder=PLACEHOLDER_CITY) |
135 | | - self.homepage_input = Input(placeholder=PLACEHOLDER_HOMEPAGE) |
| 172 | + self.name_input = LabeledInput( |
| 173 | + f"{PLACEHOLDER_NAME}:", placeholder=PLACEHOLDER_NAME |
| 174 | + ) |
| 175 | + self.email_input = LabeledInput( |
| 176 | + f"{PLACEHOLDER_EMAIL}:", placeholder=PLACEHOLDER_EMAIL |
| 177 | + ) |
| 178 | + self.city_input = LabeledInput( |
| 179 | + f"{PLACEHOLDER_CITY}:", placeholder=PLACEHOLDER_CITY |
| 180 | + ) |
| 181 | + self.homepage_input = LabeledInput( |
| 182 | + f"{PLACEHOLDER_HOMEPAGE}:", placeholder=PLACEHOLDER_HOMEPAGE |
| 183 | + ) |
136 | 184 |
|
137 | 185 | self.who_area = TextArea() |
138 | 186 | self.python_area = TextArea() |
|
0 commit comments