Skip to content

Commit

Permalink
hugo: added select-and-copy filenames in code tabs
Browse files Browse the repository at this point in the history
- Added small file icon (select-and-copy) prefix for filenames in code-tabs
- Added select-and-copy button for copying filename - code-tab
- Added file icon to ui.svg
- Updated code-tabs shortcode example page

Fixes: cue-lang/cue#2935

Closes #469 as merged as of commit 90b21c7e.

Preview-Path: /examples/shortcodes/code-tabs/
Signed-off-by: juanstelling <[email protected]>
Change-Id: Ib9546da4f36c7ea8eec3fd8ba62dde852f1ee6b6
Dispatch-Trailer: {"type":"trybot","CL":1200531,"patchset":2,"ref":"refs/changes/31/1200531/2","targetBranch":"master"}
  • Loading branch information
JuanUsMedia authored and cueckoo committed Sep 3, 2024
1 parent 6ccc4f0 commit d17d82d
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 18 deletions.
7 changes: 5 additions & 2 deletions content/examples/shortcodes/code-tabs/en.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ languages:
name: Norwegian
{{</* /code-tab */>}}
{{</* code-tab name="data.yaml" language="yaml" linenos="true" area="bottom-left" */>}}
{{</* code-tab name="data.yaml" language="yaml" linenos="true" area="bottom-left" fileIcon="false */>}}
languages:
- tag: en
name: English
Expand Down Expand Up @@ -68,7 +68,7 @@ languages:
name: Norwegian
{{< /code-tab >}}

{{< code-tab name="data.yaml" language="yaml" linenos="true" area="bottom-left" >}}
{{< code-tab name="data.yaml" language="yaml" linenos="true" area="bottom-left" fileIcon="false" >}}
languages:
- tag: en
name: English
Expand Down Expand Up @@ -125,6 +125,9 @@ codeToCopy
Make sure it's base64 encoded when you pass something to this attribute.
You can also set it to false to hide the copy button.

fileIcon
: optional - Showing file icon. Can be true or false. By default the value is true.

## Examples of usage of different area's

### 2 tabs in top-left (1 column)
Expand Down
53 changes: 49 additions & 4 deletions hugo/assets/scss/components/tabs-nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@

border-bottom: 1px solid var(--tabs-nav-border, transparentize($c-blue--darker, .9));
display: flex;
overflow: hidden;

&__tabs {
display: flex;
overflow-x: auto;
padding: 0 $p-gutter;
scroll-behavior: smooth;
scrollbar-width: none;
}

&__item {
display: flex;
flex: 0 0 auto;
padding-right: 1.75rem;

Expand All @@ -27,10 +26,24 @@
}
}

&__copy {
height: 36px;
position: relative;
width: 1rem;

&:focus,
&:hover {
.icon {
fill: $c-blue--light;
}
}
}

