Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(addon-doc): use code actions together #5570

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions projects/addon-doc/components/code/code.style.less
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
margin: 0;
white-space: normal;

&:hover .t-copy,
&:focus-visible .t-copy {
&:hover .t-code-actions,
&:focus-visible .t-code-actions {
opacity: 1;
}
}
Expand All @@ -24,11 +24,14 @@
margin-top: 1rem;
}

.t-copy {
.t-code-actions {
position: absolute;
top: 0.875rem;
right: 2rem;
display: flex;
opacity: 0;
gap: 0.5rem;
flex-direction: row-reverse;
}

// highlightjs added class
Expand Down
5 changes: 4 additions & 1 deletion projects/addon-doc/components/code/code.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
class="t-code"
>
<code [lineNumbers]="true" [highlight]="content"></code>
<tui-doc-copy class="t-copy" [cdkCopyToClipboard]="content"></tui-doc-copy>
<div class="t-code-actions">
<tui-doc-copy class="t-copy" [cdkCopyToClipboard]="content"></tui-doc-copy>
<ng-content></ng-content>
</div>
</pre>
15 changes: 12 additions & 3 deletions projects/addon-doc/components/code/tests/code.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ describe(`TuiDocCodeComponent`, () => {

expect(fixture.nativeElement.querySelector(`.t-code`)?.innerHTML.trim()).toEqual(
`<code class="hljs"><span class="hljs-keyword">const</span> a = <span class="hljs-number">5</span>;</code>
<tui-doc-copy class="t-copy"></tui-doc-copy>`,
<div class="t-code-actions">
<tui-doc-copy class="t-copy"></tui-doc-copy>
\t
</div>`.replace(`\t`, ` `), // prettier problem
);
});

Expand All @@ -68,7 +71,10 @@ describe(`TuiDocCodeComponent`, () => {

expect(fixture.nativeElement.querySelector(`.t-code`)?.innerHTML.trim()).toEqual(
`<code class="hljs"><span class="hljs-keyword">const</span> a = <span class="hljs-number">10</span>;</code>
<tui-doc-copy class="t-copy"></tui-doc-copy>`,
<div class="t-code-actions">
<tui-doc-copy class="t-copy"></tui-doc-copy>
\t
</div>`.replace(`\t`, ` `), // prettier problem
);
});

Expand All @@ -82,7 +88,10 @@ describe(`TuiDocCodeComponent`, () => {

expect(fixture.nativeElement.querySelector(`.t-code`)?.innerHTML.trim()).toEqual(
`<code class="hljs"><span class="hljs-keyword">const</span> a = <span class="hljs-number">15</span>;</code>
<tui-doc-copy class="t-copy"></tui-doc-copy>`,
<div class="t-code-actions">
<tui-doc-copy class="t-copy"></tui-doc-copy>
\t
</div>`.replace(`\t`, ` `), // prettier problem
);
});

Expand Down
13 changes: 0 additions & 13 deletions projects/addon-doc/components/example/example.style.less
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,6 @@
}
}

.t-code-actions {
position: absolute;
top: 4.375rem;
right: 1rem;
display: flex;
justify-content: flex-end;
align-items: center;

& > * {
margin-left: 0.5rem;
}
}

.t-link-icon {
margin-left: 0.3rem;
vertical-align: baseline;
Expand Down
5 changes: 2 additions & 3 deletions projects/addon-doc/components/example/example.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,11 @@
#codeSection
let-code
>
<section class="t-code-actions">
<tui-doc-code [code]="code">
<ng-container *ngFor="let action of codeActions">
<ng-container *polymorpheusOutlet="action as text; context: {$implicit: code}">
{{ text }}
</ng-container>
</ng-container>
</section>
<tui-doc-code [code]="code"></tui-doc-code>
</tui-doc-code>
</ng-template>
Loading