def __init__(self, klass: Union[hc.HtmlClass, str]): super().__init__(klass) self.css.add_style(kv.KLoc.L.get_css()) self.css.add_style( hc.Css([ # group container styles hc.CssChunk( self.get_selector(SelectorType.GROUP), { 'display': 'grid', 'grid-template-columns': 'auto', 'grid-gap': '5px 10px', # vert, horz }), # kv key styles hc.CssChunk(self.get_selector(SelectorType.KEY), { 'text-align': 'left', }), # kv value styles hc.CssChunk(self.get_selector(SelectorType.VALUE), { 'text-align': 'right', }), ]))
def set_kv_horz_alignment(self, alignment: KvAlign): self.css.add_style( hc.Css([ hc.CssChunk(self.get_selector(SelectorType.KEY), { 'text-align': alignment.key_alignment, }), hc.CssChunk(self.get_selector(SelectorType.VALUE), { 'text-align': alignment.value_alignment, }), ]))
def get_css( self, kv_name: Optional[str] = None, containing_class: Optional[Union[hc.HtmlClass, str]] = None, ) -> hc.Css: kv_css = hc.Css() # TODO: clean this selector creation business up if kv_name is not None and containing_class is not None: raise ValueError(f'Only one of kv_name and containing_class may be set') elif containing_class is not None: if isinstance(containing_class, hc.HtmlClass): class_name = containing_class.name elif isinstance(containing_class, str): class_name = containing_class else: raise ValueError(f'containing_class should be either an HtmlClass or str. ' f'Got {type(containing_class)}') container_selector = hc.HtmlClassesNested([class_name, SelectorType.KV_CONTAINER.html_class_name]) key_selector = hc.HtmlClassesNested([class_name, SelectorType.KEY.html_class_name]) value_selector = hc.HtmlClassesNested([class_name, SelectorType.VALUE.html_class_name]) else: # containing_class is None. kv_name is set or is None container_selector = get_all_classes_container_selector(kv_name) key_selector = get_all_classes_key_selector(kv_name) value_selector = get_all_classes_value_selector(kv_name) kv_css.add_style(hc.CssChunk( container_selector, { 'display': 'grid', 'grid-template-columns': ' '.join(['auto'] * self.num_cols), 'grid-template-rows': ' '.join(['auto'] * self.num_rows), }, )) kv_css.add_style(hc.CssChunk( key_selector, { 'grid-column-start': self.key_col, 'grid-row-start': self.key_row, }, )) kv_css.add_style(hc.CssChunk( value_selector, { 'grid-column-start': self.value_col, 'grid-row-start': self.value_row, }, )) return kv_css
def do_add_colon_to_keys(self): self.css.add_style( hc.CssChunk( f'{self.get_selector(SelectorType.KEY).to_selector_str()}:after', { 'content': "':'", }), )
def _get_css_chunk(word_id: str, color_str: str): return hc.CssChunk( selector=f'#{word_id}', values={ 'background-color': color_str, 'color': color_str, }, )
def set_kv_vert_alignment(self, alignment: KvAlign): self.css.add_style( hc.Css([ hc.CssChunk( self.get_selector(SelectorType.KEY_OUTER), { 'display': 'flex', 'flex-direction': 'column', 'justify-content': alignment.key_alignment, 'height': '100%', }), hc.CssChunk( self.get_selector(SelectorType.VALUE_OUTER), { 'display': 'flex', 'flex-direction': 'column', 'justify-content': alignment.value_alignment, 'height': '100%', }), ]))
def set_css_property(self, property: str, value: Optional[str], selector_type=SelectorType.KEY): if value is None: return self.css.add_style( hc.CssChunk(self.get_selector(selector_type), { property: value, }))
def __init__(self, klass: Union[hc.HtmlClass, str]): super().__init__(klass) self.html_chunks = [] css = hc.Css([ hc.CssChunk(self.get_selector(SelectorType.GROUP), { 'border-collapse': 'collapse', 'height': '1px', }), hc.CssChunk( self.get_selector(SelectorType.TDS_IN_GROUP), { 'border-style': 'solid', 'border-width': '1px', 'padding': '1px', 'height': '100%', }), hc.CssChunk(self.get_selector(SelectorType.TRS_IN_GROUP), { 'height': '100%', }), ]) self.add_style(css)