Skip to content

Commit

Permalink
Annotations display redesign (rancher#9835)
Browse files Browse the repository at this point in the history
* Added new colors to yaml

* Added tooltip on click

* Clean up code

* Added i18n for text and code clean up

* Fixed typo
  • Loading branch information
bisht-richa authored Oct 5, 2023
1 parent c252794 commit 63d6ffd
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 52 deletions.
19 changes: 19 additions & 0 deletions shell/assets/styles/themes/_dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@

$drag-over: #DCDEE7;

// The library that decorates the code blocks in CodeMirror uses the same colours for light and dark themes.
// This causes a contrast and accessibility issues.
// To fix the issues we have added new colors to the code blocks in CodeMirror for light and dark themes.
$cm-meta: #FFFFFF;
$cm-string: #5CE6FF;
$cm-number: #63F7C1;
$cm-keyword: #FF9C9C;
$cm-atom: #CC8DBF;
$cm-comment: #E78957;

// Status colors Yaml variables
--cm-meta: #{$cm-meta};
--cm-string: #{$cm-string};
--cm-number: #{$cm-number};
--cm-keyword: #{$cm-keyword};
--cm-atom: #{$cm-atom};
--cm-comment: #{$cm-comment};

--default : #{$dark};
--default-text : #{$light};
--default-hover-bg : #{darken($dark, 10%)};
Expand Down Expand Up @@ -211,4 +229,5 @@

--product-icon : #{$lighter};
--product-icon-active : #{$lightest};
--annotations-hover-bg : #{$darkest};
}
22 changes: 21 additions & 1 deletion shell/assets/styles/themes/_light.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ $selected: rgba(#3D98D3, .5);

$drag-over: #DCDEE7;


// The library that decorates the code blocks in CodeMirror uses the same colours for light and dark themes.
// This causes a contrast and accessibility issues.
// To fix the issues we have added new colors to the code blocks in CodeMirror for light and dark themes.
$cm-meta: #141419;
$cm-string: #00529F;
$cm-number: #005E3B;
$cm-keyword: #B94545;
$cm-atom: #921E80;
$cm-comment: #8F5536;

BODY, .theme-light {

--primary : #{$primary};
Expand All @@ -55,6 +66,14 @@ BODY, .theme-light {
--primary-light-bg : #{rgba($primary, 0.05)};


// Status colors Yaml variables
--cm-meta: #{$cm-meta};
--cm-string: #{$cm-string};
--cm-number: #{$cm-number};
--cm-keyword: #{$cm-keyword};
--cm-atom: #{$cm-atom};
--cm-comment: #{$cm-comment};

.text-primary {
color: var(--primary) !important;
}
Expand Down Expand Up @@ -86,7 +105,6 @@ BODY, .theme-light {
--link-light-bg : #{rgba($link, 0.05)};



.text-link {
color: var(--link) !important;
}
Expand Down Expand Up @@ -541,4 +559,6 @@ BODY, .theme-light {

--product-icon : #{$darker};
--product-icon-active : #{$darkest};

--annotations-hover-bg : #{$lighter};
}
2 changes: 2 additions & 0 deletions shell/assets/translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ generic:
=1 {Matches 1 of {total, number}: "{sample}"}
other {Matches {matched, number} of {total, number}, including "{sample}"}
}
copyValue: Copy value
valueCopied: Value copied!

locale:
en-us: English
Expand Down
28 changes: 28 additions & 0 deletions shell/components/CodeMirror.vue
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,34 @@ export default {
height: initial;
background: none
}
.cm-s-base16-dark .cm-atom,
.cm-s-base16-light .cm-atom {
color: var(--cm-atom);
}
.cm-meta {
color: var(--cm-meta);
}
.cm-s-base16-dark .cm-comment,
.cm-s-base16-light .cm-comment {
color: var(--cm-meta);
}
.cm-s-base16-dark .cm-string,
.cm-s-base16-light .cm-string {
color: var(--cm-string);
}
.cm-s-base16-dark span.cm-keyword,
.cm-s-base16-light span.cm-keyword {
color: var(--cm-keyword);
}
.cm-s-base16-dark span.cm-number,
.cm-s-base16-light span.cm-number {
color: var(--cm-number);
}
&.as-text-area {
min-height: 40px;
Expand Down
41 changes: 34 additions & 7 deletions shell/components/CopyToClipboardText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export default {
plain: {
type: Boolean,
default: false
}
},
// If false Show toolTip instead of label before copy-to-clipboard icon
showLabel: {
type: Boolean,
default: true
},
},
data() {
Expand All @@ -28,28 +33,50 @@ export default {
if (t.tagName === 'I') {
t = t.parentElement || t;
}
setTimeout(() => {
this.copied = false;
}, 500);
}, 800);
}
},
}
}
};
</script>

<template>
<a
v-tooltip="!showLabel ? {content: $store.getters['i18n/t']('generic.copyValue')} : {content: null}"
class="copy-to-clipboard-text"
:class="{ 'copied': copied, 'plain': plain}"
href="#"
@click="clicked"
>
{{ text }} <i
class="icon"
:class="{ 'icon-copy': !copied, 'icon-checkmark': copied}"
/>
<span v-if="showLabel">{{ text }}</span>
<v-popover
popover-class="clipboard-text-copied"
placement="top"
:trigger="!showLabel ? 'click' : ''"
:open="copied && !showLabel"
>
<i
class="icon"
:class="{ 'icon-copy': !copied, 'icon-checkmark': copied}"
/>
<template slot="popover">
<span>{{ t('generic.valueCopied') }}</span>
</template>
</v-popover>
</a>
</template>
<style lang="scss">
.clipboard-text-copied {
.wrapper {
.popover-inner {
background: var(--tooltip-bg);
}
}
}
</style>
<style lang="scss" scoped>
.copy-to-clipboard-text {
&.plain {
Expand Down
97 changes: 53 additions & 44 deletions shell/components/DetailText.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
import { mapGetters } from 'vuex';
import { asciiLike, nlToBr } from '@shell/utils/string';
import { HIDE_SENSITIVE } from '@shell/store/prefs';
import CopyToClipboard from '@shell/components/CopyToClipboard';
import CodeMirror from '@shell/components/CodeMirror';
import { binarySize } from '@shell/utils/crypto';
import CopyToClipboardText from '@shell/components/CopyToClipboardText';
export default {
components: { CopyToClipboard, CodeMirror },
components: {
CopyToClipboardText,
CodeMirror
},
props: {
label: {
Expand Down Expand Up @@ -150,55 +153,52 @@ export default {
{{ label }}
</h5>

<span
v-if="isEmpty"
v-t="'detailText.empty'"
class="text-italic"
/>
<span
v-else-if="isBinary"
class="text-italic"
>{{ body }}</span>

<CodeMirror
v-else-if="jsonStr"
:options="{mode:{name:'javascript', json:true}, lineNumbers:false, foldGutter:false, readOnly:true}"
:value="jsonStr"
:class="{'conceal': concealed}"
/>

<span
v-else
v-clean-html="bodyHtml"
data-testid="detail-top_html"
:class="{'conceal': concealed, 'monospace': monospace && !isBinary}"
/>

<template v-if="!isBinary && !jsonStr && isLong && !expanded">
<a
href="#"
@click.prevent="expand"
>{{ plusMore }}</a>
</template>

<CopyToClipboard
v-if="copy && !isBinary"
:text="value"
class="role-tertiary"
action-color=""
/>
<div class="value-wrapper">
<CopyToClipboardText
v-if="copy && !isBinary"
:text="value"
:showLabel="false"
action-color=""
/>
<span
v-if="isEmpty"
v-t="'detailText.empty'"
class="text-italic"
/>
<span
v-else-if="isBinary"
class="text-italic "
>{{ body }}</span>

<CodeMirror
v-else-if="jsonStr"
:options="{mode:{name:'javascript', json:true}, lineNumbers:false, foldGutter:false, readOnly:true}"
:value="jsonStr"
:class="{'conceal': concealed}"
/>

<span
v-else
v-clean-html="bodyHtml"
data-testid="detail-top_html"
:class="{'conceal': concealed, 'monospace': monospace && !isBinary}"
/>

<template v-if="!isBinary && !jsonStr && isLong && !expanded">
<a
href="#"
@click.prevent="expand"
>{{ plusMore }}</a>
</template>
</div>
</div>
</template>

<style lang='scss' scoped>
.with-copy {
border: solid 1px var(--border);
border-radius: var(--border-radius);
padding: 10px;
padding: 8px 0;
position: relative;
background-color: var(--input-bg);
border-radius: var(--border-radius);
border: solid var(--border-width) var(--input-border);
> button {
position: absolute;
Expand All @@ -212,4 +212,13 @@ export default {
white-space: pre-wrap;
word-wrap: break-all
}
.value-wrapper {
display: flex;
padding: 8px 20px;
&:hover {
background: var(--annotations-hover-bg);
}
}
</style>
13 changes: 13 additions & 0 deletions shell/components/DetailTop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,19 @@ export default {
.annotation {
margin-top: 10px;
h5 {
font-weight: bold;
margin-left: 20px;
}
.icon {
margin-right: 10px;
}
.CodeMirror-lines {
margin: 0;
}
}
.label {
Expand Down

0 comments on commit 63d6ffd

Please sign in to comment.