Components ========== Structure --------- Each component is a valid HTML code. By simple words it consist of nested blocks with text and media content. Sections (optional): #. Client-side Java Scripts. #. Main component HTML markup. #. Local and global styles. #. Server-side Python code. .. highlight:: pantra Sample code::

Any HTML code here

# server-side python code from pantra.ctx import * def action(node): refs['greetz'].set_text('Very well!') Each component is stored to a file with extension `html`. Components are semantically grouped by directories, but component names should be unique. First letter of component name should be in **uppercase**. Common components are stored in `components` directory. Other components specific to application stored in application :doc:`directory `. Tags and attributes ------------------- HTML tag ^^^^^^^^ Any regular HTML tag from HTML5 specification is allowed. Tags should be specified in **lowercase**. .. note:: First letter case is important. So, ` * `on:drag="DragClass"` - drag-and-drop event. `pantra` provides special class :class:`~pantra.components.controllers.DragController` for this case::

from pantra.ctx import * from pantra.components.controllers import DragController class DragCtrl(DragController): node: HTMLElement def start(self, node) -> bool: if isinstance(node.style, str): node.style = DynamicStyles(node.style) node.style['left'] = node.metrics.left node.style['top'] = node.metrics.top self.node = node return True def move(self): self.node.move_box(self.delta_x, self.delta_y) def stop(self): pass * `on:keyup` and `on:keydown` can track any key pressed. However, it is possible to specify a key name in form `on:keydown:Enter`. Check key names on `MDN `__. For global events see :ref:`events`:: def undo_edit(node, key): node.set_text("") * Class switch `class:name="value"`. Enable or disable class of HTML element by result of expression from value. If value is omitted, it means contextual variable name has the same name as class, for example, `class:wide` <-> `class:wide="@wide"`. It is possible to combine several class switches with regular `class` attribute::
.. _style attr: * Partial dynamic style `css:style_name="value"`. Assign expression to evaluate specific style. It is possible to omit expression when local context has the same variable name: `css:color` <-> `css:color="@color"`. It is impossible to combine with regular `style` attribute.::
{{caption}}
* Behavior of boolean attributes is slightly changed: empty strings now are treated as `False`, removing attribute at render time. Actual for `checked`, `disabled` and `required`. * Non-string attribute assigning short form `set:attr_name="value"`. * Works better with boolean attributes: `set:hidden="{not visible}"` <-> `hidden="{not visible and 'hidden' else ''}"` * Omit value to assign variable with the same name: `set:required` <-> `set:required="{required}"` * Works with "focused" state of element: `set:focused` -> sets element focus after render * It understands string representation of boolean values: "yes"/"no": `set:focused="yes"` <-> `set:focused="{True}"`:: * Server-to-client variable connector `bind:value`. Works for interactive elements like ``, `