&__tab {
background-color: var(--tab-background, $c-white);
color: var(--tab-color, $c-blue--darker);
display: block;
display: flex;
gap: 4px;
height: var(--tab-height, 52px);
line-height: var(--tab-height, 52px);
position: relative;
Expand Down Expand Up @@ -62,7 +75,7 @@
background-color: var(--tab-background-active, $c-white);
color: var(--tab-color-active, $c-blue--darker);
font-weight: $weight-bold;
pointer-events: none;
pointer-events: auto;

&::after {
background-color: var(--tab-border-color-active, $c-yellow);
Expand Down Expand Up @@ -123,6 +136,38 @@
width: 24px;
}

&__message {
@include style-text-small;

background-color: $c-grey-blue;
border-radius: $b-radius;
color: $c-blue--darker;
display: block;
left: -10px;
margin-right: 0.75rem;
padding: 4px 8px;
position: absolute;
top: 48px;
width: fit-content;
z-index: 1;

&::before {
border-color: transparent transparent $c-grey-blue;
border-style: solid;
border-width: 0 10px 10px;
bottom: 100%;
content: '';
height: 0;
left: 8px;
position: absolute;
width: 0;
}

&.is-hidden {
display: none;
}
}

&--prev {
margin-left: #{-$p-gutter};
}
Expand Down
3 changes: 3 additions & 0 deletions hugo/assets/svg/ui/file.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions hugo/assets/ts/widgets/copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ export class Copy extends BaseWidget {

navigator.clipboard.writeText(content).then(() => {
requestAnimationFrame(() => {
messageElement.classList.remove('is-hidden');
messageElement.setAttribute('aria-hidden', 'false');
messageElement?.classList.remove('is-hidden');
messageElement?.setAttribute('aria-hidden', 'false');
this.copyButton.classList.add('is-success');

setTimeout(() => {
messageElement.classList.add('is-hidden');
messageElement.setAttribute('aria-hidden', 'true');
messageElement?.classList.add('is-hidden');
messageElement?.setAttribute('aria-hidden', 'true');
this.copyButton.classList.remove('is-success');
}, 1000);
});
Expand Down
7 changes: 5 additions & 2 deletions hugo/content/en/examples/shortcodes/code-tabs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ languages:
name: Norwegian
{{</* /code-tab */>}}
{{</* code-tab name="data.yaml" language="yaml" linenos="true" area="bottom-left" */>}}
{{</* code-tab name="data.yaml" language="yaml" linenos="true" area="bottom-left" fileIcon="false */>}}
languages:
- tag: en
name: English
Expand Down Expand Up @@ -68,7 +68,7 @@ languages:
name: Norwegian
{{< /code-tab >}}

{{< code-tab name="data.yaml" language="yaml" linenos="true" area="bottom-left" >}}
{{< code-tab name="data.yaml" language="yaml" linenos="true" area="bottom-left" fileIcon="false" >}}
languages:
- tag: en
name: English
Expand Down Expand Up @@ -125,6 +125,9 @@ codeToCopy
Make sure it's base64 encoded when you pass something to this attribute.
You can also set it to false to hide the copy button.

fileIcon
: optional - Showing file icon. Can be true or false. By default the value is true.

## Examples of usage of different area's

### 2 tabs in top-left (1 column)
Expand Down
2 changes: 2 additions & 0 deletions hugo/i18n/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ other = "Go to the website"
# Copy button
[copy_title]
other = "Copy code"
[copy_filename]
other = "Copy filename"
[copy_message]
other = "Copied!"

Expand Down
26 changes: 24 additions & 2 deletions hugo/layouts/partials/tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@
data-tab-item="{{ .name | urlize }}"
data-tab-group="{{ $groupId }}"
class="tabs-nav__tab{{ if ne .type "default" }} tabs-nav__tab--{{ .type}}{{ end}}{{ cond (eq $idx 0) " is-active" ""}}"
>{{ .name }}</button>
{{- if and (eq .type "default") (eq .fileIcon true) -}} data-copy{{- end -}}
>
{{- if and (eq .type "default") (eq .fileIcon true) -}}
<span title="{{ T "copy_filename" }}" class="tabs-nav__copy" data-copy-button data-copy-type="text" data-copy-value="{{ .name }}">
{{- partial "icon.html" (dict "class" "" "icon" "file") -}}
<span class="tabs-nav__message is-hidden" data-copy-message aria-hidden="true">
{{ T "copy_message" }}
</span>
</span>
{{- end -}}
{{ .name }}
</button>
</li>
{{- end -}}
</ul>
Expand All @@ -37,7 +48,18 @@
data-tab-item="{{ .name | urlize }}"
data-tab-group="{{ $groupId }}"
class="tabs-nav__tab{{ if ne .type "default" }} tabs-nav__tab--{{ .type}}{{ end}}"
>{{ .name }}</div>
{{- if and (eq .type "default") (eq .fileIcon true) -}} data-copy{{- end -}}
>
{{- if and (eq .type "default") (eq .fileIcon true) -}}
<button title="{{ T "copy_filename" }}" class="tabs-nav__copy" data-copy-button data-copy-type="text" data-copy-value="{{ .name }}">
{{- partial "icon.html" (dict "class" "" "icon" "file") -}}
<span class="tabs-nav__message is-hidden" data-copy-message aria-hidden="true">
{{ T "copy_message" }}
</span>
</button>
{{- end -}}
{{ .name }}
</div>
</div>
{{- end -}}
{{- end -}}
Expand Down
2 changes: 2 additions & 0 deletions hugo/layouts/shortcodes/code-tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{{ $language := .Get "language" | default "" }}
{{ $codeToCopy := .Get "codetocopy" }}
{{ $type := .Get "type" | default "default" }}
{{ $fileIcon := .Get "fileIcon" | default true }}
{{ $lineos := .Get "linenos" | default "false" }}
{{ $groupId := .Get "groupId" | default "default" }}
{{ $arrayName := printf "tabs-%s" $area }}
Expand All @@ -19,6 +20,7 @@
"area" $area
"language" $language
"type" $type
"fileIcon" $fileIcon
"groupId" $groupId
"content" $content
) }}
Expand Down
8 changes: 4 additions & 4 deletions hugo/static/img/ui.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d17d82d

Please sign in to comment.