Skip to content

Commit

Permalink
chore: make new markdown styles optional without modifying previous c…
Browse files Browse the repository at this point in the history
…ompact implementation #2179
  • Loading branch information
marek-mihok committed Nov 13, 2023
1 parent b12d34e commit cba1f36
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 46 deletions.
10 changes: 10 additions & 0 deletions py/h2o_lightwave/h2o_lightwave/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9608,11 +9608,13 @@ def __init__(
title: str,
content: str,
data: Optional[PackedRecord] = None,
compact: Optional[bool] = None,
commands: Optional[List[Command]] = None,
):
_guard_scalar('MarkdownCard.box', box, (str,), False, False, False)
_guard_scalar('MarkdownCard.title', title, (str,), False, False, False)
_guard_scalar('MarkdownCard.content', content, (str,), False, False, False)
_guard_scalar('MarkdownCard.compact', compact, (bool,), False, True, False)
_guard_vector('MarkdownCard.commands', commands, (Command,), False, True, False)
self.box = box
"""A string indicating how to place this component on the page."""
Expand All @@ -9622,6 +9624,8 @@ def __init__(
"""The markdown content. Supports Github Flavored Markdown (GFM): https://guides.github.com/features/mastering-markdown/"""
self.data = data
"""Additional data for the card."""
self.compact = compact
"""In compact mode markdown content takes less screen space. Defaults to True."""
self.commands = commands
"""Contextual menu commands for this component."""

Expand All @@ -9630,13 +9634,15 @@ def dump(self) -> Dict:
_guard_scalar('MarkdownCard.box', self.box, (str,), False, False, False)
_guard_scalar('MarkdownCard.title', self.title, (str,), False, False, False)
_guard_scalar('MarkdownCard.content', self.content, (str,), False, False, False)
_guard_scalar('MarkdownCard.compact', self.compact, (bool,), False, True, False)
_guard_vector('MarkdownCard.commands', self.commands, (Command,), False, True, False)
return _dump(
view='markdown',
box=self.box,
title=self.title,
content=self.content,
data=self.data,
compact=self.compact,
commands=None if self.commands is None else [__e.dump() for __e in self.commands],
)

Expand All @@ -9650,18 +9656,22 @@ def load(__d: Dict) -> 'MarkdownCard':
__d_content: Any = __d.get('content')
_guard_scalar('MarkdownCard.content', __d_content, (str,), False, False, False)
__d_data: Any = __d.get('data')
__d_compact: Any = __d.get('compact')
_guard_scalar('MarkdownCard.compact', __d_compact, (bool,), False, True, False)
__d_commands: Any = __d.get('commands')
_guard_vector('MarkdownCard.commands', __d_commands, (dict,), False, True, False)
box: str = __d_box
title: str = __d_title
content: str = __d_content
data: Optional[PackedRecord] = __d_data
compact: Optional[bool] = __d_compact
commands: Optional[List[Command]] = None if __d_commands is None else [Command.load(__e) for __e in __d_commands]
return MarkdownCard(
box,
title,
content,
data,
compact,
commands,
)

Expand Down
3 changes: 3 additions & 0 deletions py/h2o_lightwave/h2o_lightwave/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3388,6 +3388,7 @@ def markdown_card(
title: str,
content: str,
data: Optional[PackedRecord] = None,
compact: Optional[bool] = None,
commands: Optional[List[Command]] = None,
) -> MarkdownCard:
"""Create a card that renders Markdown content.
Expand All @@ -3402,6 +3403,7 @@ def markdown_card(
title: The title for this card.
content: The markdown content. Supports Github Flavored Markdown (GFM): https://guides.github.com/features/mastering-markdown/
data: Additional data for the card.
compact: In compact mode markdown content takes less screen space. Defaults to True.
commands: Contextual menu commands for this component.
Returns:
A `h2o_wave.types.MarkdownCard` instance.
Expand All @@ -3411,6 +3413,7 @@ def markdown_card(
title,
content,
data,
compact,
commands,
)

Expand Down
10 changes: 10 additions & 0 deletions py/h2o_wave/h2o_wave/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -9608,11 +9608,13 @@ def __init__(
title: str,
content: str,
data: Optional[PackedRecord] = None,
compact: Optional[bool] = None,
commands: Optional[List[Command]] = None,
):
_guard_scalar('MarkdownCard.box', box, (str,), False, False, False)
_guard_scalar('MarkdownCard.title', title, (str,), False, False, False)
_guard_scalar('MarkdownCard.content', content, (str,), False, False, False)
_guard_scalar('MarkdownCard.compact', compact, (bool,), False, True, False)
_guard_vector('MarkdownCard.commands', commands, (Command,), False, True, False)
self.box = box
"""A string indicating how to place this component on the page."""
Expand All @@ -9622,6 +9624,8 @@ def __init__(
"""The markdown content. Supports Github Flavored Markdown (GFM): https://guides.github.com/features/mastering-markdown/"""
self.data = data
"""Additional data for the card."""
self.compact = compact
"""In compact mode markdown content takes less screen space. Defaults to True."""
self.commands = commands
"""Contextual menu commands for this component."""

Expand All @@ -9630,13 +9634,15 @@ def dump(self) -> Dict:
_guard_scalar('MarkdownCard.box', self.box, (str,), False, False, False)
_guard_scalar('MarkdownCard.title', self.title, (str,), False, False, False)
_guard_scalar('MarkdownCard.content', self.content, (str,), False, False, False)
_guard_scalar('MarkdownCard.compact', self.compact, (bool,), False, True, False)
_guard_vector('MarkdownCard.commands', self.commands, (Command,), False, True, False)
return _dump(
view='markdown',
box=self.box,
title=self.title,
content=self.content,
data=self.data,
compact=self.compact,
commands=None if self.commands is None else [__e.dump() for __e in self.commands],
)

Expand All @@ -9650,18 +9656,22 @@ def load(__d: Dict) -> 'MarkdownCard':
__d_content: Any = __d.get('content')
_guard_scalar('MarkdownCard.content', __d_content, (str,), False, False, False)
__d_data: Any = __d.get('data')
__d_compact: Any = __d.get('compact')
_guard_scalar('MarkdownCard.compact', __d_compact, (bool,), False, True, False)
__d_commands: Any = __d.get('commands')
_guard_vector('MarkdownCard.commands', __d_commands, (dict,), False, True, False)
box: str = __d_box
title: str = __d_title
content: str = __d_content
data: Optional[PackedRecord] = __d_data
compact: Optional[bool] = __d_compact
commands: Optional[List[Command]] = None if __d_commands is None else [Command.load(__e) for __e in __d_commands]
return MarkdownCard(
box,
title,
content,
data,
compact,
commands,
)

Expand Down
3 changes: 3 additions & 0 deletions py/h2o_wave/h2o_wave/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3388,6 +3388,7 @@ def markdown_card(
title: str,
content: str,
data: Optional[PackedRecord] = None,
compact: Optional[bool] = None,
commands: Optional[List[Command]] = None,
) -> MarkdownCard:
"""Create a card that renders Markdown content.
Expand All @@ -3402,6 +3403,7 @@ def markdown_card(
title: The title for this card.
content: The markdown content. Supports Github Flavored Markdown (GFM): https://guides.github.com/features/mastering-markdown/
data: Additional data for the card.
compact: In compact mode markdown content takes less screen space. Defaults to True.
commands: Contextual menu commands for this component.
Returns:
A `h2o_wave.types.MarkdownCard` instance.
Expand All @@ -3411,6 +3413,7 @@ def markdown_card(
title,
content,
data,
compact,
commands,
)

Expand Down
4 changes: 4 additions & 0 deletions r/R/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -3948,6 +3948,7 @@ ui_list_item1_card <- function(
#' @param title The title for this card.
#' @param content The markdown content. Supports Github Flavored Markdown (GFM): https://guides.github.com/features/mastering-markdown/
#' @param data Additional data for the card.
#' @param compact In compact mode markdown content takes less screen space. Defaults to True.
#' @param commands Contextual menu commands for this component.
#' @return A MarkdownCard instance.
#' @export
Expand All @@ -3956,17 +3957,20 @@ ui_markdown_card <- function(
title,
content,
data = NULL,
compact = NULL,
commands = NULL) {
.guard_scalar("box", "character", box)
.guard_scalar("title", "character", title)
.guard_scalar("content", "character", content)
# TODO Validate data: Rec
.guard_scalar("compact", "logical", compact)
.guard_vector("commands", "WaveCommand", commands)
.o <- list(
box=box,
title=title,
content=content,
data=data,
compact=compact,
commands=commands,
view='markdown')
class(.o) <- append(class(.o), c(.wave_obj, "WaveMarkdownCard"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1667,11 +1667,12 @@
<option name="Python" value="true"/>
</context>
</template>
<template name="w_full_markdown_card" value="ui.markdown_card(box='$box$',title='$title$',content='$content$',data=$data$,commands=[&#10; $commands$ &#10;])$END$" description="Create Wave MarkdownCard with full attributes." toReformat="true" toShortenFQNames="true">
<template name="w_full_markdown_card" value="ui.markdown_card(box='$box$',title='$title$',content='$content$',data=$data$,compact=$compact$,commands=[&#10; $commands$ &#10;])$END$" description="Create Wave MarkdownCard with full attributes." toReformat="true" toShortenFQNames="true">
<variable name="box" expression="" defaultValue="" alwaysStopAt="true"/>
<variable name="title" expression="" defaultValue="" alwaysStopAt="true"/>
<variable name="content" expression="" defaultValue="" alwaysStopAt="true"/>
<variable name="data" expression="" defaultValue="&quot;None&quot;" alwaysStopAt="true"/>
<variable name="compact" expression="" defaultValue="&quot;True&quot;" alwaysStopAt="true"/>
<variable name="commands" expression="" defaultValue="" alwaysStopAt="true"/>
<context>
<option name="Python" value="true"/>
Expand Down
2 changes: 1 addition & 1 deletion tools/vscode-extension/component-snippets.json
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,7 @@
"Wave Full MarkdownCard": {
"prefix": "w_full_markdown_card",
"body": [
"ui.markdown_card(box='$1', title='$2', content='$3', data=${4:None}, commands=[\n\t\t$5\t\t\n])$0"
"ui.markdown_card(box='$1', title='$2', content='$3', data=${4:None}, compact=${5:True}, commands=[\n\t\t$6\t\t\n])$0"
],
"description": "Create a full Wave MarkdownCard."
},
Expand Down
86 changes: 46 additions & 40 deletions ui/src/markdown.css
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Prevent `sub` and `sup` elements from affecting the line height in all browsers.
2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016)
3. Remove gaps between table borders by default.
*/
.wave-prose table {
.wave-markdown table {
text-indent: 0;
border-color: inherit;
border-collapse: collapse;
Expand Down Expand Up @@ -184,13 +184,13 @@ Constrain images and videos to the parent width and preserve their intrinsic asp
margin-bottom: 1.2em;
}

.wave-prose a {
.wave-markdown a {
color: var(--wave-themePrimary);
text-decoration: underline;
font-weight: 500;
}

.wave-prose a:hover {
.wave-markdown a:hover {
text-decoration: none;
}

Expand Down Expand Up @@ -384,22 +384,26 @@ Constrain images and videos to the parent width and preserve their intrinsic asp
padding-left: 0.375em;
}

.wave-prose table {
.wave-markdown table {
width: 100%;
table-layout: auto;
text-align: left;
margin-top: 2em;
margin-bottom: 2em;
font-size: 0.875em;
line-height: 1.7142857;
}

.wave-prose thead {
.wave-prose table {
font-size: 0.875em;
}

.wave-markdown thead {
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: var(--wave-text4);
}

.wave-prose thead th {
.wave-markdown thead th {
color: var(--wave-text);
font-weight: 600;
vertical-align: bottom;
Expand All @@ -408,25 +412,53 @@ Constrain images and videos to the parent width and preserve their intrinsic asp
padding-left: 0.5714286em;
}

.wave-prose tbody tr {
.wave-markdown tbody tr {
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: var(--wave-text2);
}

.wave-prose tbody tr:last-child {
.wave-markdown tbody tr:last-child {
border-bottom-width: 0;
}

.wave-prose tbody td {
.wave-markdown tbody td {
vertical-align: baseline;
/* padding: 11px 6px; */
}

.wave-markdown thead th:first-child {
padding-left: 0;
}

.wave-markdown thead th:last-child {
padding-right: 0;
}

.wave-markdown tbody td,
tfoot td {
padding-top: 0.5714286em;
padding-right: 0.5714286em;
padding-bottom: 0.5714286em;
padding-left: 0.5714286em;
}

.wave-markdown tbody td:first-child,
tfoot td:first-child {
padding-left: 0;
}

.wave-prose tfoot {
.wave-markdown tbody td:last-child,
tfoot td:last-child {
padding-right: 0;
}

.wave-markdown tfoot {
border-top-width: 1px;
border-top-color: var(--wave-text4);
}

.wave-prose tfoot td {
.wave-markdown tfoot td {
vertical-align: top;
}

Expand Down Expand Up @@ -525,42 +557,16 @@ ol ol {
margin-top: 0;
}

.wave-prose thead th:first-child {
padding-left: 0;
}

.wave-prose thead th:last-child {
padding-right: 0;
}

.wave-prose tbody td,
tfoot td {
padding-top: 0.5714286em;
padding-right: 0.5714286em;
padding-bottom: 0.5714286em;
padding-left: 0.5714286em;
}

.wave-prose tbody td:first-child,
tfoot td:first-child {
padding-left: 0;
}

.wave-prose tbody td:last-child,
tfoot td:last-child {
padding-right: 0;
}

.wave-prose figure {
margin-top: 2em;
margin-bottom: 2em;
}

.wave-prose> :first-child {
.wave-markdown> :first-child {
margin-top: 0;
}

.wave-prose> :last-child {
.wave-markdown> :last-child {
margin-bottom: 0;
}

Expand Down
Loading

0 comments on commit cba1f36

Please sign in to comment